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 "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 this->joinBounds(that->bounds()); | 519 this->joinBounds(that->bounds()); |
520 return true; | 520 return true; |
521 } | 521 } |
522 | 522 |
523 GrXPOverridesForBatch fOverrides; | 523 GrXPOverridesForBatch fOverrides; |
524 SkSTArray<1, Geometry, true> fGeoData; | 524 SkSTArray<1, Geometry, true> fGeoData; |
525 | 525 |
526 typedef GrVertexBatch INHERITED; | 526 typedef GrVertexBatch INHERITED; |
527 }; | 527 }; |
528 | 528 |
529 inline static void append_to_batch(AAFillRectNoLocalMatrixBatch* batch, GrColor
color, | |
530 const SkMatrix& viewMatrix, const SkRect& rec
t, | |
531 const SkRect& devRect) { | |
532 AAFillRectNoLocalMatrixBatch::Geometry& geo = batch->geoData()->push_back(); | |
533 geo.fColor = color; | |
534 geo.fViewMatrix = viewMatrix; | |
535 geo.fRect = rect; | |
536 geo.fDevRect = devRect; | |
537 } | |
538 | |
539 inline static void append_to_batch(AAFillRectLocalMatrixBatch* batch, GrColor co
lor, | |
540 const SkMatrix& viewMatrix, const SkMatrix& l
ocalMatrix, | |
541 const SkRect& rect, const SkRect& devRect) { | |
542 AAFillRectLocalMatrixBatch::Geometry& geo = batch->geoData()->push_back(); | |
543 geo.fColor = color; | |
544 geo.fViewMatrix = viewMatrix; | |
545 geo.fLocalMatrix = localMatrix; | |
546 geo.fRect = rect; | |
547 geo.fDevRect = devRect; | |
548 } | |
549 | |
550 namespace GrAAFillRectBatch { | 529 namespace GrAAFillRectBatch { |
551 | 530 |
552 GrDrawBatch* Create(GrColor color, | 531 GrDrawBatch* Create(GrColor color, |
553 const SkMatrix& viewMatrix, | 532 const SkMatrix& viewMatrix, |
554 const SkRect& rect, | 533 const SkRect& rect, |
555 const SkRect& devRect) { | 534 const SkRect& devRect) { |
556 AAFillRectNoLocalMatrixBatch* batch = AAFillRectNoLocalMatrixBatch::Create()
; | 535 AAFillRectNoLocalMatrixBatch* batch = AAFillRectNoLocalMatrixBatch::Create()
; |
557 append_to_batch(batch, color, viewMatrix, rect, devRect); | 536 AAFillRectNoLocalMatrixBatch::Geometry& geo = batch->geoData()->push_back(); |
| 537 geo.fColor = color; |
| 538 geo.fViewMatrix = viewMatrix; |
| 539 geo.fRect = rect; |
| 540 geo.fDevRect = devRect; |
558 batch->init(); | 541 batch->init(); |
559 return batch; | 542 return batch; |
560 } | 543 } |
561 | 544 |
562 GrDrawBatch* Create(GrColor color, | 545 GrDrawBatch* Create(GrColor color, |
563 const SkMatrix& viewMatrix, | 546 const SkMatrix& viewMatrix, |
564 const SkMatrix& localMatrix, | 547 const SkMatrix& localMatrix, |
565 const SkRect& rect, | 548 const SkRect& rect, |
566 const SkRect& devRect) { | 549 const SkRect& devRect) { |
567 AAFillRectLocalMatrixBatch* batch = AAFillRectLocalMatrixBatch::Create(); | 550 AAFillRectLocalMatrixBatch* batch = AAFillRectLocalMatrixBatch::Create(); |
568 append_to_batch(batch, color, viewMatrix, localMatrix, rect, devRect); | 551 AAFillRectLocalMatrixBatch::Geometry& geo = batch->geoData()->push_back(); |
| 552 geo.fColor = color; |
| 553 geo.fViewMatrix = viewMatrix; |
| 554 geo.fLocalMatrix = localMatrix; |
| 555 geo.fRect = rect; |
| 556 geo.fDevRect = devRect; |
569 batch->init(); | 557 batch->init(); |
570 return batch; | 558 return batch; |
571 } | 559 } |
572 | 560 |
573 GrDrawBatch* Create(GrColor color, | 561 GrDrawBatch* Create(GrColor color, |
574 const SkMatrix& viewMatrix, | 562 const SkMatrix& viewMatrix, |
575 const SkMatrix& localMatrix, | 563 const SkMatrix& localMatrix, |
576 const SkRect& rect) { | 564 const SkRect& rect) { |
577 SkRect devRect; | 565 SkRect devRect; |
578 viewMatrix.mapRect(&devRect, rect); | 566 viewMatrix.mapRect(&devRect, rect); |
579 return Create(color, viewMatrix, localMatrix, rect, devRect); | 567 return Create(color, viewMatrix, localMatrix, rect, devRect); |
580 } | 568 } |
581 | 569 |
582 GrDrawBatch* CreateWithLocalRect(GrColor color, | 570 GrDrawBatch* CreateWithLocalRect(GrColor color, |
583 const SkMatrix& viewMatrix, | 571 const SkMatrix& viewMatrix, |
584 const SkRect& rect, | 572 const SkRect& rect, |
585 const SkRect& localRect) { | 573 const SkRect& localRect) { |
586 SkRect devRect; | 574 SkRect devRect; |
587 viewMatrix.mapRect(&devRect, rect); | 575 viewMatrix.mapRect(&devRect, rect); |
588 SkMatrix localMatrix; | 576 SkMatrix localMatrix; |
589 if (!localMatrix.setRectToRect(rect, localRect, SkMatrix::kFill_ScaleToFit))
{ | 577 if (!localMatrix.setRectToRect(rect, localRect, SkMatrix::kFill_ScaleToFit))
{ |
590 return nullptr; | 578 return nullptr; |
591 } | 579 } |
592 return Create(color, viewMatrix, localMatrix, rect, devRect); | 580 return Create(color, viewMatrix, localMatrix, rect, devRect); |
593 } | 581 } |
594 | 582 |
595 void Append(GrBatch* origBatch, | |
596 GrColor color, | |
597 const SkMatrix& viewMatrix, | |
598 const SkRect& rect, | |
599 const SkRect& devRect) { | |
600 AAFillRectNoLocalMatrixBatch* batch = origBatch->cast<AAFillRectNoLocalMatri
xBatch>(); | |
601 append_to_batch(batch, color, viewMatrix, rect, devRect); | |
602 batch->updateBoundsAfterAppend(); | |
603 } | |
604 | |
605 void Append(GrBatch* origBatch, | |
606 GrColor color, | |
607 const SkMatrix& viewMatrix, | |
608 const SkMatrix& localMatrix, | |
609 const SkRect& rect, | |
610 const SkRect& devRect) { | |
611 AAFillRectLocalMatrixBatch* batch = origBatch->cast<AAFillRectLocalMatrixBat
ch>(); | |
612 append_to_batch(batch, color, viewMatrix, localMatrix, rect, devRect); | |
613 batch->updateBoundsAfterAppend(); | |
614 } | |
615 | |
616 }; | 583 }; |
617 | 584 |
618 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 585 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
619 | 586 |
620 #ifdef GR_TEST_UTILS | 587 #ifdef GR_TEST_UTILS |
621 | 588 |
622 #include "GrBatchTest.h" | 589 #include "GrBatchTest.h" |
623 | 590 |
624 DRAW_BATCH_TEST_DEFINE(AAFillRectBatch) { | 591 DRAW_BATCH_TEST_DEFINE(AAFillRectBatch) { |
625 GrColor color = GrRandomColor(random); | 592 GrColor color = GrRandomColor(random); |
626 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 593 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
627 SkRect rect = GrTest::TestRect(random); | 594 SkRect rect = GrTest::TestRect(random); |
628 SkRect devRect = GrTest::TestRect(random); | 595 SkRect devRect = GrTest::TestRect(random); |
629 return GrAAFillRectBatch::Create(color, viewMatrix, rect, devRect); | 596 return GrAAFillRectBatch::Create(color, viewMatrix, rect, devRect); |
630 } | 597 } |
631 | 598 |
632 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { | 599 DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { |
633 GrColor color = GrRandomColor(random); | 600 GrColor color = GrRandomColor(random); |
634 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); | 601 SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
635 SkMatrix localMatrix = GrTest::TestMatrix(random); | 602 SkMatrix localMatrix = GrTest::TestMatrix(random); |
636 SkRect rect = GrTest::TestRect(random); | 603 SkRect rect = GrTest::TestRect(random); |
637 SkRect devRect = GrTest::TestRect(random); | 604 SkRect devRect = GrTest::TestRect(random); |
638 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe
ct); | 605 return GrAAFillRectBatch::Create(color, viewMatrix, localMatrix, rect, devRe
ct); |
639 } | 606 } |
640 | 607 |
641 #endif | 608 #endif |
OLD | NEW |