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

Unified Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.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: Added flag to histograms.xml enum LoginCustomFlags. 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/core/html/HTMLCanvasElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
index ca1f5ac6b3c46766c330ea23d7032a3c969c193e..17e1eed62e0148d0232fe6c275709155072abd12 100644
--- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
@@ -148,6 +148,7 @@ inline HTMLCanvasElement::HTMLCanvasElement(Document& document)
, m_originClean(true)
, m_didFailToCreateImageBuffer(false)
, m_imageBufferIsClear(false)
+ , m_numFramesSinceLastRenderingModeSwitch(0)
{
CanvasMetrics::countCanvasContextUsage(CanvasMetrics::CanvasCreated);
}
@@ -316,6 +317,25 @@ void HTMLCanvasElement::didFinalizeFrame()
ro->invalidatePaintRectangle(mappedDirtyRect);
}
m_dirtyRect = FloatRect();
+
+ m_numFramesSinceLastRenderingModeSwitch++;
+ if (m_context->is2d() && buffer()->isAccelerated()
+ && m_numFramesSinceLastRenderingModeSwitch >= ExpensiveCanvasHeuristicParameters::MinFramesBeforeSwitch) {
+ if (RuntimeEnabledFeatures::enableCanvas2dDynamicRenderingModeSwitchingEnabled()) {
Stephen White 2016/07/19 15:47:41 Nit: perhaps this check should be outside of all o
sebastienlc 2016/07/19 18:59:24 Done.
+ if (!m_context->isAccelerationOptimalForCanvasContent()) {
+ // The switch must be done asynchronously in order to avoid switching during the paint invalidation step.
+ Platform::current()->currentThread()->getWebTaskRunner()->postTask(
+ BLINK_FROM_HERE,
+ WTF::bind([](WeakPtr<ImageBuffer> buffer) {
Stephen White 2016/07/19 15:47:41 Do you still need WTF::bind() here, or could you j
sebastienlc 2016/07/19 18:59:24 I tried but the type conversion doesn't seem to wo
+ if (buffer) {
+ buffer->disableAcceleration();
+ }
+ },
+ m_imageBuffer->m_weakPtrFactory.createWeakPtr()));
+ m_numFramesSinceLastRenderingModeSwitch = 0;
+ }
+ }
+ }
}
void HTMLCanvasElement::didDisableAcceleration()

Powered by Google App Engine
This is Rietveld 408576698