| 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 GrGLSLGeometryProcessor_DEFINED | 8 #ifndef GrGLSLGeometryProcessor_DEFINED |
| 9 #define GrGLSLGeometryProcessor_DEFINED | 9 #define GrGLSLGeometryProcessor_DEFINED |
| 10 | 10 |
| 11 #include "GrGLSLPrimitiveProcessor.h" | 11 #include "GrGLSLPrimitiveProcessor.h" |
| 12 | 12 |
| 13 class GrGLSLGPBuilder; | 13 class GrGLSLGPBuilder; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, the
n it must inherit | 16 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, the
n it must inherit |
| 17 * from this class. Since paths don't have vertices, this class is only meant to
be used internally | 17 * from this class. Since paths don't have vertices, this class is only meant to
be used internally |
| 18 * by skia, for special cases. | 18 * by skia, for special cases. |
| 19 */ | 19 */ |
| 20 class GrGLSLGeometryProcessor : public GrGLSLPrimitiveProcessor { | 20 class GrGLSLGeometryProcessor : public GrGLSLPrimitiveProcessor { |
| 21 public: | 21 public: |
| 22 /* Any general emit code goes in the base class emitCode. Subclasses overri
de onEmitCode */ | 22 /* Any general emit code goes in the base class emitCode. Subclasses overri
de onEmitCode */ |
| 23 void emitCode(EmitArgs&) override; | 23 void emitCode(EmitArgs&) override; |
| 24 | 24 |
| 25 // By default we use the identity matrix |
| 26 void setTransformData(const GrPrimitiveProcessor&, |
| 27 const GrGLSLProgramDataManager& pdman, |
| 28 int index, |
| 29 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { |
| 30 this->setTransformDataHelper(SkMatrix::I(), pdman, index, transforms); |
| 31 } |
| 32 |
| 25 protected: | 33 protected: |
| 26 // A helper which subclasses can use if needed and used above in the default
setTransformData(). | 34 // A helper which subclasses can use if needed and used above in the default
setTransformData(). |
| 27 void setTransformDataHelper(const SkMatrix& localMatrix, | 35 void setTransformDataHelper(const SkMatrix& localMatrix, |
| 28 const GrGLSLProgramDataManager& pdman, | 36 const GrGLSLProgramDataManager& pdman, |
| 29 FPCoordTransformIter*); | 37 int index, |
| 38 const SkTArray<const GrCoordTransform*, true>& t
ransforms) { |
| 39 SkTArray<TransformUniform, true>& procTransforms = fInstalledTransforms[
index]; |
| 40 int numTransforms = transforms.count(); |
| 41 for (int t = 0; t < numTransforms; ++t) { |
| 42 SkASSERT(procTransforms[t].fHandle.isValid()); |
| 43 const SkMatrix& transform = GetTransformMatrix(localMatrix, *transfo
rms[t]); |
| 44 if (!procTransforms[t].fCurrentValue.cheapEqualTo(transform)) { |
| 45 pdman.setSkMatrix(procTransforms[t].fHandle.toIndex(), transform
); |
| 46 procTransforms[t].fCurrentValue = transform; |
| 47 } |
| 48 } |
| 49 } |
| 30 | 50 |
| 31 // Emit a uniform matrix for each coord transform. | 51 // Emit a uniform matrix for each coord transform. |
| 32 void emitTransforms(GrGLSLVertexBuilder* vb, | 52 void emitTransforms(GrGLSLVertexBuilder* vb, |
| 33 GrGLSLVaryingHandler* varyingHandler, | 53 GrGLSLVaryingHandler* varyingHandler, |
| 34 GrGLSLUniformHandler* uniformHandler, | 54 GrGLSLUniformHandler* uniformHandler, |
| 35 const GrShaderVar& posVar, | 55 const GrShaderVar& posVar, |
| 36 const char* localCoords, | 56 const char* localCoords, |
| 37 FPCoordTransformHandler* handler) { | 57 const TransformsIn& tin, |
| 58 TransformsOut* tout) { |
| 38 this->emitTransforms(vb, varyingHandler, uniformHandler, | 59 this->emitTransforms(vb, varyingHandler, uniformHandler, |
| 39 posVar, localCoords, SkMatrix::I(), handler); | 60 posVar, localCoords, SkMatrix::I(), tin, tout); |
| 40 } | 61 } |
| 41 | 62 |
| 42 // Emit pre-transformed coords as a vertex attribute per coord-transform. | 63 // Emit pre-transformed coords as a vertex attribute per coord-transform. |
| 43 void emitTransforms(GrGLSLVertexBuilder*, | 64 void emitTransforms(GrGLSLVertexBuilder*, |
| 44 GrGLSLVaryingHandler*, | 65 GrGLSLVaryingHandler*, |
| 45 GrGLSLUniformHandler*, | 66 GrGLSLUniformHandler*, |
| 46 const GrShaderVar& posVar, | 67 const GrShaderVar& posVar, |
| 47 const char* localCoords, | 68 const char* localCoords, |
| 48 const SkMatrix& localMatrix, | 69 const SkMatrix& localMatrix, |
| 49 FPCoordTransformHandler*); | 70 const TransformsIn&, |
| 71 TransformsOut*); |
| 50 | 72 |
| 51 struct GrGPArgs { | 73 struct GrGPArgs { |
| 52 // The variable used by a GP to store its position. It can be | 74 // The variable used by a GP to store its position. It can be |
| 53 // either a vec2 or a vec3 depending on the presence of perspective. | 75 // either a vec2 or a vec3 depending on the presence of perspective. |
| 54 GrShaderVar fPositionVar; | 76 GrShaderVar fPositionVar; |
| 55 }; | 77 }; |
| 56 | 78 |
| 57 // Create the correct type of position variable given the CTM | 79 // Create the correct type of position variable given the CTM |
| 58 void setupPosition(GrGLSLVertexBuilder*, GrGPArgs*, const char* posName); | 80 void setupPosition(GrGLSLVertexBuilder*, GrGPArgs*, const char* posName); |
| 59 void setupPosition(GrGLSLVertexBuilder*, | 81 void setupPosition(GrGLSLVertexBuilder*, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 74 } | 96 } |
| 75 | 97 |
| 76 private: | 98 private: |
| 77 virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0; | 99 virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0; |
| 78 | 100 |
| 79 struct TransformUniform { | 101 struct TransformUniform { |
| 80 UniformHandle fHandle; | 102 UniformHandle fHandle; |
| 81 SkMatrix fCurrentValue = SkMatrix::InvalidMatrix(); | 103 SkMatrix fCurrentValue = SkMatrix::InvalidMatrix(); |
| 82 }; | 104 }; |
| 83 | 105 |
| 84 SkTArray<TransformUniform, true> fInstalledTransforms; | 106 SkSTArray<8, SkSTArray<2, TransformUniform, true> > fInstalledTransforms; |
| 85 | 107 |
| 86 typedef GrGLSLPrimitiveProcessor INHERITED; | 108 typedef GrGLSLPrimitiveProcessor INHERITED; |
| 87 }; | 109 }; |
| 88 | 110 |
| 89 #endif | 111 #endif |
| OLD | NEW |