Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Unified Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp

Issue 2391373002: Refactor CRC2D::reset() to avoid non-additive SkCanvas state operations (Closed)
Patch Set: review Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/csspaint/PaintRenderingContext2D.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp
diff --git a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp b/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp
index f2fa9f7fa472bea7b7ff7d3d04b4eb6cc8b56776..34159d0147c430dd3b0d49e5ed90a19d0ff5fb7e 100644
--- a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp
@@ -158,11 +158,16 @@ void CanvasRenderingContext2D::dispose() {
}
void CanvasRenderingContext2D::validateStateStack() const {
-#if ENABLE(ASSERT)
- SkCanvas* skCanvas = canvas()->existingDrawingCanvas();
- if (skCanvas && m_contextLostMode == NotLostContext) {
- ASSERT(static_cast<size_t>(skCanvas->getSaveCount()) ==
- m_stateStack.size());
+#if DCHECK_IS_ON()
+ if (SkCanvas* skCanvas = canvas()->existingDrawingCanvas()) {
+ // The canvas should always have an initial save frame, to support
+ // resetting the top level matrix and clip.
+ DCHECK_GT(skCanvas->getSaveCount(), 1);
+
+ if (m_contextLostMode == NotLostContext) {
+ DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()),
+ m_stateStack.size() + 1);
+ }
}
#endif
CHECK(m_stateStack.first()
@@ -279,11 +284,18 @@ void CanvasRenderingContext2D::reset() {
m_stateStack.resize(1);
m_stateStack.first() = CanvasRenderingContext2DState::create();
m_path.clear();
- SkCanvas* c = canvas()->existingDrawingCanvas();
- if (c) {
- c->resetMatrix();
- c->clipRect(SkRect::MakeWH(canvas()->width(), canvas()->height()),
- SkRegion::kReplace_Op);
+ if (SkCanvas* c = canvas()->existingDrawingCanvas()) {
+ // The canvas should always have an initial/unbalanced save frame, which
+ // we use to reset the top level matrix and clip here.
+ DCHECK_EQ(c->getSaveCount(), 2);
+ c->restore();
+ c->save();
+ DCHECK(c->getTotalMatrix().isIdentity());
+#if DCHECK_IS_ON()
+ SkIRect clipBounds;
+ DCHECK(c->getClipDeviceBounds(&clipBounds));
+ DCHECK(clipBounds == c->imageInfo().bounds());
+#endif
}
validateStateStack();
}
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/csspaint/PaintRenderingContext2D.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698