Chromium Code Reviews| 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() |