Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2012 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 "SkBitmapFactory.h" | |
| 9 | |
| 10 #include "SkBitmap.h" | |
| 11 #include "SkData.h" | |
| 12 #include "SkImageCache.h" | |
| 13 #include "SkImagePriv.h" | |
| 14 #include "SkLazyPixelRef.h" | |
| 15 | |
| 16 SkBitmapFactory::SkBitmapFactory(SkBitmapFactory::DecodeProc proc) | |
|
scroggo
2013/12/06 14:50:33
Hal deleted this file, correct?
reed1
2013/12/06 15:48:46
Done.
| |
| 17 : fDecodeProc(proc) | |
| 18 , fImageCache(NULL) | |
| 19 , fCacheSelector(NULL) { | |
| 20 SkASSERT(fDecodeProc != NULL); | |
| 21 } | |
| 22 | |
| 23 SkBitmapFactory::~SkBitmapFactory() { | |
| 24 SkSafeUnref(fImageCache); | |
| 25 SkSafeUnref(fCacheSelector); | |
| 26 } | |
| 27 | |
| 28 void SkBitmapFactory::setImageCache(SkImageCache *cache) { | |
| 29 SkRefCnt_SafeAssign(fImageCache, cache); | |
| 30 if (cache != NULL) { | |
| 31 SkSafeUnref(fCacheSelector); | |
| 32 fCacheSelector = NULL; | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 void SkBitmapFactory::setCacheSelector(CacheSelector* selector) { | |
| 37 SkRefCnt_SafeAssign(fCacheSelector, selector); | |
| 38 if (selector != NULL) { | |
| 39 SkSafeUnref(fImageCache); | |
| 40 fImageCache = NULL; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 bool SkBitmapFactory::installPixelRef(SkData* data, SkBitmap* dst) { | |
| 45 if (NULL == data || 0 == data->size() || dst == NULL) { | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 49 SkImageInfo info; | |
| 50 if (!fDecodeProc(data->data(), data->size(), &info, NULL)) { | |
| 51 return false; | |
| 52 } | |
| 53 | |
| 54 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); | |
| 55 | |
| 56 Target target; | |
| 57 // FIMXE: There will be a problem if this rowbytes is calculated differently from | |
| 58 // in SkLazyPixelRef. | |
| 59 target.fRowBytes = SkImageMinRowBytes(info); | |
| 60 dst->setConfig(config, info.fWidth, info.fHeight, target.fRowBytes, info.fAl phaType); | |
| 61 | |
| 62 // fImageCache and fCacheSelector are mutually exclusive. | |
| 63 SkASSERT(NULL == fImageCache || NULL == fCacheSelector); | |
| 64 | |
| 65 SkImageCache* cache = NULL == fCacheSelector ? fImageCache : fCacheSelector- >selectCache(info); | |
| 66 | |
| 67 if (cache != NULL) { | |
| 68 // Now set a new LazyPixelRef on dst. | |
| 69 SkAutoTUnref<SkLazyPixelRef> lazyRef(SkNEW_ARGS(SkLazyPixelRef, | |
| 70 (info, data, fDecodeProc, cache))); | |
| 71 dst->setPixelRef(lazyRef); | |
| 72 return true; | |
| 73 } else { | |
| 74 dst->allocPixels(); | |
| 75 target.fAddr = dst->getPixels(); | |
| 76 return fDecodeProc(data->data(), data->size(), &info, &target); | |
| 77 } | |
| 78 } | |
| OLD | NEW |