Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/lazy/SkBitmapFactory.cpp

Issue 12433020: Improvements/additions to SkImageCache/SkLazyPixelRef. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Respond to comments. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/ports/SkAshmemImageCache.h ('k') | src/lazy/SkLazyPixelRef.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "SkData.h" 11 #include "SkData.h"
12 #include "SkImageCache.h" 12 #include "SkImageCache.h"
13 #include "SkImagePriv.h" 13 #include "SkImagePriv.h"
14 #include "SkLazyPixelRef.h" 14 #include "SkLazyPixelRef.h"
15 15
16 SkBitmapFactory::SkBitmapFactory(SkBitmapFactory::DecodeProc proc) 16 SkBitmapFactory::SkBitmapFactory(SkBitmapFactory::DecodeProc proc)
17 : fDecodeProc(proc) 17 : fDecodeProc(proc)
18 , fImageCache(NULL) 18 , fImageCache(NULL)
19 , fCacheSelector(NULL) { 19 , fCacheSelector(NULL) {
20 SkASSERT(fDecodeProc != NULL); 20 SkASSERT(fDecodeProc != NULL);
21 } 21 }
22 22
23 SkBitmapFactory::~SkBitmapFactory() { 23 SkBitmapFactory::~SkBitmapFactory() {
24 SkSafeUnref(fImageCache); 24 SkSafeUnref(fImageCache);
25 SkSafeUnref(fCacheSelector);
25 } 26 }
26 27
27 void SkBitmapFactory::setImageCache(SkImageCache *cache) { 28 void SkBitmapFactory::setImageCache(SkImageCache *cache) {
28 SkRefCnt_SafeAssign(fImageCache, cache); 29 SkRefCnt_SafeAssign(fImageCache, cache);
29 if (cache != NULL) { 30 if (cache != NULL) {
31 SkSafeUnref(fCacheSelector);
30 fCacheSelector = NULL; 32 fCacheSelector = NULL;
31 } 33 }
32 } 34 }
33 35
34 void SkBitmapFactory::setCacheSelector(CacheSelector selector) { 36 void SkBitmapFactory::setCacheSelector(CacheSelector* selector) {
35 fCacheSelector = selector; 37 SkRefCnt_SafeAssign(fCacheSelector, selector);
36 if (selector != NULL) { 38 if (selector != NULL) {
37 SkSafeUnref(fImageCache); 39 SkSafeUnref(fImageCache);
38 fImageCache = NULL; 40 fImageCache = NULL;
39 } 41 }
40 } 42 }
41 43
42 bool SkBitmapFactory::installPixelRef(SkData* data, SkBitmap* dst) { 44 bool SkBitmapFactory::installPixelRef(SkData* data, SkBitmap* dst) {
43 if (NULL == data || 0 == data->size() || dst == NULL) { 45 if (NULL == data || 0 == data->size() || dst == NULL) {
44 return false; 46 return false;
45 } 47 }
(...skipping 10 matching lines...) Expand all
56 // FIMXE: There will be a problem if this rowbytes is calculated differently from 58 // FIMXE: There will be a problem if this rowbytes is calculated differently from
57 // in SkLazyPixelRef. 59 // in SkLazyPixelRef.
58 target.fRowBytes = SkImageMinRowBytes(info); 60 target.fRowBytes = SkImageMinRowBytes(info);
59 61
60 dst->setConfig(config, info.fWidth, info.fHeight, target.fRowBytes); 62 dst->setConfig(config, info.fWidth, info.fHeight, target.fRowBytes);
61 dst->setIsOpaque(isOpaque); 63 dst->setIsOpaque(isOpaque);
62 64
63 // fImageCache and fCacheSelector are mutually exclusive. 65 // fImageCache and fCacheSelector are mutually exclusive.
64 SkASSERT(NULL == fImageCache || NULL == fCacheSelector); 66 SkASSERT(NULL == fImageCache || NULL == fCacheSelector);
65 67
66 SkImageCache* cache = NULL == fCacheSelector ? fImageCache : fCacheSelector( info); 68 SkImageCache* cache = NULL == fCacheSelector ? fImageCache : fCacheSelector- >selectCache(info);
67 69
68 if (cache != NULL) { 70 if (cache != NULL) {
69 // Now set a new LazyPixelRef on dst. 71 // Now set a new LazyPixelRef on dst.
70 SkAutoTUnref<SkLazyPixelRef> lazyRef(SkNEW_ARGS(SkLazyPixelRef, 72 SkAutoTUnref<SkLazyPixelRef> lazyRef(SkNEW_ARGS(SkLazyPixelRef,
71 (data, fDecodeProc, cach e))); 73 (data, fDecodeProc, cach e)));
72 dst->setPixelRef(lazyRef); 74 dst->setPixelRef(lazyRef);
73 return true; 75 return true;
74 } else { 76 } else {
75 dst->allocPixels(); 77 dst->allocPixels();
76 target.fAddr = dst->getPixels(); 78 target.fAddr = dst->getPixels();
77 return fDecodeProc(data->data(), data->size(), &info, &target); 79 return fDecodeProc(data->data(), data->size(), &info, &target);
78 } 80 }
79 } 81 }
OLDNEW
« no previous file with comments | « include/ports/SkAshmemImageCache.h ('k') | src/lazy/SkLazyPixelRef.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698