5#include "flutter/display_list/geometry/dl_region.h"
6#include "gtest/gtest.h"
15TEST(DisplayListRegion, EmptyRegion) {
21TEST(DisplayListRegion, SingleRectangle) {
23 auto rects =
region.getRects();
24 ASSERT_EQ(rects.size(), 1u);
28TEST(DisplayListRegion, NonOverlappingRectangles1) {
29 std::vector<SkIRect> rects_in;
30 for (
int i = 0;
i < 10; ++
i) {
32 rects_in.push_back(
rect);
35 auto rects =
region.getRects();
36 std::vector<SkIRect> expected{
37 {0, 0, 50, 50}, {50, 50, 100, 100}, {100, 100, 150, 150},
38 {150, 150, 200, 200}, {200, 200, 250, 250}, {250, 250, 300, 300},
39 {300, 300, 350, 350}, {350, 350, 400, 400}, {400, 400, 450, 450},
42 EXPECT_EQ(rects, expected);
45TEST(DisplayListRegion, NonOverlappingRectangles2) {
52 auto rects =
region.getRects();
53 std::vector<SkIRect> expected{
59 EXPECT_EQ(rects, expected);
62TEST(DisplayListRegion, NonOverlappingRectangles3) {
74 auto rects =
region.getRects();
75 std::vector<SkIRect> expected{
86 EXPECT_EQ(rects, expected);
89TEST(DisplayListRegion, MergeTouchingRectangles) {
102 auto rects =
region.getRects();
103 std::vector<SkIRect> expected{
106 EXPECT_EQ(rects, expected);
109TEST(DisplayListRegion, OverlappingRectangles) {
110 std::vector<SkIRect> rects_in;
111 for (
int i = 0;
i < 10; ++
i) {
113 rects_in.push_back(
rect);
116 auto rects =
region.getRects();
117 std::vector<SkIRect> expected{
118 {0, 0, 50, 10}, {0, 10, 60, 20}, {0, 20, 70, 30},
119 {0, 30, 80, 40}, {0, 40, 90, 50}, {10, 50, 100, 60},
120 {20, 60, 110, 70}, {30, 70, 120, 80}, {40, 80, 130, 90},
121 {50, 90, 140, 100}, {60, 100, 140, 110}, {70, 110, 140, 120},
122 {80, 120, 140, 130}, {90, 130, 140, 140},
125 EXPECT_EQ(rects, expected);
128TEST(DisplayListRegion, Deband) {
135 auto rects_with_deband =
region.getRects(
true);
136 std::vector<SkIRect> expected{
141 EXPECT_EQ(rects_with_deband, expected);
143 auto rects_without_deband =
region.getRects(
false);
144 std::vector<SkIRect> expected_without_deband{
151 EXPECT_EQ(rects_without_deband, expected_without_deband);
154TEST(DisplayListRegion, Intersects1) {
163 EXPECT_FALSE(region1.intersects(region2));
164 EXPECT_FALSE(region2.intersects(region1));
174 EXPECT_FALSE(region1.intersects(
184TEST(DisplayListRegion, Intersects2) {
197TEST(DisplayListRegion, Intersection1) {
209 auto rects =
i.getRects();
213TEST(DisplayListRegion, Intersection2) {
224 auto rects =
i.getRects();
225 std::vector<SkIRect> expected{
229 EXPECT_EQ(rects, expected);
232TEST(DisplayListRegion, Intersection3) {
242 auto rects =
i.getRects();
243 std::vector<SkIRect> expected{
247 EXPECT_EQ(rects, expected);
250TEST(DisplayListRegion, Union1) {
262 auto rects = u.getRects();
263 std::vector<SkIRect> expected{
266 EXPECT_EQ(rects, expected);
269TEST(DisplayListRegion, Union2) {
280 auto rects = u.getRects();
281 std::vector<SkIRect> expected{
287 EXPECT_EQ(rects, expected);
290TEST(DisplayListRegion, Union3) {
299 auto rects = u.getRects();
300 std::vector<SkIRect> expected{
305 EXPECT_EQ(rects, expected);
308TEST(DisplayListRegion, UnionEmpty) {
310 DlRegion region1(std::vector<SkIRect>{});
311 DlRegion region2(std::vector<SkIRect>{});
315 auto rects = u.getRects();
319 DlRegion region1(std::vector<SkIRect>{});
325 auto rects = u.getRects();
326 std::vector<SkIRect> expected{
334 DlRegion region2(std::vector<SkIRect>{});
337 auto rects = u.getRects();
338 std::vector<SkIRect> expected{
348 auto rects = dl_region.
getRects(
false);
350 std::vector<SkIRect> skia_rects;
353 while (!iterator.done()) {
354 skia_rects.push_back(iterator.rect());
358 EXPECT_EQ(rects, skia_rects);
361TEST(DisplayListRegion, TestAgainstSkRegion) {
365 std::vector<Settings> all_settings{{100}, {400}, {800}};
367 std::vector<size_t> iterations{1, 10, 100, 1000};
369 for (
const auto&
settings : all_settings) {
370 for (
const auto iterations_1 : iterations) {
371 for (
const auto iterations_2 : iterations) {
372 std::random_device
d;
373 std::seed_seq seed{::testing::UnitTest::GetInstance()->random_seed()};
374 std::mt19937 rng(seed);
379 std::uniform_int_distribution
pos(0, 4000);
380 std::uniform_int_distribution
size(1,
settings.max_size);
382 std::vector<SkIRect> rects_in1;
383 std::vector<SkIRect> rects_in2;
385 for (
size_t i = 0;
i < iterations_1; ++
i) {
388 rects_in1.push_back(
rect);
391 for (
size_t i = 0;
i < iterations_2; ++
i) {
394 rects_in2.push_back(
rect);
398 sk_region1.
setRects(rects_in1.data(), rects_in1.size());
402 sk_region2.
setRects(rects_in2.data(), rects_in2.size());
405 auto intersects_1 = region1.
intersects(region2);
406 auto intersects_2 = region2.
intersects(region1);
407 auto sk_intesects = sk_region1.
intersects(sk_region2);
408 EXPECT_EQ(intersects_1, intersects_2);
409 EXPECT_EQ(intersects_1, sk_intesects);
412 auto rects = region2.
getRects(
true);
413 for (
const auto& r : rects) {
424 SkRegion sk_intersection(sk_region1);
@ kUnion_Op
target unioned with operand
@ kIntersect_Op
target intersected with operand
bool setRects(const SkIRect rects[], int count)
const SkIRect & getBounds() const
bool op(const SkIRect &rect, Op op)
bool intersects(const SkIRect &rect) const
static DlRegion MakeIntersection(const DlRegion &a, const DlRegion &b)
const SkIRect & bounds() const
std::vector< SkIRect > getRects(bool deband=true) const
bool intersects(const SkIRect &rect) const
Returns whether this region intersects with a rectangle.
static DlRegion MakeUnion(const DlRegion &a, const DlRegion &b)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
ClipOpAndAA opAA SkRegion region
sk_sp< SkBlender > blender SkRect rect
void CheckEquality(const DlRegion &dl_region, const SkRegion &sk_region)
TEST(DisplayListComplexity, EmptyDisplayList)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
static constexpr SkIRect MakeEmpty()
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
#define EXPECT_TRUE(handle)