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..588d86a1d5511c4ff97faa9cbbec91e3e38966f6 |
| --- /dev/null |
| +++ b/src/lazy/SkLazyCachingPixelRef.cpp |
| @@ -0,0 +1,69 @@ |
| +/* |
| + * 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(SkData* data, |
| + SkBitmapFactory::DecodeProc proc) |
| + : 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); |
| +} |
| + |
| +static inline bool operator==(const SkImageInfo& lhs, const SkImageInfo& rhs) { |
| + return 0 == memcmp(&lhs, &rhs, sizeof(SkImageInfo)); |
|
scroggo
2013/11/04 17:18:03
Is this meaningfully different from what the compi
hal.canary
2013/11/04 18:24:19
My compiler refuses to write its own comparison op
|
| +} |
| +static inline bool operator!=(const SkImageInfo& lhs, const SkImageInfo& rhs) { |
| + return !(lhs == rhs); |
|
scroggo
2013/11/04 17:18:03
Is this meaningfully different from what the compi
hal.canary
2013/11/04 18:24:19
Smae thing: my compiler refuses to write its own c
|
| +} |
| + |
| +bool SkLazyCachingPixelRef::onDecodePixels(const SkImageInfo& passedInfo, |
| + void* pixels, size_t rowBytes) { |
| + SkASSERT(pixels); |
| + SkImageInfo info; |
| + if (!this->getInfo(&info)) { |
| + return false; |
| + } |
| + if (passedInfo != info) { |
| + return false; // This implementation can not handle this case. |
| + } |
| + SkBitmapFactory::Target target = {pixels, rowBytes}; |
| + return fDecodeProc(fData->data(), fData->size(), &info, &target); |
| +} |
| + |
| +bool SkLazyCachingPixelRef::Install(SkBitmapFactory::DecodeProc proc, |
| + SkData* data, |
| + SkBitmap* destination) { |
| + SkAutoTUnref<SkLazyCachingPixelRef> ref( |
| + SkNEW_ARGS(SkLazyCachingPixelRef, (data, proc))); |
| + return ref->configure(destination) && destination->setPixelRef(ref); |
| +} |
| + |