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 "GrNonAAFillRectBatch.h" | 8 #include "GrNonAAFillRectBatch.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 for (int j = 0; j < 4; ++j) { | 84 for (int j = 0; j < 4; ++j) { |
85 *vertColor = color; | 85 *vertColor = color; |
86 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); | 86 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 class NonAAFillRectBatch : public GrVertexBatch { | 90 class NonAAFillRectBatch : public GrVertexBatch { |
91 public: | 91 public: |
92 DEFINE_BATCH_CLASS_ID | 92 DEFINE_BATCH_CLASS_ID |
93 | 93 |
94 struct Geometry { | 94 NonAAFillRectBatch(GrColor color, const SkMatrix& viewMatrix, const SkRect&
rect, |
95 SkMatrix fViewMatrix; | 95 const SkRect* localRect, const SkMatrix* localMatrix) |
96 SkRect fRect; | 96 : INHERITED(ClassID()) { |
97 GrQuad fLocalQuad; | 97 SkASSERT(!viewMatrix.hasPerspective() && (!localMatrix || |
98 GrColor fColor; | 98 !localMatrix->hasPerspective()
)); |
99 }; | 99 RectInfo& info = fRects.push_back(); |
100 | 100 info.fColor = color; |
101 static NonAAFillRectBatch* Create() { return new NonAAFillRectBatch; } | 101 info.fViewMatrix = viewMatrix; |
| 102 info.fRect = rect; |
| 103 if (localRect && localMatrix) { |
| 104 info.fLocalQuad.setFromMappedRect(*localRect, *localMatrix); |
| 105 } else if (localRect) { |
| 106 info.fLocalQuad.set(*localRect); |
| 107 } else if (localMatrix) { |
| 108 info.fLocalQuad.setFromMappedRect(rect, *localMatrix); |
| 109 } else { |
| 110 info.fLocalQuad.set(rect); |
| 111 } |
| 112 viewMatrix.mapRect(&fBounds, fRects[0].fRect); |
| 113 } |
102 | 114 |
103 const char* name() const override { return "NonAAFillRectBatch"; } | 115 const char* name() const override { return "NonAAFillRectBatch"; } |
104 | 116 |
105 SkString dumpInfo() const override { | 117 SkString dumpInfo() const override { |
106 SkString str; | 118 SkString str; |
107 str.appendf("# batched: %d\n", fGeoData.count()); | 119 str.appendf("# batched: %d\n", fRects.count()); |
108 for (int i = 0; i < fGeoData.count(); ++i) { | 120 for (int i = 0; i < fRects.count(); ++i) { |
109 const Geometry& geo = fGeoData[i]; | 121 const RectInfo& info = fRects[i]; |
110 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B:
%.2f]\n", | 122 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B:
%.2f]\n", |
111 i, geo.fColor, | 123 i, info.fColor, |
112 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.f
Rect.fBottom); | 124 info.fRect.fLeft, info.fRect.fTop, info.fRect.fRight, in
fo.fRect.fBottom); |
113 } | 125 } |
114 str.append(INHERITED::dumpInfo()); | 126 str.append(INHERITED::dumpInfo()); |
115 return str; | 127 return str; |
116 } | 128 } |
117 | 129 |
118 void computePipelineOptimizations(GrInitInvariantOutput* color, | 130 void computePipelineOptimizations(GrInitInvariantOutput* color, |
119 GrInitInvariantOutput* coverage, | 131 GrInitInvariantOutput* coverage, |
120 GrBatchToXPOverrides* overrides) const ove
rride { | 132 GrBatchToXPOverrides* overrides) const ove
rride { |
121 // When this is called on a batch, there is only one geometry bundle | 133 // When this is called on a batch, there is only one geometry bundle |
122 color->setKnownFourComponents(fGeoData[0].fColor); | 134 color->setKnownFourComponents(fRects[0].fColor); |
123 coverage->setKnownSingleComponent(0xff); | 135 coverage->setKnownSingleComponent(0xff); |
124 } | 136 } |
125 | 137 |
126 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { | 138 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
127 overrides.getOverrideColorIfSet(&fGeoData[0].fColor); | 139 overrides.getOverrideColorIfSet(&fRects[0].fColor); |
128 fOverrides = overrides; | 140 fOverrides = overrides; |
129 } | 141 } |
130 | 142 |
131 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | |
132 | |
133 // After seeding, the client should call init() so the Batch can initialize
itself | |
134 void init() { fGeoData[0].fViewMatrix.mapRect(&fBounds, fGeoData[0].fRect);
} | |
135 | |
136 private: | 143 private: |
137 NonAAFillRectBatch() : INHERITED(ClassID()) {} | 144 NonAAFillRectBatch() : INHERITED(ClassID()) {} |
138 | 145 |
139 void onPrepareDraws(Target* target) const override { | 146 void onPrepareDraws(Target* target) const override { |
140 sk_sp<GrGeometryProcessor> gp = make_gp(fGeoData[0].fViewMatrix, fOverri
des.readsCoverage(), | 147 sk_sp<GrGeometryProcessor> gp = make_gp(fRects[0].fViewMatrix, fOverride
s.readsCoverage(), |
141 true, nullptr); | 148 true, nullptr); |
142 if (!gp) { | 149 if (!gp) { |
143 SkDebugf("Couldn't create GrGeometryProcessor\n"); | 150 SkDebugf("Couldn't create GrGeometryProcessor\n"); |
144 return; | 151 return; |
145 } | 152 } |
146 SkASSERT(gp->getVertexStride() == | 153 SkASSERT(gp->getVertexStride() == |
147 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); | 154 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); |
148 | 155 |
149 size_t vertexStride = gp->getVertexStride(); | 156 size_t vertexStride = gp->getVertexStride(); |
150 int instanceCount = fGeoData.count(); | 157 int instanceCount = fRects.count(); |
151 | 158 |
152 SkAutoTUnref<const GrBuffer> indexBuffer(target->resourceProvider()->ref
QuadIndexBuffer()); | 159 SkAutoTUnref<const GrBuffer> indexBuffer(target->resourceProvider()->ref
QuadIndexBuffer()); |
153 InstancedHelper helper; | 160 InstancedHelper helper; |
154 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS
tride, | 161 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS
tride, |
155 indexBuffer, kVertsPerInstance, | 162 indexBuffer, kVertsPerInstance, |
156 kIndicesPerInstance, instanceCount); | 163 kIndicesPerInstance, instanceCount); |
157 if (!vertices || !indexBuffer) { | 164 if (!vertices || !indexBuffer) { |
158 SkDebugf("Could not allocate vertices\n"); | 165 SkDebugf("Could not allocate vertices\n"); |
159 return; | 166 return; |
160 } | 167 } |
161 | 168 |
162 for (int i = 0; i < instanceCount; i++) { | 169 for (int i = 0; i < instanceCount; i++) { |
163 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + | 170 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + |
164 i * kVertsPerInstance * vertexStride; | 171 i * kVertsPerInstance * vertexStride; |
165 tesselate(verts, vertexStride, fGeoData[i].fColor, fGeoData[i].fView
Matrix, | 172 tesselate(verts, vertexStride, fRects[i].fColor, fRects[i].fViewMatr
ix, |
166 fGeoData[i].fRect, &fGeoData[i].fLocalQuad); | 173 fRects[i].fRect, &fRects[i].fLocalQuad); |
167 } | 174 } |
168 helper.recordDraw(target, gp.get()); | 175 helper.recordDraw(target, gp.get()); |
169 } | 176 } |
170 | 177 |
171 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 178 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
172 NonAAFillRectBatch* that = t->cast<NonAAFillRectBatch>(); | 179 NonAAFillRectBatch* that = t->cast<NonAAFillRectBatch>(); |
173 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), | 180 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
174 that->bounds(), caps)) { | 181 that->bounds(), caps)) { |
175 return false; | 182 return false; |
176 } | 183 } |
177 | 184 |
178 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to | 185 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to |
179 // not tweaking | 186 // not tweaking |
180 if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakA
lphaForCoverage()) { | 187 if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakA
lphaForCoverage()) { |
181 fOverrides = that->fOverrides; | 188 fOverrides = that->fOverrides; |
182 } | 189 } |
183 | 190 |
184 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 191 fRects.push_back_n(that->fRects.count(), that->fRects.begin()); |
185 this->joinBounds(that->bounds()); | 192 this->joinBounds(that->bounds()); |
186 return true; | 193 return true; |
187 } | 194 } |
188 | 195 |
| 196 struct RectInfo { |
| 197 GrColor fColor; |
| 198 SkMatrix fViewMatrix; |
| 199 SkRect fRect; |
| 200 GrQuad fLocalQuad; |
| 201 }; |
| 202 |
189 GrXPOverridesForBatch fOverrides; | 203 GrXPOverridesForBatch fOverrides; |
190 SkSTArray<1, Geometry, true> fGeoData; | 204 SkSTArray<1, RectInfo, true> fRects; |
191 | 205 |
192 typedef GrVertexBatch INHERITED; | 206 typedef GrVertexBatch INHERITED; |
193 }; | 207 }; |
194 | 208 |
195 // We handle perspective in the local matrix or viewmatrix with special batches | 209 // We handle perspective in the local matrix or viewmatrix with special batches |
196 class NonAAFillRectPerspectiveBatch : public GrVertexBatch { | 210 class NonAAFillRectPerspectiveBatch : public GrVertexBatch { |
197 public: | 211 public: |
198 DEFINE_BATCH_CLASS_ID | 212 DEFINE_BATCH_CLASS_ID |
199 | 213 |
200 struct Geometry { | 214 NonAAFillRectPerspectiveBatch(GrColor color, const SkMatrix& viewMatrix, con
st SkRect& rect, |
201 SkMatrix fViewMatrix; | 215 const SkRect* localRect, const SkMatrix* local
Matrix) |
202 SkMatrix fLocalMatrix; | 216 : INHERITED(ClassID()) |
203 SkRect fRect; | 217 , fViewMatrix(viewMatrix) { |
204 SkRect fLocalRect; | 218 SkASSERT(viewMatrix.hasPerspective() || (localMatrix && |
205 GrColor fColor; | 219 localMatrix->hasPerspective()))
; |
206 bool fHasLocalMatrix; | 220 RectInfo& info = fRects.push_back(); |
207 bool fHasLocalRect; | 221 info.fColor = color; |
208 }; | 222 info.fRect = rect; |
209 | 223 fHasLocalRect = SkToBool(localRect); |
210 static NonAAFillRectPerspectiveBatch* Create() { return new NonAAFillRectPer
spectiveBatch; } | 224 fHasLocalMatrix = SkToBool(localMatrix); |
| 225 if (fHasLocalMatrix) { |
| 226 fLocalMatrix = *localMatrix; |
| 227 } |
| 228 if (fHasLocalRect) { |
| 229 info.fLocalRect = *localRect; |
| 230 } |
| 231 viewMatrix.mapRect(&fBounds, rect); |
| 232 } |
211 | 233 |
212 const char* name() const override { return "NonAAFillRectPerspectiveBatch";
} | 234 const char* name() const override { return "NonAAFillRectPerspectiveBatch";
} |
213 | 235 |
214 SkString dumpInfo() const override { | 236 SkString dumpInfo() const override { |
215 SkString str; | 237 SkString str; |
216 str.appendf("# batched: %d\n", fGeoData.count()); | 238 str.appendf("# batched: %d\n", fRects.count()); |
217 for (int i = 0; i < fGeoData.count(); ++i) { | 239 for (int i = 0; i < fRects.count(); ++i) { |
218 const Geometry& geo = fGeoData[0]; | 240 const RectInfo& geo = fRects[0]; |
219 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B:
%.2f]\n", | 241 str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B:
%.2f]\n", |
220 i, geo.fColor, | 242 i, geo.fColor, |
221 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.f
Rect.fBottom); | 243 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.f
Rect.fBottom); |
222 } | 244 } |
223 str.append(INHERITED::dumpInfo()); | 245 str.append(INHERITED::dumpInfo()); |
224 return str; | 246 return str; |
225 } | 247 } |
226 | 248 |
227 void computePipelineOptimizations(GrInitInvariantOutput* color, | 249 void computePipelineOptimizations(GrInitInvariantOutput* color, |
228 GrInitInvariantOutput* coverage, | 250 GrInitInvariantOutput* coverage, |
229 GrBatchToXPOverrides* overrides) const ove
rride { | 251 GrBatchToXPOverrides* overrides) const ove
rride { |
230 // When this is called on a batch, there is only one geometry bundle | 252 // When this is called on a batch, there is only one geometry bundle |
231 color->setKnownFourComponents(fGeoData[0].fColor); | 253 color->setKnownFourComponents(fRects[0].fColor); |
232 coverage->setKnownSingleComponent(0xff); | 254 coverage->setKnownSingleComponent(0xff); |
233 } | 255 } |
234 | 256 |
235 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { | 257 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
236 overrides.getOverrideColorIfSet(&fGeoData[0].fColor); | 258 overrides.getOverrideColorIfSet(&fRects[0].fColor); |
237 fOverrides = overrides; | 259 fOverrides = overrides; |
238 } | 260 } |
239 | 261 |
240 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | |
241 | |
242 // After seeding, the client should call init() so the Batch can initialize
itself | |
243 void init() { fGeoData[0].fViewMatrix.mapRect(&fBounds, fGeoData[0].fRect);
} | |
244 | |
245 private: | 262 private: |
246 NonAAFillRectPerspectiveBatch() : INHERITED(ClassID()) {} | 263 NonAAFillRectPerspectiveBatch() : INHERITED(ClassID()) {} |
247 | 264 |
248 void onPrepareDraws(Target* target) const override { | 265 void onPrepareDraws(Target* target) const override { |
249 sk_sp<GrGeometryProcessor> gp = make_gp(fGeoData[0].fViewMatrix, fOverri
des.readsCoverage(), | 266 sk_sp<GrGeometryProcessor> gp = make_gp(fViewMatrix, fOverrides.readsCov
erage(), |
250 fGeoData[0].fHasLocalRect, | 267 fHasLocalRect, |
251 fGeoData[0].fHasLocalMatrix | 268 fHasLocalMatrix ? &fLocalMatrix
: nullptr); |
252 ? &fGeoData[0].fLocalMatrix | |
253 : nullptr); | |
254 if (!gp) { | 269 if (!gp) { |
255 SkDebugf("Couldn't create GrGeometryProcessor\n"); | 270 SkDebugf("Couldn't create GrGeometryProcessor\n"); |
256 return; | 271 return; |
257 } | 272 } |
258 SkASSERT(fGeoData[0].fHasLocalRect | 273 SkASSERT(fHasLocalRect |
259 ? gp->getVertexStride() == | 274 ? gp->getVertexStride() == |
260 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord
Attr) | 275 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoord
Attr) |
261 : gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::
PositionColorAttr)); | 276 : gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::
PositionColorAttr)); |
262 | 277 |
263 size_t vertexStride = gp->getVertexStride(); | 278 size_t vertexStride = gp->getVertexStride(); |
264 int instanceCount = fGeoData.count(); | 279 int instanceCount = fRects.count(); |
265 | 280 |
266 SkAutoTUnref<const GrBuffer> indexBuffer(target->resourceProvider()->ref
QuadIndexBuffer()); | 281 SkAutoTUnref<const GrBuffer> indexBuffer(target->resourceProvider()->ref
QuadIndexBuffer()); |
267 InstancedHelper helper; | 282 InstancedHelper helper; |
268 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS
tride, | 283 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexS
tride, |
269 indexBuffer, kVertsPerInstance, | 284 indexBuffer, kVertsPerInstance, |
270 kIndicesPerInstance, instanceCount); | 285 kIndicesPerInstance, instanceCount); |
271 if (!vertices || !indexBuffer) { | 286 if (!vertices || !indexBuffer) { |
272 SkDebugf("Could not allocate vertices\n"); | 287 SkDebugf("Could not allocate vertices\n"); |
273 return; | 288 return; |
274 } | 289 } |
275 | 290 |
276 for (int i = 0; i < instanceCount; i++) { | 291 for (int i = 0; i < instanceCount; i++) { |
277 const Geometry& geo = fGeoData[i]; | 292 const RectInfo& info = fRects[i]; |
278 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + | 293 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + |
279 i * kVertsPerInstance * vertexStride; | 294 i * kVertsPerInstance * vertexStride; |
280 if (geo.fHasLocalRect) { | 295 if (fHasLocalRect) { |
281 GrQuad quad(geo.fLocalRect); | 296 GrQuad quad(info.fLocalRect); |
282 tesselate(verts, vertexStride, geo.fColor, geo.fViewMatrix, geo.
fRect, &quad); | 297 tesselate(verts, vertexStride, info.fColor, fViewMatrix, info.fR
ect, &quad); |
283 } else { | 298 } else { |
284 tesselate(verts, vertexStride, geo.fColor, geo.fViewMatrix, geo.
fRect, nullptr); | 299 tesselate(verts, vertexStride, info.fColor, fViewMatrix, info.fR
ect, nullptr); |
285 } | 300 } |
286 } | 301 } |
287 helper.recordDraw(target, gp.get()); | 302 helper.recordDraw(target, gp.get()); |
288 } | 303 } |
289 | 304 |
290 const Geometry& seedGeometry() const { return fGeoData[0]; } | |
291 | |
292 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 305 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
293 NonAAFillRectPerspectiveBatch* that = t->cast<NonAAFillRectPerspectiveBa
tch>(); | 306 NonAAFillRectPerspectiveBatch* that = t->cast<NonAAFillRectPerspectiveBa
tch>(); |
294 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), | 307 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
295 that->bounds(), caps)) { | 308 that->bounds(), caps)) { |
296 return false; | 309 return false; |
297 } | 310 } |
298 | 311 |
299 // We could batch across perspective vm changes if we really wanted to | 312 // We could batch across perspective vm changes if we really wanted to |
300 if (!fGeoData[0].fViewMatrix.cheapEqualTo(that->fGeoData[0].fViewMatrix)
) { | 313 if (!fViewMatrix.cheapEqualTo(that->fViewMatrix)) { |
301 return false; | 314 return false; |
302 } | 315 } |
303 if (fGeoData[0].fHasLocalRect != that->fGeoData[0].fHasLocalRect) { | 316 if (fHasLocalRect != that->fHasLocalRect) { |
304 return false; | 317 return false; |
305 } | 318 } |
306 if (fGeoData[0].fHasLocalMatrix && | 319 if (fHasLocalMatrix && !fLocalMatrix.cheapEqualTo(that->fLocalMatrix)) { |
307 !fGeoData[0].fLocalMatrix.cheapEqualTo(that->fGeoData[0].fLocalMatri
x)) { | |
308 return false; | 320 return false; |
309 } | 321 } |
310 | 322 |
311 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to | 323 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to |
312 // not tweaking | 324 // not tweaking |
313 if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakA
lphaForCoverage()) { | 325 if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakA
lphaForCoverage()) { |
314 fOverrides = that->fOverrides; | 326 fOverrides = that->fOverrides; |
315 } | 327 } |
316 | 328 |
317 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 329 fRects.push_back_n(that->fRects.count(), that->fRects.begin()); |
318 this->joinBounds(that->bounds()); | 330 this->joinBounds(that->bounds()); |
319 return true; | 331 return true; |
320 } | 332 } |
321 | 333 |
| 334 struct RectInfo { |
| 335 SkRect fRect; |
| 336 GrColor fColor; |
| 337 SkRect fLocalRect; |
| 338 }; |
| 339 |
322 GrXPOverridesForBatch fOverrides; | 340 GrXPOverridesForBatch fOverrides; |
323 SkSTArray<1, Geometry, true> fGeoData; | 341 SkSTArray<1, RectInfo, true> fRects; |
| 342 bool fHasLocalMatrix; |
| 343 bool fHasLocalRect; |
| 344 SkMatrix fLocalMatrix; |
| 345 SkMatrix fViewMatrix; |
324 | 346 |
325 typedef GrVertexBatch INHERITED; | 347 typedef GrVertexBatch INHERITED; |
326 }; | 348 }; |
327 | 349 |
328 namespace GrNonAAFillRectBatch { | 350 namespace GrNonAAFillRectBatch { |
329 | 351 |
330 GrDrawBatch* Create(GrColor color, | 352 GrDrawBatch* Create(GrColor color, |
331 const SkMatrix& viewMatrix, | 353 const SkMatrix& viewMatrix, |
332 const SkRect& rect, | 354 const SkRect& rect, |
333 const SkRect* localRect, | 355 const SkRect* localRect, |
334 const SkMatrix* localMatrix) { | 356 const SkMatrix* localMatrix) { |
335 NonAAFillRectBatch* batch = NonAAFillRectBatch::Create(); | 357 return new NonAAFillRectBatch(color, viewMatrix, rect, localRect, localMatri
x); |
336 SkASSERT(!viewMatrix.hasPerspective() && (!localMatrix || !localMatrix->hasP
erspective())); | |
337 NonAAFillRectBatch::Geometry& geo = batch->geoData()->push_back(); | |
338 | |
339 geo.fColor = color; | |
340 geo.fViewMatrix = viewMatrix; | |
341 geo.fRect = rect; | |
342 | |
343 if (localRect && localMatrix) { | |
344 geo.fLocalQuad.setFromMappedRect(*localRect, *localMatrix); | |
345 } else if (localRect) { | |
346 geo.fLocalQuad.set(*localRect); | |
347 } else if (localMatrix) { | |
348 geo.fLocalQuad.setFromMappedRect(rect, *localMatrix); | |
349 } else { | |
350 geo.fLocalQuad.set(rect); | |
351 } | |
352 batch->init(); | |
353 return batch; | |
354 } | 358 } |
355 | 359 |
356 GrDrawBatch* CreateWithPerspective(GrColor color, | 360 GrDrawBatch* CreateWithPerspective(GrColor color, |
357 const SkMatrix& viewMatrix, | 361 const SkMatrix& viewMatrix, |
358 const SkRect& rect, | 362 const SkRect& rect, |
359 const SkRect* localRect, | 363 const SkRect* localRect, |
360 const SkMatrix* localMatrix) { | 364 const SkMatrix* localMatrix) { |
361 NonAAFillRectPerspectiveBatch* batch = NonAAFillRectPerspectiveBatch::Create
(); | 365 return new NonAAFillRectPerspectiveBatch(color, viewMatrix, rect, localRect,
localMatrix); |
362 SkASSERT(viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPers
pective())); | |
363 NonAAFillRectPerspectiveBatch::Geometry& geo = batch->geoData()->push_back()
; | |
364 | |
365 geo.fColor = color; | |
366 geo.fViewMatrix = viewMatrix; | |
367 geo.fRect = rect; | |
368 geo.fHasLocalRect = SkToBool(localRect); | |
369 geo.fHasLocalMatrix = SkToBool(localMatrix); | |
370 if (localMatrix) { | |
371 geo.fLocalMatrix = *localMatrix; | |
372 } | |
373 if (localRect) { | |
374 geo.fLocalRect = *localRect; | |
375 } | |
376 batch->init(); | |
377 return batch; | |
378 } | 366 } |
379 | 367 |
380 }; | 368 }; |
381 | 369 |
382 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 370 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
383 | 371 |
384 #ifdef GR_TEST_UTILS | 372 #ifdef GR_TEST_UTILS |
385 | 373 |
386 #include "GrBatchTest.h" | 374 #include "GrBatchTest.h" |
387 | 375 |
388 DRAW_BATCH_TEST_DEFINE(RectBatch) { | 376 DRAW_BATCH_TEST_DEFINE(RectBatch) { |
389 GrColor color = GrRandomColor(random); | 377 GrColor color = GrRandomColor(random); |
390 SkRect rect = GrTest::TestRect(random); | 378 SkRect rect = GrTest::TestRect(random); |
391 SkRect localRect = GrTest::TestRect(random); | 379 SkRect localRect = GrTest::TestRect(random); |
392 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 380 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
393 SkMatrix localMatrix = GrTest::TestMatrix(random); | 381 SkMatrix localMatrix = GrTest::TestMatrix(random); |
394 | 382 |
395 bool hasLocalRect = random->nextBool(); | 383 bool hasLocalRect = random->nextBool(); |
396 bool hasLocalMatrix = random->nextBool(); | 384 bool hasLocalMatrix = random->nextBool(); |
397 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, | 385 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, |
398 hasLocalRect ? &localRect : nullptr, | 386 hasLocalRect ? &localRect : nullptr, |
399 hasLocalMatrix ? &localMatrix : nullptr)
; | 387 hasLocalMatrix ? &localMatrix : nullptr)
; |
400 } | 388 } |
401 | 389 |
402 #endif | 390 #endif |
OLD | NEW |