Index: src/image/SkImage_Raster.cpp |
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp |
index ab8a635c1c9af4c0be6dc0bc2303739413226972..262fb97bfa7f3d1cac1f390a4ff7649842d9d8db 100644 |
--- a/src/image/SkImage_Raster.cpp |
+++ b/src/image/SkImage_Raster.cpp |
@@ -55,6 +55,8 @@ public: |
virtual void onDraw(SkCanvas*, SkScalar, SkScalar, const SkPaint*) SK_OVERRIDE; |
virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&, const SkPaint*) SK_OVERRIDE; |
+ virtual bool onReadPixels(SkBitmap*, const SkIRect&) const SK_OVERRIDE; |
+ virtual const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const SK_OVERRIDE; |
virtual bool getROPixels(SkBitmap*) const SK_OVERRIDE; |
// exposed for SkSurface_Raster via SkNewImageFromPixelRef |
@@ -82,13 +84,20 @@ SkImage* SkImage_Raster::NewEmpty() { |
return gEmpty; |
} |
+static void release_data(void* addr, void* context) { |
+ SkData* data = static_cast<SkData*>(context); |
+ data->unref(); |
+} |
+ |
SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes) |
- : INHERITED(info.fWidth, info.fHeight) { |
- fBitmap.setConfig(info, rowBytes); |
- SkAutoTUnref<SkPixelRef> ref( |
- SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data, 0)); |
- fBitmap.setPixelRef(ref); |
+ : INHERITED(info.fWidth, info.fHeight) |
+{ |
+ data->ref(); |
+ void* addr = const_cast<void*>(data->data()); |
+ |
+ fBitmap.installPixels(info, addr, rowBytes, release_data, data); |
fBitmap.setImmutable(); |
+ fBitmap.lockPixels(); |
} |
SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes) |
@@ -96,6 +105,7 @@ SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes |
{ |
fBitmap.setConfig(info, rowBytes); |
fBitmap.setPixelRef(pr); |
+ fBitmap.lockPixels(); |
} |
SkImage_Raster::~SkImage_Raster() {} |
@@ -104,10 +114,34 @@ void SkImage_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPa |
canvas->drawBitmap(fBitmap, x, y, paint); |
} |
-void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, const SkRect& dst, const SkPaint* paint) { |
+void SkImage_Raster::onDrawRectToRect(SkCanvas* canvas, const SkRect* src, |
+ const SkRect& dst, const SkPaint* paint) { |
canvas->drawBitmapRectToRect(fBitmap, src, dst, paint); |
} |
+bool SkImage_Raster::onReadPixels(SkBitmap* dst, const SkIRect& subset) const { |
+ if (dst->pixelRef()) { |
+ return this->INHERITED::onReadPixels(dst, subset); |
+ } else { |
+ SkBitmap src; |
+ if (!fBitmap.extractSubset(&src, subset)) { |
+ return false; |
+ } |
+ return src.copyTo(dst, src.config()); |
+ } |
+} |
+ |
+const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, |
+ size_t* rowBytesPtr) const { |
+ SkImageInfo info; |
+ if (!fBitmap.asImageInfo(&info) || !fBitmap.getPixels()) { |
+ return false; |
+ } |
+ *infoPtr = info; |
+ *rowBytesPtr = fBitmap.rowBytes(); |
+ return fBitmap.getPixels(); |
+} |
+ |
bool SkImage_Raster::getROPixels(SkBitmap* dst) const { |
*dst = fBitmap; |
return true; |