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