aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBitmapDevice.cpp34
-rw-r--r--src/core/SkCanvas.cpp35
-rw-r--r--src/core/SkDevice.cpp36
-rw-r--r--src/core/SkPictureRecord.h4
-rw-r--r--src/core/SkPixmap.cpp17
5 files changed, 73 insertions, 53 deletions
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 995b427697..3e586e6630 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -9,6 +9,7 @@
#include "SkConfig8888.h"
#include "SkDeviceProperties.h"
#include "SkDraw.h"
+#include "SkPixelRef.h"
#include "SkRasterClip.h"
#include "SkShader.h"
#include "SkSurface.h"
@@ -124,17 +125,20 @@ const SkBitmap& SkBitmapDevice::onAccessBitmap() {
return fBitmap;
}
-void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) {
- if (fBitmap.getPixels()) {
- *info = fBitmap.info();
- *rowBytes = fBitmap.rowBytes();
- return fBitmap.getPixels();
+bool SkBitmapDevice::onAccessPixels(SkPixmap* pmap) {
+ const SkImageInfo info = fBitmap.info();
+ if (fBitmap.getPixels() && (kUnknown_SkColorType != info.colorType())) {
+ SkColorTable* ctable = NULL;
+ pmap->reset(fBitmap.info(), fBitmap.getPixels(), fBitmap.rowBytes(), ctable);
+ return true;
}
- return NULL;
+ return false;
}
-#include "SkConfig8888.h"
-#include "SkPixelRef.h"
+bool SkBitmapDevice::onPeekPixels(SkPixmap* pmap) {
+ // peek and access are the exact same logic for us
+ return this->onAccessPixels(pmap);
+}
bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels,
size_t srcRowBytes, int x, int y) {
@@ -356,20 +360,6 @@ SkSurface* SkBitmapDevice::newSurface(const SkImageInfo& info, const SkSurfacePr
return SkSurface::NewRaster(info, &props);
}
-const void* SkBitmapDevice::peekPixels(SkImageInfo* info, size_t* rowBytes) {
- const SkImageInfo bmInfo = fBitmap.info();
- if (fBitmap.getPixels() && (kUnknown_SkColorType != bmInfo.colorType())) {
- if (info) {
- *info = bmInfo;
- }
- if (rowBytes) {
- *rowBytes = fBitmap.rowBytes();
- }
- return fBitmap.getPixels();
- }
- return NULL;
-}
-
SkImageFilter::Cache* SkBitmapDevice::getImageFilterCache() {
SkImageFilter::Cache* cache = SkImageFilter::Cache::Get();
cache->ref();
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index aa25ca0b41..bf4e86cafa 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1133,25 +1133,44 @@ SkImageInfo SkCanvas::imageInfo() const {
}
const void* SkCanvas::peekPixels(SkImageInfo* info, size_t* rowBytes) {
- return this->onPeekPixels(info, rowBytes);
+ SkPixmap pmap;
+ if (!this->onPeekPixels(&pmap)) {
+ return NULL;
+ }
+ if (info) {
+ *info = pmap.info();
+ }
+ if (rowBytes) {
+ *rowBytes = pmap.rowBytes();
+ }
+ return pmap.addr();
}
-const void* SkCanvas::onPeekPixels(SkImageInfo* info, size_t* rowBytes) {
+bool SkCanvas::onPeekPixels(SkPixmap* pmap) {
SkBaseDevice* dev = this->getDevice();
- return dev ? dev->peekPixels(info, rowBytes) : NULL;
+ return dev && dev->peekPixels(pmap);
}
void* SkCanvas::accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin) {
- void* pixels = this->onAccessTopLayerPixels(info, rowBytes);
- if (pixels && origin) {
+ SkPixmap pmap;
+ if (!this->onAccessTopLayerPixels(&pmap)) {
+ return NULL;
+ }
+ if (info) {
+ *info = pmap.info();
+ }
+ if (rowBytes) {
+ *rowBytes = pmap.rowBytes();
+ }
+ if (origin) {
*origin = this->getTopDevice(false)->getOrigin();
}
- return pixels;
+ return pmap.writable_addr();
}
-void* SkCanvas::onAccessTopLayerPixels(SkImageInfo* info, size_t* rowBytes) {
+bool SkCanvas::onAccessTopLayerPixels(SkPixmap* pmap) {
SkBaseDevice* dev = this->getTopDevice();
- return dev ? dev->accessPixels(info, rowBytes) : NULL;
+ return dev && dev->accessPixels(pmap);
}
SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) {
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 37fafd8dfb..14784a25d6 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -91,10 +91,6 @@ void SkBaseDevice::initForRootLayer(SkPixelGeometry geo) {
geo));
}
-SkSurface* SkBaseDevice::newSurface(const SkImageInfo&, const SkSurfaceProps&) { return NULL; }
-
-const void* SkBaseDevice::peekPixels(SkImageInfo*, size_t*) { return NULL; }
-
void SkBaseDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
const SkRRect& inner, const SkPaint& paint) {
SkPath path;
@@ -221,28 +217,28 @@ bool SkBaseDevice::onReadPixels(const SkImageInfo&, void*, size_t, int x, int y)
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;
-}
-
bool SkBaseDevice::EXPERIMENTAL_drawPicture(SkCanvas*, const SkPicture*, const SkMatrix*,
const SkPaint*) {
// The base class doesn't perform any accelerated picture rendering
return false;
}
+bool SkBaseDevice::accessPixels(SkPixmap* pmap) {
+ SkPixmap tempStorage;
+ if (NULL == pmap) {
+ pmap = &tempStorage;
+ }
+ return this->onAccessPixels(pmap);
+}
+
+bool SkBaseDevice::peekPixels(SkPixmap* pmap) {
+ SkPixmap tempStorage;
+ if (NULL == pmap) {
+ pmap = &tempStorage;
+ }
+ return this->onPeekPixels(pmap);
+}
+
//////////////////////////////////////////////////////////////////////////////////////////
static void morphpoints(SkPoint dst[], const SkPoint src[], int count,
diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h
index 7a6fc813a5..af65013b55 100644
--- a/src/core/SkPictureRecord.h
+++ b/src/core/SkPictureRecord.h
@@ -147,9 +147,7 @@ protected:
}
SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
- const void* onPeekPixels(SkImageInfo*, size_t*) override {
- return NULL;
- }
+ bool onPeekPixels(SkPixmap*) override { return false; }
void willSave() override;
SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) override;
diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp
index 7c08fb96bd..3a0fad2a39 100644
--- a/src/core/SkPixmap.cpp
+++ b/src/core/SkPixmap.cpp
@@ -20,6 +20,23 @@ void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void*
/////////////////////////////////////////////////////////////////////////////////////////////////
+void SkPixmap::reset() {
+ fPixels = NULL;
+ fCTable = NULL;
+ fRowBytes = 0;
+ fInfo = SkImageInfo::MakeUnknown();
+}
+
+void SkPixmap::reset(const SkImageInfo& info, const void* addr, size_t rowBytes, SkColorTable* ct) {
+ if (addr) {
+ SkASSERT(info.validRowBytes(rowBytes));
+ }
+ fPixels = addr;
+ fCTable = ct;
+ fRowBytes = rowBytes;
+ fInfo = info;
+}
+
bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels, size_t dstRB,
int x, int y) const {
if (kUnknown_SkColorType == requestedDstInfo.colorType()) {