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

Side by Side Diff: src/gpu/GrGpuResourceCacheAccess.h

Issue 870743002: Allow unbudgeted resources to be recycled by the cache as scratch. (Closed) Base URL: https://skia.googlesource.com/skia.git@ckey
Patch Set: rebase Created 5 years, 11 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 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #ifndef GrGpuResourceCacheAccess_DEFINED 9 #ifndef GrGpuResourceCacheAccess_DEFINED
10 #define GrGpuResourceCacheAccess_DEFINED 10 #define GrGpuResourceCacheAccess_DEFINED
(...skipping 11 matching lines...) Expand all
22 * be converted to a content resource. Currently this may only be called onc e per resource. It 22 * be converted to a content resource. Currently this may only be called onc e per resource. It
23 * fails if there is already a resource with the same content key. TODO: mak e this supplant the 23 * fails if there is already a resource with the same content key. TODO: mak e this supplant the
24 * resource that currently is using the content key, allow resources' conten t keys to change, 24 * resource that currently is using the content key, allow resources' conten t keys to change,
25 * and allow removal of a content key to convert a resource back to scratch. 25 * and allow removal of a content key to convert a resource back to scratch.
26 */ 26 */
27 bool setContentKey(const GrContentKey& contentKey) { 27 bool setContentKey(const GrContentKey& contentKey) {
28 return fResource->setContentKey(contentKey); 28 return fResource->setContentKey(contentKey);
29 } 29 }
30 30
31 /** 31 /**
32 * Is the resource currently cached as scratch? This means it has a valid sc ratch key and does 32 * Is the resource currently cached as scratch? This means it is cached, has a valid scratch
33 * not have a content key. 33 * key, and does not have a content key.
34 */ 34 */
35 bool isScratch() const { 35 bool isScratch() const {
36 return !this->getContentKey().isValid() && fResource->fScratchKey.isVali d(); 36 return !this->getContentKey().isValid() && fResource->fScratchKey.isVali d() &&
37 this->isBudgeted();
37 } 38 }
38 39
39 /** 40 /**
40 * If this resource can be used as a scratch resource this returns a valid s cratch key. 41 * If this resource can be used as a scratch resource this returns a valid s cratch key.
41 * Otherwise it returns a key for which isNullScratch is true. The resource may currently be 42 * Otherwise it returns a key for which isNullScratch is true. The resource may currently be
42 * used as a content resource rather than scratch. Check isScratch(). 43 * used as a content resource rather than scratch. Check isScratch().
43 */ 44 */
44 const GrScratchKey& getScratchKey() const { return fResource->fScratchKey; } 45 const GrScratchKey& getScratchKey() const { return fResource->fScratchKey; }
45 46
46 /** 47 /**
47 * If the resource has a scratch key, the key will be removed. Since scratch keys are installed 48 * If the resource has a scratch key, the key will be removed. Since scratch keys are installed
48 * at resource creation time, this means the resource will never again be us ed as scratch. 49 * at resource creation time, this means the resource will never again be us ed as scratch.
49 */ 50 */
50 void removeScratchKey() const { fResource->removeScratchKey(); } 51 void removeScratchKey() const { fResource->removeScratchKey(); }
51 52
52 /** 53 /**
53 * If the resource is currently cached by a content key, the key is returned , otherwise NULL. 54 * If the resource is currently cached by a content key, the key is returned , otherwise NULL.
54 */ 55 */
55 const GrContentKey& getContentKey() const { return fResource->fContentKey; } 56 const GrContentKey& getContentKey() const { return fResource->fContentKey; }
56 57
57 /** 58 /**
58 * Is the resource object wrapping an externally allocated GPU resource? 59 * Is the resource object wrapping an externally allocated GPU resource?
59 */ 60 */
60 bool isWrapped() const { return GrGpuResource::kWrapped_LifeCycle == fResour ce->fLifeCycle; } 61 bool isWrapped() const { return GrGpuResource::kWrapped_LifeCycle == fResour ce->fLifeCycle; }
61 62
62 /** 63 /**
63 * Does the resource count against the resource budget? 64 * Does the resource count against the resource budget?
64 */ 65 */
65 bool isBudgeted() const { return GrGpuResource::kCached_LifeCycle == fResour ce->fLifeCycle; } 66 bool isBudgeted() const {
67 bool ret = GrGpuResource::kCached_LifeCycle == fResource->fLifeCycle;
68 SkASSERT(ret || !this->getContentKey().isValid());
69 return ret;
70 }
66 71
67 /** 72 /**
68 * If the resource is uncached make it cached. Has no effect on resources th at are wrapped or 73 * If the resource is uncached make it cached. Has no effect on resources th at are wrapped or
69 * already cached. 74 * already cached.
70 */ 75 */
71 void makeBudgeted() { fResource->makeBudgeted(); } 76 void makeBudgeted() { fResource->makeBudgeted(); }
72 77
73 /** 78 /**
79 * If the resource is cached make it uncached. Has no effect on resources th at are wrapped or
80 * already uncached. Furthermore, resources with content keys cannot be made unbudgeted.
81 */
82 void makeUnbudgeted() { fResource->makeUnbudgeted(); }
83
84 /**
74 * Called by the cache to delete the resource under normal circumstances. 85 * Called by the cache to delete the resource under normal circumstances.
75 */ 86 */
76 void release() { 87 void release() {
77 fResource->release(); 88 fResource->release();
78 if (fResource->isPurgable()) { 89 if (fResource->isPurgable()) {
79 SkDELETE(fResource); 90 SkDELETE(fResource);
80 } 91 }
81 } 92 }
82 93
83 /** 94 /**
(...skipping 20 matching lines...) Expand all
104 friend class GrGpuResource; // to construct/copy this type. 115 friend class GrGpuResource; // to construct/copy this type.
105 }; 116 };
106 117
107 inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAcc ess(this); } 118 inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAcc ess(this); }
108 119
109 inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const { 120 inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const {
110 return CacheAccess(const_cast<GrGpuResource*>(this)); 121 return CacheAccess(const_cast<GrGpuResource*>(this));
111 } 122 }
112 123
113 #endif 124 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698