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 #include "GrOvalRenderer.h" | 8 #include "GrOvalRenderer.h" |
9 | 9 |
10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 * with origin at the circle center. Two vertex attributes are used: | 64 * with origin at the circle center. Two vertex attributes are used: |
65 * vec2f : position in device space of the bounding geometry vertices | 65 * vec2f : position in device space of the bounding geometry vertices |
66 * vec4f : (p.xy, outerRad, innerRad) | 66 * vec4f : (p.xy, outerRad, innerRad) |
67 * p is the position in the normalized space. | 67 * p is the position in the normalized space. |
68 * outerRad is the outerRadius in device space. | 68 * outerRad is the outerRadius in device space. |
69 * innerRad is the innerRadius in normalized space (ignored if not s
troking). | 69 * innerRad is the innerRadius in normalized space (ignored if not s
troking). |
70 */ | 70 */ |
71 | 71 |
72 class CircleEdgeEffect : public GrGeometryProcessor { | 72 class CircleEdgeEffect : public GrGeometryProcessor { |
73 public: | 73 public: |
74 static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatri
x& localMatrix, | 74 static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatri
x& localMatrix) { |
75 bool usesLocalCoords) { | 75 return SkNEW_ARGS(CircleEdgeEffect, (color, stroke, localMatrix)); |
76 return SkNEW_ARGS(CircleEdgeEffect, (color, stroke, localMatrix, usesLoc
alCoords)); | |
77 } | 76 } |
78 | 77 |
79 const Attribute* inPosition() const { return fInPosition; } | 78 const Attribute* inPosition() const { return fInPosition; } |
80 const Attribute* inCircleEdge() const { return fInCircleEdge; } | 79 const Attribute* inCircleEdge() const { return fInCircleEdge; } |
81 GrColor color() const { return fColor; } | 80 GrColor color() const { return fColor; } |
82 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } | |
83 const SkMatrix& localMatrix() const { return fLocalMatrix; } | 81 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
84 bool usesLocalCoords() const { return fUsesLocalCoords; } | |
85 virtual ~CircleEdgeEffect() {} | 82 virtual ~CircleEdgeEffect() {} |
86 | 83 |
87 const char* name() const override { return "CircleEdge"; } | 84 const char* name() const override { return "CircleEdge"; } |
88 | 85 |
89 inline bool isStroked() const { return fStroke; } | 86 inline bool isStroked() const { return fStroke; } |
90 | 87 |
91 class GLProcessor : public GrGLGeometryProcessor { | 88 class GLProcessor : public GrGLGeometryProcessor { |
92 public: | 89 public: |
93 GLProcessor(const GrGeometryProcessor&, | 90 GLProcessor(const GrGeometryProcessor&, |
94 const GrBatchTracker&) | 91 const GrBatchTracker&) |
95 : fColor(GrColor_ILLEGAL) {} | 92 : fColor(GrColor_ILLEGAL) {} |
96 | 93 |
97 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 94 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
98 const CircleEdgeEffect& ce = args.fGP.cast<CircleEdgeEffect>(); | 95 const CircleEdgeEffect& ce = args.fGP.cast<CircleEdgeEffect>(); |
99 GrGLGPBuilder* pb = args.fPB; | 96 GrGLGPBuilder* pb = args.fPB; |
| 97 const BatchTracker& local = args.fBT.cast<BatchTracker>(); |
100 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 98 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
101 | 99 |
102 // emit attributes | 100 // emit attributes |
103 vsBuilder->emitAttributes(ce); | 101 vsBuilder->emitAttributes(ce); |
104 | 102 |
105 GrGLVertToFrag v(kVec4f_GrSLType); | 103 GrGLVertToFrag v(kVec4f_GrSLType); |
106 args.fPB->addVarying("CircleEdge", &v); | 104 args.fPB->addVarying("CircleEdge", &v); |
107 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), ce.inCircleEdge()->fNa
me); | 105 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), ce.inCircleEdge()->fNa
me); |
108 | 106 |
109 // setup pass through color | 107 // Setup pass through color |
110 if (!ce.colorIgnored()) { | 108 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC
olor, NULL, |
111 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 109 &fColorUniform); |
112 } | |
113 | 110 |
114 // Setup position | 111 // Setup position |
115 this->setupPosition(pb, gpArgs, ce.inPosition()->fName); | 112 this->setupPosition(pb, gpArgs, ce.inPosition()->fName); |
116 | 113 |
117 // emit transforms | 114 // emit transforms |
118 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ce.inPosition()
->fName, | 115 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ce.inPosition()
->fName, |
119 ce.localMatrix(), args.fTransformsIn, args.fTra
nsformsOut); | 116 ce.localMatrix(), args.fTransformsIn, args.fTra
nsformsOut); |
120 | 117 |
121 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); | 118 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
122 fsBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); | 119 fsBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); |
123 fsBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0.
0, 1.0);", v.fsIn()); | 120 fsBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0.
0, 1.0);", v.fsIn()); |
124 if (ce.isStroked()) { | 121 if (ce.isStroked()) { |
125 fsBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %s.
w), 0.0, 1.0);", | 122 fsBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %s.
w), 0.0, 1.0);", |
126 v.fsIn(), v.fsIn()); | 123 v.fsIn(), v.fsIn()); |
127 fsBuilder->codeAppend("edgeAlpha *= innerAlpha;"); | 124 fsBuilder->codeAppend("edgeAlpha *= innerAlpha;"); |
128 } | 125 } |
129 | 126 |
130 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); | 127 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); |
131 } | 128 } |
132 | 129 |
133 static void GenKey(const GrGeometryProcessor& gp, | 130 static void GenKey(const GrGeometryProcessor& gp, |
134 const GrBatchTracker& bt, | 131 const GrBatchTracker& bt, |
135 const GrGLSLCaps&, | 132 const GrGLSLCaps&, |
136 GrProcessorKeyBuilder* b) { | 133 GrProcessorKeyBuilder* b) { |
| 134 const BatchTracker& local = bt.cast<BatchTracker>(); |
137 const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>(); | 135 const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>(); |
138 uint16_t key = ce.isStroked() ? 0x1 : 0x0; | 136 uint16_t key = ce.isStroked() ? 0x1 : 0x0; |
139 key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0
x2 : 0x0; | 137 key |= local.fUsesLocalCoords && ce.localMatrix().hasPerspective() ?
0x2 : 0x0; |
140 key |= ce.colorIgnored() ? 0x4 : 0x0; | 138 b->add32(key << 16 | local.fInputColorType); |
141 b->add32(key); | |
142 } | 139 } |
143 | 140 |
144 virtual void setData(const GrGLProgramDataManager& pdman, | 141 virtual void setData(const GrGLProgramDataManager& pdman, |
145 const GrPrimitiveProcessor& gp, | 142 const GrPrimitiveProcessor& gp, |
146 const GrBatchTracker& bt) override { | 143 const GrBatchTracker& bt) override { |
147 const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>(); | 144 const BatchTracker& local = bt.cast<BatchTracker>(); |
148 if (ce.color() != fColor) { | 145 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { |
149 GrGLfloat c[4]; | 146 GrGLfloat c[4]; |
150 GrColorToRGBAFloat(ce.color(), c); | 147 GrColorToRGBAFloat(local.fColor, c); |
151 pdman.set4fv(fColorUniform, 1, c); | 148 pdman.set4fv(fColorUniform, 1, c); |
152 fColor = ce.color(); | 149 fColor = local.fColor; |
153 } | 150 } |
154 } | 151 } |
155 | 152 |
156 void setTransformData(const GrPrimitiveProcessor& primProc, | 153 void setTransformData(const GrPrimitiveProcessor& primProc, |
157 const GrGLProgramDataManager& pdman, | 154 const GrGLProgramDataManager& pdman, |
158 int index, | 155 int index, |
159 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { | 156 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { |
160 this->setTransformDataHelper<CircleEdgeEffect>(primProc, pdman, inde
x, transforms); | 157 this->setTransformDataHelper<CircleEdgeEffect>(primProc, pdman, inde
x, transforms); |
161 } | 158 } |
162 | 159 |
163 private: | 160 private: |
164 GrColor fColor; | 161 GrColor fColor; |
165 UniformHandle fColorUniform; | 162 UniformHandle fColorUniform; |
166 typedef GrGLGeometryProcessor INHERITED; | 163 typedef GrGLGeometryProcessor INHERITED; |
167 }; | 164 }; |
168 | 165 |
169 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 166 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
170 const GrGLSLCaps& caps, | 167 const GrGLSLCaps& caps, |
171 GrProcessorKeyBuilder* b) const override { | 168 GrProcessorKeyBuilder* b) const override { |
172 GLProcessor::GenKey(*this, bt, caps, b); | 169 GLProcessor::GenKey(*this, bt, caps, b); |
173 } | 170 } |
174 | 171 |
175 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 172 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
176 const GrGLSLCaps&) const ov
erride { | 173 const GrGLSLCaps&) const ov
erride { |
177 return SkNEW_ARGS(GLProcessor, (*this, bt)); | 174 return SkNEW_ARGS(GLProcessor, (*this, bt)); |
178 } | 175 } |
179 | 176 |
| 177 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override { |
| 178 BatchTracker* local = bt->cast<BatchTracker>(); |
| 179 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, false); |
| 180 local->fUsesLocalCoords = init.fUsesLocalCoords; |
| 181 } |
| 182 |
180 private: | 183 private: |
181 CircleEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix, bo
ol usesLocalCoords) | 184 CircleEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix) |
182 : fColor(color) | 185 : fColor(color) |
183 , fLocalMatrix(localMatrix) | 186 , fLocalMatrix(localMatrix) { |
184 , fUsesLocalCoords(usesLocalCoords) { | |
185 this->initClassID<CircleEdgeEffect>(); | 187 this->initClassID<CircleEdgeEffect>(); |
186 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); | 188 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); |
187 fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", | 189 fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", |
188 kVec4f_GrVertexAttrib
Type)); | 190 kVec4f_GrVertexAttrib
Type)); |
189 fStroke = stroke; | 191 fStroke = stroke; |
190 } | 192 } |
191 | 193 |
| 194 struct BatchTracker { |
| 195 GrGPInput fInputColorType; |
| 196 GrColor fColor; |
| 197 bool fUsesLocalCoords; |
| 198 }; |
| 199 |
192 GrColor fColor; | 200 GrColor fColor; |
193 SkMatrix fLocalMatrix; | 201 SkMatrix fLocalMatrix; |
194 const Attribute* fInPosition; | 202 const Attribute* fInPosition; |
195 const Attribute* fInCircleEdge; | 203 const Attribute* fInCircleEdge; |
196 bool fStroke; | 204 bool fStroke; |
197 bool fUsesLocalCoords; | |
198 | 205 |
199 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 206 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
200 | 207 |
201 typedef GrGeometryProcessor INHERITED; | 208 typedef GrGeometryProcessor INHERITED; |
202 }; | 209 }; |
203 | 210 |
204 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(CircleEdgeEffect); | 211 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(CircleEdgeEffect); |
205 | 212 |
206 GrGeometryProcessor* CircleEdgeEffect::TestCreate(SkRandom* random, | 213 GrGeometryProcessor* CircleEdgeEffect::TestCreate(SkRandom* random, |
207 GrContext* context, | 214 GrContext* context, |
208 const GrDrawTargetCaps&, | 215 const GrDrawTargetCaps&, |
209 GrTexture* textures[]) { | 216 GrTexture* textures[]) { |
210 return CircleEdgeEffect::Create(GrRandomColor(random), | 217 return CircleEdgeEffect::Create(GrRandomColor(random), |
211 random->nextBool(), | 218 random->nextBool(), |
212 GrTest::TestMatrix(random), | 219 GrTest::TestMatrix(random)); |
213 random->nextBool()); | |
214 } | 220 } |
215 | 221 |
216 /////////////////////////////////////////////////////////////////////////////// | 222 /////////////////////////////////////////////////////////////////////////////// |
217 | 223 |
218 /** | 224 /** |
219 * The output of this effect is a modulation of the input color and coverage for
an axis-aligned | 225 * The output of this effect is a modulation of the input color and coverage for
an axis-aligned |
220 * ellipse, specified as a 2D offset from center, and the reciprocals of the out
er and inner radii, | 226 * ellipse, specified as a 2D offset from center, and the reciprocals of the out
er and inner radii, |
221 * in both x and y directions. | 227 * in both x and y directions. |
222 * | 228 * |
223 * We are using an implicit function of x^2/a^2 + y^2/b^2 - 1 = 0. | 229 * We are using an implicit function of x^2/a^2 + y^2/b^2 - 1 = 0. |
224 */ | 230 */ |
225 | 231 |
226 class EllipseEdgeEffect : public GrGeometryProcessor { | 232 class EllipseEdgeEffect : public GrGeometryProcessor { |
227 public: | 233 public: |
228 static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatri
x& localMatrix, | 234 static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatri
x& localMatrix) { |
229 bool usesLocalCoords) { | 235 return SkNEW_ARGS(EllipseEdgeEffect, (color, stroke, localMatrix)); |
230 return SkNEW_ARGS(EllipseEdgeEffect, (color, stroke, localMatrix, usesLo
calCoords)); | |
231 } | 236 } |
232 | 237 |
233 virtual ~EllipseEdgeEffect() {} | 238 virtual ~EllipseEdgeEffect() {} |
234 | 239 |
235 const char* name() const override { return "EllipseEdge"; } | 240 const char* name() const override { return "EllipseEdge"; } |
236 | 241 |
237 const Attribute* inPosition() const { return fInPosition; } | 242 const Attribute* inPosition() const { return fInPosition; } |
238 const Attribute* inEllipseOffset() const { return fInEllipseOffset; } | 243 const Attribute* inEllipseOffset() const { return fInEllipseOffset; } |
239 const Attribute* inEllipseRadii() const { return fInEllipseRadii; } | 244 const Attribute* inEllipseRadii() const { return fInEllipseRadii; } |
240 GrColor color() const { return fColor; } | 245 GrColor color() const { return fColor; } |
241 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } | |
242 const SkMatrix& localMatrix() const { return fLocalMatrix; } | 246 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
243 bool usesLocalCoords() const { return fUsesLocalCoords; } | |
244 | 247 |
245 inline bool isStroked() const { return fStroke; } | 248 inline bool isStroked() const { return fStroke; } |
246 | 249 |
247 class GLProcessor : public GrGLGeometryProcessor { | 250 class GLProcessor : public GrGLGeometryProcessor { |
248 public: | 251 public: |
249 GLProcessor(const GrGeometryProcessor&, | 252 GLProcessor(const GrGeometryProcessor&, |
250 const GrBatchTracker&) | 253 const GrBatchTracker&) |
251 : fColor(GrColor_ILLEGAL) {} | 254 : fColor(GrColor_ILLEGAL) {} |
252 | 255 |
253 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 256 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
254 const EllipseEdgeEffect& ee = args.fGP.cast<EllipseEdgeEffect>(); | 257 const EllipseEdgeEffect& ee = args.fGP.cast<EllipseEdgeEffect>(); |
255 GrGLGPBuilder* pb = args.fPB; | 258 GrGLGPBuilder* pb = args.fPB; |
| 259 const BatchTracker& local = args.fBT.cast<BatchTracker>(); |
256 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 260 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
257 | 261 |
258 // emit attributes | 262 // emit attributes |
259 vsBuilder->emitAttributes(ee); | 263 vsBuilder->emitAttributes(ee); |
260 | 264 |
261 GrGLVertToFrag ellipseOffsets(kVec2f_GrSLType); | 265 GrGLVertToFrag ellipseOffsets(kVec2f_GrSLType); |
262 args.fPB->addVarying("EllipseOffsets", &ellipseOffsets); | 266 args.fPB->addVarying("EllipseOffsets", &ellipseOffsets); |
263 vsBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(), | 267 vsBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(), |
264 ee.inEllipseOffset()->fName); | 268 ee.inEllipseOffset()->fName); |
265 | 269 |
266 GrGLVertToFrag ellipseRadii(kVec4f_GrSLType); | 270 GrGLVertToFrag ellipseRadii(kVec4f_GrSLType); |
267 args.fPB->addVarying("EllipseRadii", &ellipseRadii); | 271 args.fPB->addVarying("EllipseRadii", &ellipseRadii); |
268 vsBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), | 272 vsBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), |
269 ee.inEllipseRadii()->fName); | 273 ee.inEllipseRadii()->fName); |
270 | 274 |
271 // setup pass through color | 275 // Setup pass through color |
272 if (!ee.colorIgnored()) { | 276 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC
olor, NULL, |
273 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 277 &fColorUniform); |
274 } | |
275 | 278 |
276 // Setup position | 279 // Setup position |
277 this->setupPosition(pb, gpArgs, ee.inPosition()->fName); | 280 this->setupPosition(pb, gpArgs, ee.inPosition()->fName); |
278 | 281 |
279 // emit transforms | 282 // emit transforms |
280 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()
->fName, | 283 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()
->fName, |
281 ee.localMatrix(), args.fTransformsIn, args.fTra
nsformsOut); | 284 ee.localMatrix(), args.fTransformsIn, args.fTra
nsformsOut); |
282 | 285 |
283 // for outer curve | 286 // for outer curve |
284 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); | 287 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
(...skipping 19 matching lines...) Expand all Loading... |
304 fsBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0,
1.0);"); | 307 fsBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0,
1.0);"); |
305 } | 308 } |
306 | 309 |
307 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); | 310 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); |
308 } | 311 } |
309 | 312 |
310 static void GenKey(const GrGeometryProcessor& gp, | 313 static void GenKey(const GrGeometryProcessor& gp, |
311 const GrBatchTracker& bt, | 314 const GrBatchTracker& bt, |
312 const GrGLSLCaps&, | 315 const GrGLSLCaps&, |
313 GrProcessorKeyBuilder* b) { | 316 GrProcessorKeyBuilder* b) { |
| 317 const BatchTracker& local = bt.cast<BatchTracker>(); |
314 const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>(); | 318 const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>(); |
315 uint16_t key = ee.isStroked() ? 0x1 : 0x0; | 319 uint16_t key = ee.isStroked() ? 0x1 : 0x0; |
316 key |= ee.usesLocalCoords() && ee.localMatrix().hasPerspective() ? 0
x2 : 0x0; | 320 key |= local.fUsesLocalCoords && ee.localMatrix().hasPerspective() ?
0x2 : 0x0; |
317 key |= ee.colorIgnored() ? 0x4 : 0x0; | 321 b->add32(key << 16 | local.fInputColorType); |
318 b->add32(key); | |
319 } | 322 } |
320 | 323 |
321 virtual void setData(const GrGLProgramDataManager& pdman, | 324 virtual void setData(const GrGLProgramDataManager& pdman, |
322 const GrPrimitiveProcessor& gp, | 325 const GrPrimitiveProcessor& gp, |
323 const GrBatchTracker& bt) override { | 326 const GrBatchTracker& bt) override { |
324 const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>(); | 327 |
325 if (ee.color() != fColor) { | 328 const BatchTracker& local = bt.cast<BatchTracker>(); |
| 329 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { |
326 GrGLfloat c[4]; | 330 GrGLfloat c[4]; |
327 GrColorToRGBAFloat(ee.color(), c); | 331 GrColorToRGBAFloat(local.fColor, c); |
328 pdman.set4fv(fColorUniform, 1, c); | 332 pdman.set4fv(fColorUniform, 1, c); |
329 fColor = ee.color(); | 333 fColor = local.fColor; |
330 } | 334 } |
331 } | 335 } |
332 | 336 |
333 void setTransformData(const GrPrimitiveProcessor& primProc, | 337 void setTransformData(const GrPrimitiveProcessor& primProc, |
334 const GrGLProgramDataManager& pdman, | 338 const GrGLProgramDataManager& pdman, |
335 int index, | 339 int index, |
336 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { | 340 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { |
337 this->setTransformDataHelper<EllipseEdgeEffect>(primProc, pdman, ind
ex, transforms); | 341 this->setTransformDataHelper<EllipseEdgeEffect>(primProc, pdman, ind
ex, transforms); |
338 } | 342 } |
339 | 343 |
340 private: | 344 private: |
341 GrColor fColor; | 345 GrColor fColor; |
342 UniformHandle fColorUniform; | 346 UniformHandle fColorUniform; |
343 | 347 |
344 typedef GrGLGeometryProcessor INHERITED; | 348 typedef GrGLGeometryProcessor INHERITED; |
345 }; | 349 }; |
346 | 350 |
347 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 351 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
348 const GrGLSLCaps& caps, | 352 const GrGLSLCaps& caps, |
349 GrProcessorKeyBuilder* b) const override { | 353 GrProcessorKeyBuilder* b) const override { |
350 GLProcessor::GenKey(*this, bt, caps, b); | 354 GLProcessor::GenKey(*this, bt, caps, b); |
351 } | 355 } |
352 | 356 |
353 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 357 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
354 const GrGLSLCaps&) const ov
erride { | 358 const GrGLSLCaps&) const ov
erride { |
355 return SkNEW_ARGS(GLProcessor, (*this, bt)); | 359 return SkNEW_ARGS(GLProcessor, (*this, bt)); |
356 } | 360 } |
357 | 361 |
| 362 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override { |
| 363 BatchTracker* local = bt->cast<BatchTracker>(); |
| 364 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, false); |
| 365 local->fUsesLocalCoords = init.fUsesLocalCoords; |
| 366 } |
| 367 |
358 private: | 368 private: |
359 EllipseEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix, | 369 EllipseEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix) |
360 bool usesLocalCoords) | |
361 : fColor(color) | 370 : fColor(color) |
362 , fLocalMatrix(localMatrix) | 371 , fLocalMatrix(localMatrix) { |
363 , fUsesLocalCoords(usesLocalCoords) { | |
364 this->initClassID<EllipseEdgeEffect>(); | 372 this->initClassID<EllipseEdgeEffect>(); |
365 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); | 373 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); |
366 fInEllipseOffset = &this->addVertexAttrib(Attribute("inEllipseOffset", | 374 fInEllipseOffset = &this->addVertexAttrib(Attribute("inEllipseOffset", |
367 kVec2f_GrVertexAtt
ribType)); | 375 kVec2f_GrVertexAtt
ribType)); |
368 fInEllipseRadii = &this->addVertexAttrib(Attribute("inEllipseRadii", | 376 fInEllipseRadii = &this->addVertexAttrib(Attribute("inEllipseRadii", |
369 kVec4f_GrVertexAttr
ibType)); | 377 kVec4f_GrVertexAttr
ibType)); |
370 fStroke = stroke; | 378 fStroke = stroke; |
371 } | 379 } |
372 | 380 |
| 381 struct BatchTracker { |
| 382 GrGPInput fInputColorType; |
| 383 GrColor fColor; |
| 384 bool fUsesLocalCoords; |
| 385 }; |
| 386 |
373 const Attribute* fInPosition; | 387 const Attribute* fInPosition; |
374 const Attribute* fInEllipseOffset; | 388 const Attribute* fInEllipseOffset; |
375 const Attribute* fInEllipseRadii; | 389 const Attribute* fInEllipseRadii; |
376 GrColor fColor; | 390 GrColor fColor; |
377 SkMatrix fLocalMatrix; | 391 SkMatrix fLocalMatrix; |
378 bool fStroke; | 392 bool fStroke; |
379 bool fUsesLocalCoords; | |
380 | 393 |
381 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 394 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
382 | 395 |
383 typedef GrGeometryProcessor INHERITED; | 396 typedef GrGeometryProcessor INHERITED; |
384 }; | 397 }; |
385 | 398 |
386 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(EllipseEdgeEffect); | 399 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(EllipseEdgeEffect); |
387 | 400 |
388 GrGeometryProcessor* EllipseEdgeEffect::TestCreate(SkRandom* random, | 401 GrGeometryProcessor* EllipseEdgeEffect::TestCreate(SkRandom* random, |
389 GrContext* context, | 402 GrContext* context, |
390 const GrDrawTargetCaps&, | 403 const GrDrawTargetCaps&, |
391 GrTexture* textures[]) { | 404 GrTexture* textures[]) { |
392 return EllipseEdgeEffect::Create(GrRandomColor(random), | 405 return EllipseEdgeEffect::Create(GrRandomColor(random), |
393 random->nextBool(), | 406 random->nextBool(), |
394 GrTest::TestMatrix(random), | 407 GrTest::TestMatrix(random)); |
395 random->nextBool()); | |
396 } | 408 } |
397 | 409 |
398 /////////////////////////////////////////////////////////////////////////////// | 410 /////////////////////////////////////////////////////////////////////////////// |
399 | 411 |
400 /** | 412 /** |
401 * The output of this effect is a modulation of the input color and coverage for
an ellipse, | 413 * The output of this effect is a modulation of the input color and coverage for
an ellipse, |
402 * specified as a 2D offset from center for both the outer and inner paths (if s
troked). The | 414 * specified as a 2D offset from center for both the outer and inner paths (if s
troked). The |
403 * implict equation used is for a unit circle (x^2 + y^2 - 1 = 0) and the edge c
orrected by | 415 * implict equation used is for a unit circle (x^2 + y^2 - 1 = 0) and the edge c
orrected by |
404 * using differentials. | 416 * using differentials. |
405 * | 417 * |
406 * The result is device-independent and can be used with any affine matrix. | 418 * The result is device-independent and can be used with any affine matrix. |
407 */ | 419 */ |
408 | 420 |
409 class DIEllipseEdgeEffect : public GrGeometryProcessor { | 421 class DIEllipseEdgeEffect : public GrGeometryProcessor { |
410 public: | 422 public: |
411 enum Mode { kStroke = 0, kHairline, kFill }; | 423 enum Mode { kStroke = 0, kHairline, kFill }; |
412 | 424 |
413 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, Mode mode, | 425 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix
, Mode mode) { |
414 bool usesLocalCoords) { | 426 return SkNEW_ARGS(DIEllipseEdgeEffect, (color, viewMatrix, mode)); |
415 return SkNEW_ARGS(DIEllipseEdgeEffect, (color, viewMatrix, mode, usesLoc
alCoords)); | |
416 } | 427 } |
417 | 428 |
418 virtual ~DIEllipseEdgeEffect() {} | 429 virtual ~DIEllipseEdgeEffect() {} |
419 | 430 |
420 const char* name() const override { return "DIEllipseEdge"; } | 431 const char* name() const override { return "DIEllipseEdge"; } |
421 | 432 |
422 const Attribute* inPosition() const { return fInPosition; } | 433 const Attribute* inPosition() const { return fInPosition; } |
423 const Attribute* inEllipseOffsets0() const { return fInEllipseOffsets0; } | 434 const Attribute* inEllipseOffsets0() const { return fInEllipseOffsets0; } |
424 const Attribute* inEllipseOffsets1() const { return fInEllipseOffsets1; } | 435 const Attribute* inEllipseOffsets1() const { return fInEllipseOffsets1; } |
425 GrColor color() const { return fColor; } | 436 GrColor color() const { return fColor; } |
426 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } | |
427 const SkMatrix& viewMatrix() const { return fViewMatrix; } | 437 const SkMatrix& viewMatrix() const { return fViewMatrix; } |
428 bool usesLocalCoords() const { return fUsesLocalCoords; } | |
429 | 438 |
430 inline Mode getMode() const { return fMode; } | 439 inline Mode getMode() const { return fMode; } |
431 | 440 |
432 class GLProcessor : public GrGLGeometryProcessor { | 441 class GLProcessor : public GrGLGeometryProcessor { |
433 public: | 442 public: |
434 GLProcessor(const GrGeometryProcessor&, | 443 GLProcessor(const GrGeometryProcessor&, |
435 const GrBatchTracker&) | 444 const GrBatchTracker&) |
436 : fColor(GrColor_ILLEGAL) {} | 445 : fColor(GrColor_ILLEGAL) {} |
437 | 446 |
438 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 447 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
439 const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>()
; | 448 const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>()
; |
440 GrGLGPBuilder* pb = args.fPB; | 449 GrGLGPBuilder* pb = args.fPB; |
| 450 const BatchTracker& local = args.fBT.cast<BatchTracker>(); |
441 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 451 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
442 | 452 |
443 // emit attributes | 453 // emit attributes |
444 vsBuilder->emitAttributes(ee); | 454 vsBuilder->emitAttributes(ee); |
445 | 455 |
446 GrGLVertToFrag offsets0(kVec2f_GrSLType); | 456 GrGLVertToFrag offsets0(kVec2f_GrSLType); |
447 args.fPB->addVarying("EllipseOffsets0", &offsets0); | 457 args.fPB->addVarying("EllipseOffsets0", &offsets0); |
448 vsBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), | 458 vsBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), |
449 ee.inEllipseOffsets0()->fName); | 459 ee.inEllipseOffsets0()->fName); |
450 | 460 |
451 GrGLVertToFrag offsets1(kVec2f_GrSLType); | 461 GrGLVertToFrag offsets1(kVec2f_GrSLType); |
452 args.fPB->addVarying("EllipseOffsets1", &offsets1); | 462 args.fPB->addVarying("EllipseOffsets1", &offsets1); |
453 vsBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), | 463 vsBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), |
454 ee.inEllipseOffsets1()->fName); | 464 ee.inEllipseOffsets1()->fName); |
455 | 465 |
456 // setup pass through color | 466 // Setup pass through color |
457 if (!ee.colorIgnored()) { | 467 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputC
olor, NULL, |
458 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 468 &fColorUniform); |
459 } | |
460 | 469 |
461 // Setup position | 470 // Setup position |
462 this->setupPosition(pb, gpArgs, ee.inPosition()->fName, ee.viewMatri
x()); | 471 this->setupPosition(pb, gpArgs, ee.inPosition()->fName, ee.viewMatri
x()); |
463 | 472 |
464 // emit transforms | 473 // emit transforms |
465 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()
->fName, | 474 this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()
->fName, |
466 args.fTransformsIn, args.fTransformsOut); | 475 args.fTransformsIn, args.fTransformsOut); |
467 | 476 |
468 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); | 477 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
469 SkAssertResult(fsBuilder->enableFeature( | 478 SkAssertResult(fsBuilder->enableFeature( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 fsBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0,
1.0);"); | 512 fsBuilder->codeAppend("edgeAlpha *= clamp(0.5+test*invlen, 0.0,
1.0);"); |
504 } | 513 } |
505 | 514 |
506 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); | 515 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); |
507 } | 516 } |
508 | 517 |
509 static void GenKey(const GrGeometryProcessor& gp, | 518 static void GenKey(const GrGeometryProcessor& gp, |
510 const GrBatchTracker& bt, | 519 const GrBatchTracker& bt, |
511 const GrGLSLCaps&, | 520 const GrGLSLCaps&, |
512 GrProcessorKeyBuilder* b) { | 521 GrProcessorKeyBuilder* b) { |
| 522 const BatchTracker& local = bt.cast<BatchTracker>(); |
513 const DIEllipseEdgeEffect& ellipseEffect = gp.cast<DIEllipseEdgeEffe
ct>(); | 523 const DIEllipseEdgeEffect& ellipseEffect = gp.cast<DIEllipseEdgeEffe
ct>(); |
514 uint16_t key = ellipseEffect.getMode(); | 524 uint16_t key = ellipseEffect.getMode(); |
515 key |= ellipseEffect.colorIgnored() << 9; | 525 key |= ComputePosKey(ellipseEffect.viewMatrix()) << 9; |
516 key |= ComputePosKey(ellipseEffect.viewMatrix()) << 10; | 526 b->add32(key << 16 | local.fInputColorType); |
517 b->add32(key); | |
518 } | 527 } |
519 | 528 |
520 virtual void setData(const GrGLProgramDataManager& pdman, | 529 virtual void setData(const GrGLProgramDataManager& pdman, |
521 const GrPrimitiveProcessor& gp, | 530 const GrPrimitiveProcessor& gp, |
522 const GrBatchTracker& bt) override { | 531 const GrBatchTracker& bt) override { |
523 const DIEllipseEdgeEffect& dee = gp.cast<DIEllipseEdgeEffect>(); | 532 const DIEllipseEdgeEffect& dee = gp.cast<DIEllipseEdgeEffect>(); |
524 this->setUniformViewMatrix(pdman, dee.viewMatrix()); | 533 this->setUniformViewMatrix(pdman, dee.viewMatrix()); |
525 | 534 |
526 if (dee.color() != fColor) { | 535 const BatchTracker& local = bt.cast<BatchTracker>(); |
| 536 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { |
527 GrGLfloat c[4]; | 537 GrGLfloat c[4]; |
528 GrColorToRGBAFloat(dee.color(), c); | 538 GrColorToRGBAFloat(local.fColor, c); |
529 pdman.set4fv(fColorUniform, 1, c); | 539 pdman.set4fv(fColorUniform, 1, c); |
530 fColor = dee.color(); | 540 fColor = local.fColor; |
531 } | 541 } |
532 } | 542 } |
533 | 543 |
534 private: | 544 private: |
535 GrColor fColor; | 545 GrColor fColor; |
536 UniformHandle fColorUniform; | 546 UniformHandle fColorUniform; |
537 | 547 |
538 typedef GrGLGeometryProcessor INHERITED; | 548 typedef GrGLGeometryProcessor INHERITED; |
539 }; | 549 }; |
540 | 550 |
541 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 551 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
542 const GrGLSLCaps& caps, | 552 const GrGLSLCaps& caps, |
543 GrProcessorKeyBuilder* b) const override { | 553 GrProcessorKeyBuilder* b) const override { |
544 GLProcessor::GenKey(*this, bt, caps, b); | 554 GLProcessor::GenKey(*this, bt, caps, b); |
545 } | 555 } |
546 | 556 |
547 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 557 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
548 const GrGLSLCaps&) const ov
erride { | 558 const GrGLSLCaps&) const ov
erride { |
549 return SkNEW_ARGS(GLProcessor, (*this, bt)); | 559 return SkNEW_ARGS(GLProcessor, (*this, bt)); |
550 } | 560 } |
551 | 561 |
| 562 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override { |
| 563 BatchTracker* local = bt->cast<BatchTracker>(); |
| 564 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, false); |
| 565 local->fUsesLocalCoords = init.fUsesLocalCoords; |
| 566 } |
| 567 |
552 private: | 568 private: |
553 DIEllipseEdgeEffect(GrColor color, const SkMatrix& viewMatrix, Mode mode, | 569 DIEllipseEdgeEffect(GrColor color, const SkMatrix& viewMatrix, Mode mode) |
554 bool usesLocalCoords) | |
555 : fColor(color) | 570 : fColor(color) |
556 , fViewMatrix(viewMatrix) | 571 , fViewMatrix(viewMatrix) { |
557 , fUsesLocalCoords(usesLocalCoords) { | |
558 this->initClassID<DIEllipseEdgeEffect>(); | 572 this->initClassID<DIEllipseEdgeEffect>(); |
559 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); | 573 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); |
560 fInEllipseOffsets0 = &this->addVertexAttrib(Attribute("inEllipseOffsets0
", | 574 fInEllipseOffsets0 = &this->addVertexAttrib(Attribute("inEllipseOffsets0
", |
561 kVec2f_GrVertexAtt
ribType)); | 575 kVec2f_GrVertexA
ttribType)); |
562 fInEllipseOffsets1 = &this->addVertexAttrib(Attribute("inEllipseOffsets1
", | 576 fInEllipseOffsets1 = &this->addVertexAttrib(Attribute("inEllipseOffsets1
", |
563 kVec2f_GrVertexAtt
ribType)); | 577 kVec2f_GrVertexA
ttribType)); |
564 fMode = mode; | 578 fMode = mode; |
565 } | 579 } |
566 | 580 |
| 581 struct BatchTracker { |
| 582 GrGPInput fInputColorType; |
| 583 GrColor fColor; |
| 584 bool fUsesLocalCoords; |
| 585 }; |
| 586 |
567 const Attribute* fInPosition; | 587 const Attribute* fInPosition; |
568 const Attribute* fInEllipseOffsets0; | 588 const Attribute* fInEllipseOffsets0; |
569 const Attribute* fInEllipseOffsets1; | 589 const Attribute* fInEllipseOffsets1; |
570 GrColor fColor; | 590 GrColor fColor; |
571 SkMatrix fViewMatrix; | 591 SkMatrix fViewMatrix; |
572 Mode fMode; | 592 Mode fMode; |
573 bool fUsesLocalCoords; | |
574 | 593 |
575 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 594 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
576 | 595 |
577 typedef GrGeometryProcessor INHERITED; | 596 typedef GrGeometryProcessor INHERITED; |
578 }; | 597 }; |
579 | 598 |
580 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DIEllipseEdgeEffect); | 599 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DIEllipseEdgeEffect); |
581 | 600 |
582 GrGeometryProcessor* DIEllipseEdgeEffect::TestCreate(SkRandom* random, | 601 GrGeometryProcessor* DIEllipseEdgeEffect::TestCreate(SkRandom* random, |
583 GrContext* context, | 602 GrContext* context, |
584 const GrDrawTargetCaps&, | 603 const GrDrawTargetCaps&, |
585 GrTexture* textures[]) { | 604 GrTexture* textures[]) { |
586 return DIEllipseEdgeEffect::Create(GrRandomColor(random), | 605 return DIEllipseEdgeEffect::Create(GrRandomColor(random), |
587 GrTest::TestMatrix(random), | 606 GrTest::TestMatrix(random), |
588 (Mode)(random->nextRangeU(0,2)), | 607 (Mode)(random->nextRangeU(0,2))); |
589 random->nextBool()); | |
590 } | 608 } |
591 | 609 |
592 /////////////////////////////////////////////////////////////////////////////// | 610 /////////////////////////////////////////////////////////////////////////////// |
593 | 611 |
594 bool GrOvalRenderer::drawOval(GrDrawTarget* target, | 612 bool GrOvalRenderer::drawOval(GrDrawTarget* target, |
595 GrPipelineBuilder* pipelineBuilder, | 613 GrPipelineBuilder* pipelineBuilder, |
596 GrColor color, | 614 GrColor color, |
597 const SkMatrix& viewMatrix, | 615 const SkMatrix& viewMatrix, |
598 bool useAA, | 616 bool useAA, |
599 const SkRect& oval, | 617 const SkRect& oval, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 685 |
668 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 686 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
669 SkMatrix invert; | 687 SkMatrix invert; |
670 if (!this->viewMatrix().invert(&invert)) { | 688 if (!this->viewMatrix().invert(&invert)) { |
671 return; | 689 return; |
672 } | 690 } |
673 | 691 |
674 // Setup geometry processor | 692 // Setup geometry processor |
675 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), | 693 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), |
676 this->stro
ke(), | 694 this->stro
ke(), |
677 invert, | 695 invert)); |
678 this->uses
LocalCoords())); | |
679 | 696 |
680 batchTarget->initDraw(gp, pipeline); | 697 batchTarget->initDraw(gp, pipeline); |
681 | 698 |
| 699 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
| 700 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
| 701 // everywhere we can remove this nastiness |
| 702 GrPipelineInfo init; |
| 703 init.fColorIgnored = fBatch.fColorIgnored; |
| 704 init.fOverrideColor = GrColor_ILLEGAL; |
| 705 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 706 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 707 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 708 |
682 int instanceCount = fGeoData.count(); | 709 int instanceCount = fGeoData.count(); |
683 size_t vertexStride = gp->getVertexStride(); | 710 size_t vertexStride = gp->getVertexStride(); |
684 SkASSERT(vertexStride == sizeof(CircleVertex)); | 711 SkASSERT(vertexStride == sizeof(CircleVertex)); |
685 QuadHelper helper; | 712 QuadHelper helper; |
686 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(batchT
arget, vertexStride, | 713 CircleVertex* verts = reinterpret_cast<CircleVertex*>(helper.init(batchT
arget, vertexStride, |
687 instan
ceCount)); | 714 instan
ceCount)); |
688 if (!verts) { | 715 if (!verts) { |
689 return; | 716 return; |
690 } | 717 } |
691 | 718 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 | 909 |
883 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 910 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
884 SkMatrix invert; | 911 SkMatrix invert; |
885 if (!this->viewMatrix().invert(&invert)) { | 912 if (!this->viewMatrix().invert(&invert)) { |
886 return; | 913 return; |
887 } | 914 } |
888 | 915 |
889 // Setup geometry processor | 916 // Setup geometry processor |
890 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), | 917 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), |
891 this->str
oke(), | 918 this->str
oke(), |
892 invert, | 919 invert)); |
893 this->use
sLocalCoords())); | |
894 | 920 |
895 batchTarget->initDraw(gp, pipeline); | 921 batchTarget->initDraw(gp, pipeline); |
896 | 922 |
| 923 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
| 924 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
| 925 // everywhere we can remove this nastiness |
| 926 GrPipelineInfo init; |
| 927 init.fColorIgnored = fBatch.fColorIgnored; |
| 928 init.fOverrideColor = GrColor_ILLEGAL; |
| 929 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 930 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 931 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 932 |
897 int instanceCount = fGeoData.count(); | 933 int instanceCount = fGeoData.count(); |
898 QuadHelper helper; | 934 QuadHelper helper; |
899 size_t vertexStride = gp->getVertexStride(); | 935 size_t vertexStride = gp->getVertexStride(); |
900 SkASSERT(vertexStride == sizeof(EllipseVertex)); | 936 SkASSERT(vertexStride == sizeof(EllipseVertex)); |
901 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( | 937 EllipseVertex* verts = reinterpret_cast<EllipseVertex*>( |
902 helper.init(batchTarget, vertexStride, instanceCount)); | 938 helper.init(batchTarget, vertexStride, instanceCount)); |
903 if (!verts) { | 939 if (!verts) { |
904 return; | 940 return; |
905 } | 941 } |
906 | 942 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 fBatch.fColor = fGeoData[0].fColor; | 1177 fBatch.fColor = fGeoData[0].fColor; |
1142 fBatch.fMode = fGeoData[0].fMode; | 1178 fBatch.fMode = fGeoData[0].fMode; |
1143 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; | 1179 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
1144 fBatch.fCoverageIgnored = init.fCoverageIgnored; | 1180 fBatch.fCoverageIgnored = init.fCoverageIgnored; |
1145 } | 1181 } |
1146 | 1182 |
1147 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 1183 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
1148 // Setup geometry processor | 1184 // Setup geometry processor |
1149 SkAutoTUnref<GrGeometryProcessor> gp(DIEllipseEdgeEffect::Create(this->c
olor(), | 1185 SkAutoTUnref<GrGeometryProcessor> gp(DIEllipseEdgeEffect::Create(this->c
olor(), |
1150 this->v
iewMatrix(), | 1186 this->v
iewMatrix(), |
1151 this->m
ode(), | 1187 this->m
ode())); |
1152 this->u
sesLocalCoords())); | |
1153 | 1188 |
1154 batchTarget->initDraw(gp, pipeline); | 1189 batchTarget->initDraw(gp, pipeline); |
1155 | 1190 |
| 1191 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
| 1192 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
| 1193 // everywhere we can remove this nastiness |
| 1194 GrPipelineInfo init; |
| 1195 init.fColorIgnored = fBatch.fColorIgnored; |
| 1196 init.fOverrideColor = GrColor_ILLEGAL; |
| 1197 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 1198 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 1199 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 1200 |
1156 int instanceCount = fGeoData.count(); | 1201 int instanceCount = fGeoData.count(); |
1157 size_t vertexStride = gp->getVertexStride(); | 1202 size_t vertexStride = gp->getVertexStride(); |
1158 SkASSERT(vertexStride == sizeof(DIEllipseVertex)); | 1203 SkASSERT(vertexStride == sizeof(DIEllipseVertex)); |
1159 QuadHelper helper; | 1204 QuadHelper helper; |
1160 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>( | 1205 DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>( |
1161 helper.init(batchTarget, vertexStride, instanceCount)); | 1206 helper.init(batchTarget, vertexStride, instanceCount)); |
1162 if (!verts) { | 1207 if (!verts) { |
1163 return; | 1208 return; |
1164 } | 1209 } |
1165 | 1210 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 // reset to device coordinates | 1542 // reset to device coordinates |
1498 SkMatrix invert; | 1543 SkMatrix invert; |
1499 if (!this->viewMatrix().invert(&invert)) { | 1544 if (!this->viewMatrix().invert(&invert)) { |
1500 SkDebugf("Failed to invert\n"); | 1545 SkDebugf("Failed to invert\n"); |
1501 return; | 1546 return; |
1502 } | 1547 } |
1503 | 1548 |
1504 // Setup geometry processor | 1549 // Setup geometry processor |
1505 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), | 1550 SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->colo
r(), |
1506 this->stro
ke(), | 1551 this->stro
ke(), |
1507 invert, | 1552 invert)); |
1508 this->uses
LocalCoords())); | |
1509 | 1553 |
1510 batchTarget->initDraw(gp, pipeline); | 1554 batchTarget->initDraw(gp, pipeline); |
1511 | 1555 |
| 1556 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
| 1557 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
| 1558 // everywhere we can remove this nastiness |
| 1559 GrPipelineInfo init; |
| 1560 init.fColorIgnored = fBatch.fColorIgnored; |
| 1561 init.fOverrideColor = GrColor_ILLEGAL; |
| 1562 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 1563 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 1564 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 1565 |
1512 int instanceCount = fGeoData.count(); | 1566 int instanceCount = fGeoData.count(); |
1513 size_t vertexStride = gp->getVertexStride(); | 1567 size_t vertexStride = gp->getVertexStride(); |
1514 SkASSERT(vertexStride == sizeof(CircleVertex)); | 1568 SkASSERT(vertexStride == sizeof(CircleVertex)); |
1515 | 1569 |
1516 // drop out the middle quad if we're stroked | 1570 // drop out the middle quad if we're stroked |
1517 int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndi
cesPerRRect; | 1571 int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndi
cesPerRRect; |
1518 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 1572 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
1519 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); | 1573 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); |
1520 | 1574 |
1521 InstancedHelper helper; | 1575 InstancedHelper helper; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 // reset to device coordinates | 1724 // reset to device coordinates |
1671 SkMatrix invert; | 1725 SkMatrix invert; |
1672 if (!this->viewMatrix().invert(&invert)) { | 1726 if (!this->viewMatrix().invert(&invert)) { |
1673 SkDebugf("Failed to invert\n"); | 1727 SkDebugf("Failed to invert\n"); |
1674 return; | 1728 return; |
1675 } | 1729 } |
1676 | 1730 |
1677 // Setup geometry processor | 1731 // Setup geometry processor |
1678 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), | 1732 SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->col
or(), |
1679 this->str
oke(), | 1733 this->str
oke(), |
1680 invert, | 1734 invert)); |
1681 this->use
sLocalCoords())); | |
1682 | 1735 |
1683 batchTarget->initDraw(gp, pipeline); | 1736 batchTarget->initDraw(gp, pipeline); |
1684 | 1737 |
| 1738 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
| 1739 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
| 1740 // everywhere we can remove this nastiness |
| 1741 GrPipelineInfo init; |
| 1742 init.fColorIgnored = fBatch.fColorIgnored; |
| 1743 init.fOverrideColor = GrColor_ILLEGAL; |
| 1744 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 1745 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 1746 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 1747 |
1685 int instanceCount = fGeoData.count(); | 1748 int instanceCount = fGeoData.count(); |
1686 size_t vertexStride = gp->getVertexStride(); | 1749 size_t vertexStride = gp->getVertexStride(); |
1687 SkASSERT(vertexStride == sizeof(EllipseVertex)); | 1750 SkASSERT(vertexStride == sizeof(EllipseVertex)); |
1688 | 1751 |
1689 // drop out the middle quad if we're stroked | 1752 // drop out the middle quad if we're stroked |
1690 int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndi
cesPerRRect; | 1753 int indicesPerInstance = this->stroke() ? kIndicesPerStrokeRRect : kIndi
cesPerRRect; |
1691 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 1754 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
1692 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); | 1755 ref_rrect_index_buffer(this->stroke(), batchTarget->resourceProvider
())); |
1693 | 1756 |
1694 InstancedHelper helper; | 1757 InstancedHelper helper; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2018 } | 2081 } |
2019 | 2082 |
2020 BATCH_TEST_DEFINE(RRectBatch) { | 2083 BATCH_TEST_DEFINE(RRectBatch) { |
2021 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 2084 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
2022 GrColor color = GrRandomColor(random); | 2085 GrColor color = GrRandomColor(random); |
2023 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 2086 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
2024 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 2087 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
2025 } | 2088 } |
2026 | 2089 |
2027 #endif | 2090 #endif |
OLD | NEW |