OLD | NEW |
---|---|
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 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) | 21 GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped) |
22 : fGpu(gpu) | 22 : fGpu(gpu) |
23 , fGpuMemorySize(kInvalidGpuMemorySize) | 23 , fGpuMemorySize(kInvalidGpuMemorySize) |
24 , fUniqueID(CreateUniqueID()) | 24 , fUniqueID(CreateUniqueID()) |
25 , fScratchKey(GrResourceKey::NullScratchKey()) | 25 , fScratchKey(GrResourceKey::NullScratchKey()) { |
egdaniel
2014/11/13 20:47:31
extra space
bsalomon
2014/11/13 20:53:33
Done.
| |
26 , fContentKeySet(false) { | |
27 if (isWrapped) { | 26 if (isWrapped) { |
28 fFlags = kWrapped_FlagBit; | 27 fFlags = kWrapped_Flag; |
29 } else { | 28 } else { |
30 fFlags = 0; | 29 // By default all non-wrapped resources are budgeted. |
30 fFlags = kBudgeted_Flag; | |
31 } | 31 } |
32 | |
egdaniel
2014/11/13 20:47:32
Extra \n added
bsalomon
2014/11/13 20:53:34
Done.
| |
32 } | 33 } |
33 | 34 |
34 void GrGpuResource::registerWithCache() { | 35 void GrGpuResource::registerWithCache() { |
35 get_resource_cache2(fGpu)->resourceAccess().insertResource(this); | 36 get_resource_cache2(fGpu)->resourceAccess().insertResource(this); |
36 } | 37 } |
37 | 38 |
38 GrGpuResource::~GrGpuResource() { | 39 GrGpuResource::~GrGpuResource() { |
39 // subclass should have released this. | 40 // subclass should have released this. |
40 SkASSERT(this->wasDestroyed()); | 41 SkASSERT(this->wasDestroyed()); |
41 } | 42 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) { | 89 bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) { |
89 // Currently this can only be called once and can't be called when the resou rce is scratch. | 90 // Currently this can only be called once and can't be called when the resou rce is scratch. |
90 SkASSERT(!contentKey.isScratch()); | 91 SkASSERT(!contentKey.isScratch()); |
91 SkASSERT(this->internalHasRef()); | 92 SkASSERT(this->internalHasRef()); |
92 | 93 |
93 // Wrapped resources can never have a key. | 94 // Wrapped resources can never have a key. |
94 if (this->isWrapped()) { | 95 if (this->isWrapped()) { |
95 return false; | 96 return false; |
96 } | 97 } |
97 | 98 |
98 if (fContentKeySet) { | 99 if (fFlags & kContentKeySet_Flag) { |
99 return false; | 100 return false; |
100 } | 101 } |
101 | 102 |
102 fContentKey = contentKey; | 103 fContentKey = contentKey; |
103 fContentKeySet = true; | 104 fFlags |= kContentKeySet_Flag; |
104 | 105 |
105 if (!get_resource_cache2(fGpu)->resourceAccess().didSetContentKey(this)) { | 106 if (!get_resource_cache2(fGpu)->resourceAccess().didSetContentKey(this)) { |
106 fContentKeySet = false; | 107 fFlags &= ~kContentKeySet_Flag; |
107 return false; | 108 return false; |
108 } | 109 } |
109 return true; | 110 return true; |
110 } | 111 } |
111 | 112 |
112 void GrGpuResource::notifyIsPurgable() const { | 113 void GrGpuResource::notifyIsPurgable() const { |
113 if (!this->wasDestroyed()) { | 114 if (!this->wasDestroyed()) { |
114 get_resource_cache2(fGpu)->resourceAccess().notifyPurgable(this); | 115 get_resource_cache2(fGpu)->resourceAccess().notifyPurgable(this); |
115 } | 116 } |
116 } | 117 } |
117 | 118 |
118 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { | 119 void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { |
119 SkASSERT(fScratchKey.isNullScratch()); | 120 SkASSERT(fScratchKey.isNullScratch()); |
120 SkASSERT(scratchKey.isScratch()); | 121 SkASSERT(scratchKey.isScratch()); |
121 SkASSERT(!scratchKey.isNullScratch()); | 122 SkASSERT(!scratchKey.isNullScratch()); |
122 // Wrapped resources can never have a key. | 123 // Wrapped resources can never have a key. |
123 if (this->isWrapped()) { | 124 if (this->cacheAccess().isWrapped()) { |
bsalomon
2014/11/13 19:20:54
This is unnecessary. Will revert before submitting
| |
124 return; | 125 return; |
125 } | 126 } |
126 fScratchKey = scratchKey; | 127 fScratchKey = scratchKey; |
127 } | 128 } |
128 | 129 |
129 uint32_t GrGpuResource::CreateUniqueID() { | 130 uint32_t GrGpuResource::CreateUniqueID() { |
130 static int32_t gUniqueID = SK_InvalidUniqueID; | 131 static int32_t gUniqueID = SK_InvalidUniqueID; |
131 uint32_t id; | 132 uint32_t id; |
132 do { | 133 do { |
133 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 134 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
134 } while (id == SK_InvalidUniqueID); | 135 } while (id == SK_InvalidUniqueID); |
135 return id; | 136 return id; |
136 } | 137 } |
138 | |
139 void GrGpuResource::setBudgeted(bool countsAgainstBudget) { | |
140 // Wrapped resources never count against the budget, nothing to do. No point in changing the | |
141 // budgeting of destroyed resources. | |
142 if (this->isWrapped() || this->wasDestroyed()) { | |
143 return; | |
144 } | |
145 | |
146 uint32_t oldFlags = fFlags; | |
147 if (countsAgainstBudget) { | |
148 fFlags |= kBudgeted_Flag; | |
149 } else { | |
150 fFlags &= ~kBudgeted_Flag; | |
151 } | |
152 if (fFlags != oldFlags) { | |
153 get_resource_cache2(fGpu)->resourceAccess().didChangeBudgetStatus(this); | |
154 } | |
155 } | |
OLD | NEW |