diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkBitmapDevice.cpp | 14 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 49 | ||||
-rw-r--r-- | src/core/SkDevice.cpp | 8 | ||||
-rw-r--r-- | src/core/SkPictureRecord.h | 3 | ||||
-rw-r--r-- | src/image/SkImagePriv.h | 2 | ||||
-rw-r--r-- | src/image/SkSurface.cpp | 5 |
6 files changed, 79 insertions, 2 deletions
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 9dde6e172e..374bef98c1 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -54,6 +54,10 @@ SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b SkBitmapDevice::~SkBitmapDevice() { } +SkImageInfo SkBitmapDevice::imageInfo() const { + return fBitmap.info(); +} + void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { SkASSERT(bm.width() == fBitmap.width()); SkASSERT(bm.height() == fBitmap.height()); @@ -386,6 +390,16 @@ SkSurface* SkBitmapDevice::newSurface(const SkImageInfo& info) { return SkSurface::NewRaster(info); } +const void* SkBitmapDevice::peekPixels(SkImageInfo* info, size_t* rowBytes) { + if (fBitmap.getPixels() && fBitmap.asImageInfo(info)) { + if (rowBytes) { + *rowBytes = fBitmap.rowBytes(); + } + return fBitmap.getPixels(); + } + return NULL; +} + /////////////////////////////////////////////////////////////////////////////// bool SkBitmapDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index ed8274dc5d..f5e91ffc43 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -992,6 +992,55 @@ SkSurface* SkCanvas::onNewSurface(const SkImageInfo& info) { return dev ? dev->newSurface(info) : NULL; } +SkImageInfo SkCanvas::imageInfo() const { + SkBaseDevice* dev = this->getDevice(); + if (dev) { + return dev->imageInfo(); + } else { + // TODO: need a real unknown for alphatype it seems. + SkAlphaType unknownAlphaType = kIgnore_SkAlphaType; + return SkImageInfo::Make(0, 0, kUnknown_SkColorType, unknownAlphaType); + } +} + +const void* SkCanvas::peekPixels(SkImageInfo* info, size_t* rowBytes) { + return this->onPeekPixels(info, rowBytes); +} + +const void* SkCanvas::onPeekPixels(SkImageInfo* info, size_t* rowBytes) { + SkBaseDevice* dev = this->getDevice(); + return dev ? dev->peekPixels(info, rowBytes) : NULL; +} + +SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) { + fAddr = canvas->peekPixels(&fInfo, &fRowBytes); + if (NULL == fAddr) { + fInfo = canvas->imageInfo(); + if (kUnknown_SkColorType == fInfo.colorType() || + !fBitmap.allocPixels(fInfo)) + { + return; // failure, fAddr is NULL + } + fBitmap.lockPixels(); + if (!canvas->readPixels(&fBitmap, 0, 0)) { + return; // failure, fAddr is NULL + } + fAddr = fBitmap.getPixels(); + fRowBytes = fBitmap.rowBytes(); + } + SkASSERT(fAddr); // success +} + +bool SkAutoROCanvasPixels::asROBitmap(SkBitmap* bitmap) const { + if (fAddr) { + return bitmap->installPixels(fInfo, const_cast<void*>(fAddr), fRowBytes, + NULL, NULL); + } else { + bitmap->reset(); + return false; + } +} + ///////////////////////////////////////////////////////////////////////////// void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap, diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 9ce8b6b5df..364b106dd8 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -65,6 +65,12 @@ SkMetaData& SkBaseDevice::getMetaData() { return *fMetaData; } +// TODO: should make this guy pure-virtual. +SkImageInfo SkBaseDevice::imageInfo() const { + return SkImageInfo::Make(this->width(), this->height(), + kUnknown_SkColorType, kIgnore_SkAlphaType); +} + const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) { const SkBitmap& bitmap = this->onAccessBitmap(); if (changePixels) { @@ -117,3 +123,5 @@ bool SkBaseDevice::readPixels(SkBitmap* bitmap, int x, int y, } SkSurface* SkBaseDevice::newSurface(const SkImageInfo&) { return NULL; } + +const void* SkBaseDevice::peekPixels(SkImageInfo*, size_t*) { return NULL; } diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index 0df120b31a..eaa5e73008 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -221,6 +221,9 @@ public: protected: virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; + const void* onPeekPixels(SkImageInfo*, size_t*) SK_OVERRIDE { + return NULL; + } // Return fontmetrics.fTop,fBottom in topbot[0,1], after they have been // tweaked by paint.computeFastBounds(). diff --git a/src/image/SkImagePriv.h b/src/image/SkImagePriv.h index 8883e2c070..bf28f598c5 100644 --- a/src/image/SkImagePriv.h +++ b/src/image/SkImagePriv.h @@ -14,8 +14,6 @@ class SkPicture; extern SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo&); -extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType); -extern SkColorType SkBitmapConfigToColorType(SkBitmap::Config); // Call this if you explicitly want to use/share this pixelRef in the image extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*, diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index cb029c8aea..4b5fb68134 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -121,3 +121,8 @@ void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) { return asSB(this)->onDraw(canvas, x, y, paint); } + +const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) { + return this->getCanvas()->peekPixels(info, rowBytes); +} + |