| 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 this->joinBounds(that->bounds()); | 417 this->joinBounds(that->bounds()); |
| 418 return true; | 418 return true; |
| 419 } | 419 } |
| 420 | 420 |
| 421 GrXPOverridesForBatch fOverrides; | 421 GrXPOverridesForBatch fOverrides; |
| 422 SkSTArray<1, Geometry, true> fGeoData; | 422 SkSTArray<1, Geometry, true> fGeoData; |
| 423 | 423 |
| 424 typedef GrVertexBatch INHERITED; | 424 typedef GrVertexBatch INHERITED; |
| 425 }; | 425 }; |
| 426 | 426 |
| 427 inline static void append_to_batch(NonAAFillRectBatch* batch, GrColor color, | 427 namespace GrNonAAFillRectBatch { |
| 428 const SkMatrix& viewMatrix, const SkRect& rec
t, | 428 |
| 429 const SkRect* localRect, const SkMatrix* loca
lMatrix) { | 429 GrDrawBatch* Create(GrColor color, |
| 430 const SkMatrix& viewMatrix, |
| 431 const SkRect& rect, |
| 432 const SkRect* localRect, |
| 433 const SkMatrix* localMatrix) { |
| 434 NonAAFillRectBatch* batch = NonAAFillRectBatch::Create(); |
| 430 SkASSERT(!viewMatrix.hasPerspective() && (!localMatrix || !localMatrix->hasP
erspective())); | 435 SkASSERT(!viewMatrix.hasPerspective() && (!localMatrix || !localMatrix->hasP
erspective())); |
| 431 NonAAFillRectBatch::Geometry& geo = batch->geoData()->push_back(); | 436 NonAAFillRectBatch::Geometry& geo = batch->geoData()->push_back(); |
| 432 | 437 |
| 433 geo.fColor = color; | 438 geo.fColor = color; |
| 434 geo.fViewMatrix = viewMatrix; | 439 geo.fViewMatrix = viewMatrix; |
| 435 geo.fRect = rect; | 440 geo.fRect = rect; |
| 436 | 441 |
| 437 if (localRect && localMatrix) { | 442 if (localRect && localMatrix) { |
| 438 geo.fLocalQuad.setFromMappedRect(*localRect, *localMatrix); | 443 geo.fLocalQuad.setFromMappedRect(*localRect, *localMatrix); |
| 439 } else if (localRect) { | 444 } else if (localRect) { |
| 440 geo.fLocalQuad.set(*localRect); | 445 geo.fLocalQuad.set(*localRect); |
| 441 } else if (localMatrix) { | 446 } else if (localMatrix) { |
| 442 geo.fLocalQuad.setFromMappedRect(rect, *localMatrix); | 447 geo.fLocalQuad.setFromMappedRect(rect, *localMatrix); |
| 443 } else { | 448 } else { |
| 444 geo.fLocalQuad.set(rect); | 449 geo.fLocalQuad.set(rect); |
| 445 } | 450 } |
| 451 batch->init(); |
| 452 return batch; |
| 446 } | 453 } |
| 447 | 454 |
| 448 inline static void append_to_batch(NonAAFillRectPerspectiveBatch* batch, GrColor
color, | 455 GrDrawBatch* CreateWithPerspective(GrColor color, |
| 449 const SkMatrix& viewMatrix, const SkRect& rec
t, | 456 const SkMatrix& viewMatrix, |
| 450 const SkRect* localRect, const SkMatrix* loca
lMatrix) { | 457 const SkRect& rect, |
| 458 const SkRect* localRect, |
| 459 const SkMatrix* localMatrix) { |
| 460 NonAAFillRectPerspectiveBatch* batch = NonAAFillRectPerspectiveBatch::Create
(); |
| 451 SkASSERT(viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPers
pective())); | 461 SkASSERT(viewMatrix.hasPerspective() || (localMatrix && localMatrix->hasPers
pective())); |
| 452 NonAAFillRectPerspectiveBatch::Geometry& geo = batch->geoData()->push_back()
; | 462 NonAAFillRectPerspectiveBatch::Geometry& geo = batch->geoData()->push_back()
; |
| 453 | 463 |
| 454 geo.fColor = color; | 464 geo.fColor = color; |
| 455 geo.fViewMatrix = viewMatrix; | 465 geo.fViewMatrix = viewMatrix; |
| 456 geo.fRect = rect; | 466 geo.fRect = rect; |
| 457 geo.fHasLocalRect = SkToBool(localRect); | 467 geo.fHasLocalRect = SkToBool(localRect); |
| 458 geo.fHasLocalMatrix = SkToBool(localMatrix); | 468 geo.fHasLocalMatrix = SkToBool(localMatrix); |
| 459 if (localMatrix) { | 469 if (localMatrix) { |
| 460 geo.fLocalMatrix = *localMatrix; | 470 geo.fLocalMatrix = *localMatrix; |
| 461 } | 471 } |
| 462 if (localRect) { | 472 if (localRect) { |
| 463 geo.fLocalRect = *localRect; | 473 geo.fLocalRect = *localRect; |
| 464 } | 474 } |
| 465 | |
| 466 } | |
| 467 | |
| 468 namespace GrNonAAFillRectBatch { | |
| 469 | |
| 470 GrDrawBatch* Create(GrColor color, | |
| 471 const SkMatrix& viewMatrix, | |
| 472 const SkRect& rect, | |
| 473 const SkRect* localRect, | |
| 474 const SkMatrix* localMatrix) { | |
| 475 NonAAFillRectBatch* batch = NonAAFillRectBatch::Create(); | |
| 476 append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix); | |
| 477 batch->init(); | 475 batch->init(); |
| 478 return batch; | 476 return batch; |
| 479 } | 477 } |
| 480 | 478 |
| 481 GrDrawBatch* CreateWithPerspective(GrColor color, | |
| 482 const SkMatrix& viewMatrix, | |
| 483 const SkRect& rect, | |
| 484 const SkRect* localRect, | |
| 485 const SkMatrix* localMatrix) { | |
| 486 NonAAFillRectPerspectiveBatch* batch = NonAAFillRectPerspectiveBatch::Create
(); | |
| 487 append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix); | |
| 488 batch->init(); | |
| 489 return batch; | |
| 490 } | |
| 491 | |
| 492 bool Append(GrBatch* origBatch, | |
| 493 GrColor color, | |
| 494 const SkMatrix& viewMatrix, | |
| 495 const SkRect& rect, | |
| 496 const SkRect* localRect, | |
| 497 const SkMatrix* localMatrix) { | |
| 498 bool usePerspective = viewMatrix.hasPerspective() || | |
| 499 (localMatrix && localMatrix->hasPerspective()); | |
| 500 | |
| 501 if (usePerspective && origBatch->classID() != NonAAFillRectPerspectiveBatch:
:ClassID()) { | |
| 502 return false; | |
| 503 } | |
| 504 | |
| 505 if (!usePerspective) { | |
| 506 NonAAFillRectBatch* batch = origBatch->cast<NonAAFillRectBatch>(); | |
| 507 append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix); | |
| 508 batch->updateBoundsAfterAppend(); | |
| 509 } else { | |
| 510 NonAAFillRectPerspectiveBatch* batch = origBatch->cast<NonAAFillRectPers
pectiveBatch>(); | |
| 511 const NonAAFillRectPerspectiveBatch::Geometry& geo = batch->geoData()->b
ack(); | |
| 512 | |
| 513 if (!geo.fViewMatrix.cheapEqualTo(viewMatrix) || | |
| 514 geo.fHasLocalRect != SkToBool(localRect) || | |
| 515 geo.fHasLocalMatrix != SkToBool(localMatrix) || | |
| 516 (geo.fHasLocalMatrix && !geo.fLocalMatrix.cheapEqualTo(*localMatrix)
)) { | |
| 517 return false; | |
| 518 } | |
| 519 | |
| 520 append_to_batch(batch, color, viewMatrix, rect, localRect, localMatrix); | |
| 521 batch->updateBoundsAfterAppend(); | |
| 522 } | |
| 523 | |
| 524 return true; | |
| 525 } | |
| 526 | |
| 527 }; | 479 }; |
| 528 | 480 |
| 529 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 481 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 530 | 482 |
| 531 #ifdef GR_TEST_UTILS | 483 #ifdef GR_TEST_UTILS |
| 532 | 484 |
| 533 #include "GrBatchTest.h" | 485 #include "GrBatchTest.h" |
| 534 | 486 |
| 535 DRAW_BATCH_TEST_DEFINE(RectBatch) { | 487 DRAW_BATCH_TEST_DEFINE(RectBatch) { |
| 536 GrColor color = GrRandomColor(random); | 488 GrColor color = GrRandomColor(random); |
| 537 SkRect rect = GrTest::TestRect(random); | 489 SkRect rect = GrTest::TestRect(random); |
| 538 SkRect localRect = GrTest::TestRect(random); | 490 SkRect localRect = GrTest::TestRect(random); |
| 539 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 491 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 540 SkMatrix localMatrix = GrTest::TestMatrix(random); | 492 SkMatrix localMatrix = GrTest::TestMatrix(random); |
| 541 | 493 |
| 542 bool hasLocalRect = random->nextBool(); | 494 bool hasLocalRect = random->nextBool(); |
| 543 bool hasLocalMatrix = random->nextBool(); | 495 bool hasLocalMatrix = random->nextBool(); |
| 544 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, | 496 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, |
| 545 hasLocalRect ? &localRect : nullptr, | 497 hasLocalRect ? &localRect : nullptr, |
| 546 hasLocalMatrix ? &localMatrix : nullptr)
; | 498 hasLocalMatrix ? &localMatrix : nullptr)
; |
| 547 } | 499 } |
| 548 | 500 |
| 549 #endif | 501 #endif |
| OLD | NEW |