Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: components/viz/hit_test/hit_test_aggregator_unittest.cc

Issue 2908783002: WIP Hittest Component.
Patch Set: change HitTestFlags to constants so we can mix and match and convert to struct naming convention Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "hit_test_aggregator.h"
6 #include "cc/surfaces/frame_sink_id.h"
7 #include "cc/surfaces/local_surface_id.h"
8 #include "cc/surfaces/surface_id.h"
9 #include "display_hit_test_data_factory_local.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace viz {
13 namespace hit_test {
14 namespace test {
15
16 namespace {
17
18 constexpr cc::FrameSinkId kDisplayFrameSink(2, 0);
19
20 cc::SurfaceId MakeSurfaceId(const cc::FrameSinkId& frame_sink_id,
21 uint32_t local_id) {
22 return cc::SurfaceId(
23 frame_sink_id,
24 cc::LocalSurfaceId(local_id, base::UnguessableToken::Deserialize(0, 1u)));
25 }
26
27 } // namespace
28
29 using namespace hit_test::mojom;
30
31 class HitTestAggregatorTest : public testing::Test {
32 public:
33 HitTestAggregatorTest()
34 : aggregator_(
35 base::MakeUnique<viz::hit_test::DisplayHitTestDataFactoryLocal>()) {
36 }
37 ~HitTestAggregatorTest() override {}
38
39 void SetUp() override {}
40
41 void TearDown() override {}
42
43 HitTestAggregator aggregator_;
44
45 int count() {
46 DisplayHitTestRegion* start = aggregator_.GetCurrentRegions();
47 DisplayHitTestRegion* end = start;
48 while (end->child_count != kEndOfList) {
49 end++;
50 }
51 int count = end - start;
52 return count;
53 }
54
55 DisplayHitTestRegion* RegionAtIndex(int i) {
56 return aggregator_.GetCurrentRegions() + i;
57 }
58
59 int GetPendingCount() { return aggregator_.pending_.size(); }
60 int GetActiveCount() { return aggregator_.active_.size(); }
61
62 int GetPendingRegionCount() { return RegionCount(aggregator_.pending_); }
63 int GetActiveRegionCount() { return RegionCount(aggregator_.active_); }
64
65 int RegionCount(const HitTestDataMap& map) {
66 int size = 0;
67 for (auto const& it : map) {
68 hit_test::mojom::HitTestData* hit_test_data = it.second.get();
69 size += hit_test_data->regions.size();
70 }
71 return size;
72 }
73
74 void Reset() {
75 int size = aggregator_.display_hit_test_data_->length;
76
77 aggregator_.display_hit_test_data_->regions[0].child_count = kEndOfList;
78 aggregator_.display_hit_test_data_->regions[size >> 1].child_count =
79 kEndOfList;
80
81 aggregator_.pending_.clear();
82 aggregator_.active_.clear();
83 }
84
85 int GetDisplayHitTestDataLength() {
86 return aggregator_.display_hit_test_data_->length;
87 }
88
89 // Creates a hit test data element with 8 children recursively to
90 // the specified depth. SurfaceIds are generated in sequential order and
91 // the method returns the next unused id ( also matches the count ).
92 int CreateAndSubmitHitTestDataWith8Children(int id, int depth) {
93 cc::SurfaceId surface_id = MakeSurfaceId(kDisplayFrameSink, id);
94 id++;
95
96 auto hit_test_data = HitTestData::New();
97 hit_test_data->surface_id = surface_id;
98
99 for (int i = 0; i < 8; i++) {
100 auto hit_test_region = HitTestRegion::New();
101 hit_test_region->rect.SetRect(100, 100, 100, 100);
102
103 if (depth > 0) {
104 hit_test_region->flags = kHitTestChildSurface;
105 hit_test_region->surface_id = MakeSurfaceId(kDisplayFrameSink, id);
106 id = CreateAndSubmitHitTestDataWith8Children(id, depth - 1);
107 } else {
108 hit_test_region->flags = kHitTestMine;
109 }
110 hit_test_data->regions.push_back(std::move(hit_test_region));
111 }
112
113 aggregator_.SubmitHitTestData(std::move(hit_test_data));
114 return id;
115 }
116 };
117
118 // One surface.
119 //
120 // +----------+
121 // | |
122 // | |
123 // | |
124 // +----------+
125 //
126 TEST_F(HitTestAggregatorTest, OneSurface) {
127 EXPECT_TRUE(count() == 0);
128
129 cc::SurfaceId display_surface_id = MakeSurfaceId(kDisplayFrameSink, 1);
130
131 auto hit_test_data = HitTestData::New();
132 hit_test_data->surface_id = display_surface_id;
133
134 auto hit_test_region = HitTestRegion::New();
135 hit_test_region->flags = kHitTestMine;
136 hit_test_region->surface_id = display_surface_id;
137 hit_test_region->rect.SetRect(0, 0, 1024, 768);
138
139 hit_test_data->regions.push_back(std::move(hit_test_region));
140
141 aggregator_.SubmitHitTestData(std::move(hit_test_data));
142 EXPECT_TRUE(count() == 0);
143
144 EXPECT_TRUE(GetPendingCount() == 1);
145 EXPECT_TRUE(GetActiveCount() == 0);
146
147 aggregator_.OnSurfaceWillDraw(display_surface_id);
148
149 EXPECT_TRUE(GetPendingCount() == 0);
150 EXPECT_TRUE(GetActiveCount() == 1);
151
152 aggregator_.Aggregate(display_surface_id);
153 aggregator_.Swap();
154
155 // Expect 1 entry routing all events to the one surface ( display root ).
156 EXPECT_TRUE(count() == 1);
157
158 DisplayHitTestRegion* region;
159
160 region = RegionAtIndex(0);
161 EXPECT_TRUE(region->flags == kHitTestMine);
162 EXPECT_TRUE(region->frame_sink_id == display_surface_id.frame_sink_id());
163 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 1024, 768));
164 EXPECT_TRUE(region->child_count == 0);
165 }
166
167 // One opaque embedder with two regions.
168 //
169 // +e------------+
170 // | +r1-+ +r2-+ |
171 // | | | | | |
172 // | | | | | |
173 // | +---+ +---+ |
174 // +-------------+
175 //
176 TEST_F(HitTestAggregatorTest, OneEmbedderTwoRegions) {
177 Reset();
178 EXPECT_TRUE(count() == 0);
179
180 cc::SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1);
181
182 auto e_hit_test_data = HitTestData::New();
183 e_hit_test_data->surface_id = e_surface_id;
184
185 auto e_hit_test_region = HitTestRegion::New();
186 e_hit_test_region->flags = kHitTestMine;
187 e_hit_test_region->surface_id = e_surface_id;
188 e_hit_test_region->rect.SetRect(0, 0, 1024, 768);
189
190 auto e_hit_test_region_r1 = HitTestRegion::New();
191 e_hit_test_region_r1->flags = kHitTestMine;
192 e_hit_test_region_r1->rect.SetRect(0, 0, 512, 512);
193
194 auto e_hit_test_region_r2 = HitTestRegion::New();
195 e_hit_test_region_r2->flags = kHitTestMine;
196 e_hit_test_region_r2->rect.SetRect(0, 0, 512, 512);
197
198 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_r1));
199 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_r2));
200 e_hit_test_data->regions.push_back(std::move(e_hit_test_region));
201
202 // Submit HitTestData.
203
204 EXPECT_TRUE(GetPendingCount() == 0);
205
206 aggregator_.SubmitHitTestData(std::move(e_hit_test_data));
207 EXPECT_TRUE(GetPendingCount() == 1);
208
209 // Add Surfaces to DisplayFrame ( in unexpected order ).
210
211 EXPECT_TRUE(count() == 0);
212 EXPECT_TRUE(GetActiveCount() == 0);
213
214 aggregator_.OnSurfaceWillDraw(e_surface_id);
215 EXPECT_TRUE(GetActiveCount() == 1);
216
217 // Aggregate and swap.
218
219 aggregator_.Aggregate(e_surface_id);
220 EXPECT_TRUE(count() == 0);
221
222 aggregator_.Swap();
223 EXPECT_TRUE(count() == 3);
224
225 DisplayHitTestRegion* region;
226
227 region = RegionAtIndex(0);
228 EXPECT_TRUE(region->flags == kHitTestMine);
229 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 512, 512));
230 EXPECT_TRUE(region->child_count == 0);
231
232 region = RegionAtIndex(1);
233 EXPECT_TRUE(region->flags == kHitTestMine);
234 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 512, 512));
235 EXPECT_TRUE(region->child_count == 0);
236
237 region = RegionAtIndex(2);
238 EXPECT_TRUE(region->flags == kHitTestMine);
239 EXPECT_TRUE(region->frame_sink_id == e_surface_id.frame_sink_id());
240 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 1024, 768));
241 EXPECT_TRUE(region->child_count == 0);
242 }
243
244 // One embedder with two children.
245 //
246 // +e------------+
247 // | +c1-+ +c2-+ |
248 // | | | | | |
249 // | | | | | |
250 // | +---+ +---+ |
251 // +-------------+
252 //
253
254 TEST_F(HitTestAggregatorTest, OneEmbedderTwoChildren) {
255 Reset();
256 EXPECT_TRUE(count() == 0);
257
258 cc::SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1);
259 cc::SurfaceId c1_surface_id = MakeSurfaceId(kDisplayFrameSink, 2);
260 cc::SurfaceId c2_surface_id = MakeSurfaceId(kDisplayFrameSink, 3);
261
262 auto e_hit_test_data = HitTestData::New();
263 e_hit_test_data->surface_id = e_surface_id;
264
265 auto e_hit_test_region = HitTestRegion::New();
266 e_hit_test_region->flags = kHitTestMine;
267 e_hit_test_region->surface_id = e_surface_id;
268 e_hit_test_region->rect.SetRect(0, 0, 500, 500);
269
270 auto e_hit_test_region_c1 = HitTestRegion::New();
271 e_hit_test_region_c1->flags = kHitTestChildSurface;
272 e_hit_test_region_c1->surface_id = c1_surface_id;
273 e_hit_test_region_c1->rect.SetRect(100, 100, 200, 200);
274
275 auto e_hit_test_region_c2 = HitTestRegion::New();
276 e_hit_test_region_c2->flags = kHitTestChildSurface;
277 e_hit_test_region_c2->surface_id = c2_surface_id;
278 e_hit_test_region_c2->rect.SetRect(300, 300, 400, 400);
279
280 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_c1));
281 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_c2));
282 e_hit_test_data->regions.push_back(std::move(e_hit_test_region));
283
284 auto c1_hit_test_data = HitTestData::New();
285 c1_hit_test_data->surface_id = c1_surface_id;
286
287 auto c2_hit_test_data = HitTestData::New();
288 c2_hit_test_data->surface_id = c2_surface_id;
289
290 // Submit ( in unexpected order ).
291
292 EXPECT_TRUE(GetPendingCount() == 0);
293
294 aggregator_.SubmitHitTestData(std::move(c1_hit_test_data));
295 EXPECT_TRUE(GetPendingCount() == 1);
296
297 aggregator_.SubmitHitTestData(std::move(e_hit_test_data));
298 EXPECT_TRUE(GetPendingCount() == 2);
299
300 aggregator_.SubmitHitTestData(std::move(c2_hit_test_data));
301 EXPECT_TRUE(GetPendingCount() == 3);
302
303 // Surfaces added to DisplayFrame ( in unexpected order ).
304
305 EXPECT_TRUE(count() == 0);
306
307 EXPECT_TRUE(GetActiveCount() == 0);
308
309 aggregator_.OnSurfaceWillDraw(c2_surface_id);
310 EXPECT_TRUE(GetActiveCount() == 1);
311
312 aggregator_.OnSurfaceWillDraw(c1_surface_id);
313 EXPECT_TRUE(GetActiveCount() == 2);
314
315 aggregator_.OnSurfaceWillDraw(e_surface_id);
316 EXPECT_TRUE(GetActiveCount() == 3);
317
318 // Aggregate and swap.
319
320 aggregator_.Aggregate(e_surface_id);
321 EXPECT_TRUE(count() == 0);
322
323 aggregator_.Swap();
324
325 EXPECT_TRUE(count() == 3);
326
327 DisplayHitTestRegion* region;
328
329 region = RegionAtIndex(0);
330 EXPECT_TRUE(region->flags == kHitTestChildSurface);
331 EXPECT_TRUE(region->frame_sink_id == c1_surface_id.frame_sink_id());
332 EXPECT_TRUE(region->rect == gfx::Rect(100, 100, 200, 200));
333 EXPECT_TRUE(region->child_count == 0);
334
335 region = RegionAtIndex(1);
336 EXPECT_TRUE(region->flags == kHitTestChildSurface);
337 EXPECT_TRUE(region->frame_sink_id == c2_surface_id.frame_sink_id());
338 EXPECT_TRUE(region->rect == gfx::Rect(300, 300, 400, 400));
339 EXPECT_TRUE(region->child_count == 0);
340
341 region = RegionAtIndex(2);
342 EXPECT_TRUE(region->flags == kHitTestMine);
343 EXPECT_TRUE(region->frame_sink_id == e_surface_id.frame_sink_id());
344 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 500, 500));
345 EXPECT_TRUE(region->child_count == 0);
346 }
347
348 // Occluded child frame ( OOPIF ).
349 //
350 // +e-----------+
351 // | +c--+ |
352 // | | +div-+ |
353 // | | | | |
354 // | | +----+ |
355 // | +---+ |
356 // +------------+
357 //
358
359 TEST_F(HitTestAggregatorTest, OccludedChildFrame) {
360 Reset();
361 EXPECT_TRUE(count() == 0);
362
363 cc::SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1);
364 cc::SurfaceId c_surface_id = MakeSurfaceId(kDisplayFrameSink, 2);
365
366 auto e_hit_test_data = HitTestData::New();
367 e_hit_test_data->surface_id = e_surface_id;
368
369 auto e_hit_test_region = HitTestRegion::New();
370 e_hit_test_region->flags = kHitTestMine;
371 e_hit_test_region->surface_id = e_surface_id;
372 e_hit_test_region->rect.SetRect(0, 0, 500, 500);
373
374 auto e_hit_test_region_div = HitTestRegion::New();
375 e_hit_test_region_div->flags = kHitTestMine;
376 e_hit_test_region_div->rect.SetRect(100, 100, 400, 400);
377
378 auto e_hit_test_region_c = HitTestRegion::New();
379 e_hit_test_region_c->flags = kHitTestChildSurface;
380 e_hit_test_region_c->surface_id = c_surface_id;
381 e_hit_test_region_c->rect.SetRect(200, 200, 500, 200);
382
383 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_div));
384 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_c));
385 e_hit_test_data->regions.push_back(std::move(e_hit_test_region));
386
387 auto c_hit_test_data = HitTestData::New();
388 c_hit_test_data->surface_id = c_surface_id;
389
390 auto c_hit_test_region = HitTestRegion::New();
391 c_hit_test_region->flags = kHitTestMine;
392 c_hit_test_region->surface_id = c_surface_id;
393 c_hit_test_region->rect.SetRect(0, 0, 300, 300);
394
395 c_hit_test_data->regions.push_back(std::move(c_hit_test_region));
396
397 // Submit ( in unexpected order ).
398
399 EXPECT_TRUE(GetPendingCount() == 0);
400
401 aggregator_.SubmitHitTestData(std::move(c_hit_test_data));
402 EXPECT_TRUE(GetPendingCount() == 1);
403
404 aggregator_.SubmitHitTestData(std::move(e_hit_test_data));
405 EXPECT_TRUE(GetPendingCount() == 2);
406
407 // Surfaces added to DisplayFrame ( in unexpected order ).
408
409 EXPECT_TRUE(count() == 0);
410
411 EXPECT_TRUE(GetActiveCount() == 0);
412
413 aggregator_.OnSurfaceWillDraw(e_surface_id);
414 EXPECT_TRUE(GetActiveCount() == 1);
415
416 aggregator_.OnSurfaceWillDraw(c_surface_id);
417 EXPECT_TRUE(GetActiveCount() == 2);
418
419 // Aggregate and swap.
420
421 aggregator_.Aggregate(e_surface_id);
422 EXPECT_TRUE(count() == 0);
423
424 aggregator_.Swap();
425
426 EXPECT_TRUE(count() == 4);
427
428 DisplayHitTestRegion* region;
429
430 region = RegionAtIndex(0);
431 EXPECT_TRUE(region->rect == gfx::Rect(100, 100, 400, 400));
432 EXPECT_TRUE(region->flags == kHitTestMine);
433 EXPECT_TRUE(region->child_count == 0);
434
435 region = RegionAtIndex(1);
436 EXPECT_TRUE(region->rect == gfx::Rect(200, 200, 500, 200));
437 EXPECT_TRUE(region->frame_sink_id == c_surface_id.frame_sink_id());
438 EXPECT_TRUE(region->flags == kHitTestChildSurface);
439 EXPECT_TRUE(region->child_count == 1);
440
441 region = RegionAtIndex(2);
442 EXPECT_TRUE(region->flags == kHitTestMine);
443 EXPECT_TRUE(region->frame_sink_id == c_surface_id.frame_sink_id());
444 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 300, 300));
445 EXPECT_TRUE(region->child_count == 0);
446
447 region = RegionAtIndex(3);
448 EXPECT_TRUE(region->flags == kHitTestMine);
449 EXPECT_TRUE(region->frame_sink_id == e_surface_id.frame_sink_id());
450 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 500, 500));
451 EXPECT_TRUE(region->child_count == 0);
452 }
453
454 // One embedder with a clipped child with a tab and transparent background.
455 //
456 // +e-------------+
457 // | +c---------| Point maps to
458 // | 1 |+a--+ | ----- -------
459 // | || 2 | 3 | 1 e
460 // | |+b--------| 2 a
461 // | || | 3 e ( transparent area in c )
462 // | || 4 | 4 b
463 // +--------------+
464 //
465
466 TEST_F(HitTestAggregatorTest, ClippedChildWithTabAndTransparentBackground) {
467 Reset();
468 EXPECT_TRUE(count() == 0);
469
470 cc::SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1);
471 cc::SurfaceId c_surface_id = MakeSurfaceId(kDisplayFrameSink, 2);
472 cc::SurfaceId a_surface_id = MakeSurfaceId(kDisplayFrameSink, 3);
473 cc::SurfaceId b_surface_id = MakeSurfaceId(kDisplayFrameSink, 4);
474
475 auto e_hit_test_data = HitTestData::New();
476 e_hit_test_data->surface_id = e_surface_id;
477
478 auto e_hit_test_region_c = HitTestRegion::New();
479 e_hit_test_region_c->flags = kHitTestChildSurface;
480 e_hit_test_region_c->surface_id = c_surface_id;
481 e_hit_test_region_c->rect.SetRect(200, 100, 800, 800);
482 e_hit_test_region_c->transform.Translate(200, 100);
483
484 auto e_hit_test_region = HitTestRegion::New();
485 e_hit_test_region->flags = kHitTestMine;
486 e_hit_test_region->surface_id = e_surface_id;
487 e_hit_test_region->rect.SetRect(0, 0, 600, 600);
488
489 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_c));
490 e_hit_test_data->regions.push_back(std::move(e_hit_test_region));
491
492 auto c_hit_test_data = HitTestData::New();
493 c_hit_test_data->surface_id = c_surface_id;
494
495 auto c_hit_test_region_a = HitTestRegion::New();
496 c_hit_test_region_a->flags = kHitTestChildSurface;
497 c_hit_test_region_a->surface_id = a_surface_id;
498 c_hit_test_region_a->rect.SetRect(0, 0, 200, 100);
499
500 auto c_hit_test_region_b = HitTestRegion::New();
501 c_hit_test_region_b->flags = kHitTestChildSurface;
502 c_hit_test_region_b->surface_id = b_surface_id;
503 c_hit_test_region_b->rect.SetRect(0, 100, 800, 600);
504
505 c_hit_test_data->regions.push_back(std::move(c_hit_test_region_a));
506 c_hit_test_data->regions.push_back(std::move(c_hit_test_region_b));
507
508 auto a_hit_test_data = HitTestData::New();
509 a_hit_test_data->surface_id = a_surface_id;
510
511 auto a_hit_test_region = HitTestRegion::New();
512 a_hit_test_region->flags = kHitTestMine;
513 a_hit_test_region->surface_id = a_surface_id;
514 a_hit_test_region->rect.SetRect(0, 0, 200, 100);
515
516 a_hit_test_data->regions.push_back(std::move(a_hit_test_region));
517
518 auto b_hit_test_data = HitTestData::New();
519 b_hit_test_data->surface_id = b_surface_id;
520
521 auto b_hit_test_region = HitTestRegion::New();
522 b_hit_test_region->flags = kHitTestMine;
523 b_hit_test_region->surface_id = b_surface_id;
524 b_hit_test_region->rect.SetRect(0, 0, 800, 600);
525
526 b_hit_test_data->regions.push_back(std::move(b_hit_test_region));
527
528 // Submit ( in unexpected order ).
529
530 EXPECT_TRUE(GetPendingCount() == 0);
531
532 aggregator_.SubmitHitTestData(std::move(c_hit_test_data));
533 EXPECT_TRUE(GetPendingCount() == 1);
534
535 aggregator_.SubmitHitTestData(std::move(a_hit_test_data));
536 EXPECT_TRUE(GetPendingCount() == 2);
537
538 aggregator_.SubmitHitTestData(std::move(b_hit_test_data));
539 EXPECT_TRUE(GetPendingCount() == 3);
540
541 aggregator_.SubmitHitTestData(std::move(e_hit_test_data));
542 EXPECT_TRUE(GetPendingCount() == 4);
543
544 // Surfaces added to DisplayFrame ( in unexpected order ).
545
546 EXPECT_TRUE(count() == 0);
547
548 EXPECT_TRUE(GetActiveCount() == 0);
549
550 aggregator_.OnSurfaceWillDraw(c_surface_id);
551 EXPECT_TRUE(GetActiveCount() == 1);
552
553 aggregator_.OnSurfaceWillDraw(e_surface_id);
554 EXPECT_TRUE(GetActiveCount() == 2);
555
556 aggregator_.OnSurfaceWillDraw(b_surface_id);
557 EXPECT_TRUE(GetActiveCount() == 3);
558
559 aggregator_.OnSurfaceWillDraw(a_surface_id);
560 EXPECT_TRUE(GetActiveCount() == 4);
561
562 // Aggregate and swap.
563
564 aggregator_.Aggregate(e_surface_id);
565 EXPECT_TRUE(count() == 0);
566
567 aggregator_.Swap();
568
569 EXPECT_TRUE(count() == 6);
570
571 DisplayHitTestRegion* region;
572
573 region = RegionAtIndex(0);
574 EXPECT_TRUE(region->flags == kHitTestChildSurface);
575 EXPECT_TRUE(region->frame_sink_id == c_surface_id.frame_sink_id());
576 EXPECT_TRUE(region->rect == gfx::Rect(200, 100, 800, 800));
577 EXPECT_TRUE(region->child_count == 4);
578
579 gfx::Point point(300, 300);
580 region->transform.TransformPointReverse(&point);
581 EXPECT_TRUE(point == gfx::Point(100, 200));
582
583 region = RegionAtIndex(1);
584 EXPECT_TRUE(region->flags == kHitTestChildSurface);
585 EXPECT_TRUE(region->frame_sink_id == a_surface_id.frame_sink_id());
586 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 200, 100));
587 EXPECT_TRUE(region->child_count == 1);
588
589 region = RegionAtIndex(2);
590 EXPECT_TRUE(region->flags == kHitTestMine);
591 EXPECT_TRUE(region->frame_sink_id == a_surface_id.frame_sink_id());
592 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 200, 100));
593 EXPECT_TRUE(region->child_count == 0);
594
595 region = RegionAtIndex(3);
596 EXPECT_TRUE(region->flags == kHitTestChildSurface);
597 EXPECT_TRUE(region->frame_sink_id == b_surface_id.frame_sink_id());
598 EXPECT_TRUE(region->rect == gfx::Rect(0, 100, 800, 600));
599 EXPECT_TRUE(region->child_count == 1);
600
601 region = RegionAtIndex(4);
602 EXPECT_TRUE(region->flags == kHitTestMine);
603 EXPECT_TRUE(region->frame_sink_id == b_surface_id.frame_sink_id());
604 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 800, 600));
605 EXPECT_TRUE(region->child_count == 0);
606
607 region = RegionAtIndex(5);
608 EXPECT_TRUE(region->flags == kHitTestMine);
609 EXPECT_TRUE(region->frame_sink_id == e_surface_id.frame_sink_id());
610 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 600, 600));
611 EXPECT_TRUE(region->child_count == 0);
612 }
613
614 // Three children deep.
615 //
616 // +e------------+
617 // | +c1-------+ |
618 // | | +c2---+ | |
619 // | | | +c3-| | |
620 // | | | | | | |
621 // | | | +---| | |
622 // | | +-----+ | |
623 // | +---------+ |
624 // +-------------+
625 //
626
627 TEST_F(HitTestAggregatorTest, ThreeChildrenDeep) {
628 Reset();
629 EXPECT_TRUE(count() == 0);
630
631 cc::SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1);
632 cc::SurfaceId c1_surface_id = MakeSurfaceId(kDisplayFrameSink, 2);
633 cc::SurfaceId c2_surface_id = MakeSurfaceId(kDisplayFrameSink, 3);
634 cc::SurfaceId c3_surface_id = MakeSurfaceId(kDisplayFrameSink, 4);
635
636 auto e_hit_test_data = HitTestData::New();
637 e_hit_test_data->surface_id = e_surface_id;
638
639 auto e_hit_test_region_c1 = HitTestRegion::New();
640 e_hit_test_region_c1->flags = kHitTestChildSurface;
641 e_hit_test_region_c1->surface_id = c1_surface_id;
642 e_hit_test_region_c1->rect.SetRect(100, 100, 700, 700);
643
644 auto e_hit_test_region = HitTestRegion::New();
645 e_hit_test_region->flags = kHitTestMine;
646 e_hit_test_region->surface_id = e_surface_id;
647 e_hit_test_region->rect.SetRect(0, 0, 800, 800);
648
649 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_c1));
650 e_hit_test_data->regions.push_back(std::move(e_hit_test_region));
651
652 auto c1_hit_test_data = HitTestData::New();
653 c1_hit_test_data->surface_id = c1_surface_id;
654
655 auto c1_hit_test_region_c2 = HitTestRegion::New();
656 c1_hit_test_region_c2->flags = kHitTestChildSurface;
657 c1_hit_test_region_c2->surface_id = c2_surface_id;
658 c1_hit_test_region_c2->rect.SetRect(100, 100, 500, 500);
659
660 auto c1_hit_test_region = HitTestRegion::New();
661 c1_hit_test_region->flags = kHitTestMine;
662 c1_hit_test_region->surface_id = c1_surface_id;
663 c1_hit_test_region->rect.SetRect(0, 0, 600, 600);
664
665 c1_hit_test_data->regions.push_back(std::move(c1_hit_test_region_c2));
666 c1_hit_test_data->regions.push_back(std::move(c1_hit_test_region));
667
668 auto c2_hit_test_data = HitTestData::New();
669 c2_hit_test_data->surface_id = c2_surface_id;
670
671 auto c2_hit_test_region_c3 = HitTestRegion::New();
672 c2_hit_test_region_c3->flags = kHitTestChildSurface;
673 c2_hit_test_region_c3->surface_id = c3_surface_id;
674 c2_hit_test_region_c3->rect.SetRect(100, 100, 300, 300);
675
676 auto c2_hit_test_region = HitTestRegion::New();
677 c2_hit_test_region->flags = kHitTestMine;
678 c2_hit_test_region->surface_id = c2_surface_id;
679 c2_hit_test_region->rect.SetRect(0, 0, 400, 400);
680
681 c2_hit_test_data->regions.push_back(std::move(c2_hit_test_region_c3));
682 c2_hit_test_data->regions.push_back(std::move(c2_hit_test_region));
683
684 auto c3_hit_test_data = HitTestData::New();
685 c3_hit_test_data->surface_id = c3_surface_id;
686
687 auto c3_hit_test_region = HitTestRegion::New();
688 c3_hit_test_region->flags = kHitTestMine;
689 c3_hit_test_region->surface_id = c3_surface_id;
690 c3_hit_test_region->rect.SetRect(0, 0, 200, 200);
691
692 c3_hit_test_data->regions.push_back(std::move(c3_hit_test_region));
693
694 // Submit ( in unexpected order ).
695
696 EXPECT_TRUE(GetPendingCount() == 0);
697
698 aggregator_.SubmitHitTestData(std::move(c1_hit_test_data));
699 EXPECT_TRUE(GetPendingCount() == 1);
700
701 aggregator_.SubmitHitTestData(std::move(c3_hit_test_data));
702 EXPECT_TRUE(GetPendingCount() == 2);
703
704 aggregator_.SubmitHitTestData(std::move(e_hit_test_data));
705 EXPECT_TRUE(GetPendingCount() == 3);
706
707 aggregator_.SubmitHitTestData(std::move(c2_hit_test_data));
708 EXPECT_TRUE(GetPendingCount() == 4);
709
710 // Surfaces added to DisplayFrame ( in unexpected order ).
711
712 EXPECT_TRUE(count() == 0);
713
714 EXPECT_TRUE(GetActiveCount() == 0);
715
716 aggregator_.OnSurfaceWillDraw(c2_surface_id);
717 EXPECT_TRUE(GetActiveCount() == 1);
718
719 aggregator_.OnSurfaceWillDraw(c1_surface_id);
720 EXPECT_TRUE(GetActiveCount() == 2);
721
722 aggregator_.OnSurfaceWillDraw(e_surface_id);
723 EXPECT_TRUE(GetActiveCount() == 3);
724
725 aggregator_.OnSurfaceWillDraw(c3_surface_id);
726 EXPECT_TRUE(GetActiveCount() == 4);
727
728 // Aggregate and swap.
729
730 aggregator_.Aggregate(e_surface_id);
731 EXPECT_TRUE(count() == 0);
732
733 aggregator_.Swap();
734
735 EXPECT_TRUE(count() == 7);
736
737 DisplayHitTestRegion* region;
738
739 region = RegionAtIndex(0);
740 EXPECT_TRUE(region->flags == kHitTestChildSurface);
741 EXPECT_TRUE(region->frame_sink_id == c1_surface_id.frame_sink_id());
742 EXPECT_TRUE(region->rect == gfx::Rect(100, 100, 700, 700));
743 EXPECT_TRUE(region->child_count == 5);
744
745 region = RegionAtIndex(1);
746 EXPECT_TRUE(region->flags == kHitTestChildSurface);
747 EXPECT_TRUE(region->frame_sink_id == c2_surface_id.frame_sink_id());
748 EXPECT_TRUE(region->rect == gfx::Rect(100, 100, 500, 500));
749 EXPECT_TRUE(region->child_count == 3);
750
751 region = RegionAtIndex(2);
752 EXPECT_TRUE(region->flags == kHitTestChildSurface);
753 EXPECT_TRUE(region->frame_sink_id == c3_surface_id.frame_sink_id());
754 EXPECT_TRUE(region->rect == gfx::Rect(100, 100, 300, 300));
755 EXPECT_TRUE(region->child_count == 1);
756
757 region = RegionAtIndex(3);
758 EXPECT_TRUE(region->flags == kHitTestMine);
759 EXPECT_TRUE(region->frame_sink_id == c3_surface_id.frame_sink_id());
760 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 200, 200));
761 EXPECT_TRUE(region->child_count == 0);
762
763 region = RegionAtIndex(4);
764 EXPECT_TRUE(region->flags == kHitTestMine);
765 EXPECT_TRUE(region->frame_sink_id == c2_surface_id.frame_sink_id());
766 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 400, 400));
767 EXPECT_TRUE(region->child_count == 0);
768
769 region = RegionAtIndex(5);
770 EXPECT_TRUE(region->flags == kHitTestMine);
771 EXPECT_TRUE(region->frame_sink_id == c1_surface_id.frame_sink_id());
772 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 600, 600));
773 EXPECT_TRUE(region->child_count == 0);
774
775 region = RegionAtIndex(6);
776 EXPECT_TRUE(region->flags == kHitTestMine);
777 EXPECT_TRUE(region->frame_sink_id == e_surface_id.frame_sink_id());
778 EXPECT_TRUE(region->rect == gfx::Rect(0, 0, 800, 800));
779 EXPECT_TRUE(region->child_count == 0);
780 }
781
782 // Exceed limits to ensure that bounds and resize work.
783 //
784 // A tree of embedders each with 8 children and 4 levels deep = 4096 regions.
785 // This will exceed initial allocation and force a resize.
786 //
787 // +e--------------------------------------------------------+
788 // | +c1----------++c2----------++c3----------++c4----------+|
789 // | | +c1--------|| +c1--------|| +c1--------|| +c1--------||
790 // | | | +c1-++c2-|| | +c1-++c2-|| | +c1-++c2-|| | +c1-++c2-||
791 // | | | | || || | | || || | | || || | | || ||
792 // | | | +---++---|| | +---++---|| | +---++---|| | +---++---||
793 // | +------------++------------++------------++------------+|
794 // | +c5----------++c6----------++c7----------++c8----------+|
795 // | | +c1--------|| +c1--------|| +c1--------|| +c1--------||
796 // | | | +c1-++c2-|| | +c1-++c2-|| | +c1-++c2-|| | +c1-++c2-||
797 // | | | | || || | | || || | | || || | | || ||
798 // | | | +---++---|| | +---++---|| | +---++---|| | +---++---||
799 // | +------------++------------++------------++------------+|
800 // +---------------------------------------------------------+
801 //
802
803 TEST_F(HitTestAggregatorTest, ExceedLimits) {
804 Reset();
805 EXPECT_TRUE(count() == 0);
806
807 EXPECT_TRUE(GetDisplayHitTestDataLength() < 4096);
808
809 cc::SurfaceId display_surface_id = MakeSurfaceId(kDisplayFrameSink, 1);
810
811 int next_surface_id = CreateAndSubmitHitTestDataWith8Children(1, 3);
812 int surface_count = next_surface_id - 1;
813
814 int region_count = GetPendingRegionCount();
815
816 // Expect 4680 regions:
817 // 8 children 4 levels deep 8*8*8*8 is 4096
818 // 1 region for each embedder/surface + 584
819 // -----
820 // 4680.
821 EXPECT_TRUE(region_count == 4680);
822
823 EXPECT_TRUE(GetPendingCount() == surface_count);
824
825 // Mark Surfaces as added to DisplayFrame ( in unexpected order ).
826
827 EXPECT_TRUE(count() == 0);
828 EXPECT_TRUE(GetActiveCount() == 0);
829
830 for (int i = 1; i <= surface_count; i++) {
831 cc::SurfaceId surface_id = MakeSurfaceId(kDisplayFrameSink, i);
832 aggregator_.OnSurfaceWillDraw(surface_id);
833 }
834
835 EXPECT_TRUE(GetActiveCount() == surface_count);
836
837 // Aggregate and swap.
838
839 aggregator_.Aggregate(display_surface_id);
840 EXPECT_TRUE(count() == 0);
841
842 aggregator_.Swap();
843
844 EXPECT_TRUE(count() == region_count);
845
846 EXPECT_TRUE(GetDisplayHitTestDataLength() >= region_count);
847 }
848
849 } // namespace test
850 } // namespace hit_test
851 } // namespace viz
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698