From f6069db89203f0797e4429c47ae268901c69a299 Mon Sep 17 00:00:00 2001 From: danakj Date: Fri, 12 Sep 2014 17:46:47 -0700 Subject: [PATCH] Propogate the clip rect for visible_content_rect into surfaces. Currently each render surface takes as its clip rect for visible content rects as the clip rect directly clipping its own surface, but drops the clip for visible content rects from outside the surface. This means that the viewport does not clip the visible_content_rect of any layers that aren't in the root surface. Fixed by intersecting this clip for visible content rects with the one from outside the surface. BUG=410625 Review URL: https://codereview.chromium.org/565353002 Cr-Commit-Position: refs/heads/master@{#294706} --- cc/trees/layer_tree_host_common.cc | 7 ++-- cc/trees/layer_tree_host_common_unittest.cc | 56 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/cc/trees/layer_tree_host_common.cc b/cc/trees/layer_tree_host_common.cc index 840a32b2ef4a..8d2553972591 100644 --- a/cc/trees/layer_tree_host_common.cc +++ b/cc/trees/layer_tree_host_common.cc @@ -1945,8 +1945,11 @@ static void CalculateDrawPropertiesInternal( // here, or DCHECK that the transform is invertible. } + gfx::Rect surface_clip_rect_in_target_space = gfx::IntersectRects( + data_from_ancestor.clip_rect_of_target_surface_in_target_space, + ancestor_clip_rect_in_target_space); gfx::Rect projected_surface_rect = MathUtil::ProjectEnclosingClippedRect( - inverse_surface_draw_transform, ancestor_clip_rect_in_target_space); + inverse_surface_draw_transform, surface_clip_rect_in_target_space); if (layer_draw_properties.num_unclipped_descendants > 0) { // If we have unclipped descendants, we cannot count on the render @@ -2327,7 +2330,7 @@ static void CalculateDrawPropertiesInternal( layer->render_target()->render_surface()-> AddContributingDelegatedRenderPassLayer(layer); } -} +} // NOLINT(readability/fn_size) template static void ProcessCalcDrawPropsInputs( diff --git a/cc/trees/layer_tree_host_common_unittest.cc b/cc/trees/layer_tree_host_common_unittest.cc index feed1ed02008..0b52e8a2286b 100644 --- a/cc/trees/layer_tree_host_common_unittest.cc +++ b/cc/trees/layer_tree_host_common_unittest.cc @@ -8559,5 +8559,61 @@ TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); } +TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { + scoped_refptr root = Layer::Create(); + SetLayerPropertiesForTesting(root.get(), + gfx::Transform(), + gfx::Point3F(), + gfx::PointF(), + gfx::Size(768 / 2, 3000), + true, + false); + root->SetIsDrawable(true); + + scoped_refptr clip = Layer::Create(); + SetLayerPropertiesForTesting(clip.get(), + gfx::Transform(), + gfx::Point3F(), + gfx::PointF(), + gfx::Size(768 / 2, 10000), + true, + false); + clip->SetMasksToBounds(true); + + scoped_refptr content = Layer::Create(); + SetLayerPropertiesForTesting(content.get(), + gfx::Transform(), + gfx::Point3F(), + gfx::PointF(), + gfx::Size(768 / 2, 10000), + true, + false); + content->SetIsDrawable(true); + content->SetForceRenderSurface(true); + + root->AddChild(clip); + clip->AddChild(content); + + scoped_ptr host = FakeLayerTreeHost::Create(); + host->SetRootLayer(root); + + gfx::Size device_viewport_size(768, 582); + RenderSurfaceLayerList render_surface_layer_list; + LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( + host->root_layer(), device_viewport_size, &render_surface_layer_list); + inputs.device_scale_factor = 2.f; + inputs.page_scale_factor = 1.f; + inputs.page_scale_application_layer = NULL; + LayerTreeHostCommon::CalculateDrawProperties(&inputs); + + // Layers in the root render surface have their visible content rect clipped + // by the viewport. + EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); + + // Layers drawing to a child render surface should still have their visible + // content rect clipped by the viewport. + EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); +} + } // namespace } // namespace cc -- 2.11.4.GIT