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, |
| 34 | const GrBatchTracker& bt, |
| 35 | const char* outputColor, |
| 36 | const char* outputCoverage, |
| 37 | const TextureSamplerArray& samplers, |
| 38 | const TransformsIn& transformsIn, |
| 39 | TransformsOut* transformsOut) |
| 40 | : fPB(pb) |
| 41 | , fGP(gp) |
| 42 | , fBT(bt) |
| 43 | , fOutputColor(outputColor) |
| 44 | , fOutputCoverage(outputCoverage) |
| 45 | , fSamplers(samplers) |
| 46 | , fTransformsIn(transformsIn) |
| 47 | , fTransformsOut(transformsOut) {} |
| 48 | GrGLGPBuilder* fPB; |
| 49 | const GrPrimitiveProcessor& fGP; |
| 50 | const GrBatchTracker& fBT; |
| 51 | const char* fOutputColor; |
| 52 | const char* fOutputCoverage; |
| 53 | const TextureSamplerArray& fSamplers; |
| 54 | const TransformsIn& fTransformsIn; |
| 55 | TransformsOut* fTransformsOut; |
| 56 | }; |
| 57 | |
| 58 | /** |
| 59 | * This is similar to emitCode() in the base class, except it takes a full shader builder. |
| 60 | * This allows the effect subclass to emit vertex code. |
| 61 | */ |
| 62 | virtual void emitCode(EmitArgs&) = 0; |
| 63 | |
| 64 | |
| 65 | /** A GrGLPrimitiveProcessor instance can be reused with any GrGLPrimitiveProcessor that |
| 66 | produces the same stage key; this function reads data from a GrGLPrimitiveProcessor and |
| 67 | uploads any uniform variables required by the shaders created in emitCode(). The |
| 68 | GrPrimitiveProcessor parameter is guaranteed to be of the same type that created this |
| 69 | GrGLPrimitiveProcessor and to have an identical processor key as the one that created this |
| 70 | GrGLPrimitiveProcessor. */ |
| 71 | virtual void setData(const GrGLProgramDataManager&, |
| 72 | const GrPrimitiveProcessor&, |
| 73 | const GrBatchTracker&) = 0; |
| 74 | |
| 75 | static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoordTransform&); |
| 76 | |
| 77 | protected: |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 78 | void setupUniformColor(GrGLGPBuilder* pb, const char* outputName, UniformHandle* colorUniform); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 79 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 80 | class ShaderVarHandle { |
| 81 | public: |
| 82 | bool isValid() const { return fHandle > -1; } |
| 83 | ShaderVarHandle() : fHandle(-1) {} |
| 84 | ShaderVarHandle(int value) : fHandle(value) { SkASSERT(this->isValid()); } |
| 85 | int handle() const { SkASSERT(this->isValid()); return fHandle; } |
| 86 | UniformHandle convertToUniformHandle() { |
| 87 | SkASSERT(this->isValid()); |
| 88 | return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex(fHandle); |
| 89 | } |
kkinnunen | 7aedda5 | 2015-06-29 23:01:28 -0700 | [diff] [blame^] | 90 | SeparableVaryingHandle convertToSeparableVaryingHandle() { |
| 91 | SkASSERT(this->isValid()); |
| 92 | return SeparableVaryingHandle::CreateFromSeparableVaryingIndex(fHandle); |
| 93 | } |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 94 | |
| 95 | private: |
| 96 | int fHandle; |
| 97 | }; |
| 98 | |
| 99 | struct Transform { |
| 100 | Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidMatrix(); } |
| 101 | ShaderVarHandle fHandle; |
| 102 | SkMatrix fCurrentValue; |
| 103 | GrSLType fType; |
| 104 | }; |
| 105 | |
| 106 | SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | #endif |