OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGLGeometryProcessor_DEFINED | 8 #ifndef GrGLGeometryProcessor_DEFINED |
9 #define GrGLGeometryProcessor_DEFINED | 9 #define GrGLGeometryProcessor_DEFINED |
10 | 10 |
11 #include "GrGLProcessor.h" | 11 #include "GrGLProcessor.h" |
12 | 12 |
13 class GrBatchTracker; | 13 class GrBatchTracker; |
| 14 class GrFragmentProcessor; |
14 class GrGLGPBuilder; | 15 class GrGLGPBuilder; |
15 | 16 |
16 /** | 17 class GrGLPrimitiveProcessor { |
17 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, the
n it must inherit | |
18 * from this class. Since paths don't have vertices, this class is only meant to
be used internally | |
19 * by skia, for special cases. | |
20 */ | |
21 class GrGLGeometryProcessor { | |
22 public: | 18 public: |
23 GrGLGeometryProcessor() : fViewMatrixName(NULL) { fViewMatrix = SkMatrix::In
validMatrix(); } | 19 GrGLPrimitiveProcessor() : fViewMatrixName(NULL) { fViewMatrix = SkMatrix::I
nvalidMatrix(); } |
24 virtual ~GrGLGeometryProcessor() {} | 20 virtual ~GrGLPrimitiveProcessor() {} |
25 | 21 |
26 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 22 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
27 typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; | 23 typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; |
28 | 24 |
| 25 typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords; |
| 26 typedef SkSTArray<8, ProcCoords> TransformsIn; |
| 27 typedef SkSTArray<8, GrGLProcessor::TransformedCoordsArray> TransformsOut; |
| 28 |
29 struct EmitArgs { | 29 struct EmitArgs { |
30 EmitArgs(GrGLGPBuilder* pb, | 30 EmitArgs(GrGLGPBuilder* pb, |
31 const GrPrimitiveProcessor& gp, | 31 const GrPrimitiveProcessor& gp, |
32 const GrBatchTracker& bt, | 32 const GrBatchTracker& bt, |
33 const char* outputColor, | 33 const char* outputColor, |
34 const char* outputCoverage, | 34 const char* outputCoverage, |
35 const TextureSamplerArray& samplers) | 35 const TextureSamplerArray& samplers, |
| 36 const TransformsIn& transformsIn, |
| 37 TransformsOut* transformsOut) |
36 : fPB(pb) | 38 : fPB(pb) |
37 , fGP(gp) | 39 , fGP(gp) |
38 , fBT(bt) | 40 , fBT(bt) |
39 , fOutputColor(outputColor) | 41 , fOutputColor(outputColor) |
40 , fOutputCoverage(outputCoverage) | 42 , fOutputCoverage(outputCoverage) |
41 , fSamplers(samplers) {} | 43 , fSamplers(samplers) |
| 44 , fTransformsIn(transformsIn) |
| 45 , fTransformsOut(transformsOut) {} |
42 GrGLGPBuilder* fPB; | 46 GrGLGPBuilder* fPB; |
43 const GrPrimitiveProcessor& fGP; | 47 const GrPrimitiveProcessor& fGP; |
44 const GrBatchTracker& fBT; | 48 const GrBatchTracker& fBT; |
45 const char* fOutputColor; | 49 const char* fOutputColor; |
46 const char* fOutputCoverage; | 50 const char* fOutputCoverage; |
47 const TextureSamplerArray& fSamplers; | 51 const TextureSamplerArray& fSamplers; |
| 52 const TransformsIn& fTransformsIn; |
| 53 TransformsOut* fTransformsOut; |
48 }; | 54 }; |
49 | 55 |
50 /** | 56 /** |
51 * This is similar to emitCode() in the base class, except it takes a full s
hader builder. | 57 * This is similar to emitCode() in the base class, except it takes a full s
hader builder. |
52 * This allows the effect subclass to emit vertex code. | 58 * This allows the effect subclass to emit vertex code. |
53 */ | 59 */ |
54 virtual void emitCode(const EmitArgs&) = 0; | 60 virtual void emitCode(EmitArgs&) = 0; |
55 | 61 |
56 /** A GrGLGeometryProcessor instance can be reused with any GrGLGeometryProc
essor that produces | 62 /** A GrGLPrimitiveProcessor instance can be reused with any GrGLPrimitivePr
ocessor that |
57 the same stage key; this function reads data from a GrGLGeometryProcesso
r and uploads any | 63 produces the same stage key; this function reads data from a GrGLPrimiti
veProcessor and |
58 uniform variables required by the shaders created in emitCode(). The Gr
GeometryProcessor | 64 uploads any uniform variables required by the shaders created in emitCo
de(). The |
59 parameter is guaranteed to be of the same type that created this GrGLGeo
metryProcessor and | 65 GrPrimitiveProcessor parameter is guaranteed to be of the same type that
created this |
60 to have an identical processor key as the one that created this GrGLGeom
etryProcessor. */ | 66 GrGLPrimitiveProcessor and to have an identical processor key as the one
that created this |
| 67 GrGLPrimitiveProcessor. */ |
61 virtual void setData(const GrGLProgramDataManager&, | 68 virtual void setData(const GrGLProgramDataManager&, |
62 const GrPrimitiveProcessor&, | 69 const GrPrimitiveProcessor&, |
63 const GrBatchTracker&) = 0; | 70 const GrBatchTracker&) = 0; |
64 | 71 |
| 72 static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoor
dTransform&); |
| 73 |
65 protected: | 74 protected: |
66 /** a helper which can setup vertex, constant, or uniform color depending on
inputType. | 75 /** a helper which can setup vertex, constant, or uniform color depending on
inputType. |
67 * This function will only do the minimum required to emit the correct shad
er code. If | 76 * This function will only do the minimum required to emit the correct shad
er code. If |
68 * inputType == attribute, then colorAttr must not be NULL. Likewise, if i
nputType == Uniform | 77 * inputType == attribute, then colorAttr must not be NULL. Likewise, if i
nputType == Uniform |
69 * then colorUniform must not be NULL. | 78 * then colorUniform must not be NULL. |
70 */ | 79 */ |
71 void setupColorPassThrough(GrGLGPBuilder* pb, | 80 void setupColorPassThrough(GrGLGPBuilder* pb, |
72 GrGPInput inputType, | 81 GrGPInput inputType, |
73 const char* inputName, | 82 const char* inputName, |
74 const GrGeometryProcessor::GrAttribute* colorAttr
, | 83 const GrGeometryProcessor::GrAttribute* colorAttr
, |
75 UniformHandle* colorUniform); | 84 UniformHandle* colorUniform); |
76 | 85 |
77 const char* uViewM() const { return fViewMatrixName; } | 86 const char* uViewM() const { return fViewMatrixName; } |
78 | 87 |
79 /** a helper function to setup the uniform handle for the uniform view matri
x */ | 88 /** a helper function to setup the uniform handle for the uniform view matri
x */ |
80 void addUniformViewMatrix(GrGLGPBuilder*); | 89 void addUniformViewMatrix(GrGLGPBuilder*); |
81 | 90 |
82 | 91 |
83 /** a helper function to upload a uniform viewmatrix. | 92 /** a helper function to upload a uniform viewmatrix. |
84 * TODO we can remove this function when we have deferred geometry in place | 93 * TODO we can remove this function when we have deferred geometry in place |
85 */ | 94 */ |
86 void setUniformViewMatrix(const GrGLProgramDataManager&, | 95 void setUniformViewMatrix(const GrGLProgramDataManager&, |
87 const SkMatrix& viewMatrix); | 96 const SkMatrix& viewMatrix); |
88 | 97 |
| 98 class ShaderVarHandle { |
| 99 public: |
| 100 bool isValid() const { return fHandle > -1; } |
| 101 ShaderVarHandle() : fHandle(-1) {} |
| 102 ShaderVarHandle(int value) : fHandle(value) { SkASSERT(this->isValid());
} |
| 103 int handle() const { SkASSERT(this->isValid()); return fHandle; } |
| 104 UniformHandle convertToUniformHandle() { |
| 105 SkASSERT(this->isValid()); |
| 106 return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex
(fHandle); |
| 107 } |
| 108 |
| 109 private: |
| 110 int fHandle; |
| 111 }; |
| 112 |
| 113 struct Transform { |
| 114 Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidM
atrix(); } |
| 115 ShaderVarHandle fHandle; |
| 116 SkMatrix fCurrentValue; |
| 117 GrSLType fType; |
| 118 }; |
| 119 |
| 120 SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; |
| 121 |
89 private: | 122 private: |
90 UniformHandle fViewMatrixUniform; | 123 UniformHandle fViewMatrixUniform; |
91 SkMatrix fViewMatrix; | 124 SkMatrix fViewMatrix; |
92 const char* fViewMatrixName; | 125 const char* fViewMatrixName; |
| 126 }; |
93 | 127 |
94 typedef GrGLProcessor INHERITED; | 128 class GrGLPathRendering; |
| 129 /** |
| 130 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, the
n it must inherit |
| 131 * from this class. Since paths don't have vertices, this class is only meant to
be used internally |
| 132 * by skia, for special cases. |
| 133 */ |
| 134 class GrGLGeometryProcessor : public GrGLPrimitiveProcessor { |
| 135 public: |
| 136 void setTransformData(const GrPrimitiveProcessor*, |
| 137 const GrGLProgramDataManager&, |
| 138 int index, |
| 139 const SkTArray<const GrCoordTransform*, true>& transfo
rms); |
| 140 |
| 141 protected: |
| 142 // Many GrGeometryProcessors do not need explicit local coords |
| 143 void emitTransforms(GrGLGPBuilder* gp, |
| 144 const char* position, |
| 145 const SkMatrix& localMatrix, |
| 146 const TransformsIn& tin, |
| 147 TransformsOut* tout) { |
| 148 this->emitTransforms(gp, position, position, localMatrix, tin, tout); |
| 149 } |
| 150 |
| 151 void emitTransforms(GrGLGPBuilder*, |
| 152 const char* position, |
| 153 const char* localCoords, |
| 154 const SkMatrix& localMatrix, |
| 155 const TransformsIn&, |
| 156 TransformsOut*); |
| 157 |
| 158 private: |
| 159 typedef GrGLPrimitiveProcessor INHERITED; |
| 160 }; |
| 161 |
| 162 class GrGLGpu; |
| 163 |
| 164 class GrGLPathProcessor : public GrGLPrimitiveProcessor { |
| 165 public: |
| 166 GrGLPathProcessor(const GrPathProcessor&, const GrBatchTracker&); |
| 167 |
| 168 static void GenKey(const GrPathProcessor&, |
| 169 const GrBatchTracker& bt, |
| 170 const GrGLCaps&, |
| 171 GrProcessorKeyBuilder* b); |
| 172 |
| 173 void emitCode(EmitArgs&) SK_OVERRIDE; |
| 174 |
| 175 virtual void emitTransforms(GrGLGPBuilder*, const TransformsIn&, TransformsO
ut*) = 0; |
| 176 |
| 177 virtual void resolveSeparableVaryings(GrGLGpu* gpu, GrGLuint programId) {} |
| 178 |
| 179 void setData(const GrGLProgramDataManager&, |
| 180 const GrPrimitiveProcessor&, |
| 181 const GrBatchTracker&) SK_OVERRIDE; |
| 182 |
| 183 virtual void setTransformData(const GrPrimitiveProcessor*, |
| 184 int index, |
| 185 const SkTArray<const GrCoordTransform*, true>&
transforms, |
| 186 GrGLPathRendering*, |
| 187 GrGLuint programID) = 0; |
| 188 |
| 189 virtual void didSetData(GrGLPathRendering*) {} |
| 190 |
| 191 private: |
| 192 UniformHandle fColorUniform; |
| 193 GrColor fColor; |
| 194 |
| 195 typedef GrGLPrimitiveProcessor INHERITED; |
95 }; | 196 }; |
96 | 197 |
97 #endif | 198 #endif |
OLD | NEW |