OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkBitmapCache.h" | 8 #include "SkBitmapCache.h" |
9 #include "SkResourceCache.h" | 9 #include "SkResourceCache.h" |
10 #include "SkMipMap.h" | 10 #include "SkMipMap.h" |
| 11 #include "SkPixelRef.h" |
11 #include "SkRect.h" | 12 #include "SkRect.h" |
12 | 13 |
13 /** | 14 /** |
14 * Use this for bitmapcache and mipmapcache entries. | 15 * Use this for bitmapcache and mipmapcache entries. |
15 */ | 16 */ |
16 uint64_t SkMakeResourceCacheSharedIDForBitmap(uint32_t bitmapGenID) { | 17 uint64_t SkMakeResourceCacheSharedIDForBitmap(uint32_t bitmapGenID) { |
17 uint64_t sharedID = SkSetFourByteTag('b', 'm', 'a', 'p'); | 18 uint64_t sharedID = SkSetFourByteTag('b', 'm', 'a', 'p'); |
18 return (sharedID << 32) | bitmapGenID; | 19 return (sharedID << 32) | bitmapGenID; |
19 } | 20 } |
20 | 21 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca
leY, | 106 void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca
leY, |
106 const SkBitmap& result, SkResourceCache* localCache) { | 107 const SkBitmap& result, SkResourceCache* localCache) { |
107 if (0 == invScaleX || 0 == invScaleY) { | 108 if (0 == invScaleX || 0 == invScaleY) { |
108 // degenerate, and the key we use for mipmaps | 109 // degenerate, and the key we use for mipmaps |
109 return; | 110 return; |
110 } | 111 } |
111 SkASSERT(result.isImmutable()); | 112 SkASSERT(result.isImmutable()); |
112 BitmapRec* rec = SkNEW_ARGS(BitmapRec, (src.getGenerationID(), invScaleX, in
vScaleY, | 113 BitmapRec* rec = SkNEW_ARGS(BitmapRec, (src.getGenerationID(), invScaleX, in
vScaleY, |
113 get_bounds_from_bitmap(src), result)
); | 114 get_bounds_from_bitmap(src), result)
); |
114 CHECK_LOCAL(localCache, add, Add, rec); | 115 CHECK_LOCAL(localCache, add, Add, rec); |
| 116 src.pixelRef()->notifyAddedToCache(); |
115 } | 117 } |
116 | 118 |
117 bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result
, | 119 bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result
, |
118 SkResourceCache* localCache) { | 120 SkResourceCache* localCache) { |
119 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, subset); | 121 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, subset); |
120 | 122 |
121 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Finder, result); | 123 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Finder, result); |
122 } | 124 } |
123 | 125 |
124 bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& r
esult, | 126 bool SkBitmapCache::Add(SkPixelRef* pr, const SkIRect& subset, const SkBitmap& r
esult, |
125 SkResourceCache* localCache) { | 127 SkResourceCache* localCache) { |
126 SkASSERT(result.isImmutable()); | 128 SkASSERT(result.isImmutable()); |
127 | 129 |
128 if (subset.isEmpty() | 130 if (subset.isEmpty() |
129 || subset.top() < 0 | 131 || subset.top() < 0 |
130 || subset.left() < 0 | 132 || subset.left() < 0 |
131 || result.width() != subset.width() | 133 || result.width() != subset.width() |
132 || result.height() != subset.height()) { | 134 || result.height() != subset.height()) { |
133 return false; | 135 return false; |
134 } else { | 136 } else { |
135 BitmapRec* rec = SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1, s
ubset, result)); | 137 BitmapRec* rec = SkNEW_ARGS(BitmapRec, (pr->getGenerationID(), 1, 1, sub
set, result)); |
136 | 138 |
137 CHECK_LOCAL(localCache, add, Add, rec); | 139 CHECK_LOCAL(localCache, add, Add, rec); |
| 140 pr->notifyAddedToCache(); |
138 return true; | 141 return true; |
139 } | 142 } |
140 } | 143 } |
141 | 144 |
142 ////////////////////////////////////////////////////////////////////////////////
////////// | 145 ////////////////////////////////////////////////////////////////////////////////
////////// |
143 ////////////////////////////////////////////////////////////////////////////////
////////// | 146 ////////////////////////////////////////////////////////////////////////////////
////////// |
144 | 147 |
145 namespace { | 148 namespace { |
146 static unsigned gMipMapKeyNamespaceLabel; | 149 static unsigned gMipMapKeyNamespaceLabel; |
147 | 150 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 static SkResourceCache::DiscardableFactory get_fact(SkResourceCache* localCache)
{ | 207 static SkResourceCache::DiscardableFactory get_fact(SkResourceCache* localCache)
{ |
205 return localCache ? localCache->GetDiscardableFactory() | 208 return localCache ? localCache->GetDiscardableFactory() |
206 : SkResourceCache::GetDiscardableFactory(); | 209 : SkResourceCache::GetDiscardableFactory(); |
207 } | 210 } |
208 | 211 |
209 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
ocalCache) { | 212 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
ocalCache) { |
210 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); | 213 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); |
211 if (mipmap) { | 214 if (mipmap) { |
212 MipMapRec* rec = SkNEW_ARGS(MipMapRec, (src, mipmap)); | 215 MipMapRec* rec = SkNEW_ARGS(MipMapRec, (src, mipmap)); |
213 CHECK_LOCAL(localCache, add, Add, rec); | 216 CHECK_LOCAL(localCache, add, Add, rec); |
| 217 src.pixelRef()->notifyAddedToCache(); |
214 } | 218 } |
215 return mipmap; | 219 return mipmap; |
216 } | 220 } |
OLD | NEW |