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

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

Issue 716143004: Replace GrResourceCache with GrResourceCache2. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix asserts Created 6 years, 1 month 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 9
10 #include "GrGpuResource.h" 10 #include "GrGpuResource.h"
11 #include "GrResourceCache2.h" 11 #include "GrResourceCache2.h"
12 #include "GrGpu.h" 12 #include "GrGpu.h"
13 13
14 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) { 14 static inline GrResourceCache2* get_resource_cache2(GrGpu* gpu) {
15 SkASSERT(gpu); 15 SkASSERT(gpu);
16 SkASSERT(gpu->getContext()); 16 SkASSERT(gpu->getContext());
17 SkASSERT(gpu->getContext()->getResourceCache2()); 17 SkASSERT(gpu->getContext()->getResourceCache2());
18 return gpu->getContext()->getResourceCache2(); 18 return gpu->getContext()->getResourceCache2();
19 } 19 }
20 20
21 static inline GrResourceCache* get_resource_cache(GrGpu* gpu) {
22 SkASSERT(gpu);
23 SkASSERT(gpu->getContext());
24 SkASSERT(gpu->getContext()->getResourceCache());
25 return gpu->getContext()->getResourceCache();
26 }
27
28 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) 21 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped)
29 : fGpu(gpu) 22 : fGpu(gpu)
30 , fCacheEntry(NULL)
31 , fGpuMemorySize(kInvalidGpuMemorySize) 23 , fGpuMemorySize(kInvalidGpuMemorySize)
32 , fUniqueID(CreateUniqueID()) 24 , fUniqueID(CreateUniqueID())
33 , fScratchKey(GrResourceKey::NullScratchKey()) 25 , fScratchKey(GrResourceKey::NullScratchKey())
34 , fContentKeySet(false) { 26 , fContentKeySet(false) {
35 if (isWrapped) { 27 if (isWrapped) {
36 fFlags = kWrapped_FlagBit; 28 fFlags = kWrapped_FlagBit;
37 } else { 29 } else {
38 fFlags = 0; 30 fFlags = 0;
39 } 31 }
40 } 32 }
41 33
42 void GrGpuResource::registerWithCache() { 34 void GrGpuResource::registerWithCache() {
43 get_resource_cache2(fGpu)->insertResource(this); 35 get_resource_cache2(fGpu)->resourceAccess().insertResource(this);
44 } 36 }
45 37
46 GrGpuResource::~GrGpuResource() { 38 GrGpuResource::~GrGpuResource() {
47 // subclass should have released this. 39 // subclass should have released this.
48 SkASSERT(this->wasDestroyed()); 40 SkASSERT(this->wasDestroyed());
49 } 41 }
50 42
51 void GrGpuResource::release() { 43 void GrGpuResource::release() {
52 if (fGpu) { 44 if (fGpu) {
53 this->onRelease(); 45 this->onRelease();
54 get_resource_cache2(fGpu)->removeResource(this); 46 get_resource_cache2(fGpu)->resourceAccess().removeResource(this);
55 fGpu = NULL; 47 fGpu = NULL;
48 fGpuMemorySize = 0;
56 } 49 }
57 } 50 }
58 51
59 void GrGpuResource::abandon() { 52 void GrGpuResource::abandon() {
60 if (fGpu) { 53 if (fGpu) {
61 this->onAbandon(); 54 this->onAbandon();
62 get_resource_cache2(fGpu)->removeResource(this); 55 get_resource_cache2(fGpu)->resourceAccess().removeResource(this);
63 fGpu = NULL; 56 fGpu = NULL;
57 fGpuMemorySize = 0;
64 } 58 }
65 } 59 }
66 60
67 const GrContext* GrGpuResource::getContext() const { 61 const GrContext* GrGpuResource::getContext() const {
68 if (fGpu) { 62 if (fGpu) {
69 return fGpu->getContext(); 63 return fGpu->getContext();
70 } else { 64 } else {
71 return NULL; 65 return NULL;
72 } 66 }
73 } 67 }
74 68
75 GrContext* GrGpuResource::getContext() { 69 GrContext* GrGpuResource::getContext() {
76 if (fGpu) { 70 if (fGpu) {
77 return fGpu->getContext(); 71 return fGpu->getContext();
78 } else { 72 } else {
79 return NULL; 73 return NULL;
80 } 74 }
81 } 75 }
82 76
77 void GrGpuResource::didChangeGpuMemorySize() const {
78 if (this->wasDestroyed()) {
79 return;
80 }
81
82 size_t oldSize = fGpuMemorySize;
83 SkASSERT(kInvalidGpuMemorySize != oldSize);
84 fGpuMemorySize = kInvalidGpuMemorySize;
85 get_resource_cache2(fGpu)->resourceAccess().didChangeGpuMemorySize(this, old Size);
86 }
87
83 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) { 88 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) {
84 // Currently this can only be called once and can't be called when the resou rce is scratch. 89 // Currently this can only be called once and can't be called when the resou rce is scratch.
85 SkASSERT(!contentKey.isScratch()); 90 SkASSERT(!contentKey.isScratch());
86 SkASSERT(this->internalHasRef()); 91 SkASSERT(this->internalHasRef());
87 92
88 if (fContentKeySet) { 93 if (fContentKeySet) {
89 return false; 94 return false;
90 } 95 }
91 96
92 fContentKey = contentKey; 97 fContentKey = contentKey;
93 fContentKeySet = true; 98 fContentKeySet = true;
94 99
95 if (!get_resource_cache2(fGpu)->didSetContentKey(this)) { 100 if (!get_resource_cache2(fGpu)->resourceAccess().didSetContentKey(this)) {
96 fContentKeySet = false; 101 fContentKeySet = false;
97 return false; 102 return false;
98 } 103 }
99 return true; 104 return true;
100 } 105 }
101 106
102 void GrGpuResource::notifyIsPurgable() const { 107 void GrGpuResource::notifyIsPurgable() const {
103 if (fCacheEntry && !this->wasDestroyed()) { 108 if (!this->wasDestroyed()) {
104 get_resource_cache(fGpu)->notifyPurgable(this); 109 get_resource_cache2(fGpu)->resourceAccess().notifyPurgable(this);
105 } 110 }
106 } 111 }
107 112
108 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { 113 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) {
109 SkASSERT(fScratchKey.isNullScratch()); 114 SkASSERT(fScratchKey.isNullScratch());
110 SkASSERT(scratchKey.isScratch()); 115 SkASSERT(scratchKey.isScratch());
111 SkASSERT(!scratchKey.isNullScratch()); 116 SkASSERT(!scratchKey.isNullScratch());
112 fScratchKey = scratchKey; 117 fScratchKey = scratchKey;
113 } 118 }
114 119
115 uint32_t GrGpuResource::CreateUniqueID() { 120 uint32_t GrGpuResource::CreateUniqueID() {
116 static int32_t gUniqueID = SK_InvalidUniqueID; 121 static int32_t gUniqueID = SK_InvalidUniqueID;
117 uint32_t id; 122 uint32_t id;
118 do { 123 do {
119 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); 124 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
120 } while (id == SK_InvalidUniqueID); 125 } while (id == SK_InvalidUniqueID);
121 return id; 126 return id;
122 } 127 }
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