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..5ded9f3bdedd1b984292b3e7960188c363f0f1d3 |
| --- /dev/null |
| +++ b/src/lazy/SkLazyCachingPixelRef.cpp |
| @@ -0,0 +1,57 @@ |
| +/* |
| + * 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" |
| + |
| +SkLazyCachingPixelRef::SkLazyCachingPixelRef(const SkImageInfo& info, |
|
scroggo
2013/12/06 14:50:33
Deleted by Hal?
|
| + SkData* data, |
| + SkBitmapFactory::DecodeProc proc) |
| + : INHERITED(info) |
| + , 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::onDecodePixels(void* pixels, size_t rowBytes) { |
| + SkASSERT(pixels); |
| + SkImageInfo info = this->info(); |
| + SkBitmapFactory::Target target = { pixels, rowBytes }; |
| + return fDecodeProc(fData->data(), fData->size(), &info, &target); |
| +} |
| + |
| +bool SkLazyCachingPixelRef::Install(SkBitmapFactory::DecodeProc proc, |
| + SkData* data, |
| + SkBitmap* destination) { |
| + SkImageInfo info; |
| + if (!proc(data->data(), data->size(), &info, NULL)) { |
| + return false; |
| + } |
| + |
| + SkAutoTUnref<SkLazyCachingPixelRef> ref( |
| + SkNEW_ARGS(SkLazyCachingPixelRef, (info, data, proc))); |
| + return ref->configure(destination) && destination->setPixelRef(ref); |
| +} |