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

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp

Issue 2874463002: avoid calling host() directly for imageBuffer on 2D rendenring contexts (Closed)
Patch Set: Created 3 years, 7 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/offscreencanvas2d/OffscreenCanvasRenderingContext2D.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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 DCHECK_EQ(static_cast<size_t>(sk_canvas->getSaveCount()), 160 DCHECK_EQ(static_cast<size_t>(sk_canvas->getSaveCount()),
161 state_stack_.size() + 1); 161 state_stack_.size() + 1);
162 } 162 }
163 } 163 }
164 #endif 164 #endif
165 CHECK(state_stack_.front() 165 CHECK(state_stack_.front()
166 .Get()); // Temporary for investigating crbug.com/648510 166 .Get()); // Temporary for investigating crbug.com/648510
167 } 167 }
168 168
169 bool CanvasRenderingContext2D::IsAccelerated() const { 169 bool CanvasRenderingContext2D::IsAccelerated() const {
170 if (!host()->GetImageBuffer()) 170 if (!HasImageBuffer())
171 return false; 171 return false;
172 return host()->GetImageBuffer()->IsAccelerated(); 172 return GetImageBuffer()->IsAccelerated();
173 } 173 }
174 174
175 bool CanvasRenderingContext2D::IsComposited() const { 175 bool CanvasRenderingContext2D::IsComposited() const {
176 return IsAccelerated(); 176 return IsAccelerated();
177 } 177 }
178 178
179 void CanvasRenderingContext2D::Stop() { 179 void CanvasRenderingContext2D::Stop() {
180 if (!isContextLost()) { 180 if (!isContextLost()) {
181 // Never attempt to restore the context because the page is being torn down. 181 // Never attempt to restore the context because the page is being torn down.
182 LoseContext(kSyntheticLostContext); 182 LoseContext(kSyntheticLostContext);
(...skipping 12 matching lines...) Expand all
195 host()->DiscardImageBuffer(); 195 host()->DiscardImageBuffer();
196 } 196 }
197 dispatch_context_lost_event_timer_.StartOneShot(0, BLINK_FROM_HERE); 197 dispatch_context_lost_event_timer_.StartOneShot(0, BLINK_FROM_HERE);
198 } 198 }
199 199
200 void CanvasRenderingContext2D::DidSetSurfaceSize() { 200 void CanvasRenderingContext2D::DidSetSurfaceSize() {
201 if (!context_restorable_) 201 if (!context_restorable_)
202 return; 202 return;
203 // This code path is for restoring from an eviction 203 // This code path is for restoring from an eviction
204 // Restoring from surface failure is handled internally 204 // Restoring from surface failure is handled internally
205 DCHECK(context_lost_mode_ != kNotLostContext && !host()->GetImageBuffer()); 205 DCHECK(context_lost_mode_ != kNotLostContext && !HasImageBuffer());
206 206
207 if (host()->GetOrCreateImageBuffer()) { 207 if (GetImageBuffer()) {
208 if (ContextLostRestoredEventsEnabled()) { 208 if (ContextLostRestoredEventsEnabled()) {
209 dispatch_context_restored_event_timer_.StartOneShot(0, BLINK_FROM_HERE); 209 dispatch_context_restored_event_timer_.StartOneShot(0, BLINK_FROM_HERE);
210 } else { 210 } else {
211 // legacy synchronous context restoration. 211 // legacy synchronous context restoration.
212 Reset(); 212 Reset();
213 context_lost_mode_ = kNotLostContext; 213 context_lost_mode_ = kNotLostContext;
214 } 214 }
215 } 215 }
216 } 216 }
217 217
(...skipping 25 matching lines...) Expand all
243 243
244 void CanvasRenderingContext2D::TryRestoreContextEvent(TimerBase* timer) { 244 void CanvasRenderingContext2D::TryRestoreContextEvent(TimerBase* timer) {
245 if (context_lost_mode_ == kNotLostContext) { 245 if (context_lost_mode_ == kNotLostContext) {
246 // Canvas was already restored (possibly thanks to a resize), so stop 246 // Canvas was already restored (possibly thanks to a resize), so stop
247 // trying. 247 // trying.
248 try_restore_context_event_timer_.Stop(); 248 try_restore_context_event_timer_.Stop();
249 return; 249 return;
250 } 250 }
251 251
252 DCHECK(context_lost_mode_ == kRealLostContext); 252 DCHECK(context_lost_mode_ == kRealLostContext);
253 if (host()->GetImageBuffer() && host()->GetImageBuffer()->RestoreSurface()) { 253 if (HasImageBuffer() && GetImageBuffer()->RestoreSurface()) {
254 try_restore_context_event_timer_.Stop(); 254 try_restore_context_event_timer_.Stop();
255 DispatchContextRestoredEvent(nullptr); 255 DispatchContextRestoredEvent(nullptr);
256 } 256 }
257 257
258 if (++try_restore_context_attempt_count_ > kMaxTryRestoreContextAttempts) { 258 if (++try_restore_context_attempt_count_ > kMaxTryRestoreContextAttempts) {
259 // final attempt: allocate a brand new image buffer instead of restoring 259 // final attempt: allocate a brand new image buffer instead of restoring
260 host()->DiscardImageBuffer(); 260 host()->DiscardImageBuffer();
261 try_restore_context_event_timer_.Stop(); 261 try_restore_context_event_timer_.Stop();
262 if (host()->GetOrCreateImageBuffer()) 262 if (GetImageBuffer())
263 DispatchContextRestoredEvent(nullptr); 263 DispatchContextRestoredEvent(nullptr);
264 } 264 }
265 } 265 }
266 266
267 void CanvasRenderingContext2D::DispatchContextRestoredEvent(TimerBase*) { 267 void CanvasRenderingContext2D::DispatchContextRestoredEvent(TimerBase*) {
268 if (context_lost_mode_ == kNotLostContext) 268 if (context_lost_mode_ == kNotLostContext)
269 return; 269 return;
270 Reset(); 270 Reset();
271 context_lost_mode_ = kNotLostContext; 271 context_lost_mode_ = kNotLostContext;
272 if (ContextLostRestoredEventsEnabled()) { 272 if (ContextLostRestoredEventsEnabled()) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 hit_region_manager_->RemoveHitRegionsInRect(rect, GetState().Transform()); 361 hit_region_manager_->RemoveHitRegionsInRect(rect, GetState().Transform());
362 } 362 }
363 } 363 }
364 364
365 void CanvasRenderingContext2D::DidDraw(const SkIRect& dirty_rect) { 365 void CanvasRenderingContext2D::DidDraw(const SkIRect& dirty_rect) {
366 if (dirty_rect.isEmpty()) 366 if (dirty_rect.isEmpty())
367 return; 367 return;
368 368
369 if (ExpensiveCanvasHeuristicParameters::kBlurredShadowsAreExpensive && 369 if (ExpensiveCanvasHeuristicParameters::kBlurredShadowsAreExpensive &&
370 GetState().ShouldDrawShadows() && GetState().ShadowBlur() > 0) { 370 GetState().ShouldDrawShadows() && GetState().ShadowBlur() > 0) {
371 ImageBuffer* buffer = host()->GetOrCreateImageBuffer(); 371 ImageBuffer* buffer = GetImageBuffer();
372 if (buffer) 372 if (buffer)
373 buffer->SetHasExpensiveOp(); 373 buffer->SetHasExpensiveOp();
374 } 374 }
375 375
376 CanvasRenderingContext::DidDraw(dirty_rect); 376 CanvasRenderingContext::DidDraw(dirty_rect);
377 } 377 }
378 378
379 bool CanvasRenderingContext2D::StateHasFilter() { 379 bool CanvasRenderingContext2D::StateHasFilter() {
380 return GetState().HasFilter(canvas(), canvas()->Size(), this); 380 return GetState().HasFilter(canvas(), canvas()->Size(), this);
381 } 381 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 ImageBuffer* CanvasRenderingContext2D::GetImageBuffer() const { 608 ImageBuffer* CanvasRenderingContext2D::GetImageBuffer() const {
609 return const_cast<CanvasRenderingContextHost*>(host()) 609 return const_cast<CanvasRenderingContextHost*>(host())
610 ->GetOrCreateImageBuffer(); 610 ->GetOrCreateImageBuffer();
611 } 611 }
612 612
613 PassRefPtr<Image> blink::CanvasRenderingContext2D::GetImage( 613 PassRefPtr<Image> blink::CanvasRenderingContext2D::GetImage(
614 AccelerationHint hint, 614 AccelerationHint hint,
615 SnapshotReason reason) const { 615 SnapshotReason reason) const {
616 if (!HasImageBuffer()) 616 if (!HasImageBuffer())
617 return nullptr; 617 return nullptr;
618 return host()->GetOrCreateImageBuffer()->NewImageSnapshot(hint, reason); 618 return GetImageBuffer()->NewImageSnapshot(hint, reason);
619 } 619 }
620 620
621 bool CanvasRenderingContext2D::ParseColorOrCurrentColor( 621 bool CanvasRenderingContext2D::ParseColorOrCurrentColor(
622 Color& color, 622 Color& color,
623 const String& color_string) const { 623 const String& color_string) const {
624 return ::blink::ParseColorOrCurrentColor(color, color_string, canvas()); 624 return ::blink::ParseColorOrCurrentColor(color, color_string, canvas());
625 } 625 }
626 626
627 HitTestCanvasResult* CanvasRenderingContext2D::GetControlAndIdIfHitRegionExists( 627 HitTestCanvasResult* CanvasRenderingContext2D::GetControlAndIdIfHitRegionExists(
628 const LayoutPoint& location) { 628 const LayoutPoint& location) {
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 : -font_metrics.Descent() + font_metrics.Height() / 2; 973 : -font_metrics.Descent() + font_metrics.Height() / 2;
974 case kAlphabeticTextBaseline: 974 case kAlphabeticTextBaseline:
975 default: 975 default:
976 // Do nothing. 976 // Do nothing.
977 break; 977 break;
978 } 978 }
979 return 0; 979 return 0;
980 } 980 }
981 981
982 void CanvasRenderingContext2D::SetIsHidden(bool hidden) { 982 void CanvasRenderingContext2D::SetIsHidden(bool hidden) {
983 if (host()->GetImageBuffer()) 983 if (HasImageBuffer())
984 host()->GetImageBuffer()->SetIsHidden(hidden); 984 GetImageBuffer()->SetIsHidden(hidden);
985 if (hidden) { 985 if (hidden) {
986 PruneLocalFontCache(0); 986 PruneLocalFontCache(0);
987 } 987 }
988 } 988 }
989 989
990 bool CanvasRenderingContext2D::IsTransformInvertible() const { 990 bool CanvasRenderingContext2D::IsTransformInvertible() const {
991 return GetState().IsTransformInvertible(); 991 return GetState().IsTransformInvertible();
992 } 992 }
993 993
994 WebLayer* CanvasRenderingContext2D::PlatformLayer() const { 994 WebLayer* CanvasRenderingContext2D::PlatformLayer() const {
995 return host()->GetOrCreateImageBuffer() 995 return GetImageBuffer() ? GetImageBuffer()->PlatformLayer() : 0;
996 ? host()->GetImageBuffer()->PlatformLayer()
997 : 0;
998 } 996 }
999 997
1000 void CanvasRenderingContext2D::getContextAttributes( 998 void CanvasRenderingContext2D::getContextAttributes(
1001 CanvasRenderingContext2DSettings& settings) const { 999 CanvasRenderingContext2DSettings& settings) const {
1002 settings.setAlpha(CreationAttributes().alpha()); 1000 settings.setAlpha(CreationAttributes().alpha());
1003 settings.setColorSpace(ColorSpaceAsString()); 1001 settings.setColorSpace(ColorSpaceAsString());
1004 settings.setPixelFormat(PixelFormatAsString()); 1002 settings.setPixelFormat(PixelFormatAsString());
1005 settings.setLinearPixelMath(color_params().LinearPixelMath()); 1003 settings.setLinearPixelMath(color_params().LinearPixelMath());
1006 } 1004 }
1007 1005
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 } 1190 }
1193 return true; 1191 return true;
1194 } 1192 }
1195 1193
1196 void CanvasRenderingContext2D::ResetUsageTracking() { 1194 void CanvasRenderingContext2D::ResetUsageTracking() {
1197 UsageCounters new_counters; 1195 UsageCounters new_counters;
1198 usage_counters_ = new_counters; 1196 usage_counters_ = new_counters;
1199 } 1197 }
1200 1198
1201 } // namespace blink 1199 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698