Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (285333 => 285334)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2021-11-05 04:06:12 UTC (rev 285333)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2021-11-05 04:52:41 UTC (rev 285334)
@@ -1061,12 +1061,9 @@
} else
c->fillPath(path);
- if (isEntireBackingStoreDirty())
- didDraw(std::nullopt);
- else if (repaintEntireCanvas)
- didDrawEntireCanvas();
- else
- didDraw(path.fastBoundingRect());
+ didDraw(repaintEntireCanvas, [&] {
+ return path.fastBoundingRect();
+ });
c->setFillRule(savedFillRule);
}
@@ -1100,15 +1097,11 @@
} else
c->strokePath(path);
- if (isEntireBackingStoreDirty())
- didDraw(std::nullopt);
- else if (repaintEntireCanvas)
- didDrawEntireCanvas();
- else {
+ didDraw(repaintEntireCanvas, [&] {
auto dirtyRect = path.fastBoundingRect();
inflateStrokeRect(dirtyRect);
- didDraw(dirtyRect);
- }
+ return dirtyRect;
+ });
}
void CanvasRenderingContext2DBase::clipInternal(const Path& path, CanvasFillRule windingRule)
@@ -1270,12 +1263,7 @@
} else
c->fillRect(rect);
- if (isEntireBackingStoreDirty())
- didDraw(std::nullopt);
- else if (repaintEntireCanvas)
- didDrawEntireCanvas();
- else
- didDraw(rect);
+ didDraw(repaintEntireCanvas, rect);
}
void CanvasRenderingContext2DBase::strokeRect(double x, double y, double width, double height)
@@ -1310,15 +1298,11 @@
} else
c->strokeRect(rect, state().lineWidth);
- if (isEntireBackingStoreDirty())
- didDraw(std::nullopt);
- else if (repaintEntireCanvas)
- didDrawEntireCanvas();
- else {
+ didDraw(repaintEntireCanvas, [&] {
auto boundingRect = rect;
boundingRect.inflate(state().lineWidth / 2);
- didDraw(boundingRect);
- }
+ return boundingRect;
+ });
}
void CanvasRenderingContext2DBase::setShadow(float width, float height, float blur, const String& colorString, std::optional<float> alpha)
@@ -1582,12 +1566,7 @@
} else
c->drawImageForCanvas(*image, normalizedDstRect, normalizedSrcRect, options, colorSpace());
- if (isEntireBackingStoreDirty())
- didDraw(std::nullopt);
- else if (repaintEntireCanvas)
- didDrawEntireCanvas();
- else
- didDraw(normalizedDstRect);
+ didDraw(repaintEntireCanvas, normalizedDstRect);
if (image->drawsSVGImage())
image->setImageObserver(observer);
@@ -1644,12 +1623,7 @@
} else
c->drawImageBuffer(*buffer, dstRect, srcRect, { state().globalComposite, state().globalBlend });
- if (isEntireBackingStoreDirty())
- didDraw(std::nullopt);
- else if (repaintEntireCanvas)
- didDrawEntireCanvas();
- else
- didDraw(dstRect);
+ didDraw(repaintEntireCanvas, dstRect);
return { };
}
@@ -1676,17 +1650,14 @@
checkOrigin(&video);
+ bool repaintEntireCanvas = rectContainsCanvas(dstRect);
+
#if USE(CG)
if (c->hasPlatformContext()) {
if (auto image = video.nativeImageForCurrentTime()) {
c->drawNativeImage(*image, FloatSize(video.videoWidth(), video.videoHeight()), dstRect, srcRect);
- if (isEntireBackingStoreDirty())
- didDraw(std::nullopt);
- else if (rectContainsCanvas(dstRect))
- didDrawEntireCanvas();
- else
- didDraw(dstRect);
+ didDraw(repaintEntireCanvas, dstRect);
return { };
}
@@ -1701,10 +1672,7 @@
video.paintCurrentFrameInContext(*c, FloatRect(FloatPoint(), size(video)));
stateSaver.restore();
- if (isEntireBackingStoreDirty())
- didDraw(std::nullopt);
- else
- didDraw(dstRect);
+ didDraw(repaintEntireCanvas, dstRect);
return { };
}
@@ -1752,12 +1720,7 @@
} else
c->drawImageBuffer(*buffer, dstRect, srcRect, { state().globalComposite, state().globalBlend });
- if (isEntireBackingStoreDirty())
- didDraw(std::nullopt);
- else if (repaintEntireCanvas)
- didDrawEntireCanvas();
- else
- didDraw(dstRect);
+ didDraw(repaintEntireCanvas, dstRect);
return { };
}
@@ -2093,6 +2056,24 @@
}
}
+void CanvasRenderingContext2DBase::didDraw(bool entireCanvas, const FloatRect& rect)
+{
+ return didDraw(entireCanvas, [&] {
+ return rect;
+ });
+}
+
+template<typename RectProvider>
+void CanvasRenderingContext2DBase::didDraw(bool entireCanvas, RectProvider rectProvider)
+{
+ if (isEntireBackingStoreDirty())
+ didDraw(std::nullopt);
+ else if (entireCanvas)
+ didDrawEntireCanvas();
+ else
+ didDraw(rectProvider());
+}
+
void CanvasRenderingContext2DBase::clearAccumulatedDirtyRect()
{
m_dirtyRect = { };
@@ -2533,12 +2514,7 @@
} else
fontProxy.drawBidiText(*c, textRun, location, FontCascade::UseFallbackIfFontNotReady);
- if (isEntireBackingStoreDirty())
- didDraw(std::nullopt);
- else if (repaintEntireCanvas)
- didDrawEntireCanvas();
- else
- didDraw(textRect);
+ didDraw(repaintEntireCanvas, textRect);
}
Ref<TextMetrics> CanvasRenderingContext2DBase::measureTextInternal(const String& text)
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h (285333 => 285334)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h 2021-11-05 04:06:12 UTC (rev 285333)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h 2021-11-05 04:52:41 UTC (rev 285334)
@@ -324,6 +324,8 @@
};
void didDraw(std::optional<FloatRect>, OptionSet<DidDrawOption> = { DidDrawOption::ApplyTransform, DidDrawOption::ApplyShadow, DidDrawOption::ApplyClip });
void didDrawEntireCanvas();
+ void didDraw(bool entireCanvas, const FloatRect&);
+ template<typename RectProvider> void didDraw(bool entireCanvas, RectProvider);
void paintRenderingResultsToCanvas() override;
bool needsPreparationForDisplay() const final;