OLD | NEW |
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 GrTexture* texture(int index) const { return this->textureAccess(index).getT
exture(); } | 107 GrTexture* texture(int index) const { return this->textureAccess(index).getT
exture(); } |
108 | 108 |
109 /** Will this effect read the destination pixel value? */ | 109 /** Will this effect read the destination pixel value? */ |
110 bool willReadDstColor() const { return fWillReadDstColor; } | 110 bool willReadDstColor() const { return fWillReadDstColor; } |
111 | 111 |
112 /** Will this effect read the fragment position? */ | 112 /** Will this effect read the fragment position? */ |
113 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; } | 113 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; } |
114 | 114 |
115 /** Will this effect emit custom vertex shader code? | 115 /** Will this effect emit custom vertex shader code? |
116 (To set this value the effect must inherit from GrEffect.) */ | 116 (To set this value the effect must inherit from GrEffect.) */ |
117 bool hasVertexCode() const { return fHasVertexCode; } | 117 bool requiresVertexShader() const { return fRequiresVertexShader; } |
118 | 118 |
119 int numVertexAttribs() const { | 119 int numVertexAttribs() const { |
120 SkASSERT(0 == fVertexAttribTypes.count() || fHasVertexCode); | 120 SkASSERT(0 == fVertexAttribTypes.count() || fRequiresVertexShader); |
121 return fVertexAttribTypes.count(); | 121 return fVertexAttribTypes.count(); |
122 } | 122 } |
123 | 123 |
124 GrSLType vertexAttribType(int index) const { return fVertexAttribTypes[index
]; } | 124 GrSLType vertexAttribType(int index) const { return fVertexAttribTypes[index
]; } |
125 | 125 |
126 static const int kMaxVertexAttribs = 2; | 126 static const int kMaxVertexAttribs = 2; |
127 | 127 |
128 /** Useful for effects that want to insert a texture matrix that is implied
by the texture | 128 /** Useful for effects that want to insert a texture matrix that is implied
by the texture |
129 dimensions */ | 129 dimensions */ |
130 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { | 130 static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) { |
(...skipping 28 matching lines...) Expand all Loading... |
159 * subclass manages the lifetime of the accesses (this function only stores
a pointer). The | 159 * subclass manages the lifetime of the accesses (this function only stores
a pointer). The |
160 * GrTextureAccess is typically a member field of the GrEffect subclass. Thi
s must only be | 160 * GrTextureAccess is typically a member field of the GrEffect subclass. Thi
s must only be |
161 * called from the constructor because GrEffects are immutable. | 161 * called from the constructor because GrEffects are immutable. |
162 */ | 162 */ |
163 void addTextureAccess(const GrTextureAccess* textureAccess); | 163 void addTextureAccess(const GrTextureAccess* textureAccess); |
164 | 164 |
165 GrEffect() | 165 GrEffect() |
166 : fWillReadDstColor(false) | 166 : fWillReadDstColor(false) |
167 , fWillReadFragmentPosition(false) | 167 , fWillReadFragmentPosition(false) |
168 , fWillUseInputColor(true) | 168 , fWillUseInputColor(true) |
169 , fHasVertexCode(false) {} | 169 , fRequiresVertexShader(false) {} |
170 | 170 |
171 /** | 171 /** |
172 * Helper for down-casting to a GrEffect subclass | 172 * Helper for down-casting to a GrEffect subclass |
173 */ | 173 */ |
174 template <typename T> static const T& CastEffect(const GrEffect& effect) { | 174 template <typename T> static const T& CastEffect(const GrEffect& effect) { |
175 return *static_cast<const T*>(&effect); | 175 return *static_cast<const T*>(&effect); |
176 } | 176 } |
177 | 177 |
178 /** | 178 /** |
179 * If the effect subclass will read the destination pixel value then it must
call this function | 179 * If the effect subclass will read the destination pixel value then it must
call this function |
(...skipping 17 matching lines...) Expand all Loading... |
197 void setWillNotUseInputColor() { fWillUseInputColor = false; } | 197 void setWillNotUseInputColor() { fWillUseInputColor = false; } |
198 | 198 |
199 private: | 199 private: |
200 SkDEBUGCODE(void assertEquality(const GrEffect& other) const;) | 200 SkDEBUGCODE(void assertEquality(const GrEffect& other) const;) |
201 | 201 |
202 /** Subclass implements this to support isEqual(). It will only be called if
it is known that | 202 /** Subclass implements this to support isEqual(). It will only be called if
it is known that |
203 the two effects are of the same subclass (i.e. they return the same obje
ct from | 203 the two effects are of the same subclass (i.e. they return the same obje
ct from |
204 getFactory()).*/ | 204 getFactory()).*/ |
205 virtual bool onIsEqual(const GrEffect& other) const = 0; | 205 virtual bool onIsEqual(const GrEffect& other) const = 0; |
206 | 206 |
207 friend class GrVertexEffect; // to set fHasVertexCode and build fVertexAttri
bTypes. | 207 friend class GrVertexEffect; // to set fRequiresVertexShader and build fVert
exAttribTypes. |
208 | 208 |
209 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | 209 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
210 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; | 210 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; |
211 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; | 211 SkSTArray<kMaxVertexAttribs, GrSLType, true> fVertexAttribTypes; |
212 bool fWillReadDstColor; | 212 bool fWillReadDstColor; |
213 bool fWillReadFragmentPosition; | 213 bool fWillReadFragmentPosition; |
214 bool fWillUseInputColor; | 214 bool fWillUseInputColor; |
215 bool fHasVertexCode; | 215 bool fRequiresVertexShader; |
216 | 216 |
217 typedef SkRefCnt INHERITED; | 217 typedef SkRefCnt INHERITED; |
218 }; | 218 }; |
219 | 219 |
220 /** | 220 /** |
221 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called | 221 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called |
222 * at global destruction time. NAME will be the name of the created GrEffect. | 222 * at global destruction time. NAME will be the name of the created GrEffect. |
223 */ | 223 */ |
224 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS)
\ | 224 #define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS)
\ |
225 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ | 225 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ |
226 static GrEffect* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLAS
S, ARGS); \ | 226 static GrEffect* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLAS
S, ARGS); \ |
227 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME); | 227 static SkAutoTDestroy<GrEffect> NAME##_ad(NAME); |
228 | 228 |
229 | 229 |
230 #endif | 230 #endif |
OLD | NEW |