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 "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 Loading... | |
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 Loading... | |
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 | |
robertphillips
2015/05/07 16:33:21
Don't bother initing viewMatrix and/or localMatrix
| |
261 SkMatrix viewMatrix = SkMatrix::I(); | |
262 SkMatrix localMatrix = SkMatrix::I(); | |
263 SkRect rect = GrTest::TestRect(random); | |
264 SkRect localRect; | |
265 bool hasLocalRect = random->nextBool(); | |
266 bool hasLocalMatrix = random->nextBool(); | |
267 | |
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 | |
OLD | NEW |