diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-09-13 16:04:49 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-09-13 16:04:49 +0000 |
commit | cee9dcb8377e1f85a7a232822a894464ea6ccddc (patch) | |
tree | 7471eebad4be65ad6d3c8ca7e8d6ebbdc03a36fa /src/lazy | |
parent | f4dc60457b0fd77f75483767a0e3e346ab5b2795 (diff) |
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
Diffstat (limited to 'src/lazy')
-rw-r--r-- | src/lazy/SkLazyPixelRef.cpp | 53 | ||||
-rw-r--r-- | src/lazy/SkLazyPixelRef.h | 2 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/lazy/SkLazyPixelRef.cpp b/src/lazy/SkLazyPixelRef.cpp index dc9aef9f06..870056091f 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; +} + + diff --git a/src/lazy/SkLazyPixelRef.h b/src/lazy/SkLazyPixelRef.h index fd41dd4682..c51675dd5f 100644 --- a/src/lazy/SkLazyPixelRef.h +++ b/src/lazy/SkLazyPixelRef.h @@ -61,6 +61,8 @@ protected: virtual void onUnlockPixels() SK_OVERRIDE; virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } virtual SkData* onRefEncodedData() SK_OVERRIDE; + virtual bool onImplementsDecodeInto() SK_OVERRIDE; + virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; private: bool fErrorInDecoding; |