joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 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 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 8 | #ifndef GrGLSLPrimitiveProcessor_DEFINED |
| 9 | #define GrGLSLPrimitiveProcessor_DEFINED |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 10 | |
| 11 | #include "GrPrimitiveProcessor.h" |
egdaniel | 7dc4bd0 | 2015-10-29 07:57:01 -0700 | [diff] [blame] | 12 | #include "glsl/GrGLSLProcessorTypes.h" |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 13 | #include "glsl/GrGLSLProgramDataManager.h" |
egdaniel | 7dc4bd0 | 2015-10-29 07:57:01 -0700 | [diff] [blame] | 14 | #include "glsl/GrGLSLTextureSampler.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 15 | |
| 16 | class GrBatchTracker; |
| 17 | class GrPrimitiveProcessor; |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 18 | class GrGLSLCaps; |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame^] | 19 | class GrGLSLPPFragmentBuilder; |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 20 | class GrGLSLGPBuilder; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 21 | class GrGLSLUniformHandler; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 22 | class GrGLSLVaryingHandler; |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 23 | class GrGLSLVertexBuilder; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 24 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 25 | class GrGLSLPrimitiveProcessor { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 26 | public: |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 27 | virtual ~GrGLSLPrimitiveProcessor() {} |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 28 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 29 | typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
egdaniel | 7dc4bd0 | 2015-10-29 07:57:01 -0700 | [diff] [blame] | 30 | typedef GrGLSLTextureSampler::TextureSamplerArray TextureSamplerArray; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 31 | |
| 32 | typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords; |
| 33 | typedef SkSTArray<8, ProcCoords> TransformsIn; |
egdaniel | 7dc4bd0 | 2015-10-29 07:57:01 -0700 | [diff] [blame] | 34 | typedef SkSTArray<8, GrGLSLTransformedCoordsArray> TransformsOut; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 35 | |
| 36 | struct EmitArgs { |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 37 | EmitArgs(GrGLSLVertexBuilder* vertBuilder, |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame^] | 38 | GrGLSLPPFragmentBuilder* fragBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 39 | GrGLSLVaryingHandler* varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 40 | GrGLSLUniformHandler* uniformHandler, |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 41 | const GrGLSLCaps* caps, |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 42 | const GrPrimitiveProcessor& gp, |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 43 | const char* outputColor, |
| 44 | const char* outputCoverage, |
| 45 | const TextureSamplerArray& samplers, |
| 46 | const TransformsIn& transformsIn, |
| 47 | TransformsOut* transformsOut) |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 48 | : fVertBuilder(vertBuilder) |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 49 | , fFragBuilder(fragBuilder) |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 50 | , fVaryingHandler(varyingHandler) |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 51 | , fUniformHandler(uniformHandler) |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 52 | , fGLSLCaps(caps) |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 53 | , fGP(gp) |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 54 | , fOutputColor(outputColor) |
| 55 | , fOutputCoverage(outputCoverage) |
| 56 | , fSamplers(samplers) |
| 57 | , fTransformsIn(transformsIn) |
| 58 | , fTransformsOut(transformsOut) {} |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 59 | GrGLSLVertexBuilder* fVertBuilder; |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame^] | 60 | GrGLSLPPFragmentBuilder* fFragBuilder; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 61 | GrGLSLVaryingHandler* fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 62 | GrGLSLUniformHandler* fUniformHandler; |
egdaniel | a2e3e0f | 2015-11-19 07:23:45 -0800 | [diff] [blame] | 63 | const GrGLSLCaps* fGLSLCaps; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 64 | const GrPrimitiveProcessor& fGP; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 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 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 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 |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 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 |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 83 | GrGLSLPrimitiveProcessor and to have an identical processor key as the one that created this |
| 84 | GrGLSLPrimitiveProcessor. */ |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 85 | virtual void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) = 0; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 86 | |
| 87 | static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoordTransform&); |
| 88 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 89 | virtual void setTransformData(const GrPrimitiveProcessor&, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 90 | const GrGLSLProgramDataManager& pdman, |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 91 | int index, |
| 92 | const SkTArray<const GrCoordTransform*, true>& transforms) = 0; |
| 93 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 94 | protected: |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame^] | 95 | void setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 96 | GrGLSLUniformHandler* uniformHandler, |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 97 | const char* outputName, |
| 98 | UniformHandle* colorUniform); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 99 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 100 | struct Transform { |
| 101 | Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidMatrix(); } |
egdaniel | 7dc4bd0 | 2015-10-29 07:57:01 -0700 | [diff] [blame] | 102 | UniformHandle fHandle; |
| 103 | SkMatrix fCurrentValue; |
| 104 | GrSLType fType; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | #endif |