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

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

Issue 1217573002: remove SkInstCnt (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 5 years, 5 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 #include "SkInstCnt.h"
15 14
16 class GrContext; 15 class GrContext;
17 class GrGpu; 16 class GrGpu;
18 class GrResourceCache; 17 class GrResourceCache;
19 18
20 /** 19 /**
21 * Base class for GrGpuResource. Handles the various types of refs we need. Sepa rated out as a base 20 * 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 21 * class to isolate the ref-cnting behavior and provide friendship without expos ing all of
23 * GrGpuResource. 22 * GrGpuResource.
24 * 23 *
(...skipping 14 matching lines...) Expand all
39 * the ref cnt to reach zero and the other counts are zero, notifyRefCountIsZero () will be called 38 * the ref cnt to reach zero and the other counts are zero, notifyRefCountIsZero () will be called
40 * before notifyIsPurgeable(). Moreover, if notifyRefCountIsZero() returns false then 39 * before notifyIsPurgeable(). Moreover, if notifyRefCountIsZero() returns false then
41 * notifyAllRefCntsAreZero() won't be called at all. notifyRefCountIsZero() must return false if the 40 * notifyAllRefCntsAreZero() won't be called at all. notifyRefCountIsZero() must return false if the
42 * object may be deleted after notifyRefCntIsZero() returns. 41 * object may be deleted after notifyRefCntIsZero() returns.
43 * 42 *
44 * GrIORef and GrGpuResource are separate classes for organizational reasons and to be 43 * GrIORef and GrGpuResource are separate classes for organizational reasons and to be
45 * able to give access via friendship to only the functions related to pending I O operations. 44 * able to give access via friendship to only the functions related to pending I O operations.
46 */ 45 */
47 template <typename DERIVED> class GrIORef : public SkNoncopyable { 46 template <typename DERIVED> class GrIORef : public SkNoncopyable {
48 public: 47 public:
49 SK_DECLARE_INST_COUNT(GrIORef)
50
51 // Some of the signatures are written to mirror SkRefCnt so that GrGpuResour ce can work with 48 // Some of the signatures are written to mirror SkRefCnt so that GrGpuResour ce can work with
52 // templated helper classes (e.g. SkAutoTUnref). However, we have different categories of 49 // templated helper classes (e.g. SkAutoTUnref). However, we have different categories of
53 // refs (e.g. pending reads). We also don't require thread safety as GrCache able objects are 50 // refs (e.g. pending reads). We also don't require thread safety as GrCache able objects are
54 // not intended to cross thread boundaries. 51 // not intended to cross thread boundaries.
55 void ref() const { 52 void ref() const {
56 this->validate(); 53 this->validate();
57 ++fRefCnt; 54 ++fRefCnt;
58 } 55 }
59 56
60 void unref() const { 57 void unref() const {
61 this->validate(); 58 this->validate();
62 59
63 if (!(--fRefCnt)) { 60 if (!(--fRefCnt)) {
64 if (!static_cast<const DERIVED*>(this)->notifyRefCountIsZero()) { 61 if (!static_cast<const DERIVED*>(this)->notifyRefCountIsZero()) {
65 return; 62 return;
66 } 63 }
67 } 64 }
68 65
69 this->didRemoveRefOrPendingIO(kRef_CntType); 66 this->didRemoveRefOrPendingIO(kRef_CntType);
70 } 67 }
71 68
72 void validate() const { 69 void validate() const {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 friend class GrResourceCache; // to check IO ref counts. 131 friend class GrResourceCache; // to check IO ref counts.
135 132
136 template <typename, GrIOType> friend class GrPendingIOResource; 133 template <typename, GrIOType> friend class GrPendingIOResource;
137 }; 134 };
138 135
139 /** 136 /**
140 * Base class for objects that can be kept in the GrResourceCache. 137 * Base class for objects that can be kept in the GrResourceCache.
141 */ 138 */
142 class SK_API GrGpuResource : public GrIORef<GrGpuResource> { 139 class SK_API GrGpuResource : public GrIORef<GrGpuResource> {
143 public: 140 public:
144 SK_DECLARE_INST_COUNT(GrGpuResource) 141
145 142
146 enum LifeCycle { 143 enum LifeCycle {
147 /** 144 /**
148 * The resource is cached and owned by Skia. Resources with this status may be kept alive 145 * The resource is cached and owned by Skia. Resources with this status may be kept alive
149 * by the cache as either scratch or unique resources even when there ar e no refs to them. 146 * by the cache as either scratch or unique resources even when there ar e no refs to them.
150 * The cache may release them whenever there are no refs. 147 * The cache may release them whenever there are no refs.
151 */ 148 */
152 kCached_LifeCycle, 149 kCached_LifeCycle,
153 150
154 /** 151 /**
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 LifeCycle fLifeCycle; 330 LifeCycle fLifeCycle;
334 const uint32_t fUniqueID; 331 const uint32_t fUniqueID;
335 332
336 SkAutoTUnref<const SkData> fData; 333 SkAutoTUnref<const SkData> fData;
337 334
338 typedef GrIORef<GrGpuResource> INHERITED; 335 typedef GrIORef<GrGpuResource> INHERITED;
339 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n otifyRefCntIsZero. 336 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n otifyRefCntIsZero.
340 }; 337 };
341 338
342 #endif 339 #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