| 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 "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
| 11 #include "GrBatchTest.h" | 11 #include "GrBatchTest.h" |
| 12 #include "GrDrawTarget.h" | 12 #include "GrDrawTarget.h" |
| 13 #include "GrGeometryProcessor.h" | 13 #include "GrGeometryProcessor.h" |
| 14 #include "GrInvariantOutput.h" | 14 #include "GrInvariantOutput.h" |
| 15 #include "GrPipelineBuilder.h" | 15 #include "GrPipelineBuilder.h" |
| 16 #include "GrProcessor.h" | 16 #include "GrProcessor.h" |
| 17 #include "GrResourceProvider.h" | 17 #include "GrResourceProvider.h" |
| 18 #include "GrVertexBuffer.h" | 18 #include "GrVertexBuffer.h" |
| 19 #include "SkRRect.h" | 19 #include "SkRRect.h" |
| 20 #include "SkStrokeRec.h" | 20 #include "SkStrokeRec.h" |
| 21 #include "SkTLazy.h" | 21 #include "SkTLazy.h" |
| 22 #include "batches/GrVertexBatch.h" | 22 #include "batches/GrVertexBatch.h" |
| 23 #include "effects/GrRRectEffect.h" | 23 #include "effects/GrRRectEffect.h" |
| 24 #include "gl/GrGLUtil.h" | 24 #include "gl/GrGLUtil.h" |
| 25 #include "gl/GrGLProcessor.h" | 25 #include "gl/GrGLProcessor.h" |
| 26 #include "gl/GrGLGeometryProcessor.h" | 26 #include "gl/GrGLGeometryProcessor.h" |
| 27 #include "gl/builders/GrGLProgramBuilder.h" | 27 #include "gl/builders/GrGLProgramBuilder.h" |
| 28 #include "glsl/GrGLSLProgramDataManager.h" |
| 28 | 29 |
| 29 // TODO(joshualitt) - Break this file up during GrBatch post implementation clea
nup | 30 // TODO(joshualitt) - Break this file up during GrBatch post implementation clea
nup |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 // TODO(joshualitt) add per vertex colors | 33 // TODO(joshualitt) add per vertex colors |
| 33 struct CircleVertex { | 34 struct CircleVertex { |
| 34 SkPoint fPos; | 35 SkPoint fPos; |
| 35 SkPoint fOffset; | 36 SkPoint fOffset; |
| 36 SkScalar fOuterRadius; | 37 SkScalar fOuterRadius; |
| 37 SkScalar fInnerRadius; | 38 SkScalar fInnerRadius; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 static void GenKey(const GrGeometryProcessor& gp, | 133 static void GenKey(const GrGeometryProcessor& gp, |
| 133 const GrGLSLCaps&, | 134 const GrGLSLCaps&, |
| 134 GrProcessorKeyBuilder* b) { | 135 GrProcessorKeyBuilder* b) { |
| 135 const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>(); | 136 const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>(); |
| 136 uint16_t key = ce.isStroked() ? 0x1 : 0x0; | 137 uint16_t key = ce.isStroked() ? 0x1 : 0x0; |
| 137 key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0
x2 : 0x0; | 138 key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0
x2 : 0x0; |
| 138 key |= ce.colorIgnored() ? 0x4 : 0x0; | 139 key |= ce.colorIgnored() ? 0x4 : 0x0; |
| 139 b->add32(key); | 140 b->add32(key); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProce
ssor& gp) override { | 143 void setData(const GrGLSLProgramDataManager& pdman, |
| 144 const GrPrimitiveProcessor& gp) override { |
| 143 const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>(); | 145 const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>(); |
| 144 if (ce.color() != fColor) { | 146 if (ce.color() != fColor) { |
| 145 GrGLfloat c[4]; | 147 float c[4]; |
| 146 GrColorToRGBAFloat(ce.color(), c); | 148 GrColorToRGBAFloat(ce.color(), c); |
| 147 pdman.set4fv(fColorUniform, 1, c); | 149 pdman.set4fv(fColorUniform, 1, c); |
| 148 fColor = ce.color(); | 150 fColor = ce.color(); |
| 149 } | 151 } |
| 150 } | 152 } |
| 151 | 153 |
| 152 void setTransformData(const GrPrimitiveProcessor& primProc, | 154 void setTransformData(const GrPrimitiveProcessor& primProc, |
| 153 const GrGLProgramDataManager& pdman, | 155 const GrGLSLProgramDataManager& pdman, |
| 154 int index, | 156 int index, |
| 155 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { | 157 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { |
| 156 this->setTransformDataHelper<CircleEdgeEffect>(primProc, pdman, inde
x, transforms); | 158 this->setTransformDataHelper<CircleEdgeEffect>(primProc, pdman, inde
x, transforms); |
| 157 } | 159 } |
| 158 | 160 |
| 159 private: | 161 private: |
| 160 GrColor fColor; | 162 GrColor fColor; |
| 161 UniformHandle fColorUniform; | 163 UniformHandle fColorUniform; |
| 162 typedef GrGLGeometryProcessor INHERITED; | 164 typedef GrGLGeometryProcessor INHERITED; |
| 163 }; | 165 }; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 static void GenKey(const GrGeometryProcessor& gp, | 302 static void GenKey(const GrGeometryProcessor& gp, |
| 301 const GrGLSLCaps&, | 303 const GrGLSLCaps&, |
| 302 GrProcessorKeyBuilder* b) { | 304 GrProcessorKeyBuilder* b) { |
| 303 const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>(); | 305 const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>(); |
| 304 uint16_t key = ee.isStroked() ? 0x1 : 0x0; | 306 uint16_t key = ee.isStroked() ? 0x1 : 0x0; |
| 305 key |= ee.usesLocalCoords() && ee.localMatrix().hasPerspective() ? 0
x2 : 0x0; | 307 key |= ee.usesLocalCoords() && ee.localMatrix().hasPerspective() ? 0
x2 : 0x0; |
| 306 key |= ee.colorIgnored() ? 0x4 : 0x0; | 308 key |= ee.colorIgnored() ? 0x4 : 0x0; |
| 307 b->add32(key); | 309 b->add32(key); |
| 308 } | 310 } |
| 309 | 311 |
| 310 void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProce
ssor& gp) override { | 312 void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitivePro
cessor& gp) override { |
| 311 const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>(); | 313 const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>(); |
| 312 if (ee.color() != fColor) { | 314 if (ee.color() != fColor) { |
| 313 GrGLfloat c[4]; | 315 float c[4]; |
| 314 GrColorToRGBAFloat(ee.color(), c); | 316 GrColorToRGBAFloat(ee.color(), c); |
| 315 pdman.set4fv(fColorUniform, 1, c); | 317 pdman.set4fv(fColorUniform, 1, c); |
| 316 fColor = ee.color(); | 318 fColor = ee.color(); |
| 317 } | 319 } |
| 318 } | 320 } |
| 319 | 321 |
| 320 void setTransformData(const GrPrimitiveProcessor& primProc, | 322 void setTransformData(const GrPrimitiveProcessor& primProc, |
| 321 const GrGLProgramDataManager& pdman, | 323 const GrGLSLProgramDataManager& pdman, |
| 322 int index, | 324 int index, |
| 323 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { | 325 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { |
| 324 this->setTransformDataHelper<EllipseEdgeEffect>(primProc, pdman, ind
ex, transforms); | 326 this->setTransformDataHelper<EllipseEdgeEffect>(primProc, pdman, ind
ex, transforms); |
| 325 } | 327 } |
| 326 | 328 |
| 327 private: | 329 private: |
| 328 GrColor fColor; | 330 GrColor fColor; |
| 329 UniformHandle fColorUniform; | 331 UniformHandle fColorUniform; |
| 330 | 332 |
| 331 typedef GrGLGeometryProcessor INHERITED; | 333 typedef GrGLGeometryProcessor INHERITED; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 static void GenKey(const GrGeometryProcessor& gp, | 492 static void GenKey(const GrGeometryProcessor& gp, |
| 491 const GrGLSLCaps&, | 493 const GrGLSLCaps&, |
| 492 GrProcessorKeyBuilder* b) { | 494 GrProcessorKeyBuilder* b) { |
| 493 const DIEllipseEdgeEffect& ellipseEffect = gp.cast<DIEllipseEdgeEffe
ct>(); | 495 const DIEllipseEdgeEffect& ellipseEffect = gp.cast<DIEllipseEdgeEffe
ct>(); |
| 494 uint16_t key = ellipseEffect.getMode(); | 496 uint16_t key = ellipseEffect.getMode(); |
| 495 key |= ellipseEffect.colorIgnored() << 9; | 497 key |= ellipseEffect.colorIgnored() << 9; |
| 496 key |= ComputePosKey(ellipseEffect.viewMatrix()) << 10; | 498 key |= ComputePosKey(ellipseEffect.viewMatrix()) << 10; |
| 497 b->add32(key); | 499 b->add32(key); |
| 498 } | 500 } |
| 499 | 501 |
| 500 void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProce
ssor& gp) override { | 502 void setData(const GrGLSLProgramDataManager& pdman, |
| 503 const GrPrimitiveProcessor& gp) override { |
| 501 const DIEllipseEdgeEffect& dee = gp.cast<DIEllipseEdgeEffect>(); | 504 const DIEllipseEdgeEffect& dee = gp.cast<DIEllipseEdgeEffect>(); |
| 502 | 505 |
| 503 if (!dee.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dee.
viewMatrix())) { | 506 if (!dee.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dee.
viewMatrix())) { |
| 504 fViewMatrix = dee.viewMatrix(); | 507 fViewMatrix = dee.viewMatrix(); |
| 505 GrGLfloat viewMatrix[3 * 3]; | 508 float viewMatrix[3 * 3]; |
| 506 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); | 509 GrGLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 507 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 510 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 508 } | 511 } |
| 509 | 512 |
| 510 if (dee.color() != fColor) { | 513 if (dee.color() != fColor) { |
| 511 GrGLfloat c[4]; | 514 float c[4]; |
| 512 GrColorToRGBAFloat(dee.color(), c); | 515 GrColorToRGBAFloat(dee.color(), c); |
| 513 pdman.set4fv(fColorUniform, 1, c); | 516 pdman.set4fv(fColorUniform, 1, c); |
| 514 fColor = dee.color(); | 517 fColor = dee.color(); |
| 515 } | 518 } |
| 516 } | 519 } |
| 517 | 520 |
| 518 private: | 521 private: |
| 519 SkMatrix fViewMatrix; | 522 SkMatrix fViewMatrix; |
| 520 GrColor fColor; | 523 GrColor fColor; |
| 521 UniformHandle fColorUniform; | 524 UniformHandle fColorUniform; |
| (...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2028 } | 2031 } |
| 2029 | 2032 |
| 2030 DRAW_BATCH_TEST_DEFINE(RRectBatch) { | 2033 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
| 2031 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 2034 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
| 2032 GrColor color = GrRandomColor(random); | 2035 GrColor color = GrRandomColor(random); |
| 2033 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 2036 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
| 2034 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 2037 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
| 2035 } | 2038 } |
| 2036 | 2039 |
| 2037 #endif | 2040 #endif |
| OLD | NEW |