| 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 "GrStrokeRectBatch.h" | 8 #include "GrStrokeRectBatch.h" |
| 9 #include "GrBatchTest.h" | 9 #include "GrBatchTest.h" |
| 10 #include "GrBatchFlushState.h" |
| 10 #include "SkRandom.h" | 11 #include "SkRandom.h" |
| 11 | 12 |
| 12 GrStrokeRectBatch::GrStrokeRectBatch(const Geometry& geometry, bool snapToPixelC
enters) { | 13 GrStrokeRectBatch::GrStrokeRectBatch(const Geometry& geometry, bool snapToPixelC
enters) { |
| 13 this->initClassID<GrStrokeRectBatch>(); | 14 this->initClassID<GrStrokeRectBatch>(); |
| 14 | 15 |
| 15 fBatch.fHairline = geometry.fStrokeWidth == 0; | 16 fBatch.fHairline = geometry.fStrokeWidth == 0; |
| 16 | 17 |
| 17 fGeoData.push_back(geometry); | 18 fGeoData.push_back(geometry); |
| 18 | 19 |
| 19 // setup bounds | 20 // setup bounds |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 verts[2].set(rect.fRight - rad, rect.fTop + rad); | 59 verts[2].set(rect.fRight - rad, rect.fTop + rad); |
| 59 verts[3].set(rect.fRight + rad, rect.fTop - rad); | 60 verts[3].set(rect.fRight + rad, rect.fTop - rad); |
| 60 verts[4].set(rect.fRight - rad, rect.fBottom - rad); | 61 verts[4].set(rect.fRight - rad, rect.fBottom - rad); |
| 61 verts[5].set(rect.fRight + rad, rect.fBottom + rad); | 62 verts[5].set(rect.fRight + rad, rect.fBottom + rad); |
| 62 verts[6].set(rect.fLeft + rad, rect.fBottom - rad); | 63 verts[6].set(rect.fLeft + rad, rect.fBottom - rad); |
| 63 verts[7].set(rect.fLeft - rad, rect.fBottom + rad); | 64 verts[7].set(rect.fLeft - rad, rect.fBottom + rad); |
| 64 verts[8] = verts[0]; | 65 verts[8] = verts[0]; |
| 65 verts[9] = verts[1]; | 66 verts[9] = verts[1]; |
| 66 } | 67 } |
| 67 | 68 |
| 68 | 69 void GrStrokeRectBatch::onPrepareDraws(Target* target) { |
| 69 void GrStrokeRectBatch::generateGeometry(GrBatchTarget* batchTarget) { | |
| 70 SkAutoTUnref<const GrGeometryProcessor> gp; | 70 SkAutoTUnref<const GrGeometryProcessor> gp; |
| 71 { | 71 { |
| 72 using namespace GrDefaultGeoProcFactory; | 72 using namespace GrDefaultGeoProcFactory; |
| 73 Color color(this->color()); | 73 Color color(this->color()); |
| 74 Coverage coverage(this->coverageIgnored() ? Coverage::kSolid_Type : | 74 Coverage coverage(this->coverageIgnored() ? Coverage::kSolid_Type : |
| 75 Coverage::kNone_Type); | 75 Coverage::kNone_Type); |
| 76 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUsePosit
ion_Type : | 76 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUsePosit
ion_Type : |
| 77 LocalCoords::kUnused
_Type); | 77 LocalCoords::kUnused
_Type); |
| 78 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoords, | 78 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoords, |
| 79 this->viewMatrix())); | 79 this->viewMatrix())); |
| 80 } | 80 } |
| 81 | 81 |
| 82 batchTarget->initDraw(gp, this->pipeline()); | 82 target->initDraw(gp, this->pipeline()); |
| 83 | 83 |
| 84 size_t vertexStride = gp->getVertexStride(); | 84 size_t vertexStride = gp->getVertexStride(); |
| 85 | 85 |
| 86 SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr)); | 86 SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr)); |
| 87 | 87 |
| 88 Geometry& args = fGeoData[0]; | 88 Geometry& args = fGeoData[0]; |
| 89 | 89 |
| 90 int vertexCount = kVertsPerHairlineRect; | 90 int vertexCount = kVertsPerHairlineRect; |
| 91 if (args.fStrokeWidth > 0) { | 91 if (args.fStrokeWidth > 0) { |
| 92 vertexCount = kVertsPerStrokeRect; | 92 vertexCount = kVertsPerStrokeRect; |
| 93 } | 93 } |
| 94 | 94 |
| 95 const GrVertexBuffer* vertexBuffer; | 95 const GrVertexBuffer* vertexBuffer; |
| 96 int firstVertex; | 96 int firstVertex; |
| 97 | 97 |
| 98 void* verts = batchTarget->makeVertSpace(vertexStride, vertexCount, | 98 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuff
er, &firstVertex); |
| 99 &vertexBuffer, &firstVertex); | |
| 100 | 99 |
| 101 if (!verts) { | 100 if (!verts) { |
| 102 SkDebugf("Could not allocate vertices\n"); | 101 SkDebugf("Could not allocate vertices\n"); |
| 103 return; | 102 return; |
| 104 } | 103 } |
| 105 | 104 |
| 106 SkPoint* vertex = reinterpret_cast<SkPoint*>(verts); | 105 SkPoint* vertex = reinterpret_cast<SkPoint*>(verts); |
| 107 | 106 |
| 108 GrPrimitiveType primType; | 107 GrPrimitiveType primType; |
| 109 | 108 |
| 110 if (args.fStrokeWidth > 0) {; | 109 if (args.fStrokeWidth > 0) {; |
| 111 primType = kTriangleStrip_GrPrimitiveType; | 110 primType = kTriangleStrip_GrPrimitiveType; |
| 112 args.fRect.sort(); | 111 args.fRect.sort(); |
| 113 init_stroke_rect_strip(vertex, args.fRect, args.fStrokeWidth); | 112 init_stroke_rect_strip(vertex, args.fRect, args.fStrokeWidth); |
| 114 } else { | 113 } else { |
| 115 // hairline | 114 // hairline |
| 116 primType = kLineStrip_GrPrimitiveType; | 115 primType = kLineStrip_GrPrimitiveType; |
| 117 vertex[0].set(args.fRect.fLeft, args.fRect.fTop); | 116 vertex[0].set(args.fRect.fLeft, args.fRect.fTop); |
| 118 vertex[1].set(args.fRect.fRight, args.fRect.fTop); | 117 vertex[1].set(args.fRect.fRight, args.fRect.fTop); |
| 119 vertex[2].set(args.fRect.fRight, args.fRect.fBottom); | 118 vertex[2].set(args.fRect.fRight, args.fRect.fBottom); |
| 120 vertex[3].set(args.fRect.fLeft, args.fRect.fBottom); | 119 vertex[3].set(args.fRect.fLeft, args.fRect.fBottom); |
| 121 vertex[4].set(args.fRect.fLeft, args.fRect.fTop); | 120 vertex[4].set(args.fRect.fLeft, args.fRect.fTop); |
| 122 } | 121 } |
| 123 | 122 |
| 124 GrVertices vertices; | 123 GrVertices vertices; |
| 125 vertices.init(primType, vertexBuffer, firstVertex, vertexCount); | 124 vertices.init(primType, vertexBuffer, firstVertex, vertexCount); |
| 126 batchTarget->draw(vertices); | 125 target->draw(vertices); |
| 127 } | 126 } |
| 128 | 127 |
| 129 #ifdef GR_TEST_UTILS | 128 #ifdef GR_TEST_UTILS |
| 130 | 129 |
| 131 DRAW_BATCH_TEST_DEFINE(GrStrokeRectBatch) { | 130 DRAW_BATCH_TEST_DEFINE(GrStrokeRectBatch) { |
| 132 GrStrokeRectBatch::Geometry geometry; | 131 GrStrokeRectBatch::Geometry geometry; |
| 133 geometry.fViewMatrix = GrTest::TestMatrix(random); | 132 geometry.fViewMatrix = GrTest::TestMatrix(random); |
| 134 geometry.fColor = GrRandomColor(random); | 133 geometry.fColor = GrRandomColor(random); |
| 135 geometry.fRect = GrTest::TestRect(random); | 134 geometry.fRect = GrTest::TestRect(random); |
| 136 geometry.fStrokeWidth = random->nextBool() ? 0.0f : 1.0f; | 135 geometry.fStrokeWidth = random->nextBool() ? 0.0f : 1.0f; |
| 137 | 136 |
| 138 return GrStrokeRectBatch::Create(geometry, random->nextBool()); | 137 return GrStrokeRectBatch::Create(geometry, random->nextBool()); |
| 139 } | 138 } |
| 140 | 139 |
| 141 #endif | 140 #endif |
| OLD | NEW |