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

Unified Diff: Source/core/platform/graphics/ImageBuffer.cpp

Issue 21858004: Refactoring Canvas2DLayerBridge to make it easier to write unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed similarity blunder Created 7 years, 4 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
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/platform/graphics/chromium/Canvas2DLayerBridge.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/platform/graphics/ImageBuffer.cpp
diff --git a/Source/core/platform/graphics/ImageBuffer.cpp b/Source/core/platform/graphics/ImageBuffer.cpp
index 86fde9637bf93805800850150773d2a31cea747d..8f25602d03fca50efbd63a44f757e9f46158e772 100644
--- a/Source/core/platform/graphics/ImageBuffer.cpp
+++ b/Source/core/platform/graphics/ImageBuffer.cpp
@@ -61,13 +61,40 @@ using namespace std;
namespace WebCore {
+namespace {
+
+class AcceleratedLayerHelper : public Canvas2DLayerBridge::Helper {
+public:
+ virtual PassRefPtr<GraphicsContext3D> getContext() OVERRIDE
+ {
+ return SharedGraphicsContext3D::get();
+ }
+
+ virtual SkSurface* createSurface(GraphicsContext3D* context3D, const IntSize& size) OVERRIDE
+ {
+ ASSERT(!context3D->webContext()->isContextLost());
+ GrContext* gr = context3D->grContext();
+ if (!gr)
+ return 0;
+ gr->resetContext();
+ SkImage::Info info;
+ info.fWidth = size.width();
+ info.fHeight = size.height();
+ info.fColorType = SkImage::kPMColor_ColorType;
+ info.fAlphaType = SkImage::kPremul_AlphaType;
+ return SkSurface::NewRenderTarget(gr, info);
+ }
+};
+
+} // unnamed namespace
+
static SkCanvas* createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLayerBridge>* outLayerBridge, OpacityMode opacityMode)
{
- RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get();
- if (!context3D)
+ OwnPtr<AcceleratedLayerHelper> helper = adoptPtr(new AcceleratedLayerHelper);
+ if (!helper->getContext())
return 0;
Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ? Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque;
- *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), size, bridgeOpacityMode);
+ *outLayerBridge = Canvas2DLayerBridge::create(helper.release(), size, bridgeOpacityMode);
// If canvas buffer allocation failed, debug build will have asserted
// For release builds, we must verify whether the device has a render target
return (*outLayerBridge) ? (*outLayerBridge)->getCanvas() : 0;
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/platform/graphics/chromium/Canvas2DLayerBridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698