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

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

Issue 1293583002: Introduce GrBatch subclasses GrDrawBatch and GrVertexBatch to prepare for non-drawing batches (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove duplicated fields in GrVertexBatch Created 5 years, 4 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
« no previous file with comments | « src/gpu/batches/GrBWFillRectBatch.h ('k') | src/gpu/batches/GrBatch.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "GrBWFillRectBatch.h" 8 #include "GrBWFillRectBatch.h"
9 9
10 #include "GrBatch.h" 10 #include "GrBatch.h"
11 #include "GrBatchTarget.h" 11 #include "GrBatchTarget.h"
12 #include "GrColor.h" 12 #include "GrColor.h"
13 #include "GrDefaultGeoProcFactory.h" 13 #include "GrDefaultGeoProcFactory.h"
14 #include "GrPrimitiveProcessor.h" 14 #include "GrPrimitiveProcessor.h"
15 15
16 class GrBatchTarget; 16 class GrBatchTarget;
17 class SkMatrix; 17 class SkMatrix;
18 struct SkRect; 18 struct SkRect;
19 19
20 class BWFillRectBatch : public GrBatch { 20 class BWFillRectBatch : public GrVertexBatch {
21 public: 21 public:
22 struct Geometry { 22 struct Geometry {
23 SkMatrix fViewMatrix; 23 SkMatrix fViewMatrix;
24 SkRect fRect; 24 SkRect fRect;
25 SkRect fLocalRect; 25 SkRect fLocalRect;
26 SkMatrix fLocalMatrix; 26 SkMatrix fLocalMatrix;
27 GrColor fColor; 27 GrColor fColor;
28 bool fHasLocalRect; 28 bool fHasLocalRect;
29 bool fHasLocalMatrix; 29 bool fHasLocalMatrix;
30 }; 30 };
31 31
32 static GrBatch* Create(const Geometry& geometry) { 32 static GrDrawBatch* Create(const Geometry& geometry) {
33 return SkNEW_ARGS(BWFillRectBatch, (geometry)); 33 return SkNEW_ARGS(BWFillRectBatch, (geometry));
34 } 34 }
35 35
36 const char* name() const override { return "RectBatch"; } 36 const char* name() const override { return "RectBatch"; }
37 37
38 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { 38 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
39 // When this is called on a batch, there is only one geometry bundle 39 // When this is called on a batch, there is only one geometry bundle
40 out->setKnownFourComponents(fGeoData[0].fColor); 40 out->setKnownFourComponents(fGeoData[0].fColor);
41 } 41 }
42 42
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 GrColor color() const { return fBatch.fColor; } 127 GrColor color() const { return fBatch.fColor; }
128 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 128 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
129 bool colorIgnored() const { return fBatch.fColorIgnored; } 129 bool colorIgnored() const { return fBatch.fColorIgnored; }
130 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } 130 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; }
131 const SkMatrix& localMatrix() const { return fGeoData[0].fLocalMatrix; } 131 const SkMatrix& localMatrix() const { return fGeoData[0].fLocalMatrix; }
132 bool hasLocalRect() const { return fGeoData[0].fHasLocalRect; } 132 bool hasLocalRect() const { return fGeoData[0].fHasLocalRect; }
133 bool hasLocalMatrix() const { return fGeoData[0].fHasLocalMatrix; } 133 bool hasLocalMatrix() const { return fGeoData[0].fHasLocalMatrix; }
134 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } 134 bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
135 135
136 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { 136 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
137 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipel ine(), t->bounds(), 137 BWFillRectBatch* that = t->cast<BWFillRectBatch>();
138 caps)) { 138 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(),
139 that->bounds(), caps)) {
139 return false; 140 return false;
140 } 141 }
141 142
142 BWFillRectBatch* that = t->cast<BWFillRectBatch>();
143
144 if (this->hasLocalRect() != that->hasLocalRect()) { 143 if (this->hasLocalRect() != that->hasLocalRect()) {
145 return false; 144 return false;
146 } 145 }
147 146
148 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); 147 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords());
149 if (!this->hasLocalRect() && this->usesLocalCoords()) { 148 if (!this->hasLocalRect() && this->usesLocalCoords()) {
150 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { 149 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
151 return false; 150 return false;
152 } 151 }
153 152
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 bool fUsesLocalCoords; 202 bool fUsesLocalCoords;
204 bool fColorIgnored; 203 bool fColorIgnored;
205 bool fCoverageIgnored; 204 bool fCoverageIgnored;
206 }; 205 };
207 206
208 BatchTracker fBatch; 207 BatchTracker fBatch;
209 SkSTArray<1, Geometry, true> fGeoData; 208 SkSTArray<1, Geometry, true> fGeoData;
210 }; 209 };
211 210
212 namespace GrBWFillRectBatch { 211 namespace GrBWFillRectBatch {
213 GrBatch* Create(GrColor color, 212 GrDrawBatch* Create(GrColor color,
214 const SkMatrix& viewMatrix, 213 const SkMatrix& viewMatrix,
215 const SkRect& rect, 214 const SkRect& rect,
216 const SkRect* localRect, 215 const SkRect* localRect,
217 const SkMatrix* localMatrix) { 216 const SkMatrix* localMatrix) {
218 BWFillRectBatch::Geometry geometry; 217 BWFillRectBatch::Geometry geometry;
219 geometry.fColor = color; 218 geometry.fColor = color;
220 geometry.fViewMatrix = viewMatrix; 219 geometry.fViewMatrix = viewMatrix;
221 geometry.fRect = rect; 220 geometry.fRect = rect;
222 221
223 if (localRect) { 222 if (localRect) {
224 geometry.fHasLocalRect = true; 223 geometry.fHasLocalRect = true;
225 geometry.fLocalRect = *localRect; 224 geometry.fLocalRect = *localRect;
226 } else { 225 } else {
227 geometry.fHasLocalRect = false; 226 geometry.fHasLocalRect = false;
228 } 227 }
229 228
230 if (localMatrix) { 229 if (localMatrix) {
231 geometry.fHasLocalMatrix = true; 230 geometry.fHasLocalMatrix = true;
232 geometry.fLocalMatrix = *localMatrix; 231 geometry.fLocalMatrix = *localMatrix;
233 } else { 232 } else {
234 geometry.fHasLocalMatrix = false; 233 geometry.fHasLocalMatrix = false;
235 } 234 }
236 235
237 return BWFillRectBatch::Create(geometry); 236 return BWFillRectBatch::Create(geometry);
238 } 237 }
239 }; 238 };
240 239
241 //////////////////////////////////////////////////////////////////////////////// /////////////////// 240 //////////////////////////////////////////////////////////////////////////////// ///////////////////
242 241
243 #ifdef GR_TEST_UTILS 242 #ifdef GR_TEST_UTILS
244 243
245 #include "GrBatchTest.h" 244 #include "GrBatchTest.h"
246 245
247 BATCH_TEST_DEFINE(RectBatch) { 246 DRAW_BATCH_TEST_DEFINE(RectBatch) {
248 BWFillRectBatch::Geometry geometry; 247 BWFillRectBatch::Geometry geometry;
249 geometry.fColor = GrRandomColor(random); 248 geometry.fColor = GrRandomColor(random);
250 249
251 geometry.fRect = GrTest::TestRect(random); 250 geometry.fRect = GrTest::TestRect(random);
252 geometry.fHasLocalRect = random->nextBool(); 251 geometry.fHasLocalRect = random->nextBool();
253 252
254 if (geometry.fHasLocalRect) { 253 if (geometry.fHasLocalRect) {
255 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); 254 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random);
256 geometry.fLocalRect = GrTest::TestRect(random); 255 geometry.fLocalRect = GrTest::TestRect(random);
257 } else { 256 } else {
258 geometry.fViewMatrix = GrTest::TestMatrix(random); 257 geometry.fViewMatrix = GrTest::TestMatrix(random);
259 } 258 }
260 259
261 geometry.fHasLocalMatrix = random->nextBool(); 260 geometry.fHasLocalMatrix = random->nextBool();
262 if (geometry.fHasLocalMatrix) { 261 if (geometry.fHasLocalMatrix) {
263 geometry.fLocalMatrix = GrTest::TestMatrix(random); 262 geometry.fLocalMatrix = GrTest::TestMatrix(random);
264 } 263 }
265 264
266 return BWFillRectBatch::Create(geometry); 265 return BWFillRectBatch::Create(geometry);
267 } 266 }
268 267
269 #endif 268 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrBWFillRectBatch.h ('k') | src/gpu/batches/GrBatch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698