Chromium Code Reviews| 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 SkImageInfo info = this->getInfo(); // local copy of info. | |
|
scroggo
2013/11/01 18:27:55
Shouldn't this be const SkImageInfo& info, as it i
hal.canary
2013/11/01 18:52:59
DecodeProc takes a non-const info, so I have to co
| |
| 47 if (info.fWidth < 0) { // getInfo() failed | |
| 48 return false; | |
| 49 } | |
| 50 SkBitmapFactory::Target target = {pixels, rowBytes}; | |
| 51 return fDecodeProc(fData->data(), fData->size(), &info, &target); | |
| 52 } | |
| 53 | |
| 54 bool SkLazyCachingPixelRef::Install(SkBitmapFactory::DecodeProc proc, | |
| 55 SkData* data, | |
| 56 SkBitmap* destination, | |
| 57 SkScaledImageCache* cache) { | |
| 58 SkAutoTUnref<SkLazyCachingPixelRef> ref( | |
| 59 SkNEW_ARGS(SkLazyCachingPixelRef, (data, proc, cache))); | |
| 60 return ref->configure(destination) && destination->setPixelRef(ref); | |
| 61 } | |
| 62 | |
| OLD | NEW |