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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 { 455 {
456 if (!m_surfaceCreationFailedAtLeastOnce) { 456 if (!m_surfaceCreationFailedAtLeastOnce) {
457 // Only count the failure once per instance so that the histogram may 457 // Only count the failure once per instance so that the histogram may
458 // reflect the proportion of Canvas2DLayerBridge instances with surface 458 // reflect the proportion of Canvas2DLayerBridge instances with surface
459 // allocation failures. 459 // allocation failures.
460 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa nvasSurfaceCreationFailed); 460 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa nvasSurfaceCreationFailed);
461 m_surfaceCreationFailedAtLeastOnce = true; 461 m_surfaceCreationFailedAtLeastOnce = true;
462 } 462 }
463 } 463 }
464 464
465 void Canvas2DLayerBridge::disableAcceleration()
466 {
467 DCHECK(m_layer);
468 bool surfaceIsAccelerated;
469 RefPtr<SkSurface> newSurface = createSkSurface(nullptr, m_size, m_msaaSample Count, m_opacityMode, &surfaceIsAccelerated);
470 if (newSurface) {
471 DCHECK(!surfaceIsAccelerated);
472 flushRecordingOnly();
473 SkPaint copyPaint;
474 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
475 m_surface->draw(newSurface->getCanvas(), 0, 0, &copyPaint); // GPU readb ack here
476 m_accelerationMode = DisableAcceleration; // Acceleration gets permanent ly disabled
477 GraphicsLayer::unregisterContentsLayer(m_layer->layer());
478 m_layer->clearTexture();
479 m_layer->layer()->removeFromParent();
480 m_layer.reset();
481 m_surface = newSurface;
482 }
483 }
xidachen 2016/06/15 14:12:36 By looking at the test results failure, it looks l
484
465 SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint) 485 SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint)
466 { 486 {
467 if (m_surface) 487 if (m_surface) {
488 if (hint == ForceNoAcceleration && m_layer)
489 disableAcceleration();
468 return m_surface.get(); 490 return m_surface.get();
491 }
469 492
470 if (m_layer && !isHibernating() && hint == PreferAcceleration) { 493 if (m_layer && !isHibernating() && hint == PreferAcceleration) {
471 return nullptr; // re-creation will happen through restore() 494 return nullptr; // re-creation will happen through restore()
472 } 495 }
473 496
474 bool wantAcceleration = shouldAccelerate(hint); 497 bool wantAcceleration = shouldAccelerate(hint);
475 bool surfaceIsAccelerated;
476 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && wantAccelerati on) { 498 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && wantAccelerati on) {
477 wantAcceleration = false; 499 wantAcceleration = false;
478 m_softwareRenderingWhileHidden = true; 500 m_softwareRenderingWhileHidden = true;
479 } 501 }
480 502
503 bool surfaceIsAccelerated;
481 m_surface = createSkSurface(wantAcceleration ? m_contextProvider->grContext( ) : nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated); 504 m_surface = createSkSurface(wantAcceleration ? m_contextProvider->grContext( ) : nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated);
482 505
483 if (!m_surface) 506 if (!m_surface)
484 reportSurfaceCreationFailure(); 507 reportSurfaceCreationFailure();
485 508
486 if (m_surface && surfaceIsAccelerated && !m_layer) { 509 if (m_surface && surfaceIsAccelerated && !m_layer) {
487 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExter nalTextureLayer(this)); 510 m_layer = adoptPtr(Platform::current()->compositorSupport()->createExter nalTextureLayer(this));
488 m_layer->setOpaque(m_opacityMode == Opaque); 511 m_layer->setOpaque(m_opacityMode == Opaque);
489 m_layer->setBlendBackgroundColor(m_opacityMode != Opaque); 512 m_layer->setBlendBackgroundColor(m_opacityMode != Opaque);
490 GraphicsLayer::registerContentsLayer(m_layer->layer()); 513 GraphicsLayer::registerContentsLayer(m_layer->layer());
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 #endif // USE_IOSURFACE_FOR_2D_CANVAS 1017 #endif // USE_IOSURFACE_FOR_2D_CANVAS
995 } 1018 }
996 1019
997 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) 1020 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event)
998 { 1021 {
999 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib ernationEvents", HibernationEventCount)); 1022 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib ernationEvents", HibernationEventCount));
1000 hibernationHistogram.count(event); 1023 hibernationHistogram.count(event);
1001 } 1024 }
1002 1025
1003 } // namespace blink 1026 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698