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 | |
16 SkLazyCachingPixelRef::SkLazyCachingPixelRef(SkData* data, | |
17 SkBitmapFactory::DecodeProc proc) | |
18 : fDecodeProc(proc) { | |
19 if (NULL == data) { | |
20 fData = SkData::NewEmpty(); | |
21 } else { | |
22 fData = data; | |
23 fData->ref(); | |
24 } | |
25 if (NULL == fDecodeProc) { // use a reasonable default. | |
26 fDecodeProc = SkImageDecoder::DecodeMemoryToTarget; | |
27 } | |
28 this->setImmutable(); | |
29 } | |
30 | |
31 SkLazyCachingPixelRef::~SkLazyCachingPixelRef() { | |
32 SkASSERT(fData != NULL); | |
33 fData->unref(); | |
34 } | |
35 | |
36 bool SkLazyCachingPixelRef::onDecodeInfo(SkImageInfo* info) { | |
37 SkASSERT(info); | |
38 return fDecodeProc(fData->data(), fData->size(), info, NULL); | |
39 } | |
40 | |
41 static inline bool operator==(const SkImageInfo& lhs, const SkImageInfo& rhs) { | |
42 return 0 == memcmp(&lhs, &rhs, sizeof(SkImageInfo)); | |
scroggo
2013/11/04 17:18:03
Is this meaningfully different from what the compi
hal.canary
2013/11/04 18:24:19
My compiler refuses to write its own comparison op
| |
43 } | |
44 static inline bool operator!=(const SkImageInfo& lhs, const SkImageInfo& rhs) { | |
45 return !(lhs == rhs); | |
scroggo
2013/11/04 17:18:03
Is this meaningfully different from what the compi
hal.canary
2013/11/04 18:24:19
Smae thing: my compiler refuses to write its own c
| |
46 } | |
47 | |
48 bool SkLazyCachingPixelRef::onDecodePixels(const SkImageInfo& passedInfo, | |
49 void* pixels, size_t rowBytes) { | |
50 SkASSERT(pixels); | |
51 SkImageInfo info; | |
52 if (!this->getInfo(&info)) { | |
53 return false; | |
54 } | |
55 if (passedInfo != info) { | |
56 return false; // This implementation can not handle this case. | |
57 } | |
58 SkBitmapFactory::Target target = {pixels, rowBytes}; | |
59 return fDecodeProc(fData->data(), fData->size(), &info, &target); | |
60 } | |
61 | |
62 bool SkLazyCachingPixelRef::Install(SkBitmapFactory::DecodeProc proc, | |
63 SkData* data, | |
64 SkBitmap* destination) { | |
65 SkAutoTUnref<SkLazyCachingPixelRef> ref( | |
66 SkNEW_ARGS(SkLazyCachingPixelRef, (data, proc))); | |
67 return ref->configure(destination) && destination->setPixelRef(ref); | |
68 } | |
69 | |
OLD | NEW |