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

Unified Diff: src/lazy/SkLazyPixelRef.cpp

Issue 23591030: start to remove lockPixels from bitmapshader (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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/lazy/SkLazyPixelRef.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/lazy/SkLazyPixelRef.cpp
diff --git a/src/lazy/SkLazyPixelRef.cpp b/src/lazy/SkLazyPixelRef.cpp
index dc9aef9f062dbdbbe8935795e4c820c050d44291..870056091f13c1d045ebed092045298187aabdf6 100644
--- a/src/lazy/SkLazyPixelRef.cpp
+++ b/src/lazy/SkLazyPixelRef.cpp
@@ -145,3 +145,56 @@ SkData* SkLazyPixelRef::onRefEncodedData() {
fData->ref();
return fData;
}
+
+#include "SkImagePriv.h"
+
+static bool init_from_info(SkBitmap* bm, const SkImage::Info& info,
+ size_t rowBytes) {
+ bool isOpaque;
+ SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
+ if (SkBitmap::kNo_Config == config) {
+ return false;
+ }
+
+ bm->setConfig(config, info.fWidth, info.fHeight, rowBytes);
+ bm->setIsOpaque(isOpaque);
+ return bm->allocPixels();
+}
+
+bool SkLazyPixelRef::onImplementsDecodeInto() {
+ return true;
+}
+
+bool SkLazyPixelRef::onDecodeInto(int pow2, SkBitmap* bitmap) {
+ SkASSERT(fData != NULL && fData->size() > 0);
+ if (fErrorInDecoding) {
+ return false;
+ }
+
+ SkImage::Info info;
+ // Determine the size of the image in order to determine how much memory to allocate.
+ // FIXME: As an optimization, only do this part once.
+ fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, NULL);
+ if (fErrorInDecoding) {
+ return false;
+ }
+
+ SkBitmapFactory::Target target;
+ (void)ComputeMinRowBytesAndSize(info, &target.fRowBytes);
+
+ SkBitmap tmp;
+ if (!init_from_info(&tmp, info, target.fRowBytes)) {
+ return false;
+ }
+
+ target.fAddr = tmp.getPixels();
+ fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, &target);
+ if (fErrorInDecoding) {
+ return false;
+ }
+
+ *bitmap = tmp;
+ return true;
+}
+
+
« no previous file with comments | « src/lazy/SkLazyPixelRef.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698