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

Side by Side Diff: include/private/GrSurfaceProxy.h

Issue 2502923003: Add IORef capability to GrSurfaceProxy objects - take 2 (Closed)
Patch Set: Fixed bug in transferRefs Created 4 years, 1 month 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/GrGpuResource.h ('k') | src/gpu/GrSurfaceProxy.cpp » ('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 2016 Google Inc. 2 * Copyright 2016 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 GrSurfaceProxy_DEFINED 8 #ifndef GrSurfaceProxy_DEFINED
9 #define GrSurfaceProxy_DEFINED 9 #define GrSurfaceProxy_DEFINED
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 if (!(--fRefCnt)) { 43 if (!(--fRefCnt)) {
44 delete this; 44 delete this;
45 return; 45 return;
46 } 46 }
47 47
48 this->validate(); 48 this->validate();
49 } 49 }
50 50
51 void validate() const { 51 void validate() const {
52 #ifdef SK_DEBUG 52 #ifdef SK_DEBUG
53 SkASSERT(fRefCnt >= 0); 53 SkASSERT(fRefCnt >= 1);
54 SkASSERT(fPendingReads >= 0);
55 SkASSERT(fPendingWrites >= 0);
56 SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 1);
57
58 if (fTarget) {
59 SkASSERT(!fPendingReads && !fPendingWrites);
60 // The backing GrSurface can have more refs than the proxy if the pr oxy
61 // started off wrapping an external resource (that came in with refs ).
62 // The GrSurface should never have fewer refs than the proxy however .
63 SkASSERT(fTarget->fRefCnt >= fRefCnt);
64 }
54 #endif 65 #endif
55 } 66 }
56 67
68 int32_t getProxyRefCnt_TestOnly() const;
69 int32_t getBackingRefCnt_TestOnly() const;
70 int32_t getPendingReadCnt_TestOnly() const;
71 int32_t getPendingWriteCnt_TestOnly() const;
72
57 protected: 73 protected:
58 GrIORefProxy() : fRefCnt(1), fTarget(nullptr) {} 74 GrIORefProxy() : fTarget(nullptr), fRefCnt(1), fPendingReads(0), fPendingWri tes(0) {}
59 GrIORefProxy(sk_sp<GrSurface> surface) : fRefCnt(1) { 75 GrIORefProxy(sk_sp<GrSurface> surface) : fRefCnt(1), fPendingReads(0), fPend ingWrites(0) {
60 // Since we're manually forwarding on refs & unrefs we don't want sk_sp doing 76 // Since we're manually forwarding on refs & unrefs we don't want sk_sp doing
61 // anything extra. 77 // anything extra.
62 fTarget = surface.release(); 78 fTarget = surface.release();
63 } 79 }
64 virtual ~GrIORefProxy() { 80 virtual ~GrIORefProxy() {
65 // We don't unref 'fTarget' here since the 'unref' method will already 81 // We don't unref 'fTarget' here since the 'unref' method will already
66 // have forwarded on the unref call that got use here. 82 // have forwarded on the unref call that got use here.
67 } 83 }
68 84
69 // TODO: add the IO ref counts. Although if we can delay shader creation to flush time 85 // This GrIORefProxy was deferred before but has just been instantiated. To
70 // we may not even need to do that. 86 // make all the reffing & unreffing work out we now need to transfer any def erred
71 mutable int32_t fRefCnt; 87 // refs & unrefs to the new GrSurface
88 void transferRefs() {
89 SkASSERT(fTarget);
90
91 fTarget->fRefCnt += (fRefCnt-1); // don't xfer the proxy's creation ref
92 fTarget->fPendingReads += fPendingReads;
93 fTarget->fPendingWrites += fPendingWrites;
94
95 fPendingReads = 0;
96 fPendingWrites = 0;
97 }
72 98
73 // For deferred proxies this will be null. For wrapped proxies it will point to the 99 // For deferred proxies this will be null. For wrapped proxies it will point to the
74 // wrapped resource. 100 // wrapped resource.
75 GrSurface* fTarget; 101 GrSurface* fTarget;
102
103 private:
104 // This class is used to manage conversion of refs to pending reads/writes.
105 friend class GrGpuResourceRef;
106 template <typename, GrIOType> friend class GrPendingIOResource;
107
108 void addPendingRead() const {
109 this->validate();
110
111 if (fTarget) {
112 fTarget->addPendingRead();
113 return;
114 }
115
116 ++fPendingReads;
117 }
118
119 void completedRead() const {
120 this->validate();
121
122 if (fTarget) {
123 fTarget->completedRead();
124 return;
125 }
126
127 SkFAIL("How was the read completed if the Proxy hasn't been instantiated ?");
128 }
129
130 void addPendingWrite() const {
131 this->validate();
132
133 if (fTarget) {
134 fTarget->addPendingWrite();
135 return;
136 }
137
138 ++fPendingWrites;
139 }
140
141 void completedWrite() const {
142 this->validate();
143
144 if (fTarget) {
145 fTarget->completedWrite();
146 return;
147 }
148
149 SkFAIL("How was the write completed if the Proxy hasn't been instantiate d?");
150 }
151
152 mutable int32_t fRefCnt;
153 mutable int32_t fPendingReads;
154 mutable int32_t fPendingWrites;
76 }; 155 };
77 156
78 class GrSurfaceProxy : public GrIORefProxy { 157 class GrSurfaceProxy : public GrIORefProxy {
79 public: 158 public:
80 static sk_sp<GrSurfaceProxy> MakeWrapped(sk_sp<GrSurface>); 159 static sk_sp<GrSurfaceProxy> MakeWrapped(sk_sp<GrSurface>);
81 160
82 static sk_sp<GrSurfaceProxy> MakeDeferred(const GrCaps&, const GrSurfaceDesc &, 161 static sk_sp<GrSurfaceProxy> MakeDeferred(const GrCaps&, const GrSurfaceDesc &,
83 SkBackingFit, SkBudgeted); 162 SkBackingFit, SkBudgeted);
84 163
85 // TODO: need to refine ownership semantics of 'srcData' if we're in complet ely 164 // TODO: need to refine ownership semantics of 'srcData' if we're in complet ely
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // This back-pointer is required so that we can add a dependancy between 301 // This back-pointer is required so that we can add a dependancy between
223 // the opList used to create the current contents of this surface 302 // the opList used to create the current contents of this surface
224 // and the opList of a destination surface to which this one is being drawn or copied. 303 // and the opList of a destination surface to which this one is being drawn or copied.
225 GrOpList* fLastOpList; 304 GrOpList* fLastOpList;
226 305
227 306
228 typedef GrIORefProxy INHERITED; 307 typedef GrIORefProxy INHERITED;
229 }; 308 };
230 309
231 #endif 310 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrGpuResource.h ('k') | src/gpu/GrSurfaceProxy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698