| 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 "GrNonAAStrokeRectBatch.h" | 8 #include "GrNonAAStrokeRectBatch.h" |
| 9 | 9 |
| 10 #include "GrBatchTest.h" | 10 #include "GrBatchTest.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 overrides->fUsePLSDstRead = false; | 63 overrides->fUsePLSDstRead = false; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void append(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect, | 66 void append(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect, |
| 67 SkScalar strokeWidth) { | 67 SkScalar strokeWidth) { |
| 68 Geometry& geometry = fGeoData.push_back(); | 68 Geometry& geometry = fGeoData.push_back(); |
| 69 geometry.fViewMatrix = viewMatrix; | 69 geometry.fViewMatrix = viewMatrix; |
| 70 geometry.fRect = rect; | 70 geometry.fRect = rect; |
| 71 geometry.fStrokeWidth = strokeWidth; | 71 geometry.fStrokeWidth = strokeWidth; |
| 72 geometry.fColor = color; | 72 geometry.fColor = color; |
| 73 |
| 74 // Sort the rect for hairlines |
| 75 geometry.fRect.sort(); |
| 73 } | 76 } |
| 74 | 77 |
| 75 void appendAndUpdateBounds(GrColor color, const SkMatrix& viewMatrix, const
SkRect& rect, | 78 void appendAndUpdateBounds(GrColor color, const SkMatrix& viewMatrix, const
SkRect& rect, |
| 76 SkScalar strokeWidth, bool snapToPixelCenters) { | 79 SkScalar strokeWidth, bool snapToPixelCenters) { |
| 77 this->append(color, viewMatrix, rect, strokeWidth); | 80 this->append(color, viewMatrix, rect, strokeWidth); |
| 78 | 81 |
| 79 SkRect bounds; | 82 SkRect bounds; |
| 80 this->setupBounds(&bounds, fGeoData.back(), snapToPixelCenters); | 83 this->setupBounds(&bounds, fGeoData.back(), snapToPixelCenters); |
| 81 this->joinBounds(bounds); | 84 this->joinBounds(bounds); |
| 82 } | 85 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 95 SkScalar rad = SkScalarHalf(geo.fStrokeWidth); | 98 SkScalar rad = SkScalarHalf(geo.fStrokeWidth); |
| 96 bounds->outset(rad, rad); | 99 bounds->outset(rad, rad); |
| 97 geo.fViewMatrix.mapRect(&fBounds); | 100 geo.fViewMatrix.mapRect(&fBounds); |
| 98 | 101 |
| 99 // If our caller snaps to pixel centers then we have to round out the bo
unds | 102 // If our caller snaps to pixel centers then we have to round out the bo
unds |
| 100 if (snapToPixelCenters) { | 103 if (snapToPixelCenters) { |
| 101 bounds->roundOut(); | 104 bounds->roundOut(); |
| 102 } | 105 } |
| 103 } | 106 } |
| 104 | 107 |
| 105 void onPrepareDraws(Target* target) override { | 108 void onPrepareDraws(Target* target) const override { |
| 106 SkAutoTUnref<const GrGeometryProcessor> gp; | 109 SkAutoTUnref<const GrGeometryProcessor> gp; |
| 107 { | 110 { |
| 108 using namespace GrDefaultGeoProcFactory; | 111 using namespace GrDefaultGeoProcFactory; |
| 109 Color color(this->color()); | 112 Color color(this->color()); |
| 110 Coverage coverage(this->coverageIgnored() ? Coverage::kSolid_Type : | 113 Coverage coverage(this->coverageIgnored() ? Coverage::kSolid_Type : |
| 111 Coverage::kNone_Type); | 114 Coverage::kNone_Type); |
| 112 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP
osition_Type : | 115 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP
osition_Type : |
| 113 LocalCoords::kUnus
ed_Type); | 116 LocalCoords::kUnus
ed_Type); |
| 114 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord
s, | 117 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord
s, |
| 115 this->viewMatrix())); | 118 this->viewMatrix())); |
| 116 } | 119 } |
| 117 | 120 |
| 118 target->initDraw(gp, this->pipeline()); | 121 target->initDraw(gp, this->pipeline()); |
| 119 | 122 |
| 120 size_t vertexStride = gp->getVertexStride(); | 123 size_t vertexStride = gp->getVertexStride(); |
| 121 | 124 |
| 122 SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr)); | 125 SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr)); |
| 123 | 126 |
| 124 Geometry& args = fGeoData[0]; | 127 const Geometry& args = fGeoData[0]; |
| 125 | 128 |
| 126 int vertexCount = kVertsPerHairlineRect; | 129 int vertexCount = kVertsPerHairlineRect; |
| 127 if (args.fStrokeWidth > 0) { | 130 if (args.fStrokeWidth > 0) { |
| 128 vertexCount = kVertsPerStrokeRect; | 131 vertexCount = kVertsPerStrokeRect; |
| 129 } | 132 } |
| 130 | 133 |
| 131 const GrVertexBuffer* vertexBuffer; | 134 const GrVertexBuffer* vertexBuffer; |
| 132 int firstVertex; | 135 int firstVertex; |
| 133 | 136 |
| 134 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex
Buffer, | 137 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex
Buffer, |
| 135 &firstVertex); | 138 &firstVertex); |
| 136 | 139 |
| 137 if (!verts) { | 140 if (!verts) { |
| 138 SkDebugf("Could not allocate vertices\n"); | 141 SkDebugf("Could not allocate vertices\n"); |
| 139 return; | 142 return; |
| 140 } | 143 } |
| 141 | 144 |
| 142 SkPoint* vertex = reinterpret_cast<SkPoint*>(verts); | 145 SkPoint* vertex = reinterpret_cast<SkPoint*>(verts); |
| 143 | 146 |
| 144 GrPrimitiveType primType; | 147 GrPrimitiveType primType; |
| 145 | |
| 146 if (args.fStrokeWidth > 0) {; | 148 if (args.fStrokeWidth > 0) {; |
| 147 primType = kTriangleStrip_GrPrimitiveType; | 149 primType = kTriangleStrip_GrPrimitiveType; |
| 148 args.fRect.sort(); | |
| 149 init_stroke_rect_strip(vertex, args.fRect, args.fStrokeWidth); | 150 init_stroke_rect_strip(vertex, args.fRect, args.fStrokeWidth); |
| 150 } else { | 151 } else { |
| 151 // hairline | 152 // hairline |
| 152 primType = kLineStrip_GrPrimitiveType; | 153 primType = kLineStrip_GrPrimitiveType; |
| 153 vertex[0].set(args.fRect.fLeft, args.fRect.fTop); | 154 vertex[0].set(args.fRect.fLeft, args.fRect.fTop); |
| 154 vertex[1].set(args.fRect.fRight, args.fRect.fTop); | 155 vertex[1].set(args.fRect.fRight, args.fRect.fTop); |
| 155 vertex[2].set(args.fRect.fRight, args.fRect.fBottom); | 156 vertex[2].set(args.fRect.fRight, args.fRect.fBottom); |
| 156 vertex[3].set(args.fRect.fLeft, args.fRect.fBottom); | 157 vertex[3].set(args.fRect.fLeft, args.fRect.fBottom); |
| 157 vertex[4].set(args.fRect.fLeft, args.fRect.fTop); | 158 vertex[4].set(args.fRect.fLeft, args.fRect.fTop); |
| 158 } | 159 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 DRAW_BATCH_TEST_DEFINE(NonAAStrokeRectBatch) { | 245 DRAW_BATCH_TEST_DEFINE(NonAAStrokeRectBatch) { |
| 245 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 246 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 246 GrColor color = GrRandomColor(random); | 247 GrColor color = GrRandomColor(random); |
| 247 SkRect rect = GrTest::TestRect(random); | 248 SkRect rect = GrTest::TestRect(random); |
| 248 SkScalar strokeWidth = random->nextBool() ? 0.0f : 1.0f; | 249 SkScalar strokeWidth = random->nextBool() ? 0.0f : 1.0f; |
| 249 | 250 |
| 250 return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeWidth,
random->nextBool()); | 251 return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeWidth,
random->nextBool()); |
| 251 } | 252 } |
| 252 | 253 |
| 253 #endif | 254 #endif |
| OLD | NEW |