Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(738)

Side by Side Diff: cc/trees/layer_tree_host_common_unittest.cc

Issue 2873593002: Force use of and cache render surface. (Closed)
Patch Set: Rebased to resolve conflict. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_common.cc ('k') | cc/trees/occlusion_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10148 matching lines...) Expand 10 before | Expand all | Expand 10 after
10159 EXPECT_EQ(gfx::RectF(50.0f, 50.0f), 10159 EXPECT_EQ(gfx::RectF(50.0f, 50.0f),
10160 GetRenderSurface(copy_layer)->DrawableContentRect()); 10160 GetRenderSurface(copy_layer)->DrawableContentRect());
10161 10161
10162 // Check test layer draw properties without copy request. 10162 // Check test layer draw properties without copy request.
10163 EXPECT_EQ(gfx::Rect(10, 10), test_layer->visible_layer_rect()); 10163 EXPECT_EQ(gfx::Rect(10, 10), test_layer->visible_layer_rect());
10164 EXPECT_EQ(gfx::Transform(), test_layer->DrawTransform()); 10164 EXPECT_EQ(gfx::Transform(), test_layer->DrawTransform());
10165 EXPECT_EQ(gfx::Rect(10, 10), test_layer->clip_rect()); 10165 EXPECT_EQ(gfx::Rect(10, 10), test_layer->clip_rect());
10166 EXPECT_EQ(gfx::Rect(10, 10), test_layer->drawable_content_rect()); 10166 EXPECT_EQ(gfx::Rect(10, 10), test_layer->drawable_content_rect());
10167 } 10167 }
10168 10168
10169 TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCacheRenderSurface) {
10170 FakeImplTaskRunnerProvider task_runner_provider;
10171 TestTaskGraphRunner task_graph_runner;
10172 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
10173 host_impl.CreatePendingTree();
10174
10175 std::unique_ptr<LayerImpl> root =
10176 LayerImpl::Create(host_impl.pending_tree(), 1);
10177 root->SetBounds(gfx::Size(50, 50));
10178 root->SetDrawsContent(true);
10179 LayerImpl* root_layer = root.get();
10180
10181 std::unique_ptr<LayerImpl> cache_grand_parent =
10182 LayerImpl::Create(host_impl.pending_tree(), 2);
10183 cache_grand_parent->SetBounds(gfx::Size(40, 40));
10184 cache_grand_parent->SetDrawsContent(true);
10185 LayerImpl* cache_grand_parent_layer = cache_grand_parent.get();
10186
10187 std::unique_ptr<LayerImpl> cache_parent =
10188 LayerImpl::Create(host_impl.pending_tree(), 3);
10189 cache_parent->SetBounds(gfx::Size(30, 30));
10190 cache_parent->SetDrawsContent(true);
10191 cache_parent->test_properties()->force_render_surface = true;
10192 LayerImpl* cache_parent_layer = cache_parent.get();
10193
10194 std::unique_ptr<LayerImpl> cache_render_surface =
10195 LayerImpl::Create(host_impl.pending_tree(), 4);
10196 cache_render_surface->SetBounds(gfx::Size(20, 20));
10197 cache_render_surface->SetDrawsContent(true);
10198 cache_render_surface->test_properties()->cache_render_surface = true;
10199 LayerImpl* cache_layer = cache_render_surface.get();
10200
10201 std::unique_ptr<LayerImpl> cache_child =
10202 LayerImpl::Create(host_impl.pending_tree(), 5);
10203 cache_child->SetBounds(gfx::Size(20, 20));
10204 cache_child->SetDrawsContent(true);
10205 LayerImpl* cache_child_layer = cache_child.get();
10206
10207 std::unique_ptr<LayerImpl> cache_grand_child =
10208 LayerImpl::Create(host_impl.pending_tree(), 6);
10209 cache_grand_child->SetBounds(gfx::Size(20, 20));
10210 cache_grand_child->SetDrawsContent(true);
10211 LayerImpl* cache_grand_child_layer = cache_grand_child.get();
10212
10213 std::unique_ptr<LayerImpl> cache_grand_parent_sibling_before =
10214 LayerImpl::Create(host_impl.pending_tree(), 7);
10215 cache_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40));
10216 cache_grand_parent_sibling_before->SetDrawsContent(true);
10217 LayerImpl* cache_grand_parent_sibling_before_layer =
10218 cache_grand_parent_sibling_before.get();
10219
10220 std::unique_ptr<LayerImpl> cache_grand_parent_sibling_after =
10221 LayerImpl::Create(host_impl.pending_tree(), 8);
10222 cache_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40));
10223 cache_grand_parent_sibling_after->SetDrawsContent(true);
10224 LayerImpl* cache_grand_parent_sibling_after_layer =
10225 cache_grand_parent_sibling_after.get();
10226
10227 cache_child->test_properties()->AddChild(std::move(cache_grand_child));
10228 cache_render_surface->test_properties()->AddChild(std::move(cache_child));
10229 cache_parent->test_properties()->AddChild(std::move(cache_render_surface));
10230 cache_grand_parent->test_properties()->AddChild(std::move(cache_parent));
10231 root->test_properties()->AddChild(
10232 std::move(cache_grand_parent_sibling_before));
10233 root->test_properties()->AddChild(std::move(cache_grand_parent));
10234 root->test_properties()->AddChild(
10235 std::move(cache_grand_parent_sibling_after));
10236 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
10237
10238 // Hide the cache_grand_parent and its subtree. But cache a render surface in
10239 // that hidden subtree on cache_layer. Also hide the cache grand child and its
10240 // subtree.
10241 cache_grand_parent_layer->test_properties()->hide_layer_and_subtree = true;
10242 cache_grand_parent_sibling_before_layer->test_properties()
10243 ->hide_layer_and_subtree = true;
10244 cache_grand_parent_sibling_after_layer->test_properties()
10245 ->hide_layer_and_subtree = true;
10246 cache_grand_child_layer->test_properties()->hide_layer_and_subtree = true;
10247
10248 RenderSurfaceList render_surface_list;
10249 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
10250 root_layer, root_layer->bounds(), &render_surface_list);
10251 inputs.can_adjust_raster_scales = true;
10252 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
10253
10254 // We should have four render surfaces, one for the root, one for the grand
10255 // parent since it has opacity and two drawing descendants, one for the parent
10256 // since it owns a surface, and one for the cache_layer.
10257 ASSERT_EQ(4u, render_surface_list.size());
10258 EXPECT_EQ(static_cast<uint64_t>(root_layer->id()),
10259 render_surface_list.at(0)->id());
10260 EXPECT_EQ(static_cast<uint64_t>(cache_grand_parent_layer->id()),
10261 render_surface_list.at(1)->id());
10262 EXPECT_EQ(static_cast<uint64_t>(cache_parent_layer->id()),
10263 render_surface_list.at(2)->id());
10264 EXPECT_EQ(static_cast<uint64_t>(cache_layer->id()),
10265 render_surface_list.at(3)->id());
10266
10267 // The root render surface should have 2 contributing layers.
10268 EXPECT_EQ(2, GetRenderSurface(root_layer)->num_contributors());
10269 EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface());
10270 EXPECT_FALSE(cache_grand_parent_layer->contributes_to_drawn_render_surface());
10271 EXPECT_FALSE(cache_grand_parent_sibling_before_layer
10272 ->contributes_to_drawn_render_surface());
10273 EXPECT_FALSE(cache_grand_parent_sibling_after_layer
10274 ->contributes_to_drawn_render_surface());
10275
10276 // Nothing actually draws into the cache parent, so only the cache_layer will
10277 // appear in its list, since it needs to be drawn for the cache render
10278 // surface.
10279 ASSERT_EQ(1, GetRenderSurface(cache_parent_layer)->num_contributors());
10280 EXPECT_FALSE(cache_parent_layer->contributes_to_drawn_render_surface());
10281
10282 // The cache layer's render surface should have 2 contributing layers.
10283 ASSERT_EQ(2, GetRenderSurface(cache_layer)->num_contributors());
10284 EXPECT_TRUE(cache_layer->contributes_to_drawn_render_surface());
10285 EXPECT_TRUE(cache_child_layer->contributes_to_drawn_render_surface());
10286 EXPECT_FALSE(cache_grand_child_layer->contributes_to_drawn_render_surface());
10287
10288 // cache_grand_parent, cache_parent shouldn't be drawn because they are
10289 // hidden, but the cache_layer and cache_child should be drawn for the cache
10290 // render surface. cache grand child should not be drawn as its hidden even in
10291 // the cache render surface.
10292 EffectTree& tree =
10293 root_layer->layer_tree_impl()->property_trees()->effect_tree;
10294 EffectNode* node = tree.Node(cache_grand_parent_layer->effect_tree_index());
10295 EXPECT_FALSE(node->is_drawn);
10296 node = tree.Node(cache_parent_layer->effect_tree_index());
10297 EXPECT_FALSE(node->is_drawn);
10298 node = tree.Node(cache_layer->effect_tree_index());
10299 EXPECT_TRUE(node->is_drawn);
10300 node = tree.Node(cache_child_layer->effect_tree_index());
10301 EXPECT_TRUE(node->is_drawn);
10302 node = tree.Node(cache_grand_child_layer->effect_tree_index());
10303 EXPECT_FALSE(node->is_drawn);
10304
10305 // Though cache_layer is drawn, it shouldn't contribute to drawn surface as
10306 // its actually hidden.
10307 EXPECT_FALSE(GetRenderSurface(cache_layer)->contributes_to_drawn_surface());
10308 }
10309
10310 TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCacheRenderSurface) {
10311 LayerImpl* root = root_layer_for_testing();
10312 root->SetBounds(gfx::Size(50, 50));
10313 root->SetDrawsContent(true);
10314 root->SetMasksToBounds(true);
10315
10316 LayerImpl* cache_render_surface_layer = AddChild<LayerImpl>(root);
10317 cache_render_surface_layer->SetBounds(gfx::Size(120, 120));
10318 cache_render_surface_layer->SetDrawsContent(true);
10319 cache_render_surface_layer->test_properties()->cache_render_surface = true;
10320
10321 LayerImpl* copy_layer = AddChild<LayerImpl>(cache_render_surface_layer);
10322 copy_layer->SetBounds(gfx::Size(100, 100));
10323 copy_layer->SetDrawsContent(true);
10324 copy_layer->test_properties()->force_render_surface = true;
10325
10326 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
10327 copy_child->SetPosition(gfx::PointF(40.f, 40.f));
10328 copy_child->SetBounds(gfx::Size(20, 20));
10329 copy_child->SetDrawsContent(true);
10330
10331 LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer);
10332 copy_clip->SetBounds(gfx::Size(55, 55));
10333 copy_clip->SetMasksToBounds(true);
10334
10335 LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip);
10336 copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f));
10337 copy_clipped_child->SetBounds(gfx::Size(20, 20));
10338 copy_clipped_child->SetDrawsContent(true);
10339
10340 LayerImpl* cache_surface = AddChild<LayerImpl>(copy_clip);
10341 cache_surface->SetPosition(gfx::PointF(45.f, 45.f));
10342 cache_surface->SetBounds(gfx::Size(20, 20));
10343 cache_surface->SetDrawsContent(true);
10344
10345 ExecuteCalculateDrawProperties(root);
10346 EXPECT_EQ(gfx::Rect(120, 120),
10347 cache_render_surface_layer->visible_layer_rect());
10348 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect());
10349 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect());
10350 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect());
10351 EXPECT_EQ(gfx::Rect(10, 10), cache_surface->visible_layer_rect());
10352
10353 // Case 2: When the non root cache render surface layer is clipped.
10354 cache_render_surface_layer->SetBounds(gfx::Size(50, 50));
10355 cache_render_surface_layer->SetMasksToBounds(true);
10356 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
10357 ExecuteCalculateDrawProperties(root);
10358 EXPECT_EQ(gfx::Rect(50, 50),
10359 cache_render_surface_layer->visible_layer_rect());
10360 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
10361 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
10362 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
10363 EXPECT_EQ(gfx::Rect(5, 5), cache_surface->visible_layer_rect());
10364
10365 // Case 3: When there is device scale factor.
10366 float device_scale_factor = 2.f;
10367 ExecuteCalculateDrawProperties(root, device_scale_factor);
10368 EXPECT_EQ(gfx::Rect(50, 50),
10369 cache_render_surface_layer->visible_layer_rect());
10370 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
10371 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
10372 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
10373 EXPECT_EQ(gfx::Rect(5, 5), cache_surface->visible_layer_rect());
10374
10375 // Case 4: When the non root cache render surface layer is clipped and there
10376 // is a copy request layer beneath it.
10377 copy_layer->test_properties()->copy_requests.push_back(
10378 viz::CopyOutputRequest::CreateRequest(
10379 base::Bind(&EmptyCopyOutputCallback)));
10380 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
10381 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
10382 ExecuteCalculateDrawProperties(root);
10383 DCHECK(copy_layer->test_properties()->copy_requests.empty());
10384 EXPECT_EQ(gfx::Rect(50, 50),
10385 cache_render_surface_layer->visible_layer_rect());
10386 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect());
10387 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect());
10388 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect());
10389 EXPECT_EQ(gfx::Rect(10, 10), cache_surface->visible_layer_rect());
10390
10391 // Case 5: When there is another cache render surface layer under the copy
10392 // request layer.
10393 cache_surface->test_properties()->cache_render_surface = true;
10394 copy_layer->test_properties()->copy_requests.push_back(
10395 viz::CopyOutputRequest::CreateRequest(
10396 base::Bind(&EmptyCopyOutputCallback)));
10397 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
10398 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
10399 ExecuteCalculateDrawProperties(root);
10400 DCHECK(copy_layer->test_properties()->copy_requests.empty());
10401 EXPECT_EQ(gfx::Rect(50, 50),
10402 cache_render_surface_layer->visible_layer_rect());
10403 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect());
10404 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect());
10405 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect());
10406 EXPECT_EQ(gfx::Rect(20, 20), cache_surface->visible_layer_rect());
10407 }
10408
10169 } // namespace 10409 } // namespace
10170 } // namespace cc 10410 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_common.cc ('k') | cc/trees/occlusion_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698