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

Unified 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, 3 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
Index: third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
diff --git a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
index e0db5591d855ae297d2134e964605ecc916ca831..e18695113413e3db4d91ea3dc405909736b4dc74 100644
--- a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
@@ -964,7 +964,6 @@ void BaseRenderingContext2D::drawImageInternal(SkCanvas* c, CanvasImageSource* i
trackDrawCall(DrawBitmapImage, nullptr, dstRect.width(), dstRect.height());
}
-
int initialSaveCount = c->getSaveCount();
SkPaint imagePaint = *paint;
@@ -1076,6 +1075,26 @@ void BaseRenderingContext2D::drawImage(ExecutionContext* executionContext, Canva
validateStateStack();
+ // Heuristic for disabling acceleration based on anticipated texture upload overhead
+ // See comments in ExpensiveCanvasHeuristicParameters.h for explanation.
+ ImageBuffer* buffer = imageBuffer();
+ if (buffer && buffer->isAccelerated() && !imageSource->isAccelerated()) {
+ float srcArea = srcRect.width() * srcRect.height();
+ if (srcArea > ExpensiveCanvasHeuristicParameters::DrawImageTextureUploadHardSizeLimit) {
+ buffer->disableAcceleration();
+ } else if (srcArea > ExpensiveCanvasHeuristicParameters::DrawImageTextureUploadSoftSizeLimit) {
+ SkRect bounds = dstRect;
+ SkMatrix ctm = drawingCanvas()->getTotalMatrix();
+ ctm.mapRect(&bounds);
+ float dstArea = dstRect.width() * dstRect.height();
+ if (srcArea > dstArea * ExpensiveCanvasHeuristicParameters::DrawImageTextureUploadSoftSizeLimitScaleThreshold) {
+ buffer->disableAcceleration();
+ }
+ }
+ }
+
+ validateStateStack();
+
// TODO(xidachen): After collecting some data, come back and prune off
// the ones that is not needed.
Optional<ScopedUsHistogramTimer> timer;

Powered by Google App Engine
This is Rietveld 408576698