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

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

Issue 611383003: Revert of GrResourceCache2 manages scratch texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@surfimpl
Patch Set: Created 6 years, 2 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/GrContext.h ('k') | include/gpu/GrTexture.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
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 kWrite_IOType, 42 kWrite_IOType,
43 kRW_IOType 43 kRW_IOType
44 }; 44 };
45 45
46 virtual ~GrIORef(); 46 virtual ~GrIORef();
47 47
48 // 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
49 // 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
50 // 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
51 // not intended to cross thread boundaries. 51 // not intended to cross thread boundaries.
52 // internal_dispose() exists because of GrTexture's reliance on it. It will be removed
53 // soon.
52 void ref() const { 54 void ref() const {
55 ++fRefCnt;
56 // pre-validate once internal_dispose is removed (and therefore 0 ref cn t is not allowed).
53 this->validate(); 57 this->validate();
54 ++fRefCnt;
55 } 58 }
56 59
57 void unref() const { 60 void unref() const {
58 this->validate(); 61 this->validate();
59 --fRefCnt; 62 --fRefCnt;
60 if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) { 63 if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) {
61 SkDELETE(this); 64 this->internal_dispose();
62 } 65 }
63 } 66 }
64 67
65 bool isPurgable() const { return this->reffedOnlyByCache() && !this->interna lHasPendingIO(); } 68 virtual void internal_dispose() const { SkDELETE(this); }
66 bool reffedOnlyByCache() const { return 1 == fRefCnt; } 69
70 /** This is exists to service the old mechanism for recycling scratch textur es. It will
71 be removed soon. */
72 bool unique() const { return 1 == (fRefCnt + fPendingReads + fPendingWrites) ; }
67 73
68 void validate() const { 74 void validate() const {
69 #ifdef SK_DEBUG 75 #ifdef SK_DEBUG
70 SkASSERT(fRefCnt >= 0); 76 SkASSERT(fRefCnt >= 0);
71 SkASSERT(fPendingReads >= 0); 77 SkASSERT(fPendingReads >= 0);
72 SkASSERT(fPendingWrites >= 0); 78 SkASSERT(fPendingWrites >= 0);
73 SkASSERT(fRefCnt + fPendingReads + fPendingWrites > 0); 79 SkASSERT(fRefCnt + fPendingReads + fPendingWrites > 0);
74 #endif 80 #endif
75 } 81 }
76 82
83
77 protected: 84 protected:
78 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0), fIsScratch(kNo_ IsScratch) { } 85 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) {}
79 86
80 bool internalHasPendingRead() const { return SkToBool(fPendingReads); } 87 bool internalHasPendingRead() const { return SkToBool(fPendingReads); }
81 bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); } 88 bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); }
82 bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendin gReads); } 89 bool internalHasPendingIO() const { return SkToBool(fPendingWrites | fPendin gReads); }
83 90
84 private: 91 private:
85 void addPendingRead() const { 92 void addPendingRead() const {
86 this->validate(); 93 this->validate();
87 ++fPendingReads; 94 ++fPendingReads;
88 } 95 }
89 96
90 void completedRead() const { 97 void completedRead() const {
91 this->validate(); 98 this->validate();
92 --fPendingReads; 99 --fPendingReads;
93 if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) { 100 if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) {
94 SkDELETE(this); 101 this->internal_dispose();
95 } 102 }
96 } 103 }
97 104
98 void addPendingWrite() const { 105 void addPendingWrite() const {
99 this->validate(); 106 this->validate();
100 ++fPendingWrites; 107 ++fPendingWrites;
101 } 108 }
102 109
103 void completedWrite() const { 110 void completedWrite() const {
104 this->validate(); 111 this->validate();
105 --fPendingWrites; 112 --fPendingWrites;
106 if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) { 113 if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) {
107 SkDELETE(this); 114 this->internal_dispose();
108 } 115 }
109 } 116 }
110 117
111 private: 118 private:
112 mutable int32_t fRefCnt; 119 mutable int32_t fRefCnt;
113 mutable int32_t fPendingReads; 120 mutable int32_t fPendingReads;
114 mutable int32_t fPendingWrites; 121 mutable int32_t fPendingWrites;
115 122
116 // This class is used to manage conversion of refs to pending reads/writes. 123 // This class is used to manage conversion of refs to pending reads/writes.
117 friend class GrGpuResourceRef; 124 friend class GrGpuResourceRef;
118
119 // This is temporary until GrResourceCache is fully replaced by GrResourceCa che2.
120 enum IsScratch {
121 kNo_IsScratch,
122 kYes_IsScratch
123 } fIsScratch;
124
125 friend class GrContext; // to set the above field.
126 friend class GrResourceCache; // to check the above field.
127 friend class GrResourceCache2; // to check the above field.
128
129 template <typename, IOType> friend class GrPendingIOResource; 125 template <typename, IOType> friend class GrPendingIOResource;
130 }; 126 };
131 127
132 /** 128 /**
133 * Base class for objects that can be kept in the GrResourceCache. 129 * Base class for objects that can be kept in the GrResourceCache.
134 */ 130 */
135 class GrGpuResource : public GrIORef { 131 class GrGpuResource : public GrIORef {
136 public: 132 public:
137 SK_DECLARE_INST_COUNT(GrGpuResource) 133 SK_DECLARE_INST_COUNT(GrGpuResource)
138 134
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 250
255 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache 251 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache
256 const uint32_t fUniqueID; 252 const uint32_t fUniqueID;
257 253
258 GrResourceKey fScratchKey; 254 GrResourceKey fScratchKey;
259 255
260 typedef GrIORef INHERITED; 256 typedef GrIORef INHERITED;
261 }; 257 };
262 258
263 #endif 259 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrContext.h ('k') | include/gpu/GrTexture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698