OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/layer_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 10223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10234 EXPECT_EQ(gfx::RectF(50.0f, 50.0f), | 10234 EXPECT_EQ(gfx::RectF(50.0f, 50.0f), |
10235 GetRenderSurface(copy_layer)->DrawableContentRect()); | 10235 GetRenderSurface(copy_layer)->DrawableContentRect()); |
10236 | 10236 |
10237 // Check test layer draw properties without copy request. | 10237 // Check test layer draw properties without copy request. |
10238 EXPECT_EQ(gfx::Rect(10, 10), test_layer->visible_layer_rect()); | 10238 EXPECT_EQ(gfx::Rect(10, 10), test_layer->visible_layer_rect()); |
10239 EXPECT_EQ(gfx::Transform(), test_layer->DrawTransform()); | 10239 EXPECT_EQ(gfx::Transform(), test_layer->DrawTransform()); |
10240 EXPECT_EQ(gfx::Rect(10, 10), test_layer->clip_rect()); | 10240 EXPECT_EQ(gfx::Rect(10, 10), test_layer->clip_rect()); |
10241 EXPECT_EQ(gfx::Rect(10, 10), test_layer->drawable_content_rect()); | 10241 EXPECT_EQ(gfx::Rect(10, 10), test_layer->drawable_content_rect()); |
10242 } | 10242 } |
10243 | 10243 |
| 10244 TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCacheRenderSurface) { |
| 10245 FakeImplTaskRunnerProvider task_runner_provider; |
| 10246 TestTaskGraphRunner task_graph_runner; |
| 10247 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
| 10248 host_impl.CreatePendingTree(); |
| 10249 |
| 10250 std::unique_ptr<LayerImpl> root = |
| 10251 LayerImpl::Create(host_impl.pending_tree(), 1); |
| 10252 root->SetBounds(gfx::Size(50, 50)); |
| 10253 root->SetDrawsContent(true); |
| 10254 LayerImpl* root_layer = root.get(); |
| 10255 |
| 10256 std::unique_ptr<LayerImpl> cache_grand_parent = |
| 10257 LayerImpl::Create(host_impl.pending_tree(), 2); |
| 10258 cache_grand_parent->SetBounds(gfx::Size(40, 40)); |
| 10259 cache_grand_parent->SetDrawsContent(true); |
| 10260 LayerImpl* cache_grand_parent_layer = cache_grand_parent.get(); |
| 10261 |
| 10262 std::unique_ptr<LayerImpl> cache_parent = |
| 10263 LayerImpl::Create(host_impl.pending_tree(), 3); |
| 10264 cache_parent->SetBounds(gfx::Size(30, 30)); |
| 10265 cache_parent->SetDrawsContent(true); |
| 10266 cache_parent->test_properties()->force_render_surface = true; |
| 10267 LayerImpl* cache_parent_layer = cache_parent.get(); |
| 10268 |
| 10269 std::unique_ptr<LayerImpl> cache_render_surface = |
| 10270 LayerImpl::Create(host_impl.pending_tree(), 4); |
| 10271 cache_render_surface->SetBounds(gfx::Size(20, 20)); |
| 10272 cache_render_surface->SetDrawsContent(true); |
| 10273 cache_render_surface->test_properties()->cache_render_surface = true; |
| 10274 LayerImpl* cache_layer = cache_render_surface.get(); |
| 10275 |
| 10276 std::unique_ptr<LayerImpl> cache_child = |
| 10277 LayerImpl::Create(host_impl.pending_tree(), 5); |
| 10278 cache_child->SetBounds(gfx::Size(20, 20)); |
| 10279 cache_child->SetDrawsContent(true); |
| 10280 LayerImpl* cache_child_layer = cache_child.get(); |
| 10281 |
| 10282 std::unique_ptr<LayerImpl> cache_grand_child = |
| 10283 LayerImpl::Create(host_impl.pending_tree(), 6); |
| 10284 cache_grand_child->SetBounds(gfx::Size(20, 20)); |
| 10285 cache_grand_child->SetDrawsContent(true); |
| 10286 LayerImpl* cache_grand_child_layer = cache_grand_child.get(); |
| 10287 |
| 10288 std::unique_ptr<LayerImpl> cache_grand_parent_sibling_before = |
| 10289 LayerImpl::Create(host_impl.pending_tree(), 7); |
| 10290 cache_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40)); |
| 10291 cache_grand_parent_sibling_before->SetDrawsContent(true); |
| 10292 LayerImpl* cache_grand_parent_sibling_before_layer = |
| 10293 cache_grand_parent_sibling_before.get(); |
| 10294 |
| 10295 std::unique_ptr<LayerImpl> cache_grand_parent_sibling_after = |
| 10296 LayerImpl::Create(host_impl.pending_tree(), 8); |
| 10297 cache_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40)); |
| 10298 cache_grand_parent_sibling_after->SetDrawsContent(true); |
| 10299 LayerImpl* cache_grand_parent_sibling_after_layer = |
| 10300 cache_grand_parent_sibling_after.get(); |
| 10301 |
| 10302 cache_child->test_properties()->AddChild(std::move(cache_grand_child)); |
| 10303 cache_render_surface->test_properties()->AddChild(std::move(cache_child)); |
| 10304 cache_parent->test_properties()->AddChild(std::move(cache_render_surface)); |
| 10305 cache_grand_parent->test_properties()->AddChild(std::move(cache_parent)); |
| 10306 root->test_properties()->AddChild( |
| 10307 std::move(cache_grand_parent_sibling_before)); |
| 10308 root->test_properties()->AddChild(std::move(cache_grand_parent)); |
| 10309 root->test_properties()->AddChild( |
| 10310 std::move(cache_grand_parent_sibling_after)); |
| 10311 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
| 10312 |
| 10313 // Hide the cache_grand_parent and its subtree. But cache a render surface in |
| 10314 // that hidden subtree on cache_layer. Also hide the cache grand child and its |
| 10315 // subtree. |
| 10316 cache_grand_parent_layer->test_properties()->hide_layer_and_subtree = true; |
| 10317 cache_grand_parent_sibling_before_layer->test_properties() |
| 10318 ->hide_layer_and_subtree = true; |
| 10319 cache_grand_parent_sibling_after_layer->test_properties() |
| 10320 ->hide_layer_and_subtree = true; |
| 10321 cache_grand_child_layer->test_properties()->hide_layer_and_subtree = true; |
| 10322 |
| 10323 RenderSurfaceList render_surface_list; |
| 10324 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 10325 root_layer, root_layer->bounds(), &render_surface_list); |
| 10326 inputs.can_adjust_raster_scales = true; |
| 10327 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 10328 |
| 10329 // We should have four render surfaces, one for the root, one for the grand |
| 10330 // parent since it has opacity and two drawing descendants, one for the parent |
| 10331 // since it owns a surface, and one for the cache_layer. |
| 10332 ASSERT_EQ(4u, render_surface_list.size()); |
| 10333 EXPECT_EQ(static_cast<uint64_t>(root_layer->id()), |
| 10334 render_surface_list.at(0)->id()); |
| 10335 EXPECT_EQ(static_cast<uint64_t>(cache_grand_parent_layer->id()), |
| 10336 render_surface_list.at(1)->id()); |
| 10337 EXPECT_EQ(static_cast<uint64_t>(cache_parent_layer->id()), |
| 10338 render_surface_list.at(2)->id()); |
| 10339 EXPECT_EQ(static_cast<uint64_t>(cache_layer->id()), |
| 10340 render_surface_list.at(3)->id()); |
| 10341 |
| 10342 // The root render surface should have 2 contributing layers. |
| 10343 EXPECT_EQ(2, GetRenderSurface(root_layer)->num_contributors()); |
| 10344 EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface()); |
| 10345 EXPECT_FALSE(cache_grand_parent_layer->contributes_to_drawn_render_surface()); |
| 10346 EXPECT_FALSE(cache_grand_parent_sibling_before_layer |
| 10347 ->contributes_to_drawn_render_surface()); |
| 10348 EXPECT_FALSE(cache_grand_parent_sibling_after_layer |
| 10349 ->contributes_to_drawn_render_surface()); |
| 10350 |
| 10351 // Nothing actually draws into the cache parent, so only the cache_layer will |
| 10352 // appear in its list, since it needs to be drawn for the cache render |
| 10353 // surface. |
| 10354 ASSERT_EQ(1, GetRenderSurface(cache_parent_layer)->num_contributors()); |
| 10355 EXPECT_FALSE(cache_parent_layer->contributes_to_drawn_render_surface()); |
| 10356 |
| 10357 // The cache layer's render surface should have 2 contributing layers. |
| 10358 ASSERT_EQ(2, GetRenderSurface(cache_layer)->num_contributors()); |
| 10359 EXPECT_TRUE(cache_layer->contributes_to_drawn_render_surface()); |
| 10360 EXPECT_TRUE(cache_child_layer->contributes_to_drawn_render_surface()); |
| 10361 EXPECT_FALSE(cache_grand_child_layer->contributes_to_drawn_render_surface()); |
| 10362 |
| 10363 // cache_grand_parent, cache_parent shouldn't be drawn because they are |
| 10364 // hidden, but the cache_layer and cache_child should be drawn for the cache |
| 10365 // render surface. cache grand child should not be drawn as its hidden even in |
| 10366 // the cache render surface. |
| 10367 EffectTree& tree = |
| 10368 root_layer->layer_tree_impl()->property_trees()->effect_tree; |
| 10369 EffectNode* node = tree.Node(cache_grand_parent_layer->effect_tree_index()); |
| 10370 EXPECT_FALSE(node->is_drawn); |
| 10371 node = tree.Node(cache_parent_layer->effect_tree_index()); |
| 10372 EXPECT_FALSE(node->is_drawn); |
| 10373 node = tree.Node(cache_layer->effect_tree_index()); |
| 10374 EXPECT_TRUE(node->is_drawn); |
| 10375 node = tree.Node(cache_child_layer->effect_tree_index()); |
| 10376 EXPECT_TRUE(node->is_drawn); |
| 10377 node = tree.Node(cache_grand_child_layer->effect_tree_index()); |
| 10378 EXPECT_FALSE(node->is_drawn); |
| 10379 |
| 10380 // Though cache_layer is drawn, it shouldn't contribute to drawn surface as |
| 10381 // its actually hidden. |
| 10382 EXPECT_FALSE(GetRenderSurface(cache_layer)->contributes_to_drawn_surface()); |
| 10383 } |
| 10384 |
| 10385 TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCacheRenderSurface) { |
| 10386 LayerImpl* root = root_layer_for_testing(); |
| 10387 root->SetBounds(gfx::Size(50, 50)); |
| 10388 root->SetDrawsContent(true); |
| 10389 root->SetMasksToBounds(true); |
| 10390 |
| 10391 LayerImpl* cache_render_surface_layer = AddChild<LayerImpl>(root); |
| 10392 cache_render_surface_layer->SetBounds(gfx::Size(120, 120)); |
| 10393 cache_render_surface_layer->SetDrawsContent(true); |
| 10394 cache_render_surface_layer->test_properties()->cache_render_surface = true; |
| 10395 |
| 10396 LayerImpl* copy_layer = AddChild<LayerImpl>(cache_render_surface_layer); |
| 10397 copy_layer->SetBounds(gfx::Size(100, 100)); |
| 10398 copy_layer->SetDrawsContent(true); |
| 10399 copy_layer->test_properties()->force_render_surface = true; |
| 10400 |
| 10401 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer); |
| 10402 copy_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 10403 copy_child->SetBounds(gfx::Size(20, 20)); |
| 10404 copy_child->SetDrawsContent(true); |
| 10405 |
| 10406 LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer); |
| 10407 copy_clip->SetBounds(gfx::Size(55, 55)); |
| 10408 copy_clip->SetMasksToBounds(true); |
| 10409 |
| 10410 LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip); |
| 10411 copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 10412 copy_clipped_child->SetBounds(gfx::Size(20, 20)); |
| 10413 copy_clipped_child->SetDrawsContent(true); |
| 10414 |
| 10415 LayerImpl* cache_surface = AddChild<LayerImpl>(copy_clip); |
| 10416 cache_surface->SetPosition(gfx::PointF(45.f, 45.f)); |
| 10417 cache_surface->SetBounds(gfx::Size(20, 20)); |
| 10418 cache_surface->SetDrawsContent(true); |
| 10419 |
| 10420 ExecuteCalculateDrawProperties(root); |
| 10421 EXPECT_EQ(gfx::Rect(120, 120), |
| 10422 cache_render_surface_layer->visible_layer_rect()); |
| 10423 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect()); |
| 10424 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect()); |
| 10425 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect()); |
| 10426 EXPECT_EQ(gfx::Rect(10, 10), cache_surface->visible_layer_rect()); |
| 10427 |
| 10428 // Case 2: When the non root cache render surface layer is clipped. |
| 10429 cache_render_surface_layer->SetBounds(gfx::Size(50, 50)); |
| 10430 cache_render_surface_layer->SetMasksToBounds(true); |
| 10431 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 10432 ExecuteCalculateDrawProperties(root); |
| 10433 EXPECT_EQ(gfx::Rect(50, 50), |
| 10434 cache_render_surface_layer->visible_layer_rect()); |
| 10435 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 10436 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 10437 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 10438 EXPECT_EQ(gfx::Rect(5, 5), cache_surface->visible_layer_rect()); |
| 10439 |
| 10440 // Case 3: When there is device scale factor. |
| 10441 float device_scale_factor = 2.f; |
| 10442 ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 10443 EXPECT_EQ(gfx::Rect(50, 50), |
| 10444 cache_render_surface_layer->visible_layer_rect()); |
| 10445 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 10446 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 10447 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 10448 EXPECT_EQ(gfx::Rect(5, 5), cache_surface->visible_layer_rect()); |
| 10449 |
| 10450 // Case 4: When the non root cache render surface layer is clipped and there |
| 10451 // is a copy request layer beneath it. |
| 10452 copy_layer->test_properties()->copy_requests.push_back( |
| 10453 viz::CopyOutputRequest::CreateRequest( |
| 10454 base::Bind(&EmptyCopyOutputCallback))); |
| 10455 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 10456 DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
| 10457 ExecuteCalculateDrawProperties(root); |
| 10458 DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
| 10459 EXPECT_EQ(gfx::Rect(50, 50), |
| 10460 cache_render_surface_layer->visible_layer_rect()); |
| 10461 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect()); |
| 10462 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect()); |
| 10463 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect()); |
| 10464 EXPECT_EQ(gfx::Rect(10, 10), cache_surface->visible_layer_rect()); |
| 10465 |
| 10466 // Case 5: When there is another cache render surface layer under the copy |
| 10467 // request layer. |
| 10468 cache_surface->test_properties()->cache_render_surface = true; |
| 10469 copy_layer->test_properties()->copy_requests.push_back( |
| 10470 viz::CopyOutputRequest::CreateRequest( |
| 10471 base::Bind(&EmptyCopyOutputCallback))); |
| 10472 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 10473 DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
| 10474 ExecuteCalculateDrawProperties(root); |
| 10475 DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
| 10476 EXPECT_EQ(gfx::Rect(50, 50), |
| 10477 cache_render_surface_layer->visible_layer_rect()); |
| 10478 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect()); |
| 10479 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect()); |
| 10480 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect()); |
| 10481 EXPECT_EQ(gfx::Rect(20, 20), cache_surface->visible_layer_rect()); |
| 10482 } |
| 10483 |
10244 } // namespace | 10484 } // namespace |
10245 } // namespace cc | 10485 } // namespace cc |
OLD | NEW |