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

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

Issue 19705006: Use SkImage as a backing store for copying 2d Contexts to ImageBitmaps. Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Change SkImage to use srcRect pointer. Created 7 years, 5 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: Source/core/platform/graphics/ImageBuffer.cpp
diff --git a/Source/core/platform/graphics/ImageBuffer.cpp b/Source/core/platform/graphics/ImageBuffer.cpp
index d130b56eeb7ca153613677805429016c17297ccb..566cc735b2a9f0f984bd7e9d3bf2eb6f1260060e 100644
--- a/Source/core/platform/graphics/ImageBuffer.cpp
+++ b/Source/core/platform/graphics/ImageBuffer.cpp
@@ -41,6 +41,7 @@
#include "core/platform/graphics/GraphicsContext.h"
#include "core/platform/graphics/GraphicsContext3D.h"
#include "core/platform/graphics/IntRect.h"
+#include "core/platform/graphics/SkiaImage.h"
#include "core/platform/graphics/chromium/Canvas2DLayerBridge.h"
#include "core/platform/graphics/gpu/SharedGraphicsContext3D.h"
#include "core/platform/graphics/skia/MemoryInstrumentationSkia.h"
@@ -63,7 +64,7 @@ using namespace std;
namespace WebCore {
-static SkCanvas* createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLayerBridge>* outLayerBridge, OpacityMode opacityMode)
+SkCanvas* ImageBuffer::createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLayerBridge>* outLayerBridge, OpacityMode opacityMode)
{
RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get();
if (!context3D)
@@ -78,21 +79,28 @@ static SkCanvas* createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLay
info.fHeight = size.height();
info.fColorType = SkImage::kPMColor_ColorType;
info.fAlphaType = SkImage::kPremul_AlphaType;
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context3D->grContext(), info));
- if (!surface.get())
+ m_surface = SkSurface::NewRenderTarget(context3D->grContext(), info);
Justin Novosad 2013/07/22 15:35:41 You will need adoptPtr here, once m_surface is an
+ if (!m_surface.get())
return 0;
- SkDeferredCanvas* canvas = new SkDeferredCanvas(surface.get());
+ SkDeferredCanvas* canvas = new SkDeferredCanvas(m_surface.get());
*outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), canvas, 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 canvas;
Justin Novosad 2013/07/22 15:35:41 Now that createAcceleratedCanvas is a member of Im
}
-static SkCanvas* createNonPlatformCanvas(const IntSize& size)
+SkCanvas* 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::kPMColor_ColorType;
+ info.fAlphaType = SkImage::kPremul_AlphaType;
+ m_surface = SkSurface::NewRaster(info);
+ if (!m_surface.get())
+ return 0;
+ SkCanvas* canvas = m_surface->getCanvas();
+ return canvas;
}
PassOwnPtr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const IntSize& size, float resolutionScale, const GraphicsContext* context, bool hasAlpha)
@@ -195,6 +203,13 @@ static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap)
return tmp;
}
+PassRefPtr<Image> ImageBuffer::imageSnapshot() const
+{
+ if (!m_surface.get())
Justin Novosad 2013/07/22 15:35:41 Inside this 'if' you add ASSERT(!m_canvas) With th
+ return 0;
+ return SkiaImage::create(m_surface->newImageSnapshot());
+}
+
PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy copyBehavior, ScaleBehavior) const
{
const SkBitmap& bitmap = *context()->bitmap();

Powered by Google App Engine
This is Rietveld 408576698