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

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

Issue 13314002: Add support for reading the dst pixel value in an effect. Use in a new effect for the kDarken xfer … (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Revert whitespace/comment changes accidentally made in GrGLProgramDesc.cpp Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « include/core/SkXfermode.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 2012 Google Inc. 2 * Copyright 2012 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 GrEffect_DEFINED 8 #ifndef GrEffect_DEFINED
9 #define GrEffect_DEFINED 9 #define GrEffect_DEFINED
10 10
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 int numTextures() const { return fTextureAccesses.count(); } 132 int numTextures() const { return fTextureAccesses.count(); }
133 133
134 /** Returns the access pattern for the texture at index. index must be valid according to 134 /** Returns the access pattern for the texture at index. index must be valid according to
135 numTextures(). */ 135 numTextures(). */
136 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; } 136 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; }
137 137
138 /** Shortcut for textureAccess(index).texture(); */ 138 /** Shortcut for textureAccess(index).texture(); */
139 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); } 139 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); }
140 140
141 /** Will this effect read the destination pixel value? */
142 bool willReadDst() const { return fWillReadDst; }
141 143
142 int numVertexAttribs() const { return fVertexAttribTypes.count(); } 144 int numVertexAttribs() const { return fVertexAttribTypes.count(); }
143 145
144 GrSLType vertexAttribType(int index) const { return fVertexAttribTypes[index ]; } 146 GrSLType vertexAttribType(int index) const { return fVertexAttribTypes[index ]; }
145 147
146 static const int kMaxVertexAttribs = 2; 148 static const int kMaxVertexAttribs = 2;
147 149
148
149 /** Useful for effects that want to insert a texture matrix that is implied by the texture 150 /** Useful for effects that want to insert a texture matrix that is implied by the texture
150 dimensions */ 151 dimensions */
151 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { 152 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) {
152 GrAssert(NULL != texture); 153 GrAssert(NULL != texture);
153 SkMatrix mat; 154 SkMatrix mat;
154 mat.setIDiv(texture->width(), texture->height()); 155 mat.setIDiv(texture->width(), texture->height());
155 return mat; 156 return mat;
156 } 157 }
157 158
158 void* operator new(size_t size); 159 void* operator new(size_t size);
(...skipping 25 matching lines...) Expand all
184 */ 185 */
185 void addTextureAccess(const GrTextureAccess* textureAccess); 186 void addTextureAccess(const GrTextureAccess* textureAccess);
186 187
187 /** 188 /**
188 * Subclasses call this from their constructor to register vertex attributes (at most 189 * Subclasses call this from their constructor to register vertex attributes (at most
189 * kMaxVertexAttribs). This must only be called from the constructor because GrEffects are 190 * kMaxVertexAttribs). This must only be called from the constructor because GrEffects are
190 * immutable. 191 * immutable.
191 */ 192 */
192 void addVertexAttrib(GrSLType type); 193 void addVertexAttrib(GrSLType type);
193 194
194 GrEffect() : fEffectRef(NULL) {}; 195 GrEffect() : fWillReadDst(false), fEffectRef(NULL) {}
195 196
196 /** This should be called by GrEffect subclass factories. See the comment on AutoEffectUnref for 197 /** This should be called by GrEffect subclass factories. See the comment on AutoEffectUnref for
197 an example factory function. */ 198 an example factory function. */
198 static GrEffectRef* CreateEffectRef(GrEffect* effect) { 199 static GrEffectRef* CreateEffectRef(GrEffect* effect) {
199 if (NULL == effect->fEffectRef) { 200 if (NULL == effect->fEffectRef) {
200 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect)); 201 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect));
201 } else { 202 } else {
202 effect->fEffectRef->ref(); 203 effect->fEffectRef->ref();
203 } 204 }
204 return effect->fEffectRef; 205 return effect->fEffectRef;
(...skipping 22 matching lines...) Expand all
227 GrEffect* fEffect; 228 GrEffect* fEffect;
228 }; 229 };
229 230
230 /** Helper for getting the GrEffect out of a GrEffectRef and down-casting to a GrEffect subclass 231 /** Helper for getting the GrEffect out of a GrEffectRef and down-casting to a GrEffect subclass
231 */ 232 */
232 template <typename T> 233 template <typename T>
233 static const T& CastEffect(const GrEffect& effectRef) { 234 static const T& CastEffect(const GrEffect& effectRef) {
234 return *static_cast<const T*>(&effectRef); 235 return *static_cast<const T*>(&effectRef);
235 } 236 }
236 237
238 /**
239 * If the effect subclass will read the destination pixel value then it must call this function
240 * from its constructor. Otherwise, when its generated backend-specific effe ct class attempts
241 * to generate code that reads the destination pixel it will fail.
242 */
243 void setWillReadDst() { fWillReadDst = true; }
244
237 private: 245 private:
238 bool isEqual(const GrEffect& other) const { 246 bool isEqual(const GrEffect& other) const {
239 if (&this->getFactory() != &other.getFactory()) { 247 if (&this->getFactory() != &other.getFactory()) {
240 return false; 248 return false;
241 } 249 }
242 bool result = this->onIsEqual(other); 250 bool result = this->onIsEqual(other);
243 #if GR_DEBUG 251 #if GR_DEBUG
244 if (result) { 252 if (result) {
245 GrAssert(this->numTextures() == other.numTextures()); 253 GrAssert(this->numTextures() == other.numTextures());
246 for (int i = 0; i < this->numTextures(); ++i) { 254 for (int i = 0; i < this->numTextures(); ++i) {
(...skipping 11 matching lines...) Expand all
258 266
259 void EffectRefDestroyed() { fEffectRef = NULL; } 267 void EffectRefDestroyed() { fEffectRef = NULL; }
260 268
261 friend class GrEffectRef; // to call EffectRefDestroyed() 269 friend class GrEffectRef; // to call EffectRefDestroyed()
262 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restor ing an effect-stage 270 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restor ing an effect-stage
263 // from deferred state, to call isEqual on naked GrEffects, and 271 // from deferred state, to call isEqual on naked GrEffects, and
264 // to inc/dec deferred ref counts. 272 // to inc/dec deferred ref counts.
265 273
266 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; 274 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses;
267 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; 275 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes;
276 bool fWillReadDst;
268 GrEffectRef* fEffectRef; 277 GrEffectRef* fEffectRef;
269 278
270 typedef GrRefCnt INHERITED; 279 typedef GrRefCnt INHERITED;
271 }; 280 };
272 281
273 inline GrEffectRef::GrEffectRef(GrEffect* effect) { 282 inline GrEffectRef::GrEffectRef(GrEffect* effect) {
274 GrAssert(NULL != effect); 283 GrAssert(NULL != effect);
275 effect->ref(); 284 effect->ref();
276 fEffect = effect; 285 fEffect = effect;
277 } 286 }
278 287
279 #endif 288 #endif
OLDNEW
« no previous file with comments | « include/core/SkXfermode.h ('k') | include/gpu/GrTexture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698