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

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

Issue 1345523002: we must own/free the generator, even if we fail to return a cacherator (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « no previous file | no next file » | 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 "SkImageCacherator.h" 10 #include "SkImageCacherator.h"
11 #include "SkMallocPixelRef.h" 11 #include "SkMallocPixelRef.h"
12 #include "SkNextID.h" 12 #include "SkNextID.h"
13 #include "SkPixelRef.h" 13 #include "SkPixelRef.h"
14 14
15 #if SK_SUPPORT_GPU 15 #if SK_SUPPORT_GPU
16 #include "GrContext.h" 16 #include "GrContext.h"
17 #include "GrGpuResourcePriv.h" 17 #include "GrGpuResourcePriv.h"
18 #include "GrResourceKey.h" 18 #include "GrResourceKey.h"
19 #include "GrTextureAccess.h" 19 #include "GrTextureAccess.h"
20 #include "GrYUVProvider.h" 20 #include "GrYUVProvider.h"
21 #include "SkGr.h" 21 #include "SkGr.h"
22 #include "SkGrPriv.h" 22 #include "SkGrPriv.h"
23 #endif 23 #endif
24 24
25 SkImageCacherator* SkImageCacherator::NewFromGenerator(SkImageGenerator* gen, 25 SkImageCacherator* SkImageCacherator::NewFromGenerator(SkImageGenerator* gen,
26 const SkIRect* subset) { 26 const SkIRect* subset) {
27 if (!gen) { 27 if (!gen) {
28 return nullptr; 28 return nullptr;
29 } 29 }
30
31 // We are required to take ownership of gen, regardless of if we return a ca cherator or not
32 SkAutoTDelete<SkImageGenerator> genHolder(gen);
33
30 const SkImageInfo& info = gen->getInfo(); 34 const SkImageInfo& info = gen->getInfo();
31 if (info.isEmpty()) { 35 if (info.isEmpty()) {
32 return nullptr; 36 return nullptr;
33 } 37 }
34 38
35 uint32_t uniqueID = gen->uniqueID(); 39 uint32_t uniqueID = gen->uniqueID();
36 const SkIRect bounds = SkIRect::MakeWH(info.width(), info.height()); 40 const SkIRect bounds = SkIRect::MakeWH(info.width(), info.height());
37 if (subset) { 41 if (subset) {
38 if (!bounds.contains(*subset)) { 42 if (!bounds.contains(*subset)) {
39 return nullptr; 43 return nullptr;
40 } 44 }
41 if (*subset != bounds) { 45 if (*subset != bounds) {
42 // we need a different uniqueID since we really are a subset of the raw generator 46 // we need a different uniqueID since we really are a subset of the raw generator
43 uniqueID = SkNextID::ImageID(); 47 uniqueID = SkNextID::ImageID();
44 } 48 }
45 } else { 49 } else {
46 subset = &bounds; 50 subset = &bounds;
47 } 51 }
48 52
53 // Now that we know we can hand-off the generator (to be owned by the cacher ator) we can
54 // release our holder. (we DONT want to delete it here anymore)
tomhudson 2015/09/14 16:58:16 Nit: two words "any more" unless you're Edgar Alle
55 genHolder.detach();
56
49 return new SkImageCacherator(gen, gen->getInfo().makeWH(subset->width(), sub set->height()), 57 return new SkImageCacherator(gen, gen->getInfo().makeWH(subset->width(), sub set->height()),
50 SkIPoint::Make(subset->x(), subset->y()), uniqu eID); 58 SkIPoint::Make(subset->x(), subset->y()), uniqu eID);
51 } 59 }
52 60
53 SkImageCacherator::SkImageCacherator(SkImageGenerator* gen, const SkImageInfo& i nfo, 61 SkImageCacherator::SkImageCacherator(SkImageGenerator* gen, const SkImageInfo& i nfo,
54 const SkIPoint& origin, uint32_t uniqueID) 62 const SkIPoint& origin, uint32_t uniqueID)
55 : fNotThreadSafeGenerator(gen) 63 : fNotThreadSafeGenerator(gen)
56 , fInfo(info) 64 , fInfo(info)
57 , fOrigin(origin) 65 , fOrigin(origin)
58 , fUniqueID(uniqueID) 66 , fUniqueID(uniqueID)
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // 5. Ask the generator to return RGB(A) data, which the GPU can convert 265 // 5. Ask the generator to return RGB(A) data, which the GPU can convert
258 SkBitmap bitmap; 266 SkBitmap bitmap;
259 if (this->generateBitmap(&bitmap)) { 267 if (this->generateBitmap(&bitmap)) {
260 return GrRefCachedBitmapTexture(ctx, bitmap, usage); 268 return GrRefCachedBitmapTexture(ctx, bitmap, usage);
261 } 269 }
262 #endif 270 #endif
263 271
264 return nullptr; 272 return nullptr;
265 } 273 }
266 274
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698