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 "GrBatchTest.h" |
13 #include "GrDefaultGeoProcFactory.h" | 13 #include "GrDefaultGeoProcFactory.h" |
14 #include "GrPrimitiveProcessor.h" | 14 #include "GrPrimitiveProcessor.h" |
15 | 15 |
16 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes we | 16 /** 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 | 17 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 | 18 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. | 19 haven't seen a use case which frequently switches between local rect and no local rect draws. |
20 | 20 |
21 The color param is used to determine whether the opaque hint can be set on t he draw state. | 21 The color param is used to determine whether the opaque hint can be set on t he draw state. |
22 The caller must populate the vertex colors itself. | 22 The caller must populate the vertex colors itself. |
23 | 23 |
24 The vertex attrib order is always pos, color, [local coords]. | 24 The vertex attrib order is always pos, color, [local coords]. |
25 */ | 25 */ |
26 static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, | 26 static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, |
27 const SkMatrix* localMatrix, | 27 const SkMatrix* localMatrix, |
robertphillips
2015/07/27 17:30:40
remove usesLocalCoords ?
| |
28 bool usesLocalCoords, | 28 bool usesLocalCoords, |
29 bool coverageIgnored) { | 29 bool coverageIgnored) { |
30 // TODO remove color when we have ignored color from the XP | 30 typedef GrDefaultGeoProcFactory::Color Color; |
31 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | | 31 typedef GrDefaultGeoProcFactory::Coverage Coverage; |
32 GrDefaultGeoProcFactory::kColor_GPType; | 32 typedef GrDefaultGeoProcFactory::LocalCoords LocalCoords; |
33 flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPTyp e : 0; | 33 Color color(Color::kAttribute_Type); |
34 Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_ Type); | |
35 LocalCoords::Type localCoords; | |
36 if (hasExplicitLocalCoords) { | |
37 localCoords = LocalCoords::kHasExplicit_Type; | |
38 } else { | |
39 localCoords = LocalCoords::kUsePosition_Type; | |
40 } | |
41 | |
34 if (localMatrix) { | 42 if (localMatrix) { |
35 return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCo ords, | 43 return GrDefaultGeoProcFactory::Create(color, coverage, localCoords, SkM atrix::I(), |
36 coverageIgnored, SkMatrix::I(), * localMatrix); | 44 *localMatrix); |
37 } else { | 45 } else { |
38 return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCo ords, | 46 return GrDefaultGeoProcFactory::Create(color, coverage, localCoords); |
39 coverageIgnored, SkMatrix::I(), S kMatrix::I()); | |
40 } | 47 } |
41 } | 48 } |
42 | 49 |
43 class RectBatch : public GrBatch { | 50 class RectBatch : public GrBatch { |
44 public: | 51 public: |
45 struct Geometry { | 52 struct Geometry { |
46 SkMatrix fViewMatrix; | 53 SkMatrix fViewMatrix; |
47 SkRect fRect; | 54 SkRect fRect; |
48 SkRect fLocalRect; | 55 SkRect fLocalRect; |
49 SkMatrix fLocalMatrix; | 56 SkMatrix fLocalMatrix; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 const Geometry& geom = fGeoData[i]; | 129 const Geometry& geom = fGeoData[i]; |
123 | 130 |
124 intptr_t offset = reinterpret_cast<intptr_t>(vertices) + | 131 intptr_t offset = reinterpret_cast<intptr_t>(vertices) + |
125 kVerticesPerQuad * i * vertexStride; | 132 kVerticesPerQuad * i * vertexStride; |
126 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); | 133 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); |
127 | 134 |
128 positions->setRectFan(geom.fRect.fLeft, geom.fRect.fTop, | 135 positions->setRectFan(geom.fRect.fLeft, geom.fRect.fTop, |
129 geom.fRect.fRight, geom.fRect.fBottom, vertexS tride); | 136 geom.fRect.fRight, geom.fRect.fBottom, vertexS tride); |
130 geom.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerti cesPerQuad); | 137 geom.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerti cesPerQuad); |
131 | 138 |
139 // TODO we should only do this if local coords are being read | |
132 if (geom.fHasLocalRect) { | 140 if (geom.fHasLocalRect) { |
133 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor ); | 141 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor ); |
134 SkPoint* coords = reinterpret_cast<SkPoint*>(offset + kLocalOffs et); | 142 SkPoint* coords = reinterpret_cast<SkPoint*>(offset + kLocalOffs et); |
135 coords->setRectFan(geom.fLocalRect.fLeft, geom.fLocalRect.fTop, | 143 coords->setRectFan(geom.fLocalRect.fLeft, geom.fLocalRect.fTop, |
136 geom.fLocalRect.fRight, geom.fLocalRect.fBott om, | 144 geom.fLocalRect.fRight, geom.fLocalRect.fBott om, |
137 vertexStride); | 145 vertexStride); |
138 if (geom.fHasLocalMatrix) { | 146 if (geom.fHasLocalMatrix) { |
139 geom.fLocalMatrix.mapPointsWithStride(coords, vertexStride, kVerticesPerQuad); | 147 geom.fLocalMatrix.mapPointsWithStride(coords, vertexStride, kVerticesPerQuad); |
140 } | 148 } |
141 } | 149 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 if (hasLocalMatrix) { | 279 if (hasLocalMatrix) { |
272 localMatrix = GrTest::TestMatrix(random); | 280 localMatrix = GrTest::TestMatrix(random); |
273 } | 281 } |
274 | 282 |
275 return GrRectBatch::Create(color, viewMatrix, rect, | 283 return GrRectBatch::Create(color, viewMatrix, rect, |
276 hasLocalRect ? &localRect : NULL, | 284 hasLocalRect ? &localRect : NULL, |
277 hasLocalMatrix ? &localMatrix : NULL); | 285 hasLocalMatrix ? &localMatrix : NULL); |
278 } | 286 } |
279 | 287 |
280 #endif | 288 #endif |
OLD | NEW |