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

Side by Side Diff: src/gpu/GrRectBatch.cpp

Issue 1135513002: adding rect batch unit test (Closed) Base URL: https://skia.googlesource.com/skia.git@randbatch6
Patch Set: tidy Created 5 years, 7 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 | « no previous file | no next file » | 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 "GrRectBatch.h" 8 #include "GrRectBatch.h"
9 9
10 #include "GrBatch.h" 10 #include "GrBatch.h"
11 #include "GrBatchTarget.h" 11 #include "GrBatchTarget.h"
12 #include "GrBatchTest.h"
12 #include "GrDefaultGeoProcFactory.h" 13 #include "GrDefaultGeoProcFactory.h"
13 #include "GrPrimitiveProcessor.h" 14 #include "GrPrimitiveProcessor.h"
14 #include "GrTemplates.h" 15 #include "GrTemplates.h"
15 16
16 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes we 17 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes we
17 have explicit local coords and sometimes not. We *could* always provide expl icit local coords 18 have explicit local coords and sometimes not. We *could* always provide expl icit local coords
18 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we 19 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we
19 haven't seen a use case which frequently switches between local rect and no local rect draws. 20 haven't seen a use case which frequently switches between local rect and no local rect draws.
20 21
21 The color param is used to determine whether the opaque hint can be set on t he draw state. 22 The color param is used to determine whether the opaque hint can be set on t he draw state.
(...skipping 12 matching lines...) Expand all
34 GrColorIsOpaque(color)); 35 GrColorIsOpaque(color));
35 } else { 36 } else {
36 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMa trix::I(), 37 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMa trix::I(),
37 GrColorIsOpaque(color)); 38 GrColorIsOpaque(color));
38 } 39 }
39 } 40 }
40 41
41 class RectBatch : public GrBatch { 42 class RectBatch : public GrBatch {
42 public: 43 public:
43 struct Geometry { 44 struct Geometry {
44 GrColor fColor;
45 SkMatrix fViewMatrix; 45 SkMatrix fViewMatrix;
46 SkRect fRect; 46 SkRect fRect;
47 SkRect fLocalRect;
48 SkMatrix fLocalMatrix;
49 GrColor fColor;
47 bool fHasLocalRect; 50 bool fHasLocalRect;
48 bool fHasLocalMatrix; 51 bool fHasLocalMatrix;
49 SkRect fLocalRect;
50 SkMatrix fLocalMatrix;
51 }; 52 };
52 53
53 static GrBatch* Create(const Geometry& geometry) { 54 static GrBatch* Create(const Geometry& geometry) {
54 return SkNEW_ARGS(RectBatch, (geometry)); 55 return SkNEW_ARGS(RectBatch, (geometry));
55 } 56 }
56 57
57 const char* name() const override { return "RectBatch"; } 58 const char* name() const override { return "RectBatch"; }
58 59
59 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { 60 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
60 // When this is called on a batch, there is only one geometry bundle 61 // When this is called on a batch, there is only one geometry bundle
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 geometry.fHasLocalMatrix = true; 243 geometry.fHasLocalMatrix = true;
243 geometry.fLocalMatrix = *localMatrix; 244 geometry.fLocalMatrix = *localMatrix;
244 } else { 245 } else {
245 geometry.fHasLocalMatrix = false; 246 geometry.fHasLocalMatrix = false;
246 } 247 }
247 248
248 return RectBatch::Create(geometry); 249 return RectBatch::Create(geometry);
249 } 250 }
250 251
251 }; 252 };
253
254 //////////////////////////////////////////////////////////////////////////////// ///////////////////
255
256 #ifdef GR_TEST_UTILS
257
258 BATCH_TEST_DEFINE(RectBatch) {
259 GrColor color = GrRandomColor(random);
260
261 SkRect rect = GrTest::TestRect(random);
262 SkRect localRect;
263 bool hasLocalRect = random->nextBool();
264 bool hasLocalMatrix = random->nextBool();
265
266 SkMatrix viewMatrix;
267 SkMatrix localMatrix;
268 if (hasLocalRect) {
269 viewMatrix = GrTest::TestMatrixInvertible(random);
270 localRect = GrTest::TestRect(random);
271 } else {
272 viewMatrix = GrTest::TestMatrix(random);
273 }
274
275 if (hasLocalMatrix) {
276 localMatrix = GrTest::TestMatrix(random);
277 }
278
279 return GrRectBatch::Create(color, viewMatrix, rect,
280 hasLocalRect ? &localRect : NULL,
281 hasLocalMatrix ? &localMatrix : NULL);
282 }
283
284 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698