OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/canvas2d/CanvasRenderingContext2D.h" | 5 #include "modules/canvas2d/CanvasRenderingContext2D.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "bindings/core/v8/V8BindingForCore.h" | 8 #include "bindings/core/v8/V8BindingForCore.h" |
9 #include "bindings/core/v8/V8BindingForTesting.h" | 9 #include "bindings/core/v8/V8BindingForTesting.h" |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), | 511 TEST_OVERDRAW_2(1, setGlobalCompositeOperation(String("copy")), |
512 fillRect(0, 0, 5, 5)); | 512 fillRect(0, 0, 5, 5)); |
513 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-over")), | 513 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-over")), |
514 fillRect(0, 0, 5, 5)); | 514 fillRect(0, 0, 5, 5)); |
515 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), | 515 TEST_OVERDRAW_2(0, setGlobalCompositeOperation(String("source-in")), |
516 fillRect(0, 0, 5, 5)); | 516 fillRect(0, 0, 5, 5)); |
517 } | 517 } |
518 | 518 |
519 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionByDefault) { | 519 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionByDefault) { |
520 CreateContext(kNonOpaque); | 520 CreateContext(kNonOpaque); |
521 std::unique_ptr<RecordingImageBufferSurface> surface = | 521 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
522 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 522 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
523 auto* surface_ptr = surface.get(); | 523 auto* surface_ptr = surface.get(); |
524 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 524 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
525 | 525 |
526 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); | 526 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); |
527 EXPECT_TRUE(surface_ptr->IsRecording()); | 527 EXPECT_TRUE(surface_ptr->IsRecording()); |
528 } | 528 } |
529 | 529 |
530 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderOverdrawLimit) { | 530 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderOverdrawLimit) { |
531 CreateContext(kNonOpaque); | 531 CreateContext(kNonOpaque); |
532 std::unique_ptr<RecordingImageBufferSurface> surface = | 532 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
533 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 533 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
534 auto* surface_ptr = surface.get(); | 534 auto* surface_ptr = surface.get(); |
535 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 535 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
536 | 536 |
537 Context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization | 537 Context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization |
538 for (int i = 0; | 538 for (int i = 0; |
539 i < ExpensiveCanvasHeuristicParameters::kExpensiveOverdrawThreshold - 1; | 539 i < ExpensiveCanvasHeuristicParameters::kExpensiveOverdrawThreshold - 1; |
540 i++) { | 540 i++) { |
541 Context2d()->fillRect(0, 0, 10, 10); | 541 Context2d()->fillRect(0, 0, 10, 10); |
542 } | 542 } |
543 | 543 |
544 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); | 544 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); |
545 EXPECT_TRUE(surface_ptr->IsRecording()); | 545 EXPECT_TRUE(surface_ptr->IsRecording()); |
546 } | 546 } |
547 | 547 |
548 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverOverdrawLimit) { | 548 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverOverdrawLimit) { |
549 CreateContext(kNonOpaque); | 549 CreateContext(kNonOpaque); |
550 std::unique_ptr<RecordingImageBufferSurface> surface = | 550 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
551 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 551 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
552 auto* surface_ptr = surface.get(); | 552 auto* surface_ptr = surface.get(); |
553 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 553 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
554 | 554 |
555 Context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization | 555 Context2d()->setGlobalAlpha(0.5f); // To prevent overdraw optimization |
556 for (int i = 0; | 556 for (int i = 0; |
557 i < ExpensiveCanvasHeuristicParameters::kExpensiveOverdrawThreshold; | 557 i < ExpensiveCanvasHeuristicParameters::kExpensiveOverdrawThreshold; |
558 i++) { | 558 i++) { |
559 Context2d()->fillRect(0, 0, 10, 10); | 559 Context2d()->fillRect(0, 0, 10, 10); |
560 } | 560 } |
561 | 561 |
562 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); | 562 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); |
563 EXPECT_TRUE(surface_ptr->IsRecording()); | 563 EXPECT_TRUE(surface_ptr->IsRecording()); |
564 } | 564 } |
565 | 565 |
566 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderImageSizeRatioLimit) { | 566 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionUnderImageSizeRatioLimit) { |
567 CreateContext(kNonOpaque); | 567 CreateContext(kNonOpaque); |
568 std::unique_ptr<RecordingImageBufferSurface> surface = | 568 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
569 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 569 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
570 auto* surface_ptr = surface.get(); | 570 auto* surface_ptr = surface.get(); |
571 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 571 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
572 | 572 |
573 NonThrowableExceptionState exception_state; | 573 NonThrowableExceptionState exception_state; |
574 Element* source_canvas_element = | 574 Element* source_canvas_element = |
575 GetDocument().createElement("canvas", exception_state); | 575 GetDocument().createElement("canvas", exception_state); |
576 EXPECT_FALSE(exception_state.HadException()); | 576 EXPECT_FALSE(exception_state.HadException()); |
577 HTMLCanvasElement* source_canvas = | 577 HTMLCanvasElement* source_canvas = |
578 static_cast<HTMLCanvasElement*>(source_canvas_element); | 578 static_cast<HTMLCanvasElement*>(source_canvas_element); |
579 IntSize source_size( | 579 IntSize source_size( |
(...skipping 12 matching lines...) Expand all Loading... |
592 Context2d()->drawImage(GetScriptState(), source_image_bitmap, 0, 0, 1, 1, 0, | 592 Context2d()->drawImage(GetScriptState(), source_image_bitmap, 0, 0, 1, 1, 0, |
593 0, 1, 1, exception_state); | 593 0, 1, 1, exception_state); |
594 EXPECT_FALSE(exception_state.HadException()); | 594 EXPECT_FALSE(exception_state.HadException()); |
595 | 595 |
596 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); | 596 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); |
597 EXPECT_TRUE(surface_ptr->IsRecording()); | 597 EXPECT_TRUE(surface_ptr->IsRecording()); |
598 } | 598 } |
599 | 599 |
600 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverImageSizeRatioLimit) { | 600 TEST_F(CanvasRenderingContext2DTest, LayerPromotionOverImageSizeRatioLimit) { |
601 CreateContext(kNonOpaque); | 601 CreateContext(kNonOpaque); |
602 std::unique_ptr<RecordingImageBufferSurface> surface = | 602 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
603 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 603 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
604 auto* surface_ptr = surface.get(); | 604 auto* surface_ptr = surface.get(); |
605 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 605 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
606 | 606 |
607 NonThrowableExceptionState exception_state; | 607 NonThrowableExceptionState exception_state; |
608 Element* source_canvas_element = | 608 Element* source_canvas_element = |
609 GetDocument().createElement("canvas", exception_state); | 609 GetDocument().createElement("canvas", exception_state); |
610 EXPECT_FALSE(exception_state.HadException()); | 610 EXPECT_FALSE(exception_state.HadException()); |
611 HTMLCanvasElement* source_canvas = | 611 HTMLCanvasElement* source_canvas = |
612 static_cast<HTMLCanvasElement*>(source_canvas_element); | 612 static_cast<HTMLCanvasElement*>(source_canvas_element); |
613 IntSize source_size( | 613 IntSize source_size( |
(...skipping 14 matching lines...) Expand all Loading... |
628 0, 1, 1, exception_state); | 628 0, 1, 1, exception_state); |
629 EXPECT_FALSE(exception_state.HadException()); | 629 EXPECT_FALSE(exception_state.HadException()); |
630 | 630 |
631 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); | 631 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); |
632 EXPECT_TRUE(surface_ptr->IsRecording()); | 632 EXPECT_TRUE(surface_ptr->IsRecording()); |
633 } | 633 } |
634 | 634 |
635 TEST_F(CanvasRenderingContext2DTest, | 635 TEST_F(CanvasRenderingContext2DTest, |
636 NoLayerPromotionUnderExpensivePathPointCount) { | 636 NoLayerPromotionUnderExpensivePathPointCount) { |
637 CreateContext(kNonOpaque); | 637 CreateContext(kNonOpaque); |
638 std::unique_ptr<RecordingImageBufferSurface> surface = | 638 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
639 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 639 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
640 auto* surface_ptr = surface.get(); | 640 auto* surface_ptr = surface.get(); |
641 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 641 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
642 | 642 |
643 Context2d()->beginPath(); | 643 Context2d()->beginPath(); |
644 Context2d()->moveTo(7, 5); | 644 Context2d()->moveTo(7, 5); |
645 for (int i = 1; | 645 for (int i = 1; |
646 i < ExpensiveCanvasHeuristicParameters::kExpensivePathPointCount - 1; | 646 i < ExpensiveCanvasHeuristicParameters::kExpensivePathPointCount - 1; |
647 i++) { | 647 i++) { |
648 float angle_rad = | 648 float angle_rad = |
649 twoPiFloat * i / | 649 twoPiFloat * i / |
650 (ExpensiveCanvasHeuristicParameters::kExpensivePathPointCount - 1); | 650 (ExpensiveCanvasHeuristicParameters::kExpensivePathPointCount - 1); |
651 Context2d()->lineTo(5 + 2 * cos(angle_rad), 5 + 2 * sin(angle_rad)); | 651 Context2d()->lineTo(5 + 2 * cos(angle_rad), 5 + 2 * sin(angle_rad)); |
652 } | 652 } |
653 Context2d()->fill(); | 653 Context2d()->fill(); |
654 | 654 |
655 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); | 655 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); |
656 EXPECT_TRUE(surface_ptr->IsRecording()); | 656 EXPECT_TRUE(surface_ptr->IsRecording()); |
657 } | 657 } |
658 | 658 |
659 TEST_F(CanvasRenderingContext2DTest, | 659 TEST_F(CanvasRenderingContext2DTest, |
660 LayerPromotionOverExpensivePathPointCount) { | 660 LayerPromotionOverExpensivePathPointCount) { |
661 CreateContext(kNonOpaque); | 661 CreateContext(kNonOpaque); |
662 std::unique_ptr<RecordingImageBufferSurface> surface = | 662 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
663 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 663 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
664 auto* surface_ptr = surface.get(); | 664 auto* surface_ptr = surface.get(); |
665 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 665 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
666 | 666 |
667 Context2d()->beginPath(); | 667 Context2d()->beginPath(); |
668 Context2d()->moveTo(7, 5); | 668 Context2d()->moveTo(7, 5); |
669 for (int i = 1; | 669 for (int i = 1; |
670 i < ExpensiveCanvasHeuristicParameters::kExpensivePathPointCount + 1; | 670 i < ExpensiveCanvasHeuristicParameters::kExpensivePathPointCount + 1; |
671 i++) { | 671 i++) { |
672 float angle_rad = | 672 float angle_rad = |
673 twoPiFloat * i / | 673 twoPiFloat * i / |
674 (ExpensiveCanvasHeuristicParameters::kExpensivePathPointCount + 1); | 674 (ExpensiveCanvasHeuristicParameters::kExpensivePathPointCount + 1); |
675 Context2d()->lineTo(5 + 2 * cos(angle_rad), 5 + 2 * sin(angle_rad)); | 675 Context2d()->lineTo(5 + 2 * cos(angle_rad), 5 + 2 * sin(angle_rad)); |
676 } | 676 } |
677 Context2d()->fill(); | 677 Context2d()->fill(); |
678 | 678 |
679 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); | 679 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); |
680 EXPECT_TRUE(surface_ptr->IsRecording()); | 680 EXPECT_TRUE(surface_ptr->IsRecording()); |
681 } | 681 } |
682 | 682 |
683 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWhenPathIsConcave) { | 683 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWhenPathIsConcave) { |
684 CreateContext(kNonOpaque); | 684 CreateContext(kNonOpaque); |
685 std::unique_ptr<RecordingImageBufferSurface> surface = | 685 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
686 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 686 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
687 auto* surface_ptr = surface.get(); | 687 auto* surface_ptr = surface.get(); |
688 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 688 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
689 | 689 |
690 Context2d()->beginPath(); | 690 Context2d()->beginPath(); |
691 Context2d()->moveTo(1, 1); | 691 Context2d()->moveTo(1, 1); |
692 Context2d()->lineTo(5, 5); | 692 Context2d()->lineTo(5, 5); |
693 Context2d()->lineTo(9, 1); | 693 Context2d()->lineTo(9, 1); |
694 Context2d()->lineTo(5, 9); | 694 Context2d()->lineTo(5, 9); |
695 Context2d()->fill(); | 695 Context2d()->fill(); |
696 | 696 |
697 if (ExpensiveCanvasHeuristicParameters::kConcavePathsAreExpensive) { | 697 if (ExpensiveCanvasHeuristicParameters::kConcavePathsAreExpensive) { |
698 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); | 698 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); |
699 } else { | 699 } else { |
700 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); | 700 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); |
701 } | 701 } |
702 EXPECT_TRUE(surface_ptr->IsRecording()); | 702 EXPECT_TRUE(surface_ptr->IsRecording()); |
703 } | 703 } |
704 | 704 |
705 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithRectangleClip) { | 705 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithRectangleClip) { |
706 CreateContext(kNonOpaque); | 706 CreateContext(kNonOpaque); |
707 std::unique_ptr<RecordingImageBufferSurface> surface = | 707 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
708 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 708 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
709 auto* surface_ptr = surface.get(); | 709 auto* surface_ptr = surface.get(); |
710 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 710 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
711 | 711 |
712 Context2d()->beginPath(); | 712 Context2d()->beginPath(); |
713 Context2d()->rect(1, 1, 2, 2); | 713 Context2d()->rect(1, 1, 2, 2); |
714 Context2d()->clip(); | 714 Context2d()->clip(); |
715 Context2d()->fillRect(0, 0, 4, 4); | 715 Context2d()->fillRect(0, 0, 4, 4); |
716 | 716 |
717 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); | 717 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); |
718 EXPECT_TRUE(surface_ptr->IsRecording()); | 718 EXPECT_TRUE(surface_ptr->IsRecording()); |
719 } | 719 } |
720 | 720 |
721 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithComplexClip) { | 721 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithComplexClip) { |
722 CreateContext(kNonOpaque); | 722 CreateContext(kNonOpaque); |
723 std::unique_ptr<RecordingImageBufferSurface> surface = | 723 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
724 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 724 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
725 auto* surface_ptr = surface.get(); | 725 auto* surface_ptr = surface.get(); |
726 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 726 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
727 | 727 |
728 Context2d()->beginPath(); | 728 Context2d()->beginPath(); |
729 Context2d()->moveTo(1, 1); | 729 Context2d()->moveTo(1, 1); |
730 Context2d()->lineTo(5, 5); | 730 Context2d()->lineTo(5, 5); |
731 Context2d()->lineTo(9, 1); | 731 Context2d()->lineTo(9, 1); |
732 Context2d()->lineTo(5, 9); | 732 Context2d()->lineTo(5, 9); |
733 Context2d()->clip(); | 733 Context2d()->clip(); |
734 Context2d()->fillRect(0, 0, 4, 4); | 734 Context2d()->fillRect(0, 0, 4, 4); |
735 | 735 |
736 if (ExpensiveCanvasHeuristicParameters::kComplexClipsAreExpensive) { | 736 if (ExpensiveCanvasHeuristicParameters::kComplexClipsAreExpensive) { |
737 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); | 737 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); |
738 } else { | 738 } else { |
739 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); | 739 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); |
740 } | 740 } |
741 EXPECT_TRUE(surface_ptr->IsRecording()); | 741 EXPECT_TRUE(surface_ptr->IsRecording()); |
742 } | 742 } |
743 | 743 |
744 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithBlurredShadow) { | 744 TEST_F(CanvasRenderingContext2DTest, LayerPromotionWithBlurredShadow) { |
745 CreateContext(kNonOpaque); | 745 CreateContext(kNonOpaque); |
746 std::unique_ptr<RecordingImageBufferSurface> surface = | 746 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
747 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 747 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
748 auto* surface_ptr = surface.get(); | 748 auto* surface_ptr = surface.get(); |
749 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 749 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
750 | 750 |
751 Context2d()->setShadowColor(String("red")); | 751 Context2d()->setShadowColor(String("red")); |
752 Context2d()->setShadowBlur(1.0f); | 752 Context2d()->setShadowBlur(1.0f); |
753 Context2d()->fillRect(1, 1, 1, 1); | 753 Context2d()->fillRect(1, 1, 1, 1); |
754 | 754 |
755 if (ExpensiveCanvasHeuristicParameters::kBlurredShadowsAreExpensive) { | 755 if (ExpensiveCanvasHeuristicParameters::kBlurredShadowsAreExpensive) { |
756 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); | 756 EXPECT_TRUE(CanvasElement().ShouldBeDirectComposited()); |
757 } else { | 757 } else { |
758 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); | 758 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); |
759 } | 759 } |
760 EXPECT_TRUE(surface_ptr->IsRecording()); | 760 EXPECT_TRUE(surface_ptr->IsRecording()); |
761 } | 761 } |
762 | 762 |
763 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithSharpShadow) { | 763 TEST_F(CanvasRenderingContext2DTest, NoLayerPromotionWithSharpShadow) { |
764 CreateContext(kNonOpaque); | 764 CreateContext(kNonOpaque); |
765 std::unique_ptr<RecordingImageBufferSurface> surface = | 765 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
766 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 766 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
767 auto* surface_ptr = surface.get(); | 767 auto* surface_ptr = surface.get(); |
768 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 768 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
769 | 769 |
770 Context2d()->setShadowColor(String("red")); | 770 Context2d()->setShadowColor(String("red")); |
771 Context2d()->setShadowOffsetX(1.0f); | 771 Context2d()->setShadowOffsetX(1.0f); |
772 Context2d()->fillRect(1, 1, 1, 1); | 772 Context2d()->fillRect(1, 1, 1, 1); |
773 | 773 |
774 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); | 774 EXPECT_FALSE(CanvasElement().ShouldBeDirectComposited()); |
775 EXPECT_TRUE(surface_ptr->IsRecording()); | 775 EXPECT_TRUE(surface_ptr->IsRecording()); |
776 } | 776 } |
777 | 777 |
778 TEST_F(CanvasRenderingContext2DTest, NoFallbackWithSmallState) { | 778 TEST_F(CanvasRenderingContext2DTest, NoFallbackWithSmallState) { |
779 CreateContext(kNonOpaque); | 779 CreateContext(kNonOpaque); |
780 std::unique_ptr<RecordingImageBufferSurface> surface = | 780 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
781 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 781 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
782 auto* surface_ptr = surface.get(); | 782 auto* surface_ptr = surface.get(); |
783 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 783 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
784 | 784 |
785 Context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect. | 785 Context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect. |
786 for (int i = 0; | 786 for (int i = 0; |
787 i < | 787 i < |
788 ExpensiveCanvasHeuristicParameters::kExpensiveRecordingStackDepth - 1; | 788 ExpensiveCanvasHeuristicParameters::kExpensiveRecordingStackDepth - 1; |
789 ++i) { | 789 ++i) { |
790 Context2d()->save(); | 790 Context2d()->save(); |
791 Context2d()->translate(1.0f, 0.0f); | 791 Context2d()->translate(1.0f, 0.0f); |
792 } | 792 } |
793 CanvasElement().FinalizeFrame(); // To close the current frame. | 793 CanvasElement().FinalizeFrame(); // To close the current frame. |
794 | 794 |
795 EXPECT_TRUE(surface_ptr->IsRecording()); | 795 EXPECT_TRUE(surface_ptr->IsRecording()); |
796 } | 796 } |
797 | 797 |
798 TEST_F(CanvasRenderingContext2DTest, FallbackWithLargeState) { | 798 TEST_F(CanvasRenderingContext2DTest, FallbackWithLargeState) { |
799 CreateContext(kNonOpaque); | 799 CreateContext(kNonOpaque); |
800 std::unique_ptr<RecordingImageBufferSurface> surface = | 800 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
801 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 801 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
802 auto* surface_ptr = surface.get(); | 802 auto* surface_ptr = surface.get(); |
803 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 803 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
804 | 804 |
805 Context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect. | 805 Context2d()->fillRect(0, 0, 1, 1); // To have a non-empty dirty rect. |
806 for (int i = 0; | 806 for (int i = 0; |
807 i < ExpensiveCanvasHeuristicParameters::kExpensiveRecordingStackDepth; | 807 i < ExpensiveCanvasHeuristicParameters::kExpensiveRecordingStackDepth; |
808 ++i) { | 808 ++i) { |
809 Context2d()->save(); | 809 Context2d()->save(); |
810 Context2d()->translate(1.0f, 0.0f); | 810 Context2d()->translate(1.0f, 0.0f); |
811 } | 811 } |
812 CanvasElement().FinalizeFrame(); // To close the current frame. | 812 CanvasElement().FinalizeFrame(); // To close the current frame. |
813 | 813 |
814 EXPECT_FALSE(surface_ptr->IsRecording()); | 814 EXPECT_FALSE(surface_ptr->IsRecording()); |
815 } | 815 } |
816 | 816 |
817 TEST_F(CanvasRenderingContext2DTest, OpaqueDisplayListFallsBackForText) { | 817 TEST_F(CanvasRenderingContext2DTest, OpaqueDisplayListFallsBackForText) { |
818 // Verify that drawing text to an opaque canvas, which is expected to | 818 // Verify that drawing text to an opaque canvas, which is expected to |
819 // render with subpixel text anti-aliasing, results in falling out | 819 // render with subpixel text anti-aliasing, results in falling out |
820 // of display list mode because the current diplay list implementation | 820 // of display list mode because the current diplay list implementation |
821 // does not support pixel geometry settings. | 821 // does not support pixel geometry settings. |
822 // See: crbug.com/583809 | 822 // See: crbug.com/583809 |
823 CreateContext(kOpaque); | 823 CreateContext(kOpaque); |
824 auto surface = | 824 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
825 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kOpaque); | 825 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kOpaque); |
826 auto* surface_ptr = surface.get(); | 826 auto* surface_ptr = surface.get(); |
827 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 827 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
828 | 828 |
829 Context2d()->fillText("Text", 0, 5); | 829 Context2d()->fillText("Text", 0, 5); |
830 | 830 |
831 EXPECT_FALSE(surface_ptr->IsRecording()); | 831 EXPECT_FALSE(surface_ptr->IsRecording()); |
832 } | 832 } |
833 | 833 |
834 TEST_F(CanvasRenderingContext2DTest, | 834 TEST_F(CanvasRenderingContext2DTest, |
835 NonOpaqueDisplayListDoesNotFallBackForText) { | 835 NonOpaqueDisplayListDoesNotFallBackForText) { |
836 CreateContext(kNonOpaque); | 836 CreateContext(kNonOpaque); |
837 std::unique_ptr<RecordingImageBufferSurface> surface = | 837 auto surface = WTF::MakeUnique<RecordingImageBufferSurface>( |
838 WTF::MakeUnique<RecordingImageBufferSurface>(IntSize(10, 10), kNonOpaque); | 838 IntSize(10, 10), RecordingImageBufferSurface::kAllowFallback, kNonOpaque); |
839 auto* surface_ptr = surface.get(); | 839 auto* surface_ptr = surface.get(); |
840 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); | 840 CanvasElement().CreateImageBufferUsingSurfaceForTesting(std::move(surface)); |
841 | 841 |
842 Context2d()->fillText("Text", 0, 5); | 842 Context2d()->fillText("Text", 0, 5); |
843 | 843 |
844 EXPECT_TRUE(surface_ptr->IsRecording()); | 844 EXPECT_TRUE(surface_ptr->IsRecording()); |
845 } | 845 } |
846 | 846 |
847 TEST_F(CanvasRenderingContext2DTest, ImageResourceLifetime) { | 847 TEST_F(CanvasRenderingContext2DTest, ImageResourceLifetime) { |
848 NonThrowableExceptionState non_throwable_exception_state; | 848 NonThrowableExceptionState non_throwable_exception_state; |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 | 1412 |
1413 // Wake up again, which should request a compositing update synchronously. | 1413 // Wake up again, which should request a compositing update synchronously. |
1414 GetDocument().GetPage()->SetVisibilityState(kPageVisibilityStateVisible, | 1414 GetDocument().GetPage()->SetVisibilityState(kPageVisibilityStateVisible, |
1415 false); | 1415 false); |
1416 EXPECT_EQ(!!CANVAS2D_HIBERNATION_ENABLED, | 1416 EXPECT_EQ(!!CANVAS2D_HIBERNATION_ENABLED, |
1417 layer->NeedsCompositingInputsUpdate()); | 1417 layer->NeedsCompositingInputsUpdate()); |
1418 RunUntilIdle(); // Clear task queue. | 1418 RunUntilIdle(); // Clear task queue. |
1419 } | 1419 } |
1420 | 1420 |
1421 } // namespace blink | 1421 } // namespace blink |
OLD | NEW |