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

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

Issue 1806983002: Update how we send draws to gpu backend to reduce state setting. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 9 months 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 using namespace GrDefaultGeoProcFactory; 110 using namespace GrDefaultGeoProcFactory;
111 Color color(this->color()); 111 Color color(this->color());
112 Coverage coverage(this->coverageIgnored() ? Coverage::kSolid_Type : 112 Coverage coverage(this->coverageIgnored() ? Coverage::kSolid_Type :
113 Coverage::kNone_Type); 113 Coverage::kNone_Type);
114 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP osition_Type : 114 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP osition_Type :
115 LocalCoords::kUnus ed_Type); 115 LocalCoords::kUnus ed_Type);
116 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord s, 116 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord s,
117 this->viewMatrix())); 117 this->viewMatrix()));
118 } 118 }
119 119
120 target->initDraw(gp, this->pipeline());
121 120
122 size_t vertexStride = gp->getVertexStride(); 121 size_t vertexStride = gp->getVertexStride();
123 122
124 SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr)); 123 SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr));
125 124
126 const Geometry& args = fGeoData[0]; 125 const Geometry& args = fGeoData[0];
127 126
128 int vertexCount = kVertsPerHairlineRect; 127 int vertexCount = kVertsPerHairlineRect;
129 if (args.fStrokeWidth > 0) { 128 if (args.fStrokeWidth > 0) {
130 vertexCount = kVertsPerStrokeRect; 129 vertexCount = kVertsPerStrokeRect;
131 } 130 }
132 131
133 const GrVertexBuffer* vertexBuffer; 132 const GrVertexBuffer* vertexBuffer;
134 int firstVertex; 133 int firstVertex;
135 134
136 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex Buffer, 135 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex Buffer,
137 &firstVertex); 136 &firstVertex);
138 137
139 if (!verts) { 138 if (!verts) {
140 SkDebugf("Could not allocate vertices\n"); 139 SkDebugf("Could not allocate vertices\n");
141 return; 140 return;
142 } 141 }
143 142
144 SkPoint* vertex = reinterpret_cast<SkPoint*>(verts); 143 SkPoint* vertex = reinterpret_cast<SkPoint*>(verts);
145 144
146 GrPrimitiveType primType; 145 GrPrimitiveType primType;
147 if (args.fStrokeWidth > 0) {; 146 if (args.fStrokeWidth > 0) {
148 primType = kTriangleStrip_GrPrimitiveType; 147 primType = kTriangleStrip_GrPrimitiveType;
149 init_stroke_rect_strip(vertex, args.fRect, args.fStrokeWidth); 148 init_stroke_rect_strip(vertex, args.fRect, args.fStrokeWidth);
150 } else { 149 } else {
151 // hairline 150 // hairline
152 primType = kLineStrip_GrPrimitiveType; 151 primType = kLineStrip_GrPrimitiveType;
153 vertex[0].set(args.fRect.fLeft, args.fRect.fTop); 152 vertex[0].set(args.fRect.fLeft, args.fRect.fTop);
154 vertex[1].set(args.fRect.fRight, args.fRect.fTop); 153 vertex[1].set(args.fRect.fRight, args.fRect.fTop);
155 vertex[2].set(args.fRect.fRight, args.fRect.fBottom); 154 vertex[2].set(args.fRect.fRight, args.fRect.fBottom);
156 vertex[3].set(args.fRect.fLeft, args.fRect.fBottom); 155 vertex[3].set(args.fRect.fLeft, args.fRect.fBottom);
157 vertex[4].set(args.fRect.fLeft, args.fRect.fTop); 156 vertex[4].set(args.fRect.fLeft, args.fRect.fTop);
158 } 157 }
159 158
159 target->initDraw(gp, primType);
160 GrVertices vertices; 160 GrVertices vertices;
161 vertices.init(primType, vertexBuffer, firstVertex, vertexCount); 161 vertices.init(vertexBuffer, firstVertex, vertexCount);
162 target->draw(vertices); 162 target->draw(vertices);
163 } 163 }
164 164
165 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { 165 void initBatchTracker(const GrXPOverridesForBatch& overrides) override {
166 // Handle any color overrides 166 // Handle any color overrides
167 if (!overrides.readsColor()) { 167 if (!overrides.readsColor()) {
168 fGeoData[0].fColor = GrColor_ILLEGAL; 168 fGeoData[0].fColor = GrColor_ILLEGAL;
169 } 169 }
170 overrides.getOverrideColorIfSet(&fGeoData[0].fColor); 170 overrides.getOverrideColorIfSet(&fGeoData[0].fColor);
171 171
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 DRAW_BATCH_TEST_DEFINE(NonAAStrokeRectBatch) { 244 DRAW_BATCH_TEST_DEFINE(NonAAStrokeRectBatch) {
245 SkMatrix viewMatrix = GrTest::TestMatrix(random); 245 SkMatrix viewMatrix = GrTest::TestMatrix(random);
246 GrColor color = GrRandomColor(random); 246 GrColor color = GrRandomColor(random);
247 SkRect rect = GrTest::TestRect(random); 247 SkRect rect = GrTest::TestRect(random);
248 SkScalar strokeWidth = random->nextBool() ? 0.0f : 1.0f; 248 SkScalar strokeWidth = random->nextBool() ? 0.0f : 1.0f;
249 249
250 return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeWidth, random->nextBool()); 250 return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeWidth, random->nextBool());
251 } 251 }
252 252
253 #endif 253 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698