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