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

Unified Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp

Issue 2141793002: Improving canvas 2D performance by switching graphics rendering pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/CanvasRenderingContext2D.cpp
diff --git a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp b/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp
index a8f41ef5f440bb17342b0f8ca18bcd7ee3a13013..e027e2a0f0fd940c1b88d3be9f66796399d18b2f 100644
--- a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp
@@ -1068,4 +1068,38 @@ unsigned CanvasRenderingContext2D::hitRegionsCount() const
return 0;
}
+bool CanvasRenderingContext2D::shouldAccelerate() const
+{
+ // Simple heuristic to determine if the GPU accelerated pipeline should be
+ // used to maximize performance of 2D canvas based on past usage.
+ // The current implementation has a bias towards suggesting
+ // the use of the accelerated pipeline. The coefficients used
+ // to estimate the rendering cost of pipelines are approximate
+ // and were determined experimentally.
+
+ int numDrawPathCalls =
+ m_usageCounters.numDrawCalls[StrokePath] +
+ m_usageCounters.numDrawCalls[FillPath] +
+ m_usageCounters.numDrawCalls[FillText] +
+ m_usageCounters.numDrawCalls[StrokeText] +
+ m_usageCounters.numDrawCalls[FillRect] +
+ m_usageCounters.numDrawCalls[StrokeRect];
+
+ double acceleratedCost =
+ numDrawPathCalls * 0.004 +
Justin Novosad 2016/07/12 19:31:24 These coefficients should all go in ExpensiveCAnva
sebastienlc 2016/07/13 19:51:02 Done.
+ m_usageCounters.numGetImageDataCalls * 0.1 +
+ m_usageCounters.numDrawCalls[DrawImage] * 0.002;
+
+ double unacceleratedCost =
+ numDrawPathCalls * 0.0014 +
+ m_usageCounters.numGetImageDataCalls * 0.001 +
+ m_usageCounters.numDrawCalls[DrawImage] * 0.004;
+
+ double unacceleratedPenalty = 1.5; // greater than 1 to create a bias towards suggesting acceleration
Justin Novosad 2016/07/12 19:31:24 This threshold should be in ExpensiveCanvasHeurist
sebastienlc 2016/07/13 19:51:02 Done.
+ if (unacceleratedCost * unacceleratedPenalty < acceleratedCost) {
+ return false;
+ }
+ return true;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698