Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(687)

Unified Diff: src/core/SkCanvas.cpp

Issue 159723006: add peekPixels to canvas (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,

Powered by Google App Engine
This is Rietveld 408576698