| 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 "GrAAFillRectBatch.h" | 8 #include "GrAAFillRectBatch.h" |
| 9 | 9 |
| 10 #include "GrColor.h" | 10 #include "GrColor.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 const GrPipelineOptimizations& opts) { | 281 const GrPipelineOptimizations& opts) { |
| 282 generate_aa_fill_rect_geometry(vertices, vertexStride, | 282 generate_aa_fill_rect_geometry(vertices, vertexStride, |
| 283 geo.fColor, geo.fViewMatrix, geo.fRect, g
eo.fDevRect, opts, | 283 geo.fColor, geo.fViewMatrix, geo.fRect, g
eo.fDevRect, opts, |
| 284 &geo.fLocalMatrix); | 284 &geo.fLocalMatrix); |
| 285 } | 285 } |
| 286 }; | 286 }; |
| 287 | 287 |
| 288 typedef GrTInstanceBatch<AAFillRectBatchNoLocalMatrixImp> AAFillRectBatchNoLocal
Matrix; | 288 typedef GrTInstanceBatch<AAFillRectBatchNoLocalMatrixImp> AAFillRectBatchNoLocal
Matrix; |
| 289 typedef GrTInstanceBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatr
ix; | 289 typedef GrTInstanceBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatr
ix; |
| 290 | 290 |
| 291 inline static void append_to_batch(AAFillRectBatchNoLocalMatrix* batch, GrColor
color, | 291 inline static void setup_geo(AAFillRectBatchNoLocalMatrix::Geometry* geo, GrColo
r color, |
| 292 const SkMatrix& viewMatrix, const SkRect& rec
t, | 292 const SkMatrix& viewMatrix, const SkRect& rect, |
| 293 const SkRect& devRect) { | 293 const SkRect& devRect) { |
| 294 AAFillRectBatchNoLocalMatrix::Geometry& geo = batch->geoData()->push_back(); | 294 geo->fColor = color; |
| 295 geo.fColor = color; | 295 geo->fViewMatrix = viewMatrix; |
| 296 geo.fViewMatrix = viewMatrix; | 296 geo->fRect = rect; |
| 297 geo.fRect = rect; | 297 geo->fDevRect = devRect; |
| 298 geo.fDevRect = devRect; | |
| 299 } | 298 } |
| 300 | 299 |
| 301 inline static void append_to_batch(AAFillRectBatchLocalMatrix* batch, GrColor co
lor, | 300 inline static void setup_geo(AAFillRectBatchLocalMatrix::Geometry* geo, GrColor
color, |
| 302 const SkMatrix& viewMatrix, const SkMatrix& l
ocalMatrix, | 301 const SkMatrix& viewMatrix, const SkMatrix& localMa
trix, |
| 303 const SkRect& rect, const SkRect& devRect) { | 302 const SkRect& rect, const SkRect& devRect) { |
| 304 AAFillRectBatchLocalMatrix::Geometry& geo = batch->geoData()->push_back(); | 303 geo->fColor = color; |
| 305 geo.fColor = color; | 304 geo->fViewMatrix = viewMatrix; |
| 306 geo.fViewMatrix = viewMatrix; | 305 geo->fLocalMatrix = localMatrix; |
| 307 geo.fLocalMatrix = localMatrix; | 306 geo->fRect = rect; |
| 308 geo.fRect = rect; | 307 geo->fDevRect = devRect; |
| 309 geo.fDevRect = devRect; | |
| 310 } | 308 } |
| 311 | 309 |
| 312 namespace GrAAFillRectBatch { | 310 namespace GrAAFillRectBatch { |
| 313 | 311 |
| 314 GrDrawBatch* Create(GrColor color, | 312 GrDrawBatch* Create(GrColor color, |
| 315 const SkMatrix& viewMatrix, | 313 const SkMatrix& viewMatrix, |
| 316 const SkRect& rect, | 314 const SkRect& rect, |
| 317 const SkRect& devRect) { | 315 const SkRect& devRect) { |
| 318 AAFillRectBatchNoLocalMatrix* batch = AAFillRectBatchNoLocalMatrix::Create()
; | 316 AAFillRectBatchNoLocalMatrix* batch = AAFillRectBatchNoLocalMatrix::Create()
; |
| 319 append_to_batch(batch, color, viewMatrix, rect, devRect); | 317 setup_geo(&batch->geoData()->push_back(), color, viewMatrix, rect, devRect); |
| 320 batch->init(); | 318 batch->init(); |
| 321 return batch; | 319 return batch; |
| 322 } | 320 } |
| 323 | 321 |
| 324 GrDrawBatch* Create(GrColor color, | 322 GrDrawBatch* Create(GrColor color, |
| 325 const SkMatrix& viewMatrix, | 323 const SkMatrix& viewMatrix, |
| 326 const SkMatrix& localMatrix, | 324 const SkMatrix& localMatrix, |
| 327 const SkRect& rect, | 325 const SkRect& rect) { |
| 328 const SkRect& devRect) { | 326 //map rect |
| 327 SkRect devRect; |
| 328 viewMatrix.mapRect(&devRect, rect); |
| 329 |
| 329 AAFillRectBatchLocalMatrix* batch = AAFillRectBatchLocalMatrix::Create(); | 330 AAFillRectBatchLocalMatrix* batch = AAFillRectBatchLocalMatrix::Create(); |
| 330 append_to_batch(batch, color, viewMatrix, localMatrix, rect, devRect); | 331 setup_geo(&batch->geoData()->push_back(), color, viewMatrix, localMatrix, re
ct, devRect); |
| 331 batch->init(); | 332 batch->init(); |
| 332 return batch; | 333 return batch; |
| 333 } | 334 } |
| 334 | 335 |
| 335 void Append(GrBatch* origBatch, | 336 bool Append(GrBatch* origBatch, |
| 336 GrColor color, | 337 GrColor color, |
| 337 const SkMatrix& viewMatrix, | 338 const SkMatrix& viewMatrix, |
| 338 const SkRect& rect, | 339 const SkRect& rect) { |
| 339 const SkRect& devRect) { | 340 // map rect |
| 341 SkRect devRect; |
| 342 viewMatrix.mapRect(&devRect, rect); |
| 343 |
| 340 AAFillRectBatchNoLocalMatrix* batch = origBatch->cast<AAFillRectBatchNoLocal
Matrix>(); | 344 AAFillRectBatchNoLocalMatrix* batch = origBatch->cast<AAFillRectBatchNoLocal
Matrix>(); |
| 341 append_to_batch(batch, color, viewMatrix, rect, devRect); | 345 AAFillRectBatchNoLocalMatrix::Geometry geo; |
| 342 batch->updateBoundsAfterAppend(); | 346 setup_geo(&geo, color, viewMatrix, rect, devRect); |
| 347 return batch->appendIfPossible(geo); |
| 343 } | 348 } |
| 344 | 349 |
| 345 void Append(GrBatch* origBatch, | 350 bool Append(GrBatch* origBatch, |
| 346 GrColor color, | 351 GrColor color, |
| 347 const SkMatrix& viewMatrix, | 352 const SkMatrix& viewMatrix, |
| 348 const SkMatrix& localMatrix, | 353 const SkMatrix& localMatrix, |
| 349 const SkRect& rect, | 354 const SkRect& rect, |
| 350 const SkRect& devRect) { | 355 const SkRect& devRect) { |
| 351 AAFillRectBatchLocalMatrix* batch = origBatch->cast<AAFillRectBatchLocalMatr
ix>(); | 356 AAFillRectBatchLocalMatrix* batch = origBatch->cast<AAFillRectBatchLocalMatr
ix>(); |
| 352 append_to_batch(batch, color, viewMatrix, localMatrix, rect, devRect); | 357 AAFillRectBatchLocalMatrix::Geometry geo; |
| 353 batch->updateBoundsAfterAppend(); | 358 setup_geo(&geo, color, viewMatrix, localMatrix, rect, devRect); |
| 359 return batch->appendIfPossible(geo); |
| 354 } | 360 } |
| 355 | 361 |
| 356 }; | 362 }; |
| 357 | 363 |
| 358 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 364 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 359 | 365 |
| 360 #ifdef GR_TEST_UTILS | 366 #ifdef GR_TEST_UTILS |
| 361 | 367 |
| 362 #include "GrBatchTest.h" | 368 #include "GrBatchTest.h" |
| 363 | 369 |
| 364 DRAW_BATCH_TEST_DEFINE(AAFillRectBatch) { | 370 DRAW_BATCH_TEST_DEFINE(AAFillRectBatch) { |
| 365 GrColor color = GrRandomColor(random); | 371 GrColor color = GrRandomColor(random); |
| 366 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 372 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 367 SkRect rect = GrTest::TestRect(random); | 373 SkRect rect = GrTest::TestRect(random); |
| 368 SkRect devRect = GrTest::TestRect(random); | 374 SkRect devRect = GrTest::TestRect(random); |
| 369 return GrAAFillRectBatch::Create(color, viewMatrix, rect, devRect); | 375 return GrAAFillRectBatch::Create(color, viewMatrix, rect, devRect); |
| 370 } | 376 } |
| 371 | 377 |
| 372 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { | 378 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { |
| 373 GrColor color = GrRandomColor(random); | 379 GrColor color = GrRandomColor(random); |
| 374 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 380 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 375 SkMatrix localMatrix = GrTest::TestMatrix(random); | 381 SkMatrix localMatrix = GrTest::TestMatrix(random); |
| 376 SkRect rect = GrTest::TestRect(random); | 382 SkRect rect = GrTest::TestRect(random); |
| 377 SkRect devRect = GrTest::TestRect(random); | 383 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect); |
| 378 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe
ct); | |
| 379 } | 384 } |
| 380 | 385 |
| 381 #endif | 386 #endif |
| OLD | NEW |