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

Side by Side Diff: include/gpu/GrGpuResource.h

Issue 1225923010: Refugee from Dead Machine 4: MDB Monster Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Last update from dead machine Created 4 years, 7 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 | « include/gpu/GrDrawContext.h ('k') | include/gpu/GrGpuResourceRef.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 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrGpuResource_DEFINED 8 #ifndef GrGpuResource_DEFINED
9 #define GrGpuResource_DEFINED 9 #define GrGpuResource_DEFINED
10 10
11 #include "GrResourceKey.h" 11 #include "GrResourceKey.h"
12 #include "GrTypesPriv.h" 12 #include "GrTypesPriv.h"
13 #include "SkData.h" 13 #include "SkData.h"
14 14
15 #include "GrDrawContext.h"
16
15 class GrContext; 17 class GrContext;
18 class GrDrawContext;
16 class GrGpu; 19 class GrGpu;
17 class GrResourceCache; 20 class GrResourceCache;
18 class SkTraceMemoryDump; 21 class SkTraceMemoryDump;
22 class GrRenderTarget;
23 class GrSurface;
24 class GrDrawTarget;
25 class GrGpuResource;
26
27 extern GrDrawTarget* getLastDT6(GrGpuResource* rt);
28
29 // Due to header woes
30 extern void addRequiredDep(GrDrawTarget* dst, GrDrawTarget* src);
19 31
20 /** 32 /**
21 * Base class for GrGpuResource. Handles the various types of refs we need. Sepa rated out as a base 33 * Base class for GrGpuResource. Handles the various types of refs we need. Sepa rated out as a base
22 * class to isolate the ref-cnting behavior and provide friendship without expos ing all of 34 * class to isolate the ref-cnting behavior and provide friendship without expos ing all of
23 * GrGpuResource. 35 * GrGpuResource.
24 * 36 *
25 * Gpu resources can have three types of refs: 37 * Gpu resources can have three types of refs:
26 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is suing draw calls 38 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is suing draw calls
27 * that read and write the resource via GrDrawTarget and by any object that must own a 39 * that read and write the resource via GrDrawTarget and by any object that must own a
28 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien t code. 40 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien t code.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 99
88 bool isPurgeable() const { return !this->internalHasRef() && !this->internal HasPendingIO(); } 100 bool isPurgeable() const { return !this->internalHasRef() && !this->internal HasPendingIO(); }
89 101
90 bool internalHasPendingRead() const { return SkToBool(fPendingReads); } 102 bool internalHasPendingRead() const { return SkToBool(fPendingReads); }
91 bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); } 103 bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); }
92 bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendin gReads); } 104 bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendin gReads); }
93 105
94 bool internalHasRef() const { return SkToBool(fRefCnt); } 106 bool internalHasRef() const { return SkToBool(fRefCnt); }
95 107
96 private: 108 private:
97 void addPendingRead() const { 109 void addPendingRead(const DERIVED* dst) const {
110 const DERIVED* src = static_cast<const DERIVED*>(this);
111 if ((const_cast<DERIVED*>(src))->arrgh()) {
112 SkASSERT(dst);
113 SkASSERT((const_cast<DERIVED*>(dst))->arrgh());
114
115 GrDrawTarget* dstDT = getLastDT6(const_cast<DERIVED*>(dst));
116 GrDrawTarget* srcDT = getLastDT6(const_cast<DERIVED*>(src));
117
118 SkASSERT(dstDT || !srcDT);
119
120 if (src->fromRawPixels2()) {
121 // adding a read on uploaded content
122 SkASSERT(!srcDT);
123 } else {
124 // adding a read on rendered content
125 if (srcDT) {
126 SkASSERT(dstDT);
127
128 if (dstDT == srcDT) {
129 // self-read - presumably for dst reads
130 } else {
131 addRequiredDep(dstDT, srcDT);
132 }
133 }
134 }
135 }
136
98 this->validate(); 137 this->validate();
99 ++fPendingReads; 138 ++fPendingReads;
100 } 139 }
101 140
102 void completedRead() const { 141 void completedRead() const {
103 this->validate(); 142 this->validate();
104 --fPendingReads; 143 --fPendingReads;
105 this->didRemoveRefOrPendingIO(kPendingRead_CntType); 144 this->didRemoveRefOrPendingIO(kPendingRead_CntType);
106 } 145 }
107 146
108 void addPendingWrite() const { 147 void addPendingWrite() const {
109 this->validate(); 148 this->validate();
110 ++fPendingWrites; 149 ++fPendingWrites;
111 } 150 }
112 151
113 void completedWrite() const { 152 void completedWrite() const {
114 this->validate(); 153 this->validate();
115 --fPendingWrites; 154 --fPendingWrites;
116 this->didRemoveRefOrPendingIO(kPendingWrite_CntType); 155 this->didRemoveRefOrPendingIO(kPendingWrite_CntType);
117 } 156 }
118 157
119 private: 158 private:
120 void didRemoveRefOrPendingIO(CntType cntTypeRemoved) const { 159 void didRemoveRefOrPendingIO(CntType cntTypeRemoved) const {
121 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) { 160 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) {
122 static_cast<const DERIVED*>(this)->notifyAllCntsAreZero(cntTypeRemov ed); 161 static_cast<const DERIVED*>(this)->notifyAllCntsAreZero(cntTypeRemov ed);
123 } 162 }
124 } 163 }
125 164
165 public:
126 mutable int32_t fRefCnt; 166 mutable int32_t fRefCnt;
127 mutable int32_t fPendingReads; 167 mutable int32_t fPendingReads;
128 mutable int32_t fPendingWrites; 168 mutable int32_t fPendingWrites;
129 169
130 // This class is used to manage conversion of refs to pending reads/writes. 170 // This class is used to manage conversion of refs to pending reads/writes.
131 friend class GrGpuResourceRef; 171 friend class GrGpuResourceRef;
132 friend class GrResourceCache; // to check IO ref counts. 172 friend class GrResourceCache; // to check IO ref counts.
133 173
134 template <typename, GrIOType> friend class GrPendingIOResource; 174 template <typename, GrIOType> friend class GrPendingIOResource;
135 }; 175 };
136 176
177
137 /** 178 /**
138 * Base class for objects that can be kept in the GrResourceCache. 179 * Base class for objects that can be kept in the GrResourceCache.
139 */ 180 */
140 class SK_API GrGpuResource : public GrIORef<GrGpuResource> { 181 class SK_API GrGpuResource : public GrIORef<GrGpuResource> {
141 public: 182 public:
183 enum Type2 {
184 kSurface,
185 kOther
186 };
142 187
188 public:
189
190 Type2 type1() const { return fType1; }
191 virtual GrRenderTarget* arrgh() = 0;
192
193 private:
194 // fFromRawPixels2, fException & fException2 are just for the alternate test ing system
195 mutable bool fFromRawPixels2;
196 mutable bool fException; // there are often textures from raw data which do not have a key
197 public:
198 mutable bool fException2; // yuv textures have a key but have been rendered to
199 // as have CMM alpha masks
200
201 void validate() const {
202 if (fException) {
203 SkASSERT(fFromRawPixels2);
204 }
205 if (!fFromRawPixels2) {
206 SkASSERT(!fException); // can't be an exception w/o being from raw pixels
207 }
208 }
209
210 bool fromRawPixels2() const {
211 this->validate();
212 return fFromRawPixels2;
213 }
214
215 void setFromRawPixels(bool fromRawPixels) const {
216 this->validate();
217
218 fFromRawPixels2 = fromRawPixels;
219
220 this->validate();
221 }
222
223 bool exception() const { return fException; }
224
225 void setException(bool exception) {
226 this->validate();
227 fException = exception;
228 this->validate();
229 }
143 230
144 enum LifeCycle { 231 enum LifeCycle {
145 /** 232 /**
146 * The resource is cached and owned by Skia. Resources with this status may be kept alive 233 * The resource is cached and owned by Skia. Resources with this status may be kept alive
147 * by the cache as either scratch or unique resources even when there ar e no refs to them. 234 * by the cache as either scratch or unique resources even when there ar e no refs to them.
148 * The cache may release them whenever there are no refs. 235 * The cache may release them whenever there are no refs.
149 */ 236 */
150 kCached_LifeCycle, 237 kCached_LifeCycle,
151 238
152 /** 239 /**
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 * Typically, subclasses should not need to override this, and should only 345 * Typically, subclasses should not need to override this, and should only
259 * need to override setMemoryBacking. 346 * need to override setMemoryBacking.
260 **/ 347 **/
261 virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const; 348 virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
262 349
263 protected: 350 protected:
264 // This must be called by every GrGpuObject. It should be called once the ob ject is fully 351 // This must be called by every GrGpuObject. It should be called once the ob ject is fully
265 // initialized (i.e. not in a base class constructor). 352 // initialized (i.e. not in a base class constructor).
266 void registerWithCache(); 353 void registerWithCache();
267 354
268 GrGpuResource(GrGpu*, LifeCycle); 355 GrGpuResource(GrGpu*, LifeCycle, Type2);
269 virtual ~GrGpuResource(); 356 virtual ~GrGpuResource();
270 357
271 GrGpu* getGpu() const { return fGpu; } 358 GrGpu* getGpu() const { return fGpu; }
272 359
273 /** Overridden to free GPU resources in the backend API. */ 360 /** Overridden to free GPU resources in the backend API. */
274 virtual void onRelease() { } 361 virtual void onRelease() { }
275 /** Overridden to abandon any internal handles, ptrs, etc to backend API res ources. 362 /** Overridden to abandon any internal handles, ptrs, etc to backend API res ources.
276 This may be called when the underlying 3D context is no longer valid and so no 363 This may be called when the underlying 3D context is no longer valid and so no
277 backend API calls should be made. */ 364 backend API calls should be made. */
278 virtual void onAbandon() { } 365 virtual void onAbandon() { }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // This is not ref'ed but abandon() or release() will be called before the G rGpu object 426 // This is not ref'ed but abandon() or release() will be called before the G rGpu object
340 // is destroyed. Those calls set will this to NULL. 427 // is destroyed. Those calls set will this to NULL.
341 GrGpu* fGpu; 428 GrGpu* fGpu;
342 mutable size_t fGpuMemorySize; 429 mutable size_t fGpuMemorySize;
343 430
344 LifeCycle fLifeCycle; 431 LifeCycle fLifeCycle;
345 const uint32_t fUniqueID; 432 const uint32_t fUniqueID;
346 433
347 SkAutoTUnref<const SkData> fData; 434 SkAutoTUnref<const SkData> fData;
348 435
436 Type2 fType1;
437
349 typedef GrIORef<GrGpuResource> INHERITED; 438 typedef GrIORef<GrGpuResource> INHERITED;
350 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n otifyRefCntIsZero. 439 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n otifyRefCntIsZero.
351 }; 440 };
352 441
353 #endif 442 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrDrawContext.h ('k') | include/gpu/GrGpuResourceRef.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698