| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 GrGLProgramEffects_DEFINED | 8 #ifndef GrGLProgramEffects_DEFINED |
| 9 #define GrGLProgramEffects_DEFINED | 9 #define GrGLProgramEffects_DEFINED |
| 10 | 10 |
| 11 #include "GrBackendEffectFactory.h" | 11 #include "GrBackendEffectFactory.h" |
| 12 #include "GrGLProgramDataManager.h" | 12 #include "GrGLProgramDataManager.h" |
| 13 #include "GrGpu.h" |
| 13 #include "GrTexture.h" | 14 #include "GrTexture.h" |
| 14 #include "GrTextureAccess.h" | 15 #include "GrTextureAccess.h" |
| 15 | 16 |
| 16 class GrEffect; | 17 class GrEffect; |
| 17 class GrEffectStage; | 18 class GrEffectStage; |
| 18 class GrGLVertexProgramEffectsBuilder; | 19 class GrGLVertexProgramEffectsBuilder; |
| 19 class GrGLShaderBuilder; | 20 class GrGLShaderBuilder; |
| 20 class GrGLFullShaderBuilder; | 21 class GrGLFullShaderBuilder; |
| 21 class GrGLFragmentOnlyShaderBuilder; | 22 class GrGLFragmentOnlyShaderBuilder; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * This class encapsulates an array of GrGLEffects and their supporting data (co
ord transforms | 25 * This class encapsulates an array of GrGLEffects and their supporting data (co
ord transforms |
| 25 * and textures). It is built with GrGLProgramEffectsBuilder, then used to manag
e the necessary GL | 26 * and textures). It is built with GrGLProgramEffectsBuilder, then used to manag
e the necessary GL |
| 26 * state and shader uniforms. | 27 * state and shader uniforms. |
| 27 */ | 28 */ |
| 28 class GrGLProgramEffects : public SkRefCnt { | 29 class GrGLProgramEffects : public SkRefCnt { |
| 29 public: | 30 public: |
| 30 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 31 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 32 typedef GrGLProgramDataManager::VaryingHandle VaryingHandle; |
| 31 | 33 |
| 32 /** | 34 /** |
| 33 * This class emits some of the code inserted into the shaders for an effect
. The code it | 35 * This class emits some of the code inserted into the shaders for an effect
. The code it |
| 34 * creates may be dependent on properties of the effect that the effect itse
lf doesn't use | 36 * creates may be dependent on properties of the effect that the effect itse
lf doesn't use |
| 35 * in its key (e.g. the pixel format of textures used). So this class insert
s a meta-key for | 37 * in its key (e.g. the pixel format of textures used). So this class insert
s a meta-key for |
| 36 * every effect using this function. It is also responsible for inserting th
e effect's class ID | 38 * every effect using this function. It is also responsible for inserting th
e effect's class ID |
| 37 * which must be different for every GrEffect subclass. It can fail if an ef
fect uses too many | 39 * which must be different for every GrEffect subclass. It can fail if an ef
fect uses too many |
| 38 * textures, attributes, etc for the space allotted in the meta-key. | 40 * textures, attributes, etc for the space allotted in the meta-key. |
| 39 */ | 41 */ |
| 40 static bool GenEffectMetaKey(const GrDrawEffect&, const GrGLCaps&, GrEffectK
eyBuilder*); | 42 static bool GenEffectMetaKey(const GrDrawEffect&, const GrGLCaps&, GrEffectK
eyBuilder*); |
| 41 | 43 |
| 42 virtual ~GrGLProgramEffects(); | 44 virtual ~GrGLProgramEffects(); |
| 43 | 45 |
| 44 /** | 46 /** |
| 45 * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writ
es the next | 47 * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writ
es the next |
| 46 * available unit to *texUnitIdx when it returns. | 48 * available unit to *texUnitIdx when it returns. |
| 47 */ | 49 */ |
| 48 void initSamplers(const GrGLProgramDataManager&, int* texUnitIdx); | 50 void initSamplers(const GrGLProgramDataManager&, int* texUnitIdx); |
| 49 | 51 |
| 50 /** | 52 /** |
| 51 * Calls setData() on each effect, and sets their transformation matrices an
d texture bindings. | 53 * Calls setData() on each effect, and sets their transformation matrices an
d texture bindings. |
| 52 */ | 54 */ |
| 53 virtual void setData(GrGpuGL*, | 55 virtual void setData(GrGpuGL*, |
| 56 GrGpu::DrawType, |
| 54 const GrGLProgramDataManager&, | 57 const GrGLProgramDataManager&, |
| 55 const GrEffectStage* effectStages[]) = 0; | 58 const GrEffectStage* effectStages[]) = 0; |
| 56 | 59 |
| 57 /** | 60 /** |
| 58 * Passed to GrGLEffects so they can add transformed coordinates to their sh
ader code. | 61 * Passed to GrGLEffects so they can add transformed coordinates to their sh
ader code. |
| 59 */ | 62 */ |
| 60 class TransformedCoords { | 63 class TransformedCoords { |
| 61 public: | 64 public: |
| 62 TransformedCoords(const SkString& name, GrSLType type) | 65 TransformedCoords(const SkString& name, GrSLType type) |
| 63 : fName(name), fType(type) { | 66 : fName(name), fType(type) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 }; | 158 }; |
| 156 | 159 |
| 157 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
| 158 | 161 |
| 159 /** | 162 /** |
| 160 * This is a GrGLProgramEffects implementation that does coord transforms with t
he vertex shader. | 163 * This is a GrGLProgramEffects implementation that does coord transforms with t
he vertex shader. |
| 161 */ | 164 */ |
| 162 class GrGLVertexProgramEffects : public GrGLProgramEffects { | 165 class GrGLVertexProgramEffects : public GrGLProgramEffects { |
| 163 public: | 166 public: |
| 164 virtual void setData(GrGpuGL*, | 167 virtual void setData(GrGpuGL*, |
| 168 GrGpu::DrawType, |
| 165 const GrGLProgramDataManager&, | 169 const GrGLProgramDataManager&, |
| 166 const GrEffectStage* effectStages[]) SK_OVERRIDE; | 170 const GrEffectStage* effectStages[]) SK_OVERRIDE; |
| 167 | 171 |
| 168 private: | 172 private: |
| 169 friend class GrGLVertexProgramEffectsBuilder; | 173 friend class GrGLVertexProgramEffectsBuilder; |
| 170 | 174 |
| 171 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords) | 175 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords) |
| 172 : INHERITED(reserveCount) | 176 : INHERITED(reserveCount) |
| 173 , fTransforms(reserveCount) | 177 , fTransforms(reserveCount) |
| 174 , fHasExplicitLocalCoords(explicitLocalCoords) { | 178 , fHasExplicitLocalCoords(explicitLocalCoords) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 197 * of the varyings in the VS and FS as well their types are appended to the | 201 * of the varyings in the VS and FS as well their types are appended to the |
| 198 * TransformedCoordsArray* object, which is in turn passed to the effect's e
mitCode() function. | 202 * TransformedCoordsArray* object, which is in turn passed to the effect's e
mitCode() function. |
| 199 */ | 203 */ |
| 200 void emitTransforms(GrGLFullShaderBuilder*, | 204 void emitTransforms(GrGLFullShaderBuilder*, |
| 201 const GrDrawEffect&, | 205 const GrDrawEffect&, |
| 202 TransformedCoordsArray*); | 206 TransformedCoordsArray*); |
| 203 | 207 |
| 204 /** | 208 /** |
| 205 * Helper for setData(). Sets all the transform matrices for an effect. | 209 * Helper for setData(). Sets all the transform matrices for an effect. |
| 206 */ | 210 */ |
| 207 void setTransformData(const GrGLProgramDataManager&, const GrDrawEffect&, in
t effectIdx); | 211 void setTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, const GrD
rawEffect&, int effectIdx); |
| 212 void setPathTransformData(GrGpuGL* gpu, const GrGLProgramDataManager&, const
GrDrawEffect&, |
| 213 int effectIdx); |
| 208 | 214 |
| 209 struct Transform { | 215 struct Transform { |
| 210 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } | 216 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } |
| 211 UniformHandle fHandle; | 217 UniformHandle fHandle; |
| 212 SkMatrix fCurrentValue; | 218 SkMatrix fCurrentValue; |
| 213 }; | 219 }; |
| 214 | 220 |
| 221 struct PathTransform { |
| 222 PathTransform() { fCurrentValue = SkMatrix::InvalidMatrix(); } |
| 223 VaryingHandle fHandle; |
| 224 SkMatrix fCurrentValue; |
| 225 GrSLType fType; |
| 226 }; |
| 227 |
| 215 SkTArray<SkSTArray<2, Transform, true> > fTransforms; | 228 SkTArray<SkSTArray<2, Transform, true> > fTransforms; |
| 229 SkTArray<SkTArray<PathTransform, true> > fPathTransforms; |
| 216 bool fHasExplicitLocalCoords; | 230 bool fHasExplicitLocalCoords; |
| 217 | 231 |
| 218 typedef GrGLProgramEffects INHERITED; | 232 typedef GrGLProgramEffects INHERITED; |
| 219 }; | 233 }; |
| 220 | 234 |
| 221 /** | 235 /** |
| 222 * This class is used to construct a GrGLVertexProgramEffects* object. | 236 * This class is used to construct a GrGLVertexProgramEffects* object. |
| 223 */ | 237 */ |
| 224 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder { | 238 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder { |
| 225 public: | 239 public: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 247 | 261 |
| 248 //////////////////////////////////////////////////////////////////////////////// | 262 //////////////////////////////////////////////////////////////////////////////// |
| 249 | 263 |
| 250 /** | 264 /** |
| 251 * This is a GrGLProgramEffects implementation that does coord transforms with | 265 * This is a GrGLProgramEffects implementation that does coord transforms with |
| 252 * the the NV_path_rendering PathTexGen functionality. | 266 * the the NV_path_rendering PathTexGen functionality. |
| 253 */ | 267 */ |
| 254 class GrGLPathTexGenProgramEffects : public GrGLProgramEffects { | 268 class GrGLPathTexGenProgramEffects : public GrGLProgramEffects { |
| 255 public: | 269 public: |
| 256 virtual void setData(GrGpuGL*, | 270 virtual void setData(GrGpuGL*, |
| 271 GrGpu::DrawType, |
| 257 const GrGLProgramDataManager&, | 272 const GrGLProgramDataManager&, |
| 258 const GrEffectStage* effectStages[]) SK_OVERRIDE; | 273 const GrEffectStage* effectStages[]) SK_OVERRIDE; |
| 259 | 274 |
| 260 private: | 275 private: |
| 261 friend class GrGLPathTexGenProgramEffectsBuilder; | 276 friend class GrGLPathTexGenProgramEffectsBuilder; |
| 262 | 277 |
| 263 GrGLPathTexGenProgramEffects(int reserveCount) | 278 GrGLPathTexGenProgramEffects(int reserveCount) |
| 264 : INHERITED(reserveCount) | 279 : INHERITED(reserveCount) |
| 265 , fTransforms(reserveCount) { | 280 , fTransforms(reserveCount) { |
| 266 } | 281 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } | 341 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } |
| 327 | 342 |
| 328 private: | 343 private: |
| 329 GrGLFragmentOnlyShaderBuilder* fBuilder; | 344 GrGLFragmentOnlyShaderBuilder* fBuilder; |
| 330 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; | 345 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; |
| 331 | 346 |
| 332 typedef GrGLProgramEffectsBuilder INHERITED; | 347 typedef GrGLProgramEffectsBuilder INHERITED; |
| 333 }; | 348 }; |
| 334 | 349 |
| 335 #endif | 350 #endif |
| OLD | NEW |