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

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

Issue 23653059: Mark when effects and programs have vertex code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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 | « no previous file | src/gpu/GrAAConvexPathRenderer.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 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
11 #include "GrColor.h" 11 #include "GrColor.h"
12 #include "GrEffectUnitTest.h" 12 #include "GrEffectUnitTest.h"
13 #include "GrTexture.h" 13 #include "GrTexture.h"
14 #include "GrTextureAccess.h" 14 #include "GrTextureAccess.h"
15 #include "GrTypesPriv.h" 15 #include "GrTypesPriv.h"
16 16
17 class GrBackendEffectFactory; 17 class GrBackendEffectFactory;
18 class GrContext; 18 class GrContext;
19 class GrEffect; 19 class GrEffect;
20 class GrVertexEffect;
20 class SkString; 21 class SkString;
21 22
22 /** 23 /**
23 * A Wrapper class for GrEffect. Its ref-count will track owners that may use ef fects to enqueue 24 * A Wrapper class for GrEffect. Its ref-count will track owners that may use ef fects to enqueue
24 * new draw operations separately from ownership within a deferred drawing queue . When the 25 * new draw operations separately from ownership within a deferred drawing queue . When the
25 * GrEffectRef ref count reaches zero the scratch GrResources owned by the effec t can be recycled 26 * GrEffectRef ref count reaches zero the scratch GrResources owned by the effec t can be recycled
26 * in service of later draws. However, the deferred draw queue may still own dir ect references to 27 * in service of later draws. However, the deferred draw queue may still own dir ect references to
27 * the underlying GrEffect. 28 * the underlying GrEffect.
28 * 29 *
29 * GrEffectRefs created by new are placed in a per-thread managed pool. The pool is destroyed when 30 * GrEffectRefs created by new are placed in a per-thread managed pool. The pool is destroyed when
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 146
146 /** Shortcut for textureAccess(index).texture(); */ 147 /** Shortcut for textureAccess(index).texture(); */
147 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); } 148 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); }
148 149
149 /** Will this effect read the destination pixel value? */ 150 /** Will this effect read the destination pixel value? */
150 bool willReadDstColor() const { return fWillReadDstColor; } 151 bool willReadDstColor() const { return fWillReadDstColor; }
151 152
152 /** Will this effect read the fragment position? */ 153 /** Will this effect read the fragment position? */
153 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; } 154 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; }
154 155
155 int numVertexAttribs() const { return fVertexAttribTypes.count(); } 156 /** Will this effect emit custom vertex shader code?
157 (To set this value the effect must inherit from GrVertexEffect.) */
158 bool hasVertexCode() const { return fHasVertexCode; }
159
160 int numVertexAttribs() const {
161 SkASSERT(0 == fVertexAttribTypes.count() || fHasVertexCode);
162 return fVertexAttribTypes.count();
163 }
156 164
157 GrSLType vertexAttribType(int index) const { return fVertexAttribTypes[index ]; } 165 GrSLType vertexAttribType(int index) const { return fVertexAttribTypes[index ]; }
158 166
159 static const int kMaxVertexAttribs = 2; 167 static const int kMaxVertexAttribs = 2;
160 168
161 /** Useful for effects that want to insert a texture matrix that is implied by the texture 169 /** Useful for effects that want to insert a texture matrix that is implied by the texture
162 dimensions */ 170 dimensions */
163 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { 171 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) {
164 SkASSERT(NULL != texture); 172 SkASSERT(NULL != texture);
165 SkMatrix mat; 173 SkMatrix mat;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 205
198 protected: 206 protected:
199 /** 207 /**
200 * Subclasses call this from their constructor to register GrTextureAccesses . The effect 208 * Subclasses call this from their constructor to register GrTextureAccesses . The effect
201 * subclass manages the lifetime of the accesses (this function only stores a pointer). The 209 * subclass manages the lifetime of the accesses (this function only stores a pointer). The
202 * GrTextureAccess is typically a member field of the GrEffet subclass. This must only be 210 * GrTextureAccess is typically a member field of the GrEffet subclass. This must only be
203 * called from the constructor because GrEffects are immutable. 211 * called from the constructor because GrEffects are immutable.
204 */ 212 */
205 void addTextureAccess(const GrTextureAccess* textureAccess); 213 void addTextureAccess(const GrTextureAccess* textureAccess);
206 214
207 /** 215 GrEffect()
208 * Subclasses call this from their constructor to register vertex attributes (at most 216 : fWillReadDstColor(false)
209 * kMaxVertexAttribs). This must only be called from the constructor because GrEffects are 217 , fWillReadFragmentPosition(false)
210 * immutable. 218 , fHasVertexCode(false)
211 */ 219 , fEffectRef(NULL) {}
212 void addVertexAttrib(GrSLType type);
213
214 GrEffect() : fWillReadDstColor(false), fWillReadFragmentPosition(false), fEf fectRef(NULL) {}
215 220
216 /** This should be called by GrEffect subclass factories. See the comment on AutoEffectUnref for 221 /** This should be called by GrEffect subclass factories. See the comment on AutoEffectUnref for
217 an example factory function. */ 222 an example factory function. */
218 static GrEffectRef* CreateEffectRef(GrEffect* effect) { 223 static GrEffectRef* CreateEffectRef(GrEffect* effect) {
219 if (NULL == effect->fEffectRef) { 224 if (NULL == effect->fEffectRef) {
220 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect)); 225 effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect));
221 } else { 226 } else {
222 effect->fEffectRef->ref(); 227 effect->fEffectRef->ref();
223 } 228 }
224 return effect->fEffectRef; 229 return effect->fEffectRef;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 return result; 298 return result;
294 } 299 }
295 300
296 /** Subclass implements this to support isEqual(). It will only be called if it is known that 301 /** Subclass implements this to support isEqual(). It will only be called if it is known that
297 the two effects are of the same subclass (i.e. they return the same obje ct from 302 the two effects are of the same subclass (i.e. they return the same obje ct from
298 getFactory()).*/ 303 getFactory()).*/
299 virtual bool onIsEqual(const GrEffect& other) const = 0; 304 virtual bool onIsEqual(const GrEffect& other) const = 0;
300 305
301 void EffectRefDestroyed() { fEffectRef = NULL; } 306 void EffectRefDestroyed() { fEffectRef = NULL; }
302 307
303 friend class GrEffectRef; // to call EffectRefDestroyed() 308 friend class GrEffectRef; // to call EffectRefDestroyed()
304 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restor ing an effect-stage 309 friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when resto ring an effect-stage
305 // from deferred state, to call isEqual on naked GrEffects, and 310 // from deferred state, to call isEqual on nake d GrEffects, and
306 // to inc/dec deferred ref counts. 311 // to inc/dec deferred ref counts.
312 friend class GrVertexEffect; // to set fHasVertexCode and build fVertexAttri bTypes.
307 313
308 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; 314 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses;
309 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; 315 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes;
310 bool fWillReadDstColor; 316 bool fWillReadDstColor;
311 bool fWillReadFragmentPosition; 317 bool fWillReadFragmentPosition;
318 bool fHasVertexCode;
312 GrEffectRef* fEffectRef; 319 GrEffectRef* fEffectRef;
313 320
314 typedef SkRefCnt INHERITED; 321 typedef SkRefCnt INHERITED;
315 }; 322 };
316 323
317 inline GrEffectRef::GrEffectRef(GrEffect* effect) { 324 inline GrEffectRef::GrEffectRef(GrEffect* effect) {
318 SkASSERT(NULL != effect); 325 SkASSERT(NULL != effect);
319 effect->ref(); 326 effect->ref();
320 fEffect = effect; 327 fEffect = effect;
321 } 328 }
322 329
323 /** 330 /**
324 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called 331 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called
325 * at global destruction time. NAME will be the name of the created GrEffectRef. 332 * at global destruction time. NAME will be the name of the created GrEffectRef.
326 */ 333 */
327 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS) \ 334 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS) \
328 enum { \ 335 enum { \
329 k_##NAME##_EffectRefOffset = GR_CT_ALIGN_UP(sizeof(EFFECT_CLASS), 8), \ 336 k_##NAME##_EffectRefOffset = GR_CT_ALIGN_UP(sizeof(EFFECT_CLASS), 8), \
330 k_##NAME##_StorageSize = k_##NAME##_EffectRefOffset + sizeof(GrEffectRef) \ 337 k_##NAME##_StorageSize = k_##NAME##_EffectRefOffset + sizeof(GrEffectRef) \
331 }; \ 338 }; \
332 static SkAlignedSStorage<k_##NAME##_StorageSize> g_##NAME##_Storage; \ 339 static SkAlignedSStorage<k_##NAME##_StorageSize> g_##NAME##_Storage; \
333 static void* NAME##_RefLocation = (char*)g_##NAME##_Storage.get() + k_##NAME##_E ffectRefOffset; \ 340 static void* NAME##_RefLocation = (char*)g_##NAME##_Storage.get() + k_##NAME##_E ffectRefOffset; \
334 static GrEffect* NAME##_Effect SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EF FECT_CLASS, ARGS);\ 341 static GrEffect* NAME##_Effect SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EF FECT_CLASS, ARGS);\
335 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME##_Effect); \ 342 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME##_Effect); \
336 static GrEffectRef* NAME(GrEffect::CreateStaticEffectRef(NAME##_RefLocation, NAM E##_Effect)); \ 343 static GrEffectRef* NAME(GrEffect::CreateStaticEffectRef(NAME##_RefLocation, NAM E##_Effect)); \
337 static SkAutoTDestroy<GrEffectRef> NAME##_Ref_ad(NAME) 344 static SkAutoTDestroy<GrEffectRef> NAME##_Ref_ad(NAME)
338 345
339 346
340 #endif 347 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrAAConvexPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698