OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrPLSPathRenderer.h" | 8 #include "GrPLSPathRenderer.h" |
9 | 9 |
10 #include "SkChunkAlloc.h" | 10 #include "SkChunkAlloc.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "glsl/GrGLSLGeometryProcessor.h" | 29 #include "glsl/GrGLSLGeometryProcessor.h" |
30 #include "gl/builders/GrGLProgramBuilder.h" | 30 #include "gl/builders/GrGLProgramBuilder.h" |
31 #include "glsl/GrGLSLPLSPathRendering.h" | 31 #include "glsl/GrGLSLPLSPathRendering.h" |
32 | 32 |
33 GrPLSPathRenderer::GrPLSPathRenderer() { | 33 GrPLSPathRenderer::GrPLSPathRenderer() { |
34 } | 34 } |
35 | 35 |
36 struct PLSVertex { | 36 struct PLSVertex { |
37 SkPoint fPos; | 37 SkPoint fPos; |
38 // for triangles, these are the three triangle vertices | 38 // for triangles, these are the three triangle vertices |
39 // for quads, vert1 is the texture UV coords, and vert2 and vert3 are the li
ne segment | 39 // for quads, vert1 is the texture UV coords, and vert2 and vert3 are the li
ne segment |
40 // comprising the flat edge of the quad | 40 // comprising the flat edge of the quad |
41 SkPoint fVert1; | 41 SkPoint fVert1; |
42 SkPoint fVert2; | 42 SkPoint fVert2; |
43 SkPoint fVert3; | 43 SkPoint fVert3; |
44 int fWinding; | 44 int fWinding; |
45 }; | 45 }; |
46 typedef SkTArray<PLSVertex, true> PLSVertices; | 46 typedef SkTArray<PLSVertex, true> PLSVertices; |
47 | 47 |
48 typedef SkTArray<SkPoint, true> FinishVertices; | 48 typedef SkTArray<SkPoint, true> FinishVertices; |
49 | 49 |
50 static const float kCubicTolerance = 0.5f; | 50 static const float kCubicTolerance = 0.5f; |
51 static const float kConicTolerance = 0.5f; | 51 static const float kConicTolerance = 0.5f; |
52 | 52 |
53 static const float kBloatSize = 1.0f; | 53 static const float kBloatSize = 1.0f; |
54 | 54 |
55 static const float kBloatLimit = 640000.0f; | 55 static const float kBloatLimit = 640000.0f; |
56 | 56 |
57 #define kQuadNumVertices 5 | 57 #define kQuadNumVertices 5 |
58 static void add_quad(SkPoint pts[3], PLSVertices& vertices) { | 58 static void add_quad(SkPoint pts[3], PLSVertices& vertices) { |
59 SkPoint normal = SkPoint::Make(pts[0].fY - pts[2].fY, | 59 SkPoint normal = SkPoint::Make(pts[0].fY - pts[2].fY, |
60 pts[2].fX - pts[0].fX); | 60 pts[2].fX - pts[0].fX); |
61 normal.setLength(kBloatSize); | 61 normal.setLength(kBloatSize); |
62 SkScalar cross = (pts[1] - pts[0]).cross(pts[2] - pts[0]); | 62 SkScalar cross = (pts[1] - pts[0]).cross(pts[2] - pts[0]); |
63 if (cross < 0) { | 63 if (cross < 0) { |
64 normal = -normal; | 64 normal = -normal; |
65 } | 65 } |
66 PLSVertex quad[kQuadNumVertices]; | 66 PLSVertex quad[kQuadNumVertices]; |
67 quad[0].fPos = pts[0] + normal; | 67 quad[0].fPos = pts[0] + normal; |
68 quad[1].fPos = pts[0] - normal; | 68 quad[1].fPos = pts[0] - normal; |
69 quad[2].fPos = pts[1] - normal; | 69 quad[2].fPos = pts[1] - normal; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 result[2] = pts[2]; | 125 result[2] = pts[2]; |
126 if (!outset(&result[2], -line3, -line2)) { | 126 if (!outset(&result[2], -line3, -line2)) { |
127 return false; | 127 return false; |
128 } | 128 } |
129 pts[0] = result[0]; | 129 pts[0] = result[0]; |
130 pts[1] = result[1]; | 130 pts[1] = result[1]; |
131 pts[2] = result[2]; | 131 pts[2] = result[2]; |
132 return true; | 132 return true; |
133 } | 133 } |
134 | 134 |
135 static bool get_geometry(const SkPath& path, const SkMatrix& m, PLSVertices& tri
Vertices, | 135 static bool get_geometry(const SkPath& path, const SkMatrix& m, PLSVertices& tri
Vertices, |
136 PLSVertices& quadVertices, GrResourceProvider* resource
Provider, | 136 PLSVertices& quadVertices, GrResourceProvider* resource
Provider, |
137 SkRect bounds) { | 137 SkRect bounds) { |
138 SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance; | 138 SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance; |
139 SkScalar tol = GrPathUtils::scaleToleranceToSrc(screenSpaceTol, m, bounds); | 139 SkScalar tol = GrPathUtils::scaleToleranceToSrc(screenSpaceTol, m, bounds); |
140 int contourCnt; | 140 int contourCnt; |
141 int maxPts = GrPathUtils::worstCasePointCount(path, &contourCnt, tol); | 141 int maxPts = GrPathUtils::worstCasePointCount(path, &contourCnt, tol); |
142 if (maxPts <= 0) { | 142 if (maxPts <= 0) { |
143 return 0; | 143 return 0; |
144 } | 144 } |
145 SkPath linesOnlyPath; | 145 SkPath linesOnlyPath; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 GrGLSLVertexBuilder* vsBuilder = args.fVertBuilder; | 285 GrGLSLVertexBuilder* vsBuilder = args.fVertBuilder; |
286 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; | 286 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
287 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 287 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
288 | 288 |
289 varyingHandler->emitAttributes(te); | 289 varyingHandler->emitAttributes(te); |
290 | 290 |
291 this->setupPosition(vsBuilder, gpArgs, te.inPosition()->fName); | 291 this->setupPosition(vsBuilder, gpArgs, te.inPosition()->fName); |
292 | 292 |
293 GrGLSLVertToFrag v1(kVec2f_GrSLType); | 293 GrGLSLVertToFrag v1(kVec2f_GrSLType); |
294 varyingHandler->addVarying("Vertex1", &v1, kHigh_GrSLPrecision); | 294 varyingHandler->addVarying("Vertex1", &v1, kHigh_GrSLPrecision); |
295 vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", | 295 vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", |
296 v1.vsOut(), | 296 v1.vsOut(), |
297 te.inVertex1()->fName, | 297 te.inVertex1()->fName, |
298 te.inVertex1()->fName); | 298 te.inVertex1()->fName); |
299 | 299 |
300 GrGLSLVertToFrag v2(kVec2f_GrSLType); | 300 GrGLSLVertToFrag v2(kVec2f_GrSLType); |
301 varyingHandler->addVarying("Vertex2", &v2, kHigh_GrSLPrecision); | 301 varyingHandler->addVarying("Vertex2", &v2, kHigh_GrSLPrecision); |
302 vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", | 302 vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", |
303 v2.vsOut(), | 303 v2.vsOut(), |
304 te.inVertex2()->fName, | 304 te.inVertex2()->fName, |
305 te.inVertex2()->fName); | 305 te.inVertex2()->fName); |
306 | 306 |
307 GrGLSLVertToFrag v3(kVec2f_GrSLType); | 307 GrGLSLVertToFrag v3(kVec2f_GrSLType); |
308 varyingHandler->addVarying("Vertex3", &v3, kHigh_GrSLPrecision); | 308 varyingHandler->addVarying("Vertex3", &v3, kHigh_GrSLPrecision); |
309 vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", | 309 vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", |
310 v3.vsOut(), | 310 v3.vsOut(), |
311 te.inVertex3()->fName, | 311 te.inVertex3()->fName, |
312 te.inVertex3()->fName); | 312 te.inVertex3()->fName); |
313 | 313 |
314 GrGLSLVertToFrag delta1(kVec2f_GrSLType); | 314 GrGLSLVertToFrag delta1(kVec2f_GrSLType); |
315 varyingHandler->addVarying("delta1", &delta1, kHigh_GrSLPrecision); | 315 varyingHandler->addVarying("delta1", &delta1, kHigh_GrSLPrecision); |
316 vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;",
| 316 vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;", |
317 delta1.vsOut(), v1.vsOut(), v2.vsOut(), v2.vs
Out(), v1.vsOut()); | 317 delta1.vsOut(), v1.vsOut(), v2.vsOut(), v2.vs
Out(), v1.vsOut()); |
318 | 318 |
319 GrGLSLVertToFrag delta2(kVec2f_GrSLType); | 319 GrGLSLVertToFrag delta2(kVec2f_GrSLType); |
320 varyingHandler->addVarying("delta2", &delta2, kHigh_GrSLPrecision); | 320 varyingHandler->addVarying("delta2", &delta2, kHigh_GrSLPrecision); |
321 vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;",
| 321 vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;", |
322 delta2.vsOut(), v2.vsOut(), v3.vsOut(), v3.vs
Out(), v2.vsOut()); | 322 delta2.vsOut(), v2.vsOut(), v3.vsOut(), v3.vs
Out(), v2.vsOut()); |
323 | 323 |
324 GrGLSLVertToFrag delta3(kVec2f_GrSLType); | 324 GrGLSLVertToFrag delta3(kVec2f_GrSLType); |
325 varyingHandler->addVarying("delta3", &delta3, kHigh_GrSLPrecision); | 325 varyingHandler->addVarying("delta3", &delta3, kHigh_GrSLPrecision); |
326 vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;",
| 326 vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;", |
327 delta3.vsOut(), v3.vsOut(), v1.vsOut(), v1.vs
Out(), v3.vsOut()); | 327 delta3.vsOut(), v3.vsOut(), v1.vsOut(), v1.vs
Out(), v3.vsOut()); |
328 | 328 |
329 GrGLSLVertToFrag windings(kInt_GrSLType); | 329 GrGLSLVertToFrag windings(kInt_GrSLType); |
330 varyingHandler->addFlatVarying("windings", &windings, kLow_GrSLPreci
sion); | 330 varyingHandler->addFlatVarying("windings", &windings, kLow_GrSLPreci
sion); |
331 vsBuilder->codeAppendf("%s = %s;", | 331 vsBuilder->codeAppendf("%s = %s;", |
332 windings.vsOut(), te.inWindings()->fName); | 332 windings.vsOut(), te.inWindings()->fName); |
333 | 333 |
334 // emit transforms | 334 // emit transforms |
335 this->emitTransforms(vsBuilder, varyingHandler, uniformHandler, gpAr
gs->fPositionVar, | 335 this->emitTransforms(vsBuilder, varyingHandler, uniformHandler, gpAr
gs->fPositionVar, |
336 te.inPosition()->fName, te.localMatrix(), args.
fTransformsIn, | 336 te.inPosition()->fName, te.localMatrix(), args.
fTransformsIn, |
337 args.fTransformsOut); | 337 args.fTransformsOut); |
338 | 338 |
339 GrGLSLPPFragmentBuilder* fsBuilder = args.fFragBuilder; | 339 GrGLSLPPFragmentBuilder* fsBuilder = args.fFragBuilder; |
340 SkAssertResult(fsBuilder->enableFeature( | 340 SkAssertResult(fsBuilder->enableFeature( |
341 GrGLSLFragmentShaderBuilder::kPixelLocalStorage_GLSLF
eature)); | 341 GrGLSLFragmentShaderBuilder::kPixelLocalStorage_GLSLF
eature)); |
342 SkAssertResult(fsBuilder->enableFeature( | 342 SkAssertResult(fsBuilder->enableFeature( |
343 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | 343 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); |
344 fsBuilder->declAppendf(GR_GL_PLS_PATH_DATA_DECL); | 344 fsBuilder->declAppendf(GR_GL_PLS_PATH_DATA_DECL); |
345 // Compute four subsamples, each shifted a quarter pixel along x and
y from | 345 // Compute four subsamples, each shifted a quarter pixel along x and
y from |
346 // gl_FragCoord. The oriented box positioning of the subsamples is o
f course not | 346 // gl_FragCoord. The oriented box positioning of the subsamples is o
f course not |
347 // optimal, but it greatly simplifies the math and this simplificati
on is necessary for | 347 // optimal, but it greatly simplifies the math and this simplificati
on is necessary for |
348 // performance reasons. | 348 // performance reasons. |
349 fsBuilder->codeAppendf("highp vec2 firstSample = %s.xy - vec2(0.25);
", | 349 fsBuilder->codeAppendf("highp vec2 firstSample = %s.xy - vec2(0.25);
", |
350 fsBuilder->fragmentPosition()); | 350 fsBuilder->fragmentPosition()); |
351 fsBuilder->codeAppendf("highp vec2 delta1 = %s;", delta1.fsIn()); | 351 fsBuilder->codeAppendf("highp vec2 delta1 = %s;", delta1.fsIn()); |
352 fsBuilder->codeAppendf("highp vec2 delta2 = %s;", delta2.fsIn()); | 352 fsBuilder->codeAppendf("highp vec2 delta2 = %s;", delta2.fsIn()); |
353 fsBuilder->codeAppendf("highp vec2 delta3 = %s;", delta3.fsIn()); | 353 fsBuilder->codeAppendf("highp vec2 delta3 = %s;", delta3.fsIn()); |
354 // Check whether first sample is inside the triangle by computing th
ree dot products. If | 354 // Check whether first sample is inside the triangle by computing th
ree dot products. If |
355 // all are < 0, we're inside. The first vector in each case is half
of what it is | 355 // all are < 0, we're inside. The first vector in each case is half
of what it is |
356 // "supposed" to be, because we re-use them later as adjustment fact
ors for which half | 356 // "supposed" to be, because we re-use them later as adjustment fact
ors for which half |
357 // is the correct value, so we multiply the dots by two to compensat
e. | 357 // is the correct value, so we multiply the dots by two to compensat
e. |
358 fsBuilder->codeAppendf("highp float d1 = dot(delta1, (firstSample -
%s).yx) * 2.0;", | 358 fsBuilder->codeAppendf("highp float d1 = dot(delta1, (firstSample -
%s).yx) * 2.0;", |
359 v1.fsIn()); | 359 v1.fsIn()); |
360 fsBuilder->codeAppendf("highp float d2 = dot(delta2, (firstSample -
%s).yx) * 2.0;", | 360 fsBuilder->codeAppendf("highp float d2 = dot(delta2, (firstSample -
%s).yx) * 2.0;", |
361 v2.fsIn()); | 361 v2.fsIn()); |
362 fsBuilder->codeAppendf("highp float d3 = dot(delta3, (firstSample -
%s).yx) * 2.0;", | 362 fsBuilder->codeAppendf("highp float d3 = dot(delta3, (firstSample -
%s).yx) * 2.0;", |
363 v3.fsIn()); | 363 v3.fsIn()); |
364 fsBuilder->codeAppend("highp float dmax = max(d1, max(d2, d3));"); | 364 fsBuilder->codeAppend("highp float dmax = max(d1, max(d2, d3));"); |
365 fsBuilder->codeAppendf("pls.windings[0] += (dmax <= 0.0) ? %s : 0;",
windings.fsIn()); | 365 fsBuilder->codeAppendf("pls.windings[0] += (dmax <= 0.0) ? %s : 0;",
windings.fsIn()); |
366 // for subsequent samples, we don't recalculate the entire dot produ
ct -- just adjust it | 366 // for subsequent samples, we don't recalculate the entire dot produ
ct -- just adjust it |
367 // to the value it would have if we did recompute it. | 367 // to the value it would have if we did recompute it. |
368 fsBuilder->codeAppend("d1 += delta1.x;"); | 368 fsBuilder->codeAppend("d1 += delta1.x;"); |
369 fsBuilder->codeAppend("d2 += delta2.x;"); | 369 fsBuilder->codeAppend("d2 += delta2.x;"); |
370 fsBuilder->codeAppend("d3 += delta3.x;"); | 370 fsBuilder->codeAppend("d3 += delta3.x;"); |
371 fsBuilder->codeAppend("dmax = max(d1, max(d2, d3));"); | 371 fsBuilder->codeAppend("dmax = max(d1, max(d2, d3));"); |
372 fsBuilder->codeAppendf("pls.windings[1] += (dmax <= 0.0) ? %s : 0;",
windings.fsIn()); | 372 fsBuilder->codeAppendf("pls.windings[1] += (dmax <= 0.0) ? %s : 0;",
windings.fsIn()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 413 |
414 virtual GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) cons
t override { | 414 virtual GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) cons
t override { |
415 return new GLSLProcessor(*this); | 415 return new GLSLProcessor(*this); |
416 } | 416 } |
417 | 417 |
418 private: | 418 private: |
419 PLSAATriangleEffect(const SkMatrix& localMatrix, bool usesLocalCoords) | 419 PLSAATriangleEffect(const SkMatrix& localMatrix, bool usesLocalCoords) |
420 : fLocalMatrix(localMatrix) | 420 : fLocalMatrix(localMatrix) |
421 , fUsesLocalCoords(usesLocalCoords) { | 421 , fUsesLocalCoords(usesLocalCoords) { |
422 this->initClassID<PLSAATriangleEffect>(); | 422 this->initClassID<PLSAATriangleEffect>(); |
423 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType, | 423 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType, |
424 kHigh_GrSLPrecision)); | 424 kHigh_GrSLPrecision)); |
425 fInVertex1 = &this->addVertexAttrib(Attribute("inVertex1", kVec2f_GrVert
exAttribType, | 425 fInVertex1 = &this->addVertexAttrib(Attribute("inVertex1", kVec2f_GrVert
exAttribType, |
426 kHigh_GrSLPrecision)); | 426 kHigh_GrSLPrecision)); |
427 fInVertex2 = &this->addVertexAttrib(Attribute("inVertex2", kVec2f_GrVert
exAttribType, | 427 fInVertex2 = &this->addVertexAttrib(Attribute("inVertex2", kVec2f_GrVert
exAttribType, |
428 kHigh_GrSLPrecision)); | 428 kHigh_GrSLPrecision)); |
429 fInVertex3 = &this->addVertexAttrib(Attribute("inVertex3", kVec2f_GrVert
exAttribType, | 429 fInVertex3 = &this->addVertexAttrib(Attribute("inVertex3", kVec2f_GrVert
exAttribType, |
430 kHigh_GrSLPrecision)); | 430 kHigh_GrSLPrecision)); |
431 fInWindings = &this->addVertexAttrib(Attribute("inWindings", kInt_GrVert
exAttribType, | 431 fInWindings = &this->addVertexAttrib(Attribute("inWindings", kInt_GrVert
exAttribType, |
432 kLow_GrSLPrecision)); | 432 kLow_GrSLPrecision)); |
433 this->setWillReadFragmentPosition(); | 433 this->setWillReadFragmentPosition(); |
434 } | 434 } |
435 | 435 |
436 const Attribute* fInPosition; | 436 const Attribute* fInPosition; |
437 const Attribute* fInVertex1; | 437 const Attribute* fInVertex1; |
438 const Attribute* fInVertex2; | 438 const Attribute* fInVertex2; |
439 const Attribute* fInVertex3; | 439 const Attribute* fInVertex3; |
440 const Attribute* fInWindings; | 440 const Attribute* fInWindings; |
441 SkMatrix fLocalMatrix; | 441 SkMatrix fLocalMatrix; |
442 bool fUsesLocalCoords; | 442 bool fUsesLocalCoords; |
443 | 443 |
444 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 444 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
445 | 445 |
446 typedef GrGeometryProcessor INHERITED; | 446 typedef GrGeometryProcessor INHERITED; |
447 }; | 447 }; |
448 | 448 |
449 /////////////////////////////////////////////////////////////////////////////// | 449 /////////////////////////////////////////////////////////////////////////////// |
450 | 450 |
451 /* | 451 /* |
452 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first | 452 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first |
453 * two components of the vertex attribute. Coverage is based on signed | 453 * two components of the vertex attribute. Coverage is based on signed |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 490 |
491 // emit attributes | 491 // emit attributes |
492 varyingHandler->emitAttributes(qe); | 492 varyingHandler->emitAttributes(qe); |
493 | 493 |
494 GrGLSLVertToFrag uv(kVec2f_GrSLType); | 494 GrGLSLVertToFrag uv(kVec2f_GrSLType); |
495 varyingHandler->addVarying("uv", &uv, kHigh_GrSLPrecision); | 495 varyingHandler->addVarying("uv", &uv, kHigh_GrSLPrecision); |
496 vsBuilder->codeAppendf("%s = %s;", uv.vsOut(), qe.inUV()->fName); | 496 vsBuilder->codeAppendf("%s = %s;", uv.vsOut(), qe.inUV()->fName); |
497 | 497 |
498 GrGLSLVertToFrag ep1(kVec2f_GrSLType); | 498 GrGLSLVertToFrag ep1(kVec2f_GrSLType); |
499 varyingHandler->addVarying("endpoint1", &ep1, kHigh_GrSLPrecision); | 499 varyingHandler->addVarying("endpoint1", &ep1, kHigh_GrSLPrecision); |
500 vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", ep1.vsOut(), | 500 vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", ep1.vsOut(), |
501 qe.inEndpoint1()->fName, qe.inEndpoint1()->fNa
me); | 501 qe.inEndpoint1()->fName, qe.inEndpoint1()->fNa
me); |
502 | 502 |
503 GrGLSLVertToFrag ep2(kVec2f_GrSLType); | 503 GrGLSLVertToFrag ep2(kVec2f_GrSLType); |
504 varyingHandler->addVarying("endpoint2", &ep2, kHigh_GrSLPrecision); | 504 varyingHandler->addVarying("endpoint2", &ep2, kHigh_GrSLPrecision); |
505 vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", ep2.vsOut(), | 505 vsBuilder->codeAppendf("%s = vec2(%s.x, %s.y);", ep2.vsOut(), |
506 qe.inEndpoint2()->fName, qe.inEndpoint2()->fNa
me); | 506 qe.inEndpoint2()->fName, qe.inEndpoint2()->fNa
me); |
507 | 507 |
508 GrGLSLVertToFrag delta(kVec2f_GrSLType); | 508 GrGLSLVertToFrag delta(kVec2f_GrSLType); |
509 varyingHandler->addVarying("delta", &delta, kHigh_GrSLPrecision); | 509 varyingHandler->addVarying("delta", &delta, kHigh_GrSLPrecision); |
510 vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;",
| 510 vsBuilder->codeAppendf("%s = vec2(%s.x - %s.x, %s.y - %s.y) * 0.5;", |
511 delta.vsOut(), ep1.vsOut(), ep2.vsOut(), ep2.
vsOut(), | 511 delta.vsOut(), ep1.vsOut(), ep2.vsOut(), ep2.
vsOut(), |
512 ep1.vsOut()); | 512 ep1.vsOut()); |
513 | 513 |
514 GrGLSLVertToFrag windings(kInt_GrSLType); | 514 GrGLSLVertToFrag windings(kInt_GrSLType); |
515 varyingHandler->addFlatVarying("windings", &windings, kLow_GrSLPreci
sion); | 515 varyingHandler->addFlatVarying("windings", &windings, kLow_GrSLPreci
sion); |
516 vsBuilder->codeAppendf("%s = %s;", | 516 vsBuilder->codeAppendf("%s = %s;", |
517 windings.vsOut(), qe.inWindings()->fName); | 517 windings.vsOut(), qe.inWindings()->fName); |
518 | 518 |
519 // Setup position | 519 // Setup position |
520 this->setupPosition(vsBuilder, gpArgs, qe.inPosition()->fName); | 520 this->setupPosition(vsBuilder, gpArgs, qe.inPosition()->fName); |
521 | 521 |
522 // emit transforms | 522 // emit transforms |
523 this->emitTransforms(vsBuilder, varyingHandler, uniformHandler, gpAr
gs->fPositionVar, | 523 this->emitTransforms(vsBuilder, varyingHandler, uniformHandler, gpAr
gs->fPositionVar, |
524 qe.inPosition()->fName, qe.localMatrix(), args.
fTransformsIn, | 524 qe.inPosition()->fName, qe.localMatrix(), args.
fTransformsIn, |
525 args.fTransformsOut); | 525 args.fTransformsOut); |
526 | 526 |
527 GrGLSLPPFragmentBuilder* fsBuilder = args.fFragBuilder; | 527 GrGLSLPPFragmentBuilder* fsBuilder = args.fFragBuilder; |
528 SkAssertResult(fsBuilder->enableFeature( | 528 SkAssertResult(fsBuilder->enableFeature( |
529 GrGLSLFragmentShaderBuilder::kPixelLocalStorage_GLSLF
eature)); | 529 GrGLSLFragmentShaderBuilder::kPixelLocalStorage_GLSLF
eature)); |
530 SkAssertResult(fsBuilder->enableFeature( | 530 SkAssertResult(fsBuilder->enableFeature( |
531 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | 531 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); |
532 static const int QUAD_ARGS = 2; | 532 static const int QUAD_ARGS = 2; |
533 GrGLSLShaderVar inQuadArgs[QUAD_ARGS] = { | 533 GrGLSLShaderVar inQuadArgs[QUAD_ARGS] = { |
534 GrGLSLShaderVar("dot", kFloat_GrSLType, 0, kHigh_GrSLPrecision), | 534 GrGLSLShaderVar("dot", kFloat_GrSLType, 0, kHigh_GrSLPrecision), |
535 GrGLSLShaderVar("uv", kVec2f_GrSLType, 0, kHigh_GrSLPrecision) | 535 GrGLSLShaderVar("uv", kVec2f_GrSLType, 0, kHigh_GrSLPrecision) |
536 }; | 536 }; |
537 SkString inQuadName; | 537 SkString inQuadName; |
538 | 538 |
539 const char* inQuadCode = "if (uv.x * uv.x <= uv.y) {" | 539 const char* inQuadCode = "if (uv.x * uv.x <= uv.y) {" |
540 "return dot >= 0.0;" | 540 "return dot >= 0.0;" |
541 "} else {" | 541 "} else {" |
542 "return false;" | 542 "return false;" |
543 "}"; | 543 "}"; |
544 fsBuilder->emitFunction(kBool_GrSLType, "in_quad", QUAD_ARGS, inQuad
Args, inQuadCode, | 544 fsBuilder->emitFunction(kBool_GrSLType, "in_quad", QUAD_ARGS, inQuad
Args, inQuadCode, |
545 &inQuadName); | 545 &inQuadName); |
546 fsBuilder->declAppendf(GR_GL_PLS_PATH_DATA_DECL); | 546 fsBuilder->declAppendf(GR_GL_PLS_PATH_DATA_DECL); |
547 // keep the derivative instructions outside the conditional | 547 // keep the derivative instructions outside the conditional |
548 fsBuilder->codeAppendf("highp vec2 uvdX = dFdx(%s);", uv.fsIn()); | 548 fsBuilder->codeAppendf("highp vec2 uvdX = dFdx(%s);", uv.fsIn()); |
549 fsBuilder->codeAppendf("highp vec2 uvdY = dFdy(%s);", uv.fsIn()); | 549 fsBuilder->codeAppendf("highp vec2 uvdY = dFdy(%s);", uv.fsIn()); |
550 fsBuilder->codeAppend("highp vec2 uvIncX = uvdX * 0.45 + uvdY * -0.1
;"); | 550 fsBuilder->codeAppend("highp vec2 uvIncX = uvdX * 0.45 + uvdY * -0.1
;"); |
551 fsBuilder->codeAppend("highp vec2 uvIncY = uvdX * 0.1 + uvdY * 0.55;
"); | 551 fsBuilder->codeAppend("highp vec2 uvIncY = uvdX * 0.1 + uvdY * 0.55;
"); |
552 fsBuilder->codeAppendf("highp vec2 uv = %s.xy - uvdX * 0.35 - uvdY *
0.25;", | 552 fsBuilder->codeAppendf("highp vec2 uv = %s.xy - uvdX * 0.35 - uvdY *
0.25;", |
553 uv.fsIn()); | 553 uv.fsIn()); |
554 fsBuilder->codeAppendf("highp vec2 firstSample = %s.xy - vec2(0.25);
", | 554 fsBuilder->codeAppendf("highp vec2 firstSample = %s.xy - vec2(0.25);
", |
555 fsBuilder->fragmentPosition()); | 555 fsBuilder->fragmentPosition()); |
556 fsBuilder->codeAppendf("highp float d = dot(%s, (firstSample - %s).y
x) * 2.0;", | 556 fsBuilder->codeAppendf("highp float d = dot(%s, (firstSample - %s).y
x) * 2.0;", |
557 delta.fsIn(), ep1.fsIn()); | 557 delta.fsIn(), ep1.fsIn()); |
558 fsBuilder->codeAppendf("pls.windings[0] += %s(d, uv) ? %s : 0;", inQ
uadName.c_str(), | 558 fsBuilder->codeAppendf("pls.windings[0] += %s(d, uv) ? %s : 0;", inQ
uadName.c_str(), |
559 windings.fsIn()); | 559 windings.fsIn()); |
560 fsBuilder->codeAppend("uv += uvIncX;"); | 560 fsBuilder->codeAppend("uv += uvIncX;"); |
561 fsBuilder->codeAppendf("d += %s.x;", delta.fsIn()); | 561 fsBuilder->codeAppendf("d += %s.x;", delta.fsIn()); |
562 fsBuilder->codeAppendf("pls.windings[1] += %s(d, uv) ? %s : 0;", inQ
uadName.c_str(), | 562 fsBuilder->codeAppendf("pls.windings[1] += %s(d, uv) ? %s : 0;", inQ
uadName.c_str(), |
563 windings.fsIn()); | 563 windings.fsIn()); |
564 fsBuilder->codeAppend("uv += uvIncY;"); | 564 fsBuilder->codeAppend("uv += uvIncY;"); |
565 fsBuilder->codeAppendf("d += %s.y;", delta.fsIn()); | 565 fsBuilder->codeAppendf("d += %s.y;", delta.fsIn()); |
566 fsBuilder->codeAppendf("pls.windings[2] += %s(d, uv) ? %s : 0;", inQ
uadName.c_str(), | 566 fsBuilder->codeAppendf("pls.windings[2] += %s(d, uv) ? %s : 0;", inQ
uadName.c_str(), |
567 windings.fsIn()); | 567 windings.fsIn()); |
568 fsBuilder->codeAppend("uv -= uvIncX;"); | 568 fsBuilder->codeAppend("uv -= uvIncX;"); |
569 fsBuilder->codeAppendf("d -= %s.x;", delta.fsIn()); | 569 fsBuilder->codeAppendf("d -= %s.x;", delta.fsIn()); |
570 fsBuilder->codeAppendf("pls.windings[3] += %s(d, uv) ? %s : 0;", inQ
uadName.c_str(), | 570 fsBuilder->codeAppendf("pls.windings[3] += %s(d, uv) ? %s : 0;", inQ
uadName.c_str(), |
571 windings.fsIn()); | 571 windings.fsIn()); |
572 } | 572 } |
573 | 573 |
574 static inline void GenKey(const GrGeometryProcessor& gp, | 574 static inline void GenKey(const GrGeometryProcessor& gp, |
575 const GrGLSLCaps&, | 575 const GrGLSLCaps&, |
576 GrProcessorKeyBuilder* b) { | 576 GrProcessorKeyBuilder* b) { |
577 const PLSQuadEdgeEffect& qee = gp.cast<PLSQuadEdgeEffect>(); | 577 const PLSQuadEdgeEffect& qee = gp.cast<PLSQuadEdgeEffect>(); |
578 uint32_t key = 0; | 578 uint32_t key = 0; |
579 key |= qee.usesLocalCoords() && qee.localMatrix().hasPerspective() ?
0x1 : 0x0; | 579 key |= qee.usesLocalCoords() && qee.localMatrix().hasPerspective() ?
0x1 : 0x0; |
580 b->add32(key); | 580 b->add32(key); |
(...skipping 21 matching lines...) Expand all Loading... |
602 | 602 |
603 virtual GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) cons
t override { | 603 virtual GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) cons
t override { |
604 return new GLSLProcessor(*this); | 604 return new GLSLProcessor(*this); |
605 } | 605 } |
606 | 606 |
607 private: | 607 private: |
608 PLSQuadEdgeEffect(const SkMatrix& localMatrix, bool usesLocalCoords) | 608 PLSQuadEdgeEffect(const SkMatrix& localMatrix, bool usesLocalCoords) |
609 : fLocalMatrix(localMatrix) | 609 : fLocalMatrix(localMatrix) |
610 , fUsesLocalCoords(usesLocalCoords) { | 610 , fUsesLocalCoords(usesLocalCoords) { |
611 this->initClassID<PLSQuadEdgeEffect>(); | 611 this->initClassID<PLSQuadEdgeEffect>(); |
612 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType, | 612 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType, |
613 kHigh_GrSLPrecision)); | 613 kHigh_GrSLPrecision)); |
614 fInUV = &this->addVertexAttrib(Attribute("inUV", kVec2f_GrVertexAttribTy
pe, | 614 fInUV = &this->addVertexAttrib(Attribute("inUV", kVec2f_GrVertexAttribTy
pe, |
615 kHigh_GrSLPrecision)); | 615 kHigh_GrSLPrecision)); |
616 fInEndpoint1 = &this->addVertexAttrib(Attribute("inEndpoint1", kVec2f_Gr
VertexAttribType, | 616 fInEndpoint1 = &this->addVertexAttrib(Attribute("inEndpoint1", kVec2f_Gr
VertexAttribType, |
617 kHigh_GrSLPrecision)); | 617 kHigh_GrSLPrecision)); |
618 fInEndpoint2 = &this->addVertexAttrib(Attribute("inEndpoint2", kVec2f_Gr
VertexAttribType, | 618 fInEndpoint2 = &this->addVertexAttrib(Attribute("inEndpoint2", kVec2f_Gr
VertexAttribType, |
619 kHigh_GrSLPrecision)); | 619 kHigh_GrSLPrecision)); |
620 fInWindings = &this->addVertexAttrib(Attribute("inWindings", kInt_GrVer
texAttribType, | 620 fInWindings = &this->addVertexAttrib(Attribute("inWindings", kInt_GrVer
texAttribType, |
621 kLow_GrSLPrecision)); | 621 kLow_GrSLPrecision)); |
622 this->setWillReadFragmentPosition(); | 622 this->setWillReadFragmentPosition(); |
623 } | 623 } |
624 | 624 |
625 const Attribute* fInPosition; | 625 const Attribute* fInPosition; |
626 const Attribute* fInUV; | 626 const Attribute* fInUV; |
627 const Attribute* fInEndpoint1; | 627 const Attribute* fInEndpoint1; |
628 const Attribute* fInEndpoint2; | 628 const Attribute* fInEndpoint2; |
629 const Attribute* fInWindings; | 629 const Attribute* fInWindings; |
630 SkMatrix fLocalMatrix; | 630 SkMatrix fLocalMatrix; |
631 bool fUsesLocalCoords; | 631 bool fUsesLocalCoords; |
632 | 632 |
633 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 633 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
634 | 634 |
635 typedef GrGeometryProcessor INHERITED; | 635 typedef GrGeometryProcessor INHERITED; |
636 }; | 636 }; |
637 | 637 |
638 class PLSFinishEffect : public GrGeometryProcessor { | 638 class PLSFinishEffect : public GrGeometryProcessor { |
639 public: | 639 public: |
640 | 640 |
641 static GrGeometryProcessor* Create(GrColor color, bool useEvenOdd, const SkM
atrix& localMatrix, | 641 static GrGeometryProcessor* Create(GrColor color, bool useEvenOdd, const SkM
atrix& localMatrix, |
642 bool usesLocalCoords) { | 642 bool usesLocalCoords) { |
643 return new PLSFinishEffect(color, useEvenOdd, localMatrix, usesLocalCoor
ds); | 643 return new PLSFinishEffect(color, useEvenOdd, localMatrix, usesLocalCoor
ds); |
644 } | 644 } |
645 | 645 |
646 virtual ~PLSFinishEffect() {} | 646 virtual ~PLSFinishEffect() {} |
647 | 647 |
648 const char* name() const override { return "PLSFinish"; } | 648 const char* name() const override { return "PLSFinish"; } |
649 | 649 |
650 const Attribute* inPosition() const { return fInPosition; } | 650 const Attribute* inPosition() const { return fInPosition; } |
651 GrColor color() const { return fColor; } | 651 GrColor color() const { return fColor; } |
652 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } | 652 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } |
653 const SkMatrix& localMatrix() const { return fLocalMatrix; } | 653 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
654 bool usesLocalCoords() const { return fUsesLocalCoords; } | 654 bool usesLocalCoords() const { return fUsesLocalCoords; } |
655 | 655 |
656 GrPixelLocalStorageState getPixelLocalStorageState() const override { | 656 GrPixelLocalStorageState getPixelLocalStorageState() const override { |
657 return GrPixelLocalStorageState::kFinish_GrPixelLocalStorageState; | 657 return GrPixelLocalStorageState::kFinish_GrPixelLocalStorageState; |
658 } | 658 } |
659 | 659 |
660 const char* getDestColorOverride() const override { | 660 const char* getDestColorOverride() const override { |
661 return GR_GL_PLS_DSTCOLOR_NAME; | 661 return GR_GL_PLS_DSTCOLOR_NAME; |
662 } | 662 } |
663 | 663 |
664 class GLSLProcessor : public GrGLSLGeometryProcessor { | 664 class GLSLProcessor : public GrGLSLGeometryProcessor { |
665 public: | 665 public: |
666 GLSLProcessor(const GrGeometryProcessor&) {} | 666 GLSLProcessor(const GrGeometryProcessor&) {} |
667 | 667 |
668 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { | 668 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
669 const PLSFinishEffect& fe = args.fGP.cast<PLSFinishEffect>(); | 669 const PLSFinishEffect& fe = args.fGP.cast<PLSFinishEffect>(); |
670 GrGLSLVertexBuilder* vsBuilder = args.fVertBuilder; | 670 GrGLSLVertexBuilder* vsBuilder = args.fVertBuilder; |
671 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; | 671 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
672 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 672 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
673 | 673 |
674 fUseEvenOdd = uniformHandler->addUniform(kFragment_GrShaderFlag, | 674 fUseEvenOdd = uniformHandler->addUniform(kFragment_GrShaderFlag, |
675 kFloat_GrSLType, kLow_GrSLPr
ecision, | 675 kFloat_GrSLType, kLow_GrSLPr
ecision, |
676 "useEvenOdd"); | 676 "useEvenOdd"); |
677 const char* useEvenOdd = uniformHandler->getUniformCStr(fUseEvenOdd)
; | 677 const char* useEvenOdd = uniformHandler->getUniformCStr(fUseEvenOdd)
; |
678 | 678 |
679 varyingHandler->emitAttributes(fe); | 679 varyingHandler->emitAttributes(fe); |
680 this->setupPosition(vsBuilder, gpArgs, fe.inPosition()->fName); | 680 this->setupPosition(vsBuilder, gpArgs, fe.inPosition()->fName); |
681 this->emitTransforms(vsBuilder, varyingHandler, uniformHandler, gpAr
gs->fPositionVar, | 681 this->emitTransforms(vsBuilder, varyingHandler, uniformHandler, gpAr
gs->fPositionVar, |
682 fe.inPosition()->fName, fe.localMatrix(), args.
fTransformsIn, | 682 fe.inPosition()->fName, fe.localMatrix(), args.
fTransformsIn, |
683 args.fTransformsOut); | 683 args.fTransformsOut); |
684 | 684 |
685 GrGLSLPPFragmentBuilder* fsBuilder = args.fFragBuilder; | 685 GrGLSLPPFragmentBuilder* fsBuilder = args.fFragBuilder; |
686 SkAssertResult(fsBuilder->enableFeature( | 686 SkAssertResult(fsBuilder->enableFeature( |
687 GrGLSLFragmentShaderBuilder::kPixelLocalStorage_GLSLF
eature)); | 687 GrGLSLFragmentShaderBuilder::kPixelLocalStorage_GLSLF
eature)); |
688 fsBuilder->declAppendf(GR_GL_PLS_PATH_DATA_DECL); | 688 fsBuilder->declAppendf(GR_GL_PLS_PATH_DATA_DECL); |
689 fsBuilder->codeAppend("float coverage;"); | 689 fsBuilder->codeAppend("float coverage;"); |
690 fsBuilder->codeAppendf("if (%s != 0.0) {", useEvenOdd); | 690 fsBuilder->codeAppendf("if (%s != 0.0) {", useEvenOdd); |
691 fsBuilder->codeAppend("coverage = float(abs(pls.windings[0]) % 2) *
0.25;"); | 691 fsBuilder->codeAppend("coverage = float(abs(pls.windings[0]) % 2) *
0.25;"); |
692 fsBuilder->codeAppend("coverage += float(abs(pls.windings[1]) % 2) *
0.25;"); | 692 fsBuilder->codeAppend("coverage += float(abs(pls.windings[1]) % 2) *
0.25;"); |
693 fsBuilder->codeAppend("coverage += float(abs(pls.windings[2]) % 2) *
0.25;"); | 693 fsBuilder->codeAppend("coverage += float(abs(pls.windings[2]) % 2) *
0.25;"); |
694 fsBuilder->codeAppend("coverage += float(abs(pls.windings[3]) % 2) *
0.25;"); | 694 fsBuilder->codeAppend("coverage += float(abs(pls.windings[3]) % 2) *
0.25;"); |
695 fsBuilder->codeAppend("} else {"); | 695 fsBuilder->codeAppend("} else {"); |
696 fsBuilder->codeAppend("coverage = pls.windings[0] != 0 ? 0.25 : 0.0;
"); | 696 fsBuilder->codeAppend("coverage = pls.windings[0] != 0 ? 0.25 : 0.0;
"); |
697 fsBuilder->codeAppend("coverage += pls.windings[1] != 0 ? 0.25 : 0.0
;"); | 697 fsBuilder->codeAppend("coverage += pls.windings[1] != 0 ? 0.25 : 0.0
;"); |
698 fsBuilder->codeAppend("coverage += pls.windings[2] != 0 ? 0.25 : 0.0
;"); | 698 fsBuilder->codeAppend("coverage += pls.windings[2] != 0 ? 0.25 : 0.0
;"); |
699 fsBuilder->codeAppend("coverage += pls.windings[3] != 0 ? 0.25 : 0.0
;"); | 699 fsBuilder->codeAppend("coverage += pls.windings[3] != 0 ? 0.25 : 0.0
;"); |
700 fsBuilder->codeAppend("}"); | 700 fsBuilder->codeAppend("}"); |
701 if (!fe.colorIgnored()) { | 701 if (!fe.colorIgnored()) { |
702 this->setupUniformColor(fsBuilder, uniformHandler, args.fOutputC
olor, | 702 this->setupUniformColor(fsBuilder, uniformHandler, args.fOutputC
olor, |
703 &fColorUniform); | 703 &fColorUniform); |
704 } | 704 } |
705 fsBuilder->codeAppendf("%s = vec4(coverage);", args.fOutputCoverage)
; | 705 fsBuilder->codeAppendf("%s = vec4(coverage);", args.fOutputCoverage)
; |
706 fsBuilder->codeAppendf("%s = vec4(1.0, 0.0, 1.0, 1.0);", args.fOutpu
tColor); | 706 fsBuilder->codeAppendf("%s = vec4(1.0, 0.0, 1.0, 1.0);", args.fOutpu
tColor); |
707 } | 707 } |
708 | 708 |
709 static inline void GenKey(const GrGeometryProcessor& gp, | 709 static inline void GenKey(const GrGeometryProcessor& gp, |
710 const GrGLSLCaps&, | 710 const GrGLSLCaps&, |
711 GrProcessorKeyBuilder* b) { | 711 GrProcessorKeyBuilder* b) { |
712 const PLSFinishEffect& fe = gp.cast<PLSFinishEffect>(); | 712 const PLSFinishEffect& fe = gp.cast<PLSFinishEffect>(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 virtual void getGLSLProcessorKey(const GrGLSLCaps& caps, | 745 virtual void getGLSLProcessorKey(const GrGLSLCaps& caps, |
746 GrProcessorKeyBuilder* b) const override { | 746 GrProcessorKeyBuilder* b) const override { |
747 GLSLProcessor::GenKey(*this, caps, b); | 747 GLSLProcessor::GenKey(*this, caps, b); |
748 } | 748 } |
749 | 749 |
750 virtual GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) cons
t override { | 750 virtual GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) cons
t override { |
751 return new GLSLProcessor(*this); | 751 return new GLSLProcessor(*this); |
752 } | 752 } |
753 | 753 |
754 private: | 754 private: |
755 PLSFinishEffect(GrColor color, bool useEvenOdd, const SkMatrix& localMatrix,
| 755 PLSFinishEffect(GrColor color, bool useEvenOdd, const SkMatrix& localMatrix, |
756 bool usesLocalCoords) | 756 bool usesLocalCoords) |
757 : fColor(color) | 757 : fColor(color) |
758 , fUseEvenOdd(useEvenOdd) | 758 , fUseEvenOdd(useEvenOdd) |
759 , fLocalMatrix(localMatrix) | 759 , fLocalMatrix(localMatrix) |
760 , fUsesLocalCoords(usesLocalCoords) { | 760 , fUsesLocalCoords(usesLocalCoords) { |
761 this->initClassID<PLSFinishEffect>(); | 761 this->initClassID<PLSFinishEffect>(); |
762 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType, | 762 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType, |
763 kHigh_GrSLPrecision)); | 763 kHigh_GrSLPrecision)); |
764 } | 764 } |
765 | 765 |
766 const Attribute* fInPosition; | 766 const Attribute* fInPosition; |
767 GrColor fColor; | 767 GrColor fColor; |
768 bool fUseEvenOdd; | 768 bool fUseEvenOdd; |
769 SkMatrix fLocalMatrix; | 769 SkMatrix fLocalMatrix; |
770 bool fUsesLocalCoords; | 770 bool fUsesLocalCoords; |
771 | 771 |
772 typedef GrGeometryProcessor INHERITED; | 772 typedef GrGeometryProcessor INHERITED; |
(...skipping 17 matching lines...) Expand all Loading... |
790 SkMatrix fViewMatrix; | 790 SkMatrix fViewMatrix; |
791 SkPath fPath; | 791 SkPath fPath; |
792 }; | 792 }; |
793 | 793 |
794 static GrDrawBatch* Create(const Geometry& geometry) { | 794 static GrDrawBatch* Create(const Geometry& geometry) { |
795 return new PLSPathBatch(geometry); | 795 return new PLSPathBatch(geometry); |
796 } | 796 } |
797 | 797 |
798 const char* name() const override { return "PLSBatch"; } | 798 const char* name() const override { return "PLSBatch"; } |
799 | 799 |
800 void computePipelineOptimizations(GrInitInvariantOutput* color, | 800 void computePipelineOptimizations(GrInitInvariantOutput* color, |
801 GrInitInvariantOutput* coverage, | 801 GrInitInvariantOutput* coverage, |
802 GrBatchToXPOverrides* overrides) const ove
rride { | 802 GrBatchToXPOverrides* overrides) const ove
rride { |
803 // When this is called on a batch, there is only one geometry bundle | 803 // When this is called on a batch, there is only one geometry bundle |
804 color->setKnownFourComponents(fGeoData[0].fColor); | 804 color->setKnownFourComponents(fGeoData[0].fColor); |
805 coverage->setUnknownSingleComponent(); | 805 coverage->setUnknownSingleComponent(); |
806 overrides->fUsePLSDstRead = true; | 806 overrides->fUsePLSDstRead = true; |
807 } | 807 } |
808 | 808 |
809 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { | 809 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
810 // Handle any color overrides | 810 // Handle any color overrides |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 for (int i = 0; i < quadVertices.count(); ++i) { | 904 for (int i = 0; i < quadVertices.count(); ++i) { |
905 quadVerts[i] = quadVertices[i]; | 905 quadVerts[i] = quadVertices[i]; |
906 } | 906 } |
907 mesh.init(kTriangles_GrPrimitiveType, quadVertexBuffer, firstQua
dVertex, | 907 mesh.init(kTriangles_GrPrimitiveType, quadVertexBuffer, firstQua
dVertex, |
908 quadVertices.count()); | 908 quadVertices.count()); |
909 target->initDraw(quadProcessor); | 909 target->initDraw(quadProcessor); |
910 target->draw(mesh); | 910 target->draw(mesh); |
911 } | 911 } |
912 | 912 |
913 SkAutoTUnref<GrGeometryProcessor> finishProcessor( | 913 SkAutoTUnref<GrGeometryProcessor> finishProcessor( |
914 PLSFinishEffect::Create(this->color(), | 914 PLSFinishEffect::Create(this->color(), |
915 pathPtr->getFillType() == | 915 pathPtr->getFillType() == |
916 SkPath::FillType
::kEvenOdd_FillType, | 916 SkPath::FillType
::kEvenOdd_FillType, |
917 invert, | 917 invert, |
918 this->usesLocalCoords())); | 918 this->usesLocalCoords())); |
919 const GrBuffer* rectVertexBuffer; | 919 const GrBuffer* rectVertexBuffer; |
920 size_t finishStride = finishProcessor->getVertexStride(); | 920 size_t finishStride = finishProcessor->getVertexStride(); |
921 int firstRectVertex; | 921 int firstRectVertex; |
922 static const int kRectVertexCount = 6; | 922 static const int kRectVertexCount = 6; |
923 SkPoint* rectVerts = reinterpret_cast<SkPoint*>(target->makeVertexSp
ace( | 923 SkPoint* rectVerts = reinterpret_cast<SkPoint*>(target->makeVertexSp
ace( |
924 finishStride, kRectVertexCount, &rectVertexBuffer, &firstRec
tVertex)); | 924 finishStride, kRectVertexCount, &rectVertexBuffer, &firstRec
tVertex)); |
925 if (!rectVerts) { | 925 if (!rectVerts) { |
926 SkDebugf("Could not allocate vertices\n"); | 926 SkDebugf("Could not allocate vertices\n"); |
927 return; | 927 return; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 DRAW_BATCH_TEST_DEFINE(PLSPathBatch) { | 1002 DRAW_BATCH_TEST_DEFINE(PLSPathBatch) { |
1003 PLSPathBatch::Geometry geometry; | 1003 PLSPathBatch::Geometry geometry; |
1004 geometry.fColor = GrRandomColor(random); | 1004 geometry.fColor = GrRandomColor(random); |
1005 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); | 1005 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); |
1006 geometry.fPath = GrTest::TestPathConvex(random); | 1006 geometry.fPath = GrTest::TestPathConvex(random); |
1007 | 1007 |
1008 return PLSPathBatch::Create(geometry); | 1008 return PLSPathBatch::Create(geometry); |
1009 } | 1009 } |
1010 | 1010 |
1011 #endif | 1011 #endif |
OLD | NEW |