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

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

Issue 2362363002: Cancel GPU acceleration for 2D canvas when drawing very large images (Closed)
Patch Set: fix sqrt 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/canvas2d/BaseRenderingContext2D.h" 5 #include "modules/canvas2d/BaseRenderingContext2D.h"
6 6
7 #include "bindings/core/v8/ExceptionMessages.h" 7 #include "bindings/core/v8/ExceptionMessages.h"
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 9 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
10 #include "core/css/parser/CSSParser.h" 10 #include "core/css/parser/CSSParser.h"
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 } 957 }
958 958
959 void BaseRenderingContext2D::drawImageInternal(SkCanvas* c, CanvasImageSource* i mageSource, Image* image, const FloatRect& srcRect, const FloatRect& dstRect, co nst SkPaint* paint) 959 void BaseRenderingContext2D::drawImageInternal(SkCanvas* c, CanvasImageSource* i mageSource, Image* image, const FloatRect& srcRect, const FloatRect& dstRect, co nst SkPaint* paint)
960 { 960 {
961 if (imageSource->isSVGSource()) { 961 if (imageSource->isSVGSource()) {
962 trackDrawCall(DrawVectorImage, nullptr, dstRect.width(), dstRect.height( )); 962 trackDrawCall(DrawVectorImage, nullptr, dstRect.width(), dstRect.height( ));
963 } else { 963 } else {
964 trackDrawCall(DrawBitmapImage, nullptr, dstRect.width(), dstRect.height( )); 964 trackDrawCall(DrawBitmapImage, nullptr, dstRect.width(), dstRect.height( ));
965 } 965 }
966 966
967
968 int initialSaveCount = c->getSaveCount(); 967 int initialSaveCount = c->getSaveCount();
969 SkPaint imagePaint = *paint; 968 SkPaint imagePaint = *paint;
970 969
971 if (paint->getImageFilter()) { 970 if (paint->getImageFilter()) {
972 SkMatrix ctm = c->getTotalMatrix(); 971 SkMatrix ctm = c->getTotalMatrix();
973 SkMatrix invCtm; 972 SkMatrix invCtm;
974 if (!ctm.invert(&invCtm)) { 973 if (!ctm.invert(&invCtm)) {
975 // There is an earlier check for invertibility, but the arithmetic 974 // There is an earlier check for invertibility, but the arithmetic
976 // in AffineTransform is not exactly identical, so it is possible 975 // in AffineTransform is not exactly identical, so it is possible
977 // for SkMatrix to find the transform to be non-invertible at this s tage. 976 // for SkMatrix to find the transform to be non-invertible at this s tage.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 return; 1068 return;
1070 1069
1071 DisableDeferralReason reason = DisableDeferralReasonUnknown; 1070 DisableDeferralReason reason = DisableDeferralReasonUnknown;
1072 if (shouldDisableDeferral(imageSource, &reason)) 1071 if (shouldDisableDeferral(imageSource, &reason))
1073 disableDeferral(reason); 1072 disableDeferral(reason);
1074 else if (image->isTextureBacked()) 1073 else if (image->isTextureBacked())
1075 disableDeferral(DisableDeferralDrawImageWithTextureBackedSourceImage); 1074 disableDeferral(DisableDeferralDrawImageWithTextureBackedSourceImage);
1076 1075
1077 validateStateStack(); 1076 validateStateStack();
1078 1077
1078 // Heuristic for disabling acceleration based on anticipated texture upload overhead
1079 // See comments in ExpensiveCanvasHeuristicParameters.h for explanation.
1080 ImageBuffer* buffer = imageBuffer();
1081 if (buffer && buffer->isAccelerated() && !imageSource->isAccelerated()) {
1082 float srcArea = srcRect.width() * srcRect.height();
1083 if (srcArea > ExpensiveCanvasHeuristicParameters::DrawImageTextureUpload HardSizeLimit) {
1084 buffer->disableAcceleration();
1085 } else if (srcArea > ExpensiveCanvasHeuristicParameters::DrawImageTextur eUploadSoftSizeLimit) {
1086 SkRect bounds = dstRect;
1087 SkMatrix ctm = drawingCanvas()->getTotalMatrix();
1088 ctm.mapRect(&bounds);
1089 float dstArea = dstRect.width() * dstRect.height();
1090 if (srcArea > dstArea * ExpensiveCanvasHeuristicParameters::DrawImag eTextureUploadSoftSizeLimitScaleThreshold) {
1091 buffer->disableAcceleration();
1092 }
1093 }
1094 }
1095
1096 validateStateStack();
1097
1079 // TODO(xidachen): After collecting some data, come back and prune off 1098 // TODO(xidachen): After collecting some data, come back and prune off
1080 // the ones that is not needed. 1099 // the ones that is not needed.
1081 Optional<ScopedUsHistogramTimer> timer; 1100 Optional<ScopedUsHistogramTimer> timer;
1082 if (imageBuffer() && imageBuffer()->isAccelerated()) { 1101 if (imageBuffer() && imageBuffer()->isAccelerated()) {
1083 if (imageSource->isVideoElement()) { 1102 if (imageSource->isVideoElement()) {
1084 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte rVideoGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Video.GPU", 0, 10000 000, 50)); 1103 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte rVideoGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Video.GPU", 0, 10000 000, 50));
1085 timer.emplace(scopedUsCounterVideoGPU); 1104 timer.emplace(scopedUsCounterVideoGPU);
1086 } else if (imageSource->isCanvasElement()) { 1105 } else if (imageSource->isCanvasElement()) {
1087 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte rCanvasGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Canvas.GPU", 0, 100 00000, 50)); 1106 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte rCanvasGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Canvas.GPU", 0, 100 00000, 50));
1088 timer.emplace(scopedUsCounterCanvasGPU); 1107 timer.emplace(scopedUsCounterCanvasGPU);
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 ExpensiveCanvasHeuristicParameters::RadialGradientFillVariableCostPerAre a[index] * m_usageCounters.boundingBoxAreaFillType[BaseRenderingContext2D::Radia lGradientFillType]; 1728 ExpensiveCanvasHeuristicParameters::RadialGradientFillVariableCostPerAre a[index] * m_usageCounters.boundingBoxAreaFillType[BaseRenderingContext2D::Radia lGradientFillType];
1710 1729
1711 float shadowAdjustment = 1730 float shadowAdjustment =
1712 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * m_usageCoun ters.numBlurredShadows + 1731 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * m_usageCoun ters.numBlurredShadows +
1713 ExpensiveCanvasHeuristicParameters::ShadowVariableCostPerAreaTimesShadow BlurSquared[index] * m_usageCounters.boundingBoxAreaTimesShadowBlurSquared; 1732 ExpensiveCanvasHeuristicParameters::ShadowVariableCostPerAreaTimesShadow BlurSquared[index] * m_usageCounters.boundingBoxAreaTimesShadowBlurSquared;
1714 1733
1715 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; 1734 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment;
1716 } 1735 }
1717 1736
1718 } // namespace blink 1737 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698