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 |
57 the same stage key; this function reads data from a GrGLGeometryProcesso
r and uploads any | 63 /** A GrGLPrimitiveProcessor instance can be reused with any GrGLPrimitivePr
ocessor that |
58 uniform variables required by the shaders created in emitCode(). The Gr
GeometryProcessor | 64 produces the same stage key; this function reads data from a GrGLPrimiti
veProcessor and |
59 parameter is guaranteed to be of the same type that created this GrGLGeo
metryProcessor and | 65 uploads any uniform variables required by the shaders created in emitCo
de(). The |
60 to have an identical processor key as the one that created this GrGLGeom
etryProcessor. */ | 66 GrPrimitiveProcessor parameter is guaranteed to be of the same type that
created this |
| 67 GrGLPrimitiveProcessor and to have an identical processor key as the one
that created this |
| 68 GrGLPrimitiveProcessor. */ |
61 virtual void setData(const GrGLProgramDataManager&, | 69 virtual void setData(const GrGLProgramDataManager&, |
62 const GrPrimitiveProcessor&, | 70 const GrPrimitiveProcessor&, |
63 const GrBatchTracker&) = 0; | 71 const GrBatchTracker&) = 0; |
64 | 72 |
| 73 static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoor
dTransform&); |
| 74 |
65 protected: | 75 protected: |
66 /** a helper which can setup vertex, constant, or uniform color depending on
inputType. | 76 /** 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 | 77 * 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 | 78 * inputType == attribute, then colorAttr must not be NULL. Likewise, if i
nputType == Uniform |
69 * then colorUniform must not be NULL. | 79 * then colorUniform must not be NULL. |
70 */ | 80 */ |
71 void setupColorPassThrough(GrGLGPBuilder* pb, | 81 void setupColorPassThrough(GrGLGPBuilder* pb, |
72 GrGPInput inputType, | 82 GrGPInput inputType, |
73 const char* inputName, | 83 const char* inputName, |
74 const GrGeometryProcessor::GrAttribute* colorAttr
, | 84 const GrGeometryProcessor::GrAttribute* colorAttr
, |
75 UniformHandle* colorUniform); | 85 UniformHandle* colorUniform); |
76 | 86 |
77 const char* uViewM() const { return fViewMatrixName; } | 87 const char* uViewM() const { return fViewMatrixName; } |
78 | 88 |
79 /** a helper function to setup the uniform handle for the uniform view matri
x */ | 89 /** a helper function to setup the uniform handle for the uniform view matri
x */ |
80 void addUniformViewMatrix(GrGLGPBuilder*); | 90 void addUniformViewMatrix(GrGLGPBuilder*); |
81 | 91 |
82 | 92 |
83 /** a helper function to upload a uniform viewmatrix. | 93 /** a helper function to upload a uniform viewmatrix. |
84 * TODO we can remove this function when we have deferred geometry in place | 94 * TODO we can remove this function when we have deferred geometry in place |
85 */ | 95 */ |
86 void setUniformViewMatrix(const GrGLProgramDataManager&, | 96 void setUniformViewMatrix(const GrGLProgramDataManager&, |
87 const SkMatrix& viewMatrix); | 97 const SkMatrix& viewMatrix); |
88 | 98 |
| 99 class ShaderVarHandle { |
| 100 public: |
| 101 bool isValid() const { return fHandle > -1; } |
| 102 ShaderVarHandle() : fHandle(-1) {} |
| 103 ShaderVarHandle(int value) : fHandle(value) { SkASSERT(this->isValid());
} |
| 104 int handle() const { SkASSERT(this->isValid()); return fHandle; } |
| 105 UniformHandle convertToUniformHandle() { |
| 106 SkASSERT(this->isValid()); |
| 107 return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex
(fHandle); |
| 108 } |
| 109 |
| 110 private: |
| 111 int fHandle; |
| 112 }; |
| 113 |
| 114 struct Transform { |
| 115 Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidM
atrix(); } |
| 116 ShaderVarHandle fHandle; |
| 117 SkMatrix fCurrentValue; |
| 118 GrSLType fType; |
| 119 }; |
| 120 |
| 121 SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; |
| 122 |
89 private: | 123 private: |
90 UniformHandle fViewMatrixUniform; | 124 UniformHandle fViewMatrixUniform; |
91 SkMatrix fViewMatrix; | 125 SkMatrix fViewMatrix; |
92 const char* fViewMatrixName; | 126 const char* fViewMatrixName; |
| 127 }; |
93 | 128 |
94 typedef GrGLProcessor INHERITED; | 129 class GrGLPathRendering; |
| 130 /** |
| 131 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, the
n it must inherit |
| 132 * from this class. Since paths don't have vertices, this class is only meant to
be used internally |
| 133 * by skia, for special cases. |
| 134 */ |
| 135 class GrGLGeometryProcessor : public GrGLPrimitiveProcessor { |
| 136 public: |
| 137 /* Any general emit code goes in the base class emitCode. Subclasses overri
de onEmitCode */ |
| 138 void emitCode(EmitArgs&) SK_OVERRIDE; |
| 139 |
| 140 void setTransformData(const GrPrimitiveProcessor*, |
| 141 const GrGLProgramDataManager&, |
| 142 int index, |
| 143 const SkTArray<const GrCoordTransform*, true>& transfo
rms); |
| 144 |
| 145 protected: |
| 146 const char* position() const { return "pos3"; } |
| 147 |
| 148 // Many GrGeometryProcessors do not need explicit local coords |
| 149 void emitTransforms(GrGLGPBuilder* gp, |
| 150 const char* position, |
| 151 const SkMatrix& localMatrix, |
| 152 const TransformsIn& tin, |
| 153 TransformsOut* tout) { |
| 154 this->emitTransforms(gp, position, position, localMatrix, tin, tout); |
| 155 } |
| 156 |
| 157 void emitTransforms(GrGLGPBuilder*, |
| 158 const char* position, |
| 159 const char* localCoords, |
| 160 const SkMatrix& localMatrix, |
| 161 const TransformsIn&, |
| 162 TransformsOut*); |
| 163 |
| 164 private: |
| 165 virtual void onEmitCode(EmitArgs&) = 0; |
| 166 |
| 167 typedef GrGLPrimitiveProcessor INHERITED; |
| 168 }; |
| 169 |
| 170 class GrGLGpu; |
| 171 |
| 172 class GrGLPathProcessor : public GrGLPrimitiveProcessor { |
| 173 public: |
| 174 GrGLPathProcessor(const GrPathProcessor&, const GrBatchTracker&); |
| 175 |
| 176 static void GenKey(const GrPathProcessor&, |
| 177 const GrBatchTracker& bt, |
| 178 const GrGLCaps&, |
| 179 GrProcessorKeyBuilder* b); |
| 180 |
| 181 void emitCode(EmitArgs&) SK_OVERRIDE; |
| 182 |
| 183 virtual void emitTransforms(GrGLGPBuilder*, const TransformsIn&, TransformsO
ut*) = 0; |
| 184 |
| 185 virtual void resolveSeparableVaryings(GrGLGpu* gpu, GrGLuint programId) {} |
| 186 |
| 187 void setData(const GrGLProgramDataManager&, |
| 188 const GrPrimitiveProcessor&, |
| 189 const GrBatchTracker&) SK_OVERRIDE; |
| 190 |
| 191 virtual void setTransformData(const GrPrimitiveProcessor*, |
| 192 int index, |
| 193 const SkTArray<const GrCoordTransform*, true>&
transforms, |
| 194 GrGLPathRendering*, |
| 195 GrGLuint programID) = 0; |
| 196 |
| 197 virtual void didSetData(GrGLPathRendering*) {} |
| 198 |
| 199 private: |
| 200 UniformHandle fColorUniform; |
| 201 GrColor fColor; |
| 202 |
| 203 typedef GrGLPrimitiveProcessor INHERITED; |
95 }; | 204 }; |
96 | 205 |
97 #endif | 206 #endif |
OLD | NEW |