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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/csspaint/PaintRenderingContext2D.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
3 * All rights reserved. 3 * All rights reserved.
4 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 4 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
5 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 5 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 7 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
8 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 8 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
9 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved.
10 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 10 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 151 }
152 152
153 CanvasRenderingContext2D::~CanvasRenderingContext2D() {} 153 CanvasRenderingContext2D::~CanvasRenderingContext2D() {}
154 154
155 void CanvasRenderingContext2D::dispose() { 155 void CanvasRenderingContext2D::dispose() {
156 if (m_pruneLocalFontCacheScheduled) 156 if (m_pruneLocalFontCacheScheduled)
157 Platform::current()->currentThread()->removeTaskObserver(this); 157 Platform::current()->currentThread()->removeTaskObserver(this);
158 } 158 }
159 159
160 void CanvasRenderingContext2D::validateStateStack() const { 160 void CanvasRenderingContext2D::validateStateStack() const {
161 #if ENABLE(ASSERT) 161 #if DCHECK_IS_ON()
162 SkCanvas* skCanvas = canvas()->existingDrawingCanvas(); 162 if (SkCanvas* skCanvas = canvas()->existingDrawingCanvas()) {
163 if (skCanvas && m_contextLostMode == NotLostContext) { 163 // The canvas should always have an initial save frame, to support
164 ASSERT(static_cast<size_t>(skCanvas->getSaveCount()) == 164 // resetting the top level matrix and clip.
165 m_stateStack.size()); 165 DCHECK_GT(skCanvas->getSaveCount(), 1);
166
167 if (m_contextLostMode == NotLostContext) {
168 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()),
169 m_stateStack.size() + 1);
170 }
166 } 171 }
167 #endif 172 #endif
168 CHECK(m_stateStack.first() 173 CHECK(m_stateStack.first()
169 .get()); // Temporary for investigating crbug.com/648510 174 .get()); // Temporary for investigating crbug.com/648510
170 } 175 }
171 176
172 bool CanvasRenderingContext2D::isAccelerated() const { 177 bool CanvasRenderingContext2D::isAccelerated() const {
173 if (!canvas()->hasImageBuffer()) 178 if (!canvas()->hasImageBuffer())
174 return false; 179 return false;
175 return canvas()->buffer()->isAccelerated(); 180 return canvas()->buffer()->isAccelerated();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 canvas()->dispatchEvent(event); 277 canvas()->dispatchEvent(event);
273 } 278 }
274 } 279 }
275 280
276 void CanvasRenderingContext2D::reset() { 281 void CanvasRenderingContext2D::reset() {
277 validateStateStack(); 282 validateStateStack();
278 unwindStateStack(); 283 unwindStateStack();
279 m_stateStack.resize(1); 284 m_stateStack.resize(1);
280 m_stateStack.first() = CanvasRenderingContext2DState::create(); 285 m_stateStack.first() = CanvasRenderingContext2DState::create();
281 m_path.clear(); 286 m_path.clear();
282 SkCanvas* c = canvas()->existingDrawingCanvas(); 287 if (SkCanvas* c = canvas()->existingDrawingCanvas()) {
283 if (c) { 288 // The canvas should always have an initial/unbalanced save frame, which
284 c->resetMatrix(); 289 // we use to reset the top level matrix and clip here.
285 c->clipRect(SkRect::MakeWH(canvas()->width(), canvas()->height()), 290 DCHECK_EQ(c->getSaveCount(), 2);
286 SkRegion::kReplace_Op); 291 c->restore();
292 c->save();
293 DCHECK(c->getTotalMatrix().isIdentity());
294 #if DCHECK_IS_ON()
295 SkIRect clipBounds;
296 DCHECK(c->getClipDeviceBounds(&clipBounds));
297 DCHECK(clipBounds == c->imageInfo().bounds());
298 #endif
287 } 299 }
288 validateStateStack(); 300 validateStateStack();
289 } 301 }
290 302
291 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack(SkCanvas* c) const { 303 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack(SkCanvas* c) const {
292 restoreMatrixClipStack(c); 304 restoreMatrixClipStack(c);
293 } 305 }
294 306
295 bool CanvasRenderingContext2D::shouldAntialias() const { 307 bool CanvasRenderingContext2D::shouldAntialias() const {
296 return state().shouldAntialias(); 308 return state().shouldAntialias();
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 } 1140 }
1129 return true; 1141 return true;
1130 } 1142 }
1131 1143
1132 void CanvasRenderingContext2D::resetUsageTracking() { 1144 void CanvasRenderingContext2D::resetUsageTracking() {
1133 UsageCounters newCounters; 1145 UsageCounters newCounters;
1134 m_usageCounters = newCounters; 1146 m_usageCounters = newCounters;
1135 } 1147 }
1136 1148
1137 } // namespace blink 1149 } // namespace blink
OLDNEW
« 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