66 */
77
88#include " flutter/testing/testing.h"
9- #include " flutter/testing/thread_test.h"
10- #include " skia/platform_view_rtree.h"
9+ #include " platform_view_rtree.h"
1110
1211#include " third_party/skia/include/core/SkCanvas.h"
1312#include " third_party/skia/include/core/SkPictureRecorder.h"
1413
1514namespace flutter {
1615namespace testing {
1716
18- TEST_F (PlatformViewRTree, NoIntersection) {
19- auto r_tree = sk_make_sp<FlutterRTree >();
20- auto rtree_factory = FlutterRTreeFactory (r_tree);
17+ TEST (PlatformViewRTree, NoIntersection) {
18+ auto r_tree = sk_make_sp<PlatformViewRTree >();
19+ auto rtree_factory = PlatformViewRTreeFactory (r_tree);
2120 auto recorder = std::make_unique<SkPictureRecorder>();
2221 auto recording_canvas = recorder->beginRecording (SkRect::MakeIWH (1000 , 1000 ), &rtree_factory);
2322
@@ -36,9 +35,9 @@ TEST_F(PlatformViewRTree, NoIntersection) {
3635 ASSERT_TRUE (hits.empty ());
3736}
3837
39- TEST_F (PlatformViewRTree, Intersection ) {
40- auto r_tree = sk_make_sp<FlutterRTree >();
41- auto rtree_factory = FlutterRTreeFactory (r_tree);
38+ TEST (PlatformViewRTree, SingleRectIntersection ) {
39+ auto r_tree = sk_make_sp<PlatformViewRTree >();
40+ auto rtree_factory = PlatformViewRTreeFactory (r_tree);
4241 auto recorder = std::make_unique<SkPictureRecorder>();
4342 auto recording_canvas = recorder->beginRecording (SkRect::MakeIWH (1000 , 1000 ), &rtree_factory);
4443
@@ -60,9 +59,71 @@ TEST_F(PlatformViewRTree, Intersection) {
6059 ASSERT_EQ (*hits[0 ], SkRect::MakeLTRB (120 , 120 , 160 , 160 ));
6160}
6261
63- TEST_F (PlatformViewRTree, JoinRectsWhenIntersectedCase1) {
64- auto r_tree = sk_make_sp<FlutterRTree>();
65- auto rtree_factory = FlutterRTreeFactory (r_tree);
62+ TEST (PlatformViewRTree, IgnoresNonDrawingRecords) {
63+ auto r_tree = sk_make_sp<PlatformViewRTree>();
64+ auto rtree_factory = PlatformViewRTreeFactory (r_tree);
65+ auto recorder = std::make_unique<SkPictureRecorder>();
66+ auto recording_canvas = recorder->beginRecording (SkRect::MakeIWH (1000 , 1000 ), &rtree_factory);
67+
68+ auto rect_paint = SkPaint ();
69+ rect_paint.setColor (SkColors::kCyan );
70+ rect_paint.setStyle (SkPaint::Style::kFill_Style );
71+
72+ // Creates two non drawing records.
73+ recording_canvas->translate (100 , 100 );
74+ // The result vector should only contain the clipping rect.
75+ recording_canvas->clipRect (SkRect::MakeLTRB (40 , 40 , 50 , 50 ), SkClipOp::kIntersect );
76+ recording_canvas->drawRect (SkRect::MakeLTRB (20 , 20 , 80 , 80 ), rect_paint);
77+
78+ recorder->finishRecordingAsPicture ();
79+
80+ // The rtree has a translate, a clip and a rect record.
81+ ASSERT_EQ (3 , r_tree->getCount ());
82+
83+ auto query = SkRect::MakeLTRB (0 , 0 , 1000 , 1000 );
84+ auto hits = std::vector<SkRect*>();
85+
86+ r_tree->searchRects (query, &hits);
87+ ASSERT_EQ (1UL , hits.size ());
88+ ASSERT_EQ (*hits[0 ], SkRect::MakeLTRB (120 , 120 , 180 , 180 ));
89+ }
90+
91+ TEST (PlatformViewRTree, MultipleRectIntersection) {
92+ auto r_tree = sk_make_sp<PlatformViewRTree>();
93+ auto rtree_factory = PlatformViewRTreeFactory (r_tree);
94+ auto recorder = std::make_unique<SkPictureRecorder>();
95+ auto recording_canvas = recorder->beginRecording (SkRect::MakeIWH (1000 , 1000 ), &rtree_factory);
96+
97+ auto rect_paint = SkPaint ();
98+ rect_paint.setColor (SkColors::kCyan );
99+ rect_paint.setStyle (SkPaint::Style::kFill_Style );
100+
101+ // Given the A, B that intersect with the query rect,
102+ // there should be A and B in the result vector since
103+ // they don't intersect with each other.
104+ //
105+ // +-----+ +-----+
106+ // | A | | B |
107+ // +-----+ +-----+
108+ // A
109+ recording_canvas->drawRect (SkRect::MakeLTRB (100 , 100 , 200 , 200 ), rect_paint);
110+ // B
111+ recording_canvas->drawRect (SkRect::MakeLTRB (300 , 100 , 400 , 200 ), rect_paint);
112+
113+ recorder->finishRecordingAsPicture ();
114+
115+ auto query = SkRect::MakeLTRB (0 , 0 , 1000 , 1050 );
116+ auto hits = std::vector<SkRect*>();
117+
118+ r_tree->searchRects (query, &hits);
119+ ASSERT_EQ (2UL , hits.size ());
120+ ASSERT_EQ (*hits[0 ], SkRect::MakeLTRB (100 , 100 , 200 , 200 ));
121+ ASSERT_EQ (*hits[1 ], SkRect::MakeLTRB (300 , 100 , 400 , 200 ));
122+ }
123+
124+ TEST (PlatformViewRTree, JoinRectsWhenIntersectedCase1) {
125+ auto r_tree = sk_make_sp<PlatformViewRTree>();
126+ auto rtree_factory = PlatformViewRTreeFactory (r_tree);
66127 auto recorder = std::make_unique<SkPictureRecorder>();
67128 auto recording_canvas = recorder->beginRecording (SkRect::MakeIWH (1000 , 1000 ), &rtree_factory);
68129
@@ -96,9 +157,9 @@ TEST_F(PlatformViewRTree, JoinRectsWhenIntersectedCase1) {
96157 ASSERT_EQ (*hits[0 ], SkRect::MakeLTRB (100 , 100 , 175 , 175 ));
97158}
98159
99- TEST_F (PlatformViewRTree, JoinRectsWhenIntersectedCase2) {
100- auto r_tree = sk_make_sp<FlutterRTree >();
101- auto rtree_factory = FlutterRTreeFactory (r_tree);
160+ TEST (PlatformViewRTree, JoinRectsWhenIntersectedCase2) {
161+ auto r_tree = sk_make_sp<PlatformViewRTree >();
162+ auto rtree_factory = PlatformViewRTreeFactory (r_tree);
102163 auto recorder = std::make_unique<SkPictureRecorder>();
103164 auto recording_canvas = recorder->beginRecording (SkRect::MakeIWH (1000 , 1000 ), &rtree_factory);
104165
@@ -139,9 +200,9 @@ TEST_F(PlatformViewRTree, JoinRectsWhenIntersectedCase2) {
139200 ASSERT_EQ (*hits[0 ], SkRect::MakeLTRB (50 , 50 , 500 , 250 ));
140201}
141202
142- TEST_F (PlatformViewRTree, JoinRectsWhenIntersectedCase3) {
143- auto r_tree = sk_make_sp<FlutterRTree >();
144- auto rtree_factory = FlutterRTreeFactory (r_tree);
203+ TEST (PlatformViewRTree, JoinRectsWhenIntersectedCase3) {
204+ auto r_tree = sk_make_sp<PlatformViewRTree >();
205+ auto rtree_factory = PlatformViewRTreeFactory (r_tree);
145206 auto recorder = std::make_unique<SkPictureRecorder>();
146207 auto recording_canvas = recorder->beginRecording (SkRect::MakeIWH (1000 , 1000 ), &rtree_factory);
147208
0 commit comments