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

Unified Diff: src/core/SkCanvas.cpp

Issue 163603003: add peekPixels to SkCanvas and SkSurface (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
« no previous file with comments | « src/core/SkBitmapDevice.cpp ('k') | src/core/SkDevice.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkCanvas.cpp
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index ed8274dc5d3b4a9bf09d6241541620b1a11f9a4f..f5e91ffc43fa1b943f6ca62a59bdc2529c3cec21 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,
« no previous file with comments | « src/core/SkBitmapDevice.cpp ('k') | src/core/SkDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698