|
22 | 22 | #include "flutter/testing/testing.h"
|
23 | 23 |
|
24 | 24 | #include "third_party/skia/include/core/SkPictureRecorder.h"
|
| 25 | +#include "third_party/skia/include/core/SkRSXform.h" |
25 | 26 | #include "third_party/skia/include/core/SkSurface.h"
|
26 | 27 |
|
27 | 28 | namespace flutter {
|
@@ -2636,5 +2637,164 @@ TEST_F(DisplayListTest, DrawSaveDrawCannotInheritOpacity) {
|
2636 | 2637 | ASSERT_FALSE(display_list->can_apply_group_opacity());
|
2637 | 2638 | }
|
2638 | 2639 |
|
| 2640 | +TEST_F(DisplayListTest, NopOperationsOmittedFromRecords) { |
| 2641 | + auto run_tests = [](const std::string& name, |
| 2642 | + void init(DisplayListBuilder & builder, DlPaint & paint), |
| 2643 | + uint32_t expected_op_count = 0u) { |
| 2644 | + auto run_one_test = |
| 2645 | + [init](const std::string& name, |
| 2646 | + void build(DisplayListBuilder & builder, DlPaint & paint), |
| 2647 | + uint32_t expected_op_count = 0u) { |
| 2648 | + DisplayListBuilder builder; |
| 2649 | + DlPaint paint; |
| 2650 | + init(builder, paint); |
| 2651 | + build(builder, paint); |
| 2652 | + auto list = builder.Build(); |
| 2653 | + if (list->op_count() != expected_op_count) { |
| 2654 | + FML_LOG(ERROR) << *list; |
| 2655 | + } |
| 2656 | + ASSERT_EQ(list->op_count(), expected_op_count) << name; |
| 2657 | + ASSERT_TRUE(list->bounds().isEmpty()) << name; |
| 2658 | + }; |
| 2659 | + run_one_test( |
| 2660 | + name + " DrawColor", |
| 2661 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2662 | + builder.DrawColor(paint.getColor(), paint.getBlendMode()); |
| 2663 | + }, |
| 2664 | + expected_op_count); |
| 2665 | + run_one_test( |
| 2666 | + name + " DrawPaint", |
| 2667 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2668 | + builder.DrawPaint(paint); |
| 2669 | + }, |
| 2670 | + expected_op_count); |
| 2671 | + run_one_test( |
| 2672 | + name + " DrawRect", |
| 2673 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2674 | + builder.DrawRect({10, 10, 20, 20}, paint); |
| 2675 | + }, |
| 2676 | + expected_op_count); |
| 2677 | + run_one_test( |
| 2678 | + name + " Other Draw Ops", |
| 2679 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2680 | + builder.DrawLine({10, 10}, {20, 20}, paint); |
| 2681 | + builder.DrawOval({10, 10, 20, 20}, paint); |
| 2682 | + builder.DrawCircle({50, 50}, 20, paint); |
| 2683 | + builder.DrawRRect(SkRRect::MakeRectXY({10, 10, 20, 20}, 5, 5), paint); |
| 2684 | + builder.DrawDRRect(SkRRect::MakeRectXY({5, 5, 100, 100}, 5, 5), |
| 2685 | + SkRRect::MakeRectXY({10, 10, 20, 20}, 5, 5), |
| 2686 | + paint); |
| 2687 | + builder.DrawPath(kTestPath1, paint); |
| 2688 | + builder.DrawArc({10, 10, 20, 20}, 45, 90, true, paint); |
| 2689 | + SkPoint pts[] = {{10, 10}, {20, 20}}; |
| 2690 | + builder.DrawPoints(PointMode::kLines, 2, pts, paint); |
| 2691 | + builder.DrawVertices(TestVertices1, DlBlendMode::kSrcOver, paint); |
| 2692 | + builder.DrawImage(TestImage1, {10, 10}, DlImageSampling::kLinear, |
| 2693 | + &paint); |
| 2694 | + builder.DrawImageRect(TestImage1, SkRect{0.0f, 0.0f, 10.0f, 10.0f}, |
| 2695 | + SkRect{10.0f, 10.0f, 25.0f, 25.0f}, |
| 2696 | + DlImageSampling::kLinear, &paint); |
| 2697 | + builder.DrawImageNine(TestImage1, {10, 10, 20, 20}, |
| 2698 | + {10, 10, 100, 100}, DlFilterMode::kLinear, |
| 2699 | + &paint); |
| 2700 | + SkRSXform xforms[] = {{1, 0, 10, 10}, {0, 1, 10, 10}}; |
| 2701 | + SkRect rects[] = {{10, 10, 20, 20}, {10, 20, 30, 20}}; |
| 2702 | + builder.DrawAtlas(TestImage1, xforms, rects, nullptr, 2, |
| 2703 | + DlBlendMode::kSrcOver, DlImageSampling::kLinear, |
| 2704 | + nullptr, &paint); |
| 2705 | + builder.DrawTextBlob(TestBlob1, 10, 10, paint); |
| 2706 | + |
| 2707 | + // Dst mode eliminates most rendering ops except for |
| 2708 | + // the following two, so we'll prune those manually... |
| 2709 | + if (paint.getBlendMode() != DlBlendMode::kDst) { |
| 2710 | + builder.DrawDisplayList(TestDisplayList1, paint.getOpacity()); |
| 2711 | + builder.DrawShadow(kTestPath1, paint.getColor(), 1, true, 1); |
| 2712 | + } |
| 2713 | + }, |
| 2714 | + expected_op_count); |
| 2715 | + run_one_test( |
| 2716 | + name + " SaveLayer", |
| 2717 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2718 | + builder.SaveLayer(nullptr, &paint, nullptr); |
| 2719 | + builder.DrawRect({10, 10, 20, 20}, DlPaint()); |
| 2720 | + builder.Restore(); |
| 2721 | + }, |
| 2722 | + expected_op_count); |
| 2723 | + run_one_test( |
| 2724 | + name + " inside Save", |
| 2725 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2726 | + builder.Save(); |
| 2727 | + builder.DrawRect({10, 10, 20, 20}, paint); |
| 2728 | + builder.Restore(); |
| 2729 | + }, |
| 2730 | + expected_op_count); |
| 2731 | + }; |
| 2732 | + run_tests("transparent color", // |
| 2733 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2734 | + paint.setColor(DlColor::kTransparent()); |
| 2735 | + }); |
| 2736 | + run_tests("0 alpha", // |
| 2737 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2738 | + // The transparent test above already tested transparent |
| 2739 | + // black (all 0s), we set White color here so we can test |
| 2740 | + // the case of all 1s with a 0 alpha |
| 2741 | + paint.setColor(DlColor::kWhite()); |
| 2742 | + paint.setAlpha(0); |
| 2743 | + }); |
| 2744 | + run_tests("BlendMode::kDst", // |
| 2745 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2746 | + paint.setBlendMode(DlBlendMode::kDst); |
| 2747 | + }); |
| 2748 | + run_tests("Empty rect clip", // |
| 2749 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2750 | + builder.ClipRect(SkRect::MakeEmpty(), ClipOp::kIntersect, false); |
| 2751 | + }); |
| 2752 | + run_tests("Empty rrect clip", // |
| 2753 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2754 | + builder.ClipRRect(SkRRect::MakeEmpty(), ClipOp::kIntersect, |
| 2755 | + false); |
| 2756 | + }); |
| 2757 | + run_tests("Empty path clip", // |
| 2758 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2759 | + builder.ClipPath(SkPath(), ClipOp::kIntersect, false); |
| 2760 | + }); |
| 2761 | + run_tests("Transparent SaveLayer", // |
| 2762 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2763 | + DlPaint save_paint; |
| 2764 | + save_paint.setColor(DlColor::kTransparent()); |
| 2765 | + builder.SaveLayer(nullptr, &save_paint); |
| 2766 | + }); |
| 2767 | + run_tests("0 alpha SaveLayer", // |
| 2768 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2769 | + DlPaint save_paint; |
| 2770 | + // The transparent test above already tested transparent |
| 2771 | + // black (all 0s), we set White color here so we can test |
| 2772 | + // the case of all 1s with a 0 alpha |
| 2773 | + save_paint.setColor(DlColor::kWhite()); |
| 2774 | + save_paint.setAlpha(0); |
| 2775 | + builder.SaveLayer(nullptr, &save_paint); |
| 2776 | + }); |
| 2777 | + run_tests("Dst blended SaveLayer", // |
| 2778 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2779 | + DlPaint save_paint; |
| 2780 | + save_paint.setBlendMode(DlBlendMode::kDst); |
| 2781 | + builder.SaveLayer(nullptr, &save_paint); |
| 2782 | + }); |
| 2783 | + run_tests( |
| 2784 | + "Nop inside SaveLayer", |
| 2785 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2786 | + builder.SaveLayer(nullptr, nullptr); |
| 2787 | + paint.setBlendMode(DlBlendMode::kDst); |
| 2788 | + }, |
| 2789 | + 2u); |
| 2790 | + run_tests("DrawImage inside Culled SaveLayer", // |
| 2791 | + [](DisplayListBuilder& builder, DlPaint& paint) { |
| 2792 | + DlPaint save_paint; |
| 2793 | + save_paint.setColor(DlColor::kTransparent()); |
| 2794 | + builder.SaveLayer(nullptr, &save_paint); |
| 2795 | + builder.DrawImage(TestImage1, {10, 10}, DlImageSampling::kLinear); |
| 2796 | + }); |
| 2797 | +} |
| 2798 | + |
2639 | 2799 | } // namespace testing
|
2640 | 2800 | } // namespace flutter
|
0 commit comments