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 GrGLSLPrimitiveProcessor_DEFINED 9 #define GrGLSLPrimitiveProcessor_DEFINED 10 11 #include "GrPrimitiveProcessor.h" 12 #include "glsl/GrGLSLProcessorTypes.h" 13 #include "glsl/GrGLSLProgramDataManager.h" 14 #include "glsl/GrGLSLTextureSampler.h" 15 16 class GrBatchTracker; 17 class GrPrimitiveProcessor; 18 class GrGLSLCaps; 19 class GrGLSLPPFragmentBuilder; 20 class GrGLSLGPBuilder; 21 class GrGLSLUniformHandler; 22 class GrGLSLVaryingHandler; 23 class GrGLSLVertexBuilder; 24 25 class GrGLSLPrimitiveProcessor { 26 public: 27 virtual ~GrGLSLPrimitiveProcessor() {} 28 29 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; 30 typedef GrGLSLTextureSampler::TextureSamplerArray TextureSamplerArray; 31 32 typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords; 33 typedef SkSTArray<8, ProcCoords> TransformsIn; 34 typedef SkSTArray<8, GrGLSLTransformedCoordsArray> TransformsOut; 35 36 struct EmitArgs { 37 EmitArgs(GrGLSLVertexBuilder* vertBuilder, 38 GrGLSLPPFragmentBuilder* fragBuilder, 39 GrGLSLVaryingHandler* varyingHandler, 40 GrGLSLUniformHandler* uniformHandler, 41 const GrGLSLCaps* caps, 42 const GrPrimitiveProcessor& gp, 43 const char* outputColor, 44 const char* outputCoverage, 45 const TextureSamplerArray& samplers, 46 const TransformsIn& transformsIn, 47 TransformsOut* transformsOut) 48 : fVertBuilder(vertBuilder) 49 , fFragBuilder(fragBuilder) 50 , fVaryingHandler(varyingHandler) 51 , fUniformHandler(uniformHandler) 52 , fGLSLCaps(caps) 53 , fGP(gp) 54 , fOutputColor(outputColor) 55 , fOutputCoverage(outputCoverage) 56 , fSamplers(samplers) 57 , fTransformsIn(transformsIn) 58 , fTransformsOut(transformsOut) {} 59 GrGLSLVertexBuilder* fVertBuilder; 60 GrGLSLPPFragmentBuilder* fFragBuilder; 61 GrGLSLVaryingHandler* fVaryingHandler; 62 GrGLSLUniformHandler* fUniformHandler; 63 const GrGLSLCaps* fGLSLCaps; 64 const GrPrimitiveProcessor& fGP; 65 const char* fOutputColor; 66 const char* fOutputCoverage; 67 const TextureSamplerArray& fSamplers; 68 const TransformsIn& fTransformsIn; 69 TransformsOut* fTransformsOut; 70 }; 71 72 /** 73 * This is similar to emitCode() in the base class, except it takes a full shader builder. 74 * This allows the effect subclass to emit vertex code. 75 */ 76 virtual void emitCode(EmitArgs&) = 0; 77 78 79 /** A GrGLSLPrimitiveProcessor instance can be reused with any GrGLSLPrimitiveProcessor that 80 produces the same stage key; this function reads data from a GrGLSLPrimitiveProcessor and 81 uploads any uniform variables required by the shaders created in emitCode(). The 82 GrPrimitiveProcessor parameter is guaranteed to be of the same type that created this 83 GrGLSLPrimitiveProcessor and to have an identical processor key as the one that created this 84 GrGLSLPrimitiveProcessor. */ 85 virtual void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) = 0; 86 87 static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoordTransform&); 88 89 virtual void setTransformData(const GrPrimitiveProcessor&, 90 const GrGLSLProgramDataManager& pdman, 91 int index, 92 const SkTArray<const GrCoordTransform*, true>& transforms) = 0; 93 94 protected: 95 void setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder, 96 GrGLSLUniformHandler* uniformHandler, 97 const char* outputName, 98 UniformHandle* colorUniform); 99 100 struct Transform { 101 Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidMatrix(); } 102 UniformHandle fHandle; 103 SkMatrix fCurrentValue; 104 GrSLType fType; 105 }; 106 107 SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; 108 }; 109 110 #endif 111