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 | |
| 8 | #ifndef GrGLPrimitiveProcessor_DEFINED |
| 9 | #define GrGLPrimitiveProcessor_DEFINED |
| 10 | |
| 11 | #include "GrPrimitiveProcessor.h" |
| 12 | #include "GrGLProcessor.h" |
kkinnunen | 7aedda5 | 2015-06-29 23:01:28 -0700 | [diff] [blame] | 13 | #include "GrGLPathProgramDataManager.h" |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 14 | |
| 15 | class GrBatchTracker; |
| 16 | class GrPrimitiveProcessor; |
| 17 | class GrGLGPBuilder; |
| 18 | |
| 19 | class GrGLPrimitiveProcessor { |
| 20 | public: |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 21 | virtual ~GrGLPrimitiveProcessor() {} |
| 22 | |
| 23 | typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
kkinnunen | 7aedda5 | 2015-06-29 23:01:28 -0700 | [diff] [blame] | 24 | typedef GrGLPathProgramDataManager::SeparableVaryingHandle SeparableVaryingHandle; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 25 | typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; |
| 26 | |
| 27 | typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords; |
| 28 | typedef SkSTArray<8, ProcCoords> TransformsIn; |
| 29 | typedef SkSTArray<8, GrGLProcessor::TransformedCoordsArray> TransformsOut; |
| 30 | |
| 31 | struct EmitArgs { |
| 32 | EmitArgs(GrGLGPBuilder* pb, |
| 33 | const GrPrimitiveProcessor& gp, |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 34 | const char* outputColor, |
| 35 | const char* outputCoverage, |
| 36 | const TextureSamplerArray& samplers, |
| 37 | const TransformsIn& transformsIn, |
| 38 | TransformsOut* transformsOut) |
| 39 | : fPB(pb) |
| 40 | , fGP(gp) |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 41 | , fOutputColor(outputColor) |
| 42 | , fOutputCoverage(outputCoverage) |
| 43 | , fSamplers(samplers) |
| 44 | , fTransformsIn(transformsIn) |
| 45 | , fTransformsOut(transformsOut) {} |
| 46 | GrGLGPBuilder* fPB; |
| 47 | const GrPrimitiveProcessor& fGP; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 48 | const char* fOutputColor; |
| 49 | const char* fOutputCoverage; |
| 50 | const TextureSamplerArray& fSamplers; |
| 51 | const TransformsIn& fTransformsIn; |
| 52 | TransformsOut* fTransformsOut; |
| 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * This is similar to emitCode() in the base class, except it takes a full shader builder. |
| 57 | * This allows the effect subclass to emit vertex code. |
| 58 | */ |
| 59 | virtual void emitCode(EmitArgs&) = 0; |
| 60 | |
| 61 | |
| 62 | /** A GrGLPrimitiveProcessor instance can be reused with any GrGLPrimitiveProcessor that |
| 63 | produces the same stage key; this function reads data from a GrGLPrimitiveProcessor and |
| 64 | uploads any uniform variables required by the shaders created in emitCode(). The |
| 65 | GrPrimitiveProcessor parameter is guaranteed to be of the same type that created this |
| 66 | GrGLPrimitiveProcessor and to have an identical processor key as the one that created this |
| 67 | GrGLPrimitiveProcessor. */ |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 68 | virtual void setData(const GrGLProgramDataManager&, const GrPrimitiveProcessor&) = 0; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 69 | |
| 70 | static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoordTransform&); |
| 71 | |
| 72 | protected: |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 73 | void setupUniformColor(GrGLGPBuilder* pb, const char* outputName, UniformHandle* colorUniform); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 74 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 75 | struct Transform { |
| 76 | Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidMatrix(); } |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame^] | 77 | GrGLProgramDataManager::UniformHandle fHandle; |
| 78 | SkMatrix fCurrentValue; |
| 79 | GrSLType fType; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | #endif |