From 9c135db83d198e7d8200027c7d2cf60f38517ee3 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Wed, 12 Mar 2014 18:28:35 +0000 Subject: support direct writing to top layer, and hide getTopLayer() this should remove many of the chrome callers that today call accessBitmap on the toplayer, so they can read/write those pixels. The ultimate fix will be to support custom allocation of raster layers (via GDI/cairo/mac) so we can remove PlatformDevice subclassing in skia/ext BUG=skia: R=bsalomon@google.com, scroggo@google.com Review URL: https://codereview.chromium.org/197433002 git-svn-id: http://skia.googlecode.com/svn/trunk@13774 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkBitmapDevice.cpp | 9 +++++++++ src/core/SkCanvas.cpp | 14 ++++++++++++++ src/core/SkDevice.cpp | 16 ++++++++++++++++ 3 files changed, 39 insertions(+) (limited to 'src/core') diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 098f0fc96c..8524f0b72b 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -268,6 +268,15 @@ void SkBitmapDevice::writePixels(const SkBitmap& bitmap, } #endif +void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { + if (fBitmap.getPixels()) { + *info = fBitmap.info(); + *rowBytes = fBitmap.rowBytes(); + return fBitmap.getPixels(); + } + return NULL; +} + static void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB, size_t bytesPerRow, int rowCount) { SkASSERT(bytesPerRow <= srcRB); diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 9fbb37bf31..4086291507 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1040,6 +1040,15 @@ const void* SkCanvas::onPeekPixels(SkImageInfo* info, size_t* rowBytes) { return dev ? dev->peekPixels(info, rowBytes) : NULL; } +void* SkCanvas::accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes) { + return this->onAccessTopLayerPixels(info, rowBytes); +} + +void* SkCanvas::onAccessTopLayerPixels(SkImageInfo* info, size_t* rowBytes) { + SkBaseDevice* dev = this->getTopDevice(); + return dev ? dev->accessPixels(info, rowBytes) : NULL; +} + SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) { fAddr = canvas->peekPixels(&fInfo, &fRowBytes); if (NULL == fAddr) { @@ -1713,6 +1722,11 @@ void SkCanvas::internal_private_getTotalClipAsPath(SkPath* path) const { (void)rgn.getBoundaryPath(path); } +GrRenderTarget* SkCanvas::internal_private_accessTopLayerRenderTarget() { + SkBaseDevice* dev = this->getTopDevice(); + return dev ? dev->accessRenderTarget() : NULL; +} + SkBaseDevice* SkCanvas::createLayerDevice(const SkImageInfo& info) { SkBaseDevice* device = this->getTopDevice(); return device ? device->createCompatibleDeviceForSaveLayer(info) : NULL; diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 666e456e8c..587181302d 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -194,6 +194,22 @@ bool SkBaseDevice::onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8 return false; } +void* SkBaseDevice::accessPixels(SkImageInfo* info, size_t* rowBytes) { + SkImageInfo tmpInfo; + size_t tmpRowBytes; + if (NULL == info) { + info = &tmpInfo; + } + if (NULL == rowBytes) { + rowBytes = &tmpRowBytes; + } + return this->onAccessPixels(info, rowBytes); +} + +void* SkBaseDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { + return NULL; +} + #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG void SkBaseDevice::writePixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) {} #endif -- cgit v1.2.3