OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2012 Google Inc. | |
scroggo
2013/10/31 21:53:06
2013
hal.canary
2013/11/01 03:29:24
Done.
| |
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 "SkImagePriv.h" | |
12 #include "SkLazyCachingPixelRef.h" | |
13 #include "SkScaledImageCache.h" | |
14 #include "SkPostConfig.h" | |
15 #include "SkImageDecoder.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 memset(&fLazilyCachedInfo, 0xFF, sizeof(fLazilyCachedInfo)); | |
29 | |
30 if (NULL == fDecodeProc) { // use a reasonable default. | |
31 fDecodeProc = SkImageDecoder::DecodeMemoryToTarget; | |
32 } | |
33 this->setImmutable(); | |
34 } | |
35 | |
36 SkLazyCachingPixelRef::~SkLazyCachingPixelRef() { | |
37 SkASSERT(fData != NULL); | |
38 fData->unref(); | |
39 } | |
40 | |
41 bool SkLazyCachingPixelRef::onDecodeInfo(SkISize* size, | |
42 SkBitmap::Config* config, | |
43 SkAlphaType* alphaType) { | |
44 SkASSERT(size && config &&alphaType); | |
45 if (fLazilyCachedInfo.fWidth < 0) { | |
46 SkImage::Info info; | |
47 if (!fDecodeProc(fData->data(), fData->size(), &info, NULL)) { | |
48 return false; | |
49 } | |
50 fLazilyCachedInfo = info; | |
51 } | |
52 size->set(fLazilyCachedInfo.fWidth, fLazilyCachedInfo.fHeight); | |
53 *config = SkImageInfoToBitmapConfig(fLazilyCachedInfo); | |
54 *alphaType = fLazilyCachedInfo.fAlphaType; | |
55 return true; | |
56 } | |
57 | |
58 bool SkLazyCachingPixelRef::onDecode(void* pixels, size_t rowBytes) { | |
59 SkASSERT(pixels); | |
60 if (fLazilyCachedInfo.fWidth <= 0) { | |
61 SkISize size; | |
62 SkBitmap::Config config; | |
63 SkAlphaType alphaType; | |
64 // The side effect of this is to set fLazilyCachedInfo | |
65 this->onDecodeInfo(&size, &config, &alphaType); | |
66 } | |
67 SkBitmapFactory::Target target = {pixels, rowBytes}; | |
68 return fDecodeProc(fData->data(), fData->size(), | |
69 &fLazilyCachedInfo, &target); | |
70 } | |
71 | |
72 bool SkLazyCachingPixelRef::Install(SkBitmapFactory::DecodeProc proc, | |
73 SkData* data, | |
74 SkBitmap* destination, | |
75 SkScaledImageCache* cache) { | |
76 SkAutoTUnref<SkLazyCachingPixelRef> ref( | |
77 SkNEW_ARGS(SkLazyCachingPixelRef, (data, proc, cache))); | |
78 return ref->configure(destination) && destination->setPixelRef(ref); | |
79 } | |
OLD | NEW |