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

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

Issue 373603005: Remove GrEffectStage::DeferredStage (Closed) Base URL: https://skia.googlesource.com/skia.git@no_common
Patch Set: Created 6 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 | « no previous file | no next file » | 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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 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 10
(...skipping 13 matching lines...) Expand all
24 : fEffectRef(SkRef(effectRef)) { 24 : fEffectRef(SkRef(effectRef)) {
25 fCoordChangeMatrixSet = false; 25 fCoordChangeMatrixSet = false;
26 fVertexAttribIndices[0] = attrIndex0; 26 fVertexAttribIndices[0] = attrIndex0;
27 fVertexAttribIndices[1] = attrIndex1; 27 fVertexAttribIndices[1] = attrIndex1;
28 } 28 }
29 29
30 GrEffectStage(const GrEffectStage& other) { 30 GrEffectStage(const GrEffectStage& other) {
31 *this = other; 31 *this = other;
32 } 32 }
33 33
34 class DeferredStage;
35 // This constructor balances DeferredStage::saveFrom().
36 explicit GrEffectStage(const DeferredStage& deferredStage) {
37 deferredStage.restoreTo(this);
38 }
39
40 GrEffectStage& operator= (const GrEffectStage& other) { 34 GrEffectStage& operator= (const GrEffectStage& other) {
41 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; 35 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet;
42 if (other.fCoordChangeMatrixSet) { 36 if (other.fCoordChangeMatrixSet) {
43 fCoordChangeMatrix = other.fCoordChangeMatrix; 37 fCoordChangeMatrix = other.fCoordChangeMatrix;
44 } 38 }
45 fEffectRef.reset(SkRef(other.fEffectRef.get())); 39 fEffectRef.reset(SkRef(other.fEffectRef.get()));
46 memcpy(fVertexAttribIndices, other.fVertexAttribIndices, sizeof(fVertexA ttribIndices)); 40 memcpy(fVertexAttribIndices, other.fVertexAttribIndices, sizeof(fVertexA ttribIndices));
47 return *this; 41 return *this;
48 } 42 }
49 43
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 void restoreCoordChange(const SavedCoordChange& savedCoordChange) { 108 void restoreCoordChange(const SavedCoordChange& savedCoordChange) {
115 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet; 109 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet;
116 if (fCoordChangeMatrixSet) { 110 if (fCoordChangeMatrixSet) {
117 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; 111 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix;
118 } 112 }
119 SkASSERT(savedCoordChange.fEffectRef.get() == fEffectRef); 113 SkASSERT(savedCoordChange.fEffectRef.get() == fEffectRef);
120 SkDEBUGCODE(savedCoordChange.fEffectRef.reset(NULL);) 114 SkDEBUGCODE(savedCoordChange.fEffectRef.reset(NULL);)
121 } 115 }
122 116
123 /** 117 /**
124 * Used when storing a deferred GrDrawState. The DeferredStage allows resour ces owned by its
125 * GrEffect to be recycled through the cache.
126 */
127 class DeferredStage {
128 public:
129 DeferredStage() : fEffect(NULL) {
130 SkDEBUGCODE(fInitialized = false;)
131 }
132
133 ~DeferredStage() {
134 if (NULL != fEffect) {
135 fEffect->decDeferredRefCounts();
136 }
137 }
138
139 void saveFrom(const GrEffectStage& stage) {
140 SkASSERT(!fInitialized);
141 SkASSERT(NULL != stage.fEffectRef.get());
142 stage.fEffectRef->get()->incDeferredRefCounts();
143 fEffect = stage.fEffectRef->get();
144 fCoordChangeMatrixSet = stage.fCoordChangeMatrixSet;
145 if (fCoordChangeMatrixSet) {
146 fCoordChangeMatrix = stage.fCoordChangeMatrix;
147 }
148 fVertexAttribIndices[0] = stage.fVertexAttribIndices[0];
149 fVertexAttribIndices[1] = stage.fVertexAttribIndices[1];
150 SkDEBUGCODE(fInitialized = true;)
151 }
152
153 void restoreTo(GrEffectStage* stage) const {
154 SkASSERT(fInitialized);
155 stage->fEffectRef.reset(GrEffect::CreateEffectRef(fEffect));
156 stage->fCoordChangeMatrixSet = fCoordChangeMatrixSet;
157 if (fCoordChangeMatrixSet) {
158 stage->fCoordChangeMatrix = fCoordChangeMatrix;
159 }
160 stage->fVertexAttribIndices[0] = fVertexAttribIndices[0];
161 stage->fVertexAttribIndices[1] = fVertexAttribIndices[1];
162 }
163
164 bool isEqual(const GrEffectStage& stage, bool ignoreCoordChange) const {
165 if (fVertexAttribIndices[0] != stage.fVertexAttribIndices[0] ||
166 fVertexAttribIndices[1] != stage.fVertexAttribIndices[1]) {
167 return false;
168 }
169
170 if (!(*stage.getEffect())->isEqual(*fEffect)) {
171 return false;
172 }
173
174 if (ignoreCoordChange) {
175 // ignore the coordinate change matrix since there are
176 // explicit uv coordinates
177 return true;
178 }
179
180 if (fCoordChangeMatrixSet != stage.fCoordChangeMatrixSet) {
181 return false;
182 }
183
184 if (!fCoordChangeMatrixSet) {
185 return true;
186 }
187
188 return fCoordChangeMatrix == stage.fCoordChangeMatrix;
189 }
190
191 private:
192 const GrEffect* fEffect;
193 bool fCoordChangeMatrixSet;
194 SkMatrix fCoordChangeMatrix;
195 int fVertexAttribIndices[2];
196 SkDEBUGCODE(bool fInitialized;)
197 };
198
199 /**
200 * Gets the matrix representing all changes of coordinate system since the G rEffect was 118 * Gets the matrix representing all changes of coordinate system since the G rEffect was
201 * installed in the stage. 119 * installed in the stage.
202 */ 120 */
203 const SkMatrix& getCoordChangeMatrix() const { 121 const SkMatrix& getCoordChangeMatrix() const {
204 if (fCoordChangeMatrixSet) { 122 if (fCoordChangeMatrixSet) {
205 return fCoordChangeMatrix; 123 return fCoordChangeMatrix;
206 } else { 124 } else {
207 return SkMatrix::I(); 125 return SkMatrix::I();
208 } 126 }
209 } 127 }
210 128
211 const GrEffectRef* getEffect() const { return fEffectRef.get(); } 129 const GrEffectRef* getEffect() const { return fEffectRef.get(); }
212 130
213 const int* getVertexAttribIndices() const { return fVertexAttribIndices; } 131 const int* getVertexAttribIndices() const { return fVertexAttribIndices; }
214 int getVertexAttribIndexCount() const { return fEffectRef->get()->numVertexA ttribs(); } 132 int getVertexAttribIndexCount() const { return fEffectRef->get()->numVertexA ttribs(); }
215 133
216 private: 134 private:
217 bool fCoordChangeMatrixSet; 135 bool fCoordChangeMatrixSet;
218 SkMatrix fCoordChangeMatrix; 136 SkMatrix fCoordChangeMatrix;
219 SkAutoTUnref<const GrEffectRef> fEffectRef; 137 SkAutoTUnref<const GrEffectRef> fEffectRef;
220 int fVertexAttribIndices[2]; 138 int fVertexAttribIndices[2];
221 }; 139 };
222 140
223 #endif 141 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698