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

Side by Side Diff: src/core/SkImageCacherator.cpp

Issue 1352883004: Purge cached resources on SkImage destruction. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: review comments Created 5 years, 3 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
« no previous file with comments | « src/core/SkImageCacherator.h ('k') | src/image/SkImage.cpp » ('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 2015 Google Inc. 2 * Copyright 2015 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapCache.h" 9 #include "SkBitmapCache.h"
10 #include "SkImage_Base.h"
10 #include "SkImageCacherator.h" 11 #include "SkImageCacherator.h"
11 #include "SkMallocPixelRef.h" 12 #include "SkMallocPixelRef.h"
12 #include "SkNextID.h" 13 #include "SkNextID.h"
13 #include "SkPixelRef.h" 14 #include "SkPixelRef.h"
14 #include "SkResourceCache.h" 15 #include "SkResourceCache.h"
15 16
16 #if SK_SUPPORT_GPU 17 #if SK_SUPPORT_GPU
17 #include "GrContext.h" 18 #include "GrContext.h"
18 #include "GrGpuResourcePriv.h" 19 #include "GrGpuResourcePriv.h"
19 #include "GrResourceKey.h" 20 #include "GrResourceKey.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 if (!bitmap->tryAllocPixels(fInfo, nullptr, full.getColorTable())) { 103 if (!bitmap->tryAllocPixels(fInfo, nullptr, full.getColorTable())) {
103 return false; 104 return false;
104 } 105 }
105 return full.readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowB ytes(), 106 return full.readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowB ytes(),
106 fOrigin.x(), fOrigin.y()); 107 fOrigin.x(), fOrigin.y());
107 } 108 }
108 } 109 }
109 110
110 //////////////////////////////////////////////////////////////////////////////// ////////////////// 111 //////////////////////////////////////////////////////////////////////////////// //////////////////
111 112
112 bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap) { 113 bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client) {
113 if (SkBitmapCache::Find(fUniqueID, bitmap)) { 114 if (SkBitmapCache::Find(fUniqueID, bitmap)) {
114 return check_output_bitmap(*bitmap, fUniqueID); 115 return check_output_bitmap(*bitmap, fUniqueID);
115 } 116 }
116 117
117 if (!this->generateBitmap(bitmap)) { 118 if (!this->generateBitmap(bitmap)) {
118 return false; 119 return false;
119 } 120 }
120 121
121 bitmap->pixelRef()->setImmutableWithID(fUniqueID); 122 bitmap->pixelRef()->setImmutableWithID(fUniqueID);
122 SkBitmapCache::Add(fUniqueID, *bitmap); 123 SkBitmapCache::Add(fUniqueID, *bitmap);
124 if (client) {
125 as_IB(client)->notifyAddedToCache();
126 }
127
123 return true; 128 return true;
124 } 129 }
125 130
126 bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap) { 131 bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap, const SkImage* client) {
127 if (this->tryLockAsBitmap(bitmap)) { 132 if (this->tryLockAsBitmap(bitmap, client)) {
128 return check_output_bitmap(*bitmap, fUniqueID); 133 return check_output_bitmap(*bitmap, fUniqueID);
129 } 134 }
130 135
131 #if SK_SUPPORT_GPU 136 #if SK_SUPPORT_GPU
132 // Try to get a texture and read it back to raster (and then cache that with our ID) 137 // Try to get a texture and read it back to raster (and then cache that with our ID)
133 SkAutoTUnref<GrTexture> tex; 138 SkAutoTUnref<GrTexture> tex;
134 139
135 { 140 {
136 ScopedGenerator generator(this); 141 ScopedGenerator generator(this);
137 SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width (), fInfo.height()); 142 SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width (), fInfo.height());
(...skipping 11 matching lines...) Expand all
149 154
150 const uint32_t pixelOpsFlags = 0; 155 const uint32_t pixelOpsFlags = 0;
151 if (!tex->readPixels(0, 0, bitmap->width(), bitmap->height(), SkImageInfo2Gr PixelConfig(fInfo), 156 if (!tex->readPixels(0, 0, bitmap->width(), bitmap->height(), SkImageInfo2Gr PixelConfig(fInfo),
152 bitmap->getPixels(), bitmap->rowBytes(), pixelOpsFlags) ) { 157 bitmap->getPixels(), bitmap->rowBytes(), pixelOpsFlags) ) {
153 bitmap->reset(); 158 bitmap->reset();
154 return false; 159 return false;
155 } 160 }
156 161
157 bitmap->pixelRef()->setImmutableWithID(fUniqueID); 162 bitmap->pixelRef()->setImmutableWithID(fUniqueID);
158 SkBitmapCache::Add(fUniqueID, *bitmap); 163 SkBitmapCache::Add(fUniqueID, *bitmap);
164 if (client) {
165 as_IB(client)->notifyAddedToCache();
166 }
167
159 return check_output_bitmap(*bitmap, fUniqueID); 168 return check_output_bitmap(*bitmap, fUniqueID);
160 #else 169 #else
161 return false; 170 return false;
162 #endif 171 #endif
163 } 172 }
164 173
165 //////////////////////////////////////////////////////////////////////////////// ////////////////// 174 //////////////////////////////////////////////////////////////////////////////// //////////////////
166 175
167 #if SK_SUPPORT_GPU 176 #if SK_SUPPORT_GPU
168 177
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 211
203 /* 212 /*
204 * We have a 5 ways to try to return a texture (in sorted order) 213 * We have a 5 ways to try to return a texture (in sorted order)
205 * 214 *
206 * 1. Check the cache for a pre-existing one 215 * 1. Check the cache for a pre-existing one
207 * 2. Ask the genreator to natively create one 216 * 2. Ask the genreator to natively create one
208 * 3. Ask the generator to return a compressed form that the GPU might support 217 * 3. Ask the generator to return a compressed form that the GPU might support
209 * 4. Ask the generator to return YUV planes, which the GPU can convert 218 * 4. Ask the generator to return YUV planes, which the GPU can convert
210 * 5. Ask the generator to return RGB(A) data, which the GPU can convert 219 * 5. Ask the generator to return RGB(A) data, which the GPU can convert
211 */ 220 */
212 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa ge) { 221 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa ge,
222 const SkImage* client) {
213 #if SK_SUPPORT_GPU 223 #if SK_SUPPORT_GPU
214 if (!ctx) { 224 if (!ctx) {
215 return nullptr; 225 return nullptr;
216 } 226 }
217 227
218 // textures (at least the texture-key) only support 16bit dimensions, so abo rt early 228 // textures (at least the texture-key) only support 16bit dimensions, so abo rt early
219 // if we're too big. 229 // if we're too big.
220 if (fInfo.width() > 0xFFFF || fInfo.height() > 0xFFFF) { 230 if (fInfo.width() > 0xFFFF || fInfo.height() > 0xFFFF) {
221 return nullptr; 231 return nullptr;
222 } 232 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 ScopedGenerator generator(this); 265 ScopedGenerator generator(this);
256 Generator_GrYUVProvider provider(generator); 266 Generator_GrYUVProvider provider(generator);
257 GrTexture* tex = provider.refAsTexture(ctx, desc, true); 267 GrTexture* tex = provider.refAsTexture(ctx, desc, true);
258 if (tex) { 268 if (tex) {
259 return set_key_and_return(tex, key); 269 return set_key_and_return(tex, key);
260 } 270 }
261 } 271 }
262 272
263 // 5. Ask the generator to return RGB(A) data, which the GPU can convert 273 // 5. Ask the generator to return RGB(A) data, which the GPU can convert
264 SkBitmap bitmap; 274 SkBitmap bitmap;
265 if (this->tryLockAsBitmap(&bitmap)) { 275 if (this->tryLockAsBitmap(&bitmap, client)) {
266 return GrRefCachedBitmapTexture(ctx, bitmap, usage); 276 return GrRefCachedBitmapTexture(ctx, bitmap, usage);
267 } 277 }
268 #endif 278 #endif
269 279
270 return nullptr; 280 return nullptr;
271 } 281 }
272 282
OLDNEW
« no previous file with comments | « src/core/SkImageCacherator.h ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698