 Chromium Code Reviews
 Chromium Code Reviews Issue 19705006:
  Use SkImage as a backing store for copying 2d Contexts to ImageBitmaps. 
  Base URL: svn://svn.chromium.org/blink/trunk
    
  
    Issue 19705006:
  Use SkImage as a backing store for copying 2d Contexts to ImageBitmaps. 
  Base URL: svn://svn.chromium.org/blink/trunk| Index: Source/core/platform/graphics/ImageBuffer.cpp | 
| diff --git a/Source/core/platform/graphics/ImageBuffer.cpp b/Source/core/platform/graphics/ImageBuffer.cpp | 
| index 48f2f54951c38fc7cdced7bee47c1be5477d7df3..9200a92b78e91ef91d40ce836375d467f0551aae 100644 | 
| --- a/Source/core/platform/graphics/ImageBuffer.cpp | 
| +++ b/Source/core/platform/graphics/ImageBuffer.cpp | 
| @@ -40,6 +40,7 @@ | 
| #include "core/platform/graphics/GraphicsContext.h" | 
| #include "core/platform/graphics/GraphicsContext3D.h" | 
| #include "core/platform/graphics/IntRect.h" | 
| +#include "core/platform/graphics/ReadOnlyBitmapImage.h" | 
| #include "core/platform/graphics/chromium/Canvas2DLayerBridge.h" | 
| #include "core/platform/graphics/gpu/SharedGraphicsContext3D.h" | 
| #include "core/platform/graphics/skia/NativeImageSkia.h" | 
| @@ -61,23 +62,35 @@ using namespace std; | 
| namespace WebCore { | 
| -static SkCanvas* createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLayerBridge>* outLayerBridge, OpacityMode opacityMode) | 
| +void ImageBuffer::createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLayerBridge>* outLayerBridge, OpacityMode opacityMode) | 
| 
Justin Novosad
2013/08/19 20:12:43
This clashes with a refactoring I have in flight.
 
Stephen White
2013/08/19 20:21:21
If you don't need the SkCanvas* return value anymo
 
danakj
2013/08/19 20:22:33
SkCanvas is refcounted. Should it not go in a RefP
 | 
| { | 
| RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); | 
| if (!context3D) | 
| - return 0; | 
| + return; | 
| Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ? Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; | 
| *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), size, bridgeOpacityMode); | 
| + | 
| + // FIXME: refactor Canvas2DLayerBridge so that SkSurface is accessible. | 
| + SkSurface* surface = 0; | 
| + m_surface = adoptPtr(surface); | 
| + | 
| // 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; | 
| + SkCanvas* canvas = (*outLayerBridge) ? (*outLayerBridge)->getCanvas() : 0; | 
| + m_canvas = adoptPtr(canvas); | 
| } | 
| -static SkCanvas* createNonPlatformCanvas(const IntSize& size) | 
| +void ImageBuffer::createNonPlatformCanvas(const IntSize& size) | 
| { | 
| - SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, size.width(), size.height())); | 
| - SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef(); | 
| - return pixelRef ? new SkCanvas(device) : 0; | 
| + SkImage::Info info; | 
| + info.fWidth = size.width(); | 
| + info.fHeight = size.height(); | 
| + info.fColorType = SkImage::kRGBA_8888_ColorType; | 
| + info.fAlphaType = SkImage::kPremul_AlphaType; | 
| + m_surface = adoptPtr(SkSurface::NewRaster(info)); | 
| + if (!m_surface) | 
| + return; | 
| + m_canvas = adoptPtr(m_surface->getCanvas()); | 
| } | 
| PassOwnPtr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const IntSize& size, float resolutionScale, const GraphicsContext* context, bool hasAlpha) | 
| @@ -125,13 +138,13 @@ ImageBuffer::ImageBuffer(const IntSize& size, float resolutionScale, RenderingMo | 
| , m_resolutionScale(resolutionScale) | 
| { | 
| if (renderingMode == Accelerated) { | 
| - m_canvas = adoptPtr(createAcceleratedCanvas(size, &m_layerBridge, opacityMode)); | 
| + createAcceleratedCanvas(size, &m_layerBridge, opacityMode); | 
| if (!m_canvas) | 
| renderingMode = UnacceleratedNonPlatformBuffer; | 
| } | 
| if (renderingMode == UnacceleratedNonPlatformBuffer) | 
| - m_canvas = adoptPtr(createNonPlatformCanvas(size)); | 
| + createNonPlatformCanvas(size); | 
| if (!m_canvas) | 
| m_canvas = adoptPtr(skia::TryCreateBitmapCanvas(size.width(), size.height(), false)); | 
| @@ -188,6 +201,22 @@ static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap) | 
| return tmp; | 
| } | 
| +PassRefPtr<Image> ImageBuffer::imageSnapshot() const | 
| +{ | 
| + // A canvas without a surface indicates that a platform buffer is being used. imageSnapshot() on a platform | 
| + // buffer is not supported. | 
| + ASSERT(!m_canvas); | 
| + | 
| + if (!isValid()) | 
| + return BitmapImage::create(NativeImageSkia::create()); | 
| + | 
| + // FIXME: Case where canvas is acclerated. This should be removed once ImageBuffer holds a ref to the SkSurface. | 
| + if (!m_surface) | 
| + return copyImage(CopyBackingStore); | 
| + | 
| + return ReadOnlyBitmapImage::create(m_surface->newImageSnapshot()); | 
| +} | 
| + | 
| PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, ScaleBehavior) const | 
| { | 
| if (!isValid()) |