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, LifeCycle lifeCycle) |
22 : fGpu(gpu) | 22 : fGpu(gpu) |
23 , fGpuMemorySize(kInvalidGpuMemorySize) | 23 , fGpuMemorySize(kInvalidGpuMemorySize) |
| 24 , fFlags(0) |
| 25 , fLifeCycle(lifeCycle) |
24 , fUniqueID(CreateUniqueID()) { | 26 , fUniqueID(CreateUniqueID()) { |
25 if (isWrapped) { | |
26 fFlags = kWrapped_Flag; | |
27 } else { | |
28 // By default all non-wrapped resources are budgeted. | |
29 fFlags = kBudgeted_Flag; | |
30 } | |
31 } | 27 } |
32 | 28 |
33 void GrGpuResource::registerWithCache() { | 29 void GrGpuResource::registerWithCache() { |
34 get_resource_cache2(fGpu)->resourceAccess().insertResource(this); | 30 get_resource_cache2(fGpu)->resourceAccess().insertResource(this); |
35 } | 31 } |
36 | 32 |
37 GrGpuResource::~GrGpuResource() { | 33 GrGpuResource::~GrGpuResource() { |
38 // The cache should have released or destroyed this resource. | 34 // The cache should have released or destroyed this resource. |
39 SkASSERT(this->wasDestroyed()); | 35 SkASSERT(this->wasDestroyed()); |
40 } | 36 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 135 } |
140 | 136 |
141 uint32_t GrGpuResource::CreateUniqueID() { | 137 uint32_t GrGpuResource::CreateUniqueID() { |
142 static int32_t gUniqueID = SK_InvalidUniqueID; | 138 static int32_t gUniqueID = SK_InvalidUniqueID; |
143 uint32_t id; | 139 uint32_t id; |
144 do { | 140 do { |
145 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 141 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
146 } while (id == SK_InvalidUniqueID); | 142 } while (id == SK_InvalidUniqueID); |
147 return id; | 143 return id; |
148 } | 144 } |
149 | |
150 void GrGpuResource::setBudgeted(bool countsAgainstBudget) { | |
151 // Wrapped resources never count against the budget, nothing to do. No point
in changing the | |
152 // budgeting of destroyed resources. | |
153 if (this->isWrapped() || this->wasDestroyed()) { | |
154 return; | |
155 } | |
156 | |
157 uint32_t oldFlags = fFlags; | |
158 if (countsAgainstBudget) { | |
159 fFlags |= kBudgeted_Flag; | |
160 } else { | |
161 fFlags &= ~kBudgeted_Flag; | |
162 } | |
163 if (fFlags != oldFlags) { | |
164 get_resource_cache2(fGpu)->resourceAccess().didChangeBudgetStatus(this); | |
165 } | |
166 } | |
OLD | NEW |