Index: src/core/SkCanvas.cpp |
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp |
index ed8274dc5d3b4a9bf09d6241541620b1a11f9a4f..47cf4ec8e18f3d3bfbbba37d32ce340ebade599b 100644 |
--- a/src/core/SkCanvas.cpp |
+++ b/src/core/SkCanvas.cpp |
@@ -992,6 +992,51 @@ 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) { |
+#if 1 |
+ fAddr = canvas->peekPixels(&fInfo, &fRowBytes); |
+ if (NULL == fAddr) { |
+ fInfo = canvas->imageInfo(); |
+ if (!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 |
+#else |
+ const SkBitmap& bm = canvas->getDevice()->accessBitmap(false); |
scroggo
2014/02/12 18:40:58
Is this just here for comparison?
reed2
2014/02/13 14:43:35
Just for local testing, will remove.
|
+ bm.lockPixels(); |
+ fAddr = bm.getPixels(); |
+ fInfo = bm.info(); |
+ fRowBytes = bm.rowBytes(); |
+#endif |
+} |
+ |
///////////////////////////////////////////////////////////////////////////// |
void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap, |