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