| 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 | 25 // By default we use the identity matrix |
| 26 void setTransformData(const GrPrimitiveProcessor&, | 26 void setTransformData(const GrPrimitiveProcessor&, |
| 27 const GrGLSLProgramDataManager& pdman, | 27 const GrGLSLProgramDataManager& pdman, |
| 28 int index, | 28 int index, |
| 29 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { | 29 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { |
| 30 this->setTransformDataMatrix(SkMatrix::I(), pdman, index, transforms); | 30 this->setTransformDataHelper(SkMatrix::I(), pdman, index, transforms); |
| 31 } | 31 } |
| 32 | 32 |
| 33 protected: | 33 protected: |
| 34 // A helper which subclasses can use if needed | 34 // A helper which subclasses can use if needed and used above in the default
setTransformData(). |
| 35 template <class GeometryProcessor> | 35 void setTransformDataHelper(const SkMatrix& localMatrix, |
| 36 void setTransformDataHelper(const GrPrimitiveProcessor& primProc, | |
| 37 const GrGLSLProgramDataManager& pdman, | 36 const GrGLSLProgramDataManager& pdman, |
| 38 int index, | 37 int index, |
| 39 const SkTArray<const GrCoordTransform*, true>& t
ransforms) { | 38 const SkTArray<const GrCoordTransform*, true>& t
ransforms) { |
| 40 const GeometryProcessor& gp = primProc.cast<GeometryProcessor>(); | 39 SkSTArray<2, UniformTransform, true>& procTransforms = fInstalledTransfo
rms[index]; |
| 41 this->setTransformDataMatrix(gp.localMatrix(), pdman, index, transforms)
; | 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 } |
| 42 } | 49 } |
| 43 | 50 |
| 44 // Emit a uniform matrix for each coord transform. | 51 // Emit a uniform matrix for each coord transform. |
| 45 void emitTransforms(GrGLSLVertexBuilder* vb, | 52 void emitTransforms(GrGLSLVertexBuilder* vb, |
| 46 GrGLSLVaryingHandler* varyingHandler, | 53 GrGLSLVaryingHandler* varyingHandler, |
| 47 GrGLSLUniformHandler* uniformHandler, | 54 GrGLSLUniformHandler* uniformHandler, |
| 48 const GrShaderVar& posVar, | 55 const GrShaderVar& posVar, |
| 49 const char* localCoords, | 56 const char* localCoords, |
| 50 const TransformsIn& tin, | 57 const TransformsIn& tin, |
| 51 TransformsOut* tout) { | 58 TransformsOut* tout) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 if (mat.isIdentity()) { | 96 if (mat.isIdentity()) { |
| 90 return 0x0; | 97 return 0x0; |
| 91 } else if (!mat.hasPerspective()) { | 98 } else if (!mat.hasPerspective()) { |
| 92 return 0x01; | 99 return 0x01; |
| 93 } else { | 100 } else { |
| 94 return 0x02; | 101 return 0x02; |
| 95 } | 102 } |
| 96 } | 103 } |
| 97 | 104 |
| 98 private: | 105 private: |
| 99 void setTransformDataMatrix(const SkMatrix& localMatrix, | |
| 100 const GrGLSLProgramDataManager& pdman, | |
| 101 int index, | |
| 102 const SkTArray<const GrCoordTransform*, true>& t
ransforms) { | |
| 103 SkSTArray<2, UniformTransform, true>& procTransforms = fInstalledTransfo
rms[index]; | |
| 104 int numTransforms = transforms.count(); | |
| 105 for (int t = 0; t < numTransforms; ++t) { | |
| 106 SkASSERT(procTransforms[t].fHandle.isValid()); | |
| 107 const SkMatrix& transform = GetTransformMatrix(localMatrix, *transfo
rms[t]); | |
| 108 if (!procTransforms[t].fCurrentValue.cheapEqualTo(transform)) { | |
| 109 pdman.setSkMatrix(procTransforms[t].fHandle.toIndex(), transform
); | |
| 110 procTransforms[t].fCurrentValue = transform; | |
| 111 } | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0; | 106 virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0; |
| 116 | 107 |
| 117 struct UniformTransform : public Transform { | 108 struct UniformTransform : public Transform { |
| 118 UniformTransform() : Transform() {} | 109 UniformTransform() : Transform() {} |
| 119 UniformHandle fHandle; | 110 UniformHandle fHandle; |
| 120 }; | 111 }; |
| 121 | 112 |
| 122 SkSTArray<8, SkSTArray<2, UniformTransform, true> > fInstalledTransforms; | 113 SkSTArray<8, SkSTArray<2, UniformTransform, true> > fInstalledTransforms; |
| 123 | 114 |
| 124 typedef GrGLSLPrimitiveProcessor INHERITED; | 115 typedef GrGLSLPrimitiveProcessor INHERITED; |
| 125 }; | 116 }; |
| 126 | 117 |
| 127 #endif | 118 #endif |
| OLD | NEW |