OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBitmapFactory.h" | 8 #include "SkBitmapFactory.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 SkSafeUnref(fImageCache); | 41 SkSafeUnref(fImageCache); |
42 fImageCache = NULL; | 42 fImageCache = NULL; |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 bool SkBitmapFactory::installPixelRef(SkData* data, SkBitmap* dst) { | 46 bool SkBitmapFactory::installPixelRef(SkData* data, SkBitmap* dst) { |
47 if (NULL == data || 0 == data->size() || dst == NULL) { | 47 if (NULL == data || 0 == data->size() || dst == NULL) { |
48 return false; | 48 return false; |
49 } | 49 } |
50 | 50 |
51 SkImage::Info info; | 51 SkImageInfo info; |
52 if (!fDecodeProc(data->data(), data->size(), &info, NULL)) { | 52 if (!fDecodeProc(data->data(), data->size(), &info, NULL)) { |
53 return false; | 53 return false; |
54 } | 54 } |
55 | 55 |
56 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); | 56 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); |
57 | 57 |
58 Target target; | 58 Target target; |
59 // FIMXE: There will be a problem if this rowbytes is calculated differently
from | 59 // FIMXE: There will be a problem if this rowbytes is calculated differently
from |
60 // in SkLazyPixelRef. | 60 // in SkLazyPixelRef. |
61 target.fRowBytes = SkImageMinRowBytes(info); | 61 target.fRowBytes = SkImageMinRowBytes(info); |
62 dst->setConfig(config, info.fWidth, info.fHeight, target.fRowBytes, info.fAl
phaType); | 62 dst->setConfig(config, info.fWidth, info.fHeight, target.fRowBytes, info.fAl
phaType); |
63 | 63 |
64 // fImageCache and fCacheSelector are mutually exclusive. | 64 // fImageCache and fCacheSelector are mutually exclusive. |
65 SkASSERT(NULL == fImageCache || NULL == fCacheSelector); | 65 SkASSERT(NULL == fImageCache || NULL == fCacheSelector); |
66 | 66 |
67 SkImageCache* cache = NULL == fCacheSelector ? fImageCache : fCacheSelector-
>selectCache(info); | 67 SkImageCache* cache = NULL == fCacheSelector ? fImageCache : fCacheSelector-
>selectCache(info); |
68 | 68 |
69 if (cache != NULL) { | 69 if (cache != NULL) { |
70 // Now set a new LazyPixelRef on dst. | 70 // Now set a new LazyPixelRef on dst. |
71 SkAutoTUnref<SkLazyPixelRef> lazyRef(SkNEW_ARGS(SkLazyPixelRef, | 71 SkAutoTUnref<SkLazyPixelRef> lazyRef(SkNEW_ARGS(SkLazyPixelRef, |
72 (data, fDecodeProc, cach
e))); | 72 (data, fDecodeProc, cach
e))); |
73 dst->setPixelRef(lazyRef); | 73 dst->setPixelRef(lazyRef); |
74 return true; | 74 return true; |
75 } else { | 75 } else { |
76 dst->allocPixels(); | 76 dst->allocPixels(); |
77 target.fAddr = dst->getPixels(); | 77 target.fAddr = dst->getPixels(); |
78 return fDecodeProc(data->data(), data->size(), &info, &target); | 78 return fDecodeProc(data->data(), data->size(), &info, &target); |
79 } | 79 } |
80 } | 80 } |
OLD | NEW |