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 #include "GrTemplates.h" | |
16 | 15 |
17 /** 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 |
18 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 |
19 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 |
20 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. |
21 | 20 |
22 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. |
23 The caller must populate the vertex colors itself. | 22 The caller must populate the vertex colors itself. |
24 | 23 |
25 The vertex attrib order is always pos, color, [local coords]. | 24 The vertex attrib order is always pos, color, [local coords]. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 SkASSERT(hasExplicitLocalCoords ? | 111 SkASSERT(hasExplicitLocalCoords ? |
113 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo
calCoordAttr) : | 112 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo
calCoordAttr) : |
114 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr)); | 113 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr)); |
115 QuadHelper helper; | 114 QuadHelper helper; |
116 void* vertices = helper.init(batchTarget, vertexStride, instanceCount); | 115 void* vertices = helper.init(batchTarget, vertexStride, instanceCount); |
117 | 116 |
118 if (!vertices) { | 117 if (!vertices) { |
119 return; | 118 return; |
120 } | 119 } |
121 | 120 |
122 | |
123 for (int i = 0; i < instanceCount; i++) { | 121 for (int i = 0; i < instanceCount; i++) { |
124 const Geometry& geom = fGeoData[i]; | 122 const Geometry& geom = fGeoData[i]; |
125 | 123 |
126 intptr_t offset = GrTCast<intptr_t>(vertices) + kVerticesPerQuad * i
* vertexStride; | 124 intptr_t offset = reinterpret_cast<intptr_t>(vertices) + |
127 SkPoint* positions = GrTCast<SkPoint*>(offset); | 125 kVerticesPerQuad * i * vertexStride; |
| 126 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); |
128 | 127 |
129 positions->setRectFan(geom.fRect.fLeft, geom.fRect.fTop, | 128 positions->setRectFan(geom.fRect.fLeft, geom.fRect.fTop, |
130 geom.fRect.fRight, geom.fRect.fBottom, vertexS
tride); | 129 geom.fRect.fRight, geom.fRect.fBottom, vertexS
tride); |
131 geom.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerti
cesPerQuad); | 130 geom.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerti
cesPerQuad); |
132 | 131 |
133 if (geom.fHasLocalRect) { | 132 if (geom.fHasLocalRect) { |
134 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor
); | 133 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor
); |
135 SkPoint* coords = GrTCast<SkPoint*>(offset + kLocalOffset); | 134 SkPoint* coords = reinterpret_cast<SkPoint*>(offset + kLocalOffs
et); |
136 coords->setRectFan(geom.fLocalRect.fLeft, geom.fLocalRect.fTop, | 135 coords->setRectFan(geom.fLocalRect.fLeft, geom.fLocalRect.fTop, |
137 geom.fLocalRect.fRight, geom.fLocalRect.fBott
om, | 136 geom.fLocalRect.fRight, geom.fLocalRect.fBott
om, |
138 vertexStride); | 137 vertexStride); |
139 if (geom.fHasLocalMatrix) { | 138 if (geom.fHasLocalMatrix) { |
140 geom.fLocalMatrix.mapPointsWithStride(coords, vertexStride,
kVerticesPerQuad); | 139 geom.fLocalMatrix.mapPointsWithStride(coords, vertexStride,
kVerticesPerQuad); |
141 } | 140 } |
142 } | 141 } |
143 | 142 |
144 static const int kColorOffset = sizeof(SkPoint); | 143 static const int kColorOffset = sizeof(SkPoint); |
145 GrColor* vertColor = GrTCast<GrColor*>(offset + kColorOffset); | 144 GrColor* vertColor = reinterpret_cast<GrColor*>(offset + kColorOffse
t); |
146 for (int j = 0; j < 4; ++j) { | 145 for (int j = 0; j < 4; ++j) { |
147 *vertColor = geom.fColor; | 146 *vertColor = geom.fColor; |
148 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); | 147 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); |
149 } | 148 } |
150 } | 149 } |
151 | 150 |
152 helper.issueDraw(batchTarget); | 151 helper.issueDraw(batchTarget); |
153 } | 152 } |
154 | 153 |
155 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 154 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if (hasLocalMatrix) { | 267 if (hasLocalMatrix) { |
269 localMatrix = GrTest::TestMatrix(random); | 268 localMatrix = GrTest::TestMatrix(random); |
270 } | 269 } |
271 | 270 |
272 return GrRectBatch::Create(color, viewMatrix, rect, | 271 return GrRectBatch::Create(color, viewMatrix, rect, |
273 hasLocalRect ? &localRect : NULL, | 272 hasLocalRect ? &localRect : NULL, |
274 hasLocalMatrix ? &localMatrix : NULL); | 273 hasLocalMatrix ? &localMatrix : NULL); |
275 } | 274 } |
276 | 275 |
277 #endif | 276 #endif |
OLD | NEW |