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