This repository has been archived by the owner on Feb 14, 2025. It is now read-only.
forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathview_slicer_unittests.cc
138 lines (103 loc) · 4.42 KB
/
view_slicer_unittests.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <unordered_map>
#include "display_list/dl_builder.h"
#include "flow/embedded_views.h"
#include "flutter/flow/view_slicer.h"
#include "gtest/gtest.h"
namespace flutter {
namespace testing {
namespace {
void AddSliceOfSize(
std::unordered_map<int64_t, std::unique_ptr<EmbedderViewSlice>>& slices,
int64_t id,
SkRect rect) {
slices[id] = std::make_unique<DisplayListEmbedderViewSlice>(rect);
DlPaint paint;
paint.setColor(DlColor::kBlack());
slices[id]->canvas()->DrawRect(rect, paint);
}
} // namespace
TEST(ViewSlicerTest, CanSlicerNonOverlappingViews) {
DisplayListBuilder builder(SkRect::MakeLTRB(0, 0, 100, 100));
std::vector<int64_t> composition_order = {1};
std::unordered_map<int64_t, std::unique_ptr<EmbedderViewSlice>> slices;
AddSliceOfSize(slices, 1, SkRect::MakeLTRB(99, 99, 100, 100));
std::unordered_map<int64_t, SkRect> view_rects = {
{1, SkRect::MakeLTRB(50, 50, 60, 60)}};
auto computed_overlays =
SliceViews(&builder, composition_order, slices, view_rects);
EXPECT_TRUE(computed_overlays.empty());
}
TEST(ViewSlicerTest, IgnoresFractionalOverlaps) {
DisplayListBuilder builder(SkRect::MakeLTRB(0, 0, 100, 100));
std::vector<int64_t> composition_order = {1};
std::unordered_map<int64_t, std::unique_ptr<EmbedderViewSlice>> slices;
AddSliceOfSize(slices, 1, SkRect::MakeLTRB(0, 0, 50.49, 50.49));
std::unordered_map<int64_t, SkRect> view_rects = {
{1, SkRect::MakeLTRB(50.5, 50.5, 100, 100)}};
auto computed_overlays =
SliceViews(&builder, composition_order, slices, view_rects);
EXPECT_TRUE(computed_overlays.empty());
}
TEST(ViewSlicerTest, ComputesOverlapWith1PV) {
DisplayListBuilder builder(SkRect::MakeLTRB(0, 0, 100, 100));
std::vector<int64_t> composition_order = {1};
std::unordered_map<int64_t, std::unique_ptr<EmbedderViewSlice>> slices;
AddSliceOfSize(slices, 1, SkRect::MakeLTRB(0, 0, 50, 50));
std::unordered_map<int64_t, SkRect> view_rects = {
{1, SkRect::MakeLTRB(0, 0, 100, 100)}};
auto computed_overlays =
SliceViews(&builder, composition_order, slices, view_rects);
EXPECT_EQ(computed_overlays.size(), 1u);
auto overlay = computed_overlays.find(1);
ASSERT_NE(overlay, computed_overlays.end());
EXPECT_EQ(overlay->second, SkRect::MakeLTRB(0, 0, 50, 50));
}
TEST(ViewSlicerTest, ComputesOverlapWith2PV) {
DisplayListBuilder builder(SkRect::MakeLTRB(0, 0, 100, 100));
std::vector<int64_t> composition_order = {1, 2};
std::unordered_map<int64_t, std::unique_ptr<EmbedderViewSlice>> slices;
AddSliceOfSize(slices, 1, SkRect::MakeLTRB(0, 0, 50, 50));
AddSliceOfSize(slices, 2, SkRect::MakeLTRB(50, 50, 100, 100));
std::unordered_map<int64_t, SkRect> view_rects = {
{1, SkRect::MakeLTRB(0, 0, 50, 50)}, //
{2, SkRect::MakeLTRB(50, 50, 100, 100)}, //
};
auto computed_overlays =
SliceViews(&builder, composition_order, slices, view_rects);
EXPECT_EQ(computed_overlays.size(), 2u);
auto overlay = computed_overlays.find(1);
ASSERT_NE(overlay, computed_overlays.end());
EXPECT_EQ(overlay->second, SkRect::MakeLTRB(0, 0, 50, 50));
overlay = computed_overlays.find(2);
ASSERT_NE(overlay, computed_overlays.end());
EXPECT_EQ(overlay->second, SkRect::MakeLTRB(50, 50, 100, 100));
}
TEST(ViewSlicerTest, OverlappingTwoPVs) {
DisplayListBuilder builder(SkRect::MakeLTRB(0, 0, 100, 100));
std::vector<int64_t> composition_order = {1, 2};
std::unordered_map<int64_t, std::unique_ptr<EmbedderViewSlice>> slices;
// This embeded view overlaps both platform views:
//
// [ A [ ]]
// [_____[ C ]]
// [ B [ ]]
// [ ]
AddSliceOfSize(slices, 1, SkRect::MakeLTRB(0, 0, 0, 0));
AddSliceOfSize(slices, 2, SkRect::MakeLTRB(0, 0, 100, 100));
std::unordered_map<int64_t, SkRect> view_rects = {
{1, SkRect::MakeLTRB(0, 0, 50, 50)}, //
{2, SkRect::MakeLTRB(50, 50, 100, 100)}, //
};
auto computed_overlays =
SliceViews(&builder, composition_order, slices, view_rects);
EXPECT_EQ(computed_overlays.size(), 1u);
auto overlay = computed_overlays.find(2);
ASSERT_NE(overlay, computed_overlays.end());
// We create a single overlay for both overlapping sections.
EXPECT_EQ(overlay->second, SkRect::MakeLTRB(0, 0, 100, 100));
}
} // namespace testing
} // namespace flutter