OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "Sk64.h" |
| 9 #include "SkColorTable.h" |
| 10 #include "SkData.h" |
| 11 #include "SkImageDecoder.h" |
| 12 #include "SkImagePriv.h" |
| 13 #include "SkLazyCachingPixelRef.h" |
| 14 #include "SkPostConfig.h" |
| 15 #include "SkScaledImageCache.h" |
| 16 |
| 17 SkLazyCachingPixelRef::SkLazyCachingPixelRef(SkData* data, |
| 18 SkBitmapFactory::DecodeProc proc, |
| 19 SkScaledImageCache* cache) |
| 20 : INHERITED(cache) |
| 21 , fDecodeProc(proc) { |
| 22 if (NULL == data) { |
| 23 fData = SkData::NewEmpty(); |
| 24 } else { |
| 25 fData = data; |
| 26 fData->ref(); |
| 27 } |
| 28 if (NULL == fDecodeProc) { // use a reasonable default. |
| 29 fDecodeProc = SkImageDecoder::DecodeMemoryToTarget; |
| 30 } |
| 31 this->setImmutable(); |
| 32 } |
| 33 |
| 34 SkLazyCachingPixelRef::~SkLazyCachingPixelRef() { |
| 35 SkASSERT(fData != NULL); |
| 36 fData->unref(); |
| 37 } |
| 38 |
| 39 bool SkLazyCachingPixelRef::onDecodeInfo(SkImageInfo* info) { |
| 40 SkASSERT(info); |
| 41 return fDecodeProc(fData->data(), fData->size(), info, NULL); |
| 42 } |
| 43 |
| 44 bool SkLazyCachingPixelRef::onDecode(void* pixels, size_t rowBytes) { |
| 45 SkASSERT(pixels); |
| 46 const SkImageInfo* infoPtr = this->getInfo(); |
| 47 if (NULL == infoPtr) { // getInfo() failed |
| 48 return false; |
| 49 } |
| 50 SkImageInfo info = *infoPtr; // local copy of info. |
| 51 SkBitmapFactory::Target target = {pixels, rowBytes}; |
| 52 return fDecodeProc(fData->data(), fData->size(), &info, &target); |
| 53 } |
| 54 |
| 55 bool SkLazyCachingPixelRef::Install(SkBitmapFactory::DecodeProc proc, |
| 56 SkData* data, |
| 57 SkBitmap* destination, |
| 58 SkScaledImageCache* cache) { |
| 59 SkAutoTUnref<SkLazyCachingPixelRef> ref( |
| 60 SkNEW_ARGS(SkLazyCachingPixelRef, (data, proc, cache))); |
| 61 return ref->configure(destination) && destination->setPixelRef(ref); |
| 62 } |
| 63 |
OLD | NEW |