ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
danakj | 6496cba | 2014-10-16 01:31:08 | [diff] [blame] | 9 | #include <algorithm> |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 11 | #include <set> |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 13 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 14 | #include "base/memory/ptr_util.h" |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 15 | #include "cc/animation/animation_host.h" |
| 16 | #include "cc/animation/animation_id_provider.h" |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 17 | #include "cc/animation/animation_player.h" |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 18 | #include "cc/animation/keyframed_animation_curve.h" |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 19 | #include "cc/animation/transform_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 20 | #include "cc/base/math_util.h" |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 21 | #include "cc/input/main_thread_scrolling_reason.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 22 | #include "cc/layers/content_layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 23 | #include "cc/layers/layer.h" |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 24 | #include "cc/layers/layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 25 | #include "cc/layers/layer_impl.h" |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 26 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 27 | #include "cc/layers/render_surface_impl.h" |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 28 | #include "cc/layers/texture_layer_impl.h" |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 29 | #include "cc/output/copy_output_request.h" |
| 30 | #include "cc/output/copy_output_result.h" |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 31 | #include "cc/proto/begin_main_frame_and_commit_state.pb.h" |
| 32 | #include "cc/proto/gfx_conversions.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 33 | #include "cc/test/animation_test_common.h" |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 34 | #include "cc/test/fake_compositor_frame_sink.h" |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 35 | #include "cc/test/fake_content_layer_client.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 36 | #include "cc/test/fake_impl_task_runner_provider.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 37 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 38 | #include "cc/test/fake_layer_tree_host_impl.h" |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 39 | #include "cc/test/fake_picture_layer.h" |
| 40 | #include "cc/test/fake_picture_layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 41 | #include "cc/test/geometry_test_utils.h" |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 42 | #include "cc/test/layer_test_common.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 43 | #include "cc/test/test_task_graph_runner.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 44 | #include "cc/trees/clip_node.h" |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 45 | #include "cc/trees/draw_property_utils.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 46 | #include "cc/trees/effect_node.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 47 | #include "cc/trees/layer_tree_impl.h" |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 48 | #include "cc/trees/property_tree_builder.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 49 | #include "cc/trees/scroll_node.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 50 | #include "cc/trees/single_thread_proxy.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 51 | #include "cc/trees/task_runner_provider.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 52 | #include "cc/trees/transform_node.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 53 | #include "testing/gtest/include/gtest/gtest.h" |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 54 | #include "third_party/skia/include/effects/SkOffsetImageFilter.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 55 | #include "ui/gfx/geometry/quad_f.h" |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 56 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 57 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 58 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 59 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 60 | namespace { |
| 61 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 62 | class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings { |
| 63 | public: |
| 64 | VerifyTreeCalcsLayerTreeSettings() { |
jaydasika | 853306a | 2016-07-29 19:28:34 | [diff] [blame] | 65 | verify_clip_tree_calculations = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 66 | } |
| 67 | }; |
| 68 | |
| 69 | class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { |
| 70 | public: |
| 71 | LayerTreeHostCommonTestBase() |
| 72 | : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {} |
| 73 | explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings) |
| 74 | : LayerTestCommon::LayerImplTest(settings) {} |
| 75 | |
| 76 | static void SetScrollOffsetDelta(LayerImpl* layer_impl, |
| 77 | const gfx::Vector2dF& delta) { |
| 78 | if (layer_impl->layer_tree_impl() |
| 79 | ->property_trees() |
| 80 | ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(), |
| 81 | delta)) |
vollick | c969691 | 2016-09-16 16:02:47 | [diff] [blame] | 82 | layer_impl->layer_tree_impl()->DidUpdateScrollOffset(layer_impl->id()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static float GetMaximumAnimationScale(LayerImpl* layer_impl) { |
| 86 | return layer_impl->layer_tree_impl() |
| 87 | ->property_trees() |
| 88 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 89 | layer_impl->layer_tree_impl()) |
| 90 | .maximum_animation_scale; |
| 91 | } |
| 92 | |
| 93 | static float GetStartingAnimationScale(LayerImpl* layer_impl) { |
| 94 | return layer_impl->layer_tree_impl() |
| 95 | ->property_trees() |
| 96 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 97 | layer_impl->layer_tree_impl()) |
| 98 | .starting_animation_scale; |
| 99 | } |
| 100 | |
| 101 | void ExecuteCalculateDrawProperties(Layer* root_layer, |
| 102 | float device_scale_factor, |
| 103 | float page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 104 | Layer* page_scale_layer, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 105 | Layer* inner_viewport_scroll_layer, |
| 106 | Layer* outer_viewport_scroll_layer) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 107 | PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 108 | |
| 109 | EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 110 | gfx::Size device_viewport_size = |
| 111 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 112 | root_layer->bounds().height() * device_scale_factor); |
| 113 | |
| 114 | // We are probably not testing what is intended if the root_layer bounds are |
| 115 | // empty. |
| 116 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 117 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 118 | root_layer, device_viewport_size); |
| 119 | inputs.device_scale_factor = device_scale_factor; |
| 120 | inputs.page_scale_factor = page_scale_factor; |
| 121 | inputs.page_scale_layer = page_scale_layer; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 122 | inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 123 | inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 124 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 125 | } |
| 126 | |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 127 | void ExecuteCalculateDrawProperties( |
| 128 | LayerImpl* root_layer, |
| 129 | float device_scale_factor, |
| 130 | float page_scale_factor, |
| 131 | LayerImpl* page_scale_layer, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 132 | LayerImpl* inner_viewport_scroll_layer, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 133 | LayerImpl* outer_viewport_scroll_layer, |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 134 | bool skip_verify_visible_rect_calculations = false) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 135 | if (device_scale_factor != |
| 136 | root_layer->layer_tree_impl()->device_scale_factor()) |
| 137 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 138 | |
| 139 | root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); |
| 140 | |
| 141 | EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 142 | |
| 143 | gfx::Size device_viewport_size = |
| 144 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 145 | root_layer->bounds().height() * device_scale_factor); |
| 146 | |
| 147 | render_surface_layer_list_impl_.reset(new LayerImplList); |
| 148 | |
| 149 | // We are probably not testing what is intended if the root_layer bounds are |
| 150 | // empty. |
| 151 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 152 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 153 | root_layer, device_viewport_size, |
| 154 | render_surface_layer_list_impl_.get()); |
| 155 | inputs.device_scale_factor = device_scale_factor; |
| 156 | inputs.page_scale_factor = page_scale_factor; |
| 157 | inputs.page_scale_layer = page_scale_layer; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 158 | inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 159 | inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 160 | inputs.can_adjust_raster_scales = true; |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 161 | if (skip_verify_visible_rect_calculations) |
| 162 | inputs.verify_visible_rect_calculations = false; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 163 | |
| 164 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 165 | } |
| 166 | |
| 167 | template <class LayerType> |
| 168 | void ExecuteCalculateDrawProperties(LayerType* root_layer) { |
| 169 | LayerType* page_scale_application_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 170 | LayerType* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 171 | LayerType* outer_viewport_scroll_layer = nullptr; |
| 172 | ExecuteCalculateDrawProperties( |
| 173 | root_layer, 1.f, 1.f, page_scale_application_layer, |
| 174 | inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | template <class LayerType> |
| 178 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 179 | float device_scale_factor) { |
| 180 | LayerType* page_scale_application_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 181 | LayerType* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 182 | LayerType* outer_viewport_scroll_layer = nullptr; |
| 183 | ExecuteCalculateDrawProperties( |
| 184 | root_layer, device_scale_factor, 1.f, page_scale_application_layer, |
| 185 | inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 186 | } |
| 187 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 188 | const LayerList* GetUpdateLayerList() { return &update_layer_list_; } |
| 189 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 190 | void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) { |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 191 | DCHECK(root_layer->GetLayerTree()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 192 | PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 193 | |
| 194 | bool can_render_to_separate_surface = true; |
| 195 | |
| 196 | const Layer* page_scale_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 197 | root_layer->GetLayerTree()->page_scale_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 198 | Layer* inner_viewport_scroll_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 199 | root_layer->GetLayerTree()->inner_viewport_scroll_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 200 | Layer* outer_viewport_scroll_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 201 | root_layer->GetLayerTree()->outer_viewport_scroll_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 202 | const Layer* overscroll_elasticity_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 203 | root_layer->GetLayerTree()->overscroll_elasticity_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 204 | gfx::Vector2dF elastic_overscroll = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 205 | root_layer->GetLayerTree()->elastic_overscroll(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 206 | float page_scale_factor = 1.f; |
| 207 | float device_scale_factor = 1.f; |
| 208 | gfx::Size device_viewport_size = |
| 209 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 210 | root_layer->bounds().height() * device_scale_factor); |
| 211 | PropertyTrees* property_trees = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 212 | root_layer->GetLayerTree()->property_trees(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 213 | update_layer_list_.clear(); |
| 214 | PropertyTreeBuilder::BuildPropertyTrees( |
| 215 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 216 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 217 | elastic_overscroll, page_scale_factor, device_scale_factor, |
| 218 | gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
| 219 | draw_property_utils::UpdatePropertyTrees(property_trees, |
| 220 | can_render_to_separate_surface); |
| 221 | draw_property_utils::FindLayersThatNeedUpdates( |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 222 | root_layer->GetLayerTree(), property_trees, &update_layer_list_); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 223 | } |
| 224 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 225 | void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
| 226 | LayerImpl* root_layer, |
| 227 | bool skip_verify_visible_rect_calculations = false) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 228 | DCHECK(root_layer->layer_tree_impl()); |
| 229 | PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer); |
| 230 | |
| 231 | bool can_render_to_separate_surface = true; |
| 232 | |
| 233 | LayerImpl* page_scale_layer = nullptr; |
| 234 | LayerImpl* inner_viewport_scroll_layer = |
| 235 | root_layer->layer_tree_impl()->InnerViewportScrollLayer(); |
| 236 | LayerImpl* outer_viewport_scroll_layer = |
| 237 | root_layer->layer_tree_impl()->OuterViewportScrollLayer(); |
| 238 | LayerImpl* overscroll_elasticity_layer = |
| 239 | root_layer->layer_tree_impl()->OverscrollElasticityLayer(); |
| 240 | gfx::Vector2dF elastic_overscroll = |
| 241 | root_layer->layer_tree_impl()->elastic_overscroll()->Current( |
| 242 | root_layer->layer_tree_impl()->IsActiveTree()); |
| 243 | float page_scale_factor = 1.f; |
| 244 | float device_scale_factor = 1.f; |
| 245 | gfx::Size device_viewport_size = |
| 246 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 247 | root_layer->bounds().height() * device_scale_factor); |
| 248 | update_layer_list_impl_.reset(new LayerImplList); |
| 249 | root_layer->layer_tree_impl()->BuildLayerListForTesting(); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 250 | PropertyTrees* property_trees = |
| 251 | root_layer->layer_tree_impl()->property_trees(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 252 | draw_property_utils::BuildPropertyTreesAndComputeVisibleRects( |
| 253 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 254 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 255 | elastic_overscroll, page_scale_factor, device_scale_factor, |
| 256 | gfx::Rect(device_viewport_size), gfx::Transform(), |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 257 | can_render_to_separate_surface, property_trees, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 258 | update_layer_list_impl_.get()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 259 | draw_property_utils::VerifyClipTreeCalculations(*update_layer_list_impl_, |
| 260 | property_trees); |
| 261 | if (!skip_verify_visible_rect_calculations) |
| 262 | draw_property_utils::VerifyVisibleRectsCalculations( |
| 263 | *update_layer_list_impl_, property_trees); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces( |
| 267 | LayerImpl* root_layer) { |
| 268 | gfx::Size device_viewport_size = |
| 269 | gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); |
| 270 | render_surface_layer_list_impl_.reset(new LayerImplList); |
| 271 | |
| 272 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 273 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 274 | root_layer, device_viewport_size, |
| 275 | render_surface_layer_list_impl_.get()); |
| 276 | inputs.can_adjust_raster_scales = true; |
| 277 | inputs.can_render_to_separate_surface = false; |
| 278 | |
| 279 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 280 | } |
| 281 | |
| 282 | bool UpdateLayerListImplContains(int id) const { |
| 283 | for (auto* layer : *update_layer_list_impl_) { |
| 284 | if (layer->id() == id) |
| 285 | return true; |
| 286 | } |
| 287 | return false; |
| 288 | } |
| 289 | |
| 290 | bool UpdateLayerListContains(int id) const { |
| 291 | for (const auto& layer : update_layer_list_) { |
| 292 | if (layer->id() == id) |
| 293 | return true; |
| 294 | } |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | const LayerImplList* render_surface_layer_list_impl() const { |
| 299 | return render_surface_layer_list_impl_.get(); |
| 300 | } |
| 301 | const LayerImplList* update_layer_list_impl() const { |
| 302 | return update_layer_list_impl_.get(); |
| 303 | } |
| 304 | const LayerList& update_layer_list() const { return update_layer_list_; } |
| 305 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 306 | bool VerifyLayerInList(scoped_refptr<Layer> layer, |
| 307 | const LayerList* layer_list) { |
| 308 | return std::find(layer_list->begin(), layer_list->end(), layer) != |
| 309 | layer_list->end(); |
| 310 | } |
| 311 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 312 | private: |
| 313 | std::unique_ptr<std::vector<LayerImpl*>> render_surface_layer_list_impl_; |
| 314 | LayerList update_layer_list_; |
| 315 | std::unique_ptr<LayerImplList> update_layer_list_impl_; |
| 316 | }; |
| 317 | |
| 318 | class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase, |
| 319 | public testing::Test {}; |
| 320 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 321 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 322 | public: |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 323 | LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 324 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 325 | bool DrawsContent() const override { return true; } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 326 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 327 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 328 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 329 | }; |
| 330 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 331 | class LayerTreeSettingsScaleContent : public VerifyTreeCalcsLayerTreeSettings { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 332 | public: |
| 333 | LayerTreeSettingsScaleContent() { |
| 334 | layer_transforms_should_scale_layer_contents = true; |
| 335 | } |
| 336 | }; |
| 337 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 338 | class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTestBase, |
| 339 | public testing::Test { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 340 | public: |
| 341 | LayerTreeHostCommonScalingTest() |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 342 | : LayerTreeHostCommonTestBase(LayerTreeSettingsScaleContent()) {} |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 343 | }; |
| 344 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 345 | class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest { |
| 346 | public: |
| 347 | LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {} |
| 348 | |
| 349 | LayerImpl* TestVisibleRectAndDrawableContentRect( |
| 350 | const gfx::Rect& target_rect, |
| 351 | const gfx::Transform& layer_transform, |
| 352 | const gfx::Rect& layer_rect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 353 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 354 | LayerImpl* target = AddChild<LayerImpl>(root); |
| 355 | LayerImpl* drawing_layer = AddChild<LayerImpl>(target); |
| 356 | |
| 357 | root->SetDrawsContent(true); |
| 358 | target->SetDrawsContent(true); |
| 359 | target->SetMasksToBounds(true); |
| 360 | drawing_layer->SetDrawsContent(true); |
| 361 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 362 | root->SetBounds(gfx::Size(500, 500)); |
| 363 | root->test_properties()->force_render_surface = true; |
| 364 | target->SetPosition(gfx::PointF(target_rect.origin())); |
| 365 | target->SetBounds(target_rect.size()); |
| 366 | target->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 367 | drawing_layer->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 368 | drawing_layer->SetPosition(gfx::PointF(layer_rect.origin())); |
| 369 | drawing_layer->SetBounds(layer_rect.size()); |
| 370 | drawing_layer->test_properties()->should_flatten_transform = false; |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 371 | |
| 372 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 373 | ExecuteCalculateDrawProperties(root); |
| 374 | |
| 375 | return drawing_layer; |
| 376 | } |
| 377 | }; |
| 378 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 379 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 380 | // Sanity check: For layers positioned at zero, with zero size, |
| 381 | // and with identity transforms, then the draw transform, |
| 382 | // screen space transform, and the hierarchy passed on to children |
| 383 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 384 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 385 | LayerImpl* parent = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 386 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 387 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 388 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 389 | parent->SetBounds(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 390 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 391 | ExecuteCalculateDrawProperties(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 392 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 393 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 394 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 395 | child->ScreenSpaceTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 396 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 397 | grand_child->DrawTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 398 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 399 | grand_child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 400 | } |
| 401 | |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 402 | TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) { |
| 403 | // Tests that effect tree node gets a valid transform id when a layer |
| 404 | // has opacity but doesn't create a render surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 405 | LayerImpl* parent = root_layer_for_testing(); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 406 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 407 | child->SetDrawsContent(true); |
| 408 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 409 | parent->SetBounds(gfx::Size(100, 100)); |
| 410 | child->SetPosition(gfx::PointF(10, 10)); |
| 411 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 412 | child->test_properties()->opacity = 0.f; |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 413 | ExecuteCalculateDrawProperties(parent); |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 414 | EffectTree& effect_tree = |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 415 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 416 | EffectNode* node = effect_tree.Node(child->effect_tree_index()); |
| 417 | const int transform_tree_size = parent->layer_tree_impl() |
| 418 | ->property_trees() |
| 419 | ->transform_tree.next_available_id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 420 | EXPECT_LT(node->transform_id, transform_tree_size); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 421 | } |
| 422 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 423 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 424 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 425 | LayerImpl* layer = AddChild<LayerImpl>(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 426 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 427 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 428 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 429 | EffectTree& effect_tree = |
| 430 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 431 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 432 | root->SetBounds(gfx::Size(1, 2)); |
| 433 | |
| 434 | // Case 1: Setting the bounds of the layer should not affect either the draw |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 435 | // transform or the screenspace transform. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 436 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 437 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 438 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 439 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 440 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 441 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 442 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 443 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 444 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 445 | // Case 2: The anchor point by itself (without a layer transform) should have |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 446 | // no effect on the transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 447 | layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 448 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 449 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 450 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 451 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 452 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 453 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 454 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 455 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 456 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 457 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 458 | // Case 3: A change in actual position affects both the draw transform and |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 459 | // screen space transform. |
| 460 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 461 | position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 462 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 463 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 464 | ExecuteCalculateDrawProperties(root); |
| 465 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 466 | position_transform, |
| 467 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 468 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 469 | position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 470 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 471 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 472 | // Case 4: In the correct sequence of transforms, the layer transform should |
| 473 | // pre-multiply the translation-to-center. This is easily tested by using a |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 474 | // scale transform, because scale and translation are not commutative. |
| 475 | gfx::Transform layer_transform; |
| 476 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 477 | layer->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 478 | layer->test_properties()->transform_origin = gfx::Point3F(); |
| 479 | layer->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 480 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 481 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 482 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 483 | layer_transform, |
| 484 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 485 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 486 | layer_transform, |
| 487 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 488 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 489 | // Case 5: The layer transform should occur with respect to the anchor point. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 490 | gfx::Transform translation_to_anchor; |
| 491 | translation_to_anchor.Translate(5.0, 0.0); |
| 492 | gfx::Transform expected_result = |
| 493 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 494 | layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 495 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 496 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 497 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 498 | expected_result, |
| 499 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 500 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 501 | expected_result, |
| 502 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 503 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 504 | // Case 6: Verify that position pre-multiplies the layer transform. The |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 505 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 506 | // it is still worth testing to detect accidental regressions. |
| 507 | expected_result = position_transform * translation_to_anchor * |
| 508 | layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 509 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 510 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 511 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 512 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 513 | expected_result, |
| 514 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 515 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 516 | expected_result, |
| 517 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 518 | } |
| 519 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 520 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 521 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 522 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 523 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 524 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 525 | -kScrollOffset.y()); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 526 | float page_scale = 0.888f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 527 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 528 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 529 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 530 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 531 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 532 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 533 | std::unique_ptr<LayerImpl> sublayer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 534 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 535 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 536 | sublayer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 537 | sublayer->SetBounds(gfx::Size(500, 500)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 538 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 539 | std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 540 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 541 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 542 | scroll_layer->SetBounds(gfx::Size(10, 20)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 543 | std::unique_ptr<LayerImpl> clip_layer_scoped_ptr( |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 544 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 545 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 546 | |
| 547 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 548 | clip_layer->SetBounds( |
| 549 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 550 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 551 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 552 | SetScrollOffsetDelta(scroll_layer, kScrollDelta); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 553 | gfx::Transform impl_transform; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 554 | scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 555 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 556 | clip_layer->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr)); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 557 | scroll_layer_raw_ptr->layer_tree_impl() |
| 558 | ->property_trees() |
| 559 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(), |
| 560 | kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 561 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 562 | std::unique_ptr<LayerImpl> root( |
| 563 | LayerImpl::Create(host_impl.active_tree(), 3)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 564 | root->SetBounds(gfx::Size(3, 4)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 565 | root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 566 | root->SetHasRenderSurface(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 567 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 568 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 569 | |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 570 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 571 | scroll_layer->test_properties()->parent, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 572 | nullptr, nullptr); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 573 | gfx::Transform expected_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 574 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 575 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 576 | page_scale * kDeviceScale), |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 577 | MathUtil::Round(sub_layer_screen_position.y() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 578 | page_scale * kDeviceScale)); |
| 579 | expected_transform.Scale(page_scale * kDeviceScale, |
| 580 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 581 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 582 | sublayer->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 583 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 584 | sublayer->ScreenSpaceTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 585 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 586 | gfx::Transform arbitrary_translate; |
| 587 | const float kTranslateX = 10.6f; |
| 588 | const float kTranslateY = 20.6f; |
| 589 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 590 | scroll_layer->test_properties()->transform = arbitrary_translate; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 591 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 592 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 593 | scroll_layer->test_properties()->parent, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 594 | nullptr, nullptr); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 595 | expected_transform.MakeIdentity(); |
| 596 | expected_transform.Translate( |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 597 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 598 | sub_layer_screen_position.x() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 599 | kDeviceScale), |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 600 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 601 | sub_layer_screen_position.y() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 602 | kDeviceScale)); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 603 | expected_transform.Scale(page_scale * kDeviceScale, |
| 604 | page_scale * kDeviceScale); |
| 605 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 606 | sublayer->DrawTransform()); |
| 607 | |
| 608 | // Test that page scale is updated even when we don't rebuild property trees. |
| 609 | page_scale = 1.888f; |
| 610 | root_layer->layer_tree_impl()->SetViewportLayersFromIds( |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 611 | Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(), |
| 612 | Layer::INVALID_ID, Layer::INVALID_ID); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 613 | root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 614 | EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 615 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 616 | scroll_layer->test_properties()->parent, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 617 | nullptr, nullptr); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 618 | |
| 619 | expected_transform.MakeIdentity(); |
| 620 | expected_transform.Translate( |
| 621 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 622 | sub_layer_screen_position.x() * page_scale * |
| 623 | kDeviceScale), |
| 624 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 625 | sub_layer_screen_position.y() * page_scale * |
| 626 | kDeviceScale)); |
| 627 | expected_transform.Scale(page_scale * kDeviceScale, |
| 628 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 629 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 630 | sublayer->DrawTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 631 | } |
| 632 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 633 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 634 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 635 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 636 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 637 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 638 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 639 | // One-time setup of root layer |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 640 | root->SetBounds(gfx::Size(1, 2)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 641 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 642 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 643 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 644 | EffectTree& effect_tree = |
| 645 | host_impl()->active_tree()->property_trees()->effect_tree; |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 646 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 647 | // Case 1: parent's anchor point should not affect child or grand_child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 648 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 649 | parent->SetBounds(gfx::Size(10, 12)); |
| 650 | child->SetBounds(gfx::Size(16, 18)); |
| 651 | grand_child->SetBounds(gfx::Size(76, 78)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 652 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 653 | |
| 654 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 655 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 656 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 657 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 658 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 659 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 660 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 661 | gfx::Transform(), draw_property_utils::DrawTransform( |
| 662 | grand_child, transform_tree, effect_tree)); |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 663 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 664 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 665 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 666 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 667 | // Case 2: parent's position affects child and grand_child. |
| 668 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 669 | parent_position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 670 | parent->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 671 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 672 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 673 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 674 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 675 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 676 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 677 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 678 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 679 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 680 | parent_position_transform, draw_property_utils::DrawTransform( |
| 681 | grand_child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 682 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 683 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 684 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 685 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 686 | // Case 3: parent's local transform affects child and grandchild |
| 687 | gfx::Transform parent_layer_transform; |
| 688 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 689 | gfx::Transform parent_translation_to_anchor; |
| 690 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 691 | gfx::Transform parent_composite_transform = |
| 692 | parent_translation_to_anchor * parent_layer_transform * |
| 693 | Inverse(parent_translation_to_anchor); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 694 | parent->test_properties()->transform = parent_layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 695 | parent->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 696 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 697 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 698 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 699 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 700 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 701 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 702 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 703 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 704 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 705 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 706 | draw_property_utils::DrawTransform(grand_child, transform_tree, |
| 707 | effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 708 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 709 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 710 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 711 | } |
| 712 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 713 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 714 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 715 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 716 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 717 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 718 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 719 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 720 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 721 | gfx::Transform parent_translation_to_anchor; |
| 722 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 723 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 724 | gfx::Transform parent_composite_transform = |
| 725 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 726 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 727 | gfx::Vector2dF parent_composite_scale = |
| 728 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 729 | 1.f); |
| 730 | gfx::Transform surface_sublayer_transform; |
| 731 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 732 | parent_composite_scale.y()); |
| 733 | gfx::Transform surface_sublayer_composite_transform = |
| 734 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 735 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 736 | root->SetBounds(gfx::Size(1, 2)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 737 | parent->test_properties()->transform = parent_layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 738 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f); |
| 739 | parent->SetBounds(gfx::Size(100, 120)); |
| 740 | child->SetBounds(gfx::Size(16, 18)); |
| 741 | child->test_properties()->force_render_surface = true; |
| 742 | grand_child->SetBounds(gfx::Size(8, 10)); |
| 743 | grand_child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 744 | ExecuteCalculateDrawProperties(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 745 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 746 | // Render surface should have been created now. |
| 747 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 748 | ASSERT_EQ(child->render_surface(), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 749 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 750 | // The child layer's draw transform should refer to its new render surface. |
| 751 | // The screen-space transform, however, should still refer to the root. |
| 752 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 753 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 754 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 755 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 756 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 757 | // Because the grand_child is the only drawable content, the child's render |
| 758 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 759 | // surface's subtree is drawn must be removed from the composite transform. |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 760 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, |
| 761 | child->render_target()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 762 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 763 | // The screen space is the same as the target since the child surface draws |
| 764 | // into the root. |
| 765 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 766 | surface_sublayer_composite_transform, |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 767 | child->render_target()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 768 | } |
| 769 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 770 | TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 771 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 772 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 773 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 774 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 775 | |
| 776 | gfx::Transform parent_transform; |
| 777 | parent_transform.Translate(10.0, 10.0); |
| 778 | |
| 779 | gfx::Transform child_transform; |
| 780 | child_transform.Rotate(45.0); |
| 781 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 782 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 783 | parent->test_properties()->transform = parent_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 784 | parent->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 785 | child->test_properties()->transform = child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 786 | child->SetBounds(gfx::Size(10, 10)); |
| 787 | child->test_properties()->force_render_surface = true; |
| 788 | grand_child->SetPosition(gfx::PointF(2.f, 2.f)); |
| 789 | grand_child->SetBounds(gfx::Size(20, 20)); |
| 790 | grand_child->SetDrawsContent(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 791 | |
| 792 | gfx::Transform expected_grand_child_screen_space_transform; |
| 793 | expected_grand_child_screen_space_transform.Translate(10.0, 10.0); |
| 794 | expected_grand_child_screen_space_transform.Rotate(45.0); |
| 795 | expected_grand_child_screen_space_transform.Translate(2.0, 2.0); |
| 796 | |
| 797 | // First compute draw properties with separate surfaces enabled. |
| 798 | ExecuteCalculateDrawProperties(root); |
| 799 | |
| 800 | // The grand child's draw transform should be its offset wrt the child. |
| 801 | gfx::Transform expected_grand_child_draw_transform; |
| 802 | expected_grand_child_draw_transform.Translate(2.0, 2.0); |
| 803 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 804 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 805 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 806 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 807 | |
| 808 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 809 | |
| 810 | // With separate surfaces disabled, the grand child's draw transform should be |
| 811 | // the same as its screen space transform. |
| 812 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 813 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 814 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 815 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 816 | } |
| 817 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 818 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 819 | // This test creates a more complex tree and verifies it all at once. This |
| 820 | // covers the following cases: |
| 821 | // - layers that are described w.r.t. a render surface: should have draw |
| 822 | // transforms described w.r.t. that surface |
| 823 | // - A render surface described w.r.t. an ancestor render surface: should |
| 824 | // have a draw transform described w.r.t. that ancestor surface |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 825 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 826 | // a render surface that is described w.r.t. an ancestor render surface. |
| 827 | // - verifying that each layer has a reference to the correct render surface |
| 828 | // and render target values. |
| 829 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 830 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 831 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 832 | parent->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 833 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 834 | render_surface1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 835 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 836 | render_surface2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 837 | LayerImpl* child_of_root = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 838 | child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 839 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 840 | child_of_rs1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 841 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 842 | child_of_rs2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 843 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 844 | grand_child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 845 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 846 | grand_child_of_rs1->SetDrawsContent(true); |
| 847 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 848 | grand_child_of_rs2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 849 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 850 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 851 | // to have a new render surface. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 852 | render_surface1->test_properties()->opacity = 0.5f; |
| 853 | render_surface2->test_properties()->opacity = 0.33f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 854 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 855 | // All layers in the tree are initialized with an anchor at .25 and a size of |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 856 | // (10,10). Matrix "A" is the composite layer transform used in all layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 857 | gfx::Transform translation_to_anchor; |
| 858 | translation_to_anchor.Translate(2.5, 0.0); |
| 859 | gfx::Transform layer_transform; |
| 860 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 861 | |
| 862 | gfx::Transform A = |
| 863 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 864 | |
| 865 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 866 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 867 | gfx::Transform surface1_sublayer_transform; |
| 868 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 869 | surface1_parent_transform_scale.y()); |
| 870 | |
| 871 | // SS1 = transform given to the subtree of render_surface1 |
| 872 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 873 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 874 | // the owning layer |
| 875 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 876 | |
| 877 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 878 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 879 | gfx::Transform surface2_sublayer_transform; |
| 880 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 881 | surface2_parent_transform_scale.y()); |
| 882 | |
| 883 | // SS2 = transform given to the subtree of render_surface2 |
| 884 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 885 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 886 | // the owning layer |
| 887 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 888 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 889 | root->SetBounds(gfx::Size(1, 2)); |
| 890 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 891 | parent->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 892 | parent->SetBounds(gfx::Size(10, 10)); |
| 893 | render_surface1->test_properties()->transform_origin = |
| 894 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 895 | render_surface1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 896 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 897 | render_surface1->test_properties()->force_render_surface = true; |
| 898 | render_surface2->test_properties()->transform_origin = |
| 899 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 900 | render_surface2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 901 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 902 | render_surface2->test_properties()->force_render_surface = true; |
| 903 | child_of_root->test_properties()->transform_origin = |
| 904 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 905 | child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 906 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 907 | child_of_rs1->test_properties()->transform_origin = |
| 908 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 909 | child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 910 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 911 | child_of_rs2->test_properties()->transform_origin = |
| 912 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 913 | child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 914 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 915 | grand_child_of_root->test_properties()->transform_origin = |
| 916 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 917 | grand_child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 918 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 919 | grand_child_of_rs1->test_properties()->transform_origin = |
| 920 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 921 | grand_child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 922 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 923 | grand_child_of_rs2->test_properties()->transform_origin = |
| 924 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 925 | grand_child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 926 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 927 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 928 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 929 | |
| 930 | // Only layers that are associated with render surfaces should have an actual |
| 931 | // RenderSurface() value. |
| 932 | ASSERT_TRUE(root->render_surface()); |
| 933 | ASSERT_FALSE(child_of_root->render_surface()); |
| 934 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 935 | |
| 936 | ASSERT_TRUE(render_surface1->render_surface()); |
| 937 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 938 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 939 | |
| 940 | ASSERT_TRUE(render_surface2->render_surface()); |
| 941 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 942 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 943 | |
| 944 | // Verify all render target accessors |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 945 | EXPECT_EQ(root->render_surface(), parent->render_target()); |
| 946 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 947 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 948 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 949 | EXPECT_EQ(render_surface1->render_surface(), |
| 950 | render_surface1->render_target()); |
| 951 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 952 | EXPECT_EQ(render_surface1->render_surface(), |
| 953 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 954 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 955 | EXPECT_EQ(render_surface2->render_surface(), |
| 956 | render_surface2->render_target()); |
| 957 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 958 | EXPECT_EQ(render_surface2->render_surface(), |
| 959 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 960 | |
| 961 | // Verify layer draw transforms note that draw transforms are described with |
| 962 | // respect to the nearest ancestor render surface but screen space transforms |
| 963 | // are described with respect to the root. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 964 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform()); |
| 965 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 966 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 967 | grand_child_of_root->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 968 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 969 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform()); |
| 970 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 971 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 972 | grand_child_of_rs1->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 973 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 974 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform()); |
| 975 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 976 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 977 | grand_child_of_rs2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 978 | |
| 979 | // Verify layer screen-space transforms |
| 980 | // |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 981 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform()); |
| 982 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform()); |
| 983 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
| 984 | grand_child_of_root->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 985 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 986 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 987 | render_surface1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 988 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 989 | child_of_rs1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 990 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 991 | grand_child_of_rs1->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 992 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 993 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 994 | render_surface2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 995 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 996 | child_of_rs2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 997 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 998 | grand_child_of_rs2->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 999 | |
| 1000 | // Verify render surface transforms. |
| 1001 | // |
| 1002 | // Draw transform of render surface 1 is described with respect to root. |
| 1003 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1004 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1005 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1006 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1007 | // Draw transform of render surface 2 is described with respect to render |
| 1008 | // surface 1. |
| 1009 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1010 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1011 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1012 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1013 | render_surface2->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1014 | |
| 1015 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 1016 | // is expected that we correctly set up transforms so that the y-component of |
| 1017 | // the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1018 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1019 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1020 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1021 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1022 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1023 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1024 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1025 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 1026 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1027 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1028 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1029 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1030 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1031 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 1032 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1033 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1034 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1035 | } |
| 1036 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1037 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1038 | // For layers that flatten their subtree, there should be an orthographic |
| 1039 | // projection (for x and y values) in the middle of the transform sequence. |
| 1040 | // Note that the way the code is currently implemented, it is not expected to |
| 1041 | // use a canonical orthographic projection. |
| 1042 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1043 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1044 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1045 | child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1046 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1047 | grand_child->SetDrawsContent(true); |
| 1048 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 1049 | great_grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1050 | |
| 1051 | gfx::Transform rotation_about_y_axis; |
| 1052 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1053 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1054 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1055 | child->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1056 | child->SetBounds(gfx::Size(10, 10)); |
| 1057 | child->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1058 | grand_child->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1059 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1060 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1061 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1062 | // No layers in this test should preserve 3d. |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1063 | ASSERT_TRUE(root->test_properties()->should_flatten_transform); |
| 1064 | ASSERT_TRUE(child->test_properties()->should_flatten_transform); |
| 1065 | ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform); |
| 1066 | ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1067 | |
| 1068 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1069 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1070 | gfx::Transform expected_grand_child_draw_transform = |
| 1071 | rotation_about_y_axis; // draws onto child's render surface |
| 1072 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1073 | flattened_rotation_about_y.FlattenTo2d(); |
| 1074 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1075 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1076 | gfx::Transform expected_great_grand_child_draw_transform = |
| 1077 | flattened_rotation_about_y; |
| 1078 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 1079 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1080 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1081 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1082 | |
| 1083 | // The child's draw transform should have been taken by its surface. |
| 1084 | ASSERT_TRUE(child->render_surface()); |
| 1085 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1086 | child->render_surface()->draw_transform()); |
| 1087 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1088 | expected_child_screen_space_transform, |
| 1089 | child->render_surface()->screen_space_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1090 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1091 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1092 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1093 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1094 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1095 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1096 | grand_child->ScreenSpaceTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1097 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1098 | great_grand_child->DrawTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1099 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1100 | expected_great_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1101 | great_grand_child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1102 | } |
| 1103 | |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1104 | TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1105 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1106 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1107 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1108 | |
| 1109 | gfx::Transform child_transform; |
| 1110 | child_transform.Translate(50.0, 50.0); |
| 1111 | child_transform.RotateAboutZAxis(30.0); |
| 1112 | |
| 1113 | gfx::Transform grand_child_transform; |
| 1114 | grand_child_transform.RotateAboutYAxis(90.0); |
| 1115 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1116 | root->SetBounds(gfx::Size(200, 200)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1117 | child->test_properties()->transform = child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1118 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1119 | grand_child->test_properties()->transform = grand_child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1120 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1121 | grand_child->test_properties()->should_flatten_transform = false; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1122 | grand_child->SetDrawsContent(true); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1123 | float device_scale_factor = 1.f; |
| 1124 | float page_scale_factor = 1.f; |
| 1125 | LayerImpl* page_scale_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 1126 | LayerImpl* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 1127 | LayerImpl* outer_viewport_scroll_layer = nullptr; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1128 | // Visible rects computed by combining clips in target space and root space |
| 1129 | // don't match because of rotation transforms. So, we skip |
| 1130 | // verify_visible_rect_calculations. |
| 1131 | bool skip_verify_visible_rect_calculations = true; |
| 1132 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 1133 | page_scale_layer, inner_viewport_scroll_layer, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 1134 | outer_viewport_scroll_layer, |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1135 | skip_verify_visible_rect_calculations); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1136 | |
| 1137 | // Mapping grand_child's bounds to target space produces a non-empty rect |
| 1138 | // that is fully contained within the target's bounds, so grand_child should |
| 1139 | // be considered fully visible. |
| 1140 | EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1141 | grand_child->visible_layer_rect()); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1142 | } |
| 1143 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1144 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1145 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1146 | // skipping a necessary translation. Without that translation, the coordinate |
| 1147 | // space of the layer's draw transform is incorrect. |
| 1148 | // |
| 1149 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1150 | // but if that layer becomes a render surface, then its draw transform is |
| 1151 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1152 | // incorrectly as a result. |
| 1153 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1154 | LayerImpl* root = root_layer_for_testing(); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1155 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1156 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1157 | grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1158 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1159 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1160 | // The child height is zero, but has non-zero width that should be accounted |
| 1161 | // for while computing draw transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1162 | child->SetBounds(gfx::Size(10, 0)); |
| 1163 | child->test_properties()->force_render_surface = true; |
| 1164 | grand_child->SetBounds(gfx::Size(10, 10)); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1165 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1166 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1167 | ASSERT_TRUE(child->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1168 | // This is the real test, the rest are sanity checks. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1169 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1170 | child->render_surface()->draw_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1171 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1172 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1173 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1174 | } |
| 1175 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1176 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1177 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1178 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 1179 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 1180 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1181 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1182 | gfx::Transform translate; |
| 1183 | translate.Translate3d(5, 5, 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1184 | |
| 1185 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1186 | render_surface->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1187 | render_surface->SetBounds(gfx::Size(100, 100)); |
| 1188 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1189 | child->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1190 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1191 | grand_child->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1192 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1193 | grand_child->SetDrawsContent(true); |
| 1194 | |
| 1195 | // render_surface will have a sublayer scale because of device scale factor. |
| 1196 | float device_scale_factor = 2.0f; |
| 1197 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1198 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1199 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1200 | inputs.device_scale_factor = device_scale_factor; |
| 1201 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1202 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1203 | |
| 1204 | // Between grand_child and render_surface, we translate by (10, 10) and scale |
| 1205 | // by a factor of 2. |
| 1206 | gfx::Vector2dF expected_translation(20.0f, 20.0f); |
| 1207 | EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(), |
| 1208 | expected_translation); |
| 1209 | } |
| 1210 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1211 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1212 | // Transformations applied at the root of the tree should be forwarded |
| 1213 | // to child layers instead of applied to the root RenderSurface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1214 | LayerImpl* root = root_layer_for_testing(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1215 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1216 | |
| 1217 | root->SetDrawsContent(true); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1218 | root->SetBounds(gfx::Size(100, 100)); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1219 | child->SetDrawsContent(true); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1220 | child->SetScrollClipLayer(root->id()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1221 | child->SetBounds(gfx::Size(100, 100)); |
| 1222 | child->SetMasksToBounds(true); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1223 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1224 | gfx::Transform translate; |
| 1225 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1226 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1227 | LayerImplList render_surface_layer_list_impl; |
| 1228 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1229 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1230 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1231 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1232 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1233 | translate, root->draw_properties().target_space_transform); |
| 1234 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1235 | translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1236 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1237 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1238 | EXPECT_TRANSFORMATION_MATRIX_EQ(translate, child->ScreenSpaceTransform()); |
| 1239 | EXPECT_EQ(gfx::Rect(50, 50, 100, 100), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1240 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1241 | |
| 1242 | gfx::Transform scale; |
| 1243 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1244 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1245 | LayerImplList render_surface_layer_list_impl; |
| 1246 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1247 | root, root->bounds(), scale, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1248 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1249 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1250 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1251 | scale, root->draw_properties().target_space_transform); |
| 1252 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1253 | scale, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1254 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1255 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1256 | EXPECT_TRANSFORMATION_MATRIX_EQ(scale, child->ScreenSpaceTransform()); |
| 1257 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1258 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1259 | |
| 1260 | gfx::Transform rotate; |
| 1261 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1262 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1263 | LayerImplList render_surface_layer_list_impl; |
| 1264 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1265 | root, root->bounds(), rotate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1266 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1267 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1268 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1269 | rotate, root->draw_properties().target_space_transform); |
| 1270 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1271 | rotate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1272 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1273 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1274 | EXPECT_TRANSFORMATION_MATRIX_EQ(rotate, child->ScreenSpaceTransform()); |
| 1275 | EXPECT_EQ(gfx::Rect(-4, 0, 104, 104), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1276 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1277 | |
| 1278 | gfx::Transform composite; |
| 1279 | composite.ConcatTransform(translate); |
| 1280 | composite.ConcatTransform(scale); |
| 1281 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1282 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1283 | LayerImplList render_surface_layer_list_impl; |
| 1284 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1285 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1286 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1287 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1288 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1289 | composite, root->draw_properties().target_space_transform); |
| 1290 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1291 | composite, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1292 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1293 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1294 | EXPECT_TRANSFORMATION_MATRIX_EQ(composite, child->ScreenSpaceTransform()); |
| 1295 | EXPECT_EQ(gfx::Rect(89, 103, 208, 208), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1296 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1297 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1298 | // Verify it composes correctly with device scale. |
| 1299 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1300 | |
| 1301 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1302 | LayerImplList render_surface_layer_list_impl; |
| 1303 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1304 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1305 | inputs.device_scale_factor = device_scale_factor; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1306 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1307 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1308 | gfx::Transform device_scaled_translate = translate; |
jaydasika | 18ea272 | 2016-10-27 23:47:10 | [diff] [blame] | 1309 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1310 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1311 | device_scaled_translate, |
| 1312 | root->draw_properties().target_space_transform); |
| 1313 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1314 | device_scaled_translate, |
| 1315 | child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1316 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1317 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1318 | EXPECT_TRANSFORMATION_MATRIX_EQ(device_scaled_translate, |
| 1319 | child->ScreenSpaceTransform()); |
| 1320 | EXPECT_EQ(gfx::Rect(50, 50, 150, 150), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1321 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1322 | |
| 1323 | // Verify it composes correctly with page scale. |
| 1324 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1325 | |
| 1326 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1327 | LayerImplList render_surface_layer_list_impl; |
| 1328 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1329 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1330 | inputs.page_scale_factor = page_scale_factor; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1331 | inputs.page_scale_layer = root; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1332 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1333 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1334 | gfx::Transform page_scaled_translate = translate; |
jaydasika | 18ea272 | 2016-10-27 23:47:10 | [diff] [blame] | 1335 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1336 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1337 | page_scaled_translate, root->draw_properties().target_space_transform); |
| 1338 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1339 | page_scaled_translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1340 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1341 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1342 | EXPECT_TRANSFORMATION_MATRIX_EQ(page_scaled_translate, |
| 1343 | child->ScreenSpaceTransform()); |
| 1344 | EXPECT_EQ(gfx::Rect(50, 50, 200, 200), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1345 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1346 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1347 | // Verify that it composes correctly with transforms directly on root layer. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1348 | root->test_properties()->transform = composite; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1349 | |
| 1350 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1351 | LayerImplList render_surface_layer_list_impl; |
| 1352 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1353 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1354 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1355 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1356 | gfx::Transform compositeSquared = composite; |
| 1357 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1358 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1359 | compositeSquared, root->draw_properties().target_space_transform); |
| 1360 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1361 | compositeSquared, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1362 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1363 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1364 | EXPECT_TRANSFORMATION_MATRIX_EQ(compositeSquared, |
| 1365 | child->ScreenSpaceTransform()); |
| 1366 | EXPECT_EQ(gfx::Rect(254, 316, 428, 428), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1367 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1368 | } |
| 1369 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1370 | TEST_F(LayerTreeHostCommonTest, |
| 1371 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1372 | LayerImpl* root = root_layer_for_testing(); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1373 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1374 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1375 | |
| 1376 | root->SetBounds(gfx::Size(10, 10)); |
| 1377 | root->SetMasksToBounds(true); |
| 1378 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1379 | render_surface1->test_properties()->force_render_surface = true; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1380 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1381 | child->SetPosition(gfx::PointF(30.f, 30.f)); |
| 1382 | child->SetBounds(gfx::Size(10, 10)); |
| 1383 | ExecuteCalculateDrawProperties(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1384 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1385 | // The child layer's content is entirely outside the root's clip rect, so |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1386 | // the intermediate render surface should not be listed here, even if it was |
| 1387 | // forced to be created. Render surfaces without children or visible content |
| 1388 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1389 | // of size 0). |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1390 | ASSERT_TRUE(root->render_surface()); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1391 | EXPECT_EQ(1U, render_surface_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1392 | } |
| 1393 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1394 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1395 | LayerImpl* root = root_layer_for_testing(); |
| 1396 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1397 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1398 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1399 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1400 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1401 | render_surface1->test_properties()->opacity = 0.f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1402 | child->SetBounds(gfx::Size(10, 10)); |
| 1403 | child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1404 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1405 | LayerImplList render_surface_layer_list; |
| 1406 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1407 | root, root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1408 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1409 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1410 | |
| 1411 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1412 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1413 | // have been extended by the children. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1414 | ASSERT_TRUE(root->render_surface()); |
| 1415 | EXPECT_EQ(0U, root->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1416 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1417 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 1418 | EXPECT_EQ(gfx::Rect(), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1419 | } |
| 1420 | |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1421 | TEST_F(LayerTreeHostCommonTest, |
| 1422 | RenderSurfaceListForTransparentChildWithBackgroundFilter) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1423 | LayerImpl* root = root_layer_for_testing(); |
| 1424 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1425 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1426 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1427 | root->SetBounds(gfx::Size(10, 10)); |
| 1428 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1429 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1430 | render_surface1->test_properties()->opacity = 0.f; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 1431 | render_surface1->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1432 | FilterOperations filters; |
| 1433 | filters.Append(FilterOperation::CreateBlurFilter(1.5f)); |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 1434 | render_surface1->test_properties()->background_filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1435 | child->SetBounds(gfx::Size(10, 10)); |
| 1436 | child->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1437 | |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1438 | { |
| 1439 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1440 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1441 | root, root->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1442 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1443 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1444 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1445 | } |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1446 | // The layer is fully transparent, but has a background filter, so it |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1447 | // shouldn't be skipped and should be drawn. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1448 | ASSERT_TRUE(root->render_surface()); |
| 1449 | EXPECT_EQ(1U, root->render_surface()->layer_list().size()); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1450 | EXPECT_EQ(gfx::RectF(0, 0, 10, 10), |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1451 | root->render_surface()->DrawableContentRect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1452 | EffectTree& effect_tree = |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1453 | root->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1454 | EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1455 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1456 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1457 | // When root is transparent, the layer should not be drawn. |
jaydasika | 898b2f1 | 2016-08-20 04:22:09 | [diff] [blame] | 1458 | effect_tree.OnOpacityAnimated(0.f, root->effect_tree_index(), |
| 1459 | root->layer_tree_impl()); |
| 1460 | effect_tree.OnOpacityAnimated(1.f, render_surface1->effect_tree_index(), |
| 1461 | root->layer_tree_impl()); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1462 | render_surface1->set_visible_layer_rect(gfx::Rect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1463 | { |
| 1464 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1465 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1466 | root, root->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1467 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1468 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1472 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1473 | EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect()); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1474 | } |
| 1475 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1476 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1477 | LayerImpl* root = root_layer_for_testing(); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1478 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1479 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1480 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1481 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1482 | gfx::Transform scale_matrix; |
| 1483 | scale_matrix.Scale(2.0f, 2.0f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1484 | |
| 1485 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1486 | parent->test_properties()->transform = scale_matrix; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1487 | FilterOperations filters; |
| 1488 | filters.Append(FilterOperation::CreateBlurFilter(10.0f)); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1489 | parent->test_properties()->filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1490 | parent->test_properties()->force_render_surface = true; |
| 1491 | child1->SetBounds(gfx::Size(25, 25)); |
| 1492 | child1->SetDrawsContent(true); |
| 1493 | child1->test_properties()->force_render_surface = true; |
| 1494 | child2->SetPosition(gfx::PointF(25, 25)); |
| 1495 | child2->SetBounds(gfx::Size(25, 25)); |
| 1496 | child2->SetDrawsContent(true); |
| 1497 | child2->test_properties()->force_render_surface = true; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1498 | |
| 1499 | LayerImplList render_surface_layer_list; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1500 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1501 | root, root->bounds(), &render_surface_layer_list); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1502 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1503 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1504 | |
| 1505 | ASSERT_TRUE(parent->render_surface()); |
| 1506 | EXPECT_EQ(2U, parent->render_surface()->layer_list().size()); |
| 1507 | EXPECT_EQ(4U, render_surface_layer_list.size()); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1508 | |
| 1509 | // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the |
| 1510 | // blur (-30,-30 110x110), and then scaled by the scale matrix |
| 1511 | // (-60,-60 220x220). |
| 1512 | EXPECT_EQ(gfx::RectF(-60, -60, 220, 220), |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1513 | parent->render_surface()->DrawableContentRect()); |
| 1514 | } |
| 1515 | |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1516 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1517 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1518 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1519 | |
| 1520 | root->SetBounds(gfx::Size(100, 100)); |
| 1521 | child->SetBounds(gfx::Size(25, 25)); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1522 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1523 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1524 | FilterOperations filters; |
| 1525 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1526 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1527 | child->test_properties()->filters = filters; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1528 | ExecuteCalculateDrawProperties(root); |
| 1529 | |
| 1530 | // The render surface's size should be unaffected by the offset image filter; |
| 1531 | // it need only have a drawable content rect large enough to contain the |
| 1532 | // contents (at the new offset). |
| 1533 | ASSERT_TRUE(child->render_surface()); |
| 1534 | EXPECT_EQ(gfx::RectF(50, 50, 25, 25), |
| 1535 | child->render_surface()->DrawableContentRect()); |
| 1536 | } |
| 1537 | |
| 1538 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) { |
| 1539 | const float device_scale_factor = 2.0f; |
| 1540 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1541 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1542 | LayerImpl* child = AddChild<LayerImpl>(root); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1543 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1544 | root->SetBounds(gfx::Size(100, 100)); |
| 1545 | child->SetBounds(gfx::Size(25, 25)); |
| 1546 | child->SetDrawsContent(true); |
| 1547 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1548 | |
| 1549 | FilterOperations filters; |
| 1550 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1551 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1552 | child->test_properties()->filters = filters; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1553 | |
| 1554 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 1555 | |
| 1556 | // The render surface's size should be unaffected by the offset image filter; |
| 1557 | // it need only have a drawable content rect large enough to contain the |
| 1558 | // contents (at the new offset). All coordinates should be scaled by 2, |
| 1559 | // corresponding to the device scale factor. |
| 1560 | ASSERT_TRUE(child->render_surface()); |
| 1561 | EXPECT_EQ(gfx::RectF(100, 100, 50, 50), |
| 1562 | child->render_surface()->DrawableContentRect()); |
| 1563 | } |
| 1564 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1565 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1566 | LayerImpl* root = root_layer_for_testing(); |
| 1567 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1568 | |
| 1569 | root->SetBounds(gfx::Size(10, 10)); |
| 1570 | child->SetBounds(gfx::Size(10, 10)); |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1571 | child->SetDrawsContent(true); |
ajuma | 4c14b25 | 2016-07-26 20:10:59 | [diff] [blame] | 1572 | child->test_properties()->blend_mode = SkXfermode::kMultiply_Mode; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1573 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1574 | child->test_properties()->force_render_surface = true; |
| 1575 | ExecuteCalculateDrawProperties(root); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1576 | |
| 1577 | // Since the child layer has a blend mode other than normal, it should get |
| 1578 | // its own render surface. Also, layer's draw_properties should contain the |
| 1579 | // default blend mode, since the render surface becomes responsible for |
| 1580 | // applying the blend mode. |
| 1581 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1582 | EXPECT_EQ(1.0f, child->draw_opacity()); |
| 1583 | EXPECT_EQ(0.5f, child->render_surface()->draw_opacity()); |
jaydasika | 92239dc | 2015-08-15 02:59:26 | [diff] [blame] | 1584 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode()); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1585 | } |
| 1586 | |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1587 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1588 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1589 | LayerImpl* surface1 = AddChildToRoot<LayerImpl>(); |
| 1590 | LayerImpl* not_surface = AddChild<LayerImpl>(surface1); |
| 1591 | LayerImpl* surface2 = AddChild<LayerImpl>(not_surface); |
| 1592 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1593 | root->SetBounds(gfx::Size(10, 10)); |
| 1594 | surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1595 | surface1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1596 | surface1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1597 | surface1->test_properties()->force_render_surface = true; |
| 1598 | not_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1599 | not_surface->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1600 | surface2->SetBounds(gfx::Size(10, 10)); |
| 1601 | surface2->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1602 | surface2->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1603 | surface2->test_properties()->force_render_surface = true; |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1604 | ExecuteCalculateDrawProperties(root); |
| 1605 | |
| 1606 | ASSERT_TRUE(surface1->render_surface()); |
| 1607 | ASSERT_FALSE(not_surface->render_surface()); |
| 1608 | ASSERT_TRUE(surface2->render_surface()); |
| 1609 | EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); |
| 1610 | // surface2's draw opacity should include the opacity of not-surface and |
| 1611 | // itself, but not the opacity of surface1. |
| 1612 | EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); |
| 1613 | } |
| 1614 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1615 | TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) { |
| 1616 | // Tests that when separate surfaces are disabled, a layer's draw opacity is |
| 1617 | // the product of all ancestor layer opacties and the layer's own opacity. |
| 1618 | // (Rendering will still be incorrect in situations where we really do need |
| 1619 | // surfaces to apply opacity, such as when we have overlapping layers with an |
| 1620 | // ancestor whose opacity is <1.) |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1621 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1622 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1623 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1624 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1625 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1626 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1627 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1628 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1629 | root->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1630 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1631 | parent->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1632 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1633 | child1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1634 | child1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1635 | child1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1636 | child1->test_properties()->force_render_surface = true; |
| 1637 | child2->SetBounds(gfx::Size(100, 100)); |
| 1638 | child2->SetDrawsContent(true); |
| 1639 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 1640 | grand_child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1641 | grand_child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1642 | grand_child->test_properties()->force_render_surface = true; |
| 1643 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
| 1644 | leaf_node1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1645 | leaf_node1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1646 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
| 1647 | leaf_node2->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1648 | leaf_node2->test_properties()->opacity = 0.5f; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1649 | |
| 1650 | // With surfaces enabled, each layer's draw opacity is the product of layer |
| 1651 | // opacities on the path from the layer to its render target, not including |
| 1652 | // the opacity of the layer that owns the target surface (since that opacity |
| 1653 | // is applied by the surface). |
| 1654 | ExecuteCalculateDrawProperties(root); |
| 1655 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1656 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1657 | EXPECT_EQ(1.f, child1->draw_opacity()); |
| 1658 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1659 | EXPECT_EQ(1.f, grand_child->draw_opacity()); |
| 1660 | EXPECT_EQ(0.5f, leaf_node1->draw_opacity()); |
| 1661 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1662 | |
| 1663 | // With surfaces disabled, each layer's draw opacity is the product of layer |
| 1664 | // opacities on the path from the layer to the root. |
| 1665 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1666 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1667 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1668 | EXPECT_EQ(0.5f, child1->draw_opacity()); |
| 1669 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1670 | EXPECT_EQ(0.25f, grand_child->draw_opacity()); |
| 1671 | EXPECT_EQ(0.125f, leaf_node1->draw_opacity()); |
| 1672 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1673 | } |
| 1674 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1675 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1676 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1677 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1678 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1679 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1680 | root->SetBounds(gfx::Size(10, 10)); |
| 1681 | render_surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1682 | render_surface1->test_properties()->force_render_surface = true; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1683 | child->SetBounds(gfx::Size(10, 10)); |
| 1684 | child->SetDrawsContent(true); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1685 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1686 | { |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1687 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1688 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1689 | // The root layer always creates a render surface |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1690 | EXPECT_TRUE(root->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1691 | EXPECT_TRUE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1692 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1693 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1694 | { |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1695 | render_surface1->test_properties()->force_render_surface = false; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1696 | render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1697 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1698 | EXPECT_TRUE(root->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1699 | EXPECT_FALSE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1700 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1701 | } |
| 1702 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1703 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1704 | // Render surfaces act as a flattening point for their subtree, so should |
| 1705 | // always flatten the target-to-screen space transform seen by descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1706 | LayerImpl* root = root_layer_for_testing(); |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1707 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1708 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1709 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1710 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1711 | gfx::Transform rotation_about_y_axis; |
| 1712 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1713 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1714 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1715 | parent->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1716 | parent->SetBounds(gfx::Size(10, 10)); |
| 1717 | parent->test_properties()->force_render_surface = true; |
| 1718 | child->SetBounds(gfx::Size(10, 10)); |
| 1719 | child->SetDrawsContent(true); |
| 1720 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1721 | grand_child->SetDrawsContent(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1722 | grand_child->test_properties()->should_flatten_transform = false; |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1723 | ExecuteCalculateDrawProperties(root); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1724 | |
| 1725 | EXPECT_TRUE(parent->render_surface()); |
| 1726 | EXPECT_FALSE(child->render_surface()); |
| 1727 | EXPECT_FALSE(grand_child->render_surface()); |
| 1728 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1729 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1730 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1731 | grand_child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1732 | |
| 1733 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1734 | // have been flattened at their render target. In particular, the fact that |
| 1735 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1736 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1737 | flattened_rotation_about_y.FlattenTo2d(); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1738 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1739 | child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1740 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1741 | grand_child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1742 | } |
| 1743 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1744 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1745 | // The entire subtree of layers that are outside the clip rect should be |
| 1746 | // culled away, and should not affect the render_surface_layer_list. |
| 1747 | // |
| 1748 | // The test tree is set up as follows: |
| 1749 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1750 | // that have something to draw. |
| 1751 | // - parent is a large container layer. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1752 | // - child has MasksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1753 | // - grand_child is positioned outside of the child's bounds |
| 1754 | // - great_grand_child is also kept outside child's bounds. |
| 1755 | // |
| 1756 | // In this configuration, grand_child and great_grand_child are completely |
| 1757 | // outside the clip rect, and they should never get scheduled on the list of |
| 1758 | // render surfaces. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1759 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1760 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1761 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1762 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1763 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1764 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1765 | // leaf_node1 ensures that root and child are kept on the |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1766 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1767 | // should be clipped. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1768 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(child); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1769 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1770 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1771 | root->SetBounds(gfx::Size(500, 500)); |
| 1772 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1773 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1774 | child->test_properties()->force_render_surface = true; |
| 1775 | grand_child->SetPosition(gfx::PointF(45.f, 45.f)); |
| 1776 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1777 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
| 1778 | leaf_node1->SetBounds(gfx::Size(500, 500)); |
| 1779 | leaf_node1->SetDrawsContent(true); |
| 1780 | leaf_node1->SetBounds(gfx::Size(20, 20)); |
| 1781 | leaf_node2->SetDrawsContent(true); |
| 1782 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1783 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1784 | ASSERT_EQ(2U, render_surface_layer_list_impl()->size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1785 | EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id()); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1786 | EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1787 | } |
| 1788 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1789 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1790 | // When a render surface has a clip rect, it is used to clip the content rect |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1791 | // of the surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1792 | |
| 1793 | // The test tree is set up as follows: |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1794 | // - root is a container layer that masksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1795 | // - child is a render surface, which has a clip rect set to the bounds of |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1796 | // the root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1797 | // - grand_child is a render surface, and the only visible content in child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1798 | // It is positioned outside of the clip rect from root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1799 | |
| 1800 | // In this configuration, grand_child should be outside the clipped |
| 1801 | // content rect of the child, making grand_child not appear in the |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1802 | // render_surface_layer_list. |
| 1803 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1804 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1805 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1806 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1807 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1808 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1809 | root->SetMasksToBounds(true); |
| 1810 | root->SetBounds(gfx::Size(100, 100)); |
| 1811 | child->SetBounds(gfx::Size(20, 20)); |
| 1812 | child->test_properties()->force_render_surface = true; |
| 1813 | grand_child->SetPosition(gfx::PointF(200.f, 200.f)); |
| 1814 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1815 | grand_child->test_properties()->force_render_surface = true; |
| 1816 | leaf_node->SetBounds(gfx::Size(10, 10)); |
| 1817 | leaf_node->SetDrawsContent(true); |
| 1818 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1819 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1820 | // We should cull child and grand_child from the |
| 1821 | // render_surface_layer_list. |
| 1822 | ASSERT_EQ(1U, render_surface_layer_list_impl()->size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1823 | EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1824 | } |
| 1825 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1826 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) { |
| 1827 | // Tests that LayerImpl's IsClipped() property is set to true when: |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1828 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1829 | // - the layer is clipped by an ancestor that contributes to the same |
| 1830 | // render target, |
| 1831 | // - a surface is clipped by an ancestor that contributes to the same |
| 1832 | // render target. |
| 1833 | // |
| 1834 | // In particular, for a layer that owns a render surface: |
| 1835 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1836 | // pass that clipped status to the layer itself. |
| 1837 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1838 | // and propagates the clip to the subtree. |
| 1839 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1840 | LayerImpl* root = root_layer_for_testing(); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1841 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1842 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1843 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1844 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1845 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1846 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1847 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1848 | root->SetBounds(gfx::Size(100, 100)); |
| 1849 | parent->SetBounds(gfx::Size(100, 100)); |
| 1850 | parent->SetDrawsContent(true); |
| 1851 | child1->SetBounds(gfx::Size(100, 100)); |
| 1852 | child1->SetDrawsContent(true); |
| 1853 | child2->SetBounds(gfx::Size(100, 100)); |
| 1854 | child2->SetDrawsContent(true); |
| 1855 | child2->test_properties()->force_render_surface = true; |
| 1856 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 1857 | grand_child->SetDrawsContent(true); |
| 1858 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
| 1859 | leaf_node1->SetDrawsContent(true); |
| 1860 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
| 1861 | leaf_node2->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1862 | |
| 1863 | // Case 1: nothing is clipped except the root render surface. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1864 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1865 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1866 | ASSERT_TRUE(root->render_surface()); |
| 1867 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1868 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1869 | EXPECT_FALSE(root->is_clipped()); |
| 1870 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1871 | EXPECT_FALSE(parent->is_clipped()); |
| 1872 | EXPECT_FALSE(child1->is_clipped()); |
| 1873 | EXPECT_FALSE(child2->is_clipped()); |
| 1874 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1875 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1876 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1877 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1878 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1879 | // Case 2: parent MasksToBounds, so the parent, child1, and child2's |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1880 | // surface are clipped. But layers that contribute to child2's surface are |
| 1881 | // not clipped explicitly because child2's surface already accounts for |
| 1882 | // that clip. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1883 | parent->SetMasksToBounds(true); |
| 1884 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1885 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1886 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1887 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1888 | ASSERT_TRUE(root->render_surface()); |
| 1889 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1890 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1891 | EXPECT_FALSE(root->is_clipped()); |
| 1892 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1893 | EXPECT_TRUE(parent->is_clipped()); |
| 1894 | EXPECT_TRUE(child1->is_clipped()); |
| 1895 | EXPECT_FALSE(child2->is_clipped()); |
| 1896 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1897 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1898 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1899 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1900 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1901 | parent->SetMasksToBounds(false); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1902 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1903 | // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1904 | // child2's render surface is not clipped. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1905 | child2->SetMasksToBounds(true); |
| 1906 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1907 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1908 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1909 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1910 | ASSERT_TRUE(root->render_surface()); |
| 1911 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1912 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1913 | EXPECT_FALSE(root->is_clipped()); |
| 1914 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1915 | EXPECT_FALSE(parent->is_clipped()); |
| 1916 | EXPECT_FALSE(child1->is_clipped()); |
| 1917 | EXPECT_TRUE(child2->is_clipped()); |
| 1918 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1919 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1920 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1921 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1922 | } |
| 1923 | |
| 1924 | TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) { |
| 1925 | // Tests that when as long as layer is clipped, it's clip rect is set to |
| 1926 | // correct value. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1927 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1928 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1929 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1930 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1931 | root->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1932 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1933 | parent->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1934 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1935 | child->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1936 | child->SetDrawsContent(true); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1937 | child->SetMasksToBounds(true); |
| 1938 | |
| 1939 | ExecuteCalculateDrawProperties(root); |
| 1940 | |
| 1941 | EXPECT_FALSE(root->is_clipped()); |
| 1942 | EXPECT_FALSE(parent->is_clipped()); |
| 1943 | EXPECT_TRUE(child->is_clipped()); |
| 1944 | EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect()); |
| 1945 | |
| 1946 | parent->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1947 | child->SetPosition(gfx::PointF(100.f, 100.f)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1948 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1949 | |
| 1950 | ExecuteCalculateDrawProperties(root); |
| 1951 | |
| 1952 | EXPECT_FALSE(root->is_clipped()); |
| 1953 | EXPECT_TRUE(parent->is_clipped()); |
| 1954 | EXPECT_TRUE(child->is_clipped()); |
| 1955 | EXPECT_EQ(gfx::Rect(), child->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1956 | } |
| 1957 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1958 | TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { |
| 1959 | // Tests that when separate surfaces are disabled, is_clipped is true exactly |
| 1960 | // when a layer or its ancestor has a clip; in particular, if a layer |
| 1961 | // is_clipped, so is its entire subtree (since there are no render surfaces |
| 1962 | // that can reset is_clipped). |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1963 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1964 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1965 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1966 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1967 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1968 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1969 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1970 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1971 | root->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1972 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1973 | parent->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1974 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1975 | child1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1976 | child1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1977 | child1->test_properties()->force_render_surface = true; |
| 1978 | child2->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1979 | child2->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1980 | grand_child->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1981 | grand_child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1982 | grand_child->test_properties()->force_render_surface = true; |
| 1983 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1984 | leaf_node1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1985 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1986 | leaf_node2->SetDrawsContent(true); |
| 1987 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1988 | // Case 1: Nothing is clipped. In this case, is_clipped is always false, with |
| 1989 | // or without surfaces. |
| 1990 | ExecuteCalculateDrawProperties(root); |
| 1991 | EXPECT_FALSE(root->is_clipped()); |
| 1992 | EXPECT_FALSE(parent->is_clipped()); |
| 1993 | EXPECT_FALSE(child1->is_clipped()); |
| 1994 | EXPECT_FALSE(child2->is_clipped()); |
| 1995 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1996 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1997 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1998 | |
| 1999 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2000 | EXPECT_FALSE(root->is_clipped()); |
| 2001 | EXPECT_FALSE(parent->is_clipped()); |
| 2002 | EXPECT_FALSE(child1->is_clipped()); |
| 2003 | EXPECT_FALSE(child2->is_clipped()); |
| 2004 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2005 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2006 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2007 | |
| 2008 | // Case 2: The root is clipped. With surfaces, this only persists until the |
| 2009 | // next render surface. Without surfaces, the entire tree is clipped. |
| 2010 | root->SetMasksToBounds(true); |
| 2011 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2012 | ExecuteCalculateDrawProperties(root); |
| 2013 | EXPECT_TRUE(root->is_clipped()); |
| 2014 | EXPECT_TRUE(parent->is_clipped()); |
| 2015 | EXPECT_FALSE(child1->is_clipped()); |
| 2016 | EXPECT_TRUE(child2->is_clipped()); |
| 2017 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2018 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2019 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2020 | |
| 2021 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2022 | EXPECT_TRUE(root->is_clipped()); |
| 2023 | EXPECT_TRUE(parent->is_clipped()); |
| 2024 | EXPECT_TRUE(child1->is_clipped()); |
| 2025 | EXPECT_TRUE(child2->is_clipped()); |
| 2026 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2027 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2028 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2029 | |
| 2030 | root->SetMasksToBounds(false); |
| 2031 | |
| 2032 | // Case 3: The parent is clipped. Again, with surfaces, this only persists |
| 2033 | // until the next render surface. Without surfaces, parent's entire subtree is |
| 2034 | // clipped. |
| 2035 | parent->SetMasksToBounds(true); |
| 2036 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2037 | ExecuteCalculateDrawProperties(root); |
| 2038 | EXPECT_FALSE(root->is_clipped()); |
| 2039 | EXPECT_TRUE(parent->is_clipped()); |
| 2040 | EXPECT_FALSE(child1->is_clipped()); |
| 2041 | EXPECT_TRUE(child2->is_clipped()); |
| 2042 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2043 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2044 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2045 | |
| 2046 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2047 | EXPECT_FALSE(root->is_clipped()); |
| 2048 | EXPECT_TRUE(parent->is_clipped()); |
| 2049 | EXPECT_TRUE(child1->is_clipped()); |
| 2050 | EXPECT_TRUE(child2->is_clipped()); |
| 2051 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2052 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2053 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2054 | |
| 2055 | parent->SetMasksToBounds(false); |
| 2056 | |
| 2057 | // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it |
| 2058 | // has no non-surface children. Without surfaces, child1's entire subtree is |
| 2059 | // clipped. |
| 2060 | child1->SetMasksToBounds(true); |
| 2061 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2062 | ExecuteCalculateDrawProperties(root); |
| 2063 | EXPECT_FALSE(root->is_clipped()); |
| 2064 | EXPECT_FALSE(parent->is_clipped()); |
| 2065 | EXPECT_TRUE(child1->is_clipped()); |
| 2066 | EXPECT_FALSE(child2->is_clipped()); |
| 2067 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2068 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2069 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2070 | |
| 2071 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2072 | EXPECT_FALSE(root->is_clipped()); |
| 2073 | EXPECT_FALSE(parent->is_clipped()); |
| 2074 | EXPECT_TRUE(child1->is_clipped()); |
| 2075 | EXPECT_FALSE(child2->is_clipped()); |
| 2076 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2077 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2078 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2079 | |
| 2080 | child1->SetMasksToBounds(false); |
| 2081 | |
| 2082 | // Case 5: Only the leaf nodes are clipped. The behavior with and without |
| 2083 | // surfaces is the same. |
| 2084 | leaf_node1->SetMasksToBounds(true); |
| 2085 | leaf_node2->SetMasksToBounds(true); |
| 2086 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2087 | ExecuteCalculateDrawProperties(root); |
| 2088 | EXPECT_FALSE(root->is_clipped()); |
| 2089 | EXPECT_FALSE(parent->is_clipped()); |
| 2090 | EXPECT_FALSE(child1->is_clipped()); |
| 2091 | EXPECT_FALSE(child2->is_clipped()); |
| 2092 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2093 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2094 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2095 | |
| 2096 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2097 | EXPECT_FALSE(root->is_clipped()); |
| 2098 | EXPECT_FALSE(parent->is_clipped()); |
| 2099 | EXPECT_FALSE(child1->is_clipped()); |
| 2100 | EXPECT_FALSE(child2->is_clipped()); |
| 2101 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2102 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2103 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2104 | } |
| 2105 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 2106 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2107 | // Verify that layers get the appropriate DrawableContentRect when their |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2108 | // parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2109 | // |
| 2110 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 2111 | // be the layer rect expressed in target space. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2112 | // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2113 | // will be the intersection of layer bounds and the mask region. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2114 | // grand_child3 - partially clipped and MasksToBounds; the |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2115 | // DrawableContentRect will still be the intersection of layer bounds and |
| 2116 | // the mask region. |
| 2117 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 2118 | // be empty. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2119 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2120 | LayerImpl* parent = root_layer_for_testing(); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2121 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2122 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2123 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2124 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2125 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2126 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2127 | parent->SetBounds(gfx::Size(500, 500)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2128 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2129 | child->SetBounds(gfx::Size(20, 20)); |
| 2130 | child->test_properties()->force_render_surface = true; |
| 2131 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2132 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 2133 | grand_child1->SetDrawsContent(true); |
| 2134 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2135 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 2136 | grand_child2->SetDrawsContent(true); |
| 2137 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2138 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2139 | grand_child3->SetBounds(gfx::Size(10, 10)); |
| 2140 | grand_child3->SetDrawsContent(true); |
| 2141 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 2142 | grand_child4->SetBounds(gfx::Size(10, 10)); |
| 2143 | grand_child4->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2144 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2145 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2146 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2147 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2148 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2149 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2150 | } |
| 2151 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2152 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2153 | // Verify that render surfaces (and their layers) get the appropriate |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2154 | // clip rects when their parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2155 | // |
| 2156 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2157 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2158 | // They may still have a clip rect of their own layer bounds, however, if |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2159 | // MasksToBounds was true. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2160 | LayerImpl* parent = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2161 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2162 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2163 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2164 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2165 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2166 | // The leaf nodes ensure that these grand_children become render surfaces for |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2167 | // this test. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2168 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2169 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2170 | LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2171 | LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2172 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2173 | parent->SetBounds(gfx::Size(500, 500)); |
| 2174 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2175 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2176 | child->test_properties()->force_render_surface = true; |
| 2177 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2178 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 2179 | grand_child1->test_properties()->force_render_surface = true; |
| 2180 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2181 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 2182 | grand_child2->test_properties()->force_render_surface = true; |
| 2183 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2184 | grand_child3->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2185 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2186 | grand_child3->test_properties()->force_render_surface = true; |
| 2187 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 2188 | grand_child4->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2189 | grand_child4->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2190 | grand_child4->test_properties()->force_render_surface = true; |
| 2191 | leaf_node1->SetBounds(gfx::Size(10, 10)); |
| 2192 | leaf_node1->SetDrawsContent(true); |
| 2193 | leaf_node2->SetBounds(gfx::Size(10, 10)); |
| 2194 | leaf_node2->SetDrawsContent(true); |
| 2195 | leaf_node3->SetBounds(gfx::Size(10, 10)); |
| 2196 | leaf_node3->SetDrawsContent(true); |
| 2197 | leaf_node4->SetBounds(gfx::Size(10, 10)); |
| 2198 | leaf_node4->SetDrawsContent(true); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2199 | ExecuteCalculateDrawProperties(parent); |
| 2200 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2201 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2202 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2203 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2204 | |
| 2205 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2206 | // MasksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2207 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2208 | grand_child1->render_surface()->clip_rect()); |
| 2209 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2210 | grand_child2->render_surface()->clip_rect()); |
| 2211 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2212 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2213 | } |
| 2214 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2215 | TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { |
| 2216 | // Tests that when separate surfaces are disabled, a layer's clip_rect is the |
| 2217 | // intersection of all ancestor clips in screen space; in particular, if a |
| 2218 | // layer masks to bounds, it contributes to the clip_rect of all layers in its |
| 2219 | // subtree (since there are no render surfaces that can reset the clip_rect). |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2220 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2221 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2222 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 2223 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 2224 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 2225 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 2226 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 2227 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2228 | root->SetBounds(gfx::Size(100, 100)); |
| 2229 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2230 | parent->SetBounds(gfx::Size(400, 400)); |
| 2231 | child1->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2232 | child1->SetBounds(gfx::Size(800, 800)); |
| 2233 | child2->SetPosition(gfx::PointF(3.f, 3.f)); |
| 2234 | child2->SetBounds(gfx::Size(800, 800)); |
| 2235 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2236 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2237 | leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2238 | leaf_node1->SetBounds(gfx::Size(2000, 2000)); |
| 2239 | leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); |
| 2240 | leaf_node2->SetBounds(gfx::Size(2000, 2000)); |
| 2241 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2242 | root->SetDrawsContent(true); |
| 2243 | parent->SetDrawsContent(true); |
| 2244 | child1->SetDrawsContent(true); |
| 2245 | child2->SetDrawsContent(true); |
| 2246 | grand_child->SetDrawsContent(true); |
| 2247 | leaf_node1->SetDrawsContent(true); |
| 2248 | leaf_node2->SetDrawsContent(true); |
| 2249 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2250 | root->test_properties()->force_render_surface = true; |
| 2251 | child1->test_properties()->force_render_surface = true; |
| 2252 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2253 | |
| 2254 | // Case 1: Nothing is clipped. In this case, each layer's clip rect is its |
| 2255 | // bounds in target space. The only thing that changes when surfaces are |
| 2256 | // disabled is that target space is always screen space. |
| 2257 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2258 | EXPECT_TRUE(root->has_render_surface()); |
| 2259 | EXPECT_FALSE(parent->has_render_surface()); |
| 2260 | EXPECT_TRUE(child1->has_render_surface()); |
| 2261 | EXPECT_FALSE(child2->has_render_surface()); |
| 2262 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2263 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2264 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2265 | EXPECT_FALSE(root->is_clipped()); |
| 2266 | EXPECT_FALSE(parent->is_clipped()); |
| 2267 | EXPECT_FALSE(child1->is_clipped()); |
| 2268 | EXPECT_FALSE(child2->is_clipped()); |
| 2269 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2270 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2271 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2272 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2273 | EXPECT_FALSE(child1->render_surface()->is_clipped()); |
| 2274 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2275 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2276 | |
| 2277 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2278 | EXPECT_FALSE(root->is_clipped()); |
| 2279 | EXPECT_FALSE(parent->is_clipped()); |
| 2280 | EXPECT_FALSE(child1->is_clipped()); |
| 2281 | EXPECT_FALSE(child2->is_clipped()); |
| 2282 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2283 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2284 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2285 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2286 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2287 | |
| 2288 | // Case 2: The root is clipped. In this case, layers that draw into the root |
| 2289 | // render surface are clipped by the root's bounds. |
| 2290 | root->SetMasksToBounds(true); |
| 2291 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2292 | root->test_properties()->force_render_surface = true; |
| 2293 | child1->test_properties()->force_render_surface = true; |
| 2294 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2295 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2296 | EXPECT_TRUE(root->has_render_surface()); |
| 2297 | EXPECT_FALSE(parent->has_render_surface()); |
| 2298 | EXPECT_TRUE(child1->has_render_surface()); |
| 2299 | EXPECT_FALSE(child2->has_render_surface()); |
| 2300 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2301 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2302 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2303 | EXPECT_TRUE(root->is_clipped()); |
| 2304 | EXPECT_TRUE(parent->is_clipped()); |
| 2305 | EXPECT_FALSE(child1->is_clipped()); |
| 2306 | EXPECT_TRUE(child1->render_surface()->is_clipped()); |
| 2307 | EXPECT_TRUE(child2->is_clipped()); |
| 2308 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2309 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2310 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2311 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2312 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2313 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2314 | EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2315 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2316 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2317 | |
| 2318 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2319 | EXPECT_TRUE(root->is_clipped()); |
| 2320 | EXPECT_TRUE(parent->is_clipped()); |
| 2321 | EXPECT_TRUE(child1->is_clipped()); |
| 2322 | EXPECT_TRUE(child2->is_clipped()); |
| 2323 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2324 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2325 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2326 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2327 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
| 2328 | EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect()); |
| 2329 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
| 2330 | EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect()); |
| 2331 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect()); |
| 2332 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2333 | |
| 2334 | root->SetMasksToBounds(false); |
| 2335 | |
| 2336 | // Case 3: The parent and child1 are clipped. When surfaces are enabled, the |
| 2337 | // parent clip rect only contributes to the subtree rooted at child2, since |
| 2338 | // the subtree rooted at child1 renders into a separate surface. Similarly, |
| 2339 | // child1's clip rect doesn't contribute to its descendants, since its only |
| 2340 | // child is a render surface. However, without surfaces, these clip rects |
| 2341 | // contribute to all descendants. |
| 2342 | parent->SetMasksToBounds(true); |
| 2343 | child1->SetMasksToBounds(true); |
| 2344 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2345 | root->test_properties()->force_render_surface = true; |
| 2346 | child1->test_properties()->force_render_surface = true; |
| 2347 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2348 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2349 | EXPECT_TRUE(root->has_render_surface()); |
| 2350 | EXPECT_FALSE(parent->has_render_surface()); |
| 2351 | EXPECT_TRUE(child1->has_render_surface()); |
| 2352 | EXPECT_FALSE(child2->has_render_surface()); |
| 2353 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2354 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2355 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2356 | EXPECT_FALSE(root->is_clipped()); |
| 2357 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2358 | EXPECT_TRUE(parent->is_clipped()); |
| 2359 | EXPECT_TRUE(child1->is_clipped()); |
| 2360 | EXPECT_TRUE(child2->is_clipped()); |
| 2361 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2362 | EXPECT_TRUE(grand_child->render_surface()->is_clipped()); |
| 2363 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2364 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2365 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2366 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2367 | EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); |
| 2368 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2369 | EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2370 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2371 | |
| 2372 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2373 | EXPECT_FALSE(root->is_clipped()); |
| 2374 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2375 | EXPECT_TRUE(parent->is_clipped()); |
| 2376 | EXPECT_TRUE(child1->is_clipped()); |
| 2377 | EXPECT_TRUE(child2->is_clipped()); |
| 2378 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2379 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2380 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2381 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2382 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2383 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect()); |
| 2384 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
| 2385 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect()); |
| 2386 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect()); |
| 2387 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2388 | } |
| 2389 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2390 | TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2391 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2392 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2393 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2394 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2395 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2396 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2397 | root->SetBounds(gfx::Size(100, 100)); |
| 2398 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2399 | parent->SetBounds(gfx::Size(400, 400)); |
| 2400 | parent->SetMasksToBounds(true); |
| 2401 | child->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2402 | child->SetBounds(gfx::Size(800, 800)); |
| 2403 | child->SetMasksToBounds(true); |
| 2404 | child->test_properties()->force_render_surface = true; |
| 2405 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2406 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2407 | grand_child->test_properties()->force_render_surface = true; |
| 2408 | leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2409 | leaf_node->SetBounds(gfx::Size(2000, 2000)); |
| 2410 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2411 | root->SetDrawsContent(true); |
| 2412 | parent->SetDrawsContent(true); |
| 2413 | child->SetDrawsContent(true); |
| 2414 | grand_child->SetDrawsContent(true); |
| 2415 | leaf_node->SetDrawsContent(true); |
| 2416 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2417 | host_impl()->set_resourceless_software_draw_for_testing(); |
| 2418 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2419 | gfx::PointF test_point(90.f, 90.f); |
| 2420 | LayerImpl* result_layer = |
| 2421 | root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point); |
| 2422 | ASSERT_TRUE(result_layer); |
| 2423 | EXPECT_EQ(leaf_node, result_layer); |
| 2424 | } |
| 2425 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2426 | TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { |
| 2427 | // Tests that draw properties are computed correctly when we disable and then |
| 2428 | // re-enable separate surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2429 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2430 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2431 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2432 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2433 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2434 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2435 | root->SetBounds(gfx::Size(100, 100)); |
| 2436 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2437 | parent->SetBounds(gfx::Size(400, 400)); |
| 2438 | parent->SetMasksToBounds(true); |
| 2439 | child->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2440 | child->SetBounds(gfx::Size(800, 800)); |
| 2441 | child->SetMasksToBounds(true); |
| 2442 | child->test_properties()->force_render_surface = true; |
| 2443 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2444 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2445 | grand_child->test_properties()->force_render_surface = true; |
| 2446 | leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2447 | leaf_node->SetBounds(gfx::Size(2000, 2000)); |
| 2448 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2449 | root->SetDrawsContent(true); |
| 2450 | parent->SetDrawsContent(true); |
| 2451 | child->SetDrawsContent(true); |
| 2452 | grand_child->SetDrawsContent(true); |
| 2453 | leaf_node->SetDrawsContent(true); |
| 2454 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2455 | gfx::Transform expected_leaf_draw_transform_with_surfaces; |
| 2456 | expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); |
| 2457 | |
| 2458 | gfx::Transform expected_leaf_draw_transform_without_surfaces; |
| 2459 | expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); |
| 2460 | |
| 2461 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2462 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2463 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2464 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2465 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, |
| 2466 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2467 | |
| 2468 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2469 | EXPECT_TRUE(leaf_node->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2470 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); |
| 2471 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2472 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces, |
| 2473 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2474 | |
| 2475 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2476 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2477 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2478 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2479 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, |
| 2480 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2481 | } |
| 2482 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2483 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2484 | LayerImpl* root = root_layer_for_testing(); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2485 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 2486 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
| 2487 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 2488 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 2489 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
| 2490 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 2491 | LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
| 2492 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2493 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2494 | root->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2495 | render_surface1->SetDrawsContent(true); |
| 2496 | child_of_rs1->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2497 | grand_child_of_rs1->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2498 | render_surface2->SetDrawsContent(true); |
| 2499 | child_of_rs2->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2500 | grand_child_of_rs2->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2501 | child_of_root->SetDrawsContent(true); |
| 2502 | grand_child_of_root->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2503 | |
| 2504 | gfx::Transform layer_transform; |
| 2505 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2506 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2507 | root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2508 | root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2509 | root->SetBounds(gfx::Size(10, 10)); |
| 2510 | root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2511 | render_surface1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2512 | render_surface1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2513 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 2514 | render_surface1->test_properties()->transform_origin = |
| 2515 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2516 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2517 | render_surface2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2518 | render_surface2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2519 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 2520 | render_surface2->test_properties()->transform_origin = |
| 2521 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2522 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2523 | child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2524 | child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2525 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2526 | child_of_root->test_properties()->transform_origin = |
| 2527 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2528 | child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2529 | child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2530 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2531 | child_of_rs1->test_properties()->transform_origin = |
| 2532 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2533 | child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2534 | child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2535 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2536 | child_of_rs2->test_properties()->transform_origin = |
| 2537 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2538 | grand_child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2539 | grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2540 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2541 | grand_child_of_root->test_properties()->transform_origin = |
| 2542 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2543 | grand_child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2544 | grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2545 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2546 | grand_child_of_rs1->test_properties()->transform_origin = |
| 2547 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2548 | grand_child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2549 | grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2550 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2551 | grand_child_of_rs2->test_properties()->transform_origin = |
| 2552 | gfx::Point3F(0.25f, 0.f, 0.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2553 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2554 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2555 | SetElementIdsForTesting(); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 2556 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2557 | // Put an animated opacity on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2558 | AddOpacityTransitionToElementWithPlayer( |
| 2559 | render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2560 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2561 | // Also put an animated opacity on a layer without descendants. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2562 | AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(), |
| 2563 | timeline_impl(), 10.0, 1.f, 0.f, |
| 2564 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2565 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2566 | // Put a transform animation on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2567 | AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(), |
| 2568 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2569 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2570 | // Also put transform animations on grand_child_of_root, and |
| 2571 | // grand_child_of_rs2 |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2572 | AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(), |
| 2573 | timeline_impl(), 10.0, 30, 0); |
| 2574 | AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(), |
| 2575 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2576 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2577 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 2578 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2579 | |
| 2580 | // Only layers that are associated with render surfaces should have an actual |
| 2581 | // RenderSurface() value. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2582 | ASSERT_TRUE(root->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2583 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2584 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2585 | |
| 2586 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2587 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2588 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2589 | |
| 2590 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2591 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2592 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2593 | |
| 2594 | // Verify all render target accessors |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2595 | EXPECT_EQ(root->render_surface(), root->render_target()); |
| 2596 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 2597 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2598 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2599 | EXPECT_EQ(render_surface1->render_surface(), |
| 2600 | render_surface1->render_target()); |
| 2601 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 2602 | EXPECT_EQ(render_surface1->render_surface(), |
| 2603 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2604 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2605 | EXPECT_EQ(render_surface2->render_surface(), |
| 2606 | render_surface2->render_target()); |
| 2607 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 2608 | EXPECT_EQ(render_surface2->render_surface(), |
| 2609 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2610 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2611 | // Verify screen_space_transform_is_animating values |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2612 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2613 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2614 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2615 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2616 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2617 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2618 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2619 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2620 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2621 | |
| 2622 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2623 | // It is expected that we correctly set up transforms so that the y-component |
| 2624 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2625 | EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2626 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2627 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2628 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2629 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2630 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2631 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2632 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2633 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2634 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2635 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2636 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2637 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2638 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2639 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2640 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2641 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2642 | } |
| 2643 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2644 | TEST_F(LayerTreeHostCommonTest, LargeTransforms) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2645 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2646 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2647 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2648 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2649 | gfx::Transform large_transform; |
| 2650 | large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); |
| 2651 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2652 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2653 | child->test_properties()->transform = large_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2654 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2655 | grand_child->test_properties()->transform = large_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2656 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2657 | grand_child->SetDrawsContent(true); |
| 2658 | ExecuteCalculateDrawProperties(root); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2659 | |
| 2660 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
| 2661 | } |
| 2662 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2663 | TEST_F(LayerTreeHostCommonTest, |
| 2664 | ScreenSpaceTransformIsAnimatingWithDelayedAnimation) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2665 | LayerImpl* root = root_layer_for_testing(); |
| 2666 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2667 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2668 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 2669 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2670 | root->SetDrawsContent(true); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2671 | child->SetDrawsContent(true); |
| 2672 | grand_child->SetDrawsContent(true); |
| 2673 | great_grand_child->SetDrawsContent(true); |
| 2674 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2675 | root->SetBounds(gfx::Size(10, 10)); |
| 2676 | child->SetBounds(gfx::Size(10, 10)); |
| 2677 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2678 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2679 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2680 | SetElementIdsForTesting(); |
| 2681 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2682 | // Add a transform animation with a start delay to |grand_child|. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2683 | std::unique_ptr<Animation> animation = Animation::Create( |
| 2684 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1, |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 2685 | TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 2686 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2687 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2688 | AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(), |
| 2689 | std::move(animation)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2690 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2691 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2692 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2693 | EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 2694 | |
| 2695 | EXPECT_FALSE(grand_child->TransformIsAnimating()); |
| 2696 | EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation()); |
| 2697 | EXPECT_TRUE(grand_child->screen_space_transform_is_animating()); |
| 2698 | EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating()); |
| 2699 | } |
| 2700 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2701 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) { |
| 2702 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2703 | // correctly for identity transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2704 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2705 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2706 | gfx::Transform layer_to_surface_transform; |
| 2707 | |
| 2708 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2709 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2710 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2711 | gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30); |
| 2712 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2713 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2714 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2715 | EXPECT_EQ(expected_drawable_content_rect, |
| 2716 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2717 | |
| 2718 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2719 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2720 | expected_visible_layer_rect = gfx::Rect(); |
| 2721 | expected_drawable_content_rect = gfx::Rect(); |
| 2722 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2723 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2724 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2725 | EXPECT_EQ(expected_drawable_content_rect, |
| 2726 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2727 | |
| 2728 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2729 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2730 | expected_visible_layer_rect = gfx::Rect(20, 20); |
| 2731 | expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20); |
| 2732 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2733 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2734 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2735 | EXPECT_EQ(expected_drawable_content_rect, |
| 2736 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2737 | } |
| 2738 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2739 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) { |
| 2740 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2741 | // for rotations about z-axis (i.e. 2D rotations). |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2742 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2743 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2744 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2745 | gfx::Transform layer_to_surface_transform; |
| 2746 | |
| 2747 | // Case 1: Layer is contained within the surface. |
| 2748 | layer_to_surface_transform.MakeIdentity(); |
| 2749 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2750 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2751 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2752 | gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43); |
| 2753 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2754 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2755 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2756 | EXPECT_EQ(expected_drawable_content_rect, |
| 2757 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2758 | |
| 2759 | // Case 2: Layer is outside the surface rect. |
| 2760 | layer_to_surface_transform.MakeIdentity(); |
| 2761 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2762 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2763 | expected_visible_layer_rect = gfx::Rect(); |
| 2764 | expected_drawable_content_rect = gfx::Rect(); |
| 2765 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2766 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2767 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2768 | EXPECT_EQ(expected_drawable_content_rect, |
| 2769 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2770 | |
| 2771 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2772 | // the layer is oriented diagonally, with the left half outside of the render |
| 2773 | // surface. In this case, the g should still be the entire layer |
| 2774 | // (remember the g is computed in layer space); both the top-left |
| 2775 | // and bottom-right corners of the layer are still visible. |
| 2776 | layer_to_surface_transform.MakeIdentity(); |
| 2777 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2778 | expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2779 | expected_drawable_content_rect = gfx::Rect(22, 43); |
| 2780 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2781 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2782 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2783 | EXPECT_EQ(expected_drawable_content_rect, |
| 2784 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2785 | |
| 2786 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2787 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2788 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2789 | // surface overlaps the right side of the layer. The g should be |
| 2790 | // the layer's right half. |
| 2791 | layer_to_surface_transform.MakeIdentity(); |
| 2792 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2793 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2794 | // Right half of layer bounds. |
| 2795 | expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30); |
| 2796 | expected_drawable_content_rect = gfx::Rect(22, 22); |
| 2797 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2798 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2799 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2800 | EXPECT_EQ(expected_drawable_content_rect, |
| 2801 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2802 | } |
| 2803 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2804 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) { |
| 2805 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2806 | // for 3d transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2807 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2808 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2809 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2810 | gfx::Transform layer_to_surface_transform; |
| 2811 | |
| 2812 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2813 | // degrees, should be fully contained in the render surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2814 | // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2815 | layer_to_surface_transform.MakeIdentity(); |
| 2816 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2817 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2818 | gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100); |
| 2819 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2820 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2821 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2822 | EXPECT_EQ(expected_drawable_content_rect, |
| 2823 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2824 | |
| 2825 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2826 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2827 | // visible on the surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2828 | // 50 is the un-rotated layer width; divided by sqrt(2) is the rotated width. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2829 | SkMScalar half_width_of_rotated_layer = |
| 2830 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2831 | layer_to_surface_transform.MakeIdentity(); |
| 2832 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2833 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2834 | // edge of the layer. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2835 | // Tight half of the layer. |
| 2836 | expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100); |
| 2837 | expected_drawable_content_rect = gfx::Rect(36, 100); |
| 2838 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2839 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2840 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2841 | EXPECT_EQ(expected_drawable_content_rect, |
| 2842 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2843 | } |
| 2844 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2845 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) { |
| 2846 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2847 | // when the layer has a perspective projection onto the target surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2848 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2849 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2850 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2851 | gfx::Transform layer_to_surface_transform; |
| 2852 | |
| 2853 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2854 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2855 | // its translated more than the perspective amount. |
| 2856 | layer_to_surface_transform.MakeIdentity(); |
| 2857 | |
| 2858 | // The following sequence of transforms applies the perspective about the |
| 2859 | // center of the surface. |
| 2860 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2861 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2862 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2863 | |
| 2864 | // This translate places the layer in front of the surface's projection plane. |
| 2865 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2866 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2867 | // Layer position is (-50, -50), visible rect in layer space is layer bounds |
| 2868 | // offset by layer position. |
| 2869 | gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150); |
| 2870 | gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38); |
| 2871 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2872 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2873 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2874 | EXPECT_EQ(expected_drawable_content_rect, |
| 2875 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2876 | |
| 2877 | // Case 2: same projection as before, except that the layer is also translated |
| 2878 | // to the side, so that only the right half of the layer should be visible. |
| 2879 | // |
| 2880 | // Explanation of expected result: The perspective ratio is (z distance |
| 2881 | // between layer and camera origin) / (z distance between projection plane and |
| 2882 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2883 | // move a layer by translating -25 units in projected surface units (so that |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2884 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2885 | // -25 == -100 in the layer's units. |
| 2886 | layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0); |
| 2887 | // Visible layer rect is moved by 100, and drawable content rect is in target |
| 2888 | // space and is moved by 25. |
| 2889 | expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150); |
| 2890 | expected_drawable_content_rect = gfx::Rect(13, 38); |
| 2891 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2892 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2893 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2894 | EXPECT_EQ(expected_drawable_content_rect, |
| 2895 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2896 | } |
| 2897 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2898 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2899 | DrawRectsFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2900 | // There is currently no explicit concept of an orthographic projection plane |
| 2901 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2902 | // are technically behind the surface in an orthographic world should not be |
| 2903 | // clipped when they are flattened to the surface. |
| 2904 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2905 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2906 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2907 | gfx::Transform layer_to_surface_transform; |
| 2908 | |
| 2909 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2910 | // at the center of the layer. |
| 2911 | layer_to_surface_transform.MakeIdentity(); |
| 2912 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2913 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2914 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2915 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2916 | // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface |
| 2917 | // space. |
| 2918 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2919 | gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100); |
| 2920 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2921 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2922 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2923 | EXPECT_EQ(expected_drawable_content_rect, |
| 2924 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2925 | } |
| 2926 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2927 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2928 | DrawRectsFor3dPerspectiveWhenClippedByW) { |
| 2929 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2930 | // when projecting a surface onto a layer, but the layer is partially behind |
| 2931 | // the camera (not just behind the projection plane). In this case, the |
| 2932 | // cartesian coordinates may seem to be valid, but actually they are not. The |
| 2933 | // visible rect needs to be properly clipped by the w = 0 plane in homogeneous |
| 2934 | // coordinates before converting to cartesian coordinates. The drawable |
| 2935 | // content rect would be entire surface rect because layer is rotated at the |
| 2936 | // camera position. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2937 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2938 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200); |
| 2939 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2940 | gfx::Transform layer_to_surface_transform; |
| 2941 | |
| 2942 | // The layer is positioned so that the right half of the layer should be in |
| 2943 | // front of the camera, while the other half is behind the surface's |
| 2944 | // projection plane. The following sequence of transforms applies the |
| 2945 | // perspective and rotation about the center of the layer. |
| 2946 | layer_to_surface_transform.MakeIdentity(); |
| 2947 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2948 | layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0); |
| 2949 | layer_to_surface_transform.RotateAboutYAxis(-45.0); |
| 2950 | layer_to_surface_transform.Translate(-10, -1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2951 | |
| 2952 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2953 | // transform, otherwise this code is not testing the intended scenario. |
| 2954 | bool clipped; |
| 2955 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2956 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2957 | &clipped); |
| 2958 | ASSERT_TRUE(clipped); |
| 2959 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2960 | gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1); |
| 2961 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 2962 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2963 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2964 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2965 | EXPECT_EQ(expected_drawable_content_rect, |
| 2966 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2967 | } |
| 2968 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2969 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2970 | // To determine visible rect in layer space, there needs to be an |
| 2971 | // un-projection from surface space to layer space. When the original |
| 2972 | // transform was a perspective projection that was clipped, it returns a rect |
| 2973 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2974 | // clipping again. |
| 2975 | |
| 2976 | // This sequence of transforms causes one corner of the layer to protrude |
| 2977 | // across the w = 0 plane, and should be clipped. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2978 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150); |
| 2979 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2980 | gfx::Transform layer_to_surface_transform; |
| 2981 | layer_to_surface_transform.MakeIdentity(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2982 | layer_to_surface_transform.Translate(10, 10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2983 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2984 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2985 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2986 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2987 | layer_to_surface_transform.Translate(-10, -10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2988 | |
| 2989 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2990 | // code is not testing the intended scenario. |
| 2991 | bool clipped; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2992 | gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
| 2993 | layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2994 | MathUtil::ProjectQuad( |
| 2995 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2996 | ASSERT_TRUE(clipped); |
| 2997 | |
| 2998 | // Only the corner of the layer is not visible on the surface because of being |
| 2999 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 3000 | // rect is that the entire layer should still be considered visible. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3001 | gfx::Rect expected_visible_layer_rect = layer_content_rect; |
| 3002 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 3003 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 3004 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 3005 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 3006 | EXPECT_EQ(expected_drawable_content_rect, |
| 3007 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3008 | } |
| 3009 | |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3010 | TEST_F(LayerTreeHostCommonTest, |
| 3011 | VisibleRectsForPositionedRootLayerClippedByViewport) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3012 | LayerImpl* root = root_layer_for_testing(); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3013 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3014 | root->SetPosition(gfx::PointF(60, 70)); |
| 3015 | root->SetBounds(gfx::Size(100, 100)); |
| 3016 | root->SetDrawsContent(true); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3017 | ExecuteCalculateDrawProperties(root); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3018 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3019 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3020 | root->render_surface()->DrawableContentRect()); |
| 3021 | // In target space, not clipped. |
| 3022 | EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 3023 | // In layer space, clipped. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3024 | EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3025 | } |
| 3026 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3027 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3028 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3029 | LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3030 | LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3031 | LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3032 | |
| 3033 | root->SetBounds(gfx::Size(100, 100)); |
| 3034 | child1_layer->SetBounds(gfx::Size(50, 50)); |
| 3035 | child1_layer->SetDrawsContent(true); |
| 3036 | child2_layer->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3037 | child2_layer->SetBounds(gfx::Size(50, 50)); |
| 3038 | child2_layer->SetDrawsContent(true); |
| 3039 | child3_layer->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3040 | child3_layer->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3041 | child3_layer->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3042 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3043 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3044 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3045 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3046 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3047 | // Layers that do not draw content should have empty visible_layer_rects. |
| 3048 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3049 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3050 | // layer visible_layer_rects are clipped by their target surface. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3051 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); |
| 3052 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); |
| 3053 | EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3054 | |
| 3055 | // layer drawable_content_rects are not clipped. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3056 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect()); |
| 3057 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect()); |
| 3058 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3059 | } |
| 3060 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3061 | TEST_F(LayerTreeHostCommonTest, |
| 3062 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3063 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3064 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3065 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3066 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3067 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3068 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3069 | root->SetBounds(gfx::Size(100, 100)); |
| 3070 | child->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3071 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3072 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3073 | grand_child1->SetBounds(gfx::Size(50, 50)); |
| 3074 | grand_child1->SetDrawsContent(true); |
| 3075 | grand_child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3076 | grand_child2->SetBounds(gfx::Size(50, 50)); |
| 3077 | grand_child2->SetDrawsContent(true); |
| 3078 | grand_child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3079 | grand_child3->SetBounds(gfx::Size(50, 50)); |
| 3080 | grand_child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3081 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3082 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3083 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3084 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3085 | |
| 3086 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3087 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3088 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3089 | |
| 3090 | // All grandchild visible content rects should be clipped by child. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3091 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); |
| 3092 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); |
| 3093 | EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3094 | |
| 3095 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3096 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 3097 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3098 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 3099 | } |
| 3100 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3101 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3102 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3103 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 3104 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3105 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3106 | gfx::Transform child_scale_matrix; |
| 3107 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 3108 | gfx::Transform grand_child_scale_matrix; |
| 3109 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3110 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3111 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3112 | child->test_properties()->transform = child_scale_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3113 | child->SetBounds(gfx::Size(10, 10)); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3114 | child->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3115 | grand_child->test_properties()->transform = grand_child_scale_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3116 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3117 | grand_child->SetDrawsContent(true); |
| 3118 | ExecuteCalculateDrawProperties(root); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3119 | |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 3120 | // The visible rect is expanded to integer coordinates. |
| 3121 | EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3122 | } |
| 3123 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3124 | TEST_F(LayerTreeHostCommonTest, |
| 3125 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3126 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3127 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3128 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3129 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3130 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3131 | |
| 3132 | root->SetBounds(gfx::Size(100, 100)); |
| 3133 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3134 | render_surface->test_properties()->force_render_surface = true; |
| 3135 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3136 | child1->SetBounds(gfx::Size(50, 50)); |
| 3137 | child1->SetDrawsContent(true); |
| 3138 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3139 | child2->SetBounds(gfx::Size(50, 50)); |
| 3140 | child2->SetDrawsContent(true); |
| 3141 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3142 | child3->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3143 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3144 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3145 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3146 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3147 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3148 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3149 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3150 | |
| 3151 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3152 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3153 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3154 | |
| 3155 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 3156 | // regions of the subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3157 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3158 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3159 | |
| 3160 | // All layers that draw content into the unclipped surface are also unclipped. |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3161 | // Only the viewport clip should apply |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3162 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3163 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3164 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3165 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3166 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3167 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3168 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3169 | } |
| 3170 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3171 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3172 | DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3173 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3174 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 3175 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 3176 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 3177 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); |
| 3178 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); |
| 3179 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 3180 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 3181 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3182 | root->SetBounds(gfx::Size(100, 100)); |
| 3183 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 3184 | parent->SetBounds(gfx::Size(400, 400)); |
| 3185 | child1->SetPosition(gfx::PointF(4.f, 4.f)); |
| 3186 | child1->SetBounds(gfx::Size(800, 800)); |
| 3187 | child1->test_properties()->force_render_surface = true; |
| 3188 | child2->SetPosition(gfx::PointF(3.f, 3.f)); |
| 3189 | child2->SetBounds(gfx::Size(800, 800)); |
| 3190 | child2->test_properties()->force_render_surface = true; |
| 3191 | grand_child1->SetPosition(gfx::PointF(8.f, 8.f)); |
| 3192 | grand_child1->SetBounds(gfx::Size(1500, 1500)); |
| 3193 | grand_child2->SetPosition(gfx::PointF(7.f, 7.f)); |
| 3194 | grand_child2->SetBounds(gfx::Size(1500, 1500)); |
| 3195 | leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); |
| 3196 | leaf_node1->SetBounds(gfx::Size(2000, 2000)); |
| 3197 | leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); |
| 3198 | leaf_node2->SetBounds(gfx::Size(2000, 2000)); |
| 3199 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3200 | root->SetDrawsContent(true); |
| 3201 | parent->SetDrawsContent(true); |
| 3202 | child1->SetDrawsContent(true); |
| 3203 | child2->SetDrawsContent(true); |
| 3204 | grand_child1->SetDrawsContent(true); |
| 3205 | grand_child2->SetDrawsContent(true); |
| 3206 | leaf_node1->SetDrawsContent(true); |
| 3207 | leaf_node2->SetDrawsContent(true); |
| 3208 | |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3209 | // Case 1: No layers clip. Visible rects are clipped by the viewport. |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3210 | // Each layer's drawable content rect is its bounds in target space; the only |
| 3211 | // thing that changes with surfaces disabled is that target space is always |
| 3212 | // screen space. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3213 | root->SetHasRenderSurface(true); |
| 3214 | child1->SetHasRenderSurface(true); |
| 3215 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3216 | ExecuteCalculateDrawProperties(root); |
| 3217 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3218 | EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3219 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3220 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3221 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3222 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3223 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3224 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3225 | |
| 3226 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3227 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3228 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3229 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3230 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3231 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3232 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3233 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3234 | |
| 3235 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3236 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3237 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3238 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3239 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3240 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3241 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3242 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3243 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3244 | |
| 3245 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3246 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3247 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3248 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3249 | EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), |
| 3250 | grand_child1->drawable_content_rect()); |
| 3251 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3252 | grand_child2->drawable_content_rect()); |
| 3253 | EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3254 | EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3255 | |
| 3256 | // Case 2: The parent clips. In this case, neither surface is unclipped, so |
| 3257 | // all visible layer rects are clipped by the intersection of all ancestor |
| 3258 | // clips, whether or not surfaces are disabled. However, drawable content |
| 3259 | // rects are clipped only until the next render surface is reached, so |
| 3260 | // descendants of parent have their drawable content rects clipped only when |
| 3261 | // surfaces are disabled. |
| 3262 | parent->SetMasksToBounds(true); |
| 3263 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3264 | ExecuteCalculateDrawProperties(root); |
| 3265 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3266 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3267 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3268 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3269 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3270 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3271 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3272 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3273 | |
| 3274 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3275 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3276 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3277 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3278 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3279 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3280 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3281 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3282 | |
| 3283 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3284 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3285 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3286 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3287 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3288 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3289 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3290 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3291 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3292 | |
| 3293 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3294 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3295 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect()); |
| 3296 | EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect()); |
| 3297 | EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect()); |
| 3298 | EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect()); |
| 3299 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect()); |
| 3300 | EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect()); |
| 3301 | |
| 3302 | parent->SetMasksToBounds(false); |
| 3303 | |
| 3304 | // Case 3: child1 and grand_child2 clip. In this case, descendants of these |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3305 | // layers have their visible rects clipped by them; Similarly, descendants of |
| 3306 | // these layers have their drawable content rects clipped by them. |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3307 | child1->SetMasksToBounds(true); |
| 3308 | grand_child2->SetMasksToBounds(true); |
| 3309 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3310 | ExecuteCalculateDrawProperties(root); |
| 3311 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3312 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3313 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3314 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3315 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3316 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3317 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3318 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3319 | |
| 3320 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3321 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3322 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3323 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3324 | EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect()); |
| 3325 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3326 | EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect()); |
| 3327 | EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3328 | |
| 3329 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3330 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3331 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3332 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3333 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3334 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3335 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3336 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3337 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3338 | |
| 3339 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3340 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3341 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3342 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3343 | EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect()); |
| 3344 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3345 | grand_child2->drawable_content_rect()); |
| 3346 | EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); |
| 3347 | EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3348 | } |
| 3349 | |
| 3350 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3351 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3352 | LayerImpl* root = root_layer_for_testing(); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3353 | LayerImpl* child1 = AddChild<LayerImpl>(root); |
| 3354 | LayerImpl* child2 = AddChild<LayerImpl>(root); |
| 3355 | LayerImpl* child3 = AddChild<LayerImpl>(root); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3356 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3357 | root->SetBounds(gfx::Size(100, 100)); |
| 3358 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3359 | child1->SetBounds(gfx::Size(50, 50)); |
| 3360 | child1->SetDrawsContent(true); |
| 3361 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3362 | child2->SetBounds(gfx::Size(50, 50)); |
| 3363 | child2->SetDrawsContent(true); |
| 3364 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3365 | child3->SetBounds(gfx::Size(50, 50)); |
| 3366 | child3->SetDrawsContent(true); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3367 | |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3368 | LayerImplList render_surface_layer_list_impl; |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3369 | // Now set the root render surface an empty clip. |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3370 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 3371 | root, gfx::Size(), &render_surface_layer_list_impl); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3372 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 3373 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3374 | ASSERT_TRUE(root->render_surface()); |
| 3375 | EXPECT_FALSE(root->is_clipped()); |
| 3376 | |
| 3377 | gfx::Rect empty; |
| 3378 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 3379 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 3380 | |
| 3381 | // Visible content rect calculation will check if the target surface is |
| 3382 | // clipped or not. An empty clip rect does not indicate the render surface |
| 3383 | // is unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3384 | EXPECT_EQ(empty, child1->visible_layer_rect()); |
| 3385 | EXPECT_EQ(empty, child2->visible_layer_rect()); |
| 3386 | EXPECT_EQ(empty, child3->visible_layer_rect()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3390 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3391 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3392 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3393 | |
| 3394 | root->SetBounds(gfx::Size(100, 100)); |
| 3395 | child->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3396 | child->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3397 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3398 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3399 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3400 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3401 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3402 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3403 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3404 | ExecuteCalculateDrawProperties(root); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3405 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3406 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3407 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3408 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3409 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 3410 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3411 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3412 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3413 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3414 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3415 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3416 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3417 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3418 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3419 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3420 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3421 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3422 | uninvertible_matrix.MakeIdentity(); |
| 3423 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3424 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3425 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3426 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3427 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3428 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3429 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3430 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3431 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3432 | } |
| 3433 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3434 | TEST_F(LayerTreeHostCommonTest, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3435 | VisibleContentRectForLayerWithUninvertibleDrawTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3436 | LayerImpl* root = root_layer_for_testing(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3437 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3438 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3439 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3440 | gfx::Transform perspective; |
| 3441 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3442 | |
| 3443 | gfx::Transform rotation; |
| 3444 | rotation.RotateAboutYAxis(45.0); |
| 3445 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3446 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3447 | child->test_properties()->transform = perspective; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3448 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 3449 | child->SetBounds(gfx::Size(100, 100)); |
| 3450 | child->SetDrawsContent(true); |
| 3451 | child->Set3dSortingContextId(1); |
| 3452 | child->test_properties()->should_flatten_transform = false; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3453 | grand_child->test_properties()->transform = rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3454 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 3455 | grand_child->SetDrawsContent(true); |
| 3456 | grand_child->Set3dSortingContextId(1); |
| 3457 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3458 | ExecuteCalculateDrawProperties(root); |
| 3459 | |
| 3460 | // Though all layers have invertible transforms, matrix multiplication using |
| 3461 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3462 | EXPECT_FALSE(root->layer_tree_impl() |
| 3463 | ->property_trees() |
| 3464 | ->transform_tree.Node(grand_child->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3465 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3466 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3467 | // CalcDrawProps skips a subtree when a layer's screen space transform is |
| 3468 | // uninvertible |
| 3469 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3470 | } |
| 3471 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3472 | TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) { |
| 3473 | FakeImplTaskRunnerProvider task_runner_provider; |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3474 | TestTaskGraphRunner task_graph_runner; |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3475 | std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 3476 | FakeCompositorFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 3477 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3478 | |
| 3479 | std::unique_ptr<LayerImpl> root = |
| 3480 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3481 | std::unique_ptr<LayerImpl> child = |
| 3482 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3483 | std::unique_ptr<TextureLayerImpl> surface = |
| 3484 | TextureLayerImpl::Create(host_impl.active_tree(), 3); |
| 3485 | std::unique_ptr<TextureLayerImpl> surface_child = |
| 3486 | TextureLayerImpl::Create(host_impl.active_tree(), 4); |
| 3487 | std::unique_ptr<TextureLayerImpl> surface_sibling = |
| 3488 | TextureLayerImpl::Create(host_impl.active_tree(), 5); |
| 3489 | std::unique_ptr<TextureLayerImpl> surface_child_mask = |
| 3490 | TextureLayerImpl::Create(host_impl.active_tree(), 6); |
| 3491 | |
| 3492 | surface->SetDrawsContent(true); |
| 3493 | surface_child->SetDrawsContent(true); |
| 3494 | surface_sibling->SetDrawsContent(true); |
| 3495 | surface_child_mask->SetDrawsContent(true); |
| 3496 | surface->SetContentsOpaque(true); |
| 3497 | surface_child->SetContentsOpaque(true); |
| 3498 | surface_sibling->SetContentsOpaque(true); |
| 3499 | surface_child_mask->SetContentsOpaque(true); |
| 3500 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3501 | gfx::Transform translate; |
| 3502 | translate.Translate(20.f, 20.f); |
| 3503 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3504 | root->SetBounds(gfx::Size(1000, 1000)); |
| 3505 | child->SetBounds(gfx::Size(300, 300)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3506 | surface->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3507 | surface->SetBounds(gfx::Size(300, 300)); |
| 3508 | surface->test_properties()->force_render_surface = true; |
| 3509 | surface_child->SetBounds(gfx::Size(300, 300)); |
| 3510 | surface_child->test_properties()->force_render_surface = true; |
| 3511 | surface_sibling->SetBounds(gfx::Size(200, 200)); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3512 | |
| 3513 | LayerImpl* surface_ptr = surface.get(); |
| 3514 | LayerImpl* surface_child_ptr = surface_child.get(); |
| 3515 | LayerImpl* surface_child_mask_ptr = surface_child_mask.get(); |
| 3516 | |
| 3517 | host_impl.SetViewportSize(root->bounds()); |
| 3518 | |
| 3519 | surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask)); |
| 3520 | surface->test_properties()->AddChild(std::move(surface_child)); |
| 3521 | child->test_properties()->AddChild(std::move(surface)); |
| 3522 | child->test_properties()->AddChild(std::move(surface_sibling)); |
| 3523 | root->test_properties()->AddChild(std::move(child)); |
| 3524 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 3525 | host_impl.SetVisible(true); |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3526 | host_impl.InitializeRenderer(compositor_frame_sink.get()); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3527 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 3528 | bool update_lcd_text = false; |
| 3529 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3530 | |
| 3531 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 3532 | surface_ptr->render_surface()->draw_transform(), translate); |
| 3533 | // surface_sibling draws into the root render surface and occludes |
| 3534 | // surface_child's contents. |
| 3535 | Occlusion actual_occlusion = |
| 3536 | surface_child_ptr->render_surface()->occlusion_in_content_space(); |
| 3537 | Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()), |
| 3538 | SimpleEnclosedRegion(gfx::Rect(200, 200))); |
| 3539 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3540 | |
| 3541 | // Mask layer should have the same occlusion. |
| 3542 | actual_occlusion = |
| 3543 | surface_child_mask_ptr->draw_properties().occlusion_in_content_space; |
| 3544 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3545 | } |
| 3546 | |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3547 | TEST_F(LayerTreeHostCommonTest, TextureLayerSnapping) { |
| 3548 | FakeImplTaskRunnerProvider task_runner_provider; |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3549 | TestTaskGraphRunner task_graph_runner; |
| 3550 | std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 3551 | FakeCompositorFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 3552 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3553 | |
| 3554 | std::unique_ptr<LayerImpl> root = |
| 3555 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3556 | std::unique_ptr<TextureLayerImpl> child = |
| 3557 | TextureLayerImpl::Create(host_impl.active_tree(), 2); |
| 3558 | |
| 3559 | LayerImpl* child_ptr = child.get(); |
| 3560 | |
| 3561 | root->SetBounds(gfx::Size(100, 100)); |
| 3562 | child->SetBounds(gfx::Size(100, 100)); |
| 3563 | child->SetDrawsContent(true); |
| 3564 | gfx::Transform fractional_translate; |
| 3565 | fractional_translate.Translate(10.5f, 20.3f); |
| 3566 | child->test_properties()->transform = fractional_translate; |
| 3567 | |
| 3568 | host_impl.SetViewportSize(root->bounds()); |
| 3569 | |
| 3570 | root->test_properties()->AddChild(std::move(child)); |
| 3571 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 3572 | host_impl.SetVisible(true); |
| 3573 | host_impl.InitializeRenderer(compositor_frame_sink.get()); |
| 3574 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 3575 | bool update_lcd_text = false; |
| 3576 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3577 | |
| 3578 | EXPECT_NE(child_ptr->ScreenSpaceTransform(), fractional_translate); |
| 3579 | fractional_translate.RoundTranslationComponents(); |
| 3580 | EXPECT_TRANSFORMATION_MATRIX_EQ(child_ptr->ScreenSpaceTransform(), |
| 3581 | fractional_translate); |
| 3582 | gfx::RectF layer_bounds_in_screen_space = |
| 3583 | MathUtil::MapClippedRect(child_ptr->ScreenSpaceTransform(), |
| 3584 | gfx::RectF(gfx::SizeF(child_ptr->bounds()))); |
| 3585 | EXPECT_EQ(layer_bounds_in_screen_space, gfx::RectF(11.f, 20.f, 100.f, 100.f)); |
| 3586 | } |
| 3587 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3588 | TEST_F(LayerTreeHostCommonTest, |
| 3589 | OcclusionForLayerWithUninvertibleDrawTransform) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3590 | FakeImplTaskRunnerProvider task_runner_provider; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3591 | TestTaskGraphRunner task_graph_runner; |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3592 | std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 3593 | FakeCompositorFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 3594 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3595 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3596 | std::unique_ptr<LayerImpl> root = |
| 3597 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3598 | std::unique_ptr<LayerImpl> child = |
| 3599 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3600 | std::unique_ptr<LayerImpl> grand_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3601 | LayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3602 | std::unique_ptr<LayerImpl> occluding_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3603 | LayerImpl::Create(host_impl.active_tree(), 4); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3604 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3605 | gfx::Transform perspective; |
| 3606 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3607 | |
| 3608 | gfx::Transform rotation; |
| 3609 | rotation.RotateAboutYAxis(45.0); |
| 3610 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3611 | root->SetBounds(gfx::Size(1000, 1000)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3612 | child->test_properties()->transform = perspective; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3613 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 3614 | child->SetBounds(gfx::Size(300, 300)); |
| 3615 | child->test_properties()->should_flatten_transform = false; |
| 3616 | child->Set3dSortingContextId(1); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3617 | grand_child->test_properties()->transform = rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3618 | grand_child->SetBounds(gfx::Size(200, 200)); |
| 3619 | grand_child->test_properties()->should_flatten_transform = false; |
| 3620 | grand_child->Set3dSortingContextId(1); |
| 3621 | occluding_child->SetBounds(gfx::Size(200, 200)); |
| 3622 | occluding_child->test_properties()->should_flatten_transform = false; |
| 3623 | |
| 3624 | child->SetDrawsContent(true); |
| 3625 | grand_child->SetDrawsContent(true); |
| 3626 | occluding_child->SetDrawsContent(true); |
| 3627 | occluding_child->SetContentsOpaque(true); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3628 | |
| 3629 | host_impl.SetViewportSize(root->bounds()); |
| 3630 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3631 | child->test_properties()->AddChild(std::move(grand_child)); |
| 3632 | root->test_properties()->AddChild(std::move(child)); |
| 3633 | root->test_properties()->AddChild(std::move(occluding_child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3634 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 3635 | host_impl.SetVisible(true); |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3636 | host_impl.InitializeRenderer(compositor_frame_sink.get()); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 3637 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3638 | bool update_lcd_text = false; |
| 3639 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3640 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3641 | LayerImpl* grand_child_ptr = host_impl.active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3642 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3643 | ->test_properties() |
| 3644 | ->children[0] |
| 3645 | ->test_properties() |
| 3646 | ->children[0]; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3647 | |
| 3648 | // Though all layers have invertible transforms, matrix multiplication using |
| 3649 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3650 | EXPECT_FALSE( |
| 3651 | host_impl.active_tree() |
| 3652 | ->property_trees() |
| 3653 | ->transform_tree.Node(grand_child_ptr->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3654 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3655 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3656 | // Since |grand_child| has an uninvertible screen space transform, it is |
| 3657 | // skipped so |
| 3658 | // that we are not computing its occlusion_in_content_space. |
| 3659 | gfx::Rect layer_bounds = gfx::Rect(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3660 | EXPECT_EQ( |
| 3661 | layer_bounds, |
| 3662 | grand_child_ptr->draw_properties() |
| 3663 | .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds)); |
| 3664 | } |
| 3665 | |
| 3666 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3667 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3668 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3669 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3670 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3671 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3672 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3673 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3674 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3675 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3676 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3677 | render_surface->test_properties()->force_render_surface = true; |
| 3678 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3679 | child1->SetBounds(gfx::Size(50, 50)); |
| 3680 | child1->SetDrawsContent(true); |
| 3681 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3682 | child2->SetBounds(gfx::Size(50, 50)); |
| 3683 | child2->SetDrawsContent(true); |
| 3684 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3685 | child3->SetBounds(gfx::Size(50, 50)); |
| 3686 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3687 | ExecuteCalculateDrawProperties(root); |
| 3688 | |
| 3689 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3690 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3691 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3692 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3693 | |
| 3694 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3695 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3696 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3697 | |
| 3698 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3699 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3700 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3701 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3702 | |
| 3703 | // All layers that draw content into the surface have their visible content |
| 3704 | // rect clipped by the surface clip rect. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3705 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3706 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3707 | EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3708 | |
| 3709 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3710 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3711 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3712 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3713 | } |
| 3714 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3715 | TEST_F(LayerTreeHostCommonTest, |
| 3716 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3717 | // Check that clipping does not propagate down surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3718 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3719 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3720 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 3721 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3722 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3723 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3724 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3725 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3726 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3727 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 3728 | render_surface1->test_properties()->force_render_surface = true; |
| 3729 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 3730 | render_surface2->test_properties()->force_render_surface = true; |
| 3731 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3732 | child1->SetBounds(gfx::Size(50, 50)); |
| 3733 | child1->SetDrawsContent(true); |
| 3734 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3735 | child2->SetBounds(gfx::Size(50, 50)); |
| 3736 | child2->SetDrawsContent(true); |
| 3737 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3738 | child3->SetBounds(gfx::Size(50, 50)); |
| 3739 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3740 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3741 | |
| 3742 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3743 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3744 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3745 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3746 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3747 | |
| 3748 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3749 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3750 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); |
| 3751 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3752 | |
| 3753 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3754 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3755 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3756 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3757 | |
| 3758 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3759 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3760 | // render_surface2 grows to enclose all drawable content of its subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3761 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3762 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3763 | |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3764 | // All layers that draw content into render_surface2 think they are unclipped |
| 3765 | // by the surface. So, only the viewport clip applies. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3766 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3767 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3768 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3769 | |
| 3770 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3771 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3772 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3773 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3774 | } |
| 3775 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3776 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3777 | VisibleRectsForClippedDescendantsOfUnclippedSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3778 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3779 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3780 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 3781 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 3782 | LayerImpl* render_surface2 = AddChild<LayerImpl>(child2); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3783 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3784 | root->SetBounds(gfx::Size(100, 100)); |
| 3785 | render_surface1->SetBounds(gfx::Size(100, 100)); |
| 3786 | render_surface1->test_properties()->force_render_surface = true; |
| 3787 | child1->SetBounds(gfx::Size(500, 500)); |
| 3788 | child1->SetDrawsContent(true); |
| 3789 | child2->SetBounds(gfx::Size(700, 700)); |
| 3790 | child2->SetDrawsContent(true); |
| 3791 | render_surface2->SetBounds(gfx::Size(1000, 1000)); |
| 3792 | render_surface2->test_properties()->force_render_surface = true; |
| 3793 | render_surface2->SetDrawsContent(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3794 | |
| 3795 | child1->SetMasksToBounds(true); |
| 3796 | child2->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3797 | ExecuteCalculateDrawProperties(root); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3798 | EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3799 | EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3800 | } |
| 3801 | |
| 3802 | TEST_F(LayerTreeHostCommonTest, |
| 3803 | VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3804 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3805 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3806 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3807 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3808 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3809 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3810 | root->SetBounds(gfx::Size(100, 100)); |
| 3811 | |
| 3812 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3813 | clip_parent->SetMasksToBounds(true); |
| 3814 | clip_parent->test_properties()->clip_children = |
| 3815 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3816 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3817 | |
| 3818 | render_surface1->SetBounds(gfx::Size(20, 20)); |
| 3819 | render_surface1->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3820 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3821 | render_surface1->test_properties()->force_render_surface = true; |
| 3822 | |
| 3823 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3824 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3825 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3826 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3827 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 3828 | render_surface2->SetDrawsContent(true); |
| 3829 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3830 | |
| 3831 | ExecuteCalculateDrawProperties(root); |
| 3832 | EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect()); |
| 3833 | EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect()); |
| 3834 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect()); |
| 3835 | } |
| 3836 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3837 | TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3838 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3839 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3840 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3841 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3842 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3843 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3844 | root->SetBounds(gfx::Size(100, 100)); |
| 3845 | |
| 3846 | clip_parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 3847 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3848 | clip_parent->test_properties()->clip_children = |
| 3849 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3850 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3851 | |
| 3852 | render_surface1->SetBounds(gfx::Size(20, 20)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3853 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3854 | render_surface1->test_properties()->force_render_surface = true; |
| 3855 | |
| 3856 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3857 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3858 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3859 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3860 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 3861 | render_surface2->SetDrawsContent(true); |
| 3862 | render_surface2->test_properties()->force_render_surface = true; |
| 3863 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3864 | clip_parent->SetMasksToBounds(true); |
| 3865 | render_surface1->SetMasksToBounds(true); |
| 3866 | |
| 3867 | ExecuteCalculateDrawProperties(root); |
| 3868 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect()); |
| 3869 | } |
| 3870 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3871 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) { |
| 3872 | // Test that only drawn layers contribute to render surface content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3873 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3874 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 3875 | LayerImpl* test_layer = AddChild<LayerImpl>(surface); |
| 3876 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3877 | root->SetBounds(gfx::Size(200, 200)); |
| 3878 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3879 | surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3880 | surface->test_properties()->force_render_surface = true; |
| 3881 | test_layer->SetBounds(gfx::Size(150, 150)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3882 | |
| 3883 | ExecuteCalculateDrawProperties(root); |
| 3884 | EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect()); |
| 3885 | |
| 3886 | test_layer->SetDrawsContent(true); |
| 3887 | ExecuteCalculateDrawProperties(root); |
| 3888 | EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect()); |
| 3889 | } |
| 3890 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3891 | TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) { |
| 3892 | // Tests visible rects computation when we have unclipped_surface-> |
| 3893 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3894 | // of surface_with_unclipped_descendants doesn't propagate to the |
| 3895 | // clipped_surface below it. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3896 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3897 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3898 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3899 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3900 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3901 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3902 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3903 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3904 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3905 | unclipped_surface->SetBounds(gfx::Size(30, 30)); |
| 3906 | unclipped_surface->SetDrawsContent(true); |
| 3907 | unclipped_surface->test_properties()->force_render_surface = true; |
| 3908 | |
| 3909 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3910 | clip_parent->test_properties()->clip_children = |
| 3911 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3912 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3913 | |
| 3914 | unclipped_desc_surface->SetBounds(gfx::Size(20, 20)); |
| 3915 | unclipped_desc_surface->SetDrawsContent(true); |
| 3916 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 3917 | |
| 3918 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 3919 | clip_child->test_properties()->clip_parent = clip_parent; |
| 3920 | |
| 3921 | clipped_surface->SetBounds(gfx::Size(60, 60)); |
| 3922 | clipped_surface->SetDrawsContent(true); |
| 3923 | clipped_surface->test_properties()->force_render_surface = true; |
| 3924 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3925 | clip_parent->SetMasksToBounds(true); |
| 3926 | |
| 3927 | ExecuteCalculateDrawProperties(root); |
| 3928 | EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect()); |
| 3929 | EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect()); |
| 3930 | EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect()); |
| 3931 | } |
| 3932 | |
| 3933 | TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) { |
| 3934 | // Tests visible rects computation when we have unclipped_surface-> |
| 3935 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3936 | // of root propagate to the clipped_surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3937 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3938 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3939 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3940 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3941 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3942 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3943 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3944 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3945 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3946 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
| 3947 | unclipped_surface->SetDrawsContent(true); |
| 3948 | unclipped_surface->test_properties()->force_render_surface = true; |
| 3949 | |
| 3950 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3951 | clip_parent->test_properties()->clip_children = |
| 3952 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3953 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3954 | |
| 3955 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 3956 | unclipped_desc_surface->SetDrawsContent(true); |
| 3957 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 3958 | |
| 3959 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 3960 | clip_child->test_properties()->clip_parent = clip_parent; |
| 3961 | |
| 3962 | clipped_surface->SetBounds(gfx::Size(50, 50)); |
| 3963 | clipped_surface->SetDrawsContent(true); |
| 3964 | clipped_surface->test_properties()->force_render_surface = true; |
| 3965 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3966 | clip_parent->SetMasksToBounds(true); |
| 3967 | unclipped_desc_surface->SetMasksToBounds(true); |
| 3968 | |
| 3969 | ExecuteCalculateDrawProperties(root); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3970 | EXPECT_EQ(gfx::Rect(10, 10), unclipped_surface->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3971 | EXPECT_EQ(gfx::Rect(10, 10), unclipped_desc_surface->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3972 | EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect()); |
| 3973 | } |
| 3974 | |
| 3975 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3976 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3977 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3978 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3979 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3980 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3981 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3982 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3983 | gfx::Transform child_rotation; |
| 3984 | child_rotation.Rotate(45.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3985 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3986 | root->SetBounds(gfx::Size(100, 100)); |
| 3987 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3988 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3989 | child1->test_properties()->transform = child_rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3990 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 3991 | child1->SetBounds(gfx::Size(50, 50)); |
| 3992 | child1->SetDrawsContent(true); |
| 3993 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3994 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3995 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3996 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3997 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3998 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3999 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4000 | |
| 4001 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4002 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4003 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4004 | |
| 4005 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 4006 | // regions of the subtree. |
| 4007 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 4008 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4009 | gfx::Rect(50 - diagonal_radius, |
| 4010 | 50 - diagonal_radius, |
| 4011 | diagonal_radius * 2, |
| 4012 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4013 | EXPECT_EQ(gfx::RectF(expected_surface_drawable_content), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4014 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4015 | |
| 4016 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4017 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4018 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4019 | } |
| 4020 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4021 | TEST_F(LayerTreeHostCommonTest, |
| 4022 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4023 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 4024 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4025 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4026 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 4027 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4028 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4029 | gfx::Transform child_rotation; |
| 4030 | child_rotation.Rotate(45.0); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4031 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4032 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4033 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4034 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 4035 | render_surface->test_properties()->force_render_surface = true; |
| 4036 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 4037 | child1->SetBounds(gfx::Size(50, 50)); |
| 4038 | child1->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4039 | child1->test_properties()->transform = child_rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4040 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4041 | ExecuteCalculateDrawProperties(root); |
| 4042 | |
| 4043 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4044 | |
| 4045 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 4046 | // rotated layer. |
| 4047 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4048 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 4049 | 50 - diagonal_radius, |
| 4050 | diagonal_radius * 2, |
| 4051 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4052 | gfx::RectF expected_surface_drawable_content( |
| 4053 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4054 | EXPECT_EQ(expected_surface_drawable_content, |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4055 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4056 | |
| 4057 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 4058 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 4059 | // up covering the full left half of child1. |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 4060 | EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4061 | |
| 4062 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4063 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4064 | } |
| 4065 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4066 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4067 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4068 | FakePictureLayerImpl* render_surface1 = |
| 4069 | AddChildToRoot<FakePictureLayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4070 | FakePictureLayerImpl* render_surface2 = |
| 4071 | AddChild<FakePictureLayerImpl>(render_surface1); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4072 | FakePictureLayerImpl* child1 = |
| 4073 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4074 | FakePictureLayerImpl* child2 = |
| 4075 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4076 | FakePictureLayerImpl* child3 = |
| 4077 | AddChild<FakePictureLayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4078 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4079 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4080 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4081 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 4082 | render_surface1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4083 | render_surface1->SetDrawsContent(true); |
| 4084 | render_surface1->test_properties()->force_render_surface = true; |
| 4085 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 4086 | render_surface2->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4087 | render_surface2->SetDrawsContent(true); |
| 4088 | render_surface2->test_properties()->force_render_surface = true; |
| 4089 | child1->SetBounds(gfx::Size(50, 50)); |
| 4090 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4091 | child1->SetDrawsContent(true); |
| 4092 | child2->SetBounds(gfx::Size(50, 50)); |
| 4093 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 4094 | child2->SetDrawsContent(true); |
| 4095 | child3->SetBounds(gfx::Size(50, 50)); |
| 4096 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 4097 | child3->SetDrawsContent(true); |
| 4098 | float device_scale_factor = 2.f; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4099 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4100 | |
| 4101 | ASSERT_TRUE(render_surface1->render_surface()); |
| 4102 | ASSERT_TRUE(render_surface2->render_surface()); |
| 4103 | |
| 4104 | // drawable_content_rects for all layers and surfaces are scaled by |
| 4105 | // device_scale_factor. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4106 | EXPECT_EQ(gfx::RectF(200.f, 200.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4107 | root->render_surface()->DrawableContentRect()); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4108 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4109 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4110 | |
| 4111 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 4112 | // is only implicitly clipped by render_surface1. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4113 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4114 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4115 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4116 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 4117 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 4118 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4119 | |
| 4120 | // The root layer does not actually draw content of its own. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4121 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4122 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4123 | // All layer visible content rects are not expressed in content space of each |
| 4124 | // layer, so they are not scaled by the device_scale_factor. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4125 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect()); |
| 4126 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect()); |
| 4127 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 4128 | EXPECT_EQ(gfx::Rect(0, 0, 15, 15), child2->visible_layer_rect()); |
| 4129 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4130 | } |
| 4131 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4132 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4133 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 4134 | // layers. Note that 3d transforms still apply in this case, but they are |
| 4135 | // "flattened" to each parent layer according to current W3C spec. |
| 4136 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4137 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4138 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4139 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4140 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4141 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4142 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4143 | AddChild<LayerImpl>(front_facing_surface); |
| 4144 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4145 | AddChild<LayerImpl>(front_facing_surface); |
| 4146 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4147 | AddChild<LayerImpl>(back_facing_surface); |
| 4148 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4149 | AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4150 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4151 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4152 | front_facing_child->test_properties()->double_sided = false; |
| 4153 | back_facing_child->test_properties()->double_sided = false; |
| 4154 | front_facing_surface->test_properties()->double_sided = false; |
| 4155 | back_facing_surface->test_properties()->double_sided = false; |
| 4156 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4157 | false; |
| 4158 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4159 | false; |
| 4160 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4161 | false; |
| 4162 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4163 | false; |
| 4164 | |
| 4165 | // Everything draws content. |
| 4166 | front_facing_child->SetDrawsContent(true); |
| 4167 | back_facing_child->SetDrawsContent(true); |
| 4168 | front_facing_surface->SetDrawsContent(true); |
| 4169 | back_facing_surface->SetDrawsContent(true); |
| 4170 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4171 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4172 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4173 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4174 | |
| 4175 | gfx::Transform backface_matrix; |
| 4176 | backface_matrix.Translate(50.0, 50.0); |
| 4177 | backface_matrix.RotateAboutYAxis(180.0); |
| 4178 | backface_matrix.Translate(-50.0, -50.0); |
| 4179 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4180 | root->SetBounds(gfx::Size(100, 100)); |
| 4181 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4182 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4183 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4184 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4185 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4186 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4187 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4188 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4189 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4190 | front_facing_surface->test_properties()->force_render_surface = true; |
| 4191 | back_facing_surface->test_properties()->force_render_surface = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4192 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4193 | back_facing_child->test_properties()->transform = backface_matrix; |
| 4194 | back_facing_surface->test_properties()->transform = backface_matrix; |
| 4195 | back_facing_child_of_front_facing_surface->test_properties()->transform = |
| 4196 | backface_matrix; |
| 4197 | back_facing_child_of_back_facing_surface->test_properties()->transform = |
| 4198 | backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4199 | |
| 4200 | // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms |
| 4201 | // spec, these layers should blindly use their own local transforms to |
| 4202 | // determine back-face culling. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4203 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4204 | |
| 4205 | // Verify which render surfaces were created. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4206 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4207 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4208 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
| 4209 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4210 | EXPECT_FALSE( |
| 4211 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4212 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4213 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4214 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4215 | |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame^] | 4216 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4217 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4218 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4219 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4220 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4221 | } |
| 4222 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4223 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4224 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 4225 | // is used. |
| 4226 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4227 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4228 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4229 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4230 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4231 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4232 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4233 | AddChild<LayerImpl>(front_facing_surface); |
| 4234 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4235 | AddChild<LayerImpl>(front_facing_surface); |
| 4236 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4237 | AddChild<LayerImpl>(back_facing_surface); |
| 4238 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4239 | AddChild<LayerImpl>(back_facing_surface); |
| 4240 | // Opacity will not force creation of render surfaces in this case because of |
| 4241 | // the preserve-3d transform style. Instead, an example of when a surface |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4242 | // would be created with preserve-3d is when there is a mask layer. |
| 4243 | LayerImpl* dummy_mask_layer1 = AddMaskLayer<LayerImpl>(front_facing_surface); |
| 4244 | LayerImpl* dummy_mask_layer2 = AddMaskLayer<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4245 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4246 | // Nothing is double-sided |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4247 | front_facing_child->test_properties()->double_sided = false; |
| 4248 | back_facing_child->test_properties()->double_sided = false; |
| 4249 | front_facing_surface->test_properties()->double_sided = false; |
| 4250 | back_facing_surface->test_properties()->double_sided = false; |
| 4251 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4252 | false; |
| 4253 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4254 | false; |
| 4255 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4256 | false; |
| 4257 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4258 | false; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4259 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4260 | // Everything draws content. |
| 4261 | front_facing_child->SetDrawsContent(true); |
| 4262 | back_facing_child->SetDrawsContent(true); |
| 4263 | front_facing_surface->SetDrawsContent(true); |
| 4264 | back_facing_surface->SetDrawsContent(true); |
| 4265 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4266 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4267 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4268 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4269 | dummy_mask_layer1->SetDrawsContent(true); |
| 4270 | dummy_mask_layer2->SetDrawsContent(true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4271 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4272 | gfx::Transform backface_matrix; |
| 4273 | backface_matrix.Translate(50.0, 50.0); |
| 4274 | backface_matrix.RotateAboutYAxis(180.0); |
| 4275 | backface_matrix.Translate(-50.0, -50.0); |
| 4276 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4277 | root->SetBounds(gfx::Size(100, 100)); |
| 4278 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4279 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4280 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4281 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4282 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4283 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4284 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4285 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4286 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4287 | back_facing_child->test_properties()->transform = backface_matrix; |
| 4288 | back_facing_surface->test_properties()->transform = backface_matrix; |
| 4289 | back_facing_child_of_front_facing_surface->test_properties()->transform = |
| 4290 | backface_matrix; |
| 4291 | back_facing_child_of_back_facing_surface->test_properties()->transform = |
| 4292 | backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4293 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4294 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 4295 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 4296 | // rendering context should use the transform with respect to that context. |
| 4297 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 4298 | // and (b) the layer's transform style is preserve-3d. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4299 | front_facing_surface->test_properties()->should_flatten_transform = false; |
| 4300 | front_facing_surface->Set3dSortingContextId(1); |
| 4301 | back_facing_surface->test_properties()->should_flatten_transform = false; |
| 4302 | back_facing_surface->Set3dSortingContextId(1); |
| 4303 | front_facing_child_of_front_facing_surface->Set3dSortingContextId(1); |
| 4304 | back_facing_child_of_front_facing_surface->Set3dSortingContextId(1); |
| 4305 | front_facing_child_of_back_facing_surface->Set3dSortingContextId(1); |
| 4306 | back_facing_child_of_back_facing_surface->Set3dSortingContextId(1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4307 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4308 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4309 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4310 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4311 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4312 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4313 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4314 | // We expect that a has_render_surface was created but not used. |
| 4315 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4316 | EXPECT_FALSE( |
| 4317 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4318 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4319 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4320 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4321 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4322 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4323 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4324 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4325 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4326 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4327 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4328 | } |
| 4329 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4330 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4331 | // Verify that layers are appropriately culled when their back face is showing |
| 4332 | // and they are not double sided, while animations are going on. |
| 4333 | // |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4334 | // Even layers that are animating get culled if their back face is showing and |
| 4335 | // they are not double sided. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4336 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4337 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4338 | LayerImpl* animating_surface = AddChildToRoot<LayerImpl>(); |
| 4339 | LayerImpl* child_of_animating_surface = |
| 4340 | AddChild<LayerImpl>(animating_surface); |
| 4341 | LayerImpl* animating_child = AddChildToRoot<LayerImpl>(); |
| 4342 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4343 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4344 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4345 | child->test_properties()->double_sided = false; |
| 4346 | child2->test_properties()->double_sided = false; |
| 4347 | animating_surface->test_properties()->double_sided = false; |
| 4348 | child_of_animating_surface->test_properties()->double_sided = false; |
| 4349 | animating_child->test_properties()->double_sided = false; |
| 4350 | |
| 4351 | // Everything draws content. |
| 4352 | child->SetDrawsContent(true); |
| 4353 | child2->SetDrawsContent(true); |
| 4354 | animating_surface->SetDrawsContent(true); |
| 4355 | child_of_animating_surface->SetDrawsContent(true); |
| 4356 | animating_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4357 | |
| 4358 | gfx::Transform backface_matrix; |
| 4359 | backface_matrix.Translate(50.0, 50.0); |
| 4360 | backface_matrix.RotateAboutYAxis(180.0); |
| 4361 | backface_matrix.Translate(-50.0, -50.0); |
| 4362 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4363 | SetElementIdsForTesting(); |
| 4364 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4365 | // Animate the transform on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4366 | AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(), |
| 4367 | timeline_impl(), 10.0, 30, 0); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4368 | // This is just an animating layer, not a surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4369 | AddAnimatedTransformToElementWithPlayer(animating_child->element_id(), |
| 4370 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4371 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4372 | root->SetBounds(gfx::Size(100, 100)); |
| 4373 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4374 | child->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4375 | animating_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4376 | animating_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4377 | animating_surface->test_properties()->force_render_surface = true; |
| 4378 | child_of_animating_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4379 | child_of_animating_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4380 | animating_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4381 | animating_child->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4382 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4383 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4384 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4385 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4386 | EXPECT_FALSE(child->has_render_surface()); |
| 4387 | EXPECT_TRUE(animating_surface->has_render_surface()); |
| 4388 | EXPECT_FALSE(child_of_animating_surface->has_render_surface()); |
| 4389 | EXPECT_FALSE(animating_child->has_render_surface()); |
| 4390 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4391 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4392 | EXPECT_EQ(1u, update_layer_list_impl()->size()); |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4393 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4394 | // The back facing layers are culled from the layer list, and have an empty |
| 4395 | // visible rect. |
| 4396 | EXPECT_TRUE(UpdateLayerListImplContains(child2->id())); |
| 4397 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
| 4398 | EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty()); |
| 4399 | EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty()); |
| 4400 | EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4401 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4402 | EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4403 | } |
| 4404 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4405 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4406 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4407 | // Verify the behavior of back-face culling for a render surface that is |
| 4408 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4409 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4410 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4411 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4412 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4413 | LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface); |
| 4414 | LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4415 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4416 | // RenderSurfaces are not double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4417 | front_facing_surface->test_properties()->double_sided = false; |
| 4418 | back_facing_surface->test_properties()->double_sided = false; |
| 4419 | |
| 4420 | // Everything draws content. |
| 4421 | front_facing_surface->SetDrawsContent(true); |
| 4422 | back_facing_surface->SetDrawsContent(true); |
| 4423 | child1->SetDrawsContent(true); |
| 4424 | child2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4425 | |
| 4426 | gfx::Transform backface_matrix; |
| 4427 | backface_matrix.Translate(50.0, 50.0); |
| 4428 | backface_matrix.RotateAboutYAxis(180.0); |
| 4429 | backface_matrix.Translate(-50.0, -50.0); |
| 4430 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4431 | root->SetBounds(gfx::Size(100, 100)); |
| 4432 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4433 | front_facing_surface->test_properties()->force_render_surface = true; |
| 4434 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4435 | back_facing_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4436 | back_facing_surface->test_properties()->force_render_surface = true; |
| 4437 | child1->SetBounds(gfx::Size(100, 100)); |
| 4438 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4439 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4440 | front_facing_surface->Set3dSortingContextId(1); |
| 4441 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4442 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4443 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4444 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4445 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4446 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4447 | |
| 4448 | // We expect the render surface to have been created, but remain unused. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4449 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4450 | EXPECT_FALSE(child1->has_render_surface()); |
| 4451 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4452 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4453 | EXPECT_EQ(2u, update_layer_list_impl()->size()); |
| 4454 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4455 | EXPECT_TRUE(UpdateLayerListImplContains(child1->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4456 | } |
| 4457 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4458 | TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4459 | // Verify draw and screen space transforms of layers not in a surface. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4460 | LayerImpl* root = root_layer_for_testing(); |
| 4461 | root->SetBounds(gfx::Size(100, 100)); |
| 4462 | root->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4463 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4464 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4465 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4466 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4467 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4468 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4469 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4470 | child2->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4471 | child2->SetBounds(gfx::Size(5, 5)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4472 | child2->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4473 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4474 | float device_scale_factor = 2.5f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4475 | gfx::Size viewport_size(100, 100); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4476 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4477 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4478 | EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale()); |
| 4479 | EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale()); |
| 4480 | EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale()); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4481 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4482 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4483 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4484 | // Verify root transforms |
| 4485 | gfx::Transform expected_root_transform; |
| 4486 | expected_root_transform.Scale(device_scale_factor, device_scale_factor); |
| 4487 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4488 | root->ScreenSpaceTransform()); |
| 4489 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4490 | root->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4491 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4492 | // Verify results of transformed root rects |
| 4493 | gfx::RectF root_bounds(gfx::SizeF(root->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4494 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4495 | gfx::RectF root_draw_rect = |
| 4496 | MathUtil::MapClippedRect(root->DrawTransform(), root_bounds); |
| 4497 | gfx::RectF root_screen_space_rect = |
| 4498 | MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4499 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4500 | gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds())); |
| 4501 | expected_root_draw_rect.Scale(device_scale_factor); |
| 4502 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect); |
| 4503 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4504 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4505 | // Verify child and child2 transforms. They should match. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4506 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4507 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4508 | expected_child_transform.Translate(child->position().x(), |
| 4509 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4510 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4511 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4512 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4513 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4514 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4515 | child2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4516 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4517 | child2->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4518 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4519 | // Verify results of transformed child and child2 rects. They should |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4520 | // match. |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4521 | gfx::RectF child_bounds(gfx::SizeF(child->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4522 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4523 | gfx::RectF child_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4524 | MathUtil::MapClippedRect(child->DrawTransform(), child_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4525 | gfx::RectF child_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4526 | MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4527 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4528 | gfx::RectF child2_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4529 | MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4530 | gfx::RectF child2_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4531 | MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4532 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4533 | gfx::RectF expected_child_draw_rect(child->position(), |
| 4534 | gfx::SizeF(child->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4535 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4536 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4537 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4538 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect); |
| 4539 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4540 | } |
| 4541 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4542 | TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4543 | // Verify draw and screen space transforms of layers in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4544 | gfx::Transform perspective_matrix; |
| 4545 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4546 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4547 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4548 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4549 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4550 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4551 | root->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4552 | |
| 4553 | LayerImpl* page_scale = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4554 | page_scale->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4555 | |
| 4556 | LayerImpl* parent = AddChild<LayerImpl>(page_scale); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4557 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4558 | parent->SetDrawsContent(true); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4559 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4560 | LayerImpl* perspective_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4561 | perspective_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4562 | perspective_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4563 | perspective_surface->test_properties()->transform = |
| 4564 | perspective_matrix * scale_small_matrix; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4565 | perspective_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4566 | perspective_surface->test_properties()->force_render_surface = true; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4567 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4568 | LayerImpl* scale_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4569 | scale_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4570 | scale_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4571 | scale_surface->test_properties()->transform = scale_small_matrix; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4572 | scale_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4573 | scale_surface->test_properties()->force_render_surface = true; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4574 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4575 | float device_scale_factor = 2.5f; |
| 4576 | float page_scale_factor = 3.f; |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4577 | root->layer_tree_impl()->SetViewportLayersFromIds( |
| 4578 | Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, |
| 4579 | Layer::INVALID_ID); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4580 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4581 | root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4582 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4583 | root, nullptr, nullptr); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4584 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4585 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4586 | parent->GetIdealContentsScale()); |
| 4587 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4588 | perspective_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4589 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4590 | // the nearest render target. Here this includes the layer transform as well |
| 4591 | // as the device and page scale factors. |
| 4592 | gfx::Transform transform = scale_small_matrix; |
| 4593 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4594 | device_scale_factor * page_scale_factor); |
| 4595 | gfx::Vector2dF scales = |
| 4596 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4597 | float max_2d_scale = std::max(scales.x(), scales.y()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4598 | EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4599 | |
| 4600 | // The ideal scale will draw 1:1 with its render target space along |
| 4601 | // the larger-scale axis. |
| 4602 | gfx::Vector2dF target_space_transform_scales = |
| 4603 | MathUtil::ComputeTransform2dScaleComponents( |
| 4604 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4605 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4606 | std::max(target_space_transform_scales.x(), |
| 4607 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4608 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4609 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4610 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4611 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4612 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4613 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4614 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4615 | parent->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4616 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4617 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4618 | // with the screen, and then scaled during drawing. |
| 4619 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4620 | expected_perspective_surface_draw_transform.Translate( |
| 4621 | device_scale_factor * page_scale_factor * |
| 4622 | perspective_surface->position().x(), |
| 4623 | device_scale_factor * page_scale_factor * |
| 4624 | perspective_surface->position().y()); |
| 4625 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4626 | perspective_matrix); |
| 4627 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4628 | scale_small_matrix); |
| 4629 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4630 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4631 | device_scale_factor * page_scale_factor, |
| 4632 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4633 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4634 | expected_perspective_surface_draw_transform, |
| 4635 | perspective_surface->render_surface()->draw_transform()); |
| 4636 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4637 | expected_perspective_surface_layer_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4638 | perspective_surface->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4639 | } |
| 4640 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4641 | TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4642 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4643 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4644 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4645 | |
| 4646 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4647 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4648 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4649 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4650 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4651 | root->SetBounds(gfx::Size(100, 100)); |
| 4652 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4653 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4654 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4655 | parent->test_properties()->transform = parent_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4656 | parent->SetDrawsContent(true); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4657 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4658 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4659 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4660 | child_scale->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4661 | child_scale->test_properties()->transform = child_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4662 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4663 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4664 | float device_scale_factor = 2.5f; |
| 4665 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4666 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4667 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4668 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4669 | root, nullptr, nullptr); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4670 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4671 | // The ideal scale is able to go below 1. |
| 4672 | float expected_ideal_scale = |
| 4673 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4674 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4675 | EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale()); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4676 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4677 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4678 | initial_parent_scale * initial_child_scale; |
| 4679 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4680 | EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4681 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4682 | } |
| 4683 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4684 | TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4685 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4686 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4687 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4688 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4689 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4690 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4691 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4692 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4693 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4694 | root->SetBounds(gfx::Size(100, 100)); |
| 4695 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4696 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4697 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4698 | parent->test_properties()->transform = parent_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4699 | parent->SetDrawsContent(true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4700 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4701 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4702 | child_scale->SetBounds(gfx::Size(10, 10)); |
| 4703 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4704 | child_scale->test_properties()->transform = child_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4705 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4706 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4707 | ExecuteCalculateDrawProperties(root); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4708 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4709 | EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4710 | // Animating layers compute ideal scale in the same way as when |
| 4711 | // they are static. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4712 | EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale, |
| 4713 | child_scale->GetIdealContentsScale()); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4714 | } |
| 4715 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4716 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4717 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4718 | parent->SetBounds(gfx::Size(30, 30)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4719 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4720 | parent->Set3dSortingContextId(1); |
| 4721 | parent->test_properties()->should_flatten_transform = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4722 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4723 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4724 | child->SetBounds(gfx::Size(10, 10)); |
| 4725 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4726 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4727 | child->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4728 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4729 | // This layer should end up in the same surface as child, with the same draw |
| 4730 | // and screen space transforms. |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4731 | LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4732 | duplicate_child_non_owner->SetBounds(gfx::Size(10, 10)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4733 | duplicate_child_non_owner->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4734 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4735 | float device_scale_factor = 1.5f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4736 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4737 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4738 | // We should have two render surfaces. The root's render surface and child's |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4739 | // render surface (it needs one because of force_render_surface). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4740 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4741 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4742 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4743 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4744 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4745 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4746 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4747 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4748 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4749 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4750 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4751 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4752 | child->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4753 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4754 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4755 | expected_screen_space_transform.Scale(device_scale_factor, |
| 4756 | device_scale_factor); |
| 4757 | expected_screen_space_transform.Translate(child->position().x(), |
| 4758 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4759 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4760 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4761 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4762 | gfx::Transform expected_duplicate_child_draw_transform = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4763 | child->DrawTransform(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4764 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4765 | duplicate_child_non_owner->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4766 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4767 | child->ScreenSpaceTransform(), |
| 4768 | duplicate_child_non_owner->ScreenSpaceTransform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4769 | EXPECT_EQ(child->drawable_content_rect(), |
| 4770 | duplicate_child_non_owner->drawable_content_rect()); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4771 | EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4772 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4773 | gfx::Transform expected_render_surface_draw_transform; |
| 4774 | expected_render_surface_draw_transform.Translate( |
| 4775 | device_scale_factor * child->position().x(), |
| 4776 | device_scale_factor * child->position().y()); |
| 4777 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 4778 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4779 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4780 | gfx::Transform expected_surface_draw_transform; |
| 4781 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 4782 | device_scale_factor * 2.f); |
| 4783 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 4784 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4785 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4786 | gfx::Transform expected_surface_screen_space_transform; |
| 4787 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 4788 | device_scale_factor * 2.f); |
| 4789 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4790 | expected_surface_screen_space_transform, |
| 4791 | child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4792 | } |
| 4793 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4794 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4795 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4796 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4797 | parent->SetBounds(gfx::Size(33, 31)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4798 | parent->SetDrawsContent(true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4799 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4800 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4801 | child->SetBounds(gfx::Size(13, 11)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4802 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4803 | child->test_properties()->force_render_surface = true; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4804 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 4805 | float device_scale_factor = 1.7f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4806 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4807 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4808 | // We should have two render surfaces. The root's render surface and child's |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4809 | // render surface (it needs one because of force_render_surface). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4810 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4811 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4812 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4813 | child->render_surface()->draw_transform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4814 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4815 | child->render_surface()->draw_transform()); |
| 4816 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4817 | gfx::Transform(), child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4818 | } |
| 4819 | |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 4820 | TEST_F(LayerTreeHostCommonTest, LayerSearch) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4821 | scoped_refptr<Layer> root = Layer::Create(); |
| 4822 | scoped_refptr<Layer> child = Layer::Create(); |
| 4823 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 4824 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4825 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4826 | child->AddChild(grand_child.get()); |
| 4827 | child->SetMaskLayer(mask_layer.get()); |
| 4828 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4829 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4830 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4831 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4832 | int nonexistent_id = -1; |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 4833 | LayerTree* layer_tree = host()->GetLayerTree(); |
| 4834 | EXPECT_EQ(root.get(), layer_tree->LayerById(root->id())); |
| 4835 | EXPECT_EQ(child.get(), layer_tree->LayerById(child->id())); |
| 4836 | EXPECT_EQ(grand_child.get(), layer_tree->LayerById(grand_child->id())); |
| 4837 | EXPECT_EQ(mask_layer.get(), layer_tree->LayerById(mask_layer->id())); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 4838 | EXPECT_FALSE(layer_tree->LayerById(nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4839 | } |
| 4840 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4841 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4842 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4843 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 4844 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4845 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4846 | root->SetBounds(gfx::Size(100, 100)); |
| 4847 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4848 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4849 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 4850 | grand_child->SetDrawsContent(true); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4851 | ExecuteCalculateDrawProperties(root); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4852 | EXPECT_FALSE(child->has_render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4853 | } |
| 4854 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4855 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4856 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 4857 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 4858 | FakeLayerTreeHostImpl host_impl(host()->GetSettings(), &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 4859 | &task_graph_runner); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4860 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4861 | std::unique_ptr<LayerImpl> root = |
| 4862 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4863 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4864 | root->SetDrawsContent(true); |
| 4865 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4866 | std::unique_ptr<LayerImpl> child = |
| 4867 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4868 | child->SetBounds(gfx::Size(50, 50)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4869 | child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4870 | child->test_properties()->opacity = 0.0f; |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4871 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 4872 | const int child_id = child->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4873 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 4874 | root->SetHasRenderSurface(true); |
| 4875 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4876 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4877 | host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4878 | |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4879 | // Add opacity animation. |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4880 | scoped_refptr<AnimationTimeline> timeline = |
| 4881 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 4882 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4883 | host_impl.pending_tree()->SetElementIdsForTesting(); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4884 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4885 | ElementId child_element_id = |
| 4886 | host_impl.pending_tree()->LayerById(child_id)->element_id(); |
| 4887 | |
| 4888 | AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0, |
| 4889 | 0.0f, 1.0f, false); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4890 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4891 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4892 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4893 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4894 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4895 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4896 | |
| 4897 | // We should have one render surface and two layers. The child |
| 4898 | // layer should be included even though it is transparent. |
| 4899 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4900 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4901 | |
| 4902 | // If the root itself is hidden, the child should not be drawn even if it has |
| 4903 | // an animating opacity. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4904 | root_layer->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4905 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4906 | LayerImplList render_surface_layer_list2; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4907 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4908 | root_layer, root_layer->bounds(), &render_surface_layer_list2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4909 | inputs2.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4910 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4911 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4912 | LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4913 | EffectTree& tree = |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4914 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4915 | EffectNode* node = tree.Node(child_ptr->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4916 | EXPECT_FALSE(node->is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4917 | |
| 4918 | // A layer should be drawn and it should contribute to drawn surface when |
| 4919 | // it has animating opacity even if it has opacity 0. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4920 | root_layer->test_properties()->opacity = 1.0f; |
| 4921 | child_ptr->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4922 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4923 | LayerImplList render_surface_layer_list3; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4924 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4925 | root_layer, root_layer->bounds(), &render_surface_layer_list3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4926 | inputs3.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4927 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4928 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4929 | child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
| 4930 | tree = root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4931 | node = tree.Node(child_ptr->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4932 | EXPECT_TRUE(node->is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4933 | EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index())); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4934 | |
| 4935 | // But if the opacity of the layer remains 0 after activation, it should not |
| 4936 | // be drawn. |
| 4937 | host_impl.ActivateSyncTree(); |
danakj | 0da42ca6 | 2016-07-01 19:42:33 | [diff] [blame] | 4938 | LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id()); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4939 | LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id()); |
| 4940 | |
| 4941 | EffectTree& active_effect_tree = |
| 4942 | host_impl.active_tree()->property_trees()->effect_tree; |
| 4943 | EXPECT_TRUE(active_effect_tree.needs_update()); |
| 4944 | |
| 4945 | ExecuteCalculateDrawProperties(active_root); |
| 4946 | |
| 4947 | node = active_effect_tree.Node(active_child->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4948 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4949 | EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface( |
| 4950 | active_child->effect_tree_index())); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4951 | } |
| 4952 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4953 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4954 | class LCDTextTest : public LayerTreeHostCommonTestBase, |
| 4955 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4956 | public: |
| 4957 | LCDTextTest() |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4958 | : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()), |
| 4959 | host_impl_(LCDTextTestLayerTreeSettings(), |
| 4960 | &task_runner_provider_, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4961 | &task_graph_runner_) {} |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4962 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4963 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 4964 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4965 | protected: |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4966 | LayerTreeSettings LCDTextTestLayerTreeSettings() { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4967 | LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings(); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4968 | |
| 4969 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
| 4970 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
| 4971 | settings.can_use_lcd_text = can_use_lcd_text_; |
| 4972 | settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_; |
| 4973 | return settings; |
| 4974 | } |
| 4975 | |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 4976 | void SetUp() override { |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4977 | timeline_ = |
| 4978 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 4979 | host_impl_.animation_host()->AddAnimationTimeline(timeline_); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4980 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4981 | std::unique_ptr<LayerImpl> root_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4982 | LayerImpl::Create(host_impl_.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4983 | std::unique_ptr<LayerImpl> child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4984 | LayerImpl::Create(host_impl_.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4985 | std::unique_ptr<LayerImpl> grand_child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4986 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 4987 | |
| 4988 | // Stash raw pointers to look at later. |
| 4989 | root_ = root_ptr.get(); |
| 4990 | child_ = child_ptr.get(); |
| 4991 | grand_child_ = grand_child_ptr.get(); |
| 4992 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4993 | child_->test_properties()->AddChild(std::move(grand_child_ptr)); |
| 4994 | root_->test_properties()->AddChild(std::move(child_ptr)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4995 | host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4996 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4997 | host_impl_.active_tree()->SetElementIdsForTesting(); |
| 4998 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 4999 | root_->SetContentsOpaque(true); |
| 5000 | child_->SetContentsOpaque(true); |
| 5001 | grand_child_->SetContentsOpaque(true); |
| 5002 | |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5003 | root_->SetDrawsContent(true); |
| 5004 | child_->SetDrawsContent(true); |
| 5005 | grand_child_->SetDrawsContent(true); |
| 5006 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5007 | root_->SetBounds(gfx::Size(1, 1)); |
| 5008 | child_->SetBounds(gfx::Size(1, 1)); |
| 5009 | grand_child_->SetBounds(gfx::Size(1, 1)); |
| 5010 | |
| 5011 | child_->test_properties()->force_render_surface = |
| 5012 | std::tr1::get<2>(GetParam()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5013 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5014 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5015 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5016 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5017 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5018 | FakeImplTaskRunnerProvider task_runner_provider_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5019 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5020 | FakeLayerTreeHostImpl host_impl_; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5021 | scoped_refptr<AnimationTimeline> timeline_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5022 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5023 | LayerImpl* root_ = nullptr; |
| 5024 | LayerImpl* child_ = nullptr; |
| 5025 | LayerImpl* grand_child_ = nullptr; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5026 | }; |
| 5027 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5028 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5029 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5030 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5031 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5032 | // Case 1: Identity transform. |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5033 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5034 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5035 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5036 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5037 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5038 | // Case 2: Integral translation. |
| 5039 | gfx::Transform integral_translation; |
| 5040 | integral_translation.Translate(1.0, 2.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5041 | child_->test_properties()->transform = integral_translation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5042 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5043 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5044 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5045 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5046 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5047 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5048 | // Case 3: Non-integral translation. |
| 5049 | gfx::Transform non_integral_translation; |
| 5050 | non_integral_translation.Translate(1.5, 2.5); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5051 | child_->test_properties()->transform = non_integral_translation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5052 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5053 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5054 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5055 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5056 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5057 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5058 | // Case 4: Rotation. |
| 5059 | gfx::Transform rotation; |
| 5060 | rotation.Rotate(10.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5061 | child_->test_properties()->transform = rotation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5062 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5063 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5064 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5065 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5066 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5067 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5068 | // Case 5: Scale. |
| 5069 | gfx::Transform scale; |
| 5070 | scale.Scale(2.0, 2.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5071 | child_->test_properties()->transform = scale; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5072 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5073 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5074 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5075 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5076 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5077 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5078 | // Case 6: Skew. |
| 5079 | gfx::Transform skew; |
nainar | 8ca8ee6 | 2015-09-03 01:04:10 | [diff] [blame] | 5080 | skew.Skew(10.0, 0.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5081 | child_->test_properties()->transform = skew; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5082 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5083 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5084 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5085 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5086 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5087 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5088 | // Case 7: Translucent. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5089 | child_->test_properties()->transform = gfx::Transform(); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5090 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5091 | child_->test_properties()->opacity = 0.5f; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5092 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5093 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5094 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5095 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5096 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5097 | // Case 8: Sanity check: restore transform and opacity. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5098 | child_->test_properties()->transform = gfx::Transform(); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5099 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5100 | child_->test_properties()->opacity = 1.f; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5101 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5102 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5103 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5104 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5105 | |
| 5106 | // Case 9: Non-opaque content. |
| 5107 | child_->SetContentsOpaque(false); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5108 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5109 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5110 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5111 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5112 | |
| 5113 | // Case 10: Sanity check: restore content opaqueness. |
| 5114 | child_->SetContentsOpaque(true); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5115 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5116 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5117 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5118 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5119 | } |
| 5120 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5121 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5122 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5123 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5124 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5125 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5126 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5127 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5128 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5129 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5130 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5131 | // Add opacity animation. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5132 | child_->test_properties()->opacity = 0.9f; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5133 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5134 | |
| 5135 | SetElementIdsForTesting(); |
| 5136 | |
| 5137 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5138 | 10.0, 0.9f, 0.1f, false); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5139 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5140 | // Text LCD should be adjusted while animation is active. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5141 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5142 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5143 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 5147 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5148 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5149 | |
| 5150 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5151 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5152 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5153 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5154 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5155 | SetElementIdsForTesting(); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5156 | |
| 5157 | // Mark contents non-opaque within the first animation frame. |
| 5158 | child_->SetContentsOpaque(false); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5159 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5160 | 10.0, 0.9f, 0.1f, false); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5161 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5162 | // LCD text should be disabled for non-opaque layers even during animations. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5163 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5164 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5165 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5169 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5170 | testing::Combine(testing::Bool(), |
| 5171 | testing::Bool(), |
| 5172 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5173 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5174 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5175 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5176 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 5177 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5178 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5179 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5180 | std::unique_ptr<LayerImpl> root = |
| 5181 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5182 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5183 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5184 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5185 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5186 | std::unique_ptr<LayerImpl> child = |
| 5187 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5188 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5189 | child->SetDrawsContent(true); |
| 5190 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5191 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5192 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5193 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5194 | grand_child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5195 | grand_child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5196 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5197 | child->test_properties()->AddChild(std::move(grand_child)); |
| 5198 | root->test_properties()->AddChild(std::move(child)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5199 | root->SetHasRenderSurface(true); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5200 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5201 | |
| 5202 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5203 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5204 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5205 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5206 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5207 | |
| 5208 | // We should have one render surface and two layers. The grand child has |
| 5209 | // hidden itself. |
| 5210 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5211 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5212 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
| 5213 | EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5214 | } |
| 5215 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5216 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5217 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5218 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 5219 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5220 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5221 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5222 | std::unique_ptr<LayerImpl> root = |
| 5223 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5224 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5225 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5226 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5227 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5228 | std::unique_ptr<LayerImpl> child = |
| 5229 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5230 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5231 | child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5232 | child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5233 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5234 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5235 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5236 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5237 | grand_child->SetDrawsContent(true); |
| 5238 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5239 | child->test_properties()->AddChild(std::move(grand_child)); |
| 5240 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5241 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5242 | |
| 5243 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5244 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5245 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5246 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5247 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5248 | |
| 5249 | // We should have one render surface and one layers. The child has |
| 5250 | // hidden itself and the grand child. |
| 5251 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5252 | ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size()); |
| 5253 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5254 | } |
| 5255 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5256 | void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5257 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5258 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5259 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5260 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 5261 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5262 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5263 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5264 | std::unique_ptr<LayerImpl> root = |
| 5265 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5266 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5267 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5268 | LayerImpl* root_layer = root.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5269 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5270 | std::unique_ptr<LayerImpl> copy_grand_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5271 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5272 | copy_grand_parent->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5273 | copy_grand_parent->SetDrawsContent(true); |
| 5274 | LayerImpl* copy_grand_parent_layer = copy_grand_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5275 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5276 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5277 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5278 | copy_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5279 | copy_parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5280 | copy_parent->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5281 | LayerImpl* copy_parent_layer = copy_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5282 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5283 | std::unique_ptr<LayerImpl> copy_request = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5284 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5285 | copy_request->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5286 | copy_request->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5287 | copy_request->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5288 | LayerImpl* copy_layer = copy_request.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5289 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5290 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5291 | LayerImpl::Create(host_impl.pending_tree(), 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5292 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5293 | copy_child->SetDrawsContent(true); |
| 5294 | LayerImpl* copy_child_layer = copy_child.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5295 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5296 | std::unique_ptr<LayerImpl> copy_grand_child = |
thakis | e53c527 | 2016-01-24 01:20:40 | [diff] [blame] | 5297 | LayerImpl::Create(host_impl.pending_tree(), 6); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5298 | copy_grand_child->SetBounds(gfx::Size(20, 20)); |
| 5299 | copy_grand_child->SetDrawsContent(true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5300 | LayerImpl* copy_grand_child_layer = copy_grand_child.get(); |
| 5301 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5302 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5303 | LayerImpl::Create(host_impl.pending_tree(), 7); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5304 | copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5305 | copy_grand_parent_sibling_before->SetDrawsContent(true); |
| 5306 | LayerImpl* copy_grand_parent_sibling_before_layer = |
| 5307 | copy_grand_parent_sibling_before.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5308 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5309 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5310 | LayerImpl::Create(host_impl.pending_tree(), 8); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5311 | copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5312 | copy_grand_parent_sibling_after->SetDrawsContent(true); |
| 5313 | LayerImpl* copy_grand_parent_sibling_after_layer = |
| 5314 | copy_grand_parent_sibling_after.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5315 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5316 | copy_child->test_properties()->AddChild(std::move(copy_grand_child)); |
| 5317 | copy_request->test_properties()->AddChild(std::move(copy_child)); |
| 5318 | copy_parent->test_properties()->AddChild(std::move(copy_request)); |
| 5319 | copy_grand_parent->test_properties()->AddChild(std::move(copy_parent)); |
| 5320 | root->test_properties()->AddChild( |
| 5321 | std::move(copy_grand_parent_sibling_before)); |
| 5322 | root->test_properties()->AddChild(std::move(copy_grand_parent)); |
| 5323 | root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5324 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5325 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5326 | // Hide the copy_grand_parent and its subtree. But make a copy request in that |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5327 | // hidden subtree on copy_layer. Also hide the copy grand child and its |
| 5328 | // subtree. |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5329 | copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true; |
| 5330 | copy_grand_parent_sibling_before_layer->test_properties() |
| 5331 | ->hide_layer_and_subtree = true; |
| 5332 | copy_grand_parent_sibling_after_layer->test_properties() |
| 5333 | ->hide_layer_and_subtree = true; |
| 5334 | copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5335 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5336 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5337 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5338 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5339 | LayerImplList render_surface_layer_list; |
| 5340 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5341 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5342 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5343 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5344 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5345 | EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 5346 | EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5347 | EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5348 | EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5349 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5350 | // We should have four render surfaces, one for the root, one for the grand |
| 5351 | // parent since it has opacity and two drawing descendants, one for the parent |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5352 | // since it owns a surface, and one for the copy_layer. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5353 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5354 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5355 | EXPECT_EQ(copy_grand_parent_layer->id(), |
| 5356 | render_surface_layer_list.at(1)->id()); |
| 5357 | EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id()); |
| 5358 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5359 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5360 | // The root render surface should have 2 contributing layers. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5361 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5362 | EXPECT_EQ(root_layer->id(), |
| 5363 | root_layer->render_surface()->layer_list().at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5364 | EXPECT_EQ(copy_grand_parent_layer->id(), |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5365 | root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5366 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 5367 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5368 | // appear in its list, since it needs to be drawn for the copy request. |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5369 | ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5370 | EXPECT_EQ(copy_layer->id(), |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5371 | copy_parent_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5372 | |
| 5373 | // The copy_layer's render surface should have two contributing layers. |
| 5374 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 5375 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5376 | copy_layer->render_surface()->layer_list().at(0)->id()); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5377 | EXPECT_EQ(copy_child_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5378 | copy_layer->render_surface()->layer_list().at(1)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5379 | |
| 5380 | // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden, |
| 5381 | // but the copy_layer and copy_child should be drawn for the copy request. |
| 5382 | // copy grand child should not be drawn as its hidden even in the copy |
| 5383 | // request. |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 5384 | EffectTree& tree = |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5385 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5386 | EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5387 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5388 | node = tree.Node(copy_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5389 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5390 | node = tree.Node(copy_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5391 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5392 | node = tree.Node(copy_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5393 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5394 | node = tree.Node(copy_grand_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5395 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5396 | |
| 5397 | // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its |
| 5398 | // actually hidden. |
| 5399 | EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5400 | } |
| 5401 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5402 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5403 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5404 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 5405 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5406 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5407 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5408 | std::unique_ptr<LayerImpl> root = |
| 5409 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5410 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5411 | root->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5412 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5413 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5414 | LayerImpl::Create(host_impl.pending_tree(), 2); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5415 | copy_parent->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5416 | copy_parent->SetMasksToBounds(true); |
| 5417 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5418 | std::unique_ptr<LayerImpl> copy_layer = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5419 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5420 | copy_layer->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5421 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5422 | copy_layer->test_properties()->force_render_surface = true; |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5423 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5424 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5425 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5426 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5427 | copy_child->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5428 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5429 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5430 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5431 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5432 | copy_layer->test_properties()->AddChild(std::move(copy_child)); |
| 5433 | copy_parent->test_properties()->AddChild(std::move(copy_layer)); |
| 5434 | root->test_properties()->AddChild(std::move(copy_parent)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5435 | |
| 5436 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5437 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5438 | root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5439 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5440 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5441 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5442 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5443 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5444 | // We should have two render surface, as the others are clipped out. |
| 5445 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5446 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5447 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5448 | // The root render surface should only have 2 contributing layer, since the |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5449 | // other layers are empty/clipped away. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5450 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5451 | EXPECT_EQ(root_layer->id(), |
| 5452 | root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5453 | } |
| 5454 | |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5455 | TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5456 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5457 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5458 | root->SetDrawsContent(true); |
| 5459 | root->SetMasksToBounds(true); |
| 5460 | |
| 5461 | LayerImpl* copy_layer = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5462 | copy_layer->SetBounds(gfx::Size(100, 100)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5463 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5464 | copy_layer->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5465 | |
| 5466 | LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5467 | copy_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5468 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5469 | copy_child->SetDrawsContent(true); |
| 5470 | |
| 5471 | LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5472 | copy_clip->SetBounds(gfx::Size(55, 55)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5473 | copy_clip->SetMasksToBounds(true); |
| 5474 | |
| 5475 | LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5476 | copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5477 | copy_clipped_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5478 | copy_clipped_child->SetDrawsContent(true); |
| 5479 | |
| 5480 | LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5481 | copy_surface->SetPosition(gfx::PointF(45.f, 45.f)); |
| 5482 | copy_surface->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5483 | copy_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5484 | copy_surface->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5485 | |
| 5486 | copy_layer->test_properties()->copy_requests.push_back( |
| 5487 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5488 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5489 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5490 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5491 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5492 | |
| 5493 | EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect()); |
| 5494 | EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect()); |
| 5495 | EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect()); |
| 5496 | EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect()); |
| 5497 | |
| 5498 | // Case 2: When the non root copy request layer is clipped. |
| 5499 | copy_layer->SetBounds(gfx::Size(50, 50)); |
| 5500 | copy_layer->SetMasksToBounds(true); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5501 | copy_layer->test_properties()->copy_requests.push_back( |
| 5502 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5503 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5504 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5505 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5506 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5507 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5508 | |
| 5509 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5510 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5511 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5512 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | 296dd9f | 2016-07-05 14:59:51 | [diff] [blame] | 5513 | |
| 5514 | // Case 3: When there is device scale factor. |
| 5515 | float device_scale_factor = 2.f; |
| 5516 | copy_layer->test_properties()->copy_requests.push_back( |
| 5517 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5518 | |
| 5519 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
| 5520 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 5521 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
| 5522 | |
| 5523 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5524 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5525 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5526 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5527 | } |
| 5528 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5529 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 5530 | // Ensure that a transform between the layer and its render surface is not a |
| 5531 | // problem. Constructs the following layer tree. |
| 5532 | // |
| 5533 | // root (a render surface) |
| 5534 | // + render_surface |
| 5535 | // + clip_parent (scaled) |
| 5536 | // + intervening_clipping_layer |
| 5537 | // + clip_child |
| 5538 | // |
| 5539 | // The render surface should be resized correctly and the clip child should |
| 5540 | // inherit the right clip rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5541 | LayerImpl* root = root_layer_for_testing(); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5542 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 5543 | LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5544 | clip_parent->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5545 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5546 | intervening->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5547 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5548 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5549 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5550 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5551 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5552 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5553 | |
| 5554 | intervening->SetMasksToBounds(true); |
| 5555 | clip_parent->SetMasksToBounds(true); |
| 5556 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5557 | gfx::Transform scale_transform; |
| 5558 | scale_transform.Scale(2, 2); |
| 5559 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5560 | root->SetBounds(gfx::Size(50, 50)); |
| 5561 | render_surface->SetBounds(gfx::Size(10, 10)); |
| 5562 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5563 | clip_parent->test_properties()->transform = scale_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5564 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5565 | clip_parent->SetBounds(gfx::Size(10, 10)); |
| 5566 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5567 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5568 | clip_child->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5569 | clip_child->SetBounds(gfx::Size(10, 10)); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5570 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5571 | |
| 5572 | ASSERT_TRUE(root->render_surface()); |
| 5573 | ASSERT_TRUE(render_surface->render_surface()); |
| 5574 | |
| 5575 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 5576 | // by the intervening clip layer. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5577 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect()); |
| 5578 | ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect()); |
| 5579 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5580 | |
| 5581 | // Ensure that the render surface reports a content rect that has been grown |
| 5582 | // to accomodate for the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5583 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), |
| 5584 | render_surface->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5585 | |
| 5586 | // The above check implies the two below, but they nicely demonstrate that |
| 5587 | // we've grown, despite the intervening layer's clip. |
| 5588 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 5589 | render_surface->render_surface()->content_rect())); |
| 5590 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 5591 | render_surface->render_surface()->content_rect())); |
| 5592 | } |
| 5593 | |
| 5594 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 5595 | // Ensure that intervening render surfaces are not a problem in the basic |
| 5596 | // case. In the following tree, both render surfaces should be resized to |
| 5597 | // accomodate for the clip child, despite an intervening clip. |
| 5598 | // |
| 5599 | // root (a render surface) |
| 5600 | // + clip_parent (masks to bounds) |
| 5601 | // + render_surface1 (sets opacity) |
| 5602 | // + intervening (masks to bounds) |
| 5603 | // + render_surface2 (also sets opacity) |
| 5604 | // + clip_child |
| 5605 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5606 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5607 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5608 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5609 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5610 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5611 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5612 | render_surface1->SetDrawsContent(true); |
| 5613 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5614 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5615 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5616 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5617 | |
| 5618 | intervening->SetMasksToBounds(true); |
| 5619 | clip_parent->SetMasksToBounds(true); |
| 5620 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5621 | gfx::Transform translation_transform; |
| 5622 | translation_transform.Translate(2, 2); |
| 5623 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5624 | root->SetBounds(gfx::Size(50, 50)); |
| 5625 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5626 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5627 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5628 | render_surface1->test_properties()->force_render_surface = true; |
| 5629 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5630 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5631 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5632 | render_surface2->test_properties()->force_render_surface = true; |
| 5633 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5634 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5635 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5636 | |
| 5637 | EXPECT_TRUE(root->render_surface()); |
| 5638 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5639 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5640 | |
| 5641 | // Since the render surfaces could have expanded, they should not clip (their |
| 5642 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5643 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5644 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5645 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5646 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5647 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5648 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5649 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5650 | |
| 5651 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5652 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5653 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5654 | |
| 5655 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5656 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5657 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5658 | |
| 5659 | // The content rects of both render surfaces should both have expanded to |
| 5660 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5661 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5662 | render_surface1->render_surface()->content_rect()); |
| 5663 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), |
| 5664 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5665 | |
| 5666 | // The clip child should have inherited the clip parent's clip (projected to |
| 5667 | // the right space, of course), and should have the correctly sized visible |
| 5668 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5669 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect()); |
| 5670 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5671 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5672 | } |
| 5673 | |
| 5674 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 5675 | // Ensure that intervening render surfaces are not a problem, even if there |
| 5676 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 5677 | // of transform. |
| 5678 | // |
| 5679 | // root (a render surface) |
| 5680 | // + clip_parent (masks to bounds) |
| 5681 | // + render_surface1 (sets opacity) |
| 5682 | // + intervening (masks to bounds AND scrolls) |
| 5683 | // + render_surface2 (also sets opacity) |
| 5684 | // + clip_child |
| 5685 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5686 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5687 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5688 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5689 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5690 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5691 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5692 | render_surface1->SetDrawsContent(true); |
| 5693 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5694 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5695 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5696 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5697 | |
| 5698 | intervening->SetMasksToBounds(true); |
| 5699 | clip_parent->SetMasksToBounds(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5700 | intervening->SetScrollClipLayer(clip_parent->id()); |
| 5701 | intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5702 | |
| 5703 | gfx::Transform translation_transform; |
| 5704 | translation_transform.Translate(2, 2); |
| 5705 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5706 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5707 | clip_parent->test_properties()->transform = translation_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5708 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5709 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5710 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5711 | render_surface1->test_properties()->force_render_surface = true; |
| 5712 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5713 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5714 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5715 | render_surface2->test_properties()->force_render_surface = true; |
| 5716 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5717 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5718 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5719 | |
| 5720 | EXPECT_TRUE(root->render_surface()); |
| 5721 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5722 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5723 | |
| 5724 | // Since the render surfaces could have expanded, they should not clip (their |
| 5725 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5726 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5727 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5728 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5729 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5730 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5731 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5732 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5733 | |
| 5734 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5735 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5736 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5737 | |
| 5738 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5739 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5740 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5741 | |
| 5742 | // The content rects of both render surfaces should both have expanded to |
| 5743 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5744 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5745 | render_surface1->render_surface()->content_rect()); |
| 5746 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), |
| 5747 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5748 | |
| 5749 | // The clip child should have inherited the clip parent's clip (projected to |
| 5750 | // the right space, of course), and should have the correctly sized visible |
| 5751 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5752 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect()); |
| 5753 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5754 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5755 | } |
| 5756 | |
| 5757 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 5758 | // Ensures that descendants of the clip child inherit the correct clip. |
| 5759 | // |
| 5760 | // root (a render surface) |
| 5761 | // + clip_parent (masks to bounds) |
| 5762 | // + intervening (masks to bounds) |
| 5763 | // + clip_child |
| 5764 | // + child |
| 5765 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5766 | LayerImpl* root = root_layer_for_testing(); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5767 | LayerImpl* clip_parent = AddChild<LayerImpl>(root); |
| 5768 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
| 5769 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5770 | LayerImpl* child = AddChild<LayerImpl>(clip_child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5771 | clip_child->SetDrawsContent(true); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5772 | child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5773 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5774 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5775 | clip_parent->test_properties()->clip_children = |
| 5776 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5777 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5778 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5779 | root->SetBounds(gfx::Size(50, 50)); |
| 5780 | clip_parent->SetBounds(gfx::Size(40, 40)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5781 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5782 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5783 | intervening->SetMasksToBounds(true); |
| 5784 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 5785 | child->SetBounds(gfx::Size(60, 60)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5786 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5787 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5788 | |
| 5789 | EXPECT_TRUE(root->render_surface()); |
| 5790 | |
| 5791 | // Neither the clip child nor its descendant should have inherited the clip |
| 5792 | // from |intervening|. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5793 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5794 | EXPECT_TRUE(clip_child->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5795 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5796 | EXPECT_TRUE(child->is_clipped()); |
| 5797 | } |
| 5798 | |
| 5799 | TEST_F(LayerTreeHostCommonTest, |
| 5800 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 5801 | // Ensures that non-descendant clip children in the tree do not affect |
| 5802 | // render surfaces. |
| 5803 | // |
| 5804 | // root (a render surface) |
| 5805 | // + clip_parent (masks to bounds) |
| 5806 | // + render_surface1 |
| 5807 | // + clip_child |
| 5808 | // + render_surface2 |
| 5809 | // + non_clip_child |
| 5810 | // |
| 5811 | // In this example render_surface2 should be unaffected by clip_child. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5812 | LayerImpl* root = root_layer_for_testing(); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5813 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5814 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5815 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5816 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent); |
| 5817 | LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5818 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5819 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5820 | clip_parent->test_properties()->clip_children = |
| 5821 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5822 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5823 | |
| 5824 | clip_parent->SetMasksToBounds(true); |
| 5825 | render_surface1->SetMasksToBounds(true); |
| 5826 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5827 | render_surface1->SetDrawsContent(true); |
| 5828 | clip_child->SetDrawsContent(true); |
| 5829 | render_surface2->SetDrawsContent(true); |
| 5830 | non_clip_child->SetDrawsContent(true); |
| 5831 | |
| 5832 | root->SetBounds(gfx::Size(15, 15)); |
| 5833 | clip_parent->SetBounds(gfx::Size(10, 10)); |
| 5834 | render_surface1->SetPosition(gfx::PointF(5, 5)); |
| 5835 | render_surface1->SetBounds(gfx::Size(5, 5)); |
| 5836 | render_surface1->test_properties()->force_render_surface = true; |
| 5837 | render_surface2->SetBounds(gfx::Size(5, 5)); |
| 5838 | render_surface2->test_properties()->force_render_surface = true; |
| 5839 | clip_child->SetPosition(gfx::PointF(-1, 1)); |
| 5840 | clip_child->SetBounds(gfx::Size(10, 10)); |
| 5841 | non_clip_child->SetBounds(gfx::Size(5, 5)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5842 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5843 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5844 | |
| 5845 | EXPECT_TRUE(root->render_surface()); |
| 5846 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5847 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5848 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5849 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5850 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5851 | |
| 5852 | // The render surface should not clip (it has unclipped descendants), instead |
| 5853 | // it should rely on layer clipping. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5854 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5855 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5856 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 5857 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5858 | // That said, it should have grown to accomodate the unclipped descendant and |
| 5859 | // its own size. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5860 | EXPECT_EQ(gfx::Rect(-1, 0, 6, 5), |
| 5861 | render_surface1->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5862 | |
| 5863 | // This render surface should clip. It has no unclipped descendants. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5864 | EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 5865 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5866 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 5867 | EXPECT_FALSE(render_surface2->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5868 | |
| 5869 | // It also shouldn't have grown to accomodate the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5870 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), |
| 5871 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5872 | |
| 5873 | // Sanity check our num_unclipped_descendants values. |
ajuma | 0641ded | 2016-05-05 21:28:21 | [diff] [blame] | 5874 | EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants); |
| 5875 | EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5876 | } |
| 5877 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5878 | TEST_F(LayerTreeHostCommonTest, |
| 5879 | CreateRenderSurfaceWhenFlattenInsideRenderingContext) { |
| 5880 | // Verifies that Render Surfaces are created at the edge of rendering context. |
| 5881 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5882 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5883 | LayerImpl* child1 = AddChildToRoot<LayerImpl>(); |
| 5884 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 5885 | LayerImpl* child3 = AddChild<LayerImpl>(child2); |
| 5886 | root->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5887 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5888 | gfx::Size bounds(100, 100); |
| 5889 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5890 | root->SetBounds(bounds); |
| 5891 | child1->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5892 | child1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5893 | child1->Set3dSortingContextId(1); |
| 5894 | child1->test_properties()->should_flatten_transform = false; |
| 5895 | child2->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5896 | child2->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5897 | child2->Set3dSortingContextId(1); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5898 | child3->SetBounds(bounds); |
| 5899 | child3->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5900 | child3->Set3dSortingContextId(1); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 5901 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5902 | |
| 5903 | // Verify which render surfaces were created. |
| 5904 | EXPECT_TRUE(root->has_render_surface()); |
| 5905 | EXPECT_FALSE(child1->has_render_surface()); |
| 5906 | EXPECT_TRUE(child2->has_render_surface()); |
| 5907 | EXPECT_FALSE(child3->has_render_surface()); |
| 5908 | } |
| 5909 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5910 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5911 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5912 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 5913 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5914 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5915 | std::unique_ptr<LayerImpl> root = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5916 | LayerImpl::Create(host_impl.active_tree(), 12345); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5917 | std::unique_ptr<LayerImpl> child1 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5918 | LayerImpl::Create(host_impl.active_tree(), 123456); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5919 | std::unique_ptr<LayerImpl> child2 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5920 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5921 | std::unique_ptr<LayerImpl> child3 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5922 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 5923 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5924 | gfx::Size bounds(100, 100); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5925 | |
| 5926 | root->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5927 | root->SetDrawsContent(true); |
| 5928 | |
| 5929 | // This layer structure normally forces render surface due to preserves3d |
| 5930 | // behavior. |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5931 | child1->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5932 | child1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5933 | child1->Set3dSortingContextId(1); |
| 5934 | child1->test_properties()->should_flatten_transform = false; |
| 5935 | child2->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5936 | child2->SetDrawsContent(true); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 5937 | child2->Set3dSortingContextId(1); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5938 | child3->SetBounds(bounds); |
| 5939 | child3->SetDrawsContent(true); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 5940 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5941 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5942 | child2->test_properties()->AddChild(std::move(child3)); |
| 5943 | child1->test_properties()->AddChild(std::move(child2)); |
| 5944 | root->test_properties()->AddChild(std::move(child1)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5945 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5946 | root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5947 | |
| 5948 | { |
| 5949 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5950 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5951 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5952 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5953 | inputs.can_render_to_separate_surface = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5954 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5955 | |
| 5956 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5957 | |
| 5958 | int count_represents_target_render_surface = 0; |
| 5959 | int count_represents_contributing_render_surface = 0; |
| 5960 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 5961 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 5962 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5963 | it != end; ++it) { |
| 5964 | if (it.represents_target_render_surface()) |
| 5965 | count_represents_target_render_surface++; |
| 5966 | if (it.represents_contributing_render_surface()) |
| 5967 | count_represents_contributing_render_surface++; |
| 5968 | if (it.represents_itself()) |
| 5969 | count_represents_itself++; |
| 5970 | } |
| 5971 | |
| 5972 | // Two render surfaces. |
| 5973 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 5974 | // Second render surface contributes to root render surface. |
| 5975 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 5976 | // All 4 layers represent itself. |
| 5977 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5978 | } |
| 5979 | |
| 5980 | { |
| 5981 | LayerImplList render_surface_layer_list; |
| 5982 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5983 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5984 | inputs.can_render_to_separate_surface = false; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5985 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5986 | |
| 5987 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5988 | |
| 5989 | int count_represents_target_render_surface = 0; |
| 5990 | int count_represents_contributing_render_surface = 0; |
| 5991 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 5992 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 5993 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5994 | it != end; ++it) { |
| 5995 | if (it.represents_target_render_surface()) |
| 5996 | count_represents_target_render_surface++; |
| 5997 | if (it.represents_contributing_render_surface()) |
| 5998 | count_represents_contributing_render_surface++; |
| 5999 | if (it.represents_itself()) |
| 6000 | count_represents_itself++; |
| 6001 | } |
| 6002 | |
| 6003 | // Only root layer has a render surface. |
| 6004 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 6005 | // No layer contributes a render surface to root render surface. |
| 6006 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 6007 | // All 4 layers represent itself. |
| 6008 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6009 | } |
| 6010 | } |
| 6011 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6012 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6013 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6014 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame^] | 6015 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6016 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6017 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame^] | 6018 | |
| 6019 | LayerImpl* flattener = AddChild<LayerImpl>(back_facing); |
| 6020 | LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6021 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6022 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6023 | child1->SetDrawsContent(true); |
| 6024 | child2->SetDrawsContent(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6025 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6026 | root->SetBounds(gfx::Size(50, 50)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6027 | back_facing->SetBounds(gfx::Size(50, 50)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6028 | back_facing->test_properties()->should_flatten_transform = false; |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame^] | 6029 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6030 | render_surface1->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6031 | render_surface1->test_properties()->should_flatten_transform = false; |
| 6032 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6033 | render_surface1->test_properties()->double_sided = false; |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame^] | 6034 | child1->SetBounds(gfx::Size(20, 20)); |
| 6035 | |
| 6036 | flattener->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6037 | render_surface2->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6038 | render_surface2->test_properties()->should_flatten_transform = false; |
| 6039 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6040 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6041 | child2->SetBounds(gfx::Size(20, 20)); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6042 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6043 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6044 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6045 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6046 | EXPECT_EQ(2u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6047 | ->at(0) |
| 6048 | ->render_surface() |
| 6049 | ->layer_list() |
| 6050 | .size()); |
| 6051 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
| 6052 | ->at(1) |
| 6053 | ->render_surface() |
| 6054 | ->layer_list() |
| 6055 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6056 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6057 | gfx::Transform rotation_transform; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6058 | rotation_transform.RotateAboutXAxis(180.0); |
| 6059 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6060 | back_facing->test_properties()->transform = rotation_transform; |
jaydasika | 5aa88b8 | 2015-11-10 01:48:03 | [diff] [blame] | 6061 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6062 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6063 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6064 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6065 | // render_surface1 is in the same 3d rendering context as back_facing and is |
| 6066 | // not double sided, so it should not be in RSLL. render_surface2 is also not |
| 6067 | // double-sided, but will still be in RSLL as it's in a different 3d rendering |
| 6068 | // context. |
| 6069 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
| 6070 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6071 | ->at(0) |
| 6072 | ->render_surface() |
| 6073 | ->layer_list() |
| 6074 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6075 | } |
| 6076 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6077 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6078 | LayerImpl* root = root_layer_for_testing(); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6079 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 6080 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6081 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6082 | root->SetBounds(gfx::Size(50, 50)); |
| 6083 | root->test_properties()->should_flatten_transform = false; |
| 6084 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6085 | child->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6086 | child->test_properties()->should_flatten_transform = false; |
| 6087 | grand_child->SetBounds(gfx::Size(20, 20)); |
| 6088 | grand_child->SetDrawsContent(true); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6089 | grand_child->SetUseParentBackfaceVisibility(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6090 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6091 | ExecuteCalculateDrawProperties(root); |
| 6092 | |
| 6093 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6094 | EXPECT_EQ(grand_child, render_surface_layer_list_impl() |
| 6095 | ->at(0) |
| 6096 | ->render_surface() |
| 6097 | ->layer_list()[0]); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6098 | |
| 6099 | // As all layers have identity transform, we shouldn't check for backface |
| 6100 | // visibility. |
| 6101 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6102 | EXPECT_FALSE(child->should_check_backface_visibility()); |
| 6103 | EXPECT_FALSE(grand_child->should_check_backface_visibility()); |
| 6104 | // As there are no 3d rendering contexts, all layers should use their local |
| 6105 | // transform for backface visibility. |
| 6106 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6107 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6108 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6109 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6110 | gfx::Transform rotation_transform; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6111 | rotation_transform.RotateAboutXAxis(180.0); |
| 6112 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6113 | child->test_properties()->transform = rotation_transform; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6114 | child->Set3dSortingContextId(1); |
| 6115 | grand_child->Set3dSortingContextId(1); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6116 | child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6117 | |
| 6118 | ExecuteCalculateDrawProperties(root); |
| 6119 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6120 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6121 | ->at(0) |
| 6122 | ->render_surface() |
| 6123 | ->layer_list() |
| 6124 | .size()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6125 | |
| 6126 | // We should check for backface visibilty of child as it has a rotation |
| 6127 | // transform. We should also check for grand_child as it uses the backface |
| 6128 | // visibility of its parent. |
| 6129 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6130 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6131 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6132 | // child uses its local transform for backface visibility as it is the root of |
| 6133 | // a 3d rendering context. grand_child is in a 3d rendering context and is not |
| 6134 | // the root, but it derives its backface visibility from its parent which uses |
| 6135 | // its local transform. |
| 6136 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6137 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6138 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6139 | |
| 6140 | grand_child->SetUseParentBackfaceVisibility(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6141 | grand_child->test_properties()->double_sided = false; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6142 | grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6143 | |
| 6144 | ExecuteCalculateDrawProperties(root); |
| 6145 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6146 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6147 | ->at(0) |
| 6148 | ->render_surface() |
| 6149 | ->layer_list() |
| 6150 | .size()); |
| 6151 | |
| 6152 | // We should check the backface visibility of child as it has a rotation |
| 6153 | // transform and for grand_child as it is in a 3d rendering context and not |
| 6154 | // the root of it. |
| 6155 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6156 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6157 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6158 | // grand_child is in an existing 3d rendering context, so it should not use |
| 6159 | // local transform for backface visibility. |
| 6160 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6161 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6162 | EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility()); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6163 | } |
| 6164 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6165 | TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6166 | LayerImpl* root = root_layer_for_testing(); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6167 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6168 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6169 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6170 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6171 | gfx::Transform rotate_about_y; |
| 6172 | rotate_about_y.RotateAboutYAxis(180.0); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6173 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6174 | root->SetBounds(gfx::Size(50, 50)); |
| 6175 | root->Set3dSortingContextId(1); |
| 6176 | root->test_properties()->should_flatten_transform = false; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6177 | back_facing->test_properties()->transform = rotate_about_y; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6178 | back_facing->SetBounds(gfx::Size(50, 50)); |
| 6179 | back_facing->Set3dSortingContextId(1); |
| 6180 | back_facing->test_properties()->should_flatten_transform = false; |
| 6181 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 6182 | render_surface1->Set3dSortingContextId(1); |
| 6183 | render_surface1->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6184 | render_surface1->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6185 | render_surface1->test_properties()->force_render_surface = true; |
| 6186 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 6187 | render_surface2->Set3dSortingContextId(1); |
| 6188 | render_surface2->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6189 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6190 | render_surface2->test_properties()->force_render_surface = true; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6191 | ExecuteCalculateDrawProperties(root); |
| 6192 | |
| 6193 | const EffectTree& tree = |
| 6194 | root->layer_tree_impl()->property_trees()->effect_tree; |
| 6195 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6196 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6197 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6198 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6199 | |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 6200 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6201 | gfx::Transform(), back_facing->transform_tree_index(), |
| 6202 | root->layer_tree_impl()); |
| 6203 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6204 | rotate_about_y, render_surface2->transform_tree_index(), |
| 6205 | root->layer_tree_impl()); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6206 | ExecuteCalculateDrawProperties(root); |
| 6207 | EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6208 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6209 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6210 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6211 | |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 6212 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6213 | rotate_about_y, render_surface1->transform_tree_index(), |
| 6214 | root->layer_tree_impl()); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6215 | ExecuteCalculateDrawProperties(root); |
| 6216 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6217 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6218 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6219 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6220 | } |
| 6221 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6222 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 6223 | // Checks that the simple case (being clipped by a scroll parent that would |
| 6224 | // have been processed before you anyhow) results in the right clips. |
| 6225 | // |
| 6226 | // + root |
| 6227 | // + scroll_parent_border |
| 6228 | // | + scroll_parent_clip |
| 6229 | // | + scroll_parent |
| 6230 | // + scroll_child |
| 6231 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6232 | LayerImpl* root = root_layer_for_testing(); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6233 | LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>(); |
| 6234 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6235 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6236 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6237 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6238 | scroll_parent->SetDrawsContent(true); |
| 6239 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6240 | scroll_parent_clip->SetMasksToBounds(true); |
| 6241 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6242 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6243 | scroll_parent->test_properties()->scroll_children = |
| 6244 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6245 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6246 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6247 | root->SetBounds(gfx::Size(50, 50)); |
| 6248 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6249 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6250 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6251 | scroll_child->SetBounds(gfx::Size(50, 50)); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6252 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6253 | |
| 6254 | EXPECT_TRUE(root->render_surface()); |
| 6255 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6256 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6257 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6258 | } |
| 6259 | |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6260 | TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) { |
| 6261 | // Tests the computation of draw transform for the scroll child when its |
| 6262 | // target is different from its scroll parent's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6263 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6264 | LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); |
| 6265 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); |
| 6266 | LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target); |
| 6267 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); |
| 6268 | |
| 6269 | scroll_parent->SetDrawsContent(true); |
| 6270 | scroll_child->SetDrawsContent(true); |
| 6271 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6272 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6273 | scroll_parent->test_properties()->scroll_children = |
| 6274 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6275 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6276 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6277 | root->SetBounds(gfx::Size(50, 50)); |
| 6278 | scroll_child_target->SetBounds(gfx::Size(50, 50)); |
| 6279 | scroll_child_target->test_properties()->force_render_surface = true; |
| 6280 | scroll_child->SetBounds(gfx::Size(50, 50)); |
| 6281 | scroll_parent_target->SetPosition(gfx::PointF(10, 10)); |
| 6282 | scroll_parent_target->SetBounds(gfx::Size(50, 50)); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6283 | scroll_parent_target->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6284 | scroll_parent_target->test_properties()->force_render_surface = true; |
| 6285 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6286 | |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6287 | float device_scale_factor = 1.5f; |
| 6288 | LayerImplList render_surface_layer_list_impl; |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 6289 | gfx::Size device_viewport_size = |
| 6290 | gfx::Size(root->bounds().width() * device_scale_factor, |
| 6291 | root->bounds().height() * device_scale_factor); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6292 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 6293 | root, device_viewport_size, gfx::Transform(), |
| 6294 | &render_surface_layer_list_impl); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6295 | inputs.device_scale_factor = device_scale_factor; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6296 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6297 | |
weiliangc | 1da3fb89 | 2016-03-14 20:23:52 | [diff] [blame] | 6298 | EXPECT_EQ(scroll_child->effect_tree_index(), |
| 6299 | scroll_child_target->effect_tree_index()); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6300 | EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); |
| 6301 | EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); |
| 6302 | gfx::Transform scale; |
| 6303 | scale.Scale(1.5f, 1.5f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6304 | EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6305 | } |
| 6306 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6307 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6308 | LayerImpl* root = root_layer_for_testing(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6309 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6310 | LayerImpl* child = AddChild<LayerImpl>(parent); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6311 | |
| 6312 | root->SetBounds(gfx::Size(50, 50)); |
| 6313 | root->SetDrawsContent(true); |
| 6314 | root->Set3dSortingContextId(1); |
| 6315 | parent->SetBounds(gfx::Size(30, 30)); |
| 6316 | parent->SetDrawsContent(true); |
| 6317 | parent->Set3dSortingContextId(1); |
| 6318 | parent->test_properties()->force_render_surface = true; |
| 6319 | child->SetBounds(gfx::Size(20, 20)); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6320 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6321 | child->Set3dSortingContextId(1); |
| 6322 | child->test_properties()->force_render_surface = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6323 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6324 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6325 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6326 | |
| 6327 | gfx::Transform singular_transform; |
| 6328 | singular_transform.Scale3d( |
| 6329 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 6330 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6331 | child->test_properties()->transform = singular_transform; |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6332 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6333 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6334 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6335 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6336 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6337 | |
| 6338 | // Ensure that the entire subtree under a layer with singular transform does |
| 6339 | // not get rendered. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6340 | parent->test_properties()->transform = singular_transform; |
| 6341 | child->test_properties()->transform = gfx::Transform(); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6342 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6343 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6344 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6345 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6346 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6347 | } |
| 6348 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6349 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 6350 | // Checks that clipping by a scroll parent that follows you in paint order |
| 6351 | // still results in correct clipping. |
| 6352 | // |
| 6353 | // + root |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6354 | // + scroll_parent_border |
| 6355 | // + scroll_parent_clip |
| 6356 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6357 | // + scroll_child |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6358 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6359 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6360 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6361 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6362 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6363 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6364 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6365 | scroll_parent->SetDrawsContent(true); |
| 6366 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6367 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6368 | root->SetBounds(gfx::Size(50, 50)); |
| 6369 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6370 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6371 | scroll_parent_clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6372 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6373 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6374 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6375 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6376 | scroll_parent->test_properties()->scroll_children = |
| 6377 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6378 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6379 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6380 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6381 | |
| 6382 | EXPECT_TRUE(root->render_surface()); |
| 6383 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6384 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6385 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6386 | } |
| 6387 | |
| 6388 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 6389 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 6390 | // you in paint order still results in correct clipping. |
| 6391 | // |
| 6392 | // + root |
| 6393 | // + scroll_child |
| 6394 | // + scroll_parent_border |
| 6395 | // | + scroll_parent_clip |
| 6396 | // | + scroll_parent |
| 6397 | // + scroll_grandparent_border |
| 6398 | // + scroll_grandparent_clip |
| 6399 | // + scroll_grandparent |
| 6400 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6401 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6402 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6403 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6404 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6405 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6406 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6407 | LayerImpl* scroll_grandparent_clip = |
| 6408 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6409 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6410 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6411 | scroll_parent->SetDrawsContent(true); |
| 6412 | scroll_grandparent->SetDrawsContent(true); |
| 6413 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6414 | |
| 6415 | scroll_parent_clip->SetMasksToBounds(true); |
| 6416 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6417 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6418 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6419 | scroll_parent->test_properties()->scroll_children = |
| 6420 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6421 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6422 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6423 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6424 | scroll_grandparent->test_properties()->scroll_children = |
| 6425 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6426 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 6427 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6428 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6429 | root->SetBounds(gfx::Size(50, 50)); |
| 6430 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 6431 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 6432 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 6433 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6434 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6435 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6436 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6437 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6438 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6439 | |
| 6440 | EXPECT_TRUE(root->render_surface()); |
| 6441 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6442 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6443 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6444 | |
| 6445 | // Despite the fact that we visited the above layers out of order to get the |
| 6446 | // correct clip, the layer lists should be unaffected. |
| 6447 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6448 | EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0)); |
| 6449 | EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1)); |
| 6450 | EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6451 | } |
| 6452 | |
| 6453 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 6454 | // Ensures that even if we visit layers out of order, we still produce a |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 6455 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6456 | // + root |
| 6457 | // + scroll_child |
| 6458 | // + scroll_parent_border |
| 6459 | // + scroll_parent_clip |
| 6460 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6461 | // + render_surface2 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6462 | // + scroll_grandparent_border |
| 6463 | // + scroll_grandparent_clip |
| 6464 | // + scroll_grandparent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6465 | // + render_surface1 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6466 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6467 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6468 | root->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6469 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6470 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6471 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6472 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6473 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6474 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6475 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6476 | LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent); |
| 6477 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6478 | LayerImpl* scroll_grandparent_clip = |
| 6479 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6480 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
| 6481 | LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6482 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6483 | scroll_parent->SetDrawsContent(true); |
| 6484 | render_surface1->SetDrawsContent(true); |
| 6485 | scroll_grandparent->SetDrawsContent(true); |
| 6486 | render_surface2->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6487 | |
| 6488 | scroll_parent_clip->SetMasksToBounds(true); |
| 6489 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6490 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6491 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6492 | scroll_parent->test_properties()->scroll_children = |
| 6493 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6494 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6495 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6496 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6497 | scroll_grandparent->test_properties()->scroll_children = |
| 6498 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6499 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 6500 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6501 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6502 | root->SetBounds(gfx::Size(50, 50)); |
| 6503 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 6504 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 6505 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 6506 | render_surface1->SetBounds(gfx::Size(50, 50)); |
| 6507 | render_surface1->test_properties()->force_render_surface = true; |
| 6508 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6509 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6510 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6511 | render_surface2->SetBounds(gfx::Size(50, 50)); |
| 6512 | render_surface2->test_properties()->force_render_surface = true; |
| 6513 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6514 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6515 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6516 | |
| 6517 | EXPECT_TRUE(root->render_surface()); |
| 6518 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6519 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6520 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6521 | |
| 6522 | // Despite the fact that we had to process the layers out of order to get the |
| 6523 | // right clip, our render_surface_layer_list's order should be unaffected. |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6524 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6525 | EXPECT_EQ(root, render_surface_layer_list_impl()->at(0)); |
| 6526 | EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1)); |
| 6527 | EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2)); |
| 6528 | EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface()); |
| 6529 | EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface()); |
| 6530 | EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6531 | } |
| 6532 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6533 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 6534 | // Ensures that when we have a render surface between a fixed position layer |
| 6535 | // and its container, we compute the fixed position layer's draw transform |
| 6536 | // with respect to that intervening render surface, not with respect to its |
| 6537 | // container's render target. |
| 6538 | // |
| 6539 | // + root |
| 6540 | // + render_surface |
| 6541 | // + fixed |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6542 | // + child |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6543 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6544 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6545 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 6546 | LayerImpl* fixed = AddChild<LayerImpl>(render_surface); |
| 6547 | LayerImpl* child = AddChild<LayerImpl>(fixed); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6548 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6549 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6550 | root->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6551 | |
| 6552 | LayerPositionConstraint constraint; |
| 6553 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6554 | fixed->test_properties()->position_constraint = constraint; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6555 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6556 | root->SetBounds(gfx::Size(50, 50)); |
| 6557 | render_surface->SetPosition(gfx::PointF(7.f, 9.f)); |
| 6558 | render_surface->SetBounds(gfx::Size(50, 50)); |
| 6559 | render_surface->SetDrawsContent(true); |
| 6560 | fixed->SetPosition(gfx::PointF(10.f, 15.f)); |
| 6561 | fixed->SetBounds(gfx::Size(50, 50)); |
| 6562 | fixed->SetDrawsContent(true); |
| 6563 | child->SetPosition(gfx::PointF(1.f, 2.f)); |
| 6564 | child->SetBounds(gfx::Size(50, 50)); |
| 6565 | child->SetDrawsContent(true); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6566 | ExecuteCalculateDrawProperties(root); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6567 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6568 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6569 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6570 | EffectTree& effect_tree = |
| 6571 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6572 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6573 | gfx::Transform expected_fixed_draw_transform; |
| 6574 | expected_fixed_draw_transform.Translate(10.f, 15.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6575 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6576 | expected_fixed_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6577 | draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6578 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6579 | gfx::Transform expected_fixed_screen_space_transform; |
| 6580 | expected_fixed_screen_space_transform.Translate(17.f, 24.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6581 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6582 | expected_fixed_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6583 | draw_property_utils::ScreenSpaceTransform(fixed, transform_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6584 | |
| 6585 | gfx::Transform expected_child_draw_transform; |
| 6586 | expected_child_draw_transform.Translate(11.f, 17.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6587 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6588 | expected_child_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6589 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6590 | |
| 6591 | gfx::Transform expected_child_screen_space_transform; |
| 6592 | expected_child_screen_space_transform.Translate(18.f, 26.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6593 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6594 | expected_child_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6595 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6596 | } |
| 6597 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6598 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 6599 | // This test verifies that a scrolling layer that gets snapped to |
| 6600 | // integer coordinates doesn't move a fixed position child. |
| 6601 | // |
| 6602 | // + root |
| 6603 | // + container |
| 6604 | // + scroller |
| 6605 | // + fixed |
| 6606 | // |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6607 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6608 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 6609 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6610 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6611 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6612 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 6613 | LayerImpl* root = root_ptr.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6614 | std::unique_ptr<LayerImpl> container = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6615 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 6616 | LayerImpl* container_layer = container.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6617 | std::unique_ptr<LayerImpl> scroller = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6618 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 6619 | LayerImpl* scroll_layer = scroller.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6620 | std::unique_ptr<LayerImpl> fixed = |
| 6621 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6622 | LayerImpl* fixed_layer = fixed.get(); |
| 6623 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6624 | container->test_properties()->is_container_for_fixed_position_layers = true; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6625 | |
| 6626 | LayerPositionConstraint constraint; |
| 6627 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6628 | fixed->test_properties()->position_constraint = constraint; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6629 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6630 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6631 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6632 | gfx::Transform container_transform; |
| 6633 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 6634 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 6635 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6636 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6637 | container->test_properties()->transform = container_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6638 | container->SetBounds(gfx::Size(40, 40)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6639 | container->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6640 | scroller->SetBounds(gfx::Size(30, 30)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6641 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6642 | fixed->SetBounds(gfx::Size(50, 50)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6643 | fixed->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6644 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6645 | scroller->test_properties()->AddChild(std::move(fixed)); |
| 6646 | container->test_properties()->AddChild(std::move(scroller)); |
| 6647 | root->test_properties()->AddChild(std::move(container)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6648 | root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr)); |
| 6649 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6650 | |
| 6651 | // Rounded to integers already. |
| 6652 | { |
| 6653 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6654 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6655 | |
| 6656 | LayerImplList render_surface_layer_list; |
| 6657 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6658 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6659 | root->layer_tree_impl() |
| 6660 | ->property_trees() |
| 6661 | ->transform_tree.set_source_to_parent_updates_allowed(false); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6662 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6663 | |
| 6664 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6665 | container_layer->draw_properties().screen_space_transform, |
| 6666 | fixed_layer->draw_properties().screen_space_transform); |
| 6667 | EXPECT_VECTOR_EQ( |
| 6668 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6669 | container_offset); |
| 6670 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6671 | .screen_space_transform.To2dTranslation(), |
| 6672 | container_offset - scroll_delta); |
| 6673 | } |
| 6674 | |
| 6675 | // Scroll delta requiring rounding. |
| 6676 | { |
| 6677 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6678 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6679 | |
| 6680 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 6681 | |
| 6682 | LayerImplList render_surface_layer_list; |
| 6683 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6684 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6685 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6686 | |
| 6687 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6688 | container_layer->draw_properties().screen_space_transform, |
| 6689 | fixed_layer->draw_properties().screen_space_transform); |
| 6690 | EXPECT_VECTOR_EQ( |
| 6691 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6692 | container_offset); |
| 6693 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6694 | .screen_space_transform.To2dTranslation(), |
| 6695 | container_offset - rounded_scroll_delta); |
| 6696 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6697 | |
| 6698 | // Scale is applied earlier in the tree. |
| 6699 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6700 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6701 | gfx::Transform scaled_container_transform = container_transform; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6702 | scaled_container_transform.Scale3d(2.0, 2.0, 1.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6703 | container_layer->test_properties()->transform = scaled_container_transform; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6704 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6705 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6706 | |
| 6707 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6708 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6709 | |
| 6710 | LayerImplList render_surface_layer_list; |
| 6711 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6712 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6713 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6714 | |
| 6715 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6716 | container_layer->draw_properties().screen_space_transform, |
| 6717 | fixed_layer->draw_properties().screen_space_transform); |
| 6718 | EXPECT_VECTOR_EQ( |
| 6719 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6720 | container_offset); |
| 6721 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6722 | container_layer->test_properties()->transform = container_transform; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6723 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6724 | } |
| 6725 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 6726 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6727 | ScrollSnappingWithAnimatedScreenSpaceTransform) { |
| 6728 | // This test verifies that a scrolling layer whose screen space transform is |
| 6729 | // animating doesn't get snapped to integer coordinates. |
| 6730 | // |
| 6731 | // + root |
| 6732 | // + animated layer |
| 6733 | // + surface |
| 6734 | // + container |
| 6735 | // + scroller |
| 6736 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6737 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6738 | LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>(); |
| 6739 | LayerImpl* surface = AddChild<LayerImpl>(animated_layer); |
| 6740 | LayerImpl* container = AddChild<LayerImpl>(surface); |
| 6741 | LayerImpl* scroller = AddChild<LayerImpl>(container); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6742 | |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6743 | gfx::Transform start_scale; |
| 6744 | start_scale.Scale(1.5f, 1.5f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6745 | |
| 6746 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6747 | animated_layer->test_properties()->transform = start_scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6748 | animated_layer->SetBounds(gfx::Size(50, 50)); |
| 6749 | surface->SetBounds(gfx::Size(50, 50)); |
| 6750 | surface->test_properties()->force_render_surface = true; |
| 6751 | container->SetBounds(gfx::Size(50, 50)); |
| 6752 | scroller->SetBounds(gfx::Size(100, 100)); |
| 6753 | scroller->SetScrollClipLayer(container->id()); |
| 6754 | scroller->SetDrawsContent(true); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6755 | |
| 6756 | gfx::Transform end_scale; |
| 6757 | end_scale.Scale(2.f, 2.f); |
| 6758 | TransformOperations start_operations; |
| 6759 | start_operations.AppendMatrix(start_scale); |
| 6760 | TransformOperations end_operations; |
| 6761 | end_operations.AppendMatrix(end_scale); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 6762 | SetElementIdsForTesting(); |
| 6763 | |
| 6764 | AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(), |
| 6765 | timeline_impl(), 1.0, |
| 6766 | start_operations, end_operations); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6767 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6768 | SetScrollOffsetDelta(scroller, scroll_delta); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6769 | |
| 6770 | ExecuteCalculateDrawProperties(root); |
| 6771 | |
| 6772 | gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); |
| 6773 | EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 6774 | scroller->DrawTransform().To2dTranslation()); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6775 | } |
| 6776 | |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 6777 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) { |
| 6778 | // This test verifies that a scrolling child of a scrolling layer doesn't get |
| 6779 | // snapped to integer coordinates. |
| 6780 | // |
| 6781 | // + root |
| 6782 | // + container |
| 6783 | // + scroller |
| 6784 | // + scroll_child |
| 6785 | // |
| 6786 | scoped_refptr<Layer> root = Layer::Create(); |
| 6787 | scoped_refptr<Layer> container = Layer::Create(); |
| 6788 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6789 | scoped_refptr<Layer> scroll_child = Layer::Create(); |
| 6790 | root->AddChild(container); |
| 6791 | root->AddChild(scroll_child); |
| 6792 | container->AddChild(scroller); |
| 6793 | host()->SetRootLayer(root); |
| 6794 | |
| 6795 | scroller->SetScrollClipLayerId(container->id()); |
| 6796 | scroll_child->SetScrollParent(scroller.get()); |
| 6797 | |
| 6798 | gfx::Transform rotate; |
| 6799 | rotate.RotateAboutYAxis(30); |
| 6800 | root->SetBounds(gfx::Size(50, 50)); |
| 6801 | container->SetBounds(gfx::Size(50, 50)); |
| 6802 | scroller->SetBounds(gfx::Size(100, 100)); |
| 6803 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 6804 | scroll_child->SetBounds(gfx::Size(10, 10)); |
| 6805 | scroll_child->SetTransform(rotate); |
| 6806 | |
| 6807 | ExecuteCalculateDrawProperties(root.get()); |
| 6808 | |
| 6809 | host()->host_impl()->CreatePendingTree(); |
| 6810 | host()->CommitAndCreatePendingTree(); |
| 6811 | host()->host_impl()->ActivateSyncTree(); |
| 6812 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6813 | |
| 6814 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6815 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6816 | LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id()); |
| 6817 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 6818 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 6819 | |
| 6820 | ExecuteCalculateDrawProperties(root_impl); |
| 6821 | |
| 6822 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 6823 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 6824 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6825 | |
| 6826 | gfx::Transform expected_scroll_child_screen_space_transform; |
| 6827 | expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); |
| 6828 | expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); |
| 6829 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, |
| 6830 | scroll_child_impl->ScreenSpaceTransform()); |
| 6831 | } |
| 6832 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6833 | TEST_F(LayerTreeHostCommonTest, StickyPositionTop) { |
| 6834 | scoped_refptr<Layer> root = Layer::Create(); |
| 6835 | scoped_refptr<Layer> container = Layer::Create(); |
| 6836 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6837 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6838 | root->AddChild(container); |
| 6839 | container->AddChild(scroller); |
| 6840 | scroller->AddChild(sticky_pos); |
| 6841 | host()->SetRootLayer(root); |
| 6842 | scroller->SetScrollClipLayerId(container->id()); |
| 6843 | |
| 6844 | LayerStickyPositionConstraint sticky_position; |
| 6845 | sticky_position.is_sticky = true; |
| 6846 | sticky_position.is_anchored_top = true; |
| 6847 | sticky_position.top_offset = 10.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 6848 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6849 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6850 | gfx::Rect(10, 20, 10, 10); |
| 6851 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6852 | gfx::Rect(0, 0, 50, 50); |
| 6853 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6854 | |
| 6855 | root->SetBounds(gfx::Size(100, 100)); |
| 6856 | container->SetBounds(gfx::Size(100, 100)); |
| 6857 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 6858 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6859 | sticky_pos->SetPosition(gfx::PointF(10, 20)); |
| 6860 | |
| 6861 | ExecuteCalculateDrawProperties(root.get()); |
| 6862 | host()->host_impl()->CreatePendingTree(); |
| 6863 | host()->CommitAndCreatePendingTree(); |
| 6864 | host()->host_impl()->ActivateSyncTree(); |
| 6865 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6866 | |
| 6867 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6868 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6869 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6870 | |
| 6871 | ExecuteCalculateDrawProperties(root_impl); |
| 6872 | EXPECT_VECTOR2DF_EQ( |
| 6873 | gfx::Vector2dF(10.f, 20.f), |
| 6874 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6875 | |
| 6876 | // Scroll less than sticking point, sticky element should move with scroll as |
| 6877 | // we haven't gotten to the initial sticky item location yet. |
| 6878 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 6879 | ExecuteCalculateDrawProperties(root_impl); |
| 6880 | EXPECT_VECTOR2DF_EQ( |
| 6881 | gfx::Vector2dF(5.f, 15.f), |
| 6882 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6883 | |
| 6884 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 6885 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 6886 | ExecuteCalculateDrawProperties(root_impl); |
| 6887 | EXPECT_VECTOR2DF_EQ( |
| 6888 | gfx::Vector2dF(-5.f, 10.f), |
| 6889 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6890 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f)); |
| 6891 | ExecuteCalculateDrawProperties(root_impl); |
| 6892 | EXPECT_VECTOR2DF_EQ( |
| 6893 | gfx::Vector2dF(-5.f, 10.f), |
| 6894 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6895 | |
| 6896 | // Scroll past the end of the sticky container (note: this element does not |
| 6897 | // have its own layer as it does not need to be composited). |
| 6898 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); |
| 6899 | ExecuteCalculateDrawProperties(root_impl); |
| 6900 | EXPECT_VECTOR2DF_EQ( |
| 6901 | gfx::Vector2dF(-5.f, -10.f), |
| 6902 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6903 | } |
| 6904 | |
flackr | dc5dfbe | 2016-10-24 21:43:38 | [diff] [blame] | 6905 | TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) { |
| 6906 | scoped_refptr<Layer> root = Layer::Create(); |
| 6907 | scoped_refptr<Layer> container = Layer::Create(); |
| 6908 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6909 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6910 | root->AddChild(container); |
| 6911 | container->AddChild(scroller); |
| 6912 | scroller->AddChild(sticky_pos); |
| 6913 | host()->SetRootLayer(root); |
| 6914 | scroller->SetScrollClipLayerId(container->id()); |
| 6915 | |
| 6916 | LayerStickyPositionConstraint sticky_position; |
| 6917 | sticky_position.is_sticky = true; |
| 6918 | sticky_position.is_anchored_bottom = true; |
| 6919 | sticky_position.bottom_offset = 10.0f; |
| 6920 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 200); |
| 6921 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6922 | gfx::Rect(0, 200, 10, 10); |
| 6923 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6924 | gfx::Rect(0, 0, 100, 500); |
| 6925 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6926 | |
| 6927 | root->SetBounds(gfx::Size(100, 100)); |
| 6928 | container->SetBounds(gfx::Size(100, 100)); |
| 6929 | scroller->SetBounds(gfx::Size(100, 1000)); |
| 6930 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6931 | sticky_pos->SetPosition(gfx::PointF(0, 200)); |
| 6932 | |
| 6933 | ExecuteCalculateDrawProperties(root.get()); |
| 6934 | host()->host_impl()->CreatePendingTree(); |
| 6935 | host()->CommitAndCreatePendingTree(); |
| 6936 | host()->host_impl()->ActivateSyncTree(); |
| 6937 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6938 | |
| 6939 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6940 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6941 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6942 | |
| 6943 | ExecuteCalculateDrawProperties(root_impl); |
| 6944 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.8f)); |
| 6945 | ExecuteCalculateDrawProperties(root_impl); |
| 6946 | EXPECT_VECTOR2DF_EQ( |
| 6947 | gfx::Vector2dF(0.f, 80.f), |
| 6948 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6949 | } |
| 6950 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6951 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) { |
| 6952 | scoped_refptr<Layer> root = Layer::Create(); |
| 6953 | scoped_refptr<Layer> container = Layer::Create(); |
| 6954 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6955 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6956 | root->AddChild(container); |
| 6957 | container->AddChild(scroller); |
| 6958 | scroller->AddChild(sticky_pos); |
| 6959 | host()->SetRootLayer(root); |
| 6960 | scroller->SetScrollClipLayerId(container->id()); |
| 6961 | |
| 6962 | LayerStickyPositionConstraint sticky_position; |
| 6963 | sticky_position.is_sticky = true; |
| 6964 | sticky_position.is_anchored_bottom = true; |
| 6965 | sticky_position.bottom_offset = 10.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 6966 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6967 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6968 | gfx::Rect(0, 150, 10, 10); |
| 6969 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6970 | gfx::Rect(0, 100, 50, 50); |
| 6971 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6972 | |
| 6973 | root->SetBounds(gfx::Size(100, 100)); |
| 6974 | container->SetBounds(gfx::Size(100, 100)); |
| 6975 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 6976 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6977 | sticky_pos->SetPosition(gfx::PointF(0, 150)); |
| 6978 | |
| 6979 | ExecuteCalculateDrawProperties(root.get()); |
| 6980 | host()->host_impl()->CreatePendingTree(); |
| 6981 | host()->CommitAndCreatePendingTree(); |
| 6982 | host()->host_impl()->ActivateSyncTree(); |
| 6983 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6984 | |
| 6985 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6986 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6987 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6988 | |
| 6989 | // Initially the sticky element is moved up to the top of the container. |
| 6990 | ExecuteCalculateDrawProperties(root_impl); |
| 6991 | EXPECT_VECTOR2DF_EQ( |
| 6992 | gfx::Vector2dF(0.f, 100.f), |
| 6993 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6994 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 6995 | ExecuteCalculateDrawProperties(root_impl); |
| 6996 | EXPECT_VECTOR2DF_EQ( |
| 6997 | gfx::Vector2dF(0.f, 95.f), |
| 6998 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6999 | |
| 7000 | // Once we get past the top of the container it moves to be aligned 10px |
| 7001 | // up from the the bottom of the scroller. |
| 7002 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7003 | ExecuteCalculateDrawProperties(root_impl); |
| 7004 | EXPECT_VECTOR2DF_EQ( |
| 7005 | gfx::Vector2dF(0.f, 80.f), |
| 7006 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7007 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7008 | ExecuteCalculateDrawProperties(root_impl); |
| 7009 | EXPECT_VECTOR2DF_EQ( |
| 7010 | gfx::Vector2dF(0.f, 80.f), |
| 7011 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7012 | |
| 7013 | // Once we scroll past its initial location, it sticks there. |
| 7014 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f)); |
| 7015 | ExecuteCalculateDrawProperties(root_impl); |
| 7016 | EXPECT_VECTOR2DF_EQ( |
| 7017 | gfx::Vector2dF(0.f, 0.f), |
| 7018 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7019 | } |
| 7020 | |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7021 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) { |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7022 | scoped_refptr<Layer> root = Layer::Create(); |
| 7023 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7024 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7025 | root->AddChild(scroller); |
| 7026 | scroller->AddChild(sticky_pos); |
| 7027 | host()->SetRootLayer(root); |
| 7028 | scroller->SetScrollClipLayerId(root->id()); |
| 7029 | host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller, |
| 7030 | nullptr); |
| 7031 | |
| 7032 | LayerStickyPositionConstraint sticky_position; |
| 7033 | sticky_position.is_sticky = true; |
| 7034 | sticky_position.is_anchored_bottom = true; |
| 7035 | sticky_position.bottom_offset = 10.0f; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7036 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7037 | sticky_position.scroll_container_relative_sticky_box_rect = |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7038 | gfx::Rect(0, 70, 10, 10); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7039 | sticky_position.scroll_container_relative_containing_block_rect = |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7040 | gfx::Rect(0, 60, 100, 100); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7041 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7042 | |
| 7043 | root->SetBounds(gfx::Size(100, 100)); |
| 7044 | scroller->SetBounds(gfx::Size(100, 1000)); |
| 7045 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7046 | sticky_pos->SetPosition(gfx::PointF(0, 70)); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7047 | |
| 7048 | ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7049 | scroller.get(), nullptr); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7050 | host()->CommitAndCreateLayerImplTree(); |
| 7051 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7052 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7053 | ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id()); |
| 7054 | |
| 7055 | LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
| 7056 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7057 | |
| 7058 | // Initially the sticky element is moved to the bottom of the container. |
| 7059 | EXPECT_VECTOR2DF_EQ( |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7060 | gfx::Vector2dF(0.f, 70.f), |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7061 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7062 | |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7063 | // We start to hide the toolbar, but not far enough that the sticky element |
| 7064 | // should be moved up yet. |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7065 | root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7066 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7067 | nullptr); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7068 | EXPECT_VECTOR2DF_EQ( |
| 7069 | gfx::Vector2dF(0.f, 70.f), |
| 7070 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7071 | |
| 7072 | // On hiding more of the toolbar the sticky element starts to stick. |
| 7073 | root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
| 7074 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7075 | nullptr); |
| 7076 | EXPECT_VECTOR2DF_EQ( |
| 7077 | gfx::Vector2dF(0.f, 60.f), |
| 7078 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7079 | |
| 7080 | // On hiding more the sticky element stops moving as it has reached its |
| 7081 | // limit. |
| 7082 | root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
| 7083 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7084 | nullptr); |
| 7085 | EXPECT_VECTOR2DF_EQ( |
| 7086 | gfx::Vector2dF(0.f, 60.f), |
| 7087 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7088 | } |
| 7089 | |
| 7090 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) { |
| 7091 | scoped_refptr<Layer> root = Layer::Create(); |
| 7092 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7093 | scoped_refptr<Layer> outer_clip = Layer::Create(); |
| 7094 | scoped_refptr<Layer> outer_viewport = Layer::Create(); |
| 7095 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7096 | root->AddChild(scroller); |
| 7097 | scroller->AddChild(outer_clip); |
| 7098 | outer_clip->AddChild(outer_viewport); |
| 7099 | outer_viewport->AddChild(sticky_pos); |
| 7100 | host()->SetRootLayer(root); |
| 7101 | scroller->SetScrollClipLayerId(root->id()); |
| 7102 | outer_viewport->SetScrollClipLayerId(outer_clip->id()); |
| 7103 | host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller, |
| 7104 | outer_viewport); |
| 7105 | |
| 7106 | LayerStickyPositionConstraint sticky_position; |
| 7107 | sticky_position.is_sticky = true; |
| 7108 | sticky_position.is_anchored_bottom = true; |
| 7109 | sticky_position.bottom_offset = 10.0f; |
| 7110 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); |
| 7111 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7112 | gfx::Rect(0, 70, 10, 10); |
| 7113 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7114 | gfx::Rect(0, 60, 100, 100); |
| 7115 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7116 | |
| 7117 | root->SetBounds(gfx::Size(100, 100)); |
| 7118 | scroller->SetBounds(gfx::Size(100, 1000)); |
| 7119 | outer_clip->SetBounds(gfx::Size(100, 100)); |
| 7120 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7121 | sticky_pos->SetPosition(gfx::PointF(0, 70)); |
| 7122 | |
| 7123 | ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), |
| 7124 | scroller.get(), outer_viewport.get()); |
| 7125 | host()->CommitAndCreateLayerImplTree(); |
| 7126 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7127 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7128 | ASSERT_EQ(outer_viewport->id(), |
| 7129 | layer_tree_impl->OuterViewportScrollLayer()->id()); |
| 7130 | |
| 7131 | LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
| 7132 | LayerImpl* outer_scroll = layer_tree_impl->OuterViewportScrollLayer(); |
| 7133 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7134 | LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id()); |
| 7135 | |
| 7136 | // Initially the sticky element is moved to the bottom of the container. |
| 7137 | EXPECT_VECTOR2DF_EQ( |
| 7138 | gfx::Vector2dF(0.f, 70.f), |
| 7139 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7140 | |
| 7141 | // We start to hide the toolbar, but not far enough that the sticky element |
| 7142 | // should be moved up yet. |
| 7143 | outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
| 7144 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7145 | outer_scroll); |
| 7146 | EXPECT_VECTOR2DF_EQ( |
| 7147 | gfx::Vector2dF(0.f, 70.f), |
| 7148 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7149 | |
| 7150 | // On hiding more of the toolbar the sticky element starts to stick. |
| 7151 | outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
| 7152 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7153 | outer_scroll); |
| 7154 | |
| 7155 | // On hiding more the sticky element stops moving as it has reached its |
| 7156 | // limit. |
| 7157 | EXPECT_VECTOR2DF_EQ( |
| 7158 | gfx::Vector2dF(0.f, 60.f), |
| 7159 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7160 | |
| 7161 | outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
| 7162 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7163 | outer_scroll); |
| 7164 | |
| 7165 | EXPECT_VECTOR2DF_EQ( |
| 7166 | gfx::Vector2dF(0.f, 60.f), |
| 7167 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7168 | } |
| 7169 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7170 | TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { |
| 7171 | scoped_refptr<Layer> root = Layer::Create(); |
| 7172 | scoped_refptr<Layer> container = Layer::Create(); |
| 7173 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7174 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7175 | root->AddChild(container); |
| 7176 | container->AddChild(scroller); |
| 7177 | scroller->AddChild(sticky_pos); |
| 7178 | host()->SetRootLayer(root); |
| 7179 | scroller->SetScrollClipLayerId(container->id()); |
| 7180 | |
| 7181 | LayerStickyPositionConstraint sticky_position; |
| 7182 | sticky_position.is_sticky = true; |
| 7183 | sticky_position.is_anchored_left = true; |
| 7184 | sticky_position.is_anchored_right = true; |
| 7185 | sticky_position.left_offset = 10.f; |
| 7186 | sticky_position.right_offset = 10.f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7187 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(145, 0); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7188 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7189 | gfx::Rect(145, 0, 10, 10); |
| 7190 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7191 | gfx::Rect(100, 0, 100, 100); |
| 7192 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7193 | |
| 7194 | root->SetBounds(gfx::Size(100, 100)); |
| 7195 | container->SetBounds(gfx::Size(100, 100)); |
| 7196 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7197 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7198 | sticky_pos->SetPosition(gfx::PointF(145, 0)); |
| 7199 | |
| 7200 | ExecuteCalculateDrawProperties(root.get()); |
| 7201 | host()->host_impl()->CreatePendingTree(); |
| 7202 | host()->CommitAndCreatePendingTree(); |
| 7203 | host()->host_impl()->ActivateSyncTree(); |
| 7204 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7205 | |
| 7206 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7207 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7208 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7209 | |
| 7210 | // Initially the sticky element is moved the leftmost side of the container. |
| 7211 | ExecuteCalculateDrawProperties(root_impl); |
| 7212 | EXPECT_VECTOR2DF_EQ( |
| 7213 | gfx::Vector2dF(100.f, 0.f), |
| 7214 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7215 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f)); |
| 7216 | ExecuteCalculateDrawProperties(root_impl); |
| 7217 | EXPECT_VECTOR2DF_EQ( |
| 7218 | gfx::Vector2dF(95.f, 0.f), |
| 7219 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7220 | |
| 7221 | // Once we get past the left side of the container it moves to be aligned 10px |
| 7222 | // up from the the right of the scroller. |
| 7223 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f)); |
| 7224 | ExecuteCalculateDrawProperties(root_impl); |
| 7225 | EXPECT_VECTOR2DF_EQ( |
| 7226 | gfx::Vector2dF(80.f, 0.f), |
| 7227 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7228 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f)); |
| 7229 | ExecuteCalculateDrawProperties(root_impl); |
| 7230 | EXPECT_VECTOR2DF_EQ( |
| 7231 | gfx::Vector2dF(80.f, 0.f), |
| 7232 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7233 | |
| 7234 | // When we get to the sticky element's original position we stop sticking |
| 7235 | // to the right. |
| 7236 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f)); |
| 7237 | ExecuteCalculateDrawProperties(root_impl); |
| 7238 | EXPECT_VECTOR2DF_EQ( |
| 7239 | gfx::Vector2dF(50.f, 0.f), |
| 7240 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7241 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f)); |
| 7242 | ExecuteCalculateDrawProperties(root_impl); |
| 7243 | EXPECT_VECTOR2DF_EQ( |
| 7244 | gfx::Vector2dF(40.f, 0.f), |
| 7245 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7246 | |
| 7247 | // The element starts sticking to the left once we scroll far enough. |
| 7248 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f)); |
| 7249 | ExecuteCalculateDrawProperties(root_impl); |
| 7250 | EXPECT_VECTOR2DF_EQ( |
| 7251 | gfx::Vector2dF(10.f, 0.f), |
| 7252 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7253 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f)); |
| 7254 | ExecuteCalculateDrawProperties(root_impl); |
| 7255 | EXPECT_VECTOR2DF_EQ( |
| 7256 | gfx::Vector2dF(10.f, 0.f), |
| 7257 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7258 | |
| 7259 | // Finally it stops sticking when it hits the right side of the container. |
| 7260 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f)); |
| 7261 | ExecuteCalculateDrawProperties(root_impl); |
| 7262 | EXPECT_VECTOR2DF_EQ( |
| 7263 | gfx::Vector2dF(0.f, 0.f), |
| 7264 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7265 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f)); |
| 7266 | ExecuteCalculateDrawProperties(root_impl); |
| 7267 | EXPECT_VECTOR2DF_EQ( |
| 7268 | gfx::Vector2dF(-5.f, 0.f), |
| 7269 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7270 | } |
| 7271 | |
| 7272 | // This test ensures that the compositor sticky position code correctly accounts |
| 7273 | // for the element having been given a position from the main thread sticky |
| 7274 | // position code. |
| 7275 | TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) { |
| 7276 | scoped_refptr<Layer> root = Layer::Create(); |
| 7277 | scoped_refptr<Layer> container = Layer::Create(); |
| 7278 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7279 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7280 | root->AddChild(container); |
| 7281 | container->AddChild(scroller); |
| 7282 | scroller->AddChild(sticky_pos); |
| 7283 | host()->SetRootLayer(root); |
| 7284 | scroller->SetScrollClipLayerId(container->id()); |
| 7285 | |
| 7286 | LayerStickyPositionConstraint sticky_position; |
| 7287 | sticky_position.is_sticky = true; |
| 7288 | sticky_position.is_anchored_top = true; |
| 7289 | sticky_position.top_offset = 10.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7290 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7291 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7292 | gfx::Rect(10, 20, 10, 10); |
| 7293 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7294 | gfx::Rect(0, 0, 50, 50); |
| 7295 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7296 | |
| 7297 | root->SetBounds(gfx::Size(100, 100)); |
| 7298 | container->SetBounds(gfx::Size(100, 100)); |
| 7299 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7300 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7301 | sticky_pos->SetPosition(gfx::PointF(10, 20)); |
| 7302 | |
| 7303 | ExecuteCalculateDrawProperties(root.get()); |
| 7304 | host()->host_impl()->CreatePendingTree(); |
| 7305 | host()->CommitAndCreatePendingTree(); |
| 7306 | host()->host_impl()->ActivateSyncTree(); |
| 7307 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7308 | |
| 7309 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7310 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7311 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7312 | |
| 7313 | ExecuteCalculateDrawProperties(root_impl); |
| 7314 | EXPECT_VECTOR2DF_EQ( |
| 7315 | gfx::Vector2dF(10.f, 20.f), |
| 7316 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7317 | |
| 7318 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7319 | // we haven't gotten to the initial sticky item location yet. |
| 7320 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 7321 | ExecuteCalculateDrawProperties(root_impl); |
| 7322 | EXPECT_VECTOR2DF_EQ( |
| 7323 | gfx::Vector2dF(5.f, 15.f), |
| 7324 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7325 | |
| 7326 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 7327 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 7328 | ExecuteCalculateDrawProperties(root_impl); |
| 7329 | EXPECT_VECTOR2DF_EQ( |
| 7330 | gfx::Vector2dF(-5.f, 10.f), |
| 7331 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7332 | |
| 7333 | // Now the main thread commits the new position of the sticky element. |
| 7334 | scroller->SetScrollOffset(gfx::ScrollOffset(15, 15)); |
| 7335 | sticky_pos->SetPosition(gfx::PointF(10, 25)); |
| 7336 | ExecuteCalculateDrawProperties(root.get()); |
| 7337 | host()->host_impl()->CreatePendingTree(); |
| 7338 | host()->CommitAndCreatePendingTree(); |
| 7339 | host()->host_impl()->ActivateSyncTree(); |
| 7340 | layer_tree_impl = host()->host_impl()->active_tree(); |
| 7341 | root_impl = layer_tree_impl->LayerById(root->id()); |
| 7342 | scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7343 | sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7344 | |
| 7345 | // The element should still be where it was before. We reset the delta to |
| 7346 | // (0, 0) because we have synced a scroll offset of (15, 15) from the main |
| 7347 | // thread. |
| 7348 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); |
| 7349 | ExecuteCalculateDrawProperties(root_impl); |
| 7350 | EXPECT_VECTOR2DF_EQ( |
| 7351 | gfx::Vector2dF(-5.f, 10.f), |
| 7352 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7353 | |
| 7354 | // And if we scroll a little further it remains there. |
| 7355 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); |
| 7356 | ExecuteCalculateDrawProperties(root_impl); |
| 7357 | EXPECT_VECTOR2DF_EQ( |
| 7358 | gfx::Vector2dF(-5.f, 10.f), |
| 7359 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7360 | } |
| 7361 | |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7362 | // This tests the main thread updates with a composited sticky container. In |
| 7363 | // this case the position received from main is relative to the container but |
| 7364 | // the constraint rects are relative to the ancestor scroller. |
| 7365 | TEST_F(LayerTreeHostCommonTest, StickyPositionCompositedContainer) { |
| 7366 | scoped_refptr<Layer> root = Layer::Create(); |
| 7367 | scoped_refptr<Layer> container = Layer::Create(); |
| 7368 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7369 | scoped_refptr<Layer> sticky_container = Layer::Create(); |
| 7370 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7371 | root->AddChild(container); |
| 7372 | container->AddChild(scroller); |
| 7373 | scroller->AddChild(sticky_container); |
| 7374 | sticky_container->AddChild(sticky_pos); |
| 7375 | host()->SetRootLayer(root); |
| 7376 | scroller->SetScrollClipLayerId(container->id()); |
| 7377 | |
| 7378 | LayerStickyPositionConstraint sticky_position; |
| 7379 | sticky_position.is_sticky = true; |
| 7380 | sticky_position.is_anchored_top = true; |
| 7381 | sticky_position.top_offset = 10.0f; |
| 7382 | // The sticky position layer is only offset by (0, 10) from its parent |
| 7383 | // layer, this position is used to determine the offset applied by the main |
| 7384 | // thread. |
| 7385 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 10); |
| 7386 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7387 | gfx::Rect(20, 30, 10, 10); |
| 7388 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7389 | gfx::Rect(20, 20, 30, 30); |
| 7390 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7391 | |
| 7392 | root->SetBounds(gfx::Size(100, 100)); |
| 7393 | container->SetBounds(gfx::Size(100, 100)); |
| 7394 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7395 | sticky_container->SetPosition(gfx::PointF(20, 20)); |
| 7396 | sticky_container->SetBounds(gfx::Size(30, 30)); |
| 7397 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7398 | sticky_pos->SetPosition(gfx::PointF(0, 10)); |
| 7399 | |
| 7400 | ExecuteCalculateDrawProperties(root.get()); |
| 7401 | host()->host_impl()->CreatePendingTree(); |
| 7402 | host()->CommitAndCreatePendingTree(); |
| 7403 | host()->host_impl()->ActivateSyncTree(); |
| 7404 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7405 | |
| 7406 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7407 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7408 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7409 | |
| 7410 | ExecuteCalculateDrawProperties(root_impl); |
| 7411 | EXPECT_VECTOR2DF_EQ( |
| 7412 | gfx::Vector2dF(20.f, 30.f), |
| 7413 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7414 | |
| 7415 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7416 | // we haven't gotten to the initial sticky item location yet. |
| 7417 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 7418 | ExecuteCalculateDrawProperties(root_impl); |
| 7419 | EXPECT_VECTOR2DF_EQ( |
| 7420 | gfx::Vector2dF(20.f, 25.f), |
| 7421 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7422 | |
| 7423 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 7424 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7425 | ExecuteCalculateDrawProperties(root_impl); |
| 7426 | EXPECT_VECTOR2DF_EQ( |
| 7427 | gfx::Vector2dF(20.f, 10.f), |
| 7428 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7429 | |
| 7430 | // Now the main thread commits the new position of the sticky element. |
| 7431 | scroller->SetScrollOffset(gfx::ScrollOffset(0, 25)); |
| 7432 | sticky_pos->SetPosition(gfx::PointF(0, 15)); |
| 7433 | ExecuteCalculateDrawProperties(root.get()); |
| 7434 | host()->host_impl()->CreatePendingTree(); |
| 7435 | host()->CommitAndCreatePendingTree(); |
| 7436 | host()->host_impl()->ActivateSyncTree(); |
| 7437 | layer_tree_impl = host()->host_impl()->active_tree(); |
| 7438 | root_impl = layer_tree_impl->LayerById(root->id()); |
| 7439 | scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7440 | sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7441 | |
| 7442 | // The element should still be where it was before. We reset the delta to |
| 7443 | // (0, 0) because we have synced a scroll offset of (0, 25) from the main |
| 7444 | // thread. |
| 7445 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); |
| 7446 | ExecuteCalculateDrawProperties(root_impl); |
| 7447 | EXPECT_VECTOR2DF_EQ( |
| 7448 | gfx::Vector2dF(20.f, 10.f), |
| 7449 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7450 | |
| 7451 | // And if we scroll a little further it remains there. |
| 7452 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 7453 | ExecuteCalculateDrawProperties(root_impl); |
| 7454 | EXPECT_VECTOR2DF_EQ( |
| 7455 | gfx::Vector2dF(20.f, 10.f), |
| 7456 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7457 | |
| 7458 | // And hits the bottom of the container. |
| 7459 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); |
| 7460 | ExecuteCalculateDrawProperties(root_impl); |
| 7461 | EXPECT_VECTOR2DF_EQ( |
| 7462 | gfx::Vector2dF(20.f, 5.f), |
| 7463 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7464 | } |
| 7465 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7466 | // A transform on a sticky element should not affect its sticky position. |
| 7467 | TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) { |
| 7468 | scoped_refptr<Layer> root = Layer::Create(); |
| 7469 | scoped_refptr<Layer> container = Layer::Create(); |
| 7470 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7471 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7472 | root->AddChild(container); |
| 7473 | container->AddChild(scroller); |
| 7474 | scroller->AddChild(sticky_pos); |
| 7475 | host()->SetRootLayer(root); |
| 7476 | scroller->SetScrollClipLayerId(container->id()); |
| 7477 | gfx::Transform t; |
| 7478 | t.Scale(2, 2); |
| 7479 | sticky_pos->SetTransform(t); |
| 7480 | |
| 7481 | LayerStickyPositionConstraint sticky_position; |
| 7482 | sticky_position.is_sticky = true; |
| 7483 | sticky_position.is_anchored_top = true; |
| 7484 | sticky_position.top_offset = 0.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7485 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7486 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7487 | gfx::Rect(0, 20, 10, 10); |
| 7488 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7489 | gfx::Rect(0, 0, 50, 50); |
| 7490 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7491 | |
| 7492 | root->SetBounds(gfx::Size(100, 100)); |
| 7493 | container->SetBounds(gfx::Size(100, 100)); |
| 7494 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7495 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7496 | sticky_pos->SetPosition(gfx::PointF(0, 20)); |
| 7497 | |
| 7498 | ExecuteCalculateDrawProperties(root.get()); |
| 7499 | host()->host_impl()->CreatePendingTree(); |
| 7500 | host()->CommitAndCreatePendingTree(); |
| 7501 | host()->host_impl()->ActivateSyncTree(); |
| 7502 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7503 | |
| 7504 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7505 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7506 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7507 | |
| 7508 | ExecuteCalculateDrawProperties(root_impl); |
| 7509 | EXPECT_VECTOR2DF_EQ( |
| 7510 | gfx::Vector2dF(0.f, 20.f), |
| 7511 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7512 | |
| 7513 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7514 | // we haven't gotten to the initial sticky item location yet. |
| 7515 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f)); |
| 7516 | ExecuteCalculateDrawProperties(root_impl); |
| 7517 | EXPECT_VECTOR2DF_EQ( |
| 7518 | gfx::Vector2dF(0.f, 5.f), |
| 7519 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7520 | |
| 7521 | // Scroll past the sticking point, the box is positioned at the scroller |
| 7522 | // edge. |
| 7523 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7524 | ExecuteCalculateDrawProperties(root_impl); |
| 7525 | EXPECT_VECTOR2DF_EQ( |
| 7526 | gfx::Vector2dF(0.f, 0.f), |
| 7527 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7528 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7529 | ExecuteCalculateDrawProperties(root_impl); |
| 7530 | EXPECT_VECTOR2DF_EQ( |
| 7531 | gfx::Vector2dF(0.f, 0.f), |
| 7532 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7533 | |
| 7534 | // Scroll past the end of the sticky container. |
| 7535 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); |
| 7536 | ExecuteCalculateDrawProperties(root_impl); |
| 7537 | EXPECT_VECTOR2DF_EQ( |
| 7538 | gfx::Vector2dF(0.f, -10.f), |
| 7539 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7540 | } |
| 7541 | |
| 7542 | // Tests that a transform does not affect the sticking points. The sticky |
| 7543 | // element will however move relative to the viewport due to its transform. |
| 7544 | TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) { |
| 7545 | scoped_refptr<Layer> root = Layer::Create(); |
| 7546 | scoped_refptr<Layer> container = Layer::Create(); |
| 7547 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7548 | scoped_refptr<Layer> sticky_container = Layer::Create(); |
| 7549 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7550 | root->AddChild(container); |
| 7551 | container->AddChild(scroller); |
| 7552 | scroller->AddChild(sticky_container); |
| 7553 | sticky_container->AddChild(sticky_pos); |
| 7554 | host()->SetRootLayer(root); |
| 7555 | scroller->SetScrollClipLayerId(container->id()); |
| 7556 | gfx::Transform t; |
| 7557 | t.Scale(2, 2); |
| 7558 | sticky_container->SetTransform(t); |
| 7559 | |
| 7560 | LayerStickyPositionConstraint sticky_position; |
| 7561 | sticky_position.is_sticky = true; |
| 7562 | sticky_position.is_anchored_top = true; |
| 7563 | sticky_position.top_offset = 0.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7564 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7565 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7566 | gfx::Rect(0, 20, 10, 10); |
| 7567 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7568 | gfx::Rect(0, 0, 50, 50); |
| 7569 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7570 | |
| 7571 | root->SetBounds(gfx::Size(100, 100)); |
| 7572 | container->SetBounds(gfx::Size(100, 100)); |
| 7573 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7574 | sticky_container->SetBounds(gfx::Size(50, 50)); |
| 7575 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7576 | sticky_pos->SetPosition(gfx::PointF(0, 20)); |
| 7577 | |
| 7578 | ExecuteCalculateDrawProperties(root.get()); |
| 7579 | host()->host_impl()->CreatePendingTree(); |
| 7580 | host()->CommitAndCreatePendingTree(); |
| 7581 | host()->host_impl()->ActivateSyncTree(); |
| 7582 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7583 | |
| 7584 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7585 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7586 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7587 | |
| 7588 | ExecuteCalculateDrawProperties(root_impl); |
| 7589 | EXPECT_VECTOR2DF_EQ( |
| 7590 | gfx::Vector2dF(0.f, 40.f), |
| 7591 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7592 | |
| 7593 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7594 | // we haven't gotten to the initial sticky item location yet. |
| 7595 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f)); |
| 7596 | ExecuteCalculateDrawProperties(root_impl); |
| 7597 | EXPECT_VECTOR2DF_EQ( |
| 7598 | gfx::Vector2dF(0.f, 25.f), |
| 7599 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7600 | |
| 7601 | // Scroll past the sticking point, the box is positioned at the scroller |
| 7602 | // edge but is also scaled by its container so it begins to move down. |
| 7603 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7604 | ExecuteCalculateDrawProperties(root_impl); |
| 7605 | EXPECT_VECTOR2DF_EQ( |
| 7606 | gfx::Vector2dF(0.f, 25.f), |
| 7607 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7608 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7609 | ExecuteCalculateDrawProperties(root_impl); |
| 7610 | EXPECT_VECTOR2DF_EQ( |
| 7611 | gfx::Vector2dF(0.f, 30.f), |
| 7612 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7613 | |
| 7614 | // Scroll past the end of the sticky container. |
| 7615 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); |
| 7616 | ExecuteCalculateDrawProperties(root_impl); |
| 7617 | EXPECT_VECTOR2DF_EQ( |
| 7618 | gfx::Vector2dF(0.f, 30.f), |
| 7619 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7620 | } |
| 7621 | |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7622 | TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { |
| 7623 | scoped_refptr<Layer> root = Layer::Create(); |
| 7624 | scoped_refptr<Layer> container = Layer::Create(); |
| 7625 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7626 | scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 7627 | |
| 7628 | scroller->SetIsContainerForFixedPositionLayers(true); |
| 7629 | root->AddChild(container); |
| 7630 | container->AddChild(scroller); |
| 7631 | scroller->AddChild(fixed_pos); |
| 7632 | host()->SetRootLayer(root); |
| 7633 | |
| 7634 | LayerPositionConstraint fixed_position; |
| 7635 | fixed_position.set_is_fixed_position(true); |
| 7636 | scroller->SetScrollClipLayerId(container->id()); |
| 7637 | fixed_pos->SetPositionConstraint(fixed_position); |
| 7638 | |
| 7639 | root->SetBounds(gfx::Size(50, 50)); |
| 7640 | container->SetBounds(gfx::Size(50, 50)); |
| 7641 | scroller->SetBounds(gfx::Size(50, 50)); |
| 7642 | fixed_pos->SetBounds(gfx::Size(50, 50)); |
| 7643 | |
| 7644 | gfx::Transform rotate; |
| 7645 | rotate.RotateAboutXAxis(20); |
| 7646 | container->SetTransform(rotate); |
| 7647 | |
| 7648 | ExecuteCalculateDrawProperties(root.get()); |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 7649 | TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree; |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7650 | gfx::Transform transform; |
| 7651 | tree.ComputeTranslation(fixed_pos->transform_tree_index(), |
| 7652 | container->transform_tree_index(), &transform); |
| 7653 | EXPECT_TRUE(transform.IsIdentity()); |
| 7654 | } |
| 7655 | |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 7656 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) { |
| 7657 | // This test verifies that a fixed pos child of a scrolling layer doesn't get |
| 7658 | // snapped to integer coordinates. |
| 7659 | // |
| 7660 | // + root |
| 7661 | // + container |
| 7662 | // + scroller |
| 7663 | // + fixed_pos |
| 7664 | // |
| 7665 | scoped_refptr<Layer> root = Layer::Create(); |
| 7666 | scoped_refptr<Layer> container = Layer::Create(); |
| 7667 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7668 | scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 7669 | |
| 7670 | scroller->SetIsContainerForFixedPositionLayers(true); |
| 7671 | |
| 7672 | root->AddChild(container); |
| 7673 | container->AddChild(scroller); |
| 7674 | scroller->AddChild(fixed_pos); |
| 7675 | host()->SetRootLayer(root); |
| 7676 | |
| 7677 | LayerPositionConstraint fixed_position; |
| 7678 | fixed_position.set_is_fixed_position(true); |
| 7679 | scroller->SetScrollClipLayerId(container->id()); |
| 7680 | fixed_pos->SetPositionConstraint(fixed_position); |
| 7681 | |
| 7682 | root->SetBounds(gfx::Size(50, 50)); |
| 7683 | container->SetBounds(gfx::Size(50, 50)); |
| 7684 | scroller->SetBounds(gfx::Size(100, 100)); |
| 7685 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 7686 | fixed_pos->SetBounds(gfx::Size(10, 10)); |
| 7687 | |
| 7688 | ExecuteCalculateDrawProperties(root.get()); |
| 7689 | |
| 7690 | host()->host_impl()->CreatePendingTree(); |
| 7691 | host()->CommitAndCreatePendingTree(); |
| 7692 | host()->host_impl()->ActivateSyncTree(); |
| 7693 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7694 | |
| 7695 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7696 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7697 | LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id()); |
| 7698 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 7699 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 7700 | |
| 7701 | ExecuteCalculateDrawProperties(root_impl); |
| 7702 | |
| 7703 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 7704 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 7705 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7706 | |
| 7707 | gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f, |
| 7708 | 10.3f); |
| 7709 | EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation, |
| 7710 | fixed_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7711 | } |
| 7712 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7713 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7714 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7715 | static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7716 | LayerTreeImpl* tree_impl, |
| 7717 | int id) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7718 | return base::WrapUnique( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7719 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7720 | } |
| 7721 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7722 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7723 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7724 | private: |
| 7725 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7726 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7727 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7728 | SetDrawsContent(true); |
| 7729 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7730 | }; |
| 7731 | |
| 7732 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7733 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7734 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 7735 | LayerTreeSettings settings = host()->GetSettings(); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7736 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7737 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 7738 | &task_graph_runner); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7739 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7740 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7741 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7742 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7743 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7744 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7745 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7746 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7747 | |
| 7748 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7749 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7750 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7751 | AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get(); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7752 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7753 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 7754 | parent->SetBounds(gfx::Size(1, 2)); |
| 7755 | child->SetBounds(gfx::Size(1, 2)); |
| 7756 | grand_child->SetBounds(gfx::Size(1, 2)); |
| 7757 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7758 | child->test_properties()->AddChild(std::move(grand_child)); |
| 7759 | parent->test_properties()->AddChild(std::move(child)); |
| 7760 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7761 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 7762 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7763 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7764 | |
| 7765 | // No layers have animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7766 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7767 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7768 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7769 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7770 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7771 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7772 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7773 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7774 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7775 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7776 | TransformOperations translation; |
| 7777 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7778 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7779 | scoped_refptr<AnimationTimeline> timeline; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7780 | timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7781 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7782 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7783 | host_impl.active_tree()->SetElementIdsForTesting(); |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7784 | |
| 7785 | scoped_refptr<AnimationPlayer> grand_parent_player = |
| 7786 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7787 | timeline->AttachPlayer(grand_parent_player); |
| 7788 | grand_parent_player->AttachElement(grand_parent_raw->element_id()); |
| 7789 | |
| 7790 | scoped_refptr<AnimationPlayer> parent_player = |
| 7791 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7792 | timeline->AttachPlayer(parent_player); |
| 7793 | parent_player->AttachElement(parent_raw->element_id()); |
| 7794 | |
| 7795 | scoped_refptr<AnimationPlayer> child_player = |
| 7796 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7797 | timeline->AttachPlayer(child_player); |
| 7798 | child_player->AttachElement(child_raw->element_id()); |
| 7799 | |
| 7800 | scoped_refptr<AnimationPlayer> grand_child_player = |
| 7801 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7802 | timeline->AttachPlayer(grand_child_player); |
| 7803 | grand_child_player->AttachElement(grand_child_raw->element_id()); |
| 7804 | |
| 7805 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7806 | translation); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7807 | |
| 7808 | // No layers have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7809 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7810 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7811 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7812 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7813 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7814 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7815 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7816 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7817 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7818 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7819 | TransformOperations scale; |
| 7820 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7821 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7822 | AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(), |
| 7823 | scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7824 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7825 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7826 | |
| 7827 | // Only |child| has a scale-affecting animation. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7828 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7829 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7830 | EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw)); |
| 7831 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7832 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7833 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7834 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7835 | EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw)); |
| 7836 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7837 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7838 | AddAnimatedTransformToPlayer(grand_parent_player.get(), 1.0, |
| 7839 | TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7840 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7841 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7842 | |
| 7843 | // |grand_parent| and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7844 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7845 | EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7846 | // We don't support combining animated scales from two nodes; 0.f means |
| 7847 | // that the maximum scale could not be computed. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7848 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7849 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7850 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7851 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7852 | EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw)); |
| 7853 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7854 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7855 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7856 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7857 | scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7858 | parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7859 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7860 | |
| 7861 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7862 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7863 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7864 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7865 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7866 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7867 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7868 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7869 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7870 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7871 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7872 | grand_parent_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 7873 | parent_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 7874 | child_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7875 | |
| 7876 | TransformOperations perspective; |
| 7877 | perspective.AppendPerspective(10.f); |
| 7878 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7879 | AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(), |
| 7880 | perspective); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7881 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7882 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7883 | |
| 7884 | // |child| has a scale-affecting animation but computing the maximum of this |
| 7885 | // animation is not supported. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7886 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7887 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7888 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7889 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7890 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7891 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7892 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7893 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7894 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7895 | |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 7896 | child_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 7897 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7898 | gfx::Transform scale_matrix; |
| 7899 | scale_matrix.Scale(1.f, 2.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7900 | grand_parent_raw->test_properties()->transform = scale_matrix; |
| 7901 | parent_raw->test_properties()->transform = scale_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7902 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7903 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7904 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7905 | scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7906 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7907 | |
| 7908 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 7909 | // animation with maximum scale 5.f. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7910 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7911 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 7912 | EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw)); |
| 7913 | EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7914 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7915 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7916 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 7917 | EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw)); |
| 7918 | EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7919 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7920 | gfx::Transform perspective_matrix; |
| 7921 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7922 | child_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7923 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7924 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7925 | |
| 7926 | // |child| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7927 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7928 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 7929 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7930 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7931 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7932 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7933 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 7934 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7935 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7936 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7937 | parent_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7938 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7939 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7940 | |
| 7941 | // |parent| and |child| have transforms that are neither translations nor |
| 7942 | // scales. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7943 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7944 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7945 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7946 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7947 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7948 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7949 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7950 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7951 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7952 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7953 | parent_raw->test_properties()->transform = gfx::Transform(); |
| 7954 | child_raw->test_properties()->transform = gfx::Transform(); |
| 7955 | grand_parent_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7956 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7957 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7958 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7959 | |
| 7960 | // |grand_parent| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7961 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7962 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7963 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7964 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7965 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7966 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7967 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7968 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7969 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7970 | } |
| 7971 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 7972 | static void GatherDrawnLayers(const LayerImplList* rsll, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7973 | std::set<LayerImpl*>* drawn_layers) { |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 7974 | for (LayerIterator it = LayerIterator::Begin(rsll), |
| 7975 | end = LayerIterator::End(rsll); |
| 7976 | it != end; ++it) { |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7977 | LayerImpl* layer = *it; |
| 7978 | if (it.represents_itself()) |
| 7979 | drawn_layers->insert(layer); |
| 7980 | |
| 7981 | if (!it.represents_contributing_render_surface()) |
| 7982 | continue; |
| 7983 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7984 | if (layer->render_surface()->MaskLayer()) |
| 7985 | drawn_layers->insert(layer->render_surface()->MaskLayer()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7986 | } |
| 7987 | } |
| 7988 | |
| 7989 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7990 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7991 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 7992 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7993 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7994 | std::unique_ptr<LayerImpl> grand_parent = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7995 | LayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7996 | std::unique_ptr<LayerImpl> parent = |
| 7997 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7998 | std::unique_ptr<LayerImpl> child = |
| 7999 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 8000 | std::unique_ptr<LayerImpl> grand_child1 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8001 | LayerImpl::Create(host_impl.active_tree(), 7); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8002 | std::unique_ptr<LayerImpl> grand_child2 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8003 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 8004 | |
| 8005 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 8006 | LayerImpl* parent_raw = parent.get(); |
| 8007 | LayerImpl* child_raw = child.get(); |
| 8008 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 8009 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 8010 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8011 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 8012 | parent->SetBounds(gfx::Size(1, 2)); |
| 8013 | child->SetBounds(gfx::Size(1, 2)); |
| 8014 | grand_child1->SetBounds(gfx::Size(1, 2)); |
| 8015 | grand_child2->SetBounds(gfx::Size(1, 2)); |
| 8016 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8017 | child->test_properties()->AddChild(std::move(grand_child1)); |
| 8018 | child->test_properties()->AddChild(std::move(grand_child2)); |
| 8019 | parent->test_properties()->AddChild(std::move(child)); |
| 8020 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8021 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8022 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8023 | // Start with nothing being drawn. |
| 8024 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8025 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8026 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8027 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8028 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 8029 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8030 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8031 | |
| 8032 | std::set<LayerImpl*> expected; |
| 8033 | std::set<LayerImpl*> actual; |
| 8034 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8035 | EXPECT_EQ(expected, actual); |
| 8036 | |
| 8037 | // If we force render surface, but none of the layers are in the layer list, |
| 8038 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8039 | grand_child1_raw->SetHasRenderSurface(true); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 8040 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8041 | |
| 8042 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8043 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8044 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8045 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8046 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 8047 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8048 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8049 | |
| 8050 | expected.clear(); |
| 8051 | actual.clear(); |
| 8052 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8053 | EXPECT_EQ(expected, actual); |
| 8054 | |
| 8055 | // However, if we say that this layer also draws content, it will appear in |
| 8056 | // RSLL. |
| 8057 | grand_child1_raw->SetDrawsContent(true); |
| 8058 | |
| 8059 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8060 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8061 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8062 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8063 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 8064 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8065 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8066 | |
| 8067 | expected.clear(); |
| 8068 | expected.insert(grand_child1_raw); |
| 8069 | |
| 8070 | actual.clear(); |
| 8071 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8072 | EXPECT_EQ(expected, actual); |
| 8073 | |
| 8074 | // Now child is forced to have a render surface, and one if its children draws |
| 8075 | // content. |
| 8076 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8077 | grand_child1_raw->SetHasRenderSurface(false); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 8078 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8079 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8080 | grand_child2_raw->SetDrawsContent(true); |
| 8081 | |
| 8082 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8083 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8084 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8085 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8086 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 8087 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8088 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8089 | |
| 8090 | expected.clear(); |
| 8091 | expected.insert(grand_child2_raw); |
| 8092 | |
| 8093 | actual.clear(); |
| 8094 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8095 | EXPECT_EQ(expected, actual); |
| 8096 | |
| 8097 | // Add a mask layer to child. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8098 | child_raw->test_properties()->SetMaskLayer( |
| 8099 | LayerImpl::Create(host_impl.active_tree(), 6)); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 8100 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8101 | |
| 8102 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8103 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8104 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8105 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8106 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8107 | EXPECT_TRUE(child_raw->test_properties() |
| 8108 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8109 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8110 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8111 | |
| 8112 | expected.clear(); |
| 8113 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8114 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8115 | |
| 8116 | expected.clear(); |
| 8117 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8118 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8119 | |
| 8120 | actual.clear(); |
| 8121 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8122 | EXPECT_EQ(expected, actual); |
| 8123 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8124 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8125 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8126 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8127 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8128 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8129 | EXPECT_TRUE(child_raw->test_properties() |
| 8130 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8131 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8132 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8133 | |
| 8134 | expected.clear(); |
| 8135 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8136 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8137 | |
| 8138 | actual.clear(); |
| 8139 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8140 | EXPECT_EQ(expected, actual); |
| 8141 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8142 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8143 | |
| 8144 | // With nothing drawing, we should have no layers. |
| 8145 | grand_child2_raw->SetDrawsContent(false); |
| 8146 | |
| 8147 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8148 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8149 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8150 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8151 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8152 | EXPECT_FALSE(child_raw->test_properties() |
| 8153 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8154 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8155 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8156 | |
| 8157 | expected.clear(); |
| 8158 | actual.clear(); |
| 8159 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8160 | EXPECT_EQ(expected, actual); |
| 8161 | |
| 8162 | // Child itself draws means that we should have the child and the mask in the |
| 8163 | // list. |
| 8164 | child_raw->SetDrawsContent(true); |
| 8165 | |
| 8166 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8167 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8168 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8169 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8170 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8171 | EXPECT_TRUE(child_raw->test_properties() |
| 8172 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8173 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8174 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8175 | |
| 8176 | expected.clear(); |
| 8177 | expected.insert(child_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8178 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8179 | actual.clear(); |
| 8180 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8181 | EXPECT_EQ(expected, actual); |
| 8182 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8183 | child_raw->test_properties()->SetMaskLayer(nullptr); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 8184 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8185 | |
| 8186 | // Now everyone's a member! |
| 8187 | grand_parent_raw->SetDrawsContent(true); |
| 8188 | parent_raw->SetDrawsContent(true); |
| 8189 | child_raw->SetDrawsContent(true); |
| 8190 | grand_child1_raw->SetDrawsContent(true); |
| 8191 | grand_child2_raw->SetDrawsContent(true); |
| 8192 | |
| 8193 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8194 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8195 | EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8196 | EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8197 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 8198 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8199 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8200 | |
| 8201 | expected.clear(); |
| 8202 | expected.insert(grand_parent_raw); |
| 8203 | expected.insert(parent_raw); |
| 8204 | expected.insert(child_raw); |
| 8205 | expected.insert(grand_child1_raw); |
| 8206 | expected.insert(grand_child2_raw); |
| 8207 | |
| 8208 | actual.clear(); |
| 8209 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8210 | EXPECT_EQ(expected, actual); |
| 8211 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8212 | |
| 8213 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8214 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8215 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8216 | LayerTreeSettings settings = host()->GetSettings(); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8217 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8218 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8219 | &task_graph_runner); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8220 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8221 | std::unique_ptr<LayerImpl> root = |
| 8222 | LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8223 | LayerImpl* root_layer = root.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8224 | std::unique_ptr<LayerImpl> child1 = |
| 8225 | LayerImpl::Create(host_impl.active_tree(), 2); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8226 | LayerImpl* child1_layer = child1.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8227 | std::unique_ptr<LayerImpl> child2 = |
| 8228 | LayerImpl::Create(host_impl.active_tree(), 3); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8229 | LayerImpl* child2_layer = child2.get(); |
| 8230 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8231 | gfx::Transform scale_transform_child1, scale_transform_child2; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8232 | scale_transform_child1.Scale(2, 3); |
| 8233 | scale_transform_child2.Scale(4, 5); |
| 8234 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8235 | root->SetBounds(gfx::Size(1, 1)); |
| 8236 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8237 | child1_layer->test_properties()->transform = scale_transform_child1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8238 | child1_layer->SetBounds(gfx::Size(1, 1)); |
| 8239 | child1_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8240 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8241 | child1_layer->test_properties()->SetMaskLayer( |
| 8242 | LayerImpl::Create(host_impl.active_tree(), 4)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8243 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8244 | root->test_properties()->AddChild(std::move(child1)); |
| 8245 | root->test_properties()->AddChild(std::move(child2)); |
| 8246 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8247 | host_impl.active_tree()->SetElementIdsForTesting(); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8248 | |
| 8249 | ExecuteCalculateDrawProperties(root_layer); |
| 8250 | |
| 8251 | TransformOperations scale; |
| 8252 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8253 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8254 | scoped_refptr<AnimationTimeline> timeline = |
| 8255 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8256 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8257 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8258 | child2_layer->test_properties()->transform = scale_transform_child2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8259 | child2_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 8260 | child2_layer->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8261 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 8262 | 1.0, TransformOperations(), scale); |
| 8263 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8264 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8265 | ExecuteCalculateDrawProperties(root_layer); |
| 8266 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8267 | EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale()); |
| 8268 | EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8269 | EXPECT_FLOAT_EQ( |
| 8270 | 3.f, |
| 8271 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8272 | EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8273 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8274 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8275 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8276 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8277 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8278 | // Changing page-scale would affect ideal_contents_scale and |
| 8279 | // maximum_animation_contents_scale. |
| 8280 | |
| 8281 | float page_scale_factor = 3.f; |
| 8282 | float device_scale_factor = 1.0f; |
| 8283 | std::vector<LayerImpl*> render_surface_layer_list; |
| 8284 | gfx::Size device_viewport_size = |
| 8285 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 8286 | root_layer->bounds().height() * device_scale_factor); |
| 8287 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8288 | root_layer, device_viewport_size, &render_surface_layer_list); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8289 | |
| 8290 | inputs.page_scale_factor = page_scale_factor; |
| 8291 | inputs.can_adjust_raster_scales = true; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 8292 | inputs.page_scale_layer = root_layer; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8293 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8294 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8295 | EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale()); |
| 8296 | EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8297 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8298 | 9.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8299 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8300 | EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8301 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8302 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8303 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8304 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8305 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8306 | // Changing device-scale would affect ideal_contents_scale and |
| 8307 | // maximum_animation_contents_scale. |
| 8308 | |
| 8309 | device_scale_factor = 4.0f; |
| 8310 | inputs.device_scale_factor = device_scale_factor; |
| 8311 | inputs.can_adjust_raster_scales = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8312 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8313 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8314 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8315 | EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale()); |
| 8316 | EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8317 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8318 | 36.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8319 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8320 | EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8321 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8322 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8323 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8324 | EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer)); |
| 8325 | } |
| 8326 | |
| 8327 | TEST_F(LayerTreeHostCommonTest, AnimationScales) { |
| 8328 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8329 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8330 | LayerTreeSettings settings = host()->GetSettings(); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8331 | settings.layer_transforms_should_scale_layer_contents = true; |
| 8332 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8333 | &task_graph_runner); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8334 | |
| 8335 | std::unique_ptr<LayerImpl> root = |
| 8336 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8337 | LayerImpl* root_layer = root.get(); |
| 8338 | std::unique_ptr<LayerImpl> child1 = |
| 8339 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8340 | LayerImpl* child1_layer = child1.get(); |
| 8341 | std::unique_ptr<LayerImpl> child2 = |
| 8342 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 8343 | LayerImpl* child2_layer = child2.get(); |
| 8344 | |
| 8345 | root->test_properties()->AddChild(std::move(child1)); |
| 8346 | child1_layer->test_properties()->AddChild(std::move(child2)); |
| 8347 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8348 | |
| 8349 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 8350 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8351 | gfx::Transform scale_transform_child1, scale_transform_child2; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8352 | scale_transform_child1.Scale(2, 3); |
| 8353 | scale_transform_child2.Scale(4, 5); |
| 8354 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8355 | root_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8356 | child1_layer->test_properties()->transform = scale_transform_child1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8357 | child1_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8358 | child2_layer->test_properties()->transform = scale_transform_child2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8359 | child2_layer->SetBounds(gfx::Size(1, 1)); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8360 | |
| 8361 | TransformOperations scale; |
| 8362 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8363 | |
| 8364 | scoped_refptr<AnimationTimeline> timeline = |
| 8365 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8366 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 8367 | |
| 8368 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 8369 | 1.0, TransformOperations(), scale); |
| 8370 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8371 | // Correctly computes animation scale when rebuilding property trees. |
| 8372 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8373 | ExecuteCalculateDrawProperties(root_layer); |
| 8374 | |
| 8375 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8376 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8377 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
| 8378 | |
| 8379 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 8380 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer)); |
| 8381 | EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer)); |
| 8382 | |
| 8383 | // Correctly updates animation scale when layer property changes. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8384 | child1_layer->test_properties()->transform = gfx::Transform(); |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 8385 | root_layer->layer_tree_impl() |
| 8386 | ->property_trees() |
| 8387 | ->transform_tree.OnTransformAnimated(gfx::Transform(), |
| 8388 | child1_layer->transform_tree_index(), |
| 8389 | root_layer->layer_tree_impl()); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8390 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false; |
| 8391 | ExecuteCalculateDrawProperties(root_layer); |
| 8392 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
| 8393 | EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer)); |
| 8394 | |
| 8395 | // Do not update animation scale if already updated. |
| 8396 | host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting( |
| 8397 | child2_layer->transform_tree_index(), 100.f, 100.f); |
| 8398 | EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer)); |
| 8399 | EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer)); |
| 8400 | } |
| 8401 | |
| 8402 | TEST_F(LayerTreeHostCommonTest, |
| 8403 | AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) { |
| 8404 | // Returns empty scale if layer_transforms_should_scale_layer_contents is |
| 8405 | // false. |
| 8406 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8407 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8408 | LayerTreeSettings settings = host()->GetSettings(); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8409 | settings.layer_transforms_should_scale_layer_contents = false; |
| 8410 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8411 | &task_graph_runner); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8412 | |
| 8413 | std::unique_ptr<LayerImpl> root = |
| 8414 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8415 | LayerImpl* root_layer = root.get(); |
| 8416 | std::unique_ptr<LayerImpl> child = |
| 8417 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8418 | LayerImpl* child_layer = child.get(); |
| 8419 | |
| 8420 | root->test_properties()->AddChild(std::move(child)); |
| 8421 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8422 | |
| 8423 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 8424 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8425 | gfx::Transform scale_transform_child; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8426 | scale_transform_child.Scale(4, 5); |
| 8427 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8428 | root_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8429 | child_layer->test_properties()->transform = scale_transform_child; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8430 | child_layer->SetBounds(gfx::Size(1, 1)); |
| 8431 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8432 | TransformOperations scale; |
| 8433 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8434 | |
| 8435 | scoped_refptr<AnimationTimeline> timeline = |
| 8436 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8437 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 8438 | |
| 8439 | AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline, |
| 8440 | 1.0, TransformOperations(), scale); |
| 8441 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8442 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8443 | ExecuteCalculateDrawProperties(root_layer); |
| 8444 | |
| 8445 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8446 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer)); |
| 8447 | |
| 8448 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 8449 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8450 | } |
| 8451 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8452 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8453 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8454 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 8455 | LayerImpl* content = AddChild<LayerImpl>(clip); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8456 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8457 | root->SetBounds(gfx::Size(768 / 2, 3000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8458 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8459 | clip->SetBounds(gfx::Size(768 / 2, 10000)); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8460 | clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8461 | content->SetBounds(gfx::Size(768 / 2, 10000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8462 | content->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8463 | content->test_properties()->force_render_surface = true; |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8464 | |
| 8465 | gfx::Size device_viewport_size(768, 582); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8466 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8467 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8468 | root, device_viewport_size, gfx::Transform(), |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8469 | &render_surface_layer_list_impl); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8470 | inputs.device_scale_factor = 2.f; |
| 8471 | inputs.page_scale_factor = 1.f; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 8472 | inputs.page_scale_layer = nullptr; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8473 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8474 | |
| 8475 | // Layers in the root render surface have their visible content rect clipped |
| 8476 | // by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8477 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8478 | |
| 8479 | // Layers drawing to a child render surface should still have their visible |
| 8480 | // content rect clipped by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8481 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8482 | } |
| 8483 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8484 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8485 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8486 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8487 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8488 | |
| 8489 | // Set two layers: the root layer clips it's child, |
| 8490 | // the child draws its content. |
| 8491 | |
| 8492 | gfx::Size root_size = gfx::Size(300, 500); |
| 8493 | |
| 8494 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8495 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8496 | |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 8497 | // Device viewport accomidated the root and the browser controls. |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8498 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8499 | |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 8500 | host_impl.SetViewportSize(device_viewport_size); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8501 | host_impl.active_tree()->SetRootLayerForTesting( |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8502 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8503 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8504 | LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8505 | root->SetBounds(root_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8506 | root->SetMasksToBounds(true); |
| 8507 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8508 | root->test_properties()->AddChild( |
| 8509 | LayerImpl::Create(host_impl.active_tree(), 2)); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8510 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 8511 | LayerImpl* sublayer = root->test_properties()->children[0]; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8512 | sublayer->SetBounds(sublayer_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8513 | sublayer->SetDrawsContent(true); |
| 8514 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8515 | host_impl.active_tree()->BuildPropertyTreesForTesting(); |
| 8516 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8517 | LayerImplList layer_impl_list; |
| 8518 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8519 | root, device_viewport_size, &layer_impl_list); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8520 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8521 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8522 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8523 | |
| 8524 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8525 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8526 | |
| 8527 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8528 | root_size.height() + 50); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8529 | EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8530 | } |
| 8531 | |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8532 | TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8533 | scoped_refptr<Layer> root = Layer::Create(); |
| 8534 | scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create(); |
| 8535 | scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); |
| 8536 | scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create(); |
| 8537 | scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8538 | |
| 8539 | root->AddChild(inner_viewport_container_layer); |
| 8540 | inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer); |
| 8541 | inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); |
| 8542 | outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); |
| 8543 | |
| 8544 | inner_viewport_scroll_layer->SetScrollClipLayerId( |
| 8545 | inner_viewport_container_layer->id()); |
| 8546 | outer_viewport_scroll_layer->SetScrollClipLayerId( |
| 8547 | outer_viewport_container_layer->id()); |
| 8548 | |
| 8549 | inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8550 | outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8551 | |
| 8552 | host()->SetRootLayer(root); |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 8553 | host()->GetLayerTree()->RegisterViewportLayers( |
| 8554 | nullptr, root, inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8555 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8556 | scoped_refptr<Layer> fixed_to_inner = Layer::Create(); |
| 8557 | scoped_refptr<Layer> fixed_to_outer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8558 | |
| 8559 | inner_viewport_scroll_layer->AddChild(fixed_to_inner); |
| 8560 | outer_viewport_scroll_layer->AddChild(fixed_to_outer); |
| 8561 | |
| 8562 | LayerPositionConstraint fixed_to_right; |
| 8563 | fixed_to_right.set_is_fixed_position(true); |
| 8564 | fixed_to_right.set_is_fixed_to_right_edge(true); |
| 8565 | |
| 8566 | fixed_to_inner->SetPositionConstraint(fixed_to_right); |
| 8567 | fixed_to_outer->SetPositionConstraint(fixed_to_right); |
| 8568 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8569 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8570 | |
| 8571 | TransformTree& transform_tree = host()->property_trees()->transform_tree; |
| 8572 | EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8573 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8574 | |
| 8575 | LayerPositionConstraint fixed_to_left; |
| 8576 | fixed_to_left.set_is_fixed_position(true); |
| 8577 | fixed_to_inner->SetPositionConstraint(fixed_to_left); |
| 8578 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8579 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8580 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8581 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8582 | |
| 8583 | fixed_to_outer->SetPositionConstraint(fixed_to_left); |
| 8584 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8585 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8586 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8587 | EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8588 | } |
| 8589 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8590 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8591 | host_impl()->CreatePendingTree(); |
| 8592 | std::unique_ptr<LayerImpl> pending_root = |
| 8593 | LayerImpl::Create(host_impl()->pending_tree(), 1); |
| 8594 | LayerImpl* root = pending_root.get(); |
| 8595 | host_impl()->pending_tree()->SetRootLayerForTesting(std::move(pending_root)); |
| 8596 | std::unique_ptr<LayerImpl> animated_ptr = |
| 8597 | LayerImpl::Create(host_impl()->pending_tree(), 2); |
| 8598 | LayerImpl* animated = animated_ptr.get(); |
| 8599 | root->test_properties()->AddChild(std::move(animated_ptr)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8600 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8601 | animated->SetDrawsContent(true); |
| 8602 | host_impl()->pending_tree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8603 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8604 | root->SetBounds(gfx::Size(100, 100)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8605 | root->SetMasksToBounds(true); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8606 | root->test_properties()->force_render_surface = true; |
| 8607 | animated->test_properties()->opacity = 0.f; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8608 | animated->SetBounds(gfx::Size(20, 20)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8609 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8610 | AddOpacityTransitionToElementWithPlayer( |
| 8611 | animated->element_id(), timeline_impl(), 10.0, 0.f, 1.f, false); |
| 8612 | animated->test_properties()->opacity_can_animate = true; |
| 8613 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8614 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8615 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8616 | EXPECT_FALSE(animated->visible_layer_rect().IsEmpty()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8617 | } |
| 8618 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8619 | TEST_F(LayerTreeHostCommonTest, |
| 8620 | VisibleContentRectForAnimatedLayerWithSingularTransform) { |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8621 | LayerImpl* root = root_layer_for_testing(); |
| 8622 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 8623 | LayerImpl* animated = AddChild<LayerImpl>(clip); |
| 8624 | LayerImpl* surface = AddChild<LayerImpl>(animated); |
| 8625 | LayerImpl* descendant_of_animation = AddChild<LayerImpl>(surface); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8626 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8627 | SetElementIdsForTesting(); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8628 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8629 | animated->SetDrawsContent(true); |
| 8630 | surface->SetDrawsContent(true); |
| 8631 | descendant_of_animation->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8632 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8633 | gfx::Transform uninvertible_matrix; |
| 8634 | uninvertible_matrix.Scale3d(6.f, 6.f, 0.f); |
| 8635 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8636 | root->SetBounds(gfx::Size(100, 100)); |
| 8637 | clip->SetBounds(gfx::Size(10, 10)); |
| 8638 | clip->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8639 | animated->test_properties()->transform = uninvertible_matrix; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8640 | animated->SetBounds(gfx::Size(120, 120)); |
| 8641 | surface->SetBounds(gfx::Size(100, 100)); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8642 | surface->test_properties()->force_render_surface = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8643 | descendant_of_animation->SetBounds(gfx::Size(200, 200)); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8644 | |
| 8645 | TransformOperations start_transform_operations; |
| 8646 | start_transform_operations.AppendMatrix(uninvertible_matrix); |
| 8647 | TransformOperations end_transform_operations; |
| 8648 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8649 | AddAnimatedTransformToElementWithPlayer( |
| 8650 | animated->element_id(), timeline_impl(), 10.0, start_transform_operations, |
| 8651 | end_transform_operations); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8652 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8653 | |
| 8654 | // The animated layer has a singular transform and maps to a non-empty rect in |
| 8655 | // clipped target space, so is treated as fully visible. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8656 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8657 | |
| 8658 | // The singular transform on |animated| is flattened when inherited by |
| 8659 | // |surface|, and this happens to make it invertible. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8660 | EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect()); |
| 8661 | EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8662 | |
| 8663 | gfx::Transform zero_matrix; |
| 8664 | zero_matrix.Scale3d(0.f, 0.f, 0.f); |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 8665 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 8666 | zero_matrix, animated->transform_tree_index(), root->layer_tree_impl()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8667 | // While computing visible rects by combining clips in screen space, we set |
| 8668 | // the entire layer as visible if the screen space transform is singular. This |
| 8669 | // is not always true when we combine clips in target space because if the |
| 8670 | // intersection of combined_clip in taret space with layer_rect projected to |
| 8671 | // target space is empty, we set it to an empty rect. |
| 8672 | bool skip_verify_visible_rect_calculations = true; |
| 8673 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
| 8674 | root, skip_verify_visible_rect_calculations); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8675 | |
| 8676 | // The animated layer maps to the empty rect in clipped target space, so is |
| 8677 | // treated as having an empty visible rect. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8678 | EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8679 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8680 | // The animated layer will be treated as fully visible when we combine clips |
| 8681 | // in screen space. |
| 8682 | gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic( |
| 8683 | root->layer_tree_impl()->property_trees(), animated); |
| 8684 | EXPECT_EQ(gfx::Rect(120, 120), visible_rect); |
| 8685 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8686 | // This time, flattening does not make |animated|'s transform invertible. This |
| 8687 | // means the clip cannot be projected into |surface|'s space, so we treat |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8688 | // |surface| and layers that draw into it as having empty visible rect. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8689 | EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect()); |
| 8690 | EXPECT_EQ(gfx::Rect(), descendant_of_animation->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8691 | } |
| 8692 | |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8693 | // Verify that having animated opacity but current opacity 1 still creates |
| 8694 | // a render surface. |
| 8695 | TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) { |
| 8696 | LayerImpl* root = root_layer_for_testing(); |
| 8697 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8698 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8699 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8700 | root->SetBounds(gfx::Size(50, 50)); |
| 8701 | child->SetBounds(gfx::Size(50, 50)); |
| 8702 | child->SetDrawsContent(true); |
| 8703 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8704 | grandchild->SetDrawsContent(true); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8705 | |
| 8706 | SetElementIdsForTesting(); |
| 8707 | AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8708 | 10.0, 1.f, 0.2f, false); |
| 8709 | ExecuteCalculateDrawProperties(root); |
| 8710 | |
| 8711 | EXPECT_EQ(1.f, child->Opacity()); |
| 8712 | EXPECT_TRUE(root->has_render_surface()); |
| 8713 | EXPECT_TRUE(child->has_render_surface()); |
| 8714 | EXPECT_FALSE(grandchild->has_render_surface()); |
| 8715 | } |
| 8716 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8717 | // Verify that having an animated filter (but no current filter, as these |
| 8718 | // are mutually exclusive) correctly creates a render surface. |
| 8719 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8720 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8721 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8722 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8723 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8724 | root->SetBounds(gfx::Size(50, 50)); |
| 8725 | child->SetBounds(gfx::Size(50, 50)); |
| 8726 | grandchild->SetBounds(gfx::Size(50, 50)); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8727 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8728 | SetElementIdsForTesting(); |
| 8729 | AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8730 | 10.0, 0.1f, 0.2f); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8731 | ExecuteCalculateDrawProperties(root); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8732 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8733 | EXPECT_TRUE(root->has_render_surface()); |
| 8734 | EXPECT_TRUE(child->has_render_surface()); |
| 8735 | EXPECT_FALSE(grandchild->has_render_surface()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8736 | |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 8737 | EXPECT_TRUE(root->render_surface()->Filters().IsEmpty()); |
| 8738 | EXPECT_TRUE(child->render_surface()->Filters().IsEmpty()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8739 | |
| 8740 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8741 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 8742 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8743 | } |
| 8744 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8745 | // Verify that having a filter animation with a delayed start time creates a |
| 8746 | // render surface. |
| 8747 | TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8748 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8749 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8750 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8751 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8752 | root->SetBounds(gfx::Size(50, 50)); |
| 8753 | child->SetBounds(gfx::Size(50, 50)); |
| 8754 | grandchild->SetBounds(gfx::Size(50, 50)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8755 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8756 | SetElementIdsForTesting(); |
| 8757 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8758 | std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8759 | KeyframedFilterAnimationCurve::Create()); |
| 8760 | FilterOperations start_filters; |
| 8761 | start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f)); |
| 8762 | FilterOperations end_filters; |
| 8763 | end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f)); |
| 8764 | curve->AddKeyframe( |
| 8765 | FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 8766 | curve->AddKeyframe(FilterKeyframe::Create( |
| 8767 | base::TimeDelta::FromMilliseconds(100), end_filters, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8768 | std::unique_ptr<Animation> animation = |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8769 | Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8770 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8771 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8772 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8773 | AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8774 | std::move(animation)); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8775 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8776 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8777 | EXPECT_TRUE(root->has_render_surface()); |
| 8778 | EXPECT_TRUE(child->has_render_surface()); |
| 8779 | EXPECT_FALSE(grandchild->has_render_surface()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8780 | |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 8781 | EXPECT_TRUE(root->render_surface()->Filters().IsEmpty()); |
| 8782 | EXPECT_TRUE(child->render_surface()->Filters().IsEmpty()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8783 | |
| 8784 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8785 | EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation()); |
| 8786 | EXPECT_FALSE(child->FilterIsAnimating()); |
| 8787 | EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation()); |
| 8788 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8789 | EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation()); |
| 8790 | } |
| 8791 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8792 | // Ensures that the property tree code accounts for offsets between fixed |
| 8793 | // position layers and their respective containers. |
| 8794 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8795 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8796 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8797 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8798 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8799 | root->SetBounds(gfx::Size(50, 50)); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8800 | root->SetMasksToBounds(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8801 | root->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8802 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 8803 | child->SetBounds(gfx::Size(50, 50)); |
| 8804 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 8805 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8806 | grandchild->SetDrawsContent(true); |
| 8807 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8808 | LayerPositionConstraint constraint; |
| 8809 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8810 | grandchild->test_properties()->position_constraint = constraint; |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8811 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8812 | ExecuteCalculateDrawProperties(root); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8813 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8814 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8815 | } |
| 8816 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8817 | // Ensures that the property tree code accounts for offsets between fixed |
| 8818 | // position containers and their transform tree parents, when a fixed position |
| 8819 | // layer's container is its layer tree parent, but this parent doesn't have its |
| 8820 | // own transform tree node. |
| 8821 | TEST_F(LayerTreeHostCommonTest, |
| 8822 | PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8823 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8824 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8825 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8826 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8827 | root->SetBounds(gfx::Size(50, 50)); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8828 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8829 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 8830 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 8831 | child->SetBounds(gfx::Size(50, 50)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8832 | child->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8833 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 8834 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8835 | grandchild->SetDrawsContent(true); |
| 8836 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8837 | LayerPositionConstraint constraint; |
| 8838 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8839 | grandchild->test_properties()->position_constraint = constraint; |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8840 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8841 | ExecuteCalculateDrawProperties(root); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8842 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8843 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8844 | } |
| 8845 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8846 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8847 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8848 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8849 | LayerImpl* fixed = AddChild<LayerImpl>(frame_clip); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8850 | gfx::Transform translate_z; |
| 8851 | translate_z.Translate3d(0, 0, 10); |
| 8852 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8853 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8854 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8855 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8856 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 8857 | frame_clip->SetBounds(gfx::Size(100, 100)); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8858 | frame_clip->SetMasksToBounds(true); |
| 8859 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8860 | fixed->SetBounds(gfx::Size(1000, 1000)); |
| 8861 | fixed->SetDrawsContent(true); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8862 | |
| 8863 | LayerPositionConstraint constraint; |
| 8864 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8865 | fixed->test_properties()->position_constraint = constraint; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8866 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8867 | ExecuteCalculateDrawProperties(root); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8868 | |
| 8869 | gfx::Rect expected(0, 0, 100, 100); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8870 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8871 | } |
| 8872 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8873 | TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8874 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8875 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8876 | LayerImpl* scroller = AddChild<LayerImpl>(frame_clip); |
| 8877 | LayerImpl* fixed = AddChild<LayerImpl>(scroller); |
| 8878 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8879 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8880 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8881 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 8882 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 8883 | frame_clip->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8884 | frame_clip->SetMasksToBounds(true); |
| 8885 | frame_clip->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8886 | scroller->SetBounds(gfx::Size(1000, 1000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8887 | scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100)); |
| 8888 | scroller->SetScrollClipLayer(frame_clip->id()); |
| 8889 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8890 | fixed->SetPosition(gfx::PointF(100, 100)); |
| 8891 | fixed->SetBounds(gfx::Size(50, 50)); |
| 8892 | fixed->SetMasksToBounds(true); |
| 8893 | fixed->SetDrawsContent(true); |
| 8894 | fixed->test_properties()->force_render_surface = true; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8895 | |
| 8896 | LayerPositionConstraint constraint; |
| 8897 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8898 | fixed->test_properties()->position_constraint = constraint; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8899 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8900 | ExecuteCalculateDrawProperties(root); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8901 | |
| 8902 | gfx::Rect expected(0, 0, 50, 50); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8903 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8904 | } |
| 8905 | |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8906 | TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) { |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8907 | gfx::Transform translate; |
| 8908 | gfx::Transform rotate; |
| 8909 | |
| 8910 | translate.Translate(10, 10); |
| 8911 | rotate.Rotate(45); |
| 8912 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8913 | scoped_refptr<Layer> root = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8914 | root->SetBounds(gfx::Size(800, 800)); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8915 | root->SetIsContainerForFixedPositionLayers(true); |
| 8916 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8917 | host()->SetRootLayer(root); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8918 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8919 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8920 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8921 | |
| 8922 | root->SetTransform(translate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8923 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8924 | |
| 8925 | root->SetTransform(rotate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8926 | EXPECT_TRUE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8927 | } |
| 8928 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8929 | TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8930 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8931 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8932 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8933 | gfx::Transform scale_matrix; |
| 8934 | scale_matrix.Scale(2.f, 2.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8935 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8936 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8937 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8938 | child->test_properties()->transform = scale_matrix; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8939 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8940 | child->SetDrawsContent(true); |
| 8941 | |
| 8942 | ExecuteCalculateDrawProperties(root); |
| 8943 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8944 | |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 8945 | child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8946 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8947 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8948 | ExecuteCalculateDrawProperties(root); |
| 8949 | EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8950 | } |
| 8951 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8952 | TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8953 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8954 | LayerImpl* scroll_parent = AddChild<LayerImpl>(root); |
| 8955 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8956 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8957 | gfx::Transform scale; |
| 8958 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8959 | |
| 8960 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8961 | scroll_child->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8962 | scroll_child->SetBounds(gfx::Size(40, 40)); |
| 8963 | scroll_child->SetDrawsContent(true); |
| 8964 | scroll_parent->SetBounds(gfx::Size(30, 30)); |
| 8965 | scroll_parent->SetDrawsContent(true); |
| 8966 | |
| 8967 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 8968 | scroll_parent->test_properties()->scroll_children = |
| 8969 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 8970 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8971 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8972 | ExecuteCalculateDrawProperties(root); |
| 8973 | EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8974 | |
| 8975 | scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8976 | scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
| 8977 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8978 | ExecuteCalculateDrawProperties(root); |
| 8979 | EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8980 | } |
| 8981 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8982 | static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8983 | |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8984 | TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) { |
| 8985 | // If the layer has a node in effect_tree, the return value of |
| 8986 | // num_copy_requests_in_target_subtree() must be equal to the actual number |
| 8987 | // of copy requests in the sub-layer_tree; Otherwise, the number is expected |
| 8988 | // to be the value of its nearest ancestor that owns an effect node and |
| 8989 | // greater than or equal to the actual number of copy requests in the |
| 8990 | // sub-layer_tree. |
| 8991 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8992 | scoped_refptr<Layer> root = Layer::Create(); |
| 8993 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 8994 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 8995 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 8996 | scoped_refptr<Layer> greatgrandchild = Layer::Create(); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8997 | |
| 8998 | root->AddChild(child1); |
| 8999 | root->AddChild(child2); |
| 9000 | child1->AddChild(grandchild); |
| 9001 | grandchild->AddChild(greatgrandchild); |
| 9002 | host()->SetRootLayer(root); |
| 9003 | |
| 9004 | child1->RequestCopyOfOutput( |
| 9005 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 9006 | greatgrandchild->RequestCopyOfOutput( |
| 9007 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 9008 | child2->SetOpacity(0.f); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9009 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9010 | |
| 9011 | EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2); |
| 9012 | EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2); |
| 9013 | EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0); |
| 9014 | EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2); |
| 9015 | EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1); |
| 9016 | } |
| 9017 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9018 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9019 | scoped_refptr<Layer> root = Layer::Create(); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 9020 | FakeContentLayerClient client; |
| 9021 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9022 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9023 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9024 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9025 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 9026 | scoped_refptr<FakePictureLayer> greatgrandchild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9027 | FakePictureLayer::Create(&client)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9028 | |
| 9029 | root->SetBounds(gfx::Size(100, 100)); |
| 9030 | child->SetBounds(gfx::Size(10, 10)); |
| 9031 | grandchild->SetBounds(gfx::Size(10, 10)); |
| 9032 | greatgrandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9033 | |
| 9034 | root->AddChild(child); |
| 9035 | child->AddChild(grandchild); |
| 9036 | grandchild->AddChild(greatgrandchild); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9037 | host()->SetRootLayer(root); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 9038 | host()->GetLayerTree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9039 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9040 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9041 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9042 | const LayerList* update_list = GetUpdateLayerList(); |
| 9043 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9044 | |
| 9045 | // Now we will reset the visible rect from property trees for the grandchild, |
| 9046 | // and we will configure |child| in several ways that should force the subtree |
| 9047 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 9048 | // remain empty. |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9049 | gfx::Transform singular; |
| 9050 | singular.matrix().set(0, 0, 0); |
| 9051 | |
| 9052 | child->SetTransform(singular); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9053 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9054 | update_list = GetUpdateLayerList(); |
| 9055 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9056 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9057 | |
| 9058 | child->SetHideLayerAndSubtree(true); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9059 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9060 | update_list = GetUpdateLayerList(); |
| 9061 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9062 | child->SetHideLayerAndSubtree(false); |
| 9063 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9064 | gfx::Transform zero_z_scale; |
| 9065 | zero_z_scale.Scale3d(1, 1, 0); |
| 9066 | child->SetTransform(zero_z_scale); |
| 9067 | |
| 9068 | // Add a transform animation with a start delay. Now, even though |child| has |
| 9069 | // a singular transform, the subtree should still get processed. |
| 9070 | int animation_id = 0; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9071 | std::unique_ptr<Animation> animation = Animation::Create( |
| 9072 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 9073 | animation_id, 1, TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 9074 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9075 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9076 | AddAnimationToElementWithPlayer(child->element_id(), timeline(), |
| 9077 | std::move(animation)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9078 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9079 | update_list = GetUpdateLayerList(); |
| 9080 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9081 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9082 | RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(), |
| 9083 | animation_id); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9084 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9085 | child->SetOpacity(0.f); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9086 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9087 | update_list = GetUpdateLayerList(); |
| 9088 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9089 | |
| 9090 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 9091 | // |greatgrandchild| in several ways that should force the subtree to be |
| 9092 | // processed anyhow. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9093 | grandchild->RequestCopyOfOutput( |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9094 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9095 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9096 | update_list = GetUpdateLayerList(); |
| 9097 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9098 | |
| 9099 | // Add an opacity animation with a start delay. |
| 9100 | animation_id = 1; |
| 9101 | animation = Animation::Create( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9102 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 9103 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 9104 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9105 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9106 | AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(), |
| 9107 | std::move(animation)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9108 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9109 | update_list = GetUpdateLayerList(); |
| 9110 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9111 | } |
| 9112 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9113 | TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 9114 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 9115 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 9116 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9117 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9118 | std::unique_ptr<LayerImpl> root = |
| 9119 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 9120 | std::unique_ptr<LayerImpl> child = |
| 9121 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 9122 | std::unique_ptr<LayerImpl> grandchild = |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9123 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 9124 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9125 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 9126 | FakePictureLayerImpl::Create(host_impl.active_tree(), 4)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9127 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9128 | root->SetBounds(gfx::Size(100, 100)); |
| 9129 | child->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9130 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9131 | grandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9132 | grandchild->SetDrawsContent(true); |
| 9133 | greatgrandchild->SetDrawsContent(true); |
| 9134 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 9135 | LayerImpl* root_ptr = root.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9136 | LayerImpl* child_ptr = child.get(); |
| 9137 | LayerImpl* grandchild_ptr = grandchild.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9138 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9139 | child->test_properties()->AddChild(std::move(grandchild)); |
| 9140 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9141 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9142 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9143 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 9144 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9145 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9146 | // ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9147 | // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9148 | |
| 9149 | // Now we will reset the visible rect from property trees for the grandchild, |
| 9150 | // and we will configure |child| in several ways that should force the subtree |
| 9151 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 9152 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9153 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9154 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9155 | gfx::Transform singular; |
| 9156 | singular.matrix().set(0, 0, 0); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9157 | // This line is used to make the results of skipping and not skipping layers |
| 9158 | // different. |
| 9159 | singular.matrix().set(0, 1, 1); |
| 9160 | |
| 9161 | gfx::Transform rotate; |
| 9162 | rotate.Rotate(90); |
| 9163 | |
| 9164 | gfx::Transform rotate_back_and_translate; |
| 9165 | rotate_back_and_translate.RotateAboutYAxis(180); |
| 9166 | rotate_back_and_translate.Translate(-10, 0); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9167 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9168 | child_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9169 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9170 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9171 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9172 | child_ptr->test_properties()->transform = gfx::Transform(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9173 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9174 | child_ptr->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9175 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9176 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9177 | child_ptr->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9178 | |
jaydasika | b5bc1a2 | 2016-08-24 02:59:05 | [diff] [blame] | 9179 | child_ptr->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 9180 | 0.f, child_ptr->effect_tree_index(), child_ptr->layer_tree_impl()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9181 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9182 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9183 | child_ptr->test_properties()->opacity = 1.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9184 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9185 | root_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9186 | // Force transform tree to have a node for child, so that ancestor's |
| 9187 | // invertible transform can be tested. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9188 | child_ptr->test_properties()->transform = rotate; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9189 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9190 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9191 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9192 | root_ptr->test_properties()->transform = gfx::Transform(); |
| 9193 | child_ptr->test_properties()->transform = gfx::Transform(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9194 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9195 | root_ptr->test_properties()->opacity = 0.f; |
| 9196 | child_ptr->test_properties()->opacity = 0.7f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9197 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9198 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9199 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9200 | root_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9201 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9202 | child_ptr->test_properties()->opacity = 0.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9203 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 9204 | // |greatgrandchild| in several ways that should force the subtree to be |
| 9205 | // processed anyhow. |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 9206 | grandchild_ptr->test_properties()->copy_requests.push_back( |
| 9207 | CopyOutputRequest::CreateEmptyRequest()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 9208 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9209 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9210 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 9211 | |
| 9212 | host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests(); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9213 | child_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9214 | |
| 9215 | // A double sided render surface with backface visible should not be skipped |
| 9216 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9217 | child_ptr->SetHasRenderSurface(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9218 | child_ptr->test_properties()->double_sided = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9219 | child_ptr->test_properties()->transform = rotate_back_and_translate; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9220 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9221 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9222 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9223 | child_ptr->test_properties()->transform = gfx::Transform(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9224 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9225 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9226 | KeyframedTransformAnimationCurve::Create()); |
| 9227 | TransformOperations start; |
| 9228 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 9229 | gfx::Transform transform; |
| 9230 | transform.Scale3d(1.0, 2.0, 3.0); |
| 9231 | TransformOperations operation; |
| 9232 | operation.AppendMatrix(transform); |
| 9233 | curve->AddKeyframe( |
| 9234 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 9235 | curve->AddKeyframe(TransformKeyframe::Create( |
| 9236 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9237 | std::unique_ptr<Animation> transform_animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9238 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 9239 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9240 | host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(), |
| 9241 | player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 9242 | player->AddAnimation(std::move(transform_animation)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9243 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9244 | child_ptr->SetScrollClipLayer(root_ptr->id()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9245 | root_ptr->test_properties()->transform = singular; |
| 9246 | child_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9247 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9248 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9249 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9250 | |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9251 | host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(), |
| 9252 | player.get()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9253 | } |
| 9254 | |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9255 | TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9256 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9257 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 9258 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 9259 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9260 | SetElementIdsForTesting(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9261 | |
| 9262 | gfx::Transform singular; |
| 9263 | singular.matrix().set(0, 0, 0); |
| 9264 | singular.matrix().set(0, 1, 1); |
| 9265 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9266 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9267 | child->test_properties()->transform = singular; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9268 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9269 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9270 | grand_child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9271 | grand_child->SetDrawsContent(true); |
| 9272 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 9273 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9274 | KeyframedTransformAnimationCurve::Create()); |
| 9275 | TransformOperations start; |
| 9276 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 9277 | gfx::Transform transform; |
| 9278 | transform.Scale3d(1.0, 2.0, 3.0); |
| 9279 | TransformOperations operation; |
| 9280 | operation.AppendMatrix(transform); |
| 9281 | curve->AddKeyframe( |
| 9282 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 9283 | curve->AddKeyframe(TransformKeyframe::Create( |
| 9284 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 9285 | std::unique_ptr<Animation> transform_animation( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9286 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 9287 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9288 | host_impl()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9289 | grand_child->element_id(), player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 9290 | player->AddAnimation(std::move(transform_animation)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9291 | |
| 9292 | ExecuteCalculateDrawProperties(root); |
| 9293 | EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect()); |
| 9294 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
| 9295 | |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9296 | host_impl()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9297 | grand_child->element_id(), player.get()); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9298 | } |
| 9299 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9300 | TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { |
| 9301 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9302 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 9303 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9304 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9305 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9306 | std::unique_ptr<LayerImpl> root = |
| 9307 | LayerImpl::Create(host_impl.pending_tree(), 1); |
| 9308 | std::unique_ptr<LayerImpl> child = |
| 9309 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 9310 | std::unique_ptr<LayerImpl> grandchild = |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9311 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 9312 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9313 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9314 | FakePictureLayerImpl::Create(host_impl.pending_tree(), 4)); |
| 9315 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9316 | root->SetBounds(gfx::Size(100, 100)); |
| 9317 | child->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9318 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9319 | grandchild->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9320 | grandchild->SetDrawsContent(true); |
| 9321 | greatgrandchild->SetDrawsContent(true); |
| 9322 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9323 | LayerImpl* root_ptr = root.get(); |
| 9324 | LayerImpl* grandchild_ptr = grandchild.get(); |
| 9325 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9326 | child->test_properties()->AddChild(std::move(grandchild)); |
| 9327 | root->test_properties()->AddChild(std::move(child)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9328 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9329 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9330 | host_impl.pending_tree()->SetElementIdsForTesting(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9331 | |
| 9332 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9333 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9334 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9335 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9336 | std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9337 | KeyframedFloatAnimationCurve::Create()); |
loyso | 1e4e7ee | 2016-06-03 03:04:49 | [diff] [blame] | 9338 | std::unique_ptr<TimingFunction> func = |
| 9339 | CubicBezierTimingFunction::CreatePreset( |
| 9340 | CubicBezierTimingFunction::EaseType::EASE); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9341 | curve->AddKeyframe( |
| 9342 | FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func))); |
| 9343 | curve->AddKeyframe( |
| 9344 | FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9345 | std::unique_ptr<Animation> animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9346 | Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY)); |
| 9347 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9348 | host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(), |
| 9349 | player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 9350 | player->AddAnimation(std::move(animation)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9351 | root_ptr->test_properties()->opacity = 0.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9352 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9353 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9354 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9355 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9356 | |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9357 | host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(), |
| 9358 | player.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9359 | } |
| 9360 | |
| 9361 | TEST_F(LayerTreeHostCommonTest, SkippingLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9362 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9363 | LayerImpl* child = AddChild<LayerImpl>(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9364 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9365 | root->SetBounds(gfx::Size(100, 100)); |
| 9366 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9367 | child->SetDrawsContent(true); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9368 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9369 | ExecuteCalculateDrawProperties(root); |
| 9370 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9371 | child->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9372 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9373 | child->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9374 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9375 | ExecuteCalculateDrawProperties(root); |
| 9376 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9377 | child->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9378 | |
| 9379 | child->SetBounds(gfx::Size()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9380 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9381 | ExecuteCalculateDrawProperties(root); |
| 9382 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9383 | child->SetBounds(gfx::Size(10, 10)); |
| 9384 | |
| 9385 | gfx::Transform rotate; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9386 | child->test_properties()->double_sided = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9387 | rotate.RotateAboutXAxis(180.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9388 | child->test_properties()->transform = rotate; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9389 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9390 | ExecuteCalculateDrawProperties(root); |
| 9391 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9392 | child->test_properties()->double_sided = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9393 | child->test_properties()->transform = gfx::Transform(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9394 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9395 | child->test_properties()->opacity = 0.f; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9396 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9397 | ExecuteCalculateDrawProperties(root); |
| 9398 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9399 | } |
| 9400 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9401 | TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) { |
| 9402 | // Ensure that the treewalk in LayerTreeHostCommom:: |
| 9403 | // PreCalculateMetaInformation happens when its required. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9404 | scoped_refptr<Layer> root = Layer::Create(); |
| 9405 | scoped_refptr<Layer> parent = Layer::Create(); |
| 9406 | scoped_refptr<Layer> child = Layer::Create(); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9407 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9408 | root->SetBounds(gfx::Size(100, 100)); |
| 9409 | parent->SetBounds(gfx::Size(100, 100)); |
| 9410 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9411 | child->SetClipParent(root.get()); |
| 9412 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9413 | root->AddChild(parent); |
| 9414 | parent->AddChild(child); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9415 | host()->SetRootLayer(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9416 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9417 | child->RequestCopyOfOutput( |
| 9418 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9419 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9420 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9421 | EXPECT_EQ(parent->num_unclipped_descendants(), 1u); |
| 9422 | |
| 9423 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9424 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9425 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9426 | } |
| 9427 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9428 | TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) { |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9429 | scoped_refptr<Layer> root = Layer::Create(); |
| 9430 | root->SetBounds(gfx::Size(800, 800)); |
| 9431 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9432 | gfx::Transform translate_z; |
| 9433 | translate_z.Translate3d(0, 0, 10); |
| 9434 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9435 | scoped_refptr<Layer> child = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9436 | child->SetTransform(translate_z); |
| 9437 | child->SetBounds(gfx::Size(100, 100)); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9438 | |
| 9439 | root->AddChild(child); |
| 9440 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9441 | host()->SetRootLayer(root); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9442 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9443 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9444 | EXPECT_NE(-1, child->transform_tree_index()); |
| 9445 | |
| 9446 | child->RemoveFromParent(); |
| 9447 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9448 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9449 | EXPECT_EQ(-1, child->transform_tree_index()); |
| 9450 | } |
| 9451 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9452 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { |
| 9453 | // Ensure that a Clip Node is added when a render surface applies clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9454 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9455 | LayerImpl* significant_transform = AddChildToRoot<LayerImpl>(); |
| 9456 | LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform); |
| 9457 | LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree); |
| 9458 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9459 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9460 | // This transform should be a significant one so that a transform node is |
| 9461 | // formed for it. |
| 9462 | gfx::Transform transform1; |
| 9463 | transform1.RotateAboutYAxis(45); |
| 9464 | transform1.RotateAboutXAxis(30); |
| 9465 | // This transform should be a 3d transform as we want the render surface |
| 9466 | // to flatten the transform |
| 9467 | gfx::Transform transform2; |
| 9468 | transform2.Translate3d(10, 10, 10); |
| 9469 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9470 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9471 | significant_transform->test_properties()->transform = transform1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9472 | significant_transform->SetBounds(gfx::Size(30, 30)); |
| 9473 | layer_clips_subtree->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9474 | layer_clips_subtree->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9475 | layer_clips_subtree->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9476 | render_surface->test_properties()->transform = transform2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9477 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9478 | render_surface->test_properties()->force_render_surface = true; |
| 9479 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9480 | test_layer->SetDrawsContent(true); |
| 9481 | |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9482 | float device_scale_factor = 1.f; |
| 9483 | float page_scale_factor = 1.f; |
| 9484 | LayerImpl* page_scale_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 9485 | LayerImpl* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 9486 | LayerImpl* outer_viewport_scroll_layer = nullptr; |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9487 | // Visible rects computed by combining clips in target space and root space |
| 9488 | // don't match because of rotation transforms. So, we skip |
| 9489 | // verify_visible_rect_calculations. |
| 9490 | bool skip_verify_visible_rect_calculations = true; |
| 9491 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 9492 | page_scale_layer, inner_viewport_scroll_layer, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 9493 | outer_viewport_scroll_layer, |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9494 | skip_verify_visible_rect_calculations); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9495 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9496 | TransformTree& transform_tree = |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9497 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9498 | TransformNode* transform_node = |
| 9499 | transform_tree.Node(significant_transform->transform_tree_index()); |
| 9500 | EXPECT_EQ(transform_node->owner_id, significant_transform->id()); |
| 9501 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9502 | EXPECT_TRUE(root->has_render_surface()); |
| 9503 | EXPECT_FALSE(significant_transform->has_render_surface()); |
| 9504 | EXPECT_TRUE(layer_clips_subtree->has_render_surface()); |
| 9505 | EXPECT_TRUE(render_surface->has_render_surface()); |
| 9506 | EXPECT_FALSE(test_layer->has_render_surface()); |
| 9507 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9508 | ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9509 | ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); |
ajuma | 259f1e7 | 2016-10-24 16:25:38 | [diff] [blame] | 9510 | EXPECT_EQ(clip_node->clip_type, ClipNode::ClipType::NONE); |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 9511 | EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect()); |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9512 | |
| 9513 | // Also test the visible rects computed by combining clips in root space. |
| 9514 | gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic( |
| 9515 | root->layer_tree_impl()->property_trees(), test_layer); |
| 9516 | EXPECT_EQ(gfx::Rect(30, 20), visible_rect); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9517 | } |
| 9518 | |
| 9519 | TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 9520 | // Ensure that when parent clip node's transform is an ancestor of current |
| 9521 | // clip node's target, clip is 'projected' from parent space to current |
| 9522 | // target space and visible rects are calculated correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9523 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9524 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9525 | LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 9526 | LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| 9527 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9528 | gfx::Transform transform; |
| 9529 | transform.RotateAboutYAxis(45); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9530 | |
| 9531 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9532 | clip_layer->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9533 | clip_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9534 | clip_layer->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9535 | target_layer->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9536 | target_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9537 | target_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9538 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9539 | test_layer->SetDrawsContent(true); |
| 9540 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9541 | ExecuteCalculateDrawProperties(root); |
| 9542 | |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9543 | EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9544 | } |
| 9545 | |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9546 | TEST_F(LayerTreeHostCommonTest, |
| 9547 | RenderSurfaceWithUnclippedDescendantsClipsSubtree) { |
| 9548 | // Ensure clip rect is calculated correctly when render surface has unclipped |
| 9549 | // descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9550 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9551 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9552 | LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); |
| 9553 | LayerImpl* render_surface = |
| 9554 | AddChild<LayerImpl>(between_clip_parent_and_child); |
| 9555 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9556 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9557 | gfx::Transform translate; |
| 9558 | translate.Translate(2.0, 2.0); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9559 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9560 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9561 | clip_parent->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9562 | clip_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9563 | clip_parent->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9564 | between_clip_parent_and_child->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9565 | between_clip_parent_and_child->SetBounds(gfx::Size(30, 30)); |
| 9566 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9567 | render_surface->test_properties()->force_render_surface = true; |
| 9568 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9569 | test_layer->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9570 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9571 | render_surface->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9572 | clip_parent->test_properties()->clip_children = |
| 9573 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9574 | clip_parent->test_properties()->clip_children->insert(render_surface); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9575 | |
| 9576 | ExecuteCalculateDrawProperties(root); |
| 9577 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9578 | EXPECT_TRUE(test_layer->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 9579 | EXPECT_FALSE(test_layer->render_target()->is_clipped()); |
weiliangc | 0b41eaf | 2016-03-14 21:35:56 | [diff] [blame] | 9580 | EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect()); |
| 9581 | EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9582 | } |
| 9583 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9584 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9585 | RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) { |
| 9586 | // Ensure that the visible layer rect of a descendant of a surface with |
| 9587 | // unclipped descendants is computed correctly, when the surface doesn't apply |
| 9588 | // a clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9589 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9590 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9591 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9592 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9593 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 9594 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9595 | root->SetBounds(gfx::Size(30, 10)); |
| 9596 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 9597 | render_surface->SetBounds(gfx::Size(10, 15)); |
| 9598 | render_surface->test_properties()->force_render_surface = true; |
| 9599 | clip_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9600 | clip_child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9601 | child->SetBounds(gfx::Size(40, 40)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9602 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9603 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9604 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9605 | clip_parent->test_properties()->clip_children = |
| 9606 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9607 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9608 | |
| 9609 | ExecuteCalculateDrawProperties(root); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 9610 | EXPECT_EQ(gfx::Rect(30, 10), child->visible_layer_rect()); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9611 | } |
| 9612 | |
| 9613 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9614 | RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9615 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9616 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9617 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9618 | LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface); |
| 9619 | LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1); |
| 9620 | LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child); |
| 9621 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9622 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9623 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9624 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 9625 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9626 | render_surface->SetMasksToBounds(true); |
| 9627 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9628 | render_surface->test_properties()->force_render_surface = true; |
| 9629 | test_layer1->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9630 | test_layer1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9631 | clip_child->SetBounds(gfx::Size(50, 50)); |
| 9632 | clip_child->SetDrawsContent(true); |
| 9633 | test_layer2->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9634 | test_layer2->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9635 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9636 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9637 | clip_parent->test_properties()->clip_children = |
| 9638 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9639 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9640 | |
| 9641 | ExecuteCalculateDrawProperties(root); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9642 | EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect()); |
| 9643 | EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect()); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9644 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
| 9645 | EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect()); |
| 9646 | } |
| 9647 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9648 | TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9649 | LayerImpl* root = root_layer_for_testing(); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9650 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9651 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9652 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9653 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9654 | root->SetBounds(gfx::Size(50, 50)); |
| 9655 | clip_parent->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9656 | clip_parent->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9657 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9658 | render_surface->test_properties()->force_render_surface = true; |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9659 | render_surface->SetMasksToBounds(true); |
| 9660 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9661 | clip_child->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9662 | clip_child->SetDrawsContent(true); |
| 9663 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9664 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9665 | clip_parent->test_properties()->clip_children = |
| 9666 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9667 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9668 | |
| 9669 | ExecuteCalculateDrawProperties(root); |
| 9670 | |
| 9671 | // The clip child should inherit its clip parent's clipping state, not its |
| 9672 | // tree parent's clipping state. |
| 9673 | EXPECT_FALSE(clip_parent->is_clipped()); |
| 9674 | EXPECT_TRUE(render_surface->is_clipped()); |
| 9675 | EXPECT_FALSE(clip_child->is_clipped()); |
| 9676 | } |
| 9677 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9678 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) { |
| 9679 | // Tests the value of render surface content rect when we have multiple types |
| 9680 | // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and |
| 9681 | // clipped surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9682 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9683 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 9684 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 9685 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9686 | LayerImpl* unclipped_desc_surface2 = |
| 9687 | AddChild<LayerImpl>(unclipped_desc_surface); |
| 9688 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2); |
| 9689 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 9690 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9691 | root->SetBounds(gfx::Size(80, 80)); |
| 9692 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9693 | unclipped_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9694 | unclipped_surface->SetDrawsContent(true); |
| 9695 | unclipped_surface->test_properties()->force_render_surface = true; |
| 9696 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 9697 | clip_parent->SetMasksToBounds(true); |
| 9698 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9699 | unclipped_desc_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9700 | unclipped_desc_surface->SetDrawsContent(true); |
| 9701 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9702 | unclipped_desc_surface2->SetBounds(gfx::Size(60, 60)); |
| 9703 | unclipped_desc_surface2->SetDrawsContent(true); |
| 9704 | unclipped_desc_surface2->test_properties()->force_render_surface = true; |
| 9705 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9706 | clipped_surface->SetBounds(gfx::Size(70, 70)); |
| 9707 | clipped_surface->SetDrawsContent(true); |
| 9708 | clipped_surface->test_properties()->force_render_surface = true; |
| 9709 | |
| 9710 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9711 | clip_parent->test_properties()->clip_children = |
| 9712 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9713 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9714 | |
| 9715 | ExecuteCalculateDrawProperties(root); |
| 9716 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9717 | unclipped_surface->render_surface()->content_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9718 | EXPECT_EQ(gfx::Rect(50, 50), |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9719 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9720 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9721 | unclipped_desc_surface2->render_surface()->content_rect()); |
| 9722 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9723 | clipped_surface->render_surface()->content_rect()); |
| 9724 | } |
| 9725 | |
| 9726 | TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) { |
| 9727 | // Tests the value of render surface content rect when we have a layer that |
| 9728 | // clips between the clip parent's target and clip child's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9729 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9730 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9731 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9732 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9733 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9734 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9735 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9736 | gfx::Transform translate; |
| 9737 | translate.Translate(10, 10); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9738 | |
jaydasika | 778cb27 | 2016-08-15 19:00:54 | [diff] [blame] | 9739 | gfx::Transform rotate; |
| 9740 | rotate.RotateAboutXAxis(10); |
| 9741 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9742 | root->SetBounds(gfx::Size(100, 100)); |
| 9743 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9744 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9745 | surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9746 | surface->test_properties()->transform = rotate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9747 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9748 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9749 | clip_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9750 | unclipped_desc_surface->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9751 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 9752 | unclipped_desc_surface->SetDrawsContent(true); |
| 9753 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9754 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9755 | clip_child->SetDrawsContent(true); |
| 9756 | |
| 9757 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9758 | clip_parent->test_properties()->clip_children = |
| 9759 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9760 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9761 | |
| 9762 | ExecuteCalculateDrawProperties(root); |
| 9763 | |
| 9764 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9765 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9766 | } |
| 9767 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9768 | TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9769 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9770 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9771 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9772 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9773 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9774 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9775 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9776 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9777 | gfx::Transform scale; |
| 9778 | scale.Scale(2, 2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9779 | |
| 9780 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9781 | surface->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9782 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9783 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9784 | surface->test_properties()->force_render_surface = true; |
| 9785 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9786 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9787 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 9788 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 9789 | unclipped_desc_surface->SetDrawsContent(true); |
| 9790 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9791 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9792 | clip_child->SetDrawsContent(true); |
| 9793 | |
| 9794 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9795 | clip_parent->test_properties()->clip_children = |
| 9796 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9797 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9798 | |
| 9799 | ExecuteCalculateDrawProperties(root); |
| 9800 | |
| 9801 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 9802 | } |
| 9803 | |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9804 | TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9805 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9806 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9807 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9808 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9809 | gfx::Transform translation; |
| 9810 | translation.Translate(10, 10); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9811 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9812 | root->SetBounds(gfx::Size(30, 30)); |
| 9813 | render_surface->SetBounds(gfx::Size(30, 30)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9814 | render_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9815 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9816 | test_layer->test_properties()->transform = translation; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9817 | test_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9818 | test_layer->SetDrawsContent(true); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9819 | test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9820 | test_layer->test_properties()->opacity = 0.f; |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9821 | |
| 9822 | ExecuteCalculateDrawProperties(root); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 9823 | EXPECT_TRANSFORMATION_MATRIX_EQ(translation, |
| 9824 | test_layer->ScreenSpaceTransform()); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9825 | } |
| 9826 | |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 9827 | TEST_F(LayerTreeHostCommonTest, ClipParentDrawsIntoScaledRootSurface) { |
| 9828 | LayerImpl* root = root_layer_for_testing(); |
| 9829 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9830 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9831 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9832 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9833 | |
| 9834 | root->SetBounds(gfx::Size(100, 100)); |
| 9835 | clip_layer->SetBounds(gfx::Size(20, 20)); |
| 9836 | clip_layer->SetMasksToBounds(true); |
| 9837 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 9838 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 9839 | unclipped_desc_surface->SetDrawsContent(true); |
| 9840 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9841 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9842 | clip_child->SetDrawsContent(true); |
| 9843 | |
| 9844 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9845 | clip_parent->test_properties()->clip_children = |
| 9846 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9847 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 9848 | |
| 9849 | float device_scale_factor = 1.f; |
| 9850 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 9851 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->clip_rect()); |
| 9852 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 9853 | |
| 9854 | device_scale_factor = 2.f; |
| 9855 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 9856 | EXPECT_EQ(gfx::Rect(40, 40), clip_child->clip_rect()); |
| 9857 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 9858 | } |
| 9859 | |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9860 | TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9861 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9862 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9863 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9864 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9865 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9866 | root->SetBounds(gfx::Size(30, 30)); |
| 9867 | clip_parent->SetBounds(gfx::Size(40, 40)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9868 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9869 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9870 | render_surface->SetMasksToBounds(true); |
| 9871 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9872 | render_surface->test_properties()->force_render_surface = true; |
| 9873 | clip_child->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9874 | clip_child->SetDrawsContent(true); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9875 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9876 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9877 | clip_parent->test_properties()->clip_children = |
| 9878 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9879 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9880 | |
| 9881 | ExecuteCalculateDrawProperties(root); |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 9882 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9883 | } |
| 9884 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9885 | TEST_F(LayerTreeHostCommonTest, |
| 9886 | LayerClipRectLargerThanClippingRenderSurfaceRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9887 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9888 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9889 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9890 | |
| 9891 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9892 | root->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9893 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9894 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9895 | render_surface->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9896 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9897 | render_surface->test_properties()->force_render_surface = true; |
| 9898 | test_layer->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9899 | test_layer->SetMasksToBounds(true); |
| 9900 | test_layer->SetDrawsContent(true); |
| 9901 | ExecuteCalculateDrawProperties(root); |
| 9902 | |
| 9903 | EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect()); |
| 9904 | EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect()); |
| 9905 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect()); |
| 9906 | } |
| 9907 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9908 | TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) { |
| 9909 | // Tests that subtree is hidden is updated. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9910 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9911 | LayerImpl* hidden = AddChild<LayerImpl>(root); |
| 9912 | LayerImpl* test = AddChild<LayerImpl>(hidden); |
| 9913 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9914 | root->SetBounds(gfx::Size(30, 30)); |
| 9915 | hidden->SetBounds(gfx::Size(30, 30)); |
| 9916 | hidden->test_properties()->force_render_surface = true; |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9917 | hidden->test_properties()->hide_layer_and_subtree = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9918 | test->SetBounds(gfx::Size(30, 30)); |
| 9919 | test->test_properties()->force_render_surface = true; |
| 9920 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9921 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9922 | EXPECT_TRUE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9923 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9924 | hidden->test_properties()->hide_layer_and_subtree = false; |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9925 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9926 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9927 | EXPECT_FALSE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9928 | } |
| 9929 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9930 | TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9931 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9932 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9933 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 9934 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
| 9935 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9936 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9937 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9938 | render_surface1->SetPosition(gfx::PointF(10, 10)); |
| 9939 | render_surface1->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9940 | render_surface1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9941 | render_surface1->test_properties()->force_render_surface = true; |
| 9942 | render_surface2->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9943 | render_surface2->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9944 | render_surface2->test_properties()->force_render_surface = true; |
| 9945 | clip_child->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9946 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9947 | clip_child->test_properties()->clip_parent = root; |
| 9948 | root->test_properties()->clip_children = |
| 9949 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9950 | root->test_properties()->clip_children->insert(clip_child); |
| 9951 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9952 | ExecuteCalculateDrawProperties(root); |
| 9953 | |
| 9954 | EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); |
jaydasika | daf0af0 | 2016-01-06 15:33:37 | [diff] [blame] | 9955 | // A clip node is created for every render surface and for layers that have |
| 9956 | // local clip. So, here it should be craeted for every layer. |
| 9957 | EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9958 | } |
| 9959 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9960 | TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) { |
| 9961 | // Tests that a mask layer's draw properties are computed correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9962 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9963 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9964 | child->test_properties()->SetMaskLayer( |
| 9965 | LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 9966 | LayerImpl* mask = child->test_properties()->mask_layer; |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9967 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9968 | gfx::Transform transform; |
| 9969 | transform.Translate(10, 10); |
| 9970 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9971 | root->SetBounds(gfx::Size(40, 40)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9972 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9973 | child->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9974 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9975 | child->SetDrawsContent(false); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9976 | mask->SetBounds(gfx::Size(20, 20)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9977 | ExecuteCalculateDrawProperties(root); |
| 9978 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9979 | // The render surface created for the mask has no contributing content, so the |
| 9980 | // mask isn't a drawn RSLL member. This means it has an empty visible rect, |
| 9981 | // but its screen space transform can still be computed correctly on-demand. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9982 | EXPECT_FALSE(mask->is_drawn_render_surface_layer_list_member()); |
| 9983 | EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect()); |
| 9984 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9985 | |
| 9986 | // Make the child's render surface have contributing content. |
| 9987 | child->SetDrawsContent(true); |
| 9988 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9989 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9990 | EXPECT_TRUE(mask->is_drawn_render_surface_layer_list_member()); |
| 9991 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
| 9992 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9993 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9994 | transform.Translate(10, 10); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9995 | child->test_properties()->transform = transform; |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9996 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9997 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9998 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
| 9999 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 10000 | } |
| 10001 | |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10002 | TEST_F(LayerTreeHostCommonTest, |
| 10003 | SublayerScaleWithTransformNodeBetweenTwoTargets) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10004 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10005 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 10006 | LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1); |
| 10007 | LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets); |
| 10008 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10009 | |
| 10010 | gfx::Transform scale; |
| 10011 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10012 | |
| 10013 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 10014 | render_surface1->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10015 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 10016 | render_surface1->test_properties()->force_render_surface = true; |
| 10017 | between_targets->SetBounds(gfx::Size(30, 30)); |
| 10018 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 10019 | render_surface2->test_properties()->force_render_surface = true; |
| 10020 | test_layer->SetBounds(gfx::Size(30, 30)); |
| 10021 | test_layer->SetDrawsContent(true); |
| 10022 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 10023 | // We want layer between the two targets to create a clip node and effect |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10024 | // node but it shouldn't create a render surface. |
| 10025 | between_targets->SetMasksToBounds(true); |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 10026 | between_targets->test_properties()->opacity = 0.5f; |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10027 | |
| 10028 | ExecuteCalculateDrawProperties(root); |
| 10029 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 10030 | EffectTree& tree = root->layer_tree_impl()->property_trees()->effect_tree; |
| 10031 | EffectNode* node = tree.Node(render_surface1->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 10032 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10033 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 10034 | node = tree.Node(between_targets->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 10035 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10036 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 10037 | node = tree.Node(render_surface2->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 10038 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10039 | |
| 10040 | EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect()); |
| 10041 | } |
| 10042 | |
jaydasika | 3c5633d | 2016-08-25 00:39:22 | [diff] [blame] | 10043 | TEST_F(LayerTreeHostCommonTest, NoisyTransform) { |
| 10044 | LayerImpl* root = root_layer_for_testing(); |
| 10045 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 10046 | LayerImpl* scroll_child = AddChild<LayerImpl>(render_surface); |
| 10047 | LayerImpl* scroll_clip = AddChild<LayerImpl>(render_surface); |
| 10048 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_clip); |
| 10049 | |
| 10050 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 10051 | scroll_parent->test_properties()->scroll_children = |
| 10052 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 10053 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
| 10054 | scroll_parent->SetScrollClipLayer(scroll_clip->id()); |
| 10055 | |
| 10056 | scroll_parent->SetDrawsContent(true); |
| 10057 | scroll_child->SetDrawsContent(true); |
| 10058 | render_surface->test_properties()->force_render_surface = true; |
| 10059 | |
| 10060 | // A noisy transform that's invertible. |
| 10061 | gfx::Transform transform; |
| 10062 | transform.matrix().setDouble(0, 0, 6.12323e-17); |
| 10063 | transform.matrix().setDouble(0, 2, 1); |
| 10064 | transform.matrix().setDouble(2, 2, 6.12323e-17); |
| 10065 | transform.matrix().setDouble(2, 0, -1); |
| 10066 | |
| 10067 | scroll_child->test_properties()->transform = transform; |
| 10068 | render_surface->test_properties()->transform = transform; |
| 10069 | |
| 10070 | root->SetBounds(gfx::Size(30, 30)); |
| 10071 | scroll_child->SetBounds(gfx::Size(30, 30)); |
| 10072 | scroll_parent->SetBounds(gfx::Size(30, 30)); |
| 10073 | ExecuteCalculateDrawProperties(root); |
| 10074 | |
| 10075 | gfx::Transform expected; |
| 10076 | expected.matrix().setDouble(0, 0, 3.749395e-33); |
| 10077 | expected.matrix().setDouble(0, 2, 6.12323e-17); |
| 10078 | expected.matrix().setDouble(2, 0, -1); |
| 10079 | expected.matrix().setDouble(2, 2, 6.12323e-17); |
| 10080 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
| 10081 | scroll_child->ScreenSpaceTransform()); |
| 10082 | } |
| 10083 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10084 | TEST_F(LayerTreeHostCommonTest, LargeTransformTest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10085 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10086 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 10087 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10088 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 10089 | child->SetDrawsContent(true); |
| 10090 | child->SetMasksToBounds(true); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10091 | |
| 10092 | gfx::Transform large_transform; |
| 10093 | large_transform.Scale(99999999999999999999.f, 99999999999999999999.f); |
| 10094 | large_transform.Scale(9999999999999999999.f, 9999999999999999999.f); |
| 10095 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0))); |
| 10096 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1))); |
| 10097 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10098 | root->SetBounds(gfx::Size(30, 30)); |
| 10099 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 10100 | render_surface1->test_properties()->force_render_surface = true; |
| 10101 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 10102 | // TODO(sunxd): we make child have no render surface, because if the |
| 10103 | // child has one, the large transform applied to child will result in NaNs in |
| 10104 | // the draw_transform of the render_surface, thus make draw property updates |
| 10105 | // skip the child layer. We need further investigation into this to know |
| 10106 | // what exactly happens here. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 10107 | child->test_properties()->transform = large_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10108 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10109 | |
| 10110 | ExecuteCalculateDrawProperties(root); |
| 10111 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10112 | EXPECT_EQ(gfx::RectF(), |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 10113 | render_surface1->render_surface()->DrawableContentRect()); |
| 10114 | |
| 10115 | bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) || |
| 10116 | std::isnan(child->DrawTransform().matrix().get(0, 0)); |
| 10117 | EXPECT_TRUE(is_inf_or_nan); |
| 10118 | |
| 10119 | is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) || |
| 10120 | std::isnan(child->DrawTransform().matrix().get(1, 1)); |
| 10121 | EXPECT_TRUE(is_inf_or_nan); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10122 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 10123 | // The root layer should be in the RenderSurfaceLayerListImpl. |
| 10124 | const auto* rsll = render_surface_layer_list_impl(); |
| 10125 | EXPECT_NE(std::find(rsll->begin(), rsll->end(), root), rsll->end()); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10126 | } |
| 10127 | |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10128 | TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) { |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10129 | scoped_refptr<Layer> root = Layer::Create(); |
| 10130 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 10131 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 10132 | root->AddChild(child); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10133 | host()->SetRootLayer(root); |
| 10134 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10135 | root->SetBounds(gfx::Size(100, 100)); |
| 10136 | child->SetBounds(gfx::Size(20, 20)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10137 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10138 | |
| 10139 | // Changing the opacity from 1 to non-1 value should trigger rebuild of |
| 10140 | // property trees as a new effect node will be created. |
| 10141 | child->SetOpacity(0.5f); |
| 10142 | PropertyTrees* property_trees = host()->property_trees(); |
| 10143 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 10144 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10145 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10146 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 10147 | property_trees->effect_id_to_index_map.end()); |
| 10148 | |
| 10149 | // child already has an effect node. Changing its opacity shouldn't trigger |
| 10150 | // a property trees rebuild. |
| 10151 | child->SetOpacity(0.8f); |
| 10152 | property_trees = host()->property_trees(); |
| 10153 | EXPECT_FALSE(property_trees->needs_rebuild); |
| 10154 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10155 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10156 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 10157 | property_trees->effect_id_to_index_map.end()); |
| 10158 | |
| 10159 | // Changing the opacity from non-1 value to 1 should trigger a rebuild of |
| 10160 | // property trees as the effect node may no longer be needed. |
| 10161 | child->SetOpacity(1.f); |
| 10162 | property_trees = host()->property_trees(); |
| 10163 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 10164 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10165 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10166 | EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()), |
| 10167 | property_trees->effect_id_to_index_map.end()); |
| 10168 | } |
| 10169 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10170 | TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) { |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10171 | scoped_refptr<Layer> root = Layer::Create(); |
| 10172 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 10173 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 10174 | root->AddChild(animated); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10175 | host()->SetRootLayer(root); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 10176 | host()->GetLayerTree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10177 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10178 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10179 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10180 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10181 | animated->SetOpacity(0.f); |
| 10182 | |
| 10183 | scoped_refptr<AnimationPlayer> player = |
| 10184 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 10185 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10186 | |
| 10187 | player->AttachElement(animated->element_id()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10188 | |
| 10189 | int animation_id = 0; |
| 10190 | std::unique_ptr<Animation> animation = Animation::Create( |
| 10191 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 10192 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 10193 | animation->set_fill_mode(Animation::FillMode::NONE); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10194 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 10195 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10196 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 10197 | std::move(animation)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10198 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10199 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10200 | |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 10201 | EffectTree& tree = root->GetLayerTree()->property_trees()->effect_tree; |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10202 | EffectNode* node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10203 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 10204 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10205 | |
| 10206 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
khushalsagar | 6156779 | 2016-09-17 00:13:58 | [diff] [blame] | 10207 | host()->AnimateLayers( |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10208 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 10209 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10210 | EXPECT_TRUE(node->is_currently_animating_opacity); |
| 10211 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10212 | |
| 10213 | player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/); |
| 10214 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10215 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 10216 | EXPECT_FALSE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10217 | } |
| 10218 | |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10219 | TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) { |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10220 | scoped_refptr<Layer> root = Layer::Create(); |
| 10221 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 10222 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 10223 | root->AddChild(animated); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10224 | host()->SetRootLayer(root); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 10225 | host()->GetLayerTree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10226 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10227 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10228 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10229 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10230 | |
| 10231 | scoped_refptr<AnimationPlayer> player = |
| 10232 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 10233 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10234 | player->AttachElement(animated->element_id()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10235 | |
| 10236 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 10237 | KeyframedTransformAnimationCurve::Create()); |
| 10238 | TransformOperations start; |
| 10239 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 10240 | gfx::Transform transform; |
| 10241 | transform.Scale3d(1.0, 2.0, 3.0); |
| 10242 | TransformOperations operation; |
| 10243 | operation.AppendMatrix(transform); |
| 10244 | curve->AddKeyframe( |
| 10245 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 10246 | curve->AddKeyframe(TransformKeyframe::Create( |
| 10247 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
| 10248 | std::unique_ptr<Animation> animation( |
| 10249 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 10250 | animation->set_fill_mode(Animation::FillMode::NONE); |
| 10251 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 10252 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10253 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 10254 | std::move(animation)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10255 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10256 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10257 | |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 10258 | TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree; |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10259 | TransformNode* node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10260 | EXPECT_FALSE(node->is_currently_animating); |
| 10261 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10262 | |
| 10263 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
khushalsagar | 6156779 | 2016-09-17 00:13:58 | [diff] [blame] | 10264 | host()->AnimateLayers( |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10265 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 10266 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10267 | EXPECT_TRUE(node->is_currently_animating); |
| 10268 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10269 | |
| 10270 | player->AbortAnimations(TargetProperty::TRANSFORM, |
| 10271 | false /*needs_completion*/); |
| 10272 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10273 | EXPECT_FALSE(node->is_currently_animating); |
| 10274 | EXPECT_FALSE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10275 | } |
| 10276 | |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 10277 | TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) { |
| 10278 | LayerTreeHostCommon::ScrollUpdateInfo scroll; |
| 10279 | scroll.layer_id = 2; |
| 10280 | scroll.scroll_delta = gfx::Vector2d(5, 10); |
| 10281 | |
| 10282 | proto::ScrollUpdateInfo proto; |
| 10283 | scroll.ToProtobuf(&proto); |
| 10284 | LayerTreeHostCommon::ScrollUpdateInfo new_scroll; |
| 10285 | new_scroll.FromProtobuf(proto); |
| 10286 | |
| 10287 | EXPECT_EQ(scroll, new_scroll); |
| 10288 | } |
| 10289 | |
| 10290 | TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) { |
| 10291 | ScrollAndScaleSet scroll_and_scale_set; |
| 10292 | |
| 10293 | LayerTreeHostCommon::ScrollUpdateInfo scroll1; |
| 10294 | scroll1.layer_id = 1; |
| 10295 | scroll1.scroll_delta = gfx::Vector2d(5, 10); |
| 10296 | LayerTreeHostCommon::ScrollUpdateInfo scroll2; |
| 10297 | scroll2.layer_id = 2; |
| 10298 | scroll2.scroll_delta = gfx::Vector2d(1, 5); |
| 10299 | scroll_and_scale_set.scrolls.push_back(scroll1); |
| 10300 | scroll_and_scale_set.scrolls.push_back(scroll2); |
| 10301 | |
| 10302 | scroll_and_scale_set.page_scale_delta = 0.3f; |
| 10303 | scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f); |
| 10304 | scroll_and_scale_set.top_controls_delta = 0.9f; |
| 10305 | |
| 10306 | proto::ScrollAndScaleSet proto; |
| 10307 | scroll_and_scale_set.ToProtobuf(&proto); |
| 10308 | ScrollAndScaleSet new_scroll_and_scale_set; |
| 10309 | new_scroll_and_scale_set.FromProtobuf(proto); |
| 10310 | |
| 10311 | EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); |
| 10312 | } |
| 10313 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10314 | TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 10315 | // Test the behavior of scroll tree builder |
| 10316 | // Topology: |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10317 | // +root1(1)[inner_viewport_container_layer] |
| 10318 | // +-page_scale_layer |
| 10319 | // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling & |
| 10320 | // scrollable, inner_viewport_scroll_layer] |
| 10321 | // +------child6(6)[kScrollbarScrolling] |
| 10322 | // +--------grand_child10(10)[kScrollbarScrolling] |
| 10323 | // +----parent3(3) |
| 10324 | // +------child7(7)[scrollable] |
| 10325 | // +------child8(8)[scroll_parent=7] |
| 10326 | // +--------grand_child11(11)[scrollable] |
| 10327 | // +----parent4(4) |
| 10328 | // +------child9(9) |
| 10329 | // +--------grand_child12(12) |
| 10330 | // +----parent5(5)[contains_non_fast_scrollable_region] |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10331 | // |
| 10332 | // Expected scroll tree topology: |
| 10333 | // +property_tree_root---owner:-1 |
| 10334 | // +--root---owner:1, id:1 |
| 10335 | // +----node---owner:2, id:2 |
| 10336 | // +------node---owner:6, id:3 |
| 10337 | // +----node---owner:7, id:4 |
| 10338 | // +------node---owner:11, id:5 |
| 10339 | // +----node---owner:5, id:6 |
| 10340 | // |
| 10341 | // Extra check: |
| 10342 | // scroll_tree_index() of: |
| 10343 | // grand_child10:3 |
| 10344 | // parent3:1 |
| 10345 | // child8:4 |
| 10346 | // parent4:1 |
| 10347 | // child9:1 |
| 10348 | // grand_child12:1 |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 10349 | scoped_refptr<Layer> root1 = Layer::Create(); |
| 10350 | scoped_refptr<Layer> page_scale_layer = Layer::Create(); |
| 10351 | scoped_refptr<Layer> parent2 = Layer::Create(); |
| 10352 | scoped_refptr<Layer> parent3 = Layer::Create(); |
| 10353 | scoped_refptr<Layer> parent4 = Layer::Create(); |
| 10354 | scoped_refptr<Layer> parent5 = Layer::Create(); |
| 10355 | scoped_refptr<Layer> child6 = Layer::Create(); |
| 10356 | scoped_refptr<Layer> child7 = Layer::Create(); |
| 10357 | scoped_refptr<Layer> child8 = Layer::Create(); |
| 10358 | scoped_refptr<Layer> child9 = Layer::Create(); |
| 10359 | scoped_refptr<Layer> grand_child10 = Layer::Create(); |
| 10360 | scoped_refptr<Layer> grand_child11 = Layer::Create(); |
| 10361 | scoped_refptr<Layer> grand_child12 = Layer::Create(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10362 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10363 | root1->AddChild(page_scale_layer); |
| 10364 | page_scale_layer->AddChild(parent2); |
| 10365 | page_scale_layer->AddChild(parent3); |
| 10366 | page_scale_layer->AddChild(parent4); |
| 10367 | page_scale_layer->AddChild(parent5); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10368 | parent2->AddChild(child6); |
| 10369 | parent3->AddChild(child7); |
| 10370 | parent3->AddChild(child8); |
| 10371 | parent4->AddChild(child9); |
| 10372 | child6->AddChild(grand_child10); |
| 10373 | child8->AddChild(grand_child11); |
| 10374 | child9->AddChild(grand_child12); |
| 10375 | host()->SetRootLayer(root1); |
| 10376 | |
| 10377 | parent2->AddMainThreadScrollingReasons( |
| 10378 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10379 | parent2->AddMainThreadScrollingReasons( |
| 10380 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10381 | parent2->SetScrollClipLayerId(root1->id()); |
| 10382 | child6->AddMainThreadScrollingReasons( |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10383 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10384 | grand_child10->AddMainThreadScrollingReasons( |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10385 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10386 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10387 | child7->SetScrollClipLayerId(parent3->id()); |
| 10388 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10389 | child8->SetScrollParent(child7.get()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10390 | grand_child11->SetScrollClipLayerId(parent3->id()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10391 | |
| 10392 | parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10393 | parent5->SetBounds(gfx::Size(10, 10)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10394 | |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 10395 | host()->GetLayerTree()->RegisterViewportLayers(nullptr, page_scale_layer, |
| 10396 | parent2, nullptr); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10397 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10398 | |
| 10399 | const int kInvalidPropertyTreeNodeId = -1; |
| 10400 | const int kRootPropertyTreeNodeId = 0; |
| 10401 | |
| 10402 | // Property tree root |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10403 | ScrollTree& scroll_tree = host()->property_trees()->scroll_tree; |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 10404 | PropertyTrees property_trees; |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10405 | property_trees.is_main_thread = true; |
| 10406 | property_trees.is_active = false; |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10407 | ScrollTree& expected_scroll_tree = property_trees.scroll_tree; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10408 | ScrollNode* property_tree_root = expected_scroll_tree.Node(0); |
| 10409 | property_tree_root->id = kRootPropertyTreeNodeId; |
| 10410 | property_tree_root->parent_id = kInvalidPropertyTreeNodeId; |
| 10411 | property_tree_root->owner_id = kInvalidPropertyTreeNodeId; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10412 | property_tree_root->scrollable = false; |
| 10413 | property_tree_root->main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10414 | MainThreadScrollingReason::kNotScrollingOnMain; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10415 | property_tree_root->contains_non_fast_scrollable_region = false; |
| 10416 | property_tree_root->transform_id = kRootPropertyTreeNodeId; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10417 | |
| 10418 | // The node owned by root1 |
| 10419 | ScrollNode scroll_root1; |
| 10420 | scroll_root1.id = 1; |
| 10421 | scroll_root1.owner_id = root1->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10422 | scroll_root1.user_scrollable_horizontal = true; |
| 10423 | scroll_root1.user_scrollable_vertical = true; |
| 10424 | scroll_root1.transform_id = root1->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10425 | expected_scroll_tree.Insert(scroll_root1, 0); |
| 10426 | |
| 10427 | // The node owned by parent2 |
| 10428 | ScrollNode scroll_parent2; |
| 10429 | scroll_parent2.id = 2; |
| 10430 | scroll_parent2.owner_id = parent2->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10431 | scroll_parent2.scrollable = true; |
| 10432 | scroll_parent2.main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10433 | parent2->main_thread_scrolling_reasons(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10434 | scroll_parent2.scroll_clip_layer_bounds = root1->bounds(); |
| 10435 | scroll_parent2.bounds = parent2->bounds(); |
| 10436 | scroll_parent2.max_scroll_offset_affected_by_page_scale = true; |
| 10437 | scroll_parent2.is_inner_viewport_scroll_layer = true; |
| 10438 | scroll_parent2.user_scrollable_horizontal = true; |
| 10439 | scroll_parent2.user_scrollable_vertical = true; |
| 10440 | scroll_parent2.transform_id = parent2->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10441 | expected_scroll_tree.Insert(scroll_parent2, 1); |
| 10442 | |
| 10443 | // The node owned by child6 |
| 10444 | ScrollNode scroll_child6; |
| 10445 | scroll_child6.id = 3; |
| 10446 | scroll_child6.owner_id = child6->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10447 | scroll_child6.main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10448 | child6->main_thread_scrolling_reasons(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10449 | scroll_child6.should_flatten = true; |
| 10450 | scroll_child6.user_scrollable_horizontal = true; |
| 10451 | scroll_child6.user_scrollable_vertical = true; |
| 10452 | scroll_child6.transform_id = child6->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10453 | expected_scroll_tree.Insert(scroll_child6, 2); |
| 10454 | |
| 10455 | // The node owned by child7, child7 also owns a transform node |
| 10456 | ScrollNode scroll_child7; |
| 10457 | scroll_child7.id = 4; |
| 10458 | scroll_child7.owner_id = child7->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10459 | scroll_child7.scrollable = true; |
| 10460 | scroll_child7.scroll_clip_layer_bounds = parent3->bounds(); |
| 10461 | scroll_child7.bounds = child7->bounds(); |
| 10462 | scroll_child7.user_scrollable_horizontal = true; |
| 10463 | scroll_child7.user_scrollable_vertical = true; |
| 10464 | scroll_child7.transform_id = child7->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10465 | expected_scroll_tree.Insert(scroll_child7, 1); |
| 10466 | |
| 10467 | // The node owned by grand_child11, grand_child11 also owns a transform node |
| 10468 | ScrollNode scroll_grand_child11; |
| 10469 | scroll_grand_child11.id = 5; |
| 10470 | scroll_grand_child11.owner_id = grand_child11->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10471 | scroll_grand_child11.scrollable = true; |
| 10472 | scroll_grand_child11.user_scrollable_horizontal = true; |
| 10473 | scroll_grand_child11.user_scrollable_vertical = true; |
| 10474 | scroll_grand_child11.transform_id = grand_child11->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10475 | expected_scroll_tree.Insert(scroll_grand_child11, 4); |
| 10476 | |
| 10477 | // The node owned by parent5 |
| 10478 | ScrollNode scroll_parent5; |
| 10479 | scroll_parent5.id = 8; |
| 10480 | scroll_parent5.owner_id = parent5->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10481 | scroll_parent5.contains_non_fast_scrollable_region = true; |
| 10482 | scroll_parent5.bounds = gfx::Size(10, 10); |
| 10483 | scroll_parent5.should_flatten = true; |
| 10484 | scroll_parent5.user_scrollable_horizontal = true; |
| 10485 | scroll_parent5.user_scrollable_vertical = true; |
| 10486 | scroll_parent5.transform_id = parent5->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10487 | expected_scroll_tree.Insert(scroll_parent5, 1); |
| 10488 | |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10489 | expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0)); |
| 10490 | expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0)); |
| 10491 | expected_scroll_tree.SetScrollOffset(grand_child11->id(), |
| 10492 | gfx::ScrollOffset(0, 0)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10493 | expected_scroll_tree.set_needs_update(false); |
| 10494 | |
| 10495 | EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 10496 | |
| 10497 | // Check other layers' scroll_tree_index |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10498 | EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10499 | EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10500 | EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10501 | EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10502 | EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10503 | EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10504 | EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10505 | } |
| 10506 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 10507 | } // namespace |
| 10508 | } // namespace cc |