| Index: src/lazy/SkLazyCachingPixelRef.cpp
|
| diff --git a/src/lazy/SkLazyCachingPixelRef.cpp b/src/lazy/SkLazyCachingPixelRef.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..91b5bd345ffdde36ad49204cf93f291c1c473d28
|
| --- /dev/null
|
| +++ b/src/lazy/SkLazyCachingPixelRef.cpp
|
| @@ -0,0 +1,80 @@
|
| +/*
|
| + * 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 "SkScaledImageCache.h"
|
| +#include "SkPostConfig.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();
|
| + }
|
| + memset(&fLazilyCachedInfo, 0xFF, sizeof(fLazilyCachedInfo));
|
| +
|
| + if (NULL == fDecodeProc) { // use a reasonable default.
|
| + fDecodeProc = SkImageDecoder::DecodeMemoryToTarget;
|
| + }
|
| + this->setImmutable();
|
| +}
|
| +
|
| +SkLazyCachingPixelRef::~SkLazyCachingPixelRef() {
|
| + SkASSERT(fData != NULL);
|
| + fData->unref();
|
| +}
|
| +
|
| +bool SkLazyCachingPixelRef::onDecodeInfo(SkISize* size,
|
| + SkBitmap::Config* config,
|
| + SkAlphaType* alphaType) {
|
| + SkASSERT(size && config &&alphaType);
|
| + if (fLazilyCachedInfo.fWidth < 0) {
|
| + SkImage::Info info;
|
| + if (!fDecodeProc(fData->data(), fData->size(), &info, NULL)) {
|
| + return false;
|
| + }
|
| + fLazilyCachedInfo = info;
|
| + }
|
| + size->set(fLazilyCachedInfo.fWidth, fLazilyCachedInfo.fHeight);
|
| + *config = SkImageInfoToBitmapConfig(fLazilyCachedInfo);
|
| + *alphaType = fLazilyCachedInfo.fAlphaType;
|
| + return true;
|
| +}
|
| +
|
| +bool SkLazyCachingPixelRef::onDecode(void* pixels, size_t rowBytes) {
|
| + SkASSERT(pixels);
|
| + if (fLazilyCachedInfo.fWidth <= 0) {
|
| + SkISize size;
|
| + SkBitmap::Config config;
|
| + SkAlphaType alphaType;
|
| + // The side effect of this is to set fLazilyCachedInfo
|
| + this->onDecodeInfo(&size, &config, &alphaType);
|
| + }
|
| + SkBitmapFactory::Target target = {pixels, rowBytes};
|
| + return fDecodeProc(fData->data(), fData->size(),
|
| + &fLazilyCachedInfo, &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);
|
| +}
|
| +
|
|
|