1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrGLSLGeometryProcessor_DEFINED 9 #define GrGLSLGeometryProcessor_DEFINED 10 11 #include "GrGLSLPrimitiveProcessor.h" 12 13 class GrGLSLGPBuilder; 14 15 /** 16 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, then it must inherit 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. 19 */ 20 class GrGLSLGeometryProcessor : public GrGLSLPrimitiveProcessor { 21 public: 22 /* Any general emit code goes in the base class emitCode. Subclasses override onEmitCode */ 23 void emitCode(EmitArgs&) override; 24 25 protected: 26 // A helper which subclasses can use if needed and used above in the default setTransformData(). 27 void setTransformDataHelper(const SkMatrix& localMatrix, 28 const GrGLSLProgramDataManager& pdman, 29 FPCoordTransformIter*); 30 31 // Emit a uniform matrix for each coord transform. emitTransforms(GrGLSLVertexBuilder * vb,GrGLSLVaryingHandler * varyingHandler,GrGLSLUniformHandler * uniformHandler,const GrShaderVar & posVar,const char * localCoords,FPCoordTransformHandler * handler)32 void emitTransforms(GrGLSLVertexBuilder* vb, 33 GrGLSLVaryingHandler* varyingHandler, 34 GrGLSLUniformHandler* uniformHandler, 35 const GrShaderVar& posVar, 36 const char* localCoords, 37 FPCoordTransformHandler* handler) { 38 this->emitTransforms(vb, varyingHandler, uniformHandler, 39 posVar, localCoords, SkMatrix::I(), handler); 40 } 41 42 // Emit pre-transformed coords as a vertex attribute per coord-transform. 43 void emitTransforms(GrGLSLVertexBuilder*, 44 GrGLSLVaryingHandler*, 45 GrGLSLUniformHandler*, 46 const GrShaderVar& posVar, 47 const char* localCoords, 48 const SkMatrix& localMatrix, 49 FPCoordTransformHandler*); 50 51 struct GrGPArgs { 52 // 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. 54 GrShaderVar fPositionVar; 55 }; 56 57 // Create the correct type of position variable given the CTM 58 void setupPosition(GrGLSLVertexBuilder*, GrGPArgs*, const char* posName); 59 void setupPosition(GrGLSLVertexBuilder*, 60 GrGLSLUniformHandler* uniformHandler, 61 GrGPArgs*, 62 const char* posName, 63 const SkMatrix& mat, 64 UniformHandle* viewMatrixUniform); 65 ComputePosKey(const SkMatrix & mat)66 static uint32_t ComputePosKey(const SkMatrix& mat) { 67 if (mat.isIdentity()) { 68 return 0x0; 69 } else if (!mat.hasPerspective()) { 70 return 0x01; 71 } else { 72 return 0x02; 73 } 74 } 75 76 private: 77 virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0; 78 79 struct TransformUniform { 80 UniformHandle fHandle; 81 SkMatrix fCurrentValue = SkMatrix::InvalidMatrix(); 82 }; 83 84 SkTArray<TransformUniform, true> fInstalledTransforms; 85 86 typedef GrGLSLPrimitiveProcessor INHERITED; 87 }; 88 89 #endif 90