OLD | NEW |
---|---|
(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 "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 namespace viz { | |
12 namespace hit_test { | |
13 namespace test { | |
14 | |
15 namespace { | |
16 | |
17 constexpr cc::FrameSinkId kDisplayFrameSink(2, 0); | |
18 | |
19 cc::SurfaceId MakeSurfaceId(const cc::FrameSinkId& frame_sink_id, | |
20 uint32_t local_id) { | |
21 return cc::SurfaceId( | |
22 frame_sink_id, | |
23 cc::LocalSurfaceId(local_id, base::UnguessableToken::Deserialize(0, 1u))); | |
24 } | |
25 | |
26 } // namespace | |
27 | |
28 using namespace hit_test::mojom; | |
29 | |
30 class HitTestAggregatorTest : public testing::Test { | |
31 public: | |
32 HitTestAggregatorTest() {} | |
33 ~HitTestAggregatorTest() override {} | |
34 | |
35 void SetUp() override {} | |
36 | |
37 void TearDown() override {} | |
38 | |
39 HitTestAggregator aggregator_; | |
40 | |
41 int count() { | |
42 DisplayHitTestRegion* start = aggregator_.GetCurrentRegions(); | |
43 DisplayHitTestRegion* end = start; | |
44 while (end->child_count_ != kEndOfList) { | |
45 end++; | |
46 } | |
47 int count = end - start; | |
48 return count; | |
49 } | |
50 | |
51 DisplayHitTestRegion* RegionAtIndex(int i) { | |
52 return aggregator_.GetCurrentRegions() + i; | |
53 } | |
54 | |
55 int GetPendingCount() { return aggregator_.pending_.size(); } | |
56 int GetActiveCount() { return aggregator_.active_.size(); } | |
57 | |
58 void Reset() { | |
59 int size = aggregator_.display_hit_test_data_->size_; | |
60 | |
61 aggregator_.display_hit_test_data_->regions_[0].child_count_ = kEndOfList; | |
62 aggregator_.display_hit_test_data_->regions_[size >> 1].child_count_ = | |
63 kEndOfList; | |
64 | |
65 aggregator_.pending_.clear(); | |
66 aggregator_.active_.clear(); | |
67 } | |
68 }; | |
69 | |
70 // One surface. | |
71 // | |
72 // +----------+ | |
73 // | | | |
74 // | | | |
75 // | | | |
76 // +----------+ | |
77 // | |
78 TEST_F(HitTestAggregatorTest, OneSurface) { | |
79 EXPECT_TRUE(count() == 0); | |
80 | |
81 cc::SurfaceId display_surface_id = MakeSurfaceId(kDisplayFrameSink, 1); | |
82 | |
83 auto hit_test_data = HitTestData::New(); | |
84 hit_test_data->surface_id_ = display_surface_id; | |
85 | |
86 auto hit_test_region = HitTestRegion::New(); | |
87 hit_test_region->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
rjkroege
2017/06/09 15:47:08
and... | HitTestRegionFlags::HIT_TEST_BOUNDS ?
| |
88 hit_test_region->surface_id_ = display_surface_id; | |
89 hit_test_region->rect_.SetRect(0, 0, 1024, 768); | |
90 | |
91 hit_test_data->regions_.push_back(std::move(hit_test_region)); | |
92 | |
93 aggregator_.SubmitHitTestData(std::move(hit_test_data)); | |
94 | |
95 EXPECT_TRUE(count() == 0); | |
96 | |
97 EXPECT_TRUE(GetPendingCount() == 1); | |
98 EXPECT_TRUE(GetActiveCount() == 0); | |
99 | |
100 aggregator_.OnSurfaceWillDraw(display_surface_id); | |
101 | |
102 EXPECT_TRUE(GetPendingCount() == 0); | |
103 EXPECT_TRUE(GetActiveCount() == 1); | |
104 | |
105 aggregator_.Aggregate(display_surface_id); | |
106 aggregator_.Swap(); | |
107 | |
108 // Expect 1 entry routing all events to the one surface ( display root ). | |
109 EXPECT_TRUE(count() == 1); | |
110 | |
111 DisplayHitTestRegion* region; | |
112 | |
113 region = RegionAtIndex(0); | |
114 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
115 EXPECT_TRUE(region->frame_sink_id_ == display_surface_id.frame_sink_id()); | |
116 EXPECT_TRUE(region->rect_ == gfx::Rect(0, 0, 1024, 768)); | |
117 EXPECT_TRUE(region->child_count_ == 0); | |
118 } | |
119 | |
120 // One opaque embedder with two regions. | |
121 // | |
122 // +e------------+ | |
123 // | +r1-+ +r2-+ | | |
124 // | | | | | | | |
125 // | | | | | | | |
126 // | +---+ +---+ | | |
127 // +-------------+ | |
128 // | |
129 TEST_F(HitTestAggregatorTest, OneEmbedderTwoRegions) { | |
130 Reset(); | |
131 EXPECT_TRUE(count() == 0); | |
132 | |
133 cc::SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1); | |
134 | |
135 auto e_hit_test_data = HitTestData::New(); | |
136 e_hit_test_data->surface_id_ = e_surface_id; | |
137 | |
138 auto e_hit_test_region = HitTestRegion::New(); | |
139 e_hit_test_region->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
140 e_hit_test_region->surface_id_ = e_surface_id; | |
141 e_hit_test_region->rect_.SetRect(0, 0, 1024, 768); | |
142 | |
143 auto e_hit_test_region_r1 = HitTestRegion::New(); | |
144 e_hit_test_region_r1->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
145 e_hit_test_region_r1->rect_.SetRect(0, 0, 512, 512); | |
146 | |
147 auto e_hit_test_region_r2 = HitTestRegion::New(); | |
148 e_hit_test_region_r2->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
149 e_hit_test_region_r2->rect_.SetRect(0, 0, 512, 512); | |
150 | |
151 e_hit_test_data->regions_.push_back(std::move(e_hit_test_region_r1)); | |
152 e_hit_test_data->regions_.push_back(std::move(e_hit_test_region_r2)); | |
153 e_hit_test_data->regions_.push_back(std::move(e_hit_test_region)); | |
154 | |
155 // Submit HitTestData. | |
156 | |
157 EXPECT_TRUE(GetPendingCount() == 0); | |
158 | |
159 aggregator_.SubmitHitTestData(std::move(e_hit_test_data)); | |
160 EXPECT_TRUE(GetPendingCount() == 1); | |
161 | |
162 // Add Surfaces to DisplayFrame ( in unexpected order ). | |
163 | |
164 EXPECT_TRUE(count() == 0); | |
165 EXPECT_TRUE(GetActiveCount() == 0); | |
166 | |
167 aggregator_.OnSurfaceWillDraw(e_surface_id); | |
168 EXPECT_TRUE(GetActiveCount() == 1); | |
169 | |
170 // Aggregate and swap. | |
171 | |
172 aggregator_.Aggregate(e_surface_id); | |
173 EXPECT_TRUE(count() == 0); | |
174 | |
175 aggregator_.Swap(); | |
176 EXPECT_TRUE(count() == 3); | |
177 | |
178 DisplayHitTestRegion* region; | |
179 | |
180 region = RegionAtIndex(0); | |
181 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
182 EXPECT_TRUE(region->rect_ == gfx::Rect(0, 0, 512, 512)); | |
183 EXPECT_TRUE(region->child_count_ == 0); | |
184 | |
185 region = RegionAtIndex(1); | |
186 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
187 EXPECT_TRUE(region->rect_ == gfx::Rect(0, 0, 512, 512)); | |
188 EXPECT_TRUE(region->child_count_ == 0); | |
189 | |
190 region = RegionAtIndex(2); | |
191 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
192 EXPECT_TRUE(region->frame_sink_id_ == e_surface_id.frame_sink_id()); | |
193 EXPECT_TRUE(region->rect_ == gfx::Rect(0, 0, 1024, 768)); | |
194 EXPECT_TRUE(region->child_count_ == 0); | |
195 } | |
196 | |
197 // One embedder with two children. | |
198 // | |
199 // +e------------+ | |
200 // | +c1-+ +c2-+ | | |
201 // | | | | | | | |
202 // | | | | | | | |
203 // | +---+ +---+ | | |
204 // +-------------+ | |
205 // | |
206 | |
207 TEST_F(HitTestAggregatorTest, OneEmbedderTwoChildren) { | |
208 Reset(); | |
209 EXPECT_TRUE(count() == 0); | |
210 | |
211 cc::SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1); | |
212 cc::SurfaceId c1_surface_id = MakeSurfaceId(kDisplayFrameSink, 2); | |
213 cc::SurfaceId c2_surface_id = MakeSurfaceId(kDisplayFrameSink, 3); | |
214 | |
215 auto e_hit_test_data = HitTestData::New(); | |
216 e_hit_test_data->surface_id_ = e_surface_id; | |
217 | |
218 auto e_hit_test_region = HitTestRegion::New(); | |
219 e_hit_test_region->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
220 e_hit_test_region->surface_id_ = e_surface_id; | |
221 e_hit_test_region->rect_.SetRect(0, 0, 500, 500); | |
222 | |
223 auto e_hit_test_region_c1 = HitTestRegion::New(); | |
224 e_hit_test_region_c1->flags_ = HitTestRegionFlags::HIT_TEST_CHILD_SURFACE; | |
225 e_hit_test_region_c1->surface_id_ = c1_surface_id; | |
226 e_hit_test_region_c1->rect_.SetRect(100, 100, 200, 200); | |
227 | |
228 auto e_hit_test_region_c2 = HitTestRegion::New(); | |
229 e_hit_test_region_c2->flags_ = HitTestRegionFlags::HIT_TEST_CHILD_SURFACE; | |
230 e_hit_test_region_c2->surface_id_ = c2_surface_id; | |
231 e_hit_test_region_c2->rect_.SetRect(300, 300, 400, 400); | |
232 | |
233 e_hit_test_data->regions_.push_back(std::move(e_hit_test_region_c1)); | |
234 e_hit_test_data->regions_.push_back(std::move(e_hit_test_region_c2)); | |
235 e_hit_test_data->regions_.push_back(std::move(e_hit_test_region)); | |
236 | |
237 auto c1_hit_test_data = HitTestData::New(); | |
238 c1_hit_test_data->surface_id_ = c1_surface_id; | |
239 | |
240 auto c2_hit_test_data = HitTestData::New(); | |
241 c2_hit_test_data->surface_id_ = c2_surface_id; | |
242 | |
243 // Submit ( in unexpected order ). | |
244 | |
245 EXPECT_TRUE(GetPendingCount() == 0); | |
246 | |
247 aggregator_.SubmitHitTestData(std::move(c1_hit_test_data)); | |
248 EXPECT_TRUE(GetPendingCount() == 1); | |
249 | |
250 aggregator_.SubmitHitTestData(std::move(e_hit_test_data)); | |
251 EXPECT_TRUE(GetPendingCount() == 2); | |
252 | |
253 aggregator_.SubmitHitTestData(std::move(c2_hit_test_data)); | |
254 EXPECT_TRUE(GetPendingCount() == 3); | |
255 | |
256 // Surfaces added to DisplayFrame ( in unexpected order ). | |
257 | |
258 EXPECT_TRUE(count() == 0); | |
259 | |
260 EXPECT_TRUE(GetActiveCount() == 0); | |
261 | |
262 aggregator_.OnSurfaceWillDraw(c2_surface_id); | |
263 EXPECT_TRUE(GetActiveCount() == 1); | |
264 | |
265 aggregator_.OnSurfaceWillDraw(c1_surface_id); | |
266 EXPECT_TRUE(GetActiveCount() == 2); | |
267 | |
268 aggregator_.OnSurfaceWillDraw(e_surface_id); | |
269 EXPECT_TRUE(GetActiveCount() == 3); | |
270 | |
271 // Aggregate and swap. | |
272 | |
273 aggregator_.Aggregate(e_surface_id); | |
274 EXPECT_TRUE(count() == 0); | |
275 | |
276 aggregator_.Swap(); | |
277 | |
278 EXPECT_TRUE(count() == 3); | |
279 | |
280 DisplayHitTestRegion* region; | |
281 | |
282 region = RegionAtIndex(0); | |
283 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_CHILD_SURFACE); | |
284 EXPECT_TRUE(region->frame_sink_id_ == c1_surface_id.frame_sink_id()); | |
285 EXPECT_TRUE(region->rect_ == gfx::Rect(100, 100, 200, 200)); | |
286 EXPECT_TRUE(region->child_count_ == 0); | |
287 | |
288 region = RegionAtIndex(1); | |
289 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_CHILD_SURFACE); | |
290 EXPECT_TRUE(region->frame_sink_id_ == c2_surface_id.frame_sink_id()); | |
291 EXPECT_TRUE(region->rect_ == gfx::Rect(300, 300, 400, 400)); | |
292 EXPECT_TRUE(region->child_count_ == 0); | |
293 | |
294 region = RegionAtIndex(2); | |
295 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
296 EXPECT_TRUE(region->frame_sink_id_ == e_surface_id.frame_sink_id()); | |
297 EXPECT_TRUE(region->rect_ == gfx::Rect(0, 0, 500, 500)); | |
298 EXPECT_TRUE(region->child_count_ == 0); | |
299 } | |
300 | |
301 // Three children deep. | |
302 // | |
303 // +e------------+ | |
304 // | +c1-------+ | | |
305 // | | +c2---+ | | | |
306 // | | | +c3-| | | | |
307 // | | | | | | | | |
308 // | | | +---| | | | |
309 // | | +-----+ | | | |
310 // | +---------+ | | |
311 // +-------------+ | |
312 // | |
313 | |
314 TEST_F(HitTestAggregatorTest, ThreeChildrenDeep) { | |
315 Reset(); | |
316 EXPECT_TRUE(count() == 0); | |
317 | |
318 cc::SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1); | |
319 cc::SurfaceId c1_surface_id = MakeSurfaceId(kDisplayFrameSink, 2); | |
320 cc::SurfaceId c2_surface_id = MakeSurfaceId(kDisplayFrameSink, 3); | |
321 cc::SurfaceId c3_surface_id = MakeSurfaceId(kDisplayFrameSink, 4); | |
322 | |
323 auto e_hit_test_data = HitTestData::New(); | |
324 e_hit_test_data->surface_id_ = e_surface_id; | |
325 | |
326 auto e_hit_test_region_c1 = HitTestRegion::New(); | |
327 e_hit_test_region_c1->flags_ = HitTestRegionFlags::HIT_TEST_CHILD_SURFACE; | |
328 e_hit_test_region_c1->surface_id_ = c1_surface_id; | |
329 e_hit_test_region_c1->rect_.SetRect(100, 100, 700, 700); | |
330 | |
331 auto e_hit_test_region = HitTestRegion::New(); | |
332 e_hit_test_region->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
333 e_hit_test_region->surface_id_ = e_surface_id; | |
334 e_hit_test_region->rect_.SetRect(0, 0, 800, 800); | |
335 | |
336 e_hit_test_data->regions_.push_back(std::move(e_hit_test_region_c1)); | |
337 e_hit_test_data->regions_.push_back(std::move(e_hit_test_region)); | |
338 | |
339 auto c1_hit_test_data = HitTestData::New(); | |
340 c1_hit_test_data->surface_id_ = c1_surface_id; | |
341 | |
342 auto c1_hit_test_region_c2 = HitTestRegion::New(); | |
343 c1_hit_test_region_c2->flags_ = HitTestRegionFlags::HIT_TEST_CHILD_SURFACE; | |
344 c1_hit_test_region_c2->surface_id_ = c2_surface_id; | |
345 c1_hit_test_region_c2->rect_.SetRect(100, 100, 500, 500); | |
346 | |
347 auto c1_hit_test_region = HitTestRegion::New(); | |
348 c1_hit_test_region->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
349 c1_hit_test_region->surface_id_ = c1_surface_id; | |
350 c1_hit_test_region->rect_.SetRect(0, 0, 600, 600); | |
351 | |
352 c1_hit_test_data->regions_.push_back(std::move(c1_hit_test_region_c2)); | |
353 c1_hit_test_data->regions_.push_back(std::move(c1_hit_test_region)); | |
354 | |
355 auto c2_hit_test_data = HitTestData::New(); | |
356 c2_hit_test_data->surface_id_ = c2_surface_id; | |
357 | |
358 auto c2_hit_test_region_c3 = HitTestRegion::New(); | |
359 c2_hit_test_region_c3->flags_ = HitTestRegionFlags::HIT_TEST_CHILD_SURFACE; | |
360 c2_hit_test_region_c3->surface_id_ = c3_surface_id; | |
361 c2_hit_test_region_c3->rect_.SetRect(100, 100, 300, 300); | |
362 | |
363 auto c2_hit_test_region = HitTestRegion::New(); | |
364 c2_hit_test_region->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
365 c2_hit_test_region->surface_id_ = c2_surface_id; | |
366 c2_hit_test_region->rect_.SetRect(0, 0, 400, 400); | |
367 | |
368 c2_hit_test_data->regions_.push_back(std::move(c2_hit_test_region_c3)); | |
369 c2_hit_test_data->regions_.push_back(std::move(c2_hit_test_region)); | |
370 | |
371 auto c3_hit_test_data = HitTestData::New(); | |
372 c3_hit_test_data->surface_id_ = c3_surface_id; | |
373 | |
374 auto c3_hit_test_region = HitTestRegion::New(); | |
375 c3_hit_test_region->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
376 c3_hit_test_region->surface_id_ = c3_surface_id; | |
377 c3_hit_test_region->rect_.SetRect(0, 0, 200, 200); | |
378 | |
379 c3_hit_test_data->regions_.push_back(std::move(c3_hit_test_region)); | |
380 | |
381 // Submit ( in unexpected order ). | |
382 | |
383 EXPECT_TRUE(GetPendingCount() == 0); | |
384 | |
385 aggregator_.SubmitHitTestData(std::move(c1_hit_test_data)); | |
386 EXPECT_TRUE(GetPendingCount() == 1); | |
387 | |
388 aggregator_.SubmitHitTestData(std::move(c3_hit_test_data)); | |
389 EXPECT_TRUE(GetPendingCount() == 2); | |
390 | |
391 aggregator_.SubmitHitTestData(std::move(e_hit_test_data)); | |
392 EXPECT_TRUE(GetPendingCount() == 3); | |
393 | |
394 aggregator_.SubmitHitTestData(std::move(c2_hit_test_data)); | |
395 EXPECT_TRUE(GetPendingCount() == 4); | |
396 | |
397 // Surfaces added to DisplayFrame ( in unexpected order ). | |
398 | |
399 EXPECT_TRUE(count() == 0); | |
400 | |
401 EXPECT_TRUE(GetActiveCount() == 0); | |
402 | |
403 aggregator_.OnSurfaceWillDraw(c2_surface_id); | |
404 EXPECT_TRUE(GetActiveCount() == 1); | |
405 | |
406 aggregator_.OnSurfaceWillDraw(c1_surface_id); | |
407 EXPECT_TRUE(GetActiveCount() == 2); | |
408 | |
409 aggregator_.OnSurfaceWillDraw(e_surface_id); | |
410 EXPECT_TRUE(GetActiveCount() == 3); | |
411 | |
412 aggregator_.OnSurfaceWillDraw(c3_surface_id); | |
413 EXPECT_TRUE(GetActiveCount() == 4); | |
414 | |
415 // Aggregate and swap. | |
416 | |
417 aggregator_.Aggregate(e_surface_id); | |
418 EXPECT_TRUE(count() == 0); | |
419 | |
420 aggregator_.Swap(); | |
421 | |
422 EXPECT_TRUE(count() == 7); | |
423 | |
424 DisplayHitTestRegion* region; | |
425 | |
426 region = RegionAtIndex(0); | |
427 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_CHILD_SURFACE); | |
428 EXPECT_TRUE(region->frame_sink_id_ == c1_surface_id.frame_sink_id()); | |
429 EXPECT_TRUE(region->rect_ == gfx::Rect(100, 100, 700, 700)); | |
430 EXPECT_TRUE(region->child_count_ == 5); | |
431 | |
432 region = RegionAtIndex(1); | |
433 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_CHILD_SURFACE); | |
434 EXPECT_TRUE(region->frame_sink_id_ == c2_surface_id.frame_sink_id()); | |
435 EXPECT_TRUE(region->rect_ == gfx::Rect(100, 100, 500, 500)); | |
436 EXPECT_TRUE(region->child_count_ == 3); | |
437 | |
438 region = RegionAtIndex(2); | |
439 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_CHILD_SURFACE); | |
440 EXPECT_TRUE(region->frame_sink_id_ == c3_surface_id.frame_sink_id()); | |
441 EXPECT_TRUE(region->rect_ == gfx::Rect(100, 100, 300, 300)); | |
442 EXPECT_TRUE(region->child_count_ == 1); | |
443 | |
444 region = RegionAtIndex(3); | |
445 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
446 EXPECT_TRUE(region->frame_sink_id_ == c3_surface_id.frame_sink_id()); | |
447 EXPECT_TRUE(region->rect_ == gfx::Rect(0, 0, 200, 200)); | |
448 EXPECT_TRUE(region->child_count_ == 0); | |
449 | |
450 region = RegionAtIndex(4); | |
451 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
452 EXPECT_TRUE(region->frame_sink_id_ == c2_surface_id.frame_sink_id()); | |
453 EXPECT_TRUE(region->rect_ == gfx::Rect(0, 0, 400, 400)); | |
454 EXPECT_TRUE(region->child_count_ == 0); | |
455 | |
456 region = RegionAtIndex(5); | |
457 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
458 EXPECT_TRUE(region->frame_sink_id_ == c1_surface_id.frame_sink_id()); | |
459 EXPECT_TRUE(region->rect_ == gfx::Rect(0, 0, 600, 600)); | |
460 EXPECT_TRUE(region->child_count_ == 0); | |
461 | |
462 region = RegionAtIndex(6); | |
463 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
464 EXPECT_TRUE(region->frame_sink_id_ == e_surface_id.frame_sink_id()); | |
465 EXPECT_TRUE(region->rect_ == gfx::Rect(0, 0, 800, 800)); | |
466 EXPECT_TRUE(region->child_count_ == 0); | |
467 } | |
468 | |
469 // Occluded child frame ( OOPIF ). | |
470 // | |
471 // +e-----------+ | |
472 // | +c--+ | | |
473 // | | +div-+ | | |
474 // | | | | | | |
475 // | | +----+ | | |
476 // | +---+ | | |
477 // +------------+ | |
478 // | |
479 | |
480 TEST_F(HitTestAggregatorTest, OccludedChildFrame) { | |
481 Reset(); | |
482 EXPECT_TRUE(count() == 0); | |
483 | |
484 cc::SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1); | |
485 cc::SurfaceId c_surface_id = MakeSurfaceId(kDisplayFrameSink, 2); | |
486 | |
487 auto e_hit_test_data = HitTestData::New(); | |
488 e_hit_test_data->surface_id_ = e_surface_id; | |
489 | |
490 auto e_hit_test_region = HitTestRegion::New(); | |
491 e_hit_test_region->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
492 e_hit_test_region->surface_id_ = e_surface_id; | |
493 e_hit_test_region->rect_.SetRect(0, 0, 500, 500); | |
494 | |
495 auto e_hit_test_region_div = HitTestRegion::New(); | |
496 e_hit_test_region_div->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
497 e_hit_test_region_div->rect_.SetRect(100, 100, 400, 400); | |
498 | |
499 auto e_hit_test_region_c = HitTestRegion::New(); | |
500 e_hit_test_region_c->flags_ = HitTestRegionFlags::HIT_TEST_CHILD_SURFACE; | |
501 e_hit_test_region_c->surface_id_ = c_surface_id; | |
502 e_hit_test_region_c->rect_.SetRect(200, 200, 500, 200); | |
503 | |
504 e_hit_test_data->regions_.push_back(std::move(e_hit_test_region_div)); | |
505 e_hit_test_data->regions_.push_back(std::move(e_hit_test_region_c)); | |
506 e_hit_test_data->regions_.push_back(std::move(e_hit_test_region)); | |
507 | |
508 auto c_hit_test_data = HitTestData::New(); | |
509 c_hit_test_data->surface_id_ = c_surface_id; | |
510 | |
511 auto c_hit_test_region = HitTestRegion::New(); | |
512 c_hit_test_region->flags_ = HitTestRegionFlags::HIT_TEST_MINE; | |
513 c_hit_test_region->surface_id_ = c_surface_id; | |
514 c_hit_test_region->rect_.SetRect(0, 0, 300, 300); | |
515 | |
516 c_hit_test_data->regions_.push_back(std::move(c_hit_test_region)); | |
517 | |
518 // Submit ( in unexpected order ). | |
519 | |
520 EXPECT_TRUE(GetPendingCount() == 0); | |
521 | |
522 aggregator_.SubmitHitTestData(std::move(c_hit_test_data)); | |
523 EXPECT_TRUE(GetPendingCount() == 1); | |
524 | |
525 aggregator_.SubmitHitTestData(std::move(e_hit_test_data)); | |
526 EXPECT_TRUE(GetPendingCount() == 2); | |
527 | |
528 // Surfaces added to DisplayFrame ( in unexpected order ). | |
529 | |
530 EXPECT_TRUE(count() == 0); | |
531 | |
532 EXPECT_TRUE(GetActiveCount() == 0); | |
533 | |
534 aggregator_.OnSurfaceWillDraw(e_surface_id); | |
535 EXPECT_TRUE(GetActiveCount() == 1); | |
536 | |
537 aggregator_.OnSurfaceWillDraw(c_surface_id); | |
538 EXPECT_TRUE(GetActiveCount() == 2); | |
539 | |
540 // Aggregate and swap. | |
541 | |
542 aggregator_.Aggregate(e_surface_id); | |
543 EXPECT_TRUE(count() == 0); | |
544 | |
545 aggregator_.Swap(); | |
546 | |
547 EXPECT_TRUE(count() == 4); | |
548 | |
549 DisplayHitTestRegion* region; | |
550 | |
551 region = RegionAtIndex(0); | |
552 EXPECT_TRUE(region->rect_ == gfx::Rect(100, 100, 400, 400)); | |
553 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
554 EXPECT_TRUE(region->child_count_ == 0); | |
555 | |
556 region = RegionAtIndex(1); | |
557 EXPECT_TRUE(region->rect_ == gfx::Rect(200, 200, 500, 200)); | |
558 EXPECT_TRUE(region->frame_sink_id_ == c_surface_id.frame_sink_id()); | |
559 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_CHILD_SURFACE); | |
560 EXPECT_TRUE(region->child_count_ == 1); | |
561 | |
562 region = RegionAtIndex(2); | |
563 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
564 EXPECT_TRUE(region->frame_sink_id_ == c_surface_id.frame_sink_id()); | |
565 EXPECT_TRUE(region->rect_ == gfx::Rect(0, 0, 300, 300)); | |
566 EXPECT_TRUE(region->child_count_ == 0); | |
567 | |
568 region = RegionAtIndex(3); | |
569 EXPECT_TRUE(region->flags_ == HitTestRegionFlags::HIT_TEST_MINE); | |
570 EXPECT_TRUE(region->frame_sink_id_ == e_surface_id.frame_sink_id()); | |
571 EXPECT_TRUE(region->rect_ == gfx::Rect(0, 0, 500, 500)); | |
572 EXPECT_TRUE(region->child_count_ == 0); | |
573 } | |
574 | |
575 } // namespace test | |
rjkroege
2017/06/09 15:47:08
need at least one more corresponding to current bo
| |
576 } // namespace hit_test | |
577 } // namespace viz | |
OLD | NEW |