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

Side by Side Diff: src/image/SkImage.cpp

Issue 1352883004: Purge cached resources on SkImage destruction. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: codestyle 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
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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapCache.h"
9 #include "SkCanvas.h" 10 #include "SkCanvas.h"
10 #include "SkData.h" 11 #include "SkData.h"
11 #include "SkImageGenerator.h" 12 #include "SkImageGenerator.h"
12 #include "SkImagePriv.h" 13 #include "SkImagePriv.h"
13 #include "SkImage_Base.h" 14 #include "SkImage_Base.h"
14 #include "SkNextID.h" 15 #include "SkNextID.h"
15 #include "SkPixelRef.h" 16 #include "SkPixelRef.h"
16 #include "SkPixelSerializer.h" 17 #include "SkPixelSerializer.h"
17 #include "SkReadPixelsRec.h" 18 #include "SkReadPixelsRec.h"
18 #include "SkString.h" 19 #include "SkString.h"
19 #include "SkSurface.h" 20 #include "SkSurface.h"
20 21
21 #if SK_SUPPORT_GPU 22 #if SK_SUPPORT_GPU
22 #include "GrTexture.h" 23 #include "GrTexture.h"
23 #include "GrContext.h" 24 #include "GrContext.h"
24 #include "SkImage_Gpu.h" 25 #include "SkImage_Gpu.h"
25 #endif 26 #endif
26 27
27 SkImage::SkImage(int width, int height, uint32_t uniqueID) 28 SkImage::SkImage(int width, int height, uint32_t uniqueID)
28 : fWidth(width) 29 : fWidth(width)
29 , fHeight(height) 30 , fHeight(height)
30 , fUniqueID(kNeedNewImageUniqueID == uniqueID ? SkNextID::ImageID() : unique ID) 31 , fUniqueID(kNeedNewImageUniqueID == uniqueID ? SkNextID::ImageID() : unique ID)
31 { 32 {
32 SkASSERT(width > 0); 33 SkASSERT(width > 0);
33 SkASSERT(height > 0); 34 SkASSERT(height > 0);
34 } 35 }
35 36
37 SkImage::~SkImage() { }
reed1 2015/09/18 14:32:53 nit: I think we can put this impl ( {} ) in the he
f(malita) 2015/09/18 15:00:40 Dropped the SkImage dtor completely.
38
36 const void* SkImage::peekPixels(SkImageInfo* info, size_t* rowBytes) const { 39 const void* SkImage::peekPixels(SkImageInfo* info, size_t* rowBytes) const {
37 SkImageInfo infoStorage; 40 SkImageInfo infoStorage;
38 size_t rowBytesStorage; 41 size_t rowBytesStorage;
39 if (nullptr == info) { 42 if (nullptr == info) {
40 info = &infoStorage; 43 info = &infoStorage;
41 } 44 }
42 if (nullptr == rowBytes) { 45 if (nullptr == rowBytes) {
43 rowBytes = &rowBytesStorage; 46 rowBytes = &rowBytesStorage;
44 } 47 }
45 return as_IB(this)->onPeekPixels(info, rowBytes); 48 return as_IB(this)->onPeekPixels(info, rowBytes);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 case kRGB_565_SkColorType: 206 case kRGB_565_SkColorType:
204 return true; 207 return true;
205 case kAlpha_8_SkColorType: 208 case kAlpha_8_SkColorType:
206 return true; 209 return true;
207 default: 210 default:
208 break; 211 break;
209 } 212 }
210 return false; 213 return false;
211 } 214 }
212 215
216 static SkSurfaceProps copy_or_safe_defaults(const SkSurfaceProps* props) {
217 return props ? *props : SkSurfaceProps(0, kUnknown_SkPixelGeometry);
mtklein 2015/09/18 14:32:36 We might even think about adding SkSurfaceProps::S
218 }
219
220 SkImage_Base::SkImage_Base(int width, int height, uint32_t uniqueID, const SkSur faceProps* props)
221 : INHERITED(width, height, uniqueID)
222 , fProps(copy_or_safe_defaults(props))
mtklein 2015/09/18 14:32:36 You ought to be able to do fAddedToCache(false) he
f(malita) 2015/09/18 15:00:40 Thanks, done.
223 {
224 fAddedToCache.store(false);
225 }
226
227 SkImage_Base::~SkImage_Base() {
228 if (fAddedToCache.load()) {
229 SkNotifyBitmapGenIDIsStale(this->uniqueID());
mtklein 2015/09/18 14:32:36 Are bitmap genids and skimage genids in the same n
f(malita) 2015/09/18 15:00:40 Yes.
230 }
231 }
232
213 bool SkImage_Base::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, siz e_t dstRowBytes, 233 bool SkImage_Base::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, siz e_t dstRowBytes,
214 int srcX, int srcY) const { 234 int srcX, int srcY) const {
215 if (!raster_canvas_supports(dstInfo)) { 235 if (!raster_canvas_supports(dstInfo)) {
216 return false; 236 return false;
217 } 237 }
218 238
219 SkBitmap bm; 239 SkBitmap bm;
220 bm.installPixels(dstInfo, dstPixels, dstRowBytes); 240 bm.installPixels(dstInfo, dstPixels, dstRowBytes);
221 SkCanvas canvas(bm); 241 SkCanvas canvas(bm);
222 242
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 368
349 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { 369 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
350 return nullptr; 370 return nullptr;
351 } 371 }
352 372
353 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 373 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
354 return nullptr; 374 return nullptr;
355 } 375 }
356 376
357 #endif 377 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698