Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: src/gpu/batches/GrNonAAStrokeRectBatch.cpp

Issue 1483103003: Make onPrepareDraws const (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 SkScalar rad = SkScalarHalf(geo.fStrokeWidth); 95 SkScalar rad = SkScalarHalf(geo.fStrokeWidth);
96 bounds->outset(rad, rad); 96 bounds->outset(rad, rad);
97 geo.fViewMatrix.mapRect(&fBounds); 97 geo.fViewMatrix.mapRect(&fBounds);
98 98
99 // If our caller snaps to pixel centers then we have to round out the bo unds 99 // If our caller snaps to pixel centers then we have to round out the bo unds
100 if (snapToPixelCenters) { 100 if (snapToPixelCenters) {
101 bounds->roundOut(); 101 bounds->roundOut();
102 } 102 }
103 } 103 }
104 104
105 void onPrepareDraws(Target* target) override { 105 void onPrepareDraws(Target* target) const override {
106 SkAutoTUnref<const GrGeometryProcessor> gp; 106 SkAutoTUnref<const GrGeometryProcessor> gp;
107 { 107 {
108 using namespace GrDefaultGeoProcFactory; 108 using namespace GrDefaultGeoProcFactory;
109 Color color(this->color()); 109 Color color(this->color());
110 Coverage coverage(this->coverageIgnored() ? Coverage::kSolid_Type : 110 Coverage coverage(this->coverageIgnored() ? Coverage::kSolid_Type :
111 Coverage::kNone_Type); 111 Coverage::kNone_Type);
112 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP osition_Type : 112 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP osition_Type :
113 LocalCoords::kUnus ed_Type); 113 LocalCoords::kUnus ed_Type);
114 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord s, 114 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord s,
115 this->viewMatrix())); 115 this->viewMatrix()));
116 } 116 }
117 117
118 target->initDraw(gp, this->pipeline()); 118 target->initDraw(gp, this->pipeline());
119 119
120 size_t vertexStride = gp->getVertexStride(); 120 size_t vertexStride = gp->getVertexStride();
121 121
122 SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr)); 122 SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr));
123 123
124 Geometry& args = fGeoData[0]; 124 const Geometry& args = fGeoData[0];
125 125
126 int vertexCount = kVertsPerHairlineRect; 126 int vertexCount = kVertsPerHairlineRect;
127 if (args.fStrokeWidth > 0) { 127 if (args.fStrokeWidth > 0) {
128 vertexCount = kVertsPerStrokeRect; 128 vertexCount = kVertsPerStrokeRect;
129 } 129 }
130 130
131 const GrVertexBuffer* vertexBuffer; 131 const GrVertexBuffer* vertexBuffer;
132 int firstVertex; 132 int firstVertex;
133 133
134 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex Buffer, 134 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex Buffer,
135 &firstVertex); 135 &firstVertex);
136 136
137 if (!verts) { 137 if (!verts) {
138 SkDebugf("Could not allocate vertices\n"); 138 SkDebugf("Could not allocate vertices\n");
139 return; 139 return;
140 } 140 }
141 141
142 SkPoint* vertex = reinterpret_cast<SkPoint*>(verts); 142 SkPoint* vertex = reinterpret_cast<SkPoint*>(verts);
143 143
144 GrPrimitiveType primType; 144 GrPrimitiveType primType;
145 145
robertphillips 2015/11/30 19:52:40 Just do this copy in the if clause ? What about do
146 SkRect rect = args.fRect;
146 if (args.fStrokeWidth > 0) {; 147 if (args.fStrokeWidth > 0) {;
147 primType = kTriangleStrip_GrPrimitiveType; 148 primType = kTriangleStrip_GrPrimitiveType;
148 args.fRect.sort(); 149 rect.sort();
149 init_stroke_rect_strip(vertex, args.fRect, args.fStrokeWidth); 150 init_stroke_rect_strip(vertex, rect, 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 }
159 160
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698