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

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

Issue 2903053002: Removing canvas rendering mode switching feature (Closed)
Patch Set: fix test failure 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
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "core/frame/Settings.h" 47 #include "core/frame/Settings.h"
48 #include "core/html/TextMetrics.h" 48 #include "core/html/TextMetrics.h"
49 #include "core/html/canvas/CanvasFontCache.h" 49 #include "core/html/canvas/CanvasFontCache.h"
50 #include "core/layout/HitTestCanvasResult.h" 50 #include "core/layout/HitTestCanvasResult.h"
51 #include "core/layout/LayoutBox.h" 51 #include "core/layout/LayoutBox.h"
52 #include "core/layout/LayoutTheme.h" 52 #include "core/layout/LayoutTheme.h"
53 #include "modules/canvas2d/CanvasStyle.h" 53 #include "modules/canvas2d/CanvasStyle.h"
54 #include "modules/canvas2d/HitRegion.h" 54 #include "modules/canvas2d/HitRegion.h"
55 #include "modules/canvas2d/Path2D.h" 55 #include "modules/canvas2d/Path2D.h"
56 #include "platform/fonts/FontCache.h" 56 #include "platform/fonts/FontCache.h"
57 #include "platform/graphics/CanvasHeuristicParameters.h"
57 #include "platform/graphics/DrawLooperBuilder.h" 58 #include "platform/graphics/DrawLooperBuilder.h"
58 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h"
59 #include "platform/graphics/ImageBuffer.h" 59 #include "platform/graphics/ImageBuffer.h"
60 #include "platform/graphics/StrokeData.h" 60 #include "platform/graphics/StrokeData.h"
61 #include "platform/graphics/paint/PaintCanvas.h" 61 #include "platform/graphics/paint/PaintCanvas.h"
62 #include "platform/graphics/paint/PaintFlags.h" 62 #include "platform/graphics/paint/PaintFlags.h"
63 #include "platform/graphics/skia/SkiaUtils.h" 63 #include "platform/graphics/skia/SkiaUtils.h"
64 #include "platform/text/BidiTextRun.h" 64 #include "platform/text/BidiTextRun.h"
65 #include "platform/wtf/MathExtras.h" 65 #include "platform/wtf/MathExtras.h"
66 #include "platform/wtf/text/StringBuilder.h" 66 #include "platform/wtf/text/StringBuilder.h"
67 #include "platform/wtf/typed_arrays/ArrayBufferContents.h" 67 #include "platform/wtf/typed_arrays/ArrayBufferContents.h"
68 #include "public/platform/Platform.h" 68 #include "public/platform/Platform.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 if (hit_region_manager_) { 359 if (hit_region_manager_) {
360 FloatRect rect(x, y, width, height); 360 FloatRect rect(x, y, width, height);
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 (CanvasHeuristicParameters::kBlurredShadowsAreExpensive &&
370 GetState().ShouldDrawShadows() && GetState().ShadowBlur() > 0) { 370 GetState().ShouldDrawShadows() && GetState().ShadowBlur() > 0) {
371 ImageBuffer* buffer = GetImageBuffer(); 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() {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 730
731 if (GetState().GetDirection() == direction) 731 if (GetState().GetDirection() == direction)
732 return; 732 return;
733 733
734 ModifiableState().SetDirection(direction); 734 ModifiableState().SetDirection(direction);
735 } 735 }
736 736
737 void CanvasRenderingContext2D::fillText(const String& text, 737 void CanvasRenderingContext2D::fillText(const String& text,
738 double x, 738 double x,
739 double y) { 739 double y) {
740 TrackDrawCall(kFillText);
741 DrawTextInternal(text, x, y, CanvasRenderingContext2DState::kFillPaintType); 740 DrawTextInternal(text, x, y, CanvasRenderingContext2DState::kFillPaintType);
742 } 741 }
743 742
744 void CanvasRenderingContext2D::fillText(const String& text, 743 void CanvasRenderingContext2D::fillText(const String& text,
745 double x, 744 double x,
746 double y, 745 double y,
747 double max_width) { 746 double max_width) {
748 TrackDrawCall(kFillText);
749 DrawTextInternal(text, x, y, CanvasRenderingContext2DState::kFillPaintType, 747 DrawTextInternal(text, x, y, CanvasRenderingContext2DState::kFillPaintType,
750 &max_width); 748 &max_width);
751 } 749 }
752 750
753 void CanvasRenderingContext2D::strokeText(const String& text, 751 void CanvasRenderingContext2D::strokeText(const String& text,
754 double x, 752 double x,
755 double y) { 753 double y) {
756 TrackDrawCall(kStrokeText);
757 DrawTextInternal(text, x, y, CanvasRenderingContext2DState::kStrokePaintType); 754 DrawTextInternal(text, x, y, CanvasRenderingContext2DState::kStrokePaintType);
758 } 755 }
759 756
760 void CanvasRenderingContext2D::strokeText(const String& text, 757 void CanvasRenderingContext2D::strokeText(const String& text,
761 double x, 758 double x,
762 double y, 759 double y,
763 double max_width) { 760 double max_width) {
764 TrackDrawCall(kStrokeText);
765 DrawTextInternal(text, x, y, CanvasRenderingContext2DState::kStrokePaintType, 761 DrawTextInternal(text, x, y, CanvasRenderingContext2DState::kStrokePaintType,
766 &max_width); 762 &max_width);
767 } 763 }
768 764
769 TextMetrics* CanvasRenderingContext2D::measureText(const String& text) { 765 TextMetrics* CanvasRenderingContext2D::measureText(const String& text) {
770 TextMetrics* metrics = TextMetrics::Create(); 766 TextMetrics* metrics = TextMetrics::Create();
771 767
772 // The style resolution required for fonts is not available in frame-less 768 // The style resolution required for fonts is not available in frame-less
773 // documents. 769 // documents.
774 if (!canvas()->GetDocument().GetFrame()) 770 if (!canvas()->GetDocument().GetFrame())
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 return nullptr; 1153 return nullptr;
1158 } 1154 }
1159 1155
1160 unsigned CanvasRenderingContext2D::HitRegionsCount() const { 1156 unsigned CanvasRenderingContext2D::HitRegionsCount() const {
1161 if (hit_region_manager_) 1157 if (hit_region_manager_)
1162 return hit_region_manager_->GetHitRegionsCount(); 1158 return hit_region_manager_->GetHitRegionsCount();
1163 1159
1164 return 0; 1160 return 0;
1165 } 1161 }
1166 1162
1167 bool CanvasRenderingContext2D::IsAccelerationOptimalForCanvasContent() const {
1168 // Heuristic to determine if the GPU accelerated rendering pipeline is optimal
1169 // for performance based on past usage. It has a bias towards suggesting that
1170 // the accelerated pipeline is optimal.
1171
1172 float accelerated_cost = EstimateRenderingCost(
1173 ExpensiveCanvasHeuristicParameters::kAcceleratedModeIndex);
1174
1175 float recording_cost = EstimateRenderingCost(
1176 ExpensiveCanvasHeuristicParameters::kRecordingModeIndex);
1177
1178 float cost_difference = accelerated_cost - recording_cost;
1179 float percent_cost_reduction = cost_difference / accelerated_cost * 100.0;
1180 float cost_difference_per_frame =
1181 cost_difference / usage_counters_.num_frames_since_reset;
1182
1183 if (percent_cost_reduction >=
1184 ExpensiveCanvasHeuristicParameters::
1185 kMinPercentageImprovementToSuggestDisableAcceleration &&
1186 cost_difference_per_frame >=
1187 ExpensiveCanvasHeuristicParameters::
1188 kMinCostPerFrameImprovementToSuggestDisableAcceleration) {
1189 return false;
1190 }
1191 return true;
1192 }
1193
1194 void CanvasRenderingContext2D::ResetUsageTracking() {
1195 UsageCounters new_counters;
1196 usage_counters_ = new_counters;
1197 }
1198
1199 } // namespace blink 1163 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698