Chromium Code Reviews| Index: src/lazy/SkLazyCachingPixelRef.cpp |
| diff --git a/src/lazy/SkLazyCachingPixelRef.cpp b/src/lazy/SkLazyCachingPixelRef.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0200c07a1981b38cc0d0559b2113dca8021434e4 |
| --- /dev/null |
| +++ b/src/lazy/SkLazyCachingPixelRef.cpp |
| @@ -0,0 +1,62 @@ |
| +/* |
| + * Copyright 2013 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "Sk64.h" |
| +#include "SkColorTable.h" |
| +#include "SkData.h" |
| +#include "SkImageDecoder.h" |
| +#include "SkImagePriv.h" |
| +#include "SkLazyCachingPixelRef.h" |
| +#include "SkPostConfig.h" |
| +#include "SkScaledImageCache.h" |
| + |
| +SkLazyCachingPixelRef::SkLazyCachingPixelRef(SkData* data, |
| + SkBitmapFactory::DecodeProc proc, |
| + SkScaledImageCache* cache) |
| + : INHERITED(cache) |
| + , fDecodeProc(proc) { |
| + if (NULL == data) { |
| + fData = SkData::NewEmpty(); |
| + } else { |
| + fData = data; |
| + fData->ref(); |
| + } |
| + if (NULL == fDecodeProc) { // use a reasonable default. |
| + fDecodeProc = SkImageDecoder::DecodeMemoryToTarget; |
| + } |
| + this->setImmutable(); |
| +} |
| + |
| +SkLazyCachingPixelRef::~SkLazyCachingPixelRef() { |
| + SkASSERT(fData != NULL); |
| + fData->unref(); |
| +} |
| + |
| +bool SkLazyCachingPixelRef::onDecodeInfo(SkImageInfo* info) { |
| + SkASSERT(info); |
| + return fDecodeProc(fData->data(), fData->size(), info, NULL); |
| +} |
| + |
| +bool SkLazyCachingPixelRef::onDecode(void* pixels, size_t rowBytes) { |
| + SkASSERT(pixels); |
| + SkImageInfo info = this->getInfo(); // local copy of info. |
|
scroggo
2013/11/01 18:27:55
Shouldn't this be const SkImageInfo& info, as it i
hal.canary
2013/11/01 18:52:59
DecodeProc takes a non-const info, so I have to co
|
| + if (info.fWidth < 0) { // getInfo() failed |
| + return false; |
| + } |
| + SkBitmapFactory::Target target = {pixels, rowBytes}; |
| + return fDecodeProc(fData->data(), fData->size(), &info, &target); |
| +} |
| + |
| +bool SkLazyCachingPixelRef::Install(SkBitmapFactory::DecodeProc proc, |
| + SkData* data, |
| + SkBitmap* destination, |
| + SkScaledImageCache* cache) { |
| + SkAutoTUnref<SkLazyCachingPixelRef> ref( |
| + SkNEW_ARGS(SkLazyCachingPixelRef, (data, proc, cache))); |
| + return ref->configure(destination) && destination->setPixelRef(ref); |
| +} |
| + |