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

Unified Diff: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp

Issue 2063473002: Make 2D canvas disable gpu acceleration when getImageData is called (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/platform/graphics/Canvas2DLayerBridge.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp
index 8a4c4e7d4d85691c7079a5003403eedf80462b1c..a047177b75ea0e1f975315e797fb766dbaa62b67 100644
--- a/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp
+++ b/third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp
@@ -462,22 +462,45 @@ void Canvas2DLayerBridge::reportSurfaceCreationFailure()
}
}
+void Canvas2DLayerBridge::disableAcceleration()
+{
+ DCHECK(m_layer);
+ bool surfaceIsAccelerated;
+ RefPtr<SkSurface> newSurface = createSkSurface(nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated);
+ if (newSurface) {
+ DCHECK(!surfaceIsAccelerated);
+ flushRecordingOnly();
+ SkPaint copyPaint;
+ copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
+ m_surface->draw(newSurface->getCanvas(), 0, 0, &copyPaint); // GPU readback here
+ m_accelerationMode = DisableAcceleration; // Acceleration gets permanently disabled
+ GraphicsLayer::unregisterContentsLayer(m_layer->layer());
+ m_layer->clearTexture();
+ m_layer->layer()->removeFromParent();
+ m_layer.reset();
+ m_surface = newSurface;
+ }
+}
xidachen 2016/06/15 14:12:36 By looking at the test results failure, it looks l
+
SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint)
{
- if (m_surface)
+ if (m_surface) {
+ if (hint == ForceNoAcceleration && m_layer)
+ disableAcceleration();
return m_surface.get();
+ }
if (m_layer && !isHibernating() && hint == PreferAcceleration) {
return nullptr; // re-creation will happen through restore()
}
bool wantAcceleration = shouldAccelerate(hint);
- bool surfaceIsAccelerated;
if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && wantAcceleration) {
wantAcceleration = false;
m_softwareRenderingWhileHidden = true;
}
+ bool surfaceIsAccelerated;
m_surface = createSkSurface(wantAcceleration ? m_contextProvider->grContext() : nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated);
if (!m_surface)

Powered by Google App Engine
This is Rietveld 408576698