start to remove lockPixels from bitmapshader
BUG=
R=scroggo@google.com
Review URL: https://codereview.chromium.org/23591030
git-svn-id: http://skia.googlecode.com/svn/trunk@11258 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/lazy/SkLazyPixelRef.cpp b/src/lazy/SkLazyPixelRef.cpp
index dc9aef9..8700560 100644
--- a/src/lazy/SkLazyPixelRef.cpp
+++ b/src/lazy/SkLazyPixelRef.cpp
@@ -145,3 +145,56 @@
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;
+}
+
+