| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 // This test only works with the GPU backend. | 9 // This test only works with the GPU backend. |
| 10 | 10 |
| 11 #include "gm.h" | 11 #include "gm.h" |
| 12 | 12 |
| 13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
| 14 | 14 |
| 15 #include "GrBatchTarget.h" | 15 #include "GrBatchTarget.h" |
| 16 #include "GrBufferAllocPool.h" | 16 #include "GrBufferAllocPool.h" |
| 17 #include "GrContext.h" | 17 #include "GrContext.h" |
| 18 #include "GrPathUtils.h" | 18 #include "GrPathUtils.h" |
| 19 #include "GrResourceProvider.h" |
| 19 #include "GrTest.h" | 20 #include "GrTest.h" |
| 20 #include "GrTestBatch.h" | 21 #include "GrTestBatch.h" |
| 21 #include "SkColorPriv.h" | 22 #include "SkColorPriv.h" |
| 22 #include "SkDevice.h" | 23 #include "SkDevice.h" |
| 23 #include "SkGeometry.h" | 24 #include "SkGeometry.h" |
| 24 | 25 |
| 25 #include "effects/GrBezierEffect.h" | 26 #include "effects/GrBezierEffect.h" |
| 26 | 27 |
| 27 static inline SkScalar eval_line(const SkPoint& p, const SkScalar lineEq[3], SkS
calar sign) { | 28 static inline SkScalar eval_line(const SkPoint& p, const SkScalar lineEq[3], SkS
calar sign) { |
| 28 return sign * (lineEq[0] * p.fX + lineEq[1] * p.fY + lineEq[2]); | 29 return sign * (lineEq[0] * p.fX + lineEq[1] * p.fY + lineEq[2]); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 59 SkPoint fPosition; | 60 SkPoint fPosition; |
| 60 float fKLM[4]; // The last value is ignored. The effect expects a vec4
f. | 61 float fKLM[4]; // The last value is ignored. The effect expects a vec4
f. |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 Geometry* geoData(int index) override { | 64 Geometry* geoData(int index) override { |
| 64 SkASSERT(0 == index); | 65 SkASSERT(0 == index); |
| 65 return &fGeometry; | 66 return &fGeometry; |
| 66 } | 67 } |
| 67 | 68 |
| 68 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli
ne) override { | 69 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli
ne) override { |
| 70 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
| 71 batchTarget->resourceProvider()->refQuadIndexBuffer()); |
| 72 |
| 69 size_t vertexStride = this->geometryProcessor()->getVertexStride(); | 73 size_t vertexStride = this->geometryProcessor()->getVertexStride(); |
| 70 | |
| 71 const GrVertexBuffer* vertexBuffer; | 74 const GrVertexBuffer* vertexBuffer; |
| 72 int firstVertex; | 75 int firstVertex; |
| 73 | |
| 74 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | 76 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
| 75 kVertsPerCubic, | 77 kVertsPerCubic, |
| 76 &vertexBuffer, | 78 &vertexBuffer, |
| 77 &firstVertex); | 79 &firstVertex); |
| 78 | 80 |
| 79 if (!vertices || !batchTarget->quadIndexBuffer()) { | 81 if (!vertices || !indexBuffer) { |
| 80 SkDebugf("Could not allocate buffers\n"); | 82 SkDebugf("Could not allocate buffers\n"); |
| 81 return; | 83 return; |
| 82 } | 84 } |
| 83 | 85 |
| 84 SkASSERT(vertexStride == sizeof(Vertex)); | 86 SkASSERT(vertexStride == sizeof(Vertex)); |
| 85 Vertex* verts = reinterpret_cast<Vertex*>(vertices); | 87 Vertex* verts = reinterpret_cast<Vertex*>(vertices); |
| 86 | 88 |
| 87 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds
.fTop, | 89 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds
.fTop, |
| 88 fGeometry.fBounds.fRight, fGeometry.fBound
s.fBottom, | 90 fGeometry.fBounds.fRight, fGeometry.fBound
s.fBottom, |
| 89 sizeof(Vertex)); | 91 sizeof(Vertex)); |
| 90 for (int v = 0; v < 4; ++v) { | 92 for (int v = 0; v < 4; ++v) { |
| 91 verts[v].fKLM[0] = eval_line(verts[v].fPosition, fKlmEqs + 0, fSign)
; | 93 verts[v].fKLM[0] = eval_line(verts[v].fPosition, fKlmEqs + 0, fSign)
; |
| 92 verts[v].fKLM[1] = eval_line(verts[v].fPosition, fKlmEqs + 3, fSign)
; | 94 verts[v].fKLM[1] = eval_line(verts[v].fPosition, fKlmEqs + 3, fSign)
; |
| 93 verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f); | 95 verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f); |
| 94 } | 96 } |
| 95 | 97 |
| 96 GrDrawTarget::DrawInfo drawInfo; | 98 GrDrawTarget::DrawInfo drawInfo; |
| 97 drawInfo.setPrimitiveType(kTriangleFan_GrPrimitiveType); | 99 drawInfo.setPrimitiveType(kTriangleFan_GrPrimitiveType); |
| 98 drawInfo.setVertexBuffer(vertexBuffer); | 100 drawInfo.setVertexBuffer(vertexBuffer); |
| 99 drawInfo.setStartVertex(firstVertex); | 101 drawInfo.setStartVertex(firstVertex); |
| 100 drawInfo.setVertexCount(kVertsPerCubic); | 102 drawInfo.setVertexCount(kVertsPerCubic); |
| 101 drawInfo.setStartIndex(0); | 103 drawInfo.setStartIndex(0); |
| 102 drawInfo.setIndexCount(kIndicesPerCubic); | 104 drawInfo.setIndexCount(kIndicesPerCubic); |
| 103 drawInfo.setIndexBuffer(batchTarget->quadIndexBuffer()); | 105 drawInfo.setIndexBuffer(indexBuffer); |
| 104 batchTarget->draw(drawInfo); | 106 batchTarget->draw(drawInfo); |
| 105 } | 107 } |
| 106 | 108 |
| 107 Geometry fGeometry; | 109 Geometry fGeometry; |
| 108 SkScalar fKlmEqs[9]; | 110 SkScalar fKlmEqs[9]; |
| 109 SkScalar fSign; | 111 SkScalar fSign; |
| 110 | 112 |
| 111 static const int kVertsPerCubic = 4; | 113 static const int kVertsPerCubic = 4; |
| 112 static const int kIndicesPerCubic = 6; | 114 static const int kIndicesPerCubic = 6; |
| 113 | 115 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 SkPoint fPosition; | 468 SkPoint fPosition; |
| 467 float fKLM[4]; // The last value is ignored. The effect expects a vec4
f. | 469 float fKLM[4]; // The last value is ignored. The effect expects a vec4
f. |
| 468 }; | 470 }; |
| 469 | 471 |
| 470 Geometry* geoData(int index) override { | 472 Geometry* geoData(int index) override { |
| 471 SkASSERT(0 == index); | 473 SkASSERT(0 == index); |
| 472 return &fGeometry; | 474 return &fGeometry; |
| 473 } | 475 } |
| 474 | 476 |
| 475 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli
ne) override { | 477 void onGenerateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeli
ne) override { |
| 478 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
| 479 batchTarget->resourceProvider()->refQuadIndexBuffer()); |
| 480 |
| 476 size_t vertexStride = this->geometryProcessor()->getVertexStride(); | 481 size_t vertexStride = this->geometryProcessor()->getVertexStride(); |
| 477 | |
| 478 const GrVertexBuffer* vertexBuffer; | 482 const GrVertexBuffer* vertexBuffer; |
| 479 int firstVertex; | 483 int firstVertex; |
| 480 | 484 |
| 481 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | 485 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
| 482 kVertsPerCubic, | 486 kVertsPerCubic, |
| 483 &vertexBuffer, | 487 &vertexBuffer, |
| 484 &firstVertex); | 488 &firstVertex); |
| 485 | 489 |
| 486 if (!vertices || !batchTarget->quadIndexBuffer()) { | 490 if (!vertices || !indexBuffer) { |
| 487 SkDebugf("Could not allocate buffers\n"); | 491 SkDebugf("Could not allocate buffers\n"); |
| 488 return; | 492 return; |
| 489 } | 493 } |
| 490 | 494 |
| 491 SkASSERT(vertexStride == sizeof(Vertex)); | 495 SkASSERT(vertexStride == sizeof(Vertex)); |
| 492 Vertex* verts = reinterpret_cast<Vertex*>(vertices); | 496 Vertex* verts = reinterpret_cast<Vertex*>(vertices); |
| 493 | 497 |
| 494 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds
.fTop, | 498 verts[0].fPosition.setRectFan(fGeometry.fBounds.fLeft, fGeometry.fBounds
.fTop, |
| 495 fGeometry.fBounds.fRight, fGeometry.fBound
s.fBottom, | 499 fGeometry.fBounds.fRight, fGeometry.fBound
s.fBottom, |
| 496 sizeof(Vertex)); | 500 sizeof(Vertex)); |
| 497 | 501 |
| 498 fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); | 502 fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); |
| 499 | 503 |
| 500 | 504 |
| 501 GrDrawTarget::DrawInfo drawInfo; | 505 GrDrawTarget::DrawInfo drawInfo; |
| 502 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); | 506 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); |
| 503 drawInfo.setVertexBuffer(vertexBuffer); | 507 drawInfo.setVertexBuffer(vertexBuffer); |
| 504 drawInfo.setStartVertex(firstVertex); | 508 drawInfo.setStartVertex(firstVertex); |
| 505 drawInfo.setVertexCount(kVertsPerCubic); | 509 drawInfo.setVertexCount(kVertsPerCubic); |
| 506 drawInfo.setStartIndex(0); | 510 drawInfo.setStartIndex(0); |
| 507 drawInfo.setIndexCount(kIndicesPerCubic); | 511 drawInfo.setIndexCount(kIndicesPerCubic); |
| 508 drawInfo.setIndexBuffer(batchTarget->quadIndexBuffer()); | 512 drawInfo.setIndexBuffer(indexBuffer); |
| 509 batchTarget->draw(drawInfo); | 513 batchTarget->draw(drawInfo); |
| 510 } | 514 } |
| 511 | 515 |
| 512 Geometry fGeometry; | 516 Geometry fGeometry; |
| 513 GrPathUtils::QuadUVMatrix fDevToUV; | 517 GrPathUtils::QuadUVMatrix fDevToUV; |
| 514 | 518 |
| 515 static const int kVertsPerCubic = 4; | 519 static const int kVertsPerCubic = 4; |
| 516 static const int kIndicesPerCubic = 6; | 520 static const int kIndicesPerCubic = 6; |
| 517 | 521 |
| 518 typedef GrTestBatch INHERITED; | 522 typedef GrTestBatch INHERITED; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 typedef GM INHERITED; | 660 typedef GM INHERITED; |
| 657 }; | 661 }; |
| 658 | 662 |
| 659 DEF_GM( return SkNEW(BezierCubicEffects); ) | 663 DEF_GM( return SkNEW(BezierCubicEffects); ) |
| 660 DEF_GM( return SkNEW(BezierConicEffects); ) | 664 DEF_GM( return SkNEW(BezierConicEffects); ) |
| 661 DEF_GM( return SkNEW(BezierQuadEffects); ) | 665 DEF_GM( return SkNEW(BezierQuadEffects); ) |
| 662 | 666 |
| 663 } | 667 } |
| 664 | 668 |
| 665 #endif | 669 #endif |
| OLD | NEW |