OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "GrDefaultGeoProcFactory.h" | 8 #include "GrDefaultGeoProcFactory.h" |
9 | 9 |
10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 &fViewMatrixUniform); | 92 &fViewMatrixUniform); |
93 | 93 |
94 if (gp.hasExplicitLocalCoords()) { | 94 if (gp.hasExplicitLocalCoords()) { |
95 // emit transforms with explicit local coords | 95 // emit transforms with explicit local coords |
96 this->emitTransforms(vertBuilder, | 96 this->emitTransforms(vertBuilder, |
97 varyingHandler, | 97 varyingHandler, |
98 uniformHandler, | 98 uniformHandler, |
99 gpArgs->fPositionVar, | 99 gpArgs->fPositionVar, |
100 gp.inLocalCoords()->fName, | 100 gp.inLocalCoords()->fName, |
101 gp.localMatrix(), | 101 gp.localMatrix(), |
102 args.fFPCoordTransformHandler); | 102 args.fTransformsIn, |
| 103 args.fTransformsOut); |
103 } else { | 104 } else { |
104 // emit transforms with position | 105 // emit transforms with position |
105 this->emitTransforms(vertBuilder, | 106 this->emitTransforms(vertBuilder, |
106 varyingHandler, | 107 varyingHandler, |
107 uniformHandler, | 108 uniformHandler, |
108 gpArgs->fPositionVar, | 109 gpArgs->fPositionVar, |
109 gp.inPosition()->fName, | 110 gp.inPosition()->fName, |
110 gp.localMatrix(), | 111 gp.localMatrix(), |
111 args.fFPCoordTransformHandler); | 112 args.fTransformsIn, |
| 113 args.fTransformsOut); |
112 } | 114 } |
113 | 115 |
114 // Setup coverage as pass through | 116 // Setup coverage as pass through |
115 if (!gp.coverageWillBeIgnored()) { | 117 if (!gp.coverageWillBeIgnored()) { |
116 if (gp.hasVertexCoverage()) { | 118 if (gp.hasVertexCoverage()) { |
117 fragBuilder->codeAppendf("float alpha = 1.0;"); | 119 fragBuilder->codeAppendf("float alpha = 1.0;"); |
118 varyingHandler->addPassThroughAttribute(gp.inCoverage(), "al
pha"); | 120 varyingHandler->addPassThroughAttribute(gp.inCoverage(), "al
pha"); |
119 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCo
verage); | 121 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCo
verage); |
120 } else if (gp.coverage() == 0xff) { | 122 } else if (gp.coverage() == 0xff) { |
121 fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCovera
ge); | 123 fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCovera
ge); |
(...skipping 19 matching lines...) Expand all Loading... |
141 key |= def.hasVertexColor() << 10; | 143 key |= def.hasVertexColor() << 10; |
142 key |= def.hasVertexCoverage() << 11; | 144 key |= def.hasVertexCoverage() << 11; |
143 key |= def.coverage() == 0xff ? 0x1 << 12 : 0; | 145 key |= def.coverage() == 0xff ? 0x1 << 12 : 0; |
144 key |= def.localCoordsWillBeRead() && def.localMatrix().hasPerspecti
ve() ? 0x1 << 24 : | 146 key |= def.localCoordsWillBeRead() && def.localMatrix().hasPerspecti
ve() ? 0x1 << 24 : |
145
0x0; | 147
0x0; |
146 key |= ComputePosKey(def.viewMatrix()) << 25; | 148 key |= ComputePosKey(def.viewMatrix()) << 25; |
147 b->add32(key); | 149 b->add32(key); |
148 } | 150 } |
149 | 151 |
150 void setData(const GrGLSLProgramDataManager& pdman, | 152 void setData(const GrGLSLProgramDataManager& pdman, |
151 const GrPrimitiveProcessor& gp, | 153 const GrPrimitiveProcessor& gp) override { |
152 FPCoordTransformIter&& transformIter) override { | |
153 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); | 154 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); |
154 | 155 |
155 if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp.
viewMatrix())) { | 156 if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp.
viewMatrix())) { |
156 fViewMatrix = dgp.viewMatrix(); | 157 fViewMatrix = dgp.viewMatrix(); |
157 float viewMatrix[3 * 3]; | 158 float viewMatrix[3 * 3]; |
158 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 159 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
159 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 160 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
160 } | 161 } |
161 | 162 |
162 if (dgp.color() != fColor && !dgp.hasVertexColor()) { | 163 if (dgp.color() != fColor && !dgp.hasVertexColor()) { |
163 float c[4]; | 164 float c[4]; |
164 GrColorToRGBAFloat(dgp.color(), c); | 165 GrColorToRGBAFloat(dgp.color(), c); |
165 pdman.set4fv(fColorUniform, 1, c); | 166 pdman.set4fv(fColorUniform, 1, c); |
166 fColor = dgp.color(); | 167 fColor = dgp.color(); |
167 } | 168 } |
168 | 169 |
169 if (!dgp.coverageWillBeIgnored() && | 170 if (!dgp.coverageWillBeIgnored() && |
170 dgp.coverage() != fCoverage && !dgp.hasVertexCoverage()) { | 171 dgp.coverage() != fCoverage && !dgp.hasVertexCoverage()) { |
171 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverag
e())); | 172 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverag
e())); |
172 fCoverage = dgp.coverage(); | 173 fCoverage = dgp.coverage(); |
173 } | 174 } |
174 this->setTransformDataHelper(dgp.fLocalMatrix, pdman, &transformIter
); | 175 } |
| 176 |
| 177 void setTransformData(const GrPrimitiveProcessor& primProc, |
| 178 const GrGLSLProgramDataManager& pdman, |
| 179 int index, |
| 180 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { |
| 181 this->setTransformDataHelper(primProc.cast<DefaultGeoProc>().fLocalM
atrix, pdman, index, |
| 182 transforms); |
175 } | 183 } |
176 | 184 |
177 private: | 185 private: |
178 SkMatrix fViewMatrix; | 186 SkMatrix fViewMatrix; |
179 GrColor fColor; | 187 GrColor fColor; |
180 uint8_t fCoverage; | 188 uint8_t fCoverage; |
181 UniformHandle fViewMatrixUniform; | 189 UniformHandle fViewMatrixUniform; |
182 UniformHandle fColorUniform; | 190 UniformHandle fColorUniform; |
183 UniformHandle fCoverageUniform; | 191 UniformHandle fCoverageUniform; |
184 | 192 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 315 } |
308 | 316 |
309 if (localCoords.hasLocalMatrix()) { | 317 if (localCoords.hasLocalMatrix()) { |
310 invert.preConcat(*localCoords.fMatrix); | 318 invert.preConcat(*localCoords.fMatrix); |
311 } | 319 } |
312 } | 320 } |
313 | 321 |
314 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); | 322 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
315 return Make(color, coverage, inverted, SkMatrix::I()); | 323 return Make(color, coverage, inverted, SkMatrix::I()); |
316 } | 324 } |
OLD | NEW |