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

Side by Side Diff: src/gpu/GrGpuResource.cpp

Issue 858123002: Add specialized content key class for resources. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove default template arg 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
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrGpuResourceCacheAccess.h » ('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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 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 #include "GrGpuResource.h" 9 #include "GrGpuResource.h"
10 #include "GrResourceCache2.h" 10 #include "GrResourceCache2.h"
11 #include "GrGpu.h" 11 #include "GrGpu.h"
12 12
13 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) { 13 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) {
14 SkASSERT(gpu); 14 SkASSERT(gpu);
15 SkASSERT(gpu->getContext()); 15 SkASSERT(gpu->getContext());
16 SkASSERT(gpu->getContext()->getResourceCache2()); 16 SkASSERT(gpu->getContext()->getResourceCache2());
17 return gpu->getContext()->getResourceCache2(); 17 return gpu->getContext()->getResourceCache2();
18 } 18 }
19 19
20 GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle) 20 GrGpuResource::GrGpuResource(GrGpu* gpu, LifeCycle lifeCycle)
21 : fGpu(gpu) 21 : fGpu(gpu)
22 , fGpuMemorySize(kInvalidGpuMemorySize) 22 , fGpuMemorySize(kInvalidGpuMemorySize)
23 , fFlags(0)
24 , fLifeCycle(lifeCycle) 23 , fLifeCycle(lifeCycle)
25 , fUniqueID(CreateUniqueID()) { 24 , fUniqueID(CreateUniqueID()) {
26 } 25 }
27 26
28 void GrGpuResource::registerWithCache() { 27 void GrGpuResource::registerWithCache() {
29 get_resource_cache2(fGpu)->resourceAccess().insertResource(this); 28 get_resource_cache2(fGpu)->resourceAccess().insertResource(this);
30 } 29 }
31 30
32 GrGpuResource::~GrGpuResource() { 31 GrGpuResource::~GrGpuResource() {
33 // The cache should have released or destroyed this resource. 32 // The cache should have released or destroyed this resource.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 if (this->wasDestroyed()) { 75 if (this->wasDestroyed()) {
77 return; 76 return;
78 } 77 }
79 78
80 size_t oldSize = fGpuMemorySize; 79 size_t oldSize = fGpuMemorySize;
81 SkASSERT(kInvalidGpuMemorySize != oldSize); 80 SkASSERT(kInvalidGpuMemorySize != oldSize);
82 fGpuMemorySize = kInvalidGpuMemorySize; 81 fGpuMemorySize = kInvalidGpuMemorySize;
83 get_resource_cache2(fGpu)->resourceAccess().didChangeGpuMemorySize(this, old Size); 82 get_resource_cache2(fGpu)->resourceAccess().didChangeGpuMemorySize(this, old Size);
84 } 83 }
85 84
86 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) { 85 bool GrGpuResource::setContentKey(const GrContentKey& key) {
87 // Currently this can only be called once and can't be called when the resou rce is scratch. 86 // Currently this can only be called once and can't be called when the resou rce is scratch.
88 SkASSERT(this->internalHasRef()); 87 SkASSERT(this->internalHasRef());
89 88
90 // Wrapped resources can never have a key. 89 // Wrapped resources can never have a key.
91 if (this->isWrapped()) { 90 if (this->isWrapped()) {
92 return false; 91 return false;
93 } 92 }
94 93
95 if ((fFlags & kContentKeySet_Flag) || this->wasDestroyed()) { 94 if (fContentKey.isValid() || this->wasDestroyed()) {
96 return false; 95 return false;
97 } 96 }
98 97
99 fContentKey = contentKey; 98 fContentKey = key;
100 fFlags |= kContentKeySet_Flag;
101 99
102 if (!get_resource_cache2(fGpu)->resourceAccess().didSetContentKey(this)) { 100 if (!get_resource_cache2(fGpu)->resourceAccess().didSetContentKey(this)) {
103 fFlags &= ~kContentKeySet_Flag; 101 fContentKey.reset();
104 return false; 102 return false;
105 } 103 }
106 return true; 104 return true;
107 } 105 }
108 106
109 void GrGpuResource::notifyIsPurgable() const { 107 void GrGpuResource::notifyIsPurgable() const {
110 if (this->wasDestroyed()) { 108 if (this->wasDestroyed()) {
111 // We've already been removed from the cache. Goodbye cruel world! 109 // We've already been removed from the cache. Goodbye cruel world!
112 SkDELETE(this); 110 SkDELETE(this);
113 } else { 111 } else {
(...skipping 27 matching lines...) Expand all
141 } 139 }
142 140
143 uint32_t GrGpuResource::CreateUniqueID() { 141 uint32_t GrGpuResource::CreateUniqueID() {
144 static int32_t gUniqueID = SK_InvalidUniqueID; 142 static int32_t gUniqueID = SK_InvalidUniqueID;
145 uint32_t id; 143 uint32_t id;
146 do { 144 do {
147 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); 145 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
148 } while (id == SK_InvalidUniqueID); 146 } while (id == SK_InvalidUniqueID);
149 return id; 147 return id;
150 } 148 }
OLDNEW
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrGpuResourceCacheAccess.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698