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" |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 34 | #include "cc/test/fake_content_layer_client.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 35 | #include "cc/test/fake_impl_task_runner_provider.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 36 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 37 | #include "cc/test/fake_layer_tree_host_impl.h" |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 38 | #include "cc/test/fake_output_surface.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() { |
| 65 | verify_transform_tree_calculations = true; |
jaydasika | 853306a | 2016-07-29 19:28:34 | [diff] [blame] | 66 | verify_clip_tree_calculations = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 67 | } |
| 68 | }; |
| 69 | |
| 70 | class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { |
| 71 | public: |
| 72 | LayerTreeHostCommonTestBase() |
| 73 | : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {} |
| 74 | explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings) |
| 75 | : LayerTestCommon::LayerImplTest(settings) {} |
| 76 | |
| 77 | static void SetScrollOffsetDelta(LayerImpl* layer_impl, |
| 78 | const gfx::Vector2dF& delta) { |
| 79 | if (layer_impl->layer_tree_impl() |
| 80 | ->property_trees() |
| 81 | ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(), |
| 82 | delta)) |
| 83 | layer_impl->layer_tree_impl()->DidUpdateScrollOffset( |
| 84 | layer_impl->id(), layer_impl->transform_tree_index()); |
| 85 | } |
| 86 | |
| 87 | static float GetMaximumAnimationScale(LayerImpl* layer_impl) { |
| 88 | return layer_impl->layer_tree_impl() |
| 89 | ->property_trees() |
| 90 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 91 | layer_impl->layer_tree_impl()) |
| 92 | .maximum_animation_scale; |
| 93 | } |
| 94 | |
| 95 | static float GetStartingAnimationScale(LayerImpl* layer_impl) { |
| 96 | return layer_impl->layer_tree_impl() |
| 97 | ->property_trees() |
| 98 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 99 | layer_impl->layer_tree_impl()) |
| 100 | .starting_animation_scale; |
| 101 | } |
| 102 | |
| 103 | void ExecuteCalculateDrawProperties(Layer* root_layer, |
| 104 | float device_scale_factor, |
| 105 | float page_scale_factor, |
| 106 | Layer* page_scale_layer) { |
| 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; |
| 122 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 123 | } |
| 124 | |
| 125 | void ExecuteCalculateDrawProperties(LayerImpl* root_layer, |
| 126 | float device_scale_factor, |
| 127 | float page_scale_factor, |
| 128 | LayerImpl* page_scale_layer) { |
| 129 | if (device_scale_factor != |
| 130 | root_layer->layer_tree_impl()->device_scale_factor()) |
| 131 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 132 | |
| 133 | root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); |
| 134 | |
| 135 | EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 136 | |
| 137 | gfx::Size device_viewport_size = |
| 138 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 139 | root_layer->bounds().height() * device_scale_factor); |
| 140 | |
| 141 | render_surface_layer_list_impl_.reset(new LayerImplList); |
| 142 | |
| 143 | // We are probably not testing what is intended if the root_layer bounds are |
| 144 | // empty. |
| 145 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 146 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 147 | root_layer, device_viewport_size, |
| 148 | render_surface_layer_list_impl_.get()); |
| 149 | inputs.device_scale_factor = device_scale_factor; |
| 150 | inputs.page_scale_factor = page_scale_factor; |
| 151 | inputs.page_scale_layer = page_scale_layer; |
| 152 | inputs.can_adjust_raster_scales = true; |
| 153 | |
| 154 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 155 | } |
| 156 | |
| 157 | template <class LayerType> |
| 158 | void ExecuteCalculateDrawProperties(LayerType* root_layer) { |
| 159 | LayerType* page_scale_application_layer = nullptr; |
| 160 | ExecuteCalculateDrawProperties(root_layer, 1.f, 1.f, |
| 161 | page_scale_application_layer); |
| 162 | } |
| 163 | |
| 164 | template <class LayerType> |
| 165 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 166 | float device_scale_factor) { |
| 167 | LayerType* page_scale_application_layer = nullptr; |
| 168 | ExecuteCalculateDrawProperties(root_layer, device_scale_factor, 1.f, |
| 169 | page_scale_application_layer); |
| 170 | } |
| 171 | |
| 172 | void ExecuteCalculateDrawPropertiesWithPropertyTrees(Layer* root_layer) { |
| 173 | DCHECK(root_layer->layer_tree_host()); |
| 174 | PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 175 | |
| 176 | bool can_render_to_separate_surface = true; |
| 177 | |
| 178 | const Layer* page_scale_layer = |
| 179 | root_layer->layer_tree_host()->page_scale_layer(); |
| 180 | Layer* inner_viewport_scroll_layer = |
| 181 | root_layer->layer_tree_host()->inner_viewport_scroll_layer(); |
| 182 | Layer* outer_viewport_scroll_layer = |
| 183 | root_layer->layer_tree_host()->outer_viewport_scroll_layer(); |
| 184 | const Layer* overscroll_elasticity_layer = |
| 185 | root_layer->layer_tree_host()->overscroll_elasticity_layer(); |
| 186 | gfx::Vector2dF elastic_overscroll = |
| 187 | root_layer->layer_tree_host()->elastic_overscroll(); |
| 188 | float page_scale_factor = 1.f; |
| 189 | float device_scale_factor = 1.f; |
| 190 | gfx::Size device_viewport_size = |
| 191 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 192 | root_layer->bounds().height() * device_scale_factor); |
| 193 | PropertyTrees* property_trees = |
| 194 | root_layer->layer_tree_host()->property_trees(); |
| 195 | update_layer_list_.clear(); |
| 196 | PropertyTreeBuilder::BuildPropertyTrees( |
| 197 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 198 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 199 | elastic_overscroll, page_scale_factor, device_scale_factor, |
| 200 | gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
| 201 | draw_property_utils::UpdatePropertyTrees(property_trees, |
| 202 | can_render_to_separate_surface); |
| 203 | draw_property_utils::FindLayersThatNeedUpdates( |
| 204 | root_layer->layer_tree_host(), property_trees->transform_tree, |
| 205 | property_trees->effect_tree, &update_layer_list_); |
| 206 | draw_property_utils::ComputeVisibleRectsForTesting( |
| 207 | property_trees, can_render_to_separate_surface, &update_layer_list_); |
| 208 | } |
| 209 | |
| 210 | void ExecuteCalculateDrawPropertiesWithPropertyTrees(LayerImpl* root_layer) { |
| 211 | DCHECK(root_layer->layer_tree_impl()); |
| 212 | PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer); |
| 213 | |
| 214 | bool can_render_to_separate_surface = true; |
| 215 | |
| 216 | LayerImpl* page_scale_layer = nullptr; |
| 217 | LayerImpl* inner_viewport_scroll_layer = |
| 218 | root_layer->layer_tree_impl()->InnerViewportScrollLayer(); |
| 219 | LayerImpl* outer_viewport_scroll_layer = |
| 220 | root_layer->layer_tree_impl()->OuterViewportScrollLayer(); |
| 221 | LayerImpl* overscroll_elasticity_layer = |
| 222 | root_layer->layer_tree_impl()->OverscrollElasticityLayer(); |
| 223 | gfx::Vector2dF elastic_overscroll = |
| 224 | root_layer->layer_tree_impl()->elastic_overscroll()->Current( |
| 225 | root_layer->layer_tree_impl()->IsActiveTree()); |
| 226 | float page_scale_factor = 1.f; |
| 227 | float device_scale_factor = 1.f; |
| 228 | gfx::Size device_viewport_size = |
| 229 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 230 | root_layer->bounds().height() * device_scale_factor); |
| 231 | update_layer_list_impl_.reset(new LayerImplList); |
| 232 | root_layer->layer_tree_impl()->BuildLayerListForTesting(); |
| 233 | draw_property_utils::BuildPropertyTreesAndComputeVisibleRects( |
| 234 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 235 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 236 | elastic_overscroll, page_scale_factor, device_scale_factor, |
| 237 | gfx::Rect(device_viewport_size), gfx::Transform(), |
| 238 | can_render_to_separate_surface, |
| 239 | root_layer->layer_tree_impl()->property_trees(), |
| 240 | update_layer_list_impl_.get()); |
| 241 | } |
| 242 | |
| 243 | void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces( |
| 244 | LayerImpl* root_layer) { |
| 245 | gfx::Size device_viewport_size = |
| 246 | gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); |
| 247 | render_surface_layer_list_impl_.reset(new LayerImplList); |
| 248 | |
| 249 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 250 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 251 | root_layer, device_viewport_size, |
| 252 | render_surface_layer_list_impl_.get()); |
| 253 | inputs.can_adjust_raster_scales = true; |
| 254 | inputs.can_render_to_separate_surface = false; |
| 255 | |
| 256 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 257 | } |
| 258 | |
| 259 | bool UpdateLayerListImplContains(int id) const { |
| 260 | for (auto* layer : *update_layer_list_impl_) { |
| 261 | if (layer->id() == id) |
| 262 | return true; |
| 263 | } |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | bool UpdateLayerListContains(int id) const { |
| 268 | for (const auto& layer : update_layer_list_) { |
| 269 | if (layer->id() == id) |
| 270 | return true; |
| 271 | } |
| 272 | return false; |
| 273 | } |
| 274 | |
| 275 | const LayerImplList* render_surface_layer_list_impl() const { |
| 276 | return render_surface_layer_list_impl_.get(); |
| 277 | } |
| 278 | const LayerImplList* update_layer_list_impl() const { |
| 279 | return update_layer_list_impl_.get(); |
| 280 | } |
| 281 | const LayerList& update_layer_list() const { return update_layer_list_; } |
| 282 | |
| 283 | private: |
| 284 | std::unique_ptr<std::vector<LayerImpl*>> render_surface_layer_list_impl_; |
| 285 | LayerList update_layer_list_; |
| 286 | std::unique_ptr<LayerImplList> update_layer_list_impl_; |
| 287 | }; |
| 288 | |
| 289 | class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase, |
| 290 | public testing::Test {}; |
| 291 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 292 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 293 | public: |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 294 | LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 295 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 296 | bool DrawsContent() const override { return true; } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 297 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 298 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 299 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 300 | }; |
| 301 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 302 | class LayerTreeSettingsScaleContent : public VerifyTreeCalcsLayerTreeSettings { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 303 | public: |
| 304 | LayerTreeSettingsScaleContent() { |
| 305 | layer_transforms_should_scale_layer_contents = true; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 306 | } |
| 307 | }; |
| 308 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 309 | class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTestBase, |
| 310 | public testing::Test { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 311 | public: |
| 312 | LayerTreeHostCommonScalingTest() |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 313 | : LayerTreeHostCommonTestBase(LayerTreeSettingsScaleContent()) {} |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 314 | }; |
| 315 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 316 | class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest { |
| 317 | public: |
| 318 | LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {} |
| 319 | |
| 320 | LayerImpl* TestVisibleRectAndDrawableContentRect( |
| 321 | const gfx::Rect& target_rect, |
| 322 | const gfx::Transform& layer_transform, |
| 323 | const gfx::Rect& layer_rect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 324 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 325 | LayerImpl* target = AddChild<LayerImpl>(root); |
| 326 | LayerImpl* drawing_layer = AddChild<LayerImpl>(target); |
| 327 | |
| 328 | root->SetDrawsContent(true); |
| 329 | target->SetDrawsContent(true); |
| 330 | target->SetMasksToBounds(true); |
| 331 | drawing_layer->SetDrawsContent(true); |
| 332 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 333 | root->SetBounds(gfx::Size(500, 500)); |
| 334 | root->test_properties()->force_render_surface = true; |
| 335 | target->SetPosition(gfx::PointF(target_rect.origin())); |
| 336 | target->SetBounds(target_rect.size()); |
| 337 | target->test_properties()->force_render_surface = true; |
| 338 | drawing_layer->SetTransform(layer_transform); |
| 339 | drawing_layer->SetPosition(gfx::PointF(layer_rect.origin())); |
| 340 | drawing_layer->SetBounds(layer_rect.size()); |
| 341 | drawing_layer->test_properties()->should_flatten_transform = false; |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 342 | |
| 343 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 344 | ExecuteCalculateDrawProperties(root); |
| 345 | |
| 346 | return drawing_layer; |
| 347 | } |
| 348 | }; |
| 349 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 350 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 351 | // Sanity check: For layers positioned at zero, with zero size, |
| 352 | // and with identity transforms, then the draw transform, |
| 353 | // screen space transform, and the hierarchy passed on to children |
| 354 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 355 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 356 | LayerImpl* parent = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 357 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 358 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 359 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 360 | parent->SetBounds(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 361 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 362 | ExecuteCalculateDrawProperties(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 363 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 364 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 365 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 366 | child->ScreenSpaceTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 367 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 368 | grand_child->DrawTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 369 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 370 | grand_child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 371 | } |
| 372 | |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 373 | TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) { |
| 374 | // Tests that effect tree node gets a valid transform id when a layer |
| 375 | // has opacity but doesn't create a render surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 376 | LayerImpl* parent = root_layer_for_testing(); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 377 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 378 | child->SetDrawsContent(true); |
| 379 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 380 | parent->SetBounds(gfx::Size(100, 100)); |
| 381 | child->SetPosition(gfx::PointF(10, 10)); |
| 382 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 383 | child->test_properties()->opacity = 0.f; |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 384 | ExecuteCalculateDrawProperties(parent); |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 385 | EffectTree& effect_tree = |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 386 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 387 | EffectNode* node = effect_tree.Node(child->effect_tree_index()); |
| 388 | const int transform_tree_size = parent->layer_tree_impl() |
| 389 | ->property_trees() |
| 390 | ->transform_tree.next_available_id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 391 | EXPECT_LT(node->transform_id, transform_tree_size); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 392 | } |
| 393 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 394 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 395 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 396 | LayerImpl* layer = AddChild<LayerImpl>(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 397 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 398 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 399 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 400 | EffectTree& effect_tree = |
| 401 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 402 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 403 | root->SetBounds(gfx::Size(1, 2)); |
| 404 | |
| 405 | // 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] | 406 | // transform or the screenspace transform. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 407 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 408 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 409 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 410 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 411 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 412 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 413 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 414 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 415 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 416 | // Case 2: The anchor point by itself (without a layer transform) should have |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 417 | // no effect on the transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 418 | layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 419 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 420 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 421 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 422 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 423 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 424 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 425 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 426 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 427 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 428 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 429 | // Case 3: A change in actual position affects both the draw transform and |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 430 | // screen space transform. |
| 431 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 432 | position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 433 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 434 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 435 | ExecuteCalculateDrawProperties(root); |
| 436 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 437 | position_transform, |
| 438 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 439 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 440 | position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 441 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 442 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 443 | // Case 4: In the correct sequence of transforms, the layer transform should |
| 444 | // pre-multiply the translation-to-center. This is easily tested by using a |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 445 | // scale transform, because scale and translation are not commutative. |
| 446 | gfx::Transform layer_transform; |
| 447 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 448 | layer->SetTransform(layer_transform); |
| 449 | layer->test_properties()->transform_origin = gfx::Point3F(); |
| 450 | layer->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 451 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 452 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 453 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 454 | layer_transform, |
| 455 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 456 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 457 | layer_transform, |
| 458 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 459 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 460 | // Case 5: The layer transform should occur with respect to the anchor point. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 461 | gfx::Transform translation_to_anchor; |
| 462 | translation_to_anchor.Translate(5.0, 0.0); |
| 463 | gfx::Transform expected_result = |
| 464 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 465 | layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 466 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 467 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 468 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 469 | expected_result, |
| 470 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 471 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 472 | expected_result, |
| 473 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 474 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 475 | // Case 6: Verify that position pre-multiplies the layer transform. The |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 476 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 477 | // it is still worth testing to detect accidental regressions. |
| 478 | expected_result = position_transform * translation_to_anchor * |
| 479 | layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 480 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 481 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 482 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 483 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 484 | expected_result, |
| 485 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 486 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 487 | expected_result, |
| 488 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 489 | } |
| 490 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 491 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 492 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 493 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 494 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 495 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 496 | -kScrollOffset.y()); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 497 | float page_scale = 0.888f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 498 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 499 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 500 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 501 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 502 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 503 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 504 | &task_graph_runner); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 505 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 506 | std::unique_ptr<LayerImpl> sublayer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 507 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 508 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 509 | sublayer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 510 | sublayer->SetBounds(gfx::Size(500, 500)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 511 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 512 | std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 513 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 514 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 515 | scroll_layer->SetBounds(gfx::Size(10, 20)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 516 | std::unique_ptr<LayerImpl> clip_layer_scoped_ptr( |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 517 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 518 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 519 | |
| 520 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 521 | clip_layer->SetBounds( |
| 522 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 523 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 524 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 525 | SetScrollOffsetDelta(scroll_layer, kScrollDelta); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 526 | gfx::Transform impl_transform; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 527 | scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 528 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 529 | clip_layer->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr)); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 530 | scroll_layer_raw_ptr->layer_tree_impl() |
| 531 | ->property_trees() |
| 532 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(), |
| 533 | kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 534 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 535 | std::unique_ptr<LayerImpl> root( |
| 536 | LayerImpl::Create(host_impl.active_tree(), 3)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 537 | root->SetBounds(gfx::Size(3, 4)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 538 | root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 539 | root->SetHasRenderSurface(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 540 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 541 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 542 | |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 543 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 544 | scroll_layer->test_properties()->parent); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 545 | gfx::Transform expected_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 546 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 547 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 548 | page_scale * kDeviceScale), |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 549 | MathUtil::Round(sub_layer_screen_position.y() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 550 | page_scale * kDeviceScale)); |
| 551 | expected_transform.Scale(page_scale * kDeviceScale, |
| 552 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 553 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 554 | sublayer->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 555 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 556 | sublayer->ScreenSpaceTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 557 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 558 | gfx::Transform arbitrary_translate; |
| 559 | const float kTranslateX = 10.6f; |
| 560 | const float kTranslateY = 20.6f; |
| 561 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 562 | scroll_layer->SetTransform(arbitrary_translate); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 563 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 564 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 565 | scroll_layer->test_properties()->parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 566 | expected_transform.MakeIdentity(); |
| 567 | expected_transform.Translate( |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 568 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 569 | sub_layer_screen_position.x() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 570 | kDeviceScale), |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 571 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 572 | sub_layer_screen_position.y() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 573 | kDeviceScale)); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 574 | expected_transform.Scale(page_scale * kDeviceScale, |
| 575 | page_scale * kDeviceScale); |
| 576 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 577 | sublayer->DrawTransform()); |
| 578 | |
| 579 | // Test that page scale is updated even when we don't rebuild property trees. |
| 580 | page_scale = 1.888f; |
| 581 | root_layer->layer_tree_impl()->SetViewportLayersFromIds( |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 582 | Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(), |
| 583 | Layer::INVALID_ID, Layer::INVALID_ID); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 584 | root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 585 | EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 586 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 587 | scroll_layer->test_properties()->parent); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 588 | |
| 589 | expected_transform.MakeIdentity(); |
| 590 | expected_transform.Translate( |
| 591 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 592 | sub_layer_screen_position.x() * page_scale * |
| 593 | kDeviceScale), |
| 594 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 595 | sub_layer_screen_position.y() * page_scale * |
| 596 | kDeviceScale)); |
| 597 | expected_transform.Scale(page_scale * kDeviceScale, |
| 598 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 599 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 600 | sublayer->DrawTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 601 | } |
| 602 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 603 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 604 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 605 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 606 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 607 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 608 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 609 | // One-time setup of root layer |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 610 | root->SetBounds(gfx::Size(1, 2)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 611 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 612 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 613 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 614 | EffectTree& effect_tree = |
| 615 | host_impl()->active_tree()->property_trees()->effect_tree; |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 616 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 617 | // Case 1: parent's anchor point should not affect child or grand_child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 618 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 619 | parent->SetBounds(gfx::Size(10, 12)); |
| 620 | child->SetBounds(gfx::Size(16, 18)); |
| 621 | grand_child->SetBounds(gfx::Size(76, 78)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 622 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 623 | |
| 624 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 625 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 626 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 627 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 628 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 629 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 630 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 631 | gfx::Transform(), draw_property_utils::DrawTransform( |
| 632 | grand_child, transform_tree, effect_tree)); |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 633 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 634 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 635 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 636 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 637 | // Case 2: parent's position affects child and grand_child. |
| 638 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 639 | parent_position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 640 | parent->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 641 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 642 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 643 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 644 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 645 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 646 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 647 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 648 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 649 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 650 | parent_position_transform, draw_property_utils::DrawTransform( |
| 651 | grand_child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 652 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 653 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 654 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 655 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 656 | // Case 3: parent's local transform affects child and grandchild |
| 657 | gfx::Transform parent_layer_transform; |
| 658 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 659 | gfx::Transform parent_translation_to_anchor; |
| 660 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 661 | gfx::Transform parent_composite_transform = |
| 662 | parent_translation_to_anchor * parent_layer_transform * |
| 663 | Inverse(parent_translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 664 | parent->SetTransform(parent_layer_transform); |
| 665 | parent->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 666 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 667 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 668 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 669 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 670 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 671 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 672 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 673 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 674 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 675 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 676 | draw_property_utils::DrawTransform(grand_child, transform_tree, |
| 677 | effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 678 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 679 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 680 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 681 | } |
| 682 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 683 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 684 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 685 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 686 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 687 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 688 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 689 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 690 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 691 | gfx::Transform parent_translation_to_anchor; |
| 692 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 693 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 694 | gfx::Transform parent_composite_transform = |
| 695 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 696 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 697 | gfx::Vector2dF parent_composite_scale = |
| 698 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 699 | 1.f); |
| 700 | gfx::Transform surface_sublayer_transform; |
| 701 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 702 | parent_composite_scale.y()); |
| 703 | gfx::Transform surface_sublayer_composite_transform = |
| 704 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 705 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 706 | root->SetBounds(gfx::Size(1, 2)); |
| 707 | parent->SetTransform(parent_layer_transform); |
| 708 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f); |
| 709 | parent->SetBounds(gfx::Size(100, 120)); |
| 710 | child->SetBounds(gfx::Size(16, 18)); |
| 711 | child->test_properties()->force_render_surface = true; |
| 712 | grand_child->SetBounds(gfx::Size(8, 10)); |
| 713 | grand_child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 714 | ExecuteCalculateDrawProperties(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 715 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 716 | // Render surface should have been created now. |
| 717 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 718 | ASSERT_EQ(child->render_surface(), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 719 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 720 | // The child layer's draw transform should refer to its new render surface. |
| 721 | // The screen-space transform, however, should still refer to the root. |
| 722 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 723 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 724 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 725 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 726 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 727 | // Because the grand_child is the only drawable content, the child's render |
| 728 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 729 | // surface's subtree is drawn must be removed from the composite transform. |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 730 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, |
| 731 | child->render_target()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 732 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 733 | // The screen space is the same as the target since the child surface draws |
| 734 | // into the root. |
| 735 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 736 | surface_sublayer_composite_transform, |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 737 | child->render_target()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 738 | } |
| 739 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 740 | TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 741 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 742 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 743 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 744 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 745 | |
| 746 | gfx::Transform parent_transform; |
| 747 | parent_transform.Translate(10.0, 10.0); |
| 748 | |
| 749 | gfx::Transform child_transform; |
| 750 | child_transform.Rotate(45.0); |
| 751 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 752 | root->SetBounds(gfx::Size(100, 100)); |
| 753 | parent->SetTransform(parent_transform); |
| 754 | parent->SetBounds(gfx::Size(10, 10)); |
| 755 | child->SetTransform(child_transform); |
| 756 | child->SetBounds(gfx::Size(10, 10)); |
| 757 | child->test_properties()->force_render_surface = true; |
| 758 | grand_child->SetPosition(gfx::PointF(2.f, 2.f)); |
| 759 | grand_child->SetBounds(gfx::Size(20, 20)); |
| 760 | grand_child->SetDrawsContent(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 761 | |
| 762 | gfx::Transform expected_grand_child_screen_space_transform; |
| 763 | expected_grand_child_screen_space_transform.Translate(10.0, 10.0); |
| 764 | expected_grand_child_screen_space_transform.Rotate(45.0); |
| 765 | expected_grand_child_screen_space_transform.Translate(2.0, 2.0); |
| 766 | |
| 767 | // First compute draw properties with separate surfaces enabled. |
| 768 | ExecuteCalculateDrawProperties(root); |
| 769 | |
| 770 | // The grand child's draw transform should be its offset wrt the child. |
| 771 | gfx::Transform expected_grand_child_draw_transform; |
| 772 | expected_grand_child_draw_transform.Translate(2.0, 2.0); |
| 773 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 774 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 775 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 776 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 777 | |
| 778 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 779 | |
| 780 | // With separate surfaces disabled, the grand child's draw transform should be |
| 781 | // the same as its screen space transform. |
| 782 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 783 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 784 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 785 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 786 | } |
| 787 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 788 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 789 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 790 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 791 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 792 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 793 | std::unique_ptr<LayerImpl> child_replica = |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 794 | LayerImpl::Create(host_impl()->active_tree(), 100); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 795 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 796 | gfx::Transform parent_layer_transform; |
| 797 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 798 | gfx::Transform parent_translation_to_anchor; |
| 799 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 800 | gfx::Transform parent_composite_transform = |
| 801 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 802 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 803 | gfx::Transform replica_layer_transform; |
| 804 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 805 | gfx::Vector2dF parent_composite_scale = |
| 806 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 807 | 1.f); |
| 808 | gfx::Transform surface_sublayer_transform; |
| 809 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 810 | parent_composite_scale.y()); |
| 811 | gfx::Transform replica_composite_transform = |
| 812 | parent_composite_transform * replica_layer_transform * |
| 813 | Inverse(surface_sublayer_transform); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 814 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 815 | root->SetBounds(gfx::Size(1, 2)); |
| 816 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 817 | parent->SetTransform(parent_layer_transform); |
| 818 | parent->SetBounds(gfx::Size(10, 12)); |
| 819 | child->SetBounds(gfx::Size(16, 18)); |
| 820 | child->test_properties()->force_render_surface = true; |
| 821 | grand_child->SetPosition(gfx::PointF(-0.5f, -0.5f)); |
| 822 | grand_child->SetBounds(gfx::Size(1, 1)); |
| 823 | |
| 824 | child_replica->SetTransform(replica_layer_transform); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 825 | child->test_properties()->SetReplicaLayer(std::move(child_replica)); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 826 | |
| 827 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 828 | |
| 829 | // Render surface should have been created now. |
| 830 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 831 | ASSERT_EQ(child->render_surface(), child->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 832 | |
| 833 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 834 | replica_composite_transform, |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 835 | child->render_target()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 836 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 837 | child->render_target() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 838 | ->replica_screen_space_transform()); |
| 839 | } |
| 840 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 841 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 842 | // This test creates a more complex tree and verifies it all at once. This |
| 843 | // covers the following cases: |
| 844 | // - layers that are described w.r.t. a render surface: should have draw |
| 845 | // transforms described w.r.t. that surface |
| 846 | // - A render surface described w.r.t. an ancestor render surface: should |
| 847 | // have a draw transform described w.r.t. that ancestor surface |
| 848 | // - Replicas of a render surface are described w.r.t. the replica's |
| 849 | // transform around its anchor, along with the surface itself. |
| 850 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 851 | // a render surface that is described w.r.t. an ancestor render surface. |
| 852 | // - verifying that each layer has a reference to the correct render surface |
| 853 | // and render target values. |
| 854 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 855 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 856 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 857 | parent->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 858 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 859 | render_surface1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 860 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 861 | render_surface2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 862 | LayerImpl* child_of_root = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 863 | child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 864 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 865 | child_of_rs1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 866 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 867 | child_of_rs2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 868 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 869 | grand_child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 870 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 871 | grand_child_of_rs1->SetDrawsContent(true); |
| 872 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 873 | grand_child_of_rs2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 874 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 875 | std::unique_ptr<LayerImpl> replica_of_rs1 = |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 876 | LayerImpl::Create(host_impl()->active_tree(), 101); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 877 | std::unique_ptr<LayerImpl> replica_of_rs2 = |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 878 | LayerImpl::Create(host_impl()->active_tree(), 102); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 879 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 880 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 881 | // to have a new render surface. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 882 | render_surface1->test_properties()->opacity = 0.5f; |
| 883 | render_surface2->test_properties()->opacity = 0.33f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 884 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 885 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 886 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 887 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 888 | gfx::Transform translation_to_anchor; |
| 889 | translation_to_anchor.Translate(2.5, 0.0); |
| 890 | gfx::Transform layer_transform; |
| 891 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 892 | gfx::Transform replica_layer_transform; |
| 893 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 894 | |
| 895 | gfx::Transform A = |
| 896 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 897 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 898 | Inverse(translation_to_anchor); |
| 899 | |
| 900 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 901 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 902 | gfx::Transform surface1_sublayer_transform; |
| 903 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 904 | surface1_parent_transform_scale.y()); |
| 905 | |
| 906 | // SS1 = transform given to the subtree of render_surface1 |
| 907 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 908 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 909 | // the owning layer |
| 910 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 911 | |
| 912 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 913 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 914 | gfx::Transform surface2_sublayer_transform; |
| 915 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 916 | surface2_parent_transform_scale.y()); |
| 917 | |
| 918 | // SS2 = transform given to the subtree of render_surface2 |
| 919 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 920 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 921 | // the owning layer |
| 922 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 923 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 924 | root->SetBounds(gfx::Size(1, 2)); |
| 925 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f); |
| 926 | parent->SetTransform(layer_transform); |
| 927 | parent->SetBounds(gfx::Size(10, 10)); |
| 928 | render_surface1->test_properties()->transform_origin = |
| 929 | gfx::Point3F(2.5f, 0.f, 0.f); |
| 930 | render_surface1->SetTransform(layer_transform); |
| 931 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 932 | render_surface1->test_properties()->force_render_surface = true; |
| 933 | render_surface2->test_properties()->transform_origin = |
| 934 | gfx::Point3F(2.5f, 0.f, 0.f); |
| 935 | render_surface2->SetTransform(layer_transform); |
| 936 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 937 | render_surface2->test_properties()->force_render_surface = true; |
| 938 | child_of_root->test_properties()->transform_origin = |
| 939 | gfx::Point3F(2.5f, 0.f, 0.f); |
| 940 | child_of_root->SetTransform(layer_transform); |
| 941 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 942 | child_of_rs1->test_properties()->transform_origin = |
| 943 | gfx::Point3F(2.5f, 0.f, 0.f); |
| 944 | child_of_rs1->SetTransform(layer_transform); |
| 945 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 946 | child_of_rs2->test_properties()->transform_origin = |
| 947 | gfx::Point3F(2.5f, 0.f, 0.f); |
| 948 | child_of_rs2->SetTransform(layer_transform); |
| 949 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 950 | grand_child_of_root->test_properties()->transform_origin = |
| 951 | gfx::Point3F(2.5f, 0.f, 0.f); |
| 952 | grand_child_of_root->SetTransform(layer_transform); |
| 953 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 954 | grand_child_of_rs1->test_properties()->transform_origin = |
| 955 | gfx::Point3F(2.5f, 0.f, 0.f); |
| 956 | grand_child_of_rs1->SetTransform(layer_transform); |
| 957 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 958 | grand_child_of_rs2->test_properties()->transform_origin = |
| 959 | gfx::Point3F(2.5f, 0.f, 0.f); |
| 960 | grand_child_of_rs2->SetTransform(layer_transform); |
| 961 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 962 | replica_of_rs1->test_properties()->transform_origin = |
| 963 | gfx::Point3F(2.5f, 0.f, 0.f); |
| 964 | replica_of_rs1->SetTransform(replica_layer_transform); |
| 965 | replica_of_rs2->test_properties()->transform_origin = |
| 966 | gfx::Point3F(2.5f, 0.f, 0.f); |
| 967 | replica_of_rs2->SetTransform(replica_layer_transform); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 968 | |
jaydasika | 5017a33 | 2016-03-31 01:06:22 | [diff] [blame] | 969 | // We need to set parent on replica layers for property tree building. |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 970 | replica_of_rs1->test_properties()->parent = render_surface1; |
| 971 | replica_of_rs2->test_properties()->parent = render_surface2; |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 972 | render_surface1->test_properties()->SetReplicaLayer( |
| 973 | std::move(replica_of_rs1)); |
| 974 | render_surface2->test_properties()->SetReplicaLayer( |
| 975 | std::move(replica_of_rs2)); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 976 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 977 | |
| 978 | // Only layers that are associated with render surfaces should have an actual |
| 979 | // RenderSurface() value. |
| 980 | ASSERT_TRUE(root->render_surface()); |
| 981 | ASSERT_FALSE(child_of_root->render_surface()); |
| 982 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 983 | |
| 984 | ASSERT_TRUE(render_surface1->render_surface()); |
| 985 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 986 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 987 | |
| 988 | ASSERT_TRUE(render_surface2->render_surface()); |
| 989 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 990 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 991 | |
| 992 | // Verify all render target accessors |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 993 | EXPECT_EQ(root->render_surface(), parent->render_target()); |
| 994 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 995 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 996 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 997 | EXPECT_EQ(render_surface1->render_surface(), |
| 998 | render_surface1->render_target()); |
| 999 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 1000 | EXPECT_EQ(render_surface1->render_surface(), |
| 1001 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1002 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 1003 | EXPECT_EQ(render_surface2->render_surface(), |
| 1004 | render_surface2->render_target()); |
| 1005 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 1006 | EXPECT_EQ(render_surface2->render_surface(), |
| 1007 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1008 | |
| 1009 | // Verify layer draw transforms note that draw transforms are described with |
| 1010 | // respect to the nearest ancestor render surface but screen space transforms |
| 1011 | // are described with respect to the root. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1012 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform()); |
| 1013 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1014 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1015 | grand_child_of_root->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1016 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1017 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform()); |
| 1018 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1019 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1020 | grand_child_of_rs1->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1021 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1022 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform()); |
| 1023 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1024 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1025 | grand_child_of_rs2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1026 | |
| 1027 | // Verify layer screen-space transforms |
| 1028 | // |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1029 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform()); |
| 1030 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform()); |
| 1031 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
| 1032 | grand_child_of_root->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1033 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1034 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1035 | render_surface1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1036 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1037 | child_of_rs1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1038 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1039 | grand_child_of_rs1->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1040 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1041 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1042 | render_surface2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1043 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1044 | child_of_rs2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1045 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1046 | grand_child_of_rs2->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1047 | |
| 1048 | // Verify render surface transforms. |
| 1049 | // |
| 1050 | // Draw transform of render surface 1 is described with respect to root. |
| 1051 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1052 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1053 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1054 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1055 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1056 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1057 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1058 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1059 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 1060 | // Draw transform of render surface 2 is described with respect to render |
| 1061 | // surface 1. |
| 1062 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1063 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1064 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1065 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1066 | render_surface2->render_surface()->replica_draw_transform()); |
| 1067 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1068 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1069 | render_surface2->render_surface()->screen_space_transform()); |
| 1070 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1071 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1072 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 1073 | |
| 1074 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 1075 | // is expected that we correctly set up transforms so that the y-component of |
| 1076 | // the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1077 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1078 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1079 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1080 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1081 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1082 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1083 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1084 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 1085 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1086 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1087 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1088 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1089 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1090 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 1091 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1092 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1093 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1094 | } |
| 1095 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1096 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1097 | // For layers that flatten their subtree, there should be an orthographic |
| 1098 | // projection (for x and y values) in the middle of the transform sequence. |
| 1099 | // Note that the way the code is currently implemented, it is not expected to |
| 1100 | // use a canonical orthographic projection. |
| 1101 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1102 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1103 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1104 | child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1105 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1106 | grand_child->SetDrawsContent(true); |
| 1107 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 1108 | great_grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1109 | |
| 1110 | gfx::Transform rotation_about_y_axis; |
| 1111 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1112 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1113 | root->SetBounds(gfx::Size(100, 100)); |
| 1114 | child->SetTransform(rotation_about_y_axis); |
| 1115 | child->SetBounds(gfx::Size(10, 10)); |
| 1116 | child->test_properties()->force_render_surface = true; |
| 1117 | grand_child->SetTransform(rotation_about_y_axis); |
| 1118 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1119 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1120 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1121 | // No layers in this test should preserve 3d. |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1122 | ASSERT_TRUE(root->test_properties()->should_flatten_transform); |
| 1123 | ASSERT_TRUE(child->test_properties()->should_flatten_transform); |
| 1124 | ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform); |
| 1125 | ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1126 | |
| 1127 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1128 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1129 | gfx::Transform expected_grand_child_draw_transform = |
| 1130 | rotation_about_y_axis; // draws onto child's render surface |
| 1131 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1132 | flattened_rotation_about_y.FlattenTo2d(); |
| 1133 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1134 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1135 | gfx::Transform expected_great_grand_child_draw_transform = |
| 1136 | flattened_rotation_about_y; |
| 1137 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 1138 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1139 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1140 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1141 | |
| 1142 | // The child's draw transform should have been taken by its surface. |
| 1143 | ASSERT_TRUE(child->render_surface()); |
| 1144 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1145 | child->render_surface()->draw_transform()); |
| 1146 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1147 | expected_child_screen_space_transform, |
| 1148 | child->render_surface()->screen_space_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1149 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1150 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1151 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1152 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1153 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1154 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1155 | grand_child->ScreenSpaceTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1156 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1157 | great_grand_child->DrawTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1158 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1159 | expected_great_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1160 | great_grand_child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1161 | } |
| 1162 | |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1163 | TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1164 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1165 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1166 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1167 | |
| 1168 | gfx::Transform child_transform; |
| 1169 | child_transform.Translate(50.0, 50.0); |
| 1170 | child_transform.RotateAboutZAxis(30.0); |
| 1171 | |
| 1172 | gfx::Transform grand_child_transform; |
| 1173 | grand_child_transform.RotateAboutYAxis(90.0); |
| 1174 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1175 | root->SetBounds(gfx::Size(200, 200)); |
| 1176 | child->SetTransform(child_transform); |
| 1177 | child->SetBounds(gfx::Size(10, 10)); |
| 1178 | grand_child->SetTransform(grand_child_transform); |
| 1179 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1180 | grand_child->test_properties()->should_flatten_transform = false; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1181 | grand_child->SetDrawsContent(true); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1182 | ExecuteCalculateDrawProperties(root); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1183 | |
| 1184 | // Mapping grand_child's bounds to target space produces a non-empty rect |
| 1185 | // that is fully contained within the target's bounds, so grand_child should |
| 1186 | // be considered fully visible. |
| 1187 | EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1188 | grand_child->visible_layer_rect()); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1189 | } |
| 1190 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1191 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1192 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1193 | // skipping a necessary translation. Without that translation, the coordinate |
| 1194 | // space of the layer's draw transform is incorrect. |
| 1195 | // |
| 1196 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1197 | // but if that layer becomes a render surface, then its draw transform is |
| 1198 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1199 | // incorrectly as a result. |
| 1200 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1201 | LayerImpl* root = root_layer_for_testing(); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1202 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1203 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1204 | grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1205 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1206 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1207 | // The child height is zero, but has non-zero width that should be accounted |
| 1208 | // for while computing draw transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1209 | child->SetBounds(gfx::Size(10, 0)); |
| 1210 | child->test_properties()->force_render_surface = true; |
| 1211 | grand_child->SetBounds(gfx::Size(10, 10)); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1212 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1213 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1214 | ASSERT_TRUE(child->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1215 | // This is the real test, the rest are sanity checks. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1216 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1217 | child->render_surface()->draw_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1218 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1219 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1220 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1221 | } |
| 1222 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1223 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1224 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1225 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 1226 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 1227 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1228 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1229 | gfx::Transform translate; |
| 1230 | translate.Translate3d(5, 5, 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1231 | |
| 1232 | root->SetBounds(gfx::Size(100, 100)); |
| 1233 | render_surface->SetTransform(translate); |
| 1234 | render_surface->SetBounds(gfx::Size(100, 100)); |
| 1235 | render_surface->test_properties()->force_render_surface = true; |
| 1236 | child->SetTransform(translate); |
| 1237 | child->SetBounds(gfx::Size(100, 100)); |
| 1238 | grand_child->SetTransform(translate); |
| 1239 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1240 | grand_child->SetDrawsContent(true); |
| 1241 | |
| 1242 | // render_surface will have a sublayer scale because of device scale factor. |
| 1243 | float device_scale_factor = 2.0f; |
| 1244 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1245 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1246 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1247 | inputs.device_scale_factor = device_scale_factor; |
| 1248 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1249 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1250 | |
| 1251 | // Between grand_child and render_surface, we translate by (10, 10) and scale |
| 1252 | // by a factor of 2. |
| 1253 | gfx::Vector2dF expected_translation(20.0f, 20.0f); |
| 1254 | EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(), |
| 1255 | expected_translation); |
| 1256 | } |
| 1257 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1258 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1259 | // Transformations applied at the root of the tree should be forwarded |
| 1260 | // to child layers instead of applied to the root RenderSurface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1261 | LayerImpl* root = root_layer_for_testing(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1262 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1263 | |
| 1264 | root->SetDrawsContent(true); |
| 1265 | root->SetBounds(gfx::Size(20, 20)); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1266 | child->SetDrawsContent(true); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1267 | child->SetScrollClipLayer(root->id()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1268 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1269 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1270 | gfx::Transform translate; |
| 1271 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1272 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1273 | LayerImplList render_surface_layer_list_impl; |
| 1274 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1275 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1276 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1277 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1278 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1279 | translate, root->draw_properties().target_space_transform); |
| 1280 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1281 | translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1282 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1283 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1284 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1285 | |
| 1286 | gfx::Transform scale; |
| 1287 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1288 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1289 | LayerImplList render_surface_layer_list_impl; |
| 1290 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1291 | root, root->bounds(), scale, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1292 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1293 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1294 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1295 | scale, root->draw_properties().target_space_transform); |
| 1296 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1297 | scale, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1298 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1299 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1300 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1301 | |
| 1302 | gfx::Transform rotate; |
| 1303 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1304 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1305 | LayerImplList render_surface_layer_list_impl; |
| 1306 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1307 | root, root->bounds(), rotate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1308 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1309 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1310 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1311 | rotate, root->draw_properties().target_space_transform); |
| 1312 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1313 | rotate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1314 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1315 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1316 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1317 | |
| 1318 | gfx::Transform composite; |
| 1319 | composite.ConcatTransform(translate); |
| 1320 | composite.ConcatTransform(scale); |
| 1321 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1322 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1323 | LayerImplList render_surface_layer_list_impl; |
| 1324 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1325 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1326 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1327 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1328 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1329 | composite, root->draw_properties().target_space_transform); |
| 1330 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1331 | composite, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1332 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1333 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1334 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1335 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1336 | // Verify it composes correctly with device scale. |
| 1337 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1338 | |
| 1339 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1340 | LayerImplList render_surface_layer_list_impl; |
| 1341 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1342 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1343 | inputs.device_scale_factor = device_scale_factor; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1344 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1345 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1346 | gfx::Transform device_scaled_translate = translate; |
| 1347 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1348 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1349 | device_scaled_translate, |
| 1350 | root->draw_properties().target_space_transform); |
| 1351 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1352 | device_scaled_translate, |
| 1353 | child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1354 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1355 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1356 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1357 | |
| 1358 | // Verify it composes correctly with page scale. |
| 1359 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1360 | |
| 1361 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1362 | LayerImplList render_surface_layer_list_impl; |
| 1363 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1364 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1365 | inputs.page_scale_factor = page_scale_factor; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1366 | inputs.page_scale_layer = root; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1367 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1368 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1369 | gfx::Transform page_scaled_translate = translate; |
| 1370 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1371 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1372 | page_scaled_translate, root->draw_properties().target_space_transform); |
| 1373 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1374 | page_scaled_translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1375 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1376 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1377 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1378 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1379 | // Verify that it composes correctly with transforms directly on root layer. |
| 1380 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1381 | |
| 1382 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1383 | LayerImplList render_surface_layer_list_impl; |
| 1384 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1385 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1386 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1387 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1388 | gfx::Transform compositeSquared = composite; |
| 1389 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1390 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1391 | compositeSquared, root->draw_properties().target_space_transform); |
| 1392 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1393 | compositeSquared, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1394 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1395 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1396 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1397 | } |
| 1398 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1399 | TEST_F(LayerTreeHostCommonTest, |
| 1400 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1401 | LayerImpl* root = root_layer_for_testing(); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1402 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1403 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1404 | |
| 1405 | root->SetBounds(gfx::Size(10, 10)); |
| 1406 | root->SetMasksToBounds(true); |
| 1407 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1408 | render_surface1->test_properties()->force_render_surface = true; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1409 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1410 | child->SetPosition(gfx::PointF(30.f, 30.f)); |
| 1411 | child->SetBounds(gfx::Size(10, 10)); |
| 1412 | ExecuteCalculateDrawProperties(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1413 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1414 | // 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] | 1415 | // the intermediate render surface should not be listed here, even if it was |
| 1416 | // forced to be created. Render surfaces without children or visible content |
| 1417 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1418 | // of size 0). |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1419 | ASSERT_TRUE(root->render_surface()); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1420 | EXPECT_EQ(1U, render_surface_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1421 | } |
| 1422 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1423 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1424 | LayerImpl* root = root_layer_for_testing(); |
| 1425 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1426 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1427 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 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; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1431 | child->SetBounds(gfx::Size(10, 10)); |
| 1432 | child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1433 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1434 | LayerImplList render_surface_layer_list; |
| 1435 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1436 | root, root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1437 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1438 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1439 | |
| 1440 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1441 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1442 | // have been extended by the children. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1443 | ASSERT_TRUE(root->render_surface()); |
| 1444 | EXPECT_EQ(0U, root->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1445 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1446 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 1447 | EXPECT_EQ(gfx::Rect(), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1448 | } |
| 1449 | |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1450 | TEST_F(LayerTreeHostCommonTest, |
| 1451 | RenderSurfaceListForTransparentChildWithBackgroundFilter) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1452 | LayerImpl* root = root_layer_for_testing(); |
| 1453 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1454 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1455 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1456 | root->SetBounds(gfx::Size(10, 10)); |
| 1457 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1458 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1459 | render_surface1->test_properties()->opacity = 0.f; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 1460 | render_surface1->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1461 | FilterOperations filters; |
| 1462 | filters.Append(FilterOperation::CreateBlurFilter(1.5f)); |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 1463 | render_surface1->test_properties()->background_filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1464 | child->SetBounds(gfx::Size(10, 10)); |
| 1465 | child->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1466 | |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1467 | { |
| 1468 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1469 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1470 | root, root->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1471 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1472 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1473 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1474 | } |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1475 | // The layer is fully transparent, but has a background filter, so it |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1476 | // shouldn't be skipped and should be drawn. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1477 | ASSERT_TRUE(root->render_surface()); |
| 1478 | EXPECT_EQ(1U, root->render_surface()->layer_list().size()); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1479 | EXPECT_EQ(gfx::RectF(0, 0, 10, 10), |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1480 | root->render_surface()->DrawableContentRect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1481 | EffectTree& effect_tree = |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1482 | root->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1483 | EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1484 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1485 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1486 | // When root is transparent, the layer should not be drawn. |
| 1487 | root->OnOpacityAnimated(0.f); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1488 | render_surface1->OnOpacityAnimated(1.f); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1489 | render_surface1->set_visible_layer_rect(gfx::Rect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1490 | { |
| 1491 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1492 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1493 | root, root->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1494 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1495 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1499 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1500 | EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect()); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1501 | } |
| 1502 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1503 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1504 | LayerImpl* root = root_layer_for_testing(); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1505 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1506 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1507 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1508 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1509 | gfx::Transform scale_matrix; |
| 1510 | scale_matrix.Scale(2.0f, 2.0f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1511 | |
| 1512 | root->SetBounds(gfx::Size(100, 100)); |
| 1513 | parent->SetTransform(scale_matrix); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1514 | FilterOperations filters; |
| 1515 | filters.Append(FilterOperation::CreateBlurFilter(10.0f)); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1516 | parent->test_properties()->filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1517 | parent->test_properties()->force_render_surface = true; |
| 1518 | child1->SetBounds(gfx::Size(25, 25)); |
| 1519 | child1->SetDrawsContent(true); |
| 1520 | child1->test_properties()->force_render_surface = true; |
| 1521 | child2->SetPosition(gfx::PointF(25, 25)); |
| 1522 | child2->SetBounds(gfx::Size(25, 25)); |
| 1523 | child2->SetDrawsContent(true); |
| 1524 | child2->test_properties()->force_render_surface = true; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1525 | |
| 1526 | LayerImplList render_surface_layer_list; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1527 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1528 | root, root->bounds(), &render_surface_layer_list); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1529 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1530 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1531 | |
| 1532 | ASSERT_TRUE(parent->render_surface()); |
| 1533 | EXPECT_EQ(2U, parent->render_surface()->layer_list().size()); |
| 1534 | EXPECT_EQ(4U, render_surface_layer_list.size()); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1535 | |
| 1536 | // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the |
| 1537 | // blur (-30,-30 110x110), and then scaled by the scale matrix |
| 1538 | // (-60,-60 220x220). |
| 1539 | EXPECT_EQ(gfx::RectF(-60, -60, 220, 220), |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1540 | parent->render_surface()->DrawableContentRect()); |
| 1541 | } |
| 1542 | |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1543 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1544 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1545 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1546 | |
| 1547 | root->SetBounds(gfx::Size(100, 100)); |
| 1548 | child->SetBounds(gfx::Size(25, 25)); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1549 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1550 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1551 | FilterOperations filters; |
| 1552 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1553 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1554 | child->test_properties()->filters = filters; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1555 | ExecuteCalculateDrawProperties(root); |
| 1556 | |
| 1557 | // The render surface's size should be unaffected by the offset image filter; |
| 1558 | // it need only have a drawable content rect large enough to contain the |
| 1559 | // contents (at the new offset). |
| 1560 | ASSERT_TRUE(child->render_surface()); |
| 1561 | EXPECT_EQ(gfx::RectF(50, 50, 25, 25), |
| 1562 | child->render_surface()->DrawableContentRect()); |
| 1563 | } |
| 1564 | |
| 1565 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) { |
| 1566 | const float device_scale_factor = 2.0f; |
| 1567 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1568 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1569 | LayerImpl* child = AddChild<LayerImpl>(root); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1570 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1571 | root->SetBounds(gfx::Size(100, 100)); |
| 1572 | child->SetBounds(gfx::Size(25, 25)); |
| 1573 | child->SetDrawsContent(true); |
| 1574 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1575 | |
| 1576 | FilterOperations filters; |
| 1577 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1578 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1579 | child->test_properties()->filters = filters; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1580 | |
| 1581 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 1582 | |
| 1583 | // The render surface's size should be unaffected by the offset image filter; |
| 1584 | // it need only have a drawable content rect large enough to contain the |
| 1585 | // contents (at the new offset). All coordinates should be scaled by 2, |
| 1586 | // corresponding to the device scale factor. |
| 1587 | ASSERT_TRUE(child->render_surface()); |
| 1588 | EXPECT_EQ(gfx::RectF(100, 100, 50, 50), |
| 1589 | child->render_surface()->DrawableContentRect()); |
| 1590 | } |
| 1591 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1592 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1593 | LayerImpl* root = root_layer_for_testing(); |
| 1594 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1595 | |
| 1596 | root->SetBounds(gfx::Size(10, 10)); |
| 1597 | child->SetBounds(gfx::Size(10, 10)); |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1598 | child->SetDrawsContent(true); |
ajuma | 4c14b25 | 2016-07-26 20:10:59 | [diff] [blame] | 1599 | child->test_properties()->blend_mode = SkXfermode::kMultiply_Mode; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1600 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1601 | child->test_properties()->force_render_surface = true; |
| 1602 | ExecuteCalculateDrawProperties(root); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1603 | |
| 1604 | // Since the child layer has a blend mode other than normal, it should get |
| 1605 | // its own render surface. Also, layer's draw_properties should contain the |
| 1606 | // default blend mode, since the render surface becomes responsible for |
| 1607 | // applying the blend mode. |
| 1608 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1609 | EXPECT_EQ(1.0f, child->draw_opacity()); |
| 1610 | EXPECT_EQ(0.5f, child->render_surface()->draw_opacity()); |
jaydasika | 92239dc | 2015-08-15 02:59:26 | [diff] [blame] | 1611 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode()); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1612 | } |
| 1613 | |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1614 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1615 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1616 | LayerImpl* surface1 = AddChildToRoot<LayerImpl>(); |
| 1617 | LayerImpl* not_surface = AddChild<LayerImpl>(surface1); |
| 1618 | LayerImpl* surface2 = AddChild<LayerImpl>(not_surface); |
| 1619 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1620 | root->SetBounds(gfx::Size(10, 10)); |
| 1621 | surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1622 | surface1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1623 | surface1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1624 | surface1->test_properties()->force_render_surface = true; |
| 1625 | not_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1626 | not_surface->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1627 | surface2->SetBounds(gfx::Size(10, 10)); |
| 1628 | surface2->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1629 | surface2->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1630 | surface2->test_properties()->force_render_surface = true; |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1631 | ExecuteCalculateDrawProperties(root); |
| 1632 | |
| 1633 | ASSERT_TRUE(surface1->render_surface()); |
| 1634 | ASSERT_FALSE(not_surface->render_surface()); |
| 1635 | ASSERT_TRUE(surface2->render_surface()); |
| 1636 | EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); |
| 1637 | // surface2's draw opacity should include the opacity of not-surface and |
| 1638 | // itself, but not the opacity of surface1. |
| 1639 | EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); |
| 1640 | } |
| 1641 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1642 | TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) { |
| 1643 | // Tests that when separate surfaces are disabled, a layer's draw opacity is |
| 1644 | // the product of all ancestor layer opacties and the layer's own opacity. |
| 1645 | // (Rendering will still be incorrect in situations where we really do need |
| 1646 | // surfaces to apply opacity, such as when we have overlapping layers with an |
| 1647 | // ancestor whose opacity is <1.) |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1648 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1649 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1650 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1651 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1652 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1653 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1654 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1655 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1656 | root->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1657 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1658 | parent->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1659 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1660 | child1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1661 | child1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1662 | child1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1663 | child1->test_properties()->force_render_surface = true; |
| 1664 | child2->SetBounds(gfx::Size(100, 100)); |
| 1665 | child2->SetDrawsContent(true); |
| 1666 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 1667 | grand_child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1668 | grand_child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1669 | grand_child->test_properties()->force_render_surface = true; |
| 1670 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
| 1671 | leaf_node1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1672 | leaf_node1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1673 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
| 1674 | leaf_node2->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1675 | leaf_node2->test_properties()->opacity = 0.5f; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1676 | |
| 1677 | // With surfaces enabled, each layer's draw opacity is the product of layer |
| 1678 | // opacities on the path from the layer to its render target, not including |
| 1679 | // the opacity of the layer that owns the target surface (since that opacity |
| 1680 | // is applied by the surface). |
| 1681 | ExecuteCalculateDrawProperties(root); |
| 1682 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1683 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1684 | EXPECT_EQ(1.f, child1->draw_opacity()); |
| 1685 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1686 | EXPECT_EQ(1.f, grand_child->draw_opacity()); |
| 1687 | EXPECT_EQ(0.5f, leaf_node1->draw_opacity()); |
| 1688 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1689 | |
| 1690 | // With surfaces disabled, each layer's draw opacity is the product of layer |
| 1691 | // opacities on the path from the layer to the root. |
| 1692 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1693 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1694 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1695 | EXPECT_EQ(0.5f, child1->draw_opacity()); |
| 1696 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1697 | EXPECT_EQ(0.25f, grand_child->draw_opacity()); |
| 1698 | EXPECT_EQ(0.125f, leaf_node1->draw_opacity()); |
| 1699 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1700 | } |
| 1701 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1702 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1703 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1704 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1705 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1706 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1707 | root->SetBounds(gfx::Size(10, 10)); |
| 1708 | render_surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1709 | render_surface1->test_properties()->force_render_surface = true; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1710 | child->SetBounds(gfx::Size(10, 10)); |
| 1711 | child->SetDrawsContent(true); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1712 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1713 | { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1714 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1715 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1716 | // The root layer always creates a render surface |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1717 | EXPECT_TRUE(root->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1718 | EXPECT_TRUE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1719 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1720 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1721 | { |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1722 | render_surface1->test_properties()->force_render_surface = false; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1723 | render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1724 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root); |
| 1725 | EXPECT_TRUE(root->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1726 | EXPECT_FALSE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1727 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1728 | } |
| 1729 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1730 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1731 | // Render surfaces act as a flattening point for their subtree, so should |
| 1732 | // always flatten the target-to-screen space transform seen by descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1733 | LayerImpl* root = root_layer_for_testing(); |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1734 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1735 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1736 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1737 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1738 | gfx::Transform rotation_about_y_axis; |
| 1739 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1740 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1741 | root->SetBounds(gfx::Size(100, 100)); |
| 1742 | parent->SetTransform(rotation_about_y_axis); |
| 1743 | parent->SetBounds(gfx::Size(10, 10)); |
| 1744 | parent->test_properties()->force_render_surface = true; |
| 1745 | child->SetBounds(gfx::Size(10, 10)); |
| 1746 | child->SetDrawsContent(true); |
| 1747 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1748 | grand_child->SetDrawsContent(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1749 | grand_child->test_properties()->should_flatten_transform = false; |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1750 | ExecuteCalculateDrawProperties(root); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1751 | |
| 1752 | EXPECT_TRUE(parent->render_surface()); |
| 1753 | EXPECT_FALSE(child->render_surface()); |
| 1754 | EXPECT_FALSE(grand_child->render_surface()); |
| 1755 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1756 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1757 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1758 | grand_child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1759 | |
| 1760 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1761 | // have been flattened at their render target. In particular, the fact that |
| 1762 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1763 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1764 | flattened_rotation_about_y.FlattenTo2d(); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1765 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1766 | child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1767 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1768 | grand_child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1769 | } |
| 1770 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1771 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1772 | // The entire subtree of layers that are outside the clip rect should be |
| 1773 | // culled away, and should not affect the render_surface_layer_list. |
| 1774 | // |
| 1775 | // The test tree is set up as follows: |
| 1776 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1777 | // that have something to draw. |
| 1778 | // - parent is a large container layer. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1779 | // - child has MasksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1780 | // - grand_child is positioned outside of the child's bounds |
| 1781 | // - great_grand_child is also kept outside child's bounds. |
| 1782 | // |
| 1783 | // In this configuration, grand_child and great_grand_child are completely |
| 1784 | // outside the clip rect, and they should never get scheduled on the list of |
| 1785 | // render surfaces. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1786 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1787 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1788 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1789 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1790 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1791 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1792 | // leaf_node1 ensures that root and child are kept on the |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1793 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1794 | // should be clipped. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1795 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(child); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1796 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1797 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1798 | root->SetBounds(gfx::Size(500, 500)); |
| 1799 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1800 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1801 | child->test_properties()->force_render_surface = true; |
| 1802 | grand_child->SetPosition(gfx::PointF(45.f, 45.f)); |
| 1803 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1804 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
| 1805 | leaf_node1->SetBounds(gfx::Size(500, 500)); |
| 1806 | leaf_node1->SetDrawsContent(true); |
| 1807 | leaf_node1->SetBounds(gfx::Size(20, 20)); |
| 1808 | leaf_node2->SetDrawsContent(true); |
| 1809 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1810 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1811 | ASSERT_EQ(2U, render_surface_layer_list_impl()->size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1812 | EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id()); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1813 | EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1814 | } |
| 1815 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1816 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1817 | // 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] | 1818 | // of the surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1819 | |
| 1820 | // The test tree is set up as follows: |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1821 | // - root is a container layer that masksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1822 | // - 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] | 1823 | // the root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1824 | // - grand_child is a render surface, and the only visible content in child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1825 | // It is positioned outside of the clip rect from root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1826 | |
| 1827 | // In this configuration, grand_child should be outside the clipped |
| 1828 | // content rect of the child, making grand_child not appear in the |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1829 | // render_surface_layer_list. |
| 1830 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1831 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1832 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1833 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1834 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1835 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1836 | root->SetMasksToBounds(true); |
| 1837 | root->SetBounds(gfx::Size(100, 100)); |
| 1838 | child->SetBounds(gfx::Size(20, 20)); |
| 1839 | child->test_properties()->force_render_surface = true; |
| 1840 | grand_child->SetPosition(gfx::PointF(200.f, 200.f)); |
| 1841 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1842 | grand_child->test_properties()->force_render_surface = true; |
| 1843 | leaf_node->SetBounds(gfx::Size(10, 10)); |
| 1844 | leaf_node->SetDrawsContent(true); |
| 1845 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1846 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1847 | // We should cull child and grand_child from the |
| 1848 | // render_surface_layer_list. |
| 1849 | ASSERT_EQ(1U, render_surface_layer_list_impl()->size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1850 | EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1851 | } |
| 1852 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1853 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) { |
| 1854 | // Tests that LayerImpl's IsClipped() property is set to true when: |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1855 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1856 | // - the layer is clipped by an ancestor that contributes to the same |
| 1857 | // render target, |
| 1858 | // - a surface is clipped by an ancestor that contributes to the same |
| 1859 | // render target. |
| 1860 | // |
| 1861 | // In particular, for a layer that owns a render surface: |
| 1862 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1863 | // pass that clipped status to the layer itself. |
| 1864 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1865 | // and propagates the clip to the subtree. |
| 1866 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1867 | LayerImpl* root = root_layer_for_testing(); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1868 | LayerImpl* parent = AddChild<LayerImpl>(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1869 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1870 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1871 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1872 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1873 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1874 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1875 | root->SetBounds(gfx::Size(100, 100)); |
| 1876 | parent->SetBounds(gfx::Size(100, 100)); |
| 1877 | parent->SetDrawsContent(true); |
| 1878 | child1->SetBounds(gfx::Size(100, 100)); |
| 1879 | child1->SetDrawsContent(true); |
| 1880 | child2->SetBounds(gfx::Size(100, 100)); |
| 1881 | child2->SetDrawsContent(true); |
| 1882 | child2->test_properties()->force_render_surface = true; |
| 1883 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 1884 | grand_child->SetDrawsContent(true); |
| 1885 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
| 1886 | leaf_node1->SetDrawsContent(true); |
| 1887 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
| 1888 | leaf_node2->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1889 | |
| 1890 | // Case 1: nothing is clipped except the root render surface. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1891 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1892 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1893 | ASSERT_TRUE(root->render_surface()); |
| 1894 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1895 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1896 | EXPECT_FALSE(root->is_clipped()); |
| 1897 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1898 | EXPECT_FALSE(parent->is_clipped()); |
| 1899 | EXPECT_FALSE(child1->is_clipped()); |
| 1900 | EXPECT_FALSE(child2->is_clipped()); |
| 1901 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1902 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1903 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1904 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1905 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1906 | // Case 2: parent MasksToBounds, so the parent, child1, and child2's |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1907 | // surface are clipped. But layers that contribute to child2's surface are |
| 1908 | // not clipped explicitly because child2's surface already accounts for |
| 1909 | // that clip. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1910 | parent->SetMasksToBounds(true); |
| 1911 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1912 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1913 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1914 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1915 | ASSERT_TRUE(root->render_surface()); |
| 1916 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1917 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1918 | EXPECT_FALSE(root->is_clipped()); |
| 1919 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1920 | EXPECT_TRUE(parent->is_clipped()); |
| 1921 | EXPECT_TRUE(child1->is_clipped()); |
| 1922 | EXPECT_FALSE(child2->is_clipped()); |
| 1923 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1924 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1925 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1926 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1927 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1928 | parent->SetMasksToBounds(false); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1929 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1930 | // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1931 | // child2's render surface is not clipped. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1932 | child2->SetMasksToBounds(true); |
| 1933 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1934 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1935 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1936 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1937 | ASSERT_TRUE(root->render_surface()); |
| 1938 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1939 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1940 | EXPECT_FALSE(root->is_clipped()); |
| 1941 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1942 | EXPECT_FALSE(parent->is_clipped()); |
| 1943 | EXPECT_FALSE(child1->is_clipped()); |
| 1944 | EXPECT_TRUE(child2->is_clipped()); |
| 1945 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1946 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1947 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1948 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1949 | } |
| 1950 | |
| 1951 | TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) { |
| 1952 | // Tests that when as long as layer is clipped, it's clip rect is set to |
| 1953 | // correct value. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1954 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1955 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1956 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1957 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1958 | root->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1959 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1960 | parent->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1961 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1962 | child->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1963 | child->SetDrawsContent(true); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1964 | child->SetMasksToBounds(true); |
| 1965 | |
| 1966 | ExecuteCalculateDrawProperties(root); |
| 1967 | |
| 1968 | EXPECT_FALSE(root->is_clipped()); |
| 1969 | EXPECT_FALSE(parent->is_clipped()); |
| 1970 | EXPECT_TRUE(child->is_clipped()); |
| 1971 | EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect()); |
| 1972 | |
| 1973 | parent->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1974 | child->SetPosition(gfx::PointF(100.f, 100.f)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1975 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1976 | |
| 1977 | ExecuteCalculateDrawProperties(root); |
| 1978 | |
| 1979 | EXPECT_FALSE(root->is_clipped()); |
| 1980 | EXPECT_TRUE(parent->is_clipped()); |
| 1981 | EXPECT_TRUE(child->is_clipped()); |
| 1982 | EXPECT_EQ(gfx::Rect(), child->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1983 | } |
| 1984 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1985 | TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { |
| 1986 | // Tests that when separate surfaces are disabled, is_clipped is true exactly |
| 1987 | // when a layer or its ancestor has a clip; in particular, if a layer |
| 1988 | // is_clipped, so is its entire subtree (since there are no render surfaces |
| 1989 | // that can reset is_clipped). |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1990 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1991 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1992 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1993 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1994 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1995 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1996 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1997 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1998 | root->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1999 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2000 | parent->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2001 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2002 | child1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2003 | child1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2004 | child1->test_properties()->force_render_surface = true; |
| 2005 | child2->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2006 | child2->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2007 | grand_child->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2008 | grand_child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2009 | grand_child->test_properties()->force_render_surface = true; |
| 2010 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2011 | leaf_node1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2012 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2013 | leaf_node2->SetDrawsContent(true); |
| 2014 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2015 | // Case 1: Nothing is clipped. In this case, is_clipped is always false, with |
| 2016 | // or without surfaces. |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2017 | ExecuteCalculateDrawProperties(root); |
| 2018 | EXPECT_FALSE(root->is_clipped()); |
| 2019 | EXPECT_FALSE(parent->is_clipped()); |
| 2020 | EXPECT_FALSE(child1->is_clipped()); |
| 2021 | EXPECT_FALSE(child2->is_clipped()); |
| 2022 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2023 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2024 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2025 | |
| 2026 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2027 | EXPECT_FALSE(root->is_clipped()); |
| 2028 | EXPECT_FALSE(parent->is_clipped()); |
| 2029 | EXPECT_FALSE(child1->is_clipped()); |
| 2030 | EXPECT_FALSE(child2->is_clipped()); |
| 2031 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2032 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2033 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2034 | |
| 2035 | // Case 2: The root is clipped. With surfaces, this only persists until the |
| 2036 | // next render surface. Without surfaces, the entire tree is clipped. |
| 2037 | root->SetMasksToBounds(true); |
| 2038 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2039 | ExecuteCalculateDrawProperties(root); |
| 2040 | EXPECT_TRUE(root->is_clipped()); |
| 2041 | EXPECT_TRUE(parent->is_clipped()); |
| 2042 | EXPECT_FALSE(child1->is_clipped()); |
| 2043 | EXPECT_TRUE(child2->is_clipped()); |
| 2044 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2045 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2046 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2047 | |
| 2048 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2049 | EXPECT_TRUE(root->is_clipped()); |
| 2050 | EXPECT_TRUE(parent->is_clipped()); |
| 2051 | EXPECT_TRUE(child1->is_clipped()); |
| 2052 | EXPECT_TRUE(child2->is_clipped()); |
| 2053 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2054 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2055 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2056 | |
| 2057 | root->SetMasksToBounds(false); |
| 2058 | |
| 2059 | // Case 3: The parent is clipped. Again, with surfaces, this only persists |
| 2060 | // until the next render surface. Without surfaces, parent's entire subtree is |
| 2061 | // clipped. |
| 2062 | parent->SetMasksToBounds(true); |
| 2063 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2064 | ExecuteCalculateDrawProperties(root); |
| 2065 | EXPECT_FALSE(root->is_clipped()); |
| 2066 | EXPECT_TRUE(parent->is_clipped()); |
| 2067 | EXPECT_FALSE(child1->is_clipped()); |
| 2068 | EXPECT_TRUE(child2->is_clipped()); |
| 2069 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2070 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2071 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2072 | |
| 2073 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2074 | EXPECT_FALSE(root->is_clipped()); |
| 2075 | EXPECT_TRUE(parent->is_clipped()); |
| 2076 | EXPECT_TRUE(child1->is_clipped()); |
| 2077 | EXPECT_TRUE(child2->is_clipped()); |
| 2078 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2079 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2080 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2081 | |
| 2082 | parent->SetMasksToBounds(false); |
| 2083 | |
| 2084 | // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it |
| 2085 | // has no non-surface children. Without surfaces, child1's entire subtree is |
| 2086 | // clipped. |
| 2087 | child1->SetMasksToBounds(true); |
| 2088 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2089 | ExecuteCalculateDrawProperties(root); |
| 2090 | EXPECT_FALSE(root->is_clipped()); |
| 2091 | EXPECT_FALSE(parent->is_clipped()); |
| 2092 | EXPECT_TRUE(child1->is_clipped()); |
| 2093 | EXPECT_FALSE(child2->is_clipped()); |
| 2094 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2095 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2096 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2097 | |
| 2098 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2099 | EXPECT_FALSE(root->is_clipped()); |
| 2100 | EXPECT_FALSE(parent->is_clipped()); |
| 2101 | EXPECT_TRUE(child1->is_clipped()); |
| 2102 | EXPECT_FALSE(child2->is_clipped()); |
| 2103 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2104 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2105 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2106 | |
| 2107 | child1->SetMasksToBounds(false); |
| 2108 | |
| 2109 | // Case 5: Only the leaf nodes are clipped. The behavior with and without |
| 2110 | // surfaces is the same. |
| 2111 | leaf_node1->SetMasksToBounds(true); |
| 2112 | leaf_node2->SetMasksToBounds(true); |
| 2113 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2114 | ExecuteCalculateDrawProperties(root); |
| 2115 | EXPECT_FALSE(root->is_clipped()); |
| 2116 | EXPECT_FALSE(parent->is_clipped()); |
| 2117 | EXPECT_FALSE(child1->is_clipped()); |
| 2118 | EXPECT_FALSE(child2->is_clipped()); |
| 2119 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2120 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2121 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2122 | |
| 2123 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2124 | EXPECT_FALSE(root->is_clipped()); |
| 2125 | EXPECT_FALSE(parent->is_clipped()); |
| 2126 | EXPECT_FALSE(child1->is_clipped()); |
| 2127 | EXPECT_FALSE(child2->is_clipped()); |
| 2128 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2129 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2130 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2131 | } |
| 2132 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 2133 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2134 | // Verify that layers get the appropriate DrawableContentRect when their |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2135 | // parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2136 | // |
| 2137 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 2138 | // be the layer rect expressed in target space. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2139 | // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2140 | // will be the intersection of layer bounds and the mask region. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2141 | // grand_child3 - partially clipped and MasksToBounds; the |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2142 | // DrawableContentRect will still be the intersection of layer bounds and |
| 2143 | // the mask region. |
| 2144 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 2145 | // be empty. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2146 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2147 | LayerImpl* parent = root_layer_for_testing(); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2148 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2149 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2150 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2151 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2152 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2153 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2154 | parent->SetBounds(gfx::Size(500, 500)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2155 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2156 | child->SetBounds(gfx::Size(20, 20)); |
| 2157 | child->test_properties()->force_render_surface = true; |
| 2158 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2159 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 2160 | grand_child1->SetDrawsContent(true); |
| 2161 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2162 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 2163 | grand_child2->SetDrawsContent(true); |
| 2164 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2165 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2166 | grand_child3->SetBounds(gfx::Size(10, 10)); |
| 2167 | grand_child3->SetDrawsContent(true); |
| 2168 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 2169 | grand_child4->SetBounds(gfx::Size(10, 10)); |
| 2170 | grand_child4->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2171 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2172 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2173 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2174 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2175 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2176 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2177 | } |
| 2178 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2179 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2180 | // Verify that render surfaces (and their layers) get the appropriate |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2181 | // clip rects when their parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2182 | // |
| 2183 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2184 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2185 | // They may still have a clip rect of their own layer bounds, however, if |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2186 | // MasksToBounds was true. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2187 | LayerImpl* parent = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2188 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2189 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2190 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2191 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2192 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2193 | // The leaf nodes ensure that these grand_children become render surfaces for |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2194 | // this test. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2195 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2196 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2197 | LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2198 | LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2199 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2200 | parent->SetBounds(gfx::Size(500, 500)); |
| 2201 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2202 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2203 | child->test_properties()->force_render_surface = true; |
| 2204 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2205 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 2206 | grand_child1->test_properties()->force_render_surface = true; |
| 2207 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2208 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 2209 | grand_child2->test_properties()->force_render_surface = true; |
| 2210 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2211 | grand_child3->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2212 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2213 | grand_child3->test_properties()->force_render_surface = true; |
| 2214 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 2215 | grand_child4->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2216 | grand_child4->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2217 | grand_child4->test_properties()->force_render_surface = true; |
| 2218 | leaf_node1->SetBounds(gfx::Size(10, 10)); |
| 2219 | leaf_node1->SetDrawsContent(true); |
| 2220 | leaf_node2->SetBounds(gfx::Size(10, 10)); |
| 2221 | leaf_node2->SetDrawsContent(true); |
| 2222 | leaf_node3->SetBounds(gfx::Size(10, 10)); |
| 2223 | leaf_node3->SetDrawsContent(true); |
| 2224 | leaf_node4->SetBounds(gfx::Size(10, 10)); |
| 2225 | leaf_node4->SetDrawsContent(true); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2226 | ExecuteCalculateDrawProperties(parent); |
| 2227 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2228 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2229 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2230 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2231 | |
| 2232 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2233 | // MasksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2234 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2235 | grand_child1->render_surface()->clip_rect()); |
| 2236 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2237 | grand_child2->render_surface()->clip_rect()); |
| 2238 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2239 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2240 | } |
| 2241 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2242 | TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { |
| 2243 | // Tests that when separate surfaces are disabled, a layer's clip_rect is the |
| 2244 | // intersection of all ancestor clips in screen space; in particular, if a |
| 2245 | // layer masks to bounds, it contributes to the clip_rect of all layers in its |
| 2246 | // subtree (since there are no render surfaces that can reset the clip_rect). |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2247 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2248 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2249 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 2250 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 2251 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 2252 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 2253 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 2254 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2255 | root->SetBounds(gfx::Size(100, 100)); |
| 2256 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2257 | parent->SetBounds(gfx::Size(400, 400)); |
| 2258 | child1->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2259 | child1->SetBounds(gfx::Size(800, 800)); |
| 2260 | child2->SetPosition(gfx::PointF(3.f, 3.f)); |
| 2261 | child2->SetBounds(gfx::Size(800, 800)); |
| 2262 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2263 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2264 | leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2265 | leaf_node1->SetBounds(gfx::Size(2000, 2000)); |
| 2266 | leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); |
| 2267 | leaf_node2->SetBounds(gfx::Size(2000, 2000)); |
| 2268 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2269 | root->SetDrawsContent(true); |
| 2270 | parent->SetDrawsContent(true); |
| 2271 | child1->SetDrawsContent(true); |
| 2272 | child2->SetDrawsContent(true); |
| 2273 | grand_child->SetDrawsContent(true); |
| 2274 | leaf_node1->SetDrawsContent(true); |
| 2275 | leaf_node2->SetDrawsContent(true); |
| 2276 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2277 | root->test_properties()->force_render_surface = true; |
| 2278 | child1->test_properties()->force_render_surface = true; |
| 2279 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2280 | |
| 2281 | // Case 1: Nothing is clipped. In this case, each layer's clip rect is its |
| 2282 | // bounds in target space. The only thing that changes when surfaces are |
| 2283 | // disabled is that target space is always screen space. |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2284 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2285 | EXPECT_TRUE(root->has_render_surface()); |
| 2286 | EXPECT_FALSE(parent->has_render_surface()); |
| 2287 | EXPECT_TRUE(child1->has_render_surface()); |
| 2288 | EXPECT_FALSE(child2->has_render_surface()); |
| 2289 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2290 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2291 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2292 | EXPECT_FALSE(root->is_clipped()); |
| 2293 | EXPECT_FALSE(parent->is_clipped()); |
| 2294 | EXPECT_FALSE(child1->is_clipped()); |
| 2295 | EXPECT_FALSE(child2->is_clipped()); |
| 2296 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2297 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2298 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2299 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2300 | EXPECT_FALSE(child1->render_surface()->is_clipped()); |
| 2301 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2302 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2303 | |
| 2304 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2305 | EXPECT_FALSE(root->is_clipped()); |
| 2306 | EXPECT_FALSE(parent->is_clipped()); |
| 2307 | EXPECT_FALSE(child1->is_clipped()); |
| 2308 | EXPECT_FALSE(child2->is_clipped()); |
| 2309 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2310 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2311 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2312 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2313 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2314 | |
| 2315 | // Case 2: The root is clipped. In this case, layers that draw into the root |
| 2316 | // render surface are clipped by the root's bounds. |
| 2317 | root->SetMasksToBounds(true); |
| 2318 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2319 | root->test_properties()->force_render_surface = true; |
| 2320 | child1->test_properties()->force_render_surface = true; |
| 2321 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2322 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2323 | EXPECT_TRUE(root->has_render_surface()); |
| 2324 | EXPECT_FALSE(parent->has_render_surface()); |
| 2325 | EXPECT_TRUE(child1->has_render_surface()); |
| 2326 | EXPECT_FALSE(child2->has_render_surface()); |
| 2327 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2328 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2329 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2330 | EXPECT_TRUE(root->is_clipped()); |
| 2331 | EXPECT_TRUE(parent->is_clipped()); |
| 2332 | EXPECT_FALSE(child1->is_clipped()); |
| 2333 | EXPECT_TRUE(child1->render_surface()->is_clipped()); |
| 2334 | EXPECT_TRUE(child2->is_clipped()); |
| 2335 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2336 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2337 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2338 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2339 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2340 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2341 | EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2342 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2343 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2344 | |
| 2345 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2346 | EXPECT_TRUE(root->is_clipped()); |
| 2347 | EXPECT_TRUE(parent->is_clipped()); |
| 2348 | EXPECT_TRUE(child1->is_clipped()); |
| 2349 | EXPECT_TRUE(child2->is_clipped()); |
| 2350 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2351 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2352 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2353 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2354 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
| 2355 | EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect()); |
| 2356 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
| 2357 | EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect()); |
| 2358 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect()); |
| 2359 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2360 | |
| 2361 | root->SetMasksToBounds(false); |
| 2362 | |
| 2363 | // Case 3: The parent and child1 are clipped. When surfaces are enabled, the |
| 2364 | // parent clip rect only contributes to the subtree rooted at child2, since |
| 2365 | // the subtree rooted at child1 renders into a separate surface. Similarly, |
| 2366 | // child1's clip rect doesn't contribute to its descendants, since its only |
| 2367 | // child is a render surface. However, without surfaces, these clip rects |
| 2368 | // contribute to all descendants. |
| 2369 | parent->SetMasksToBounds(true); |
| 2370 | child1->SetMasksToBounds(true); |
| 2371 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2372 | root->test_properties()->force_render_surface = true; |
| 2373 | child1->test_properties()->force_render_surface = true; |
| 2374 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2375 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2376 | EXPECT_TRUE(root->has_render_surface()); |
| 2377 | EXPECT_FALSE(parent->has_render_surface()); |
| 2378 | EXPECT_TRUE(child1->has_render_surface()); |
| 2379 | EXPECT_FALSE(child2->has_render_surface()); |
| 2380 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2381 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2382 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2383 | EXPECT_FALSE(root->is_clipped()); |
| 2384 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2385 | EXPECT_TRUE(parent->is_clipped()); |
| 2386 | EXPECT_TRUE(child1->is_clipped()); |
| 2387 | EXPECT_TRUE(child2->is_clipped()); |
| 2388 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2389 | EXPECT_TRUE(grand_child->render_surface()->is_clipped()); |
| 2390 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2391 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2392 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2393 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2394 | EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); |
| 2395 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2396 | EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2397 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2398 | |
| 2399 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2400 | EXPECT_FALSE(root->is_clipped()); |
| 2401 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2402 | EXPECT_TRUE(parent->is_clipped()); |
| 2403 | EXPECT_TRUE(child1->is_clipped()); |
| 2404 | EXPECT_TRUE(child2->is_clipped()); |
| 2405 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2406 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2407 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2408 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2409 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2410 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect()); |
| 2411 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
| 2412 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect()); |
| 2413 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect()); |
| 2414 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2415 | } |
| 2416 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2417 | TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2418 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2419 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2420 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2421 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2422 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2423 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2424 | root->SetBounds(gfx::Size(100, 100)); |
| 2425 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2426 | parent->SetBounds(gfx::Size(400, 400)); |
| 2427 | parent->SetMasksToBounds(true); |
| 2428 | child->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2429 | child->SetBounds(gfx::Size(800, 800)); |
| 2430 | child->SetMasksToBounds(true); |
| 2431 | child->test_properties()->force_render_surface = true; |
| 2432 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2433 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2434 | grand_child->test_properties()->force_render_surface = true; |
| 2435 | leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2436 | leaf_node->SetBounds(gfx::Size(2000, 2000)); |
| 2437 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2438 | root->SetDrawsContent(true); |
| 2439 | parent->SetDrawsContent(true); |
| 2440 | child->SetDrawsContent(true); |
| 2441 | grand_child->SetDrawsContent(true); |
| 2442 | leaf_node->SetDrawsContent(true); |
| 2443 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2444 | host_impl()->set_resourceless_software_draw_for_testing(); |
| 2445 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2446 | gfx::PointF test_point(90.f, 90.f); |
| 2447 | LayerImpl* result_layer = |
| 2448 | root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point); |
| 2449 | ASSERT_TRUE(result_layer); |
| 2450 | EXPECT_EQ(leaf_node, result_layer); |
| 2451 | } |
| 2452 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2453 | TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { |
| 2454 | // Tests that draw properties are computed correctly when we disable and then |
| 2455 | // re-enable separate surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2456 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2457 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2458 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2459 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2460 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2461 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2462 | root->SetBounds(gfx::Size(100, 100)); |
| 2463 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2464 | parent->SetBounds(gfx::Size(400, 400)); |
| 2465 | parent->SetMasksToBounds(true); |
| 2466 | child->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2467 | child->SetBounds(gfx::Size(800, 800)); |
| 2468 | child->SetMasksToBounds(true); |
| 2469 | child->test_properties()->force_render_surface = true; |
| 2470 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2471 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2472 | grand_child->test_properties()->force_render_surface = true; |
| 2473 | leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2474 | leaf_node->SetBounds(gfx::Size(2000, 2000)); |
| 2475 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2476 | root->SetDrawsContent(true); |
| 2477 | parent->SetDrawsContent(true); |
| 2478 | child->SetDrawsContent(true); |
| 2479 | grand_child->SetDrawsContent(true); |
| 2480 | leaf_node->SetDrawsContent(true); |
| 2481 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2482 | gfx::Transform expected_leaf_draw_transform_with_surfaces; |
| 2483 | expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); |
| 2484 | |
| 2485 | gfx::Transform expected_leaf_draw_transform_without_surfaces; |
| 2486 | expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); |
| 2487 | |
| 2488 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2489 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2490 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2491 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2492 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, |
| 2493 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2494 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2495 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2496 | EXPECT_TRUE(leaf_node->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2497 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); |
| 2498 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2499 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces, |
| 2500 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2501 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2502 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2503 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2504 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2505 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2506 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, |
| 2507 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2508 | } |
| 2509 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2510 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2511 | LayerImpl* root = root_layer_for_testing(); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2512 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 2513 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
| 2514 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 2515 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 2516 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
| 2517 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 2518 | LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
| 2519 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2520 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2521 | root->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2522 | render_surface1->SetDrawsContent(true); |
| 2523 | child_of_rs1->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2524 | grand_child_of_rs1->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2525 | render_surface2->SetDrawsContent(true); |
| 2526 | child_of_rs2->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2527 | grand_child_of_rs2->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2528 | child_of_root->SetDrawsContent(true); |
| 2529 | grand_child_of_root->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2530 | |
| 2531 | gfx::Transform layer_transform; |
| 2532 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2533 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2534 | root->SetTransform(layer_transform); |
| 2535 | root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2536 | root->SetBounds(gfx::Size(10, 10)); |
| 2537 | root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f); |
| 2538 | render_surface1->SetTransform(layer_transform); |
| 2539 | render_surface1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2540 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 2541 | render_surface1->test_properties()->transform_origin = |
| 2542 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2543 | render_surface1->test_properties()->force_render_surface = true; |
| 2544 | render_surface2->SetTransform(layer_transform); |
| 2545 | render_surface2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2546 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 2547 | render_surface2->test_properties()->transform_origin = |
| 2548 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2549 | render_surface2->test_properties()->force_render_surface = true; |
| 2550 | child_of_root->SetTransform(layer_transform); |
| 2551 | child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2552 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2553 | child_of_root->test_properties()->transform_origin = |
| 2554 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2555 | child_of_rs1->SetTransform(layer_transform); |
| 2556 | child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2557 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2558 | child_of_rs1->test_properties()->transform_origin = |
| 2559 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2560 | child_of_rs2->SetTransform(layer_transform); |
| 2561 | child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2562 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2563 | child_of_rs2->test_properties()->transform_origin = |
| 2564 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2565 | grand_child_of_root->SetTransform(layer_transform); |
| 2566 | grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2567 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2568 | grand_child_of_root->test_properties()->transform_origin = |
| 2569 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2570 | grand_child_of_rs1->SetTransform(layer_transform); |
| 2571 | grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2572 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2573 | grand_child_of_rs1->test_properties()->transform_origin = |
| 2574 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2575 | grand_child_of_rs2->SetTransform(layer_transform); |
| 2576 | grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2577 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2578 | grand_child_of_rs2->test_properties()->transform_origin = |
| 2579 | gfx::Point3F(0.25f, 0.f, 0.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2580 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2581 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2582 | SetElementIdsForTesting(); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 2583 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2584 | // Put an animated opacity on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2585 | AddOpacityTransitionToElementWithPlayer( |
| 2586 | render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2587 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2588 | // Also put an animated opacity on a layer without descendants. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2589 | AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(), |
| 2590 | timeline_impl(), 10.0, 1.f, 0.f, |
| 2591 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2592 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2593 | // Put a transform animation on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2594 | AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(), |
| 2595 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2596 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2597 | // Also put transform animations on grand_child_of_root, and |
| 2598 | // grand_child_of_rs2 |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2599 | AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(), |
| 2600 | timeline_impl(), 10.0, 30, 0); |
| 2601 | AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(), |
| 2602 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2603 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2604 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 2605 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2606 | |
| 2607 | // Only layers that are associated with render surfaces should have an actual |
| 2608 | // RenderSurface() value. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2609 | ASSERT_TRUE(root->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2610 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2611 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2612 | |
| 2613 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2614 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2615 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2616 | |
| 2617 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2618 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2619 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2620 | |
| 2621 | // Verify all render target accessors |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2622 | EXPECT_EQ(root->render_surface(), root->render_target()); |
| 2623 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 2624 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2625 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2626 | EXPECT_EQ(render_surface1->render_surface(), |
| 2627 | render_surface1->render_target()); |
| 2628 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 2629 | EXPECT_EQ(render_surface1->render_surface(), |
| 2630 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2631 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2632 | EXPECT_EQ(render_surface2->render_surface(), |
| 2633 | render_surface2->render_target()); |
| 2634 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 2635 | EXPECT_EQ(render_surface2->render_surface(), |
| 2636 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2637 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2638 | // Verify screen_space_transform_is_animating values |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2639 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2640 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2641 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2642 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2643 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2644 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2645 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2646 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2647 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2648 | |
| 2649 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2650 | // It is expected that we correctly set up transforms so that the y-component |
| 2651 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2652 | EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2653 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2654 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2655 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2656 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2657 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2658 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2659 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2660 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2661 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2662 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2663 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2664 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2665 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2666 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2667 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2668 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2669 | } |
| 2670 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2671 | TEST_F(LayerTreeHostCommonTest, LargeTransforms) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2672 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2673 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2674 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2675 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2676 | gfx::Transform large_transform; |
| 2677 | large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); |
| 2678 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2679 | root->SetBounds(gfx::Size(10, 10)); |
| 2680 | child->SetTransform(large_transform); |
| 2681 | child->SetBounds(gfx::Size(10, 10)); |
| 2682 | grand_child->SetTransform(large_transform); |
| 2683 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2684 | grand_child->SetDrawsContent(true); |
| 2685 | ExecuteCalculateDrawProperties(root); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2686 | |
| 2687 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
| 2688 | } |
| 2689 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2690 | TEST_F(LayerTreeHostCommonTest, |
| 2691 | ScreenSpaceTransformIsAnimatingWithDelayedAnimation) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2692 | LayerImpl* root = root_layer_for_testing(); |
| 2693 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2694 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2695 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 2696 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2697 | root->SetDrawsContent(true); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2698 | child->SetDrawsContent(true); |
| 2699 | grand_child->SetDrawsContent(true); |
| 2700 | great_grand_child->SetDrawsContent(true); |
| 2701 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2702 | root->SetBounds(gfx::Size(10, 10)); |
| 2703 | child->SetBounds(gfx::Size(10, 10)); |
| 2704 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2705 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2706 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2707 | SetElementIdsForTesting(); |
| 2708 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2709 | // Add a transform animation with a start delay to |grand_child|. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2710 | std::unique_ptr<Animation> animation = Animation::Create( |
| 2711 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1, |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 2712 | TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 2713 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2714 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2715 | AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(), |
| 2716 | std::move(animation)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2717 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2718 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2719 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2720 | EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 2721 | |
| 2722 | EXPECT_FALSE(grand_child->TransformIsAnimating()); |
| 2723 | EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation()); |
| 2724 | EXPECT_TRUE(grand_child->screen_space_transform_is_animating()); |
| 2725 | EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating()); |
| 2726 | } |
| 2727 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2728 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) { |
| 2729 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2730 | // correctly for identity transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2731 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2732 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2733 | gfx::Transform layer_to_surface_transform; |
| 2734 | |
| 2735 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2736 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2737 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2738 | gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30); |
| 2739 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2740 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2741 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2742 | EXPECT_EQ(expected_drawable_content_rect, |
| 2743 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2744 | |
| 2745 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2746 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2747 | expected_visible_layer_rect = gfx::Rect(); |
| 2748 | expected_drawable_content_rect = gfx::Rect(); |
| 2749 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2750 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2751 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2752 | EXPECT_EQ(expected_drawable_content_rect, |
| 2753 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2754 | |
| 2755 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2756 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2757 | expected_visible_layer_rect = gfx::Rect(20, 20); |
| 2758 | expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20); |
| 2759 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2760 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2761 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2762 | EXPECT_EQ(expected_drawable_content_rect, |
| 2763 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2764 | } |
| 2765 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2766 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) { |
| 2767 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2768 | // for rotations about z-axis (i.e. 2D rotations). |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2769 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2770 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2771 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2772 | gfx::Transform layer_to_surface_transform; |
| 2773 | |
| 2774 | // Case 1: Layer is contained within the surface. |
| 2775 | layer_to_surface_transform.MakeIdentity(); |
| 2776 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2777 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2778 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2779 | gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43); |
| 2780 | LayerImpl* 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 2: Layer is outside the surface rect. |
| 2787 | layer_to_surface_transform.MakeIdentity(); |
| 2788 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2789 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2790 | expected_visible_layer_rect = gfx::Rect(); |
| 2791 | expected_drawable_content_rect = gfx::Rect(); |
| 2792 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2793 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2794 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2795 | EXPECT_EQ(expected_drawable_content_rect, |
| 2796 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2797 | |
| 2798 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2799 | // the layer is oriented diagonally, with the left half outside of the render |
| 2800 | // surface. In this case, the g should still be the entire layer |
| 2801 | // (remember the g is computed in layer space); both the top-left |
| 2802 | // and bottom-right corners of the layer are still visible. |
| 2803 | layer_to_surface_transform.MakeIdentity(); |
| 2804 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2805 | expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2806 | expected_drawable_content_rect = gfx::Rect(22, 43); |
| 2807 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2808 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2809 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2810 | EXPECT_EQ(expected_drawable_content_rect, |
| 2811 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2812 | |
| 2813 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2814 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2815 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2816 | // surface overlaps the right side of the layer. The g should be |
| 2817 | // the layer's right half. |
| 2818 | layer_to_surface_transform.MakeIdentity(); |
| 2819 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2820 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2821 | // Right half of layer bounds. |
| 2822 | expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30); |
| 2823 | expected_drawable_content_rect = gfx::Rect(22, 22); |
| 2824 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2825 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2826 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2827 | EXPECT_EQ(expected_drawable_content_rect, |
| 2828 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2829 | } |
| 2830 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2831 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) { |
| 2832 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2833 | // for 3d transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2834 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2835 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2836 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2837 | gfx::Transform layer_to_surface_transform; |
| 2838 | |
| 2839 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2840 | // degrees, should be fully contained in the render surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2841 | // 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] | 2842 | layer_to_surface_transform.MakeIdentity(); |
| 2843 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2844 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2845 | gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100); |
| 2846 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2847 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2848 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2849 | EXPECT_EQ(expected_drawable_content_rect, |
| 2850 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2851 | |
| 2852 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2853 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2854 | // visible on the surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2855 | // 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] | 2856 | SkMScalar half_width_of_rotated_layer = |
| 2857 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2858 | layer_to_surface_transform.MakeIdentity(); |
| 2859 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2860 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2861 | // edge of the layer. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2862 | // Tight half of the layer. |
| 2863 | expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100); |
| 2864 | expected_drawable_content_rect = gfx::Rect(36, 100); |
| 2865 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2866 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2867 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2868 | EXPECT_EQ(expected_drawable_content_rect, |
| 2869 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2870 | } |
| 2871 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2872 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) { |
| 2873 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2874 | // when the layer has a perspective projection onto the target surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2875 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2876 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2877 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2878 | gfx::Transform layer_to_surface_transform; |
| 2879 | |
| 2880 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2881 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2882 | // its translated more than the perspective amount. |
| 2883 | layer_to_surface_transform.MakeIdentity(); |
| 2884 | |
| 2885 | // The following sequence of transforms applies the perspective about the |
| 2886 | // center of the surface. |
| 2887 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2888 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2889 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2890 | |
| 2891 | // This translate places the layer in front of the surface's projection plane. |
| 2892 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2893 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2894 | // Layer position is (-50, -50), visible rect in layer space is layer bounds |
| 2895 | // offset by layer position. |
| 2896 | gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150); |
| 2897 | gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38); |
| 2898 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2899 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2900 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2901 | EXPECT_EQ(expected_drawable_content_rect, |
| 2902 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2903 | |
| 2904 | // Case 2: same projection as before, except that the layer is also translated |
| 2905 | // to the side, so that only the right half of the layer should be visible. |
| 2906 | // |
| 2907 | // Explanation of expected result: The perspective ratio is (z distance |
| 2908 | // between layer and camera origin) / (z distance between projection plane and |
| 2909 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2910 | // move a layer by translating -25 units in projected surface units (so that |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2911 | // 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] | 2912 | // -25 == -100 in the layer's units. |
| 2913 | layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0); |
| 2914 | // Visible layer rect is moved by 100, and drawable content rect is in target |
| 2915 | // space and is moved by 25. |
| 2916 | expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150); |
| 2917 | expected_drawable_content_rect = gfx::Rect(13, 38); |
| 2918 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2919 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2920 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2921 | EXPECT_EQ(expected_drawable_content_rect, |
| 2922 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2923 | } |
| 2924 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2925 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2926 | DrawRectsFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2927 | // There is currently no explicit concept of an orthographic projection plane |
| 2928 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2929 | // are technically behind the surface in an orthographic world should not be |
| 2930 | // clipped when they are flattened to the surface. |
| 2931 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2932 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2933 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2934 | gfx::Transform layer_to_surface_transform; |
| 2935 | |
| 2936 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2937 | // at the center of the layer. |
| 2938 | layer_to_surface_transform.MakeIdentity(); |
| 2939 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2940 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2941 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2942 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2943 | // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface |
| 2944 | // space. |
| 2945 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2946 | gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100); |
| 2947 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2948 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2949 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2950 | EXPECT_EQ(expected_drawable_content_rect, |
| 2951 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2952 | } |
| 2953 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2954 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2955 | DrawRectsFor3dPerspectiveWhenClippedByW) { |
| 2956 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2957 | // when projecting a surface onto a layer, but the layer is partially behind |
| 2958 | // the camera (not just behind the projection plane). In this case, the |
| 2959 | // cartesian coordinates may seem to be valid, but actually they are not. The |
| 2960 | // visible rect needs to be properly clipped by the w = 0 plane in homogeneous |
| 2961 | // coordinates before converting to cartesian coordinates. The drawable |
| 2962 | // content rect would be entire surface rect because layer is rotated at the |
| 2963 | // camera position. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2964 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2965 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200); |
| 2966 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2967 | gfx::Transform layer_to_surface_transform; |
| 2968 | |
| 2969 | // The layer is positioned so that the right half of the layer should be in |
| 2970 | // front of the camera, while the other half is behind the surface's |
| 2971 | // projection plane. The following sequence of transforms applies the |
| 2972 | // perspective and rotation about the center of the layer. |
| 2973 | layer_to_surface_transform.MakeIdentity(); |
| 2974 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2975 | layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0); |
| 2976 | layer_to_surface_transform.RotateAboutYAxis(-45.0); |
| 2977 | layer_to_surface_transform.Translate(-10, -1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2978 | |
| 2979 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2980 | // transform, otherwise this code is not testing the intended scenario. |
| 2981 | bool clipped; |
| 2982 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2983 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2984 | &clipped); |
| 2985 | ASSERT_TRUE(clipped); |
| 2986 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2987 | gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1); |
| 2988 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 2989 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2990 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2991 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2992 | EXPECT_EQ(expected_drawable_content_rect, |
| 2993 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2994 | } |
| 2995 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2996 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2997 | // To determine visible rect in layer space, there needs to be an |
| 2998 | // un-projection from surface space to layer space. When the original |
| 2999 | // transform was a perspective projection that was clipped, it returns a rect |
| 3000 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 3001 | // clipping again. |
| 3002 | |
| 3003 | // This sequence of transforms causes one corner of the layer to protrude |
| 3004 | // across the w = 0 plane, and should be clipped. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3005 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150); |
| 3006 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3007 | gfx::Transform layer_to_surface_transform; |
| 3008 | layer_to_surface_transform.MakeIdentity(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3009 | layer_to_surface_transform.Translate(10, 10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3010 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 3011 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 3012 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 3013 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3014 | layer_to_surface_transform.Translate(-10, -10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3015 | |
| 3016 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 3017 | // code is not testing the intended scenario. |
| 3018 | bool clipped; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3019 | gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
| 3020 | layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3021 | MathUtil::ProjectQuad( |
| 3022 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 3023 | ASSERT_TRUE(clipped); |
| 3024 | |
| 3025 | // Only the corner of the layer is not visible on the surface because of being |
| 3026 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 3027 | // rect is that the entire layer should still be considered visible. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3028 | gfx::Rect expected_visible_layer_rect = layer_content_rect; |
| 3029 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 3030 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 3031 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 3032 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 3033 | EXPECT_EQ(expected_drawable_content_rect, |
| 3034 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3035 | } |
| 3036 | |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3037 | TEST_F(LayerTreeHostCommonTest, |
| 3038 | VisibleRectsForPositionedRootLayerClippedByViewport) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3039 | LayerImpl* root = root_layer_for_testing(); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3040 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3041 | root->SetPosition(gfx::PointF(60, 70)); |
| 3042 | root->SetBounds(gfx::Size(100, 100)); |
| 3043 | root->SetDrawsContent(true); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3044 | ExecuteCalculateDrawProperties(root); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3045 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3046 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3047 | root->render_surface()->DrawableContentRect()); |
| 3048 | // In target space, not clipped. |
| 3049 | EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 3050 | // In layer space, clipped. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3051 | EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3052 | } |
| 3053 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3054 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3055 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3056 | LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3057 | LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3058 | LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3059 | |
| 3060 | root->SetBounds(gfx::Size(100, 100)); |
| 3061 | child1_layer->SetBounds(gfx::Size(50, 50)); |
| 3062 | child1_layer->SetDrawsContent(true); |
| 3063 | child2_layer->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3064 | child2_layer->SetBounds(gfx::Size(50, 50)); |
| 3065 | child2_layer->SetDrawsContent(true); |
| 3066 | child3_layer->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3067 | child3_layer->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3068 | child3_layer->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3069 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3070 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3071 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3072 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3073 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3074 | // Layers that do not draw content should have empty visible_layer_rects. |
| 3075 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3076 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3077 | // layer visible_layer_rects are clipped by their target surface. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3078 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); |
| 3079 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); |
| 3080 | EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3081 | |
| 3082 | // layer drawable_content_rects are not clipped. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3083 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect()); |
| 3084 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect()); |
| 3085 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3086 | } |
| 3087 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3088 | TEST_F(LayerTreeHostCommonTest, |
| 3089 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3090 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3091 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3092 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3093 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3094 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3095 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3096 | root->SetBounds(gfx::Size(100, 100)); |
| 3097 | child->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3098 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3099 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3100 | grand_child1->SetBounds(gfx::Size(50, 50)); |
| 3101 | grand_child1->SetDrawsContent(true); |
| 3102 | grand_child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3103 | grand_child2->SetBounds(gfx::Size(50, 50)); |
| 3104 | grand_child2->SetDrawsContent(true); |
| 3105 | grand_child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3106 | grand_child3->SetBounds(gfx::Size(50, 50)); |
| 3107 | grand_child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3108 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3109 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3110 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3111 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3112 | |
| 3113 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3114 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3115 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3116 | |
| 3117 | // All grandchild visible content rects should be clipped by child. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3118 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); |
| 3119 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); |
| 3120 | EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3121 | |
| 3122 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3123 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 3124 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3125 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 3126 | } |
| 3127 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3128 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3129 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3130 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 3131 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3132 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3133 | gfx::Transform child_scale_matrix; |
| 3134 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 3135 | gfx::Transform grand_child_scale_matrix; |
| 3136 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3137 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3138 | root->SetBounds(gfx::Size(100, 100)); |
| 3139 | child->SetTransform(child_scale_matrix); |
| 3140 | child->SetBounds(gfx::Size(10, 10)); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3141 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3142 | grand_child->SetTransform(grand_child_scale_matrix); |
| 3143 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3144 | grand_child->SetDrawsContent(true); |
| 3145 | ExecuteCalculateDrawProperties(root); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3146 | |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 3147 | // The visible rect is expanded to integer coordinates. |
| 3148 | EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3149 | } |
| 3150 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3151 | TEST_F(LayerTreeHostCommonTest, |
| 3152 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3153 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3154 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3155 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3156 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3157 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3158 | |
| 3159 | root->SetBounds(gfx::Size(100, 100)); |
| 3160 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3161 | render_surface->test_properties()->force_render_surface = true; |
| 3162 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3163 | child1->SetBounds(gfx::Size(50, 50)); |
| 3164 | child1->SetDrawsContent(true); |
| 3165 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3166 | child2->SetBounds(gfx::Size(50, 50)); |
| 3167 | child2->SetDrawsContent(true); |
| 3168 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3169 | child3->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3170 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3171 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3172 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3173 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3174 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3175 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3176 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3177 | |
| 3178 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3179 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3180 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3181 | |
| 3182 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 3183 | // regions of the subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3184 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3185 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3186 | |
| 3187 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3188 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3189 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 3190 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3191 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3192 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3193 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3194 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3195 | } |
| 3196 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3197 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3198 | DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3199 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3200 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 3201 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 3202 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 3203 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); |
| 3204 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); |
| 3205 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 3206 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 3207 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3208 | root->SetBounds(gfx::Size(100, 100)); |
| 3209 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 3210 | parent->SetBounds(gfx::Size(400, 400)); |
| 3211 | child1->SetPosition(gfx::PointF(4.f, 4.f)); |
| 3212 | child1->SetBounds(gfx::Size(800, 800)); |
| 3213 | child1->test_properties()->force_render_surface = true; |
| 3214 | child2->SetPosition(gfx::PointF(3.f, 3.f)); |
| 3215 | child2->SetBounds(gfx::Size(800, 800)); |
| 3216 | child2->test_properties()->force_render_surface = true; |
| 3217 | grand_child1->SetPosition(gfx::PointF(8.f, 8.f)); |
| 3218 | grand_child1->SetBounds(gfx::Size(1500, 1500)); |
| 3219 | grand_child2->SetPosition(gfx::PointF(7.f, 7.f)); |
| 3220 | grand_child2->SetBounds(gfx::Size(1500, 1500)); |
| 3221 | leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); |
| 3222 | leaf_node1->SetBounds(gfx::Size(2000, 2000)); |
| 3223 | leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); |
| 3224 | leaf_node2->SetBounds(gfx::Size(2000, 2000)); |
| 3225 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3226 | root->SetDrawsContent(true); |
| 3227 | parent->SetDrawsContent(true); |
| 3228 | child1->SetDrawsContent(true); |
| 3229 | child2->SetDrawsContent(true); |
| 3230 | grand_child1->SetDrawsContent(true); |
| 3231 | grand_child2->SetDrawsContent(true); |
| 3232 | leaf_node1->SetDrawsContent(true); |
| 3233 | leaf_node2->SetDrawsContent(true); |
| 3234 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3235 | // Case 1: No layers clip. Visible rects are clipped by the viewport, but the |
| 3236 | // viewport clip doesn't apply to layers that draw into unclipped surfaces. |
| 3237 | // Each layer's drawable content rect is its bounds in target space; the only |
| 3238 | // thing that changes with surfaces disabled is that target space is always |
| 3239 | // screen space. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3240 | root->SetHasRenderSurface(true); |
| 3241 | child1->SetHasRenderSurface(true); |
| 3242 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3243 | ExecuteCalculateDrawProperties(root); |
| 3244 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3245 | EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect()); |
| 3246 | EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect()); |
| 3247 | EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect()); |
| 3248 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect()); |
| 3249 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect()); |
| 3250 | EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect()); |
| 3251 | EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect()); |
| 3252 | |
| 3253 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3254 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3255 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3256 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3257 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3258 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3259 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3260 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3261 | |
| 3262 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3263 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3264 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3265 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3266 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3267 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3268 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3269 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3270 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3271 | |
| 3272 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3273 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3274 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3275 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3276 | EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), |
| 3277 | grand_child1->drawable_content_rect()); |
| 3278 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3279 | grand_child2->drawable_content_rect()); |
| 3280 | EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3281 | EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3282 | |
| 3283 | // Case 2: The parent clips. In this case, neither surface is unclipped, so |
| 3284 | // all visible layer rects are clipped by the intersection of all ancestor |
| 3285 | // clips, whether or not surfaces are disabled. However, drawable content |
| 3286 | // rects are clipped only until the next render surface is reached, so |
| 3287 | // descendants of parent have their drawable content rects clipped only when |
| 3288 | // surfaces are disabled. |
| 3289 | parent->SetMasksToBounds(true); |
| 3290 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3291 | ExecuteCalculateDrawProperties(root); |
| 3292 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3293 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3294 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3295 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3296 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3297 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3298 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3299 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3300 | |
| 3301 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3302 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3303 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3304 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3305 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3306 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3307 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3308 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3309 | |
| 3310 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3311 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3312 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3313 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3314 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 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()); |
| 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(6, 6, 396, 396), child1->drawable_content_rect()); |
| 3323 | EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect()); |
| 3324 | EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect()); |
| 3325 | EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect()); |
| 3326 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect()); |
| 3327 | EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect()); |
| 3328 | |
| 3329 | parent->SetMasksToBounds(false); |
| 3330 | |
| 3331 | // Case 3: child1 and grand_child2 clip. In this case, descendants of these |
| 3332 | // layers have their visible rects clipped by them; without surfaces, these |
| 3333 | // rects are also clipped by the viewport. Similarly, descendants of these |
| 3334 | // layers have their drawable content rects clipped by them. |
| 3335 | child1->SetMasksToBounds(true); |
| 3336 | grand_child2->SetMasksToBounds(true); |
| 3337 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3338 | ExecuteCalculateDrawProperties(root); |
| 3339 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3340 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3341 | EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect()); |
| 3342 | EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect()); |
| 3343 | EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect()); |
| 3344 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect()); |
| 3345 | EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect()); |
| 3346 | EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect()); |
| 3347 | |
| 3348 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3349 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3350 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3351 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3352 | EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect()); |
| 3353 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3354 | EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect()); |
| 3355 | EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3356 | |
| 3357 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3358 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3359 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3360 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3361 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3362 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3363 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3364 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3365 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3366 | |
| 3367 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3368 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3369 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3370 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3371 | EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect()); |
| 3372 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3373 | grand_child2->drawable_content_rect()); |
| 3374 | EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); |
| 3375 | EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3376 | } |
| 3377 | |
| 3378 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3379 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3380 | LayerImpl* root = root_layer_for_testing(); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3381 | LayerImpl* child1 = AddChild<LayerImpl>(root); |
| 3382 | LayerImpl* child2 = AddChild<LayerImpl>(root); |
| 3383 | LayerImpl* child3 = AddChild<LayerImpl>(root); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3384 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3385 | root->SetBounds(gfx::Size(100, 100)); |
| 3386 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3387 | child1->SetBounds(gfx::Size(50, 50)); |
| 3388 | child1->SetDrawsContent(true); |
| 3389 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3390 | child2->SetBounds(gfx::Size(50, 50)); |
| 3391 | child2->SetDrawsContent(true); |
| 3392 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3393 | child3->SetBounds(gfx::Size(50, 50)); |
| 3394 | child3->SetDrawsContent(true); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3395 | |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3396 | LayerImplList render_surface_layer_list_impl; |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3397 | // Now set the root render surface an empty clip. |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3398 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 3399 | root, gfx::Size(), &render_surface_layer_list_impl); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3400 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 3401 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3402 | ASSERT_TRUE(root->render_surface()); |
| 3403 | EXPECT_FALSE(root->is_clipped()); |
| 3404 | |
| 3405 | gfx::Rect empty; |
| 3406 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 3407 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 3408 | |
| 3409 | // Visible content rect calculation will check if the target surface is |
| 3410 | // clipped or not. An empty clip rect does not indicate the render surface |
| 3411 | // is unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3412 | EXPECT_EQ(empty, child1->visible_layer_rect()); |
| 3413 | EXPECT_EQ(empty, child2->visible_layer_rect()); |
| 3414 | EXPECT_EQ(empty, child3->visible_layer_rect()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3418 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3419 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3420 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3421 | |
| 3422 | root->SetBounds(gfx::Size(100, 100)); |
| 3423 | child->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3424 | child->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3425 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3426 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3427 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3428 | 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] | 3429 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3430 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3431 | child->SetTransform(uninvertible_matrix); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3432 | ExecuteCalculateDrawProperties(root); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3433 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3434 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3435 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3436 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3437 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 3438 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3439 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3440 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3441 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3442 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3443 | child->SetTransform(uninvertible_matrix); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3444 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3445 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3446 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3447 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3448 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3449 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3450 | uninvertible_matrix.MakeIdentity(); |
| 3451 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3452 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3453 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3454 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3455 | child->SetTransform(uninvertible_matrix); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3456 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3457 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3458 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3459 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3460 | } |
| 3461 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3462 | TEST_F(LayerTreeHostCommonTest, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3463 | VisibleContentRectForLayerWithUninvertibleDrawTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3464 | LayerImpl* root = root_layer_for_testing(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3465 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3466 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3467 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3468 | gfx::Transform perspective; |
| 3469 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3470 | |
| 3471 | gfx::Transform rotation; |
| 3472 | rotation.RotateAboutYAxis(45.0); |
| 3473 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3474 | root->SetBounds(gfx::Size(100, 100)); |
| 3475 | child->SetTransform(perspective); |
| 3476 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 3477 | child->SetBounds(gfx::Size(100, 100)); |
| 3478 | child->SetDrawsContent(true); |
| 3479 | child->Set3dSortingContextId(1); |
| 3480 | child->test_properties()->should_flatten_transform = false; |
| 3481 | grand_child->SetTransform(rotation); |
| 3482 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 3483 | grand_child->SetDrawsContent(true); |
| 3484 | grand_child->Set3dSortingContextId(1); |
| 3485 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3486 | ExecuteCalculateDrawProperties(root); |
| 3487 | |
| 3488 | // Though all layers have invertible transforms, matrix multiplication using |
| 3489 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3490 | EXPECT_FALSE(root->layer_tree_impl() |
| 3491 | ->property_trees() |
| 3492 | ->transform_tree.Node(grand_child->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3493 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3494 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3495 | // CalcDrawProps skips a subtree when a layer's screen space transform is |
| 3496 | // uninvertible |
| 3497 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3498 | } |
| 3499 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3500 | TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) { |
| 3501 | FakeImplTaskRunnerProvider task_runner_provider; |
| 3502 | TestSharedBitmapManager shared_bitmap_manager; |
| 3503 | TestTaskGraphRunner task_graph_runner; |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 3504 | std::unique_ptr<OutputSurface> output_surface = |
| 3505 | FakeOutputSurface::CreateDelegating3d(); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3506 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 3507 | &task_graph_runner); |
| 3508 | |
| 3509 | std::unique_ptr<LayerImpl> root = |
| 3510 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3511 | std::unique_ptr<LayerImpl> child = |
| 3512 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3513 | std::unique_ptr<TextureLayerImpl> surface = |
| 3514 | TextureLayerImpl::Create(host_impl.active_tree(), 3); |
| 3515 | std::unique_ptr<TextureLayerImpl> surface_child = |
| 3516 | TextureLayerImpl::Create(host_impl.active_tree(), 4); |
| 3517 | std::unique_ptr<TextureLayerImpl> surface_sibling = |
| 3518 | TextureLayerImpl::Create(host_impl.active_tree(), 5); |
| 3519 | std::unique_ptr<TextureLayerImpl> surface_child_mask = |
| 3520 | TextureLayerImpl::Create(host_impl.active_tree(), 6); |
| 3521 | |
| 3522 | surface->SetDrawsContent(true); |
| 3523 | surface_child->SetDrawsContent(true); |
| 3524 | surface_sibling->SetDrawsContent(true); |
| 3525 | surface_child_mask->SetDrawsContent(true); |
| 3526 | surface->SetContentsOpaque(true); |
| 3527 | surface_child->SetContentsOpaque(true); |
| 3528 | surface_sibling->SetContentsOpaque(true); |
| 3529 | surface_child_mask->SetContentsOpaque(true); |
| 3530 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3531 | gfx::Transform translate; |
| 3532 | translate.Translate(20.f, 20.f); |
| 3533 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3534 | root->SetBounds(gfx::Size(1000, 1000)); |
| 3535 | child->SetBounds(gfx::Size(300, 300)); |
| 3536 | surface->SetTransform(translate); |
| 3537 | surface->SetBounds(gfx::Size(300, 300)); |
| 3538 | surface->test_properties()->force_render_surface = true; |
| 3539 | surface_child->SetBounds(gfx::Size(300, 300)); |
| 3540 | surface_child->test_properties()->force_render_surface = true; |
| 3541 | surface_sibling->SetBounds(gfx::Size(200, 200)); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3542 | |
| 3543 | LayerImpl* surface_ptr = surface.get(); |
| 3544 | LayerImpl* surface_child_ptr = surface_child.get(); |
| 3545 | LayerImpl* surface_child_mask_ptr = surface_child_mask.get(); |
| 3546 | |
| 3547 | host_impl.SetViewportSize(root->bounds()); |
| 3548 | |
| 3549 | surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask)); |
| 3550 | surface->test_properties()->AddChild(std::move(surface_child)); |
| 3551 | child->test_properties()->AddChild(std::move(surface)); |
| 3552 | child->test_properties()->AddChild(std::move(surface_sibling)); |
| 3553 | root->test_properties()->AddChild(std::move(child)); |
| 3554 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 3555 | host_impl.SetVisible(true); |
| 3556 | host_impl.InitializeRenderer(output_surface.get()); |
| 3557 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 3558 | bool update_lcd_text = false; |
| 3559 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3560 | |
| 3561 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 3562 | surface_ptr->render_surface()->draw_transform(), translate); |
| 3563 | // surface_sibling draws into the root render surface and occludes |
| 3564 | // surface_child's contents. |
| 3565 | Occlusion actual_occlusion = |
| 3566 | surface_child_ptr->render_surface()->occlusion_in_content_space(); |
| 3567 | Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()), |
| 3568 | SimpleEnclosedRegion(gfx::Rect(200, 200))); |
| 3569 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3570 | |
| 3571 | // Mask layer should have the same occlusion. |
| 3572 | actual_occlusion = |
| 3573 | surface_child_mask_ptr->draw_properties().occlusion_in_content_space; |
| 3574 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3575 | } |
| 3576 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3577 | TEST_F(LayerTreeHostCommonTest, |
| 3578 | OcclusionForLayerWithUninvertibleDrawTransform) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3579 | FakeImplTaskRunnerProvider task_runner_provider; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3580 | TestSharedBitmapManager shared_bitmap_manager; |
| 3581 | TestTaskGraphRunner task_graph_runner; |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 3582 | std::unique_ptr<OutputSurface> output_surface = |
| 3583 | FakeOutputSurface::CreateDelegating3d(); |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3584 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3585 | &task_graph_runner); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3586 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3587 | std::unique_ptr<LayerImpl> root = |
| 3588 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3589 | std::unique_ptr<LayerImpl> child = |
| 3590 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3591 | std::unique_ptr<LayerImpl> grand_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3592 | LayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3593 | std::unique_ptr<LayerImpl> occluding_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3594 | LayerImpl::Create(host_impl.active_tree(), 4); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3595 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3596 | gfx::Transform perspective; |
| 3597 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3598 | |
| 3599 | gfx::Transform rotation; |
| 3600 | rotation.RotateAboutYAxis(45.0); |
| 3601 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3602 | root->SetBounds(gfx::Size(1000, 1000)); |
| 3603 | child->SetTransform(perspective); |
| 3604 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 3605 | child->SetBounds(gfx::Size(300, 300)); |
| 3606 | child->test_properties()->should_flatten_transform = false; |
| 3607 | child->Set3dSortingContextId(1); |
| 3608 | grand_child->SetTransform(rotation); |
| 3609 | grand_child->SetBounds(gfx::Size(200, 200)); |
| 3610 | grand_child->test_properties()->should_flatten_transform = false; |
| 3611 | grand_child->Set3dSortingContextId(1); |
| 3612 | occluding_child->SetBounds(gfx::Size(200, 200)); |
| 3613 | occluding_child->test_properties()->should_flatten_transform = false; |
| 3614 | |
| 3615 | child->SetDrawsContent(true); |
| 3616 | grand_child->SetDrawsContent(true); |
| 3617 | occluding_child->SetDrawsContent(true); |
| 3618 | occluding_child->SetContentsOpaque(true); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3619 | |
| 3620 | host_impl.SetViewportSize(root->bounds()); |
| 3621 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3622 | child->test_properties()->AddChild(std::move(grand_child)); |
| 3623 | root->test_properties()->AddChild(std::move(child)); |
| 3624 | root->test_properties()->AddChild(std::move(occluding_child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3625 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 3626 | host_impl.SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 3627 | host_impl.InitializeRenderer(output_surface.get()); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 3628 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3629 | bool update_lcd_text = false; |
| 3630 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3631 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3632 | LayerImpl* grand_child_ptr = host_impl.active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3633 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3634 | ->test_properties() |
| 3635 | ->children[0] |
| 3636 | ->test_properties() |
| 3637 | ->children[0]; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3638 | |
| 3639 | // Though all layers have invertible transforms, matrix multiplication using |
| 3640 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3641 | EXPECT_FALSE( |
| 3642 | host_impl.active_tree() |
| 3643 | ->property_trees() |
| 3644 | ->transform_tree.Node(grand_child_ptr->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3645 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3646 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3647 | // Since |grand_child| has an uninvertible screen space transform, it is |
| 3648 | // skipped so |
| 3649 | // that we are not computing its occlusion_in_content_space. |
| 3650 | gfx::Rect layer_bounds = gfx::Rect(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3651 | EXPECT_EQ( |
| 3652 | layer_bounds, |
| 3653 | grand_child_ptr->draw_properties() |
| 3654 | .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds)); |
| 3655 | } |
| 3656 | |
| 3657 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3658 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3659 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3660 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3661 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3662 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3663 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3664 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3665 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3666 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3667 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3668 | render_surface->test_properties()->force_render_surface = true; |
| 3669 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3670 | child1->SetBounds(gfx::Size(50, 50)); |
| 3671 | child1->SetDrawsContent(true); |
| 3672 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3673 | child2->SetBounds(gfx::Size(50, 50)); |
| 3674 | child2->SetDrawsContent(true); |
| 3675 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3676 | child3->SetBounds(gfx::Size(50, 50)); |
| 3677 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3678 | ExecuteCalculateDrawProperties(root); |
| 3679 | |
| 3680 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3681 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3682 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3683 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3684 | |
| 3685 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3686 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3687 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3688 | |
| 3689 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3690 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3691 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3692 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3693 | |
| 3694 | // All layers that draw content into the surface have their visible content |
| 3695 | // rect clipped by the surface clip rect. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3696 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3697 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3698 | EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3699 | |
| 3700 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3701 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3702 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3703 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3704 | } |
| 3705 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3706 | TEST_F(LayerTreeHostCommonTest, |
| 3707 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3708 | // Check that clipping does not propagate down surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3709 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3710 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3711 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 3712 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3713 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3714 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3715 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3716 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3717 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3718 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 3719 | render_surface1->test_properties()->force_render_surface = true; |
| 3720 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 3721 | render_surface2->test_properties()->force_render_surface = true; |
| 3722 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3723 | child1->SetBounds(gfx::Size(50, 50)); |
| 3724 | child1->SetDrawsContent(true); |
| 3725 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3726 | child2->SetBounds(gfx::Size(50, 50)); |
| 3727 | child2->SetDrawsContent(true); |
| 3728 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3729 | child3->SetBounds(gfx::Size(50, 50)); |
| 3730 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3731 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3732 | |
| 3733 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3734 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3735 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3736 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3737 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3738 | |
| 3739 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3740 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3741 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); |
| 3742 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3743 | |
| 3744 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3745 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3746 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3747 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3748 | |
| 3749 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3750 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3751 | // render_surface2 grows to enclose all drawable content of its subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3752 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3753 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3754 | |
| 3755 | // All layers that draw content into render_surface2 think they are unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3756 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3757 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 3758 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3759 | |
| 3760 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3761 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3762 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3763 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3764 | } |
| 3765 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3766 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3767 | VisibleRectsForClippedDescendantsOfUnclippedSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3768 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3769 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3770 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 3771 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 3772 | LayerImpl* render_surface2 = AddChild<LayerImpl>(child2); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3773 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3774 | root->SetBounds(gfx::Size(100, 100)); |
| 3775 | render_surface1->SetBounds(gfx::Size(100, 100)); |
| 3776 | render_surface1->test_properties()->force_render_surface = true; |
| 3777 | child1->SetBounds(gfx::Size(500, 500)); |
| 3778 | child1->SetDrawsContent(true); |
| 3779 | child2->SetBounds(gfx::Size(700, 700)); |
| 3780 | child2->SetDrawsContent(true); |
| 3781 | render_surface2->SetBounds(gfx::Size(1000, 1000)); |
| 3782 | render_surface2->test_properties()->force_render_surface = true; |
| 3783 | render_surface2->SetDrawsContent(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3784 | |
| 3785 | child1->SetMasksToBounds(true); |
| 3786 | child2->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3787 | ExecuteCalculateDrawProperties(root); |
| 3788 | EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect()); |
| 3789 | EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3790 | } |
| 3791 | |
| 3792 | TEST_F(LayerTreeHostCommonTest, |
| 3793 | VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3794 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3795 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3796 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3797 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3798 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3799 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3800 | root->SetBounds(gfx::Size(100, 100)); |
| 3801 | |
| 3802 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3803 | clip_parent->SetMasksToBounds(true); |
| 3804 | clip_parent->test_properties()->clip_children = |
| 3805 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3806 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3807 | |
| 3808 | render_surface1->SetBounds(gfx::Size(20, 20)); |
| 3809 | render_surface1->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3810 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3811 | render_surface1->test_properties()->force_render_surface = true; |
| 3812 | |
| 3813 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3814 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3815 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3816 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3817 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 3818 | render_surface2->SetDrawsContent(true); |
| 3819 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3820 | |
| 3821 | ExecuteCalculateDrawProperties(root); |
| 3822 | EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect()); |
| 3823 | EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect()); |
| 3824 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect()); |
| 3825 | } |
| 3826 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3827 | TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3828 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3829 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3830 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3831 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3832 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3833 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3834 | root->SetBounds(gfx::Size(100, 100)); |
| 3835 | |
| 3836 | clip_parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 3837 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3838 | clip_parent->test_properties()->clip_children = |
| 3839 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3840 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3841 | |
| 3842 | render_surface1->SetBounds(gfx::Size(20, 20)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3843 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3844 | render_surface1->test_properties()->force_render_surface = true; |
| 3845 | |
| 3846 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3847 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3848 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3849 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3850 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 3851 | render_surface2->SetDrawsContent(true); |
| 3852 | render_surface2->test_properties()->force_render_surface = true; |
| 3853 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3854 | clip_parent->SetMasksToBounds(true); |
| 3855 | render_surface1->SetMasksToBounds(true); |
| 3856 | |
| 3857 | ExecuteCalculateDrawProperties(root); |
| 3858 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect()); |
| 3859 | } |
| 3860 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3861 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) { |
| 3862 | // Test that only drawn layers contribute to render surface content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3863 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3864 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 3865 | LayerImpl* test_layer = AddChild<LayerImpl>(surface); |
| 3866 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3867 | root->SetBounds(gfx::Size(200, 200)); |
| 3868 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3869 | surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3870 | surface->test_properties()->force_render_surface = true; |
| 3871 | test_layer->SetBounds(gfx::Size(150, 150)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3872 | |
| 3873 | ExecuteCalculateDrawProperties(root); |
| 3874 | EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect()); |
| 3875 | |
| 3876 | test_layer->SetDrawsContent(true); |
| 3877 | ExecuteCalculateDrawProperties(root); |
| 3878 | EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect()); |
| 3879 | } |
| 3880 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3881 | TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) { |
| 3882 | // Tests visible rects computation when we have unclipped_surface-> |
| 3883 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3884 | // of surface_with_unclipped_descendants doesn't propagate to the |
| 3885 | // clipped_surface below it. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3886 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3887 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3888 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3889 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3890 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3891 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3892 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3893 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3894 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3895 | unclipped_surface->SetBounds(gfx::Size(30, 30)); |
| 3896 | unclipped_surface->SetDrawsContent(true); |
| 3897 | unclipped_surface->test_properties()->force_render_surface = true; |
| 3898 | |
| 3899 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3900 | clip_parent->test_properties()->clip_children = |
| 3901 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3902 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3903 | |
| 3904 | unclipped_desc_surface->SetBounds(gfx::Size(20, 20)); |
| 3905 | unclipped_desc_surface->SetDrawsContent(true); |
| 3906 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 3907 | |
| 3908 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 3909 | clip_child->test_properties()->clip_parent = clip_parent; |
| 3910 | |
| 3911 | clipped_surface->SetBounds(gfx::Size(60, 60)); |
| 3912 | clipped_surface->SetDrawsContent(true); |
| 3913 | clipped_surface->test_properties()->force_render_surface = true; |
| 3914 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3915 | clip_parent->SetMasksToBounds(true); |
| 3916 | |
| 3917 | ExecuteCalculateDrawProperties(root); |
| 3918 | EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect()); |
| 3919 | EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect()); |
| 3920 | EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect()); |
| 3921 | } |
| 3922 | |
| 3923 | TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) { |
| 3924 | // Tests visible rects computation when we have unclipped_surface-> |
| 3925 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3926 | // of root propagate to the clipped_surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3927 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3928 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3929 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3930 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3931 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3932 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3933 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3934 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3935 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3936 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
| 3937 | unclipped_surface->SetDrawsContent(true); |
| 3938 | unclipped_surface->test_properties()->force_render_surface = true; |
| 3939 | |
| 3940 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3941 | clip_parent->test_properties()->clip_children = |
| 3942 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3943 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3944 | |
| 3945 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 3946 | unclipped_desc_surface->SetDrawsContent(true); |
| 3947 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 3948 | |
| 3949 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 3950 | clip_child->test_properties()->clip_parent = clip_parent; |
| 3951 | |
| 3952 | clipped_surface->SetBounds(gfx::Size(50, 50)); |
| 3953 | clipped_surface->SetDrawsContent(true); |
| 3954 | clipped_surface->test_properties()->force_render_surface = true; |
| 3955 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3956 | clip_parent->SetMasksToBounds(true); |
| 3957 | unclipped_desc_surface->SetMasksToBounds(true); |
| 3958 | |
| 3959 | ExecuteCalculateDrawProperties(root); |
| 3960 | EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 3961 | EXPECT_EQ(gfx::Rect(50, 50), unclipped_desc_surface->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3962 | EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect()); |
| 3963 | } |
| 3964 | |
| 3965 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3966 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3967 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3968 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3969 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3970 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3971 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3972 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3973 | gfx::Transform child_rotation; |
| 3974 | child_rotation.Rotate(45.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3975 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3976 | root->SetBounds(gfx::Size(100, 100)); |
| 3977 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3978 | render_surface->test_properties()->force_render_surface = true; |
| 3979 | child1->SetTransform(child_rotation); |
| 3980 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 3981 | child1->SetBounds(gfx::Size(50, 50)); |
| 3982 | child1->SetDrawsContent(true); |
| 3983 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3984 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3985 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3986 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3987 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3988 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3989 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3990 | |
| 3991 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3992 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3993 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3994 | |
| 3995 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3996 | // regions of the subtree. |
| 3997 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3998 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3999 | gfx::Rect(50 - diagonal_radius, |
| 4000 | 50 - diagonal_radius, |
| 4001 | diagonal_radius * 2, |
| 4002 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4003 | EXPECT_EQ(gfx::RectF(expected_surface_drawable_content), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4004 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4005 | |
| 4006 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4007 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4008 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4009 | } |
| 4010 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4011 | TEST_F(LayerTreeHostCommonTest, |
| 4012 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4013 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 4014 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4015 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4016 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 4017 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4018 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4019 | gfx::Transform child_rotation; |
| 4020 | child_rotation.Rotate(45.0); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4021 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4022 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4023 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4024 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 4025 | render_surface->test_properties()->force_render_surface = true; |
| 4026 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 4027 | child1->SetBounds(gfx::Size(50, 50)); |
| 4028 | child1->SetDrawsContent(true); |
| 4029 | child1->SetTransform(child_rotation); |
| 4030 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4031 | ExecuteCalculateDrawProperties(root); |
| 4032 | |
| 4033 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4034 | |
| 4035 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 4036 | // rotated layer. |
| 4037 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4038 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 4039 | 50 - diagonal_radius, |
| 4040 | diagonal_radius * 2, |
| 4041 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4042 | gfx::RectF expected_surface_drawable_content( |
| 4043 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4044 | EXPECT_EQ(expected_surface_drawable_content, |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4045 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4046 | |
| 4047 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 4048 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 4049 | // up covering the full left half of child1. |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 4050 | EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4051 | |
| 4052 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4053 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4054 | } |
| 4055 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4056 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4057 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4058 | FakePictureLayerImpl* render_surface1 = |
| 4059 | AddChildToRoot<FakePictureLayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4060 | FakePictureLayerImpl* render_surface2 = |
| 4061 | AddChild<FakePictureLayerImpl>(render_surface1); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4062 | FakePictureLayerImpl* child1 = |
| 4063 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4064 | FakePictureLayerImpl* child2 = |
| 4065 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4066 | FakePictureLayerImpl* child3 = |
| 4067 | AddChild<FakePictureLayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4068 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4069 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4070 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4071 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 4072 | render_surface1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4073 | render_surface1->SetDrawsContent(true); |
| 4074 | render_surface1->test_properties()->force_render_surface = true; |
| 4075 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 4076 | render_surface2->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4077 | render_surface2->SetDrawsContent(true); |
| 4078 | render_surface2->test_properties()->force_render_surface = true; |
| 4079 | child1->SetBounds(gfx::Size(50, 50)); |
| 4080 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4081 | child1->SetDrawsContent(true); |
| 4082 | child2->SetBounds(gfx::Size(50, 50)); |
| 4083 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 4084 | child2->SetDrawsContent(true); |
| 4085 | child3->SetBounds(gfx::Size(50, 50)); |
| 4086 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 4087 | child3->SetDrawsContent(true); |
| 4088 | float device_scale_factor = 2.f; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4089 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4090 | |
| 4091 | ASSERT_TRUE(render_surface1->render_surface()); |
| 4092 | ASSERT_TRUE(render_surface2->render_surface()); |
| 4093 | |
| 4094 | // drawable_content_rects for all layers and surfaces are scaled by |
| 4095 | // device_scale_factor. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4096 | EXPECT_EQ(gfx::RectF(200.f, 200.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4097 | root->render_surface()->DrawableContentRect()); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4098 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4099 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4100 | |
| 4101 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 4102 | // is only implicitly clipped by render_surface1. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4103 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4104 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4105 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4106 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 4107 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 4108 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4109 | |
| 4110 | // The root layer does not actually draw content of its own. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4111 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4112 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4113 | // All layer visible content rects are not expressed in content space of each |
| 4114 | // layer, so they are not scaled by the device_scale_factor. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4115 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect()); |
| 4116 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect()); |
| 4117 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 4118 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 4119 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4120 | } |
| 4121 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4122 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4123 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 4124 | // layers. Note that 3d transforms still apply in this case, but they are |
| 4125 | // "flattened" to each parent layer according to current W3C spec. |
| 4126 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4127 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4128 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4129 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4130 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4131 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4132 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4133 | AddChild<LayerImpl>(front_facing_surface); |
| 4134 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4135 | AddChild<LayerImpl>(front_facing_surface); |
| 4136 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4137 | AddChild<LayerImpl>(back_facing_surface); |
| 4138 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4139 | AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4140 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4141 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4142 | front_facing_child->test_properties()->double_sided = false; |
| 4143 | back_facing_child->test_properties()->double_sided = false; |
| 4144 | front_facing_surface->test_properties()->double_sided = false; |
| 4145 | back_facing_surface->test_properties()->double_sided = false; |
| 4146 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4147 | false; |
| 4148 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4149 | false; |
| 4150 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4151 | false; |
| 4152 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4153 | false; |
| 4154 | |
| 4155 | // Everything draws content. |
| 4156 | front_facing_child->SetDrawsContent(true); |
| 4157 | back_facing_child->SetDrawsContent(true); |
| 4158 | front_facing_surface->SetDrawsContent(true); |
| 4159 | back_facing_surface->SetDrawsContent(true); |
| 4160 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4161 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4162 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4163 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4164 | |
| 4165 | gfx::Transform backface_matrix; |
| 4166 | backface_matrix.Translate(50.0, 50.0); |
| 4167 | backface_matrix.RotateAboutYAxis(180.0); |
| 4168 | backface_matrix.Translate(-50.0, -50.0); |
| 4169 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4170 | root->SetBounds(gfx::Size(100, 100)); |
| 4171 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4172 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4173 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4174 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4175 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4176 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4177 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4178 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4179 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4180 | front_facing_surface->test_properties()->force_render_surface = true; |
| 4181 | back_facing_surface->test_properties()->force_render_surface = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4182 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4183 | back_facing_child->SetTransform(backface_matrix); |
| 4184 | back_facing_surface->SetTransform(backface_matrix); |
| 4185 | back_facing_child_of_front_facing_surface->SetTransform(backface_matrix); |
| 4186 | back_facing_child_of_back_facing_surface->SetTransform(backface_matrix); |
| 4187 | |
| 4188 | // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms |
| 4189 | // spec, these layers should blindly use their own local transforms to |
| 4190 | // determine back-face culling. |
| 4191 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4192 | |
| 4193 | // Verify which render surfaces were created. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4194 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4195 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4196 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
| 4197 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4198 | EXPECT_FALSE( |
| 4199 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4200 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4201 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4202 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4203 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4204 | EXPECT_EQ(4u, update_layer_list_impl()->size()); |
| 4205 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4206 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4207 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4208 | front_facing_child_of_front_facing_surface->id())); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4209 | EXPECT_TRUE(UpdateLayerListImplContains( |
| 4210 | front_facing_child_of_back_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4211 | } |
| 4212 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4213 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4214 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 4215 | // is used. |
| 4216 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4217 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4218 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4219 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4220 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4221 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4222 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4223 | AddChild<LayerImpl>(front_facing_surface); |
| 4224 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4225 | AddChild<LayerImpl>(front_facing_surface); |
| 4226 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4227 | AddChild<LayerImpl>(back_facing_surface); |
| 4228 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4229 | AddChild<LayerImpl>(back_facing_surface); |
| 4230 | // Opacity will not force creation of render surfaces in this case because of |
| 4231 | // the preserve-3d transform style. Instead, an example of when a surface |
| 4232 | // would be created with preserve-3d is when there is a replica layer. |
| 4233 | LayerImpl* dummy_replica_layer1 = |
| 4234 | AddReplicaLayer<LayerImpl>(front_facing_surface); |
| 4235 | LayerImpl* dummy_replica_layer2 = |
| 4236 | AddReplicaLayer<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4237 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4238 | // Nothing is double-sided |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4239 | front_facing_child->test_properties()->double_sided = false; |
| 4240 | back_facing_child->test_properties()->double_sided = false; |
| 4241 | front_facing_surface->test_properties()->double_sided = false; |
| 4242 | back_facing_surface->test_properties()->double_sided = false; |
| 4243 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4244 | false; |
| 4245 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4246 | false; |
| 4247 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4248 | false; |
| 4249 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4250 | false; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4251 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4252 | // Everything draws content. |
| 4253 | front_facing_child->SetDrawsContent(true); |
| 4254 | back_facing_child->SetDrawsContent(true); |
| 4255 | front_facing_surface->SetDrawsContent(true); |
| 4256 | back_facing_surface->SetDrawsContent(true); |
| 4257 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4258 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4259 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4260 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4261 | dummy_replica_layer1->SetDrawsContent(true); |
| 4262 | dummy_replica_layer2->SetDrawsContent(true); |
| 4263 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4264 | gfx::Transform backface_matrix; |
| 4265 | backface_matrix.Translate(50.0, 50.0); |
| 4266 | backface_matrix.RotateAboutYAxis(180.0); |
| 4267 | backface_matrix.Translate(-50.0, -50.0); |
| 4268 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4269 | root->SetBounds(gfx::Size(100, 100)); |
| 4270 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4271 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4272 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4273 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4274 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4275 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4276 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4277 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4278 | |
| 4279 | back_facing_child->SetTransform(backface_matrix); |
| 4280 | back_facing_surface->SetTransform(backface_matrix); |
| 4281 | back_facing_child_of_front_facing_surface->SetTransform(backface_matrix); |
| 4282 | back_facing_child_of_back_facing_surface->SetTransform(backface_matrix); |
| 4283 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4284 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 4285 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 4286 | // rendering context should use the transform with respect to that context. |
| 4287 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 4288 | // and (b) the layer's transform style is preserve-3d. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4289 | front_facing_surface->test_properties()->should_flatten_transform = false; |
| 4290 | front_facing_surface->Set3dSortingContextId(1); |
| 4291 | back_facing_surface->test_properties()->should_flatten_transform = false; |
| 4292 | back_facing_surface->Set3dSortingContextId(1); |
| 4293 | front_facing_child_of_front_facing_surface->Set3dSortingContextId(1); |
| 4294 | back_facing_child_of_front_facing_surface->Set3dSortingContextId(1); |
| 4295 | front_facing_child_of_back_facing_surface->Set3dSortingContextId(1); |
| 4296 | back_facing_child_of_back_facing_surface->Set3dSortingContextId(1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4297 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4298 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4299 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4300 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4301 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4302 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4303 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4304 | // We expect that a has_render_surface was created but not used. |
| 4305 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4306 | EXPECT_FALSE( |
| 4307 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4308 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4309 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4310 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4311 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4312 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4313 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4314 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4315 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4316 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4317 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4318 | } |
| 4319 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4320 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4321 | // Verify that layers are appropriately culled when their back face is showing |
| 4322 | // and they are not double sided, while animations are going on. |
| 4323 | // |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4324 | // Even layers that are animating get culled if their back face is showing and |
| 4325 | // they are not double sided. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4326 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4327 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4328 | LayerImpl* animating_surface = AddChildToRoot<LayerImpl>(); |
| 4329 | LayerImpl* child_of_animating_surface = |
| 4330 | AddChild<LayerImpl>(animating_surface); |
| 4331 | LayerImpl* animating_child = AddChildToRoot<LayerImpl>(); |
| 4332 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4333 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4334 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4335 | child->test_properties()->double_sided = false; |
| 4336 | child2->test_properties()->double_sided = false; |
| 4337 | animating_surface->test_properties()->double_sided = false; |
| 4338 | child_of_animating_surface->test_properties()->double_sided = false; |
| 4339 | animating_child->test_properties()->double_sided = false; |
| 4340 | |
| 4341 | // Everything draws content. |
| 4342 | child->SetDrawsContent(true); |
| 4343 | child2->SetDrawsContent(true); |
| 4344 | animating_surface->SetDrawsContent(true); |
| 4345 | child_of_animating_surface->SetDrawsContent(true); |
| 4346 | animating_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4347 | |
| 4348 | gfx::Transform backface_matrix; |
| 4349 | backface_matrix.Translate(50.0, 50.0); |
| 4350 | backface_matrix.RotateAboutYAxis(180.0); |
| 4351 | backface_matrix.Translate(-50.0, -50.0); |
| 4352 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4353 | SetElementIdsForTesting(); |
| 4354 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4355 | // Animate the transform on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4356 | AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(), |
| 4357 | timeline_impl(), 10.0, 30, 0); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4358 | // This is just an animating layer, not a surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4359 | AddAnimatedTransformToElementWithPlayer(animating_child->element_id(), |
| 4360 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4361 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4362 | root->SetBounds(gfx::Size(100, 100)); |
| 4363 | child->SetBounds(gfx::Size(100, 100)); |
| 4364 | child->SetTransform(backface_matrix); |
| 4365 | animating_surface->SetBounds(gfx::Size(100, 100)); |
| 4366 | animating_surface->SetTransform(backface_matrix); |
| 4367 | animating_surface->test_properties()->force_render_surface = true; |
| 4368 | child_of_animating_surface->SetBounds(gfx::Size(100, 100)); |
| 4369 | child_of_animating_surface->SetTransform(backface_matrix); |
| 4370 | animating_child->SetBounds(gfx::Size(100, 100)); |
| 4371 | animating_child->SetTransform(backface_matrix); |
| 4372 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4373 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4374 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4375 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4376 | EXPECT_FALSE(child->has_render_surface()); |
| 4377 | EXPECT_TRUE(animating_surface->has_render_surface()); |
| 4378 | EXPECT_FALSE(child_of_animating_surface->has_render_surface()); |
| 4379 | EXPECT_FALSE(animating_child->has_render_surface()); |
| 4380 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4381 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4382 | EXPECT_EQ(1u, update_layer_list_impl()->size()); |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4383 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4384 | // The back facing layers are culled from the layer list, and have an empty |
| 4385 | // visible rect. |
| 4386 | EXPECT_TRUE(UpdateLayerListImplContains(child2->id())); |
| 4387 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
| 4388 | EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty()); |
| 4389 | EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty()); |
| 4390 | EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty()); |
[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(gfx::Rect(100, 100), child2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4393 | } |
| 4394 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4395 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4396 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4397 | // Verify the behavior of back-face culling for a render surface that is |
| 4398 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4399 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4400 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4401 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4402 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4403 | LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface); |
| 4404 | LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4405 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4406 | // RenderSurfaces are not double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4407 | front_facing_surface->test_properties()->double_sided = false; |
| 4408 | back_facing_surface->test_properties()->double_sided = false; |
| 4409 | |
| 4410 | // Everything draws content. |
| 4411 | front_facing_surface->SetDrawsContent(true); |
| 4412 | back_facing_surface->SetDrawsContent(true); |
| 4413 | child1->SetDrawsContent(true); |
| 4414 | child2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4415 | |
| 4416 | gfx::Transform backface_matrix; |
| 4417 | backface_matrix.Translate(50.0, 50.0); |
| 4418 | backface_matrix.RotateAboutYAxis(180.0); |
| 4419 | backface_matrix.Translate(-50.0, -50.0); |
| 4420 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4421 | root->SetBounds(gfx::Size(100, 100)); |
| 4422 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4423 | front_facing_surface->test_properties()->force_render_surface = true; |
| 4424 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4425 | back_facing_surface->SetTransform(backface_matrix); |
| 4426 | back_facing_surface->test_properties()->force_render_surface = true; |
| 4427 | child1->SetBounds(gfx::Size(100, 100)); |
| 4428 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4429 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4430 | front_facing_surface->Set3dSortingContextId(1); |
| 4431 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4432 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4433 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4434 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4435 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4436 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4437 | |
| 4438 | // We expect the render surface to have been created, but remain unused. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4439 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4440 | EXPECT_FALSE(child1->has_render_surface()); |
| 4441 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4442 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4443 | EXPECT_EQ(2u, update_layer_list_impl()->size()); |
| 4444 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4445 | EXPECT_TRUE(UpdateLayerListImplContains(child1->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4446 | } |
| 4447 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4448 | TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4449 | // Verify draw and screen space transforms of layers not in a surface. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4450 | LayerImpl* root = root_layer_for_testing(); |
| 4451 | root->SetBounds(gfx::Size(100, 100)); |
| 4452 | root->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4453 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4454 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4455 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4456 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4457 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4458 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4459 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4460 | child2->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4461 | child2->SetBounds(gfx::Size(5, 5)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4462 | child2->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4463 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4464 | float device_scale_factor = 2.5f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4465 | gfx::Size viewport_size(100, 100); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4466 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4467 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4468 | EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale()); |
| 4469 | EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale()); |
| 4470 | EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale()); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4471 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4472 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4473 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4474 | // Verify root transforms |
| 4475 | gfx::Transform expected_root_transform; |
| 4476 | expected_root_transform.Scale(device_scale_factor, device_scale_factor); |
| 4477 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4478 | root->ScreenSpaceTransform()); |
| 4479 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4480 | root->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4481 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4482 | // Verify results of transformed root rects |
| 4483 | gfx::RectF root_bounds(gfx::SizeF(root->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4484 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4485 | gfx::RectF root_draw_rect = |
| 4486 | MathUtil::MapClippedRect(root->DrawTransform(), root_bounds); |
| 4487 | gfx::RectF root_screen_space_rect = |
| 4488 | MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4489 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4490 | gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds())); |
| 4491 | expected_root_draw_rect.Scale(device_scale_factor); |
| 4492 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect); |
| 4493 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4494 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4495 | // Verify child and child2 transforms. They should match. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4496 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4497 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4498 | expected_child_transform.Translate(child->position().x(), |
| 4499 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4500 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4501 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4502 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4503 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4504 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4505 | child2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4506 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4507 | child2->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4508 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4509 | // Verify results of transformed child and child2 rects. They should |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4510 | // match. |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4511 | gfx::RectF child_bounds(gfx::SizeF(child->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4512 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4513 | gfx::RectF child_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4514 | MathUtil::MapClippedRect(child->DrawTransform(), child_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4515 | gfx::RectF child_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4516 | MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4517 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4518 | gfx::RectF child2_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4519 | MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4520 | gfx::RectF child2_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4521 | MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4522 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4523 | gfx::RectF expected_child_draw_rect(child->position(), |
| 4524 | gfx::SizeF(child->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4525 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4526 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4527 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4528 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect); |
| 4529 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4530 | } |
| 4531 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4532 | TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4533 | // Verify draw and screen space transforms of layers in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4534 | gfx::Transform perspective_matrix; |
| 4535 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4536 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4537 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4538 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4539 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4540 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4541 | root->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4542 | |
| 4543 | LayerImpl* page_scale = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4544 | page_scale->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4545 | |
| 4546 | LayerImpl* parent = AddChild<LayerImpl>(page_scale); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4547 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4548 | parent->SetDrawsContent(true); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4549 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4550 | LayerImpl* perspective_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4551 | perspective_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4552 | perspective_surface->SetBounds(gfx::Size(10, 10)); |
| 4553 | perspective_surface->SetTransform(perspective_matrix * scale_small_matrix); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4554 | perspective_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4555 | perspective_surface->test_properties()->force_render_surface = true; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4556 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4557 | LayerImpl* scale_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4558 | scale_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4559 | scale_surface->SetBounds(gfx::Size(10, 10)); |
| 4560 | scale_surface->SetTransform(scale_small_matrix); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4561 | scale_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4562 | scale_surface->test_properties()->force_render_surface = true; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4563 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4564 | float device_scale_factor = 2.5f; |
| 4565 | float page_scale_factor = 3.f; |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4566 | root->layer_tree_impl()->SetViewportLayersFromIds( |
| 4567 | Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, |
| 4568 | Layer::INVALID_ID); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4569 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4570 | root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4571 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4572 | root); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4573 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4574 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4575 | parent->GetIdealContentsScale()); |
| 4576 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4577 | perspective_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4578 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4579 | // the nearest render target. Here this includes the layer transform as well |
| 4580 | // as the device and page scale factors. |
| 4581 | gfx::Transform transform = scale_small_matrix; |
| 4582 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4583 | device_scale_factor * page_scale_factor); |
| 4584 | gfx::Vector2dF scales = |
| 4585 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4586 | float max_2d_scale = std::max(scales.x(), scales.y()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4587 | EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4588 | |
| 4589 | // The ideal scale will draw 1:1 with its render target space along |
| 4590 | // the larger-scale axis. |
| 4591 | gfx::Vector2dF target_space_transform_scales = |
| 4592 | MathUtil::ComputeTransform2dScaleComponents( |
| 4593 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4594 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4595 | std::max(target_space_transform_scales.x(), |
| 4596 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4597 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4598 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4599 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4600 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4601 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4602 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4603 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4604 | parent->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4605 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4606 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4607 | // with the screen, and then scaled during drawing. |
| 4608 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4609 | expected_perspective_surface_draw_transform.Translate( |
| 4610 | device_scale_factor * page_scale_factor * |
| 4611 | perspective_surface->position().x(), |
| 4612 | device_scale_factor * page_scale_factor * |
| 4613 | perspective_surface->position().y()); |
| 4614 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4615 | perspective_matrix); |
| 4616 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4617 | scale_small_matrix); |
| 4618 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4619 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4620 | device_scale_factor * page_scale_factor, |
| 4621 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4622 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4623 | expected_perspective_surface_draw_transform, |
| 4624 | perspective_surface->render_surface()->draw_transform()); |
| 4625 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4626 | expected_perspective_surface_layer_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4627 | perspective_surface->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4628 | } |
| 4629 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4630 | TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4631 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4632 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4633 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4634 | |
| 4635 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4636 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4637 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4638 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4639 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4640 | root->SetBounds(gfx::Size(100, 100)); |
| 4641 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4642 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4643 | parent->SetBounds(gfx::Size(100, 100)); |
| 4644 | parent->SetTransform(parent_scale_matrix); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4645 | parent->SetDrawsContent(true); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4646 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4647 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4648 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4649 | child_scale->SetBounds(gfx::Size(10, 10)); |
| 4650 | child_scale->SetTransform(child_scale_matrix); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4651 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4652 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4653 | float device_scale_factor = 2.5f; |
| 4654 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4655 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4656 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4657 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4658 | root); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4659 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4660 | // The ideal scale is able to go below 1. |
| 4661 | float expected_ideal_scale = |
| 4662 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4663 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4664 | EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale()); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4665 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4666 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4667 | initial_parent_scale * initial_child_scale; |
| 4668 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4669 | EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4670 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4671 | } |
| 4672 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4673 | TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4674 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4675 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4676 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4677 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4678 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4679 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4680 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4681 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4682 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4683 | root->SetBounds(gfx::Size(100, 100)); |
| 4684 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4685 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4686 | parent->SetBounds(gfx::Size(100, 100)); |
| 4687 | parent->SetTransform(parent_scale_matrix); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4688 | parent->SetDrawsContent(true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4689 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4690 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4691 | child_scale->SetBounds(gfx::Size(10, 10)); |
| 4692 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4693 | child_scale->SetTransform(child_scale_matrix); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4694 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4695 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4696 | ExecuteCalculateDrawProperties(root); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4697 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4698 | EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4699 | // Animating layers compute ideal scale in the same way as when |
| 4700 | // they are static. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4701 | EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale, |
| 4702 | child_scale->GetIdealContentsScale()); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4703 | } |
| 4704 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4705 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4706 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4707 | parent->SetBounds(gfx::Size(30, 30)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4708 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4709 | parent->Set3dSortingContextId(1); |
| 4710 | parent->test_properties()->should_flatten_transform = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4711 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4712 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4713 | child->SetBounds(gfx::Size(10, 10)); |
| 4714 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4715 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4716 | child->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4717 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4718 | gfx::Transform replica_transform; |
| 4719 | replica_transform.Scale(1.0, -1.0); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4720 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4721 | std::unique_ptr<LayerImpl> replica = |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4722 | LayerImpl::Create(host_impl()->active_tree(), 7); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4723 | replica->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4724 | replica->SetTransform(replica_transform); |
| 4725 | |
jaydasika | 5017a33 | 2016-03-31 01:06:22 | [diff] [blame] | 4726 | // We need to set parent on replica layer for property tree building. |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4727 | replica->test_properties()->parent = child; |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 4728 | child->test_properties()->SetReplicaLayer(std::move(replica)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4729 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4730 | // This layer should end up in the same surface as child, with the same draw |
| 4731 | // and screen space transforms. |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4732 | LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4733 | duplicate_child_non_owner->SetBounds(gfx::Size(10, 10)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4734 | duplicate_child_non_owner->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4735 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4736 | float device_scale_factor = 1.5f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4737 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4738 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4739 | // We should have two render surfaces. The root's render surface and child's |
| 4740 | // render surface (it needs one because it has a replica layer). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4741 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4742 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4743 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4744 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4745 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4746 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4747 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4748 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4749 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4750 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4751 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4752 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4753 | child->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4754 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4755 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4756 | expected_screen_space_transform.Scale(device_scale_factor, |
| 4757 | device_scale_factor); |
| 4758 | expected_screen_space_transform.Translate(child->position().x(), |
| 4759 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4760 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4761 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4762 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4763 | gfx::Transform expected_duplicate_child_draw_transform = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4764 | child->DrawTransform(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4765 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4766 | duplicate_child_non_owner->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4767 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4768 | child->ScreenSpaceTransform(), |
| 4769 | duplicate_child_non_owner->ScreenSpaceTransform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4770 | EXPECT_EQ(child->drawable_content_rect(), |
| 4771 | duplicate_child_non_owner->drawable_content_rect()); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4772 | EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4773 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4774 | gfx::Transform expected_render_surface_draw_transform; |
| 4775 | expected_render_surface_draw_transform.Translate( |
| 4776 | device_scale_factor * child->position().x(), |
| 4777 | device_scale_factor * child->position().y()); |
| 4778 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 4779 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4780 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4781 | gfx::Transform expected_surface_draw_transform; |
| 4782 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 4783 | device_scale_factor * 2.f); |
| 4784 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 4785 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4786 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4787 | gfx::Transform expected_surface_screen_space_transform; |
| 4788 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 4789 | device_scale_factor * 2.f); |
| 4790 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4791 | expected_surface_screen_space_transform, |
| 4792 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4793 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4794 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4795 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 4796 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 4797 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4798 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4799 | expected_replica_draw_transform, |
| 4800 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4801 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4802 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4803 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 4804 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 4805 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4806 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4807 | expected_replica_screen_space_transform, |
| 4808 | child->render_surface()->replica_screen_space_transform()); |
| 4809 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4810 | expected_replica_screen_space_transform, |
| 4811 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4812 | } |
| 4813 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4814 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4815 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4816 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4817 | parent->SetBounds(gfx::Size(33, 31)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4818 | parent->SetDrawsContent(true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4819 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4820 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4821 | child->SetBounds(gfx::Size(13, 11)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4822 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4823 | child->test_properties()->force_render_surface = true; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4824 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4825 | gfx::Transform replica_transform; |
| 4826 | replica_transform.Scale(1.0, -1.0); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4827 | std::unique_ptr<LayerImpl> replica = |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4828 | LayerImpl::Create(host_impl()->active_tree(), 7); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4829 | replica->SetTransform(replica_transform); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 4830 | child->test_properties()->SetReplicaLayer(std::move(replica)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4831 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 4832 | float device_scale_factor = 1.7f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4833 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4834 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4835 | // We should have two render surfaces. The root's render surface and child's |
| 4836 | // render surface (it needs one because it has a replica layer). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4837 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4838 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4839 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4840 | child->render_surface()->draw_transform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4841 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4842 | child->render_surface()->draw_transform()); |
| 4843 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4844 | gfx::Transform(), child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4845 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4846 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4847 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4848 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4849 | expected_replica_draw_transform, |
| 4850 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4851 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4852 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4853 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4854 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4855 | expected_replica_screen_space_transform, |
| 4856 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4857 | } |
| 4858 | |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 4859 | TEST_F(LayerTreeHostCommonTest, LayerSearch) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4860 | scoped_refptr<Layer> root = Layer::Create(); |
| 4861 | scoped_refptr<Layer> child = Layer::Create(); |
| 4862 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 4863 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 4864 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4865 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4866 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 4867 | child->AddChild(grand_child.get()); |
| 4868 | child->SetMaskLayer(mask_layer.get()); |
| 4869 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4870 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4871 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4872 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4873 | int nonexistent_id = -1; |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 4874 | EXPECT_EQ(root.get(), host()->LayerById(root->id())); |
| 4875 | EXPECT_EQ(child.get(), host()->LayerById(child->id())); |
| 4876 | EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id())); |
| 4877 | EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id())); |
| 4878 | EXPECT_EQ(replica_layer.get(), host()->LayerById(replica_layer->id())); |
| 4879 | EXPECT_FALSE(host()->LayerById(nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4880 | } |
| 4881 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4882 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4883 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4884 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 4885 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4886 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4887 | root->SetBounds(gfx::Size(100, 100)); |
| 4888 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4889 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4890 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 4891 | grand_child->SetDrawsContent(true); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4892 | ExecuteCalculateDrawProperties(root); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4893 | EXPECT_FALSE(child->has_render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4894 | } |
| 4895 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4896 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4897 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4898 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 4899 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4900 | FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider, |
| 4901 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4902 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4903 | std::unique_ptr<LayerImpl> root = |
| 4904 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4905 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4906 | root->SetDrawsContent(true); |
| 4907 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4908 | std::unique_ptr<LayerImpl> child = |
| 4909 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4910 | child->SetBounds(gfx::Size(50, 50)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4911 | child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4912 | child->test_properties()->opacity = 0.0f; |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4913 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 4914 | const int child_id = child->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4915 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 4916 | root->SetHasRenderSurface(true); |
| 4917 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4918 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4919 | host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4920 | |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4921 | // Add opacity animation. |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4922 | scoped_refptr<AnimationTimeline> timeline = |
| 4923 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 4924 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4925 | host_impl.pending_tree()->SetElementIdsForTesting(); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4926 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4927 | ElementId child_element_id = |
| 4928 | host_impl.pending_tree()->LayerById(child_id)->element_id(); |
| 4929 | |
| 4930 | AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0, |
| 4931 | 0.0f, 1.0f, false); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4932 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4933 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4934 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4935 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4936 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4937 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4938 | |
| 4939 | // We should have one render surface and two layers. The child |
| 4940 | // layer should be included even though it is transparent. |
| 4941 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4942 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4943 | |
| 4944 | // If the root itself is hidden, the child should not be drawn even if it has |
| 4945 | // an animating opacity. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4946 | root_layer->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4947 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4948 | LayerImplList render_surface_layer_list2; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4949 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4950 | root_layer, root_layer->bounds(), &render_surface_layer_list2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4951 | inputs2.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4952 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4953 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4954 | LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4955 | EffectTree& tree = |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4956 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4957 | EffectNode* node = tree.Node(child_ptr->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4958 | EXPECT_FALSE(node->is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4959 | |
| 4960 | // A layer should be drawn and it should contribute to drawn surface when |
| 4961 | // it has animating opacity even if it has opacity 0. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4962 | root_layer->test_properties()->opacity = 1.0f; |
| 4963 | child_ptr->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4964 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4965 | LayerImplList render_surface_layer_list3; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4966 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4967 | root_layer, root_layer->bounds(), &render_surface_layer_list3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4968 | inputs3.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4969 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4970 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4971 | child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
| 4972 | tree = root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4973 | node = tree.Node(child_ptr->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4974 | EXPECT_TRUE(node->is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4975 | EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index())); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4976 | |
| 4977 | // But if the opacity of the layer remains 0 after activation, it should not |
| 4978 | // be drawn. |
| 4979 | host_impl.ActivateSyncTree(); |
danakj | 0da42ca6 | 2016-07-01 19:42:33 | [diff] [blame] | 4980 | LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id()); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4981 | LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id()); |
| 4982 | |
| 4983 | EffectTree& active_effect_tree = |
| 4984 | host_impl.active_tree()->property_trees()->effect_tree; |
| 4985 | EXPECT_TRUE(active_effect_tree.needs_update()); |
| 4986 | |
| 4987 | ExecuteCalculateDrawProperties(active_root); |
| 4988 | |
| 4989 | node = active_effect_tree.Node(active_child->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4990 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4991 | EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface( |
| 4992 | active_child->effect_tree_index())); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4993 | } |
| 4994 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4995 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4996 | class LCDTextTest : public LayerTreeHostCommonTestBase, |
| 4997 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4998 | public: |
| 4999 | LCDTextTest() |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5000 | : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()), |
| 5001 | host_impl_(LCDTextTestLayerTreeSettings(), |
| 5002 | &task_runner_provider_, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5003 | &shared_bitmap_manager_, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5004 | &task_graph_runner_) {} |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5005 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5006 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 5007 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5008 | protected: |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5009 | LayerTreeSettings LCDTextTestLayerTreeSettings() { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5010 | LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings(); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5011 | |
| 5012 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
| 5013 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
| 5014 | settings.can_use_lcd_text = can_use_lcd_text_; |
| 5015 | settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_; |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5016 | return settings; |
| 5017 | } |
| 5018 | |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 5019 | void SetUp() override { |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5020 | timeline_ = |
| 5021 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 5022 | host_impl_.animation_host()->AddAnimationTimeline(timeline_); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5023 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5024 | std::unique_ptr<LayerImpl> root_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5025 | LayerImpl::Create(host_impl_.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5026 | std::unique_ptr<LayerImpl> child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5027 | LayerImpl::Create(host_impl_.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5028 | std::unique_ptr<LayerImpl> grand_child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5029 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 5030 | |
| 5031 | // Stash raw pointers to look at later. |
| 5032 | root_ = root_ptr.get(); |
| 5033 | child_ = child_ptr.get(); |
| 5034 | grand_child_ = grand_child_ptr.get(); |
| 5035 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5036 | child_->test_properties()->AddChild(std::move(grand_child_ptr)); |
| 5037 | root_->test_properties()->AddChild(std::move(child_ptr)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5038 | host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5039 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5040 | host_impl_.active_tree()->SetElementIdsForTesting(); |
| 5041 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5042 | root_->SetContentsOpaque(true); |
| 5043 | child_->SetContentsOpaque(true); |
| 5044 | grand_child_->SetContentsOpaque(true); |
| 5045 | |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5046 | root_->SetDrawsContent(true); |
| 5047 | child_->SetDrawsContent(true); |
| 5048 | grand_child_->SetDrawsContent(true); |
| 5049 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5050 | root_->SetBounds(gfx::Size(1, 1)); |
| 5051 | child_->SetBounds(gfx::Size(1, 1)); |
| 5052 | grand_child_->SetBounds(gfx::Size(1, 1)); |
| 5053 | |
| 5054 | child_->test_properties()->force_render_surface = |
| 5055 | std::tr1::get<2>(GetParam()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5056 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5057 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5058 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5059 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5060 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5061 | FakeImplTaskRunnerProvider task_runner_provider_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5062 | TestSharedBitmapManager shared_bitmap_manager_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5063 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5064 | FakeLayerTreeHostImpl host_impl_; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5065 | scoped_refptr<AnimationTimeline> timeline_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5066 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5067 | LayerImpl* root_ = nullptr; |
| 5068 | LayerImpl* child_ = nullptr; |
| 5069 | LayerImpl* grand_child_ = nullptr; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5070 | }; |
| 5071 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5072 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5073 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5074 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5075 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5076 | // Case 1: Identity transform. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5077 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5078 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5079 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5080 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5081 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5082 | // Case 2: Integral translation. |
| 5083 | gfx::Transform integral_translation; |
| 5084 | integral_translation.Translate(1.0, 2.0); |
| 5085 | child_->SetTransform(integral_translation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5086 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5087 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5088 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5089 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5090 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5091 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5092 | // Case 3: Non-integral translation. |
| 5093 | gfx::Transform non_integral_translation; |
| 5094 | non_integral_translation.Translate(1.5, 2.5); |
| 5095 | child_->SetTransform(non_integral_translation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5096 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5097 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5098 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5099 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5100 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5101 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5102 | // Case 4: Rotation. |
| 5103 | gfx::Transform rotation; |
| 5104 | rotation.Rotate(10.0); |
| 5105 | child_->SetTransform(rotation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5106 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5107 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5108 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5109 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5110 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5111 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5112 | // Case 5: Scale. |
| 5113 | gfx::Transform scale; |
| 5114 | scale.Scale(2.0, 2.0); |
| 5115 | child_->SetTransform(scale); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5116 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5117 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5118 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5119 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5120 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5121 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5122 | // Case 6: Skew. |
| 5123 | gfx::Transform skew; |
nainar | 8ca8ee6 | 2015-09-03 01:04:10 | [diff] [blame] | 5124 | skew.Skew(10.0, 0.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5125 | child_->SetTransform(skew); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5126 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5127 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5128 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5129 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5130 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5131 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5132 | // Case 7: Translucent. |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5133 | child_->SetTransform(gfx::Transform()); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5134 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5135 | child_->test_properties()->opacity = 0.5f; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5136 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5137 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5138 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5139 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5140 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5141 | // Case 8: Sanity check: restore transform and opacity. |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5142 | child_->SetTransform(gfx::Transform()); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5143 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5144 | child_->test_properties()->opacity = 1.f; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5145 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5146 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5147 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5148 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5149 | |
| 5150 | // Case 9: Non-opaque content. |
| 5151 | child_->SetContentsOpaque(false); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5152 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5153 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5154 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5155 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5156 | |
| 5157 | // Case 10: Sanity check: restore content opaqueness. |
| 5158 | child_->SetContentsOpaque(true); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5159 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5160 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5161 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5162 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5163 | } |
| 5164 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5165 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5166 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5167 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5168 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5169 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5170 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5171 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5172 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5173 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5174 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5175 | // Add opacity animation. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5176 | child_->test_properties()->opacity = 0.9f; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5177 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5178 | |
| 5179 | SetElementIdsForTesting(); |
| 5180 | |
| 5181 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5182 | 10.0, 0.9f, 0.1f, false); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5183 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5184 | // Text LCD should be adjusted while animation is active. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5185 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5186 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5187 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 5191 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5192 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5193 | |
| 5194 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5195 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5196 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5197 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5198 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5199 | SetElementIdsForTesting(); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5200 | |
| 5201 | // Mark contents non-opaque within the first animation frame. |
| 5202 | child_->SetContentsOpaque(false); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5203 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5204 | 10.0, 0.9f, 0.1f, false); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5205 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5206 | // LCD text should be disabled for non-opaque layers even during animations. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5207 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5208 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5209 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5210 | } |
| 5211 | |
| 5212 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5213 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5214 | testing::Combine(testing::Bool(), |
| 5215 | testing::Bool(), |
| 5216 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5217 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5218 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5219 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5220 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5221 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5222 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5223 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5224 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5225 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5226 | std::unique_ptr<LayerImpl> root = |
| 5227 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5228 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5229 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5230 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5231 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5232 | std::unique_ptr<LayerImpl> child = |
| 5233 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5234 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5235 | child->SetDrawsContent(true); |
| 5236 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5237 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5238 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5239 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5240 | grand_child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5241 | grand_child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5242 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5243 | child->test_properties()->AddChild(std::move(grand_child)); |
| 5244 | root->test_properties()->AddChild(std::move(child)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5245 | root->SetHasRenderSurface(true); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5246 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5247 | |
| 5248 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5249 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5250 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5251 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5252 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5253 | |
| 5254 | // We should have one render surface and two layers. The grand child has |
| 5255 | // hidden itself. |
| 5256 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5257 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5258 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
| 5259 | EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5260 | } |
| 5261 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5262 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5263 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5264 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5265 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5266 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5267 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5268 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5269 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5270 | std::unique_ptr<LayerImpl> root = |
| 5271 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5272 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5273 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5274 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5275 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5276 | std::unique_ptr<LayerImpl> child = |
| 5277 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5278 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5279 | child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5280 | child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5281 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5282 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5283 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5284 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5285 | grand_child->SetDrawsContent(true); |
| 5286 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5287 | child->test_properties()->AddChild(std::move(grand_child)); |
| 5288 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5289 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5290 | |
| 5291 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5292 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5293 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5294 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5295 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5296 | |
| 5297 | // We should have one render surface and one layers. The child has |
| 5298 | // hidden itself and the grand child. |
| 5299 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5300 | ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size()); |
| 5301 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5302 | } |
| 5303 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5304 | void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5305 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5306 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5307 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5308 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5309 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5310 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5311 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5312 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5313 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5314 | std::unique_ptr<LayerImpl> root = |
| 5315 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5316 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5317 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5318 | LayerImpl* root_layer = root.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5319 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5320 | std::unique_ptr<LayerImpl> copy_grand_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5321 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5322 | copy_grand_parent->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5323 | copy_grand_parent->SetDrawsContent(true); |
| 5324 | LayerImpl* copy_grand_parent_layer = copy_grand_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5325 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5326 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5327 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5328 | copy_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5329 | copy_parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5330 | copy_parent->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5331 | LayerImpl* copy_parent_layer = copy_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5332 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5333 | std::unique_ptr<LayerImpl> copy_request = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5334 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5335 | copy_request->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5336 | copy_request->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5337 | copy_request->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5338 | LayerImpl* copy_layer = copy_request.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5339 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5340 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5341 | LayerImpl::Create(host_impl.pending_tree(), 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5342 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5343 | copy_child->SetDrawsContent(true); |
| 5344 | LayerImpl* copy_child_layer = copy_child.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5345 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5346 | std::unique_ptr<LayerImpl> copy_grand_child = |
thakis | e53c527 | 2016-01-24 01:20:40 | [diff] [blame] | 5347 | LayerImpl::Create(host_impl.pending_tree(), 6); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5348 | copy_grand_child->SetBounds(gfx::Size(20, 20)); |
| 5349 | copy_grand_child->SetDrawsContent(true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5350 | LayerImpl* copy_grand_child_layer = copy_grand_child.get(); |
| 5351 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5352 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5353 | LayerImpl::Create(host_impl.pending_tree(), 7); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5354 | copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5355 | copy_grand_parent_sibling_before->SetDrawsContent(true); |
| 5356 | LayerImpl* copy_grand_parent_sibling_before_layer = |
| 5357 | copy_grand_parent_sibling_before.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5358 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5359 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5360 | LayerImpl::Create(host_impl.pending_tree(), 8); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5361 | copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5362 | copy_grand_parent_sibling_after->SetDrawsContent(true); |
| 5363 | LayerImpl* copy_grand_parent_sibling_after_layer = |
| 5364 | copy_grand_parent_sibling_after.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5365 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5366 | copy_child->test_properties()->AddChild(std::move(copy_grand_child)); |
| 5367 | copy_request->test_properties()->AddChild(std::move(copy_child)); |
| 5368 | copy_parent->test_properties()->AddChild(std::move(copy_request)); |
| 5369 | copy_grand_parent->test_properties()->AddChild(std::move(copy_parent)); |
| 5370 | root->test_properties()->AddChild( |
| 5371 | std::move(copy_grand_parent_sibling_before)); |
| 5372 | root->test_properties()->AddChild(std::move(copy_grand_parent)); |
| 5373 | root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5374 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5375 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5376 | // 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] | 5377 | // hidden subtree on copy_layer. Also hide the copy grand child and its |
| 5378 | // subtree. |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5379 | copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true; |
| 5380 | copy_grand_parent_sibling_before_layer->test_properties() |
| 5381 | ->hide_layer_and_subtree = true; |
| 5382 | copy_grand_parent_sibling_after_layer->test_properties() |
| 5383 | ->hide_layer_and_subtree = true; |
| 5384 | copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5385 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5386 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5387 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5388 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5389 | LayerImplList render_surface_layer_list; |
| 5390 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5391 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5392 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5393 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5394 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5395 | EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 5396 | EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5397 | EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5398 | EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5399 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5400 | // We should have four render surfaces, one for the root, one for the grand |
| 5401 | // parent since it has opacity and two drawing descendants, one for the parent |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5402 | // since it owns a surface, and one for the copy_layer. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5403 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5404 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5405 | EXPECT_EQ(copy_grand_parent_layer->id(), |
| 5406 | render_surface_layer_list.at(1)->id()); |
| 5407 | EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id()); |
| 5408 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5409 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5410 | // The root render surface should have 2 contributing layers. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5411 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5412 | EXPECT_EQ(root_layer->id(), |
| 5413 | root_layer->render_surface()->layer_list().at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5414 | EXPECT_EQ(copy_grand_parent_layer->id(), |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5415 | root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5416 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 5417 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5418 | // appear in its list, since it needs to be drawn for the copy request. |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5419 | ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5420 | EXPECT_EQ(copy_layer->id(), |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5421 | copy_parent_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5422 | |
| 5423 | // The copy_layer's render surface should have two contributing layers. |
| 5424 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 5425 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5426 | copy_layer->render_surface()->layer_list().at(0)->id()); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5427 | EXPECT_EQ(copy_child_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5428 | copy_layer->render_surface()->layer_list().at(1)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5429 | |
| 5430 | // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden, |
| 5431 | // but the copy_layer and copy_child should be drawn for the copy request. |
| 5432 | // copy grand child should not be drawn as its hidden even in the copy |
| 5433 | // request. |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 5434 | EffectTree& tree = |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5435 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5436 | EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5437 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5438 | node = tree.Node(copy_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5439 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5440 | node = tree.Node(copy_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5441 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5442 | node = tree.Node(copy_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5443 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5444 | node = tree.Node(copy_grand_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5445 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5446 | |
| 5447 | // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its |
| 5448 | // actually hidden. |
| 5449 | EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5450 | } |
| 5451 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5452 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5453 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5454 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5455 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5456 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5457 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5458 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5459 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5460 | std::unique_ptr<LayerImpl> root = |
| 5461 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5462 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5463 | root->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5464 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5465 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5466 | LayerImpl::Create(host_impl.pending_tree(), 2); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5467 | copy_parent->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5468 | copy_parent->SetMasksToBounds(true); |
| 5469 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5470 | std::unique_ptr<LayerImpl> copy_layer = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5471 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5472 | copy_layer->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5473 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5474 | copy_layer->test_properties()->force_render_surface = true; |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5475 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5476 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5477 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5478 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5479 | copy_child->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5480 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5481 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5482 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5483 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5484 | copy_layer->test_properties()->AddChild(std::move(copy_child)); |
| 5485 | copy_parent->test_properties()->AddChild(std::move(copy_layer)); |
| 5486 | root->test_properties()->AddChild(std::move(copy_parent)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5487 | |
| 5488 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5489 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5490 | root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5491 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5492 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5493 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5494 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5495 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5496 | // We should have two render surface, as the others are clipped out. |
| 5497 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5498 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5499 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5500 | // The root render surface should only have 2 contributing layer, since the |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5501 | // other layers are empty/clipped away. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5502 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5503 | EXPECT_EQ(root_layer->id(), |
| 5504 | root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5505 | } |
| 5506 | |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5507 | TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5508 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5509 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5510 | root->SetDrawsContent(true); |
| 5511 | root->SetMasksToBounds(true); |
| 5512 | |
| 5513 | LayerImpl* copy_layer = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5514 | copy_layer->SetBounds(gfx::Size(100, 100)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5515 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5516 | copy_layer->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5517 | |
| 5518 | LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5519 | copy_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5520 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5521 | copy_child->SetDrawsContent(true); |
| 5522 | |
| 5523 | LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5524 | copy_clip->SetBounds(gfx::Size(55, 55)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5525 | copy_clip->SetMasksToBounds(true); |
| 5526 | |
| 5527 | LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5528 | copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5529 | copy_clipped_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5530 | copy_clipped_child->SetDrawsContent(true); |
| 5531 | |
| 5532 | LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5533 | copy_surface->SetPosition(gfx::PointF(45.f, 45.f)); |
| 5534 | copy_surface->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5535 | copy_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5536 | copy_surface->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5537 | |
| 5538 | copy_layer->test_properties()->copy_requests.push_back( |
| 5539 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5540 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5541 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5542 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5543 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5544 | |
| 5545 | EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect()); |
| 5546 | EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect()); |
| 5547 | EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect()); |
| 5548 | EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect()); |
| 5549 | |
| 5550 | // Case 2: When the non root copy request layer is clipped. |
| 5551 | copy_layer->SetBounds(gfx::Size(50, 50)); |
| 5552 | copy_layer->SetMasksToBounds(true); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5553 | copy_layer->test_properties()->copy_requests.push_back( |
| 5554 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5555 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5556 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5557 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5558 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5559 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5560 | |
| 5561 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5562 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5563 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5564 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | 296dd9f | 2016-07-05 14:59:51 | [diff] [blame] | 5565 | |
| 5566 | // Case 3: When there is device scale factor. |
| 5567 | float device_scale_factor = 2.f; |
| 5568 | copy_layer->test_properties()->copy_requests.push_back( |
| 5569 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5570 | |
| 5571 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
| 5572 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 5573 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
| 5574 | |
| 5575 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5576 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5577 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5578 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5579 | } |
| 5580 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5581 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5582 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5583 | LayerImpl* surface = AddChild<LayerImpl>(root); |
| 5584 | LayerImpl* surface_child = AddChild<LayerImpl>(surface); |
| 5585 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5586 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5587 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5588 | surface->SetPosition(gfx::PointF(-10, 20)); |
| 5589 | surface->test_properties()->force_render_surface = true; |
| 5590 | surface_child->SetBounds(gfx::Size(50, 50)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5591 | surface_child->SetDrawsContent(true); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5592 | ExecuteCalculateDrawProperties(root); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5593 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 5594 | // The visible_layer_rect for the |surface_child| should not be clipped by |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5595 | // the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5596 | EXPECT_EQ(gfx::Rect(50, 50), surface_child->visible_layer_rect()); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5597 | } |
| 5598 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5599 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 5600 | // Ensure that a transform between the layer and its render surface is not a |
| 5601 | // problem. Constructs the following layer tree. |
| 5602 | // |
| 5603 | // root (a render surface) |
| 5604 | // + render_surface |
| 5605 | // + clip_parent (scaled) |
| 5606 | // + intervening_clipping_layer |
| 5607 | // + clip_child |
| 5608 | // |
| 5609 | // The render surface should be resized correctly and the clip child should |
| 5610 | // inherit the right clip rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5611 | LayerImpl* root = root_layer_for_testing(); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5612 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 5613 | LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5614 | clip_parent->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5615 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5616 | intervening->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5617 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5618 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5619 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5620 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5621 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5622 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5623 | |
| 5624 | intervening->SetMasksToBounds(true); |
| 5625 | clip_parent->SetMasksToBounds(true); |
| 5626 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5627 | gfx::Transform scale_transform; |
| 5628 | scale_transform.Scale(2, 2); |
| 5629 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5630 | root->SetBounds(gfx::Size(50, 50)); |
| 5631 | render_surface->SetBounds(gfx::Size(10, 10)); |
| 5632 | render_surface->test_properties()->force_render_surface = true; |
| 5633 | clip_parent->SetTransform(scale_transform); |
| 5634 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5635 | clip_parent->SetBounds(gfx::Size(10, 10)); |
| 5636 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5637 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5638 | clip_child->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5639 | clip_child->SetBounds(gfx::Size(10, 10)); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5640 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5641 | |
| 5642 | ASSERT_TRUE(root->render_surface()); |
| 5643 | ASSERT_TRUE(render_surface->render_surface()); |
| 5644 | |
| 5645 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 5646 | // by the intervening clip layer. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5647 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect()); |
| 5648 | ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect()); |
| 5649 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5650 | |
| 5651 | // Ensure that the render surface reports a content rect that has been grown |
| 5652 | // to accomodate for the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5653 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), |
| 5654 | render_surface->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5655 | |
| 5656 | // The above check implies the two below, but they nicely demonstrate that |
| 5657 | // we've grown, despite the intervening layer's clip. |
| 5658 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 5659 | render_surface->render_surface()->content_rect())); |
| 5660 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 5661 | render_surface->render_surface()->content_rect())); |
| 5662 | } |
| 5663 | |
| 5664 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 5665 | // Ensure that intervening render surfaces are not a problem in the basic |
| 5666 | // case. In the following tree, both render surfaces should be resized to |
| 5667 | // accomodate for the clip child, despite an intervening clip. |
| 5668 | // |
| 5669 | // root (a render surface) |
| 5670 | // + clip_parent (masks to bounds) |
| 5671 | // + render_surface1 (sets opacity) |
| 5672 | // + intervening (masks to bounds) |
| 5673 | // + render_surface2 (also sets opacity) |
| 5674 | // + clip_child |
| 5675 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5676 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5677 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5678 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5679 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5680 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5681 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5682 | render_surface1->SetDrawsContent(true); |
| 5683 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5684 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5685 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5686 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5687 | |
| 5688 | intervening->SetMasksToBounds(true); |
| 5689 | clip_parent->SetMasksToBounds(true); |
| 5690 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5691 | gfx::Transform translation_transform; |
| 5692 | translation_transform.Translate(2, 2); |
| 5693 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5694 | root->SetBounds(gfx::Size(50, 50)); |
| 5695 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5696 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5697 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5698 | render_surface1->test_properties()->force_render_surface = true; |
| 5699 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5700 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5701 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5702 | render_surface2->test_properties()->force_render_surface = true; |
| 5703 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5704 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5705 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5706 | |
| 5707 | EXPECT_TRUE(root->render_surface()); |
| 5708 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5709 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5710 | |
| 5711 | // Since the render surfaces could have expanded, they should not clip (their |
| 5712 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5713 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5714 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5715 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5716 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5717 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5718 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5719 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5720 | |
| 5721 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5722 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5723 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5724 | |
| 5725 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5726 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5727 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5728 | |
| 5729 | // The content rects of both render surfaces should both have expanded to |
| 5730 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5731 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5732 | render_surface1->render_surface()->content_rect()); |
| 5733 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), |
| 5734 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5735 | |
| 5736 | // The clip child should have inherited the clip parent's clip (projected to |
| 5737 | // the right space, of course), and should have the correctly sized visible |
| 5738 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5739 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect()); |
| 5740 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5741 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5742 | } |
| 5743 | |
| 5744 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 5745 | // Ensure that intervening render surfaces are not a problem, even if there |
| 5746 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 5747 | // of transform. |
| 5748 | // |
| 5749 | // root (a render surface) |
| 5750 | // + clip_parent (masks to bounds) |
| 5751 | // + render_surface1 (sets opacity) |
| 5752 | // + intervening (masks to bounds AND scrolls) |
| 5753 | // + render_surface2 (also sets opacity) |
| 5754 | // + clip_child |
| 5755 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5756 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5757 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5758 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5759 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5760 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5761 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5762 | render_surface1->SetDrawsContent(true); |
| 5763 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5764 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5765 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5766 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5767 | |
| 5768 | intervening->SetMasksToBounds(true); |
| 5769 | clip_parent->SetMasksToBounds(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5770 | intervening->SetScrollClipLayer(clip_parent->id()); |
| 5771 | intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5772 | |
| 5773 | gfx::Transform translation_transform; |
| 5774 | translation_transform.Translate(2, 2); |
| 5775 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5776 | root->SetBounds(gfx::Size(50, 50)); |
| 5777 | clip_parent->SetTransform(translation_transform); |
| 5778 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5779 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5780 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5781 | render_surface1->test_properties()->force_render_surface = true; |
| 5782 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5783 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5784 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5785 | render_surface2->test_properties()->force_render_surface = true; |
| 5786 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5787 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5788 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5789 | |
| 5790 | EXPECT_TRUE(root->render_surface()); |
| 5791 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5792 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5793 | |
| 5794 | // Since the render surfaces could have expanded, they should not clip (their |
| 5795 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5796 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5797 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5798 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5799 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5800 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5801 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5802 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5803 | |
| 5804 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5805 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5806 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5807 | |
| 5808 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5809 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5810 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5811 | |
| 5812 | // The content rects of both render surfaces should both have expanded to |
| 5813 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5814 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5815 | render_surface1->render_surface()->content_rect()); |
| 5816 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), |
| 5817 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5818 | |
| 5819 | // The clip child should have inherited the clip parent's clip (projected to |
| 5820 | // the right space, of course), and should have the correctly sized visible |
| 5821 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5822 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect()); |
| 5823 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5824 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5825 | } |
| 5826 | |
| 5827 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 5828 | // Ensures that descendants of the clip child inherit the correct clip. |
| 5829 | // |
| 5830 | // root (a render surface) |
| 5831 | // + clip_parent (masks to bounds) |
| 5832 | // + intervening (masks to bounds) |
| 5833 | // + clip_child |
| 5834 | // + child |
| 5835 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5836 | LayerImpl* root = root_layer_for_testing(); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5837 | LayerImpl* clip_parent = AddChild<LayerImpl>(root); |
| 5838 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
| 5839 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5840 | LayerImpl* child = AddChild<LayerImpl>(clip_child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5841 | clip_child->SetDrawsContent(true); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5842 | child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5843 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5844 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5845 | clip_parent->test_properties()->clip_children = |
| 5846 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5847 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5848 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5849 | root->SetBounds(gfx::Size(50, 50)); |
| 5850 | clip_parent->SetBounds(gfx::Size(40, 40)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5851 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5852 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5853 | intervening->SetMasksToBounds(true); |
| 5854 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 5855 | child->SetBounds(gfx::Size(60, 60)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5856 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5857 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5858 | |
| 5859 | EXPECT_TRUE(root->render_surface()); |
| 5860 | |
| 5861 | // Neither the clip child nor its descendant should have inherited the clip |
| 5862 | // from |intervening|. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5863 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5864 | EXPECT_TRUE(clip_child->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5865 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5866 | EXPECT_TRUE(child->is_clipped()); |
| 5867 | } |
| 5868 | |
| 5869 | TEST_F(LayerTreeHostCommonTest, |
| 5870 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 5871 | // Ensures that non-descendant clip children in the tree do not affect |
| 5872 | // render surfaces. |
| 5873 | // |
| 5874 | // root (a render surface) |
| 5875 | // + clip_parent (masks to bounds) |
| 5876 | // + render_surface1 |
| 5877 | // + clip_child |
| 5878 | // + render_surface2 |
| 5879 | // + non_clip_child |
| 5880 | // |
| 5881 | // In this example render_surface2 should be unaffected by clip_child. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5882 | LayerImpl* root = root_layer_for_testing(); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5883 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5884 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5885 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5886 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5887 | LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5888 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5889 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5890 | clip_parent->test_properties()->clip_children = |
| 5891 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5892 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5893 | |
| 5894 | clip_parent->SetMasksToBounds(true); |
| 5895 | render_surface1->SetMasksToBounds(true); |
| 5896 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5897 | render_surface1->SetDrawsContent(true); |
| 5898 | clip_child->SetDrawsContent(true); |
| 5899 | render_surface2->SetDrawsContent(true); |
| 5900 | non_clip_child->SetDrawsContent(true); |
| 5901 | |
| 5902 | root->SetBounds(gfx::Size(15, 15)); |
| 5903 | clip_parent->SetBounds(gfx::Size(10, 10)); |
| 5904 | render_surface1->SetPosition(gfx::PointF(5, 5)); |
| 5905 | render_surface1->SetBounds(gfx::Size(5, 5)); |
| 5906 | render_surface1->test_properties()->force_render_surface = true; |
| 5907 | render_surface2->SetBounds(gfx::Size(5, 5)); |
| 5908 | render_surface2->test_properties()->force_render_surface = true; |
| 5909 | clip_child->SetPosition(gfx::PointF(-1, 1)); |
| 5910 | clip_child->SetBounds(gfx::Size(10, 10)); |
| 5911 | non_clip_child->SetBounds(gfx::Size(5, 5)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5912 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5913 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5914 | |
| 5915 | EXPECT_TRUE(root->render_surface()); |
| 5916 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5917 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5918 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5919 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5920 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5921 | |
| 5922 | // The render surface should not clip (it has unclipped descendants), instead |
| 5923 | // it should rely on layer clipping. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5924 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5925 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5926 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 5927 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5928 | // That said, it should have grown to accomodate the unclipped descendant and |
| 5929 | // its own size. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5930 | EXPECT_EQ(gfx::Rect(-1, 0, 6, 5), |
| 5931 | render_surface1->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5932 | |
| 5933 | // This render surface should clip. It has no unclipped descendants. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5934 | EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 5935 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5936 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 5937 | EXPECT_FALSE(render_surface2->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5938 | |
| 5939 | // It also shouldn't have grown to accomodate the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5940 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), |
| 5941 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5942 | |
| 5943 | // Sanity check our num_unclipped_descendants values. |
ajuma | 0641ded | 2016-05-05 21:28:21 | [diff] [blame] | 5944 | EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants); |
| 5945 | EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5946 | } |
| 5947 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5948 | TEST_F(LayerTreeHostCommonTest, |
| 5949 | CreateRenderSurfaceWhenFlattenInsideRenderingContext) { |
| 5950 | // Verifies that Render Surfaces are created at the edge of rendering context. |
| 5951 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5952 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5953 | LayerImpl* child1 = AddChildToRoot<LayerImpl>(); |
| 5954 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 5955 | LayerImpl* child3 = AddChild<LayerImpl>(child2); |
| 5956 | root->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5957 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5958 | gfx::Size bounds(100, 100); |
| 5959 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5960 | root->SetBounds(bounds); |
| 5961 | child1->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5962 | child1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5963 | child1->Set3dSortingContextId(1); |
| 5964 | child1->test_properties()->should_flatten_transform = false; |
| 5965 | child2->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5966 | child2->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5967 | child2->Set3dSortingContextId(1); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5968 | child3->SetBounds(bounds); |
| 5969 | child3->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5970 | child3->Set3dSortingContextId(1); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5971 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5972 | |
| 5973 | // Verify which render surfaces were created. |
| 5974 | EXPECT_TRUE(root->has_render_surface()); |
| 5975 | EXPECT_FALSE(child1->has_render_surface()); |
| 5976 | EXPECT_TRUE(child2->has_render_surface()); |
| 5977 | EXPECT_FALSE(child3->has_render_surface()); |
| 5978 | } |
| 5979 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5980 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5981 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5982 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5983 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5984 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5985 | &task_graph_runner); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5986 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5987 | std::unique_ptr<LayerImpl> root = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5988 | LayerImpl::Create(host_impl.active_tree(), 12345); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5989 | std::unique_ptr<LayerImpl> child1 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5990 | LayerImpl::Create(host_impl.active_tree(), 123456); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5991 | std::unique_ptr<LayerImpl> child2 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5992 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5993 | std::unique_ptr<LayerImpl> child3 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5994 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 5995 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5996 | gfx::Size bounds(100, 100); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5997 | |
| 5998 | root->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5999 | root->SetDrawsContent(true); |
| 6000 | |
| 6001 | // This layer structure normally forces render surface due to preserves3d |
| 6002 | // behavior. |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6003 | child1->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6004 | child1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6005 | child1->Set3dSortingContextId(1); |
| 6006 | child1->test_properties()->should_flatten_transform = false; |
| 6007 | child2->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6008 | child2->SetDrawsContent(true); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6009 | child2->Set3dSortingContextId(1); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6010 | child3->SetBounds(bounds); |
| 6011 | child3->SetDrawsContent(true); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6012 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6013 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6014 | child2->test_properties()->AddChild(std::move(child3)); |
| 6015 | child1->test_properties()->AddChild(std::move(child2)); |
| 6016 | root->test_properties()->AddChild(std::move(child1)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6017 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6018 | root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6019 | |
| 6020 | { |
| 6021 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6022 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6023 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6024 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6025 | inputs.can_render_to_separate_surface = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6026 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6027 | |
| 6028 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6029 | |
| 6030 | int count_represents_target_render_surface = 0; |
| 6031 | int count_represents_contributing_render_surface = 0; |
| 6032 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6033 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6034 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6035 | it != end; ++it) { |
| 6036 | if (it.represents_target_render_surface()) |
| 6037 | count_represents_target_render_surface++; |
| 6038 | if (it.represents_contributing_render_surface()) |
| 6039 | count_represents_contributing_render_surface++; |
| 6040 | if (it.represents_itself()) |
| 6041 | count_represents_itself++; |
| 6042 | } |
| 6043 | |
| 6044 | // Two render surfaces. |
| 6045 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 6046 | // Second render surface contributes to root render surface. |
| 6047 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 6048 | // All 4 layers represent itself. |
| 6049 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6050 | } |
| 6051 | |
| 6052 | { |
| 6053 | LayerImplList render_surface_layer_list; |
| 6054 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6055 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6056 | inputs.can_render_to_separate_surface = false; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6057 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6058 | |
| 6059 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6060 | |
| 6061 | int count_represents_target_render_surface = 0; |
| 6062 | int count_represents_contributing_render_surface = 0; |
| 6063 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6064 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6065 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6066 | it != end; ++it) { |
| 6067 | if (it.represents_target_render_surface()) |
| 6068 | count_represents_target_render_surface++; |
| 6069 | if (it.represents_contributing_render_surface()) |
| 6070 | count_represents_contributing_render_surface++; |
| 6071 | if (it.represents_itself()) |
| 6072 | count_represents_itself++; |
| 6073 | } |
| 6074 | |
| 6075 | // Only root layer has a render surface. |
| 6076 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 6077 | // No layer contributes a render surface to root render surface. |
| 6078 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 6079 | // All 4 layers represent itself. |
| 6080 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6081 | } |
| 6082 | } |
| 6083 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6084 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6085 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6086 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6087 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6088 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6089 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 6090 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6091 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6092 | child1->SetDrawsContent(true); |
| 6093 | child2->SetDrawsContent(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6094 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6095 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6096 | root->Set3dSortingContextId(1); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6097 | root->test_properties()->should_flatten_transform = false; |
| 6098 | back_facing->SetBounds(gfx::Size(50, 50)); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6099 | back_facing->Set3dSortingContextId(1); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6100 | back_facing->test_properties()->should_flatten_transform = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6101 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 6102 | render_surface1->Set3dSortingContextId(1); |
| 6103 | render_surface1->test_properties()->should_flatten_transform = false; |
| 6104 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6105 | render_surface1->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6106 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 6107 | // Different context from the rest. |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6108 | render_surface2->Set3dSortingContextId(2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6109 | render_surface2->test_properties()->should_flatten_transform = false; |
| 6110 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6111 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6112 | child1->SetBounds(gfx::Size(20, 20)); |
| 6113 | child2->SetBounds(gfx::Size(20, 20)); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6114 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6115 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6116 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6117 | EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id()); |
| 6118 | EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id()); |
| 6119 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6120 | EXPECT_EQ(2u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6121 | ->at(0) |
| 6122 | ->render_surface() |
| 6123 | ->layer_list() |
| 6124 | .size()); |
| 6125 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
| 6126 | ->at(1) |
| 6127 | ->render_surface() |
| 6128 | ->layer_list() |
| 6129 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6130 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6131 | gfx::Transform rotation_transform; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6132 | rotation_transform.RotateAboutXAxis(180.0); |
| 6133 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6134 | back_facing->SetTransform(rotation_transform); |
jaydasika | 5aa88b8 | 2015-11-10 01:48:03 | [diff] [blame] | 6135 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6136 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6137 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6138 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6139 | // render_surface1 is in the same 3d rendering context as back_facing and is |
| 6140 | // not double sided, so it should not be in RSLL. render_surface2 is also not |
| 6141 | // double-sided, but will still be in RSLL as it's in a different 3d rendering |
| 6142 | // context. |
| 6143 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
| 6144 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6145 | ->at(0) |
| 6146 | ->render_surface() |
| 6147 | ->layer_list() |
| 6148 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6149 | } |
| 6150 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6151 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6152 | LayerImpl* root = root_layer_for_testing(); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6153 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 6154 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6155 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6156 | root->SetBounds(gfx::Size(50, 50)); |
| 6157 | root->test_properties()->should_flatten_transform = false; |
| 6158 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6159 | child->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6160 | child->test_properties()->should_flatten_transform = false; |
| 6161 | grand_child->SetBounds(gfx::Size(20, 20)); |
| 6162 | grand_child->SetDrawsContent(true); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6163 | grand_child->SetUseParentBackfaceVisibility(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6164 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6165 | ExecuteCalculateDrawProperties(root); |
| 6166 | |
| 6167 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6168 | EXPECT_EQ(grand_child, render_surface_layer_list_impl() |
| 6169 | ->at(0) |
| 6170 | ->render_surface() |
| 6171 | ->layer_list()[0]); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6172 | |
| 6173 | // As all layers have identity transform, we shouldn't check for backface |
| 6174 | // visibility. |
| 6175 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6176 | EXPECT_FALSE(child->should_check_backface_visibility()); |
| 6177 | EXPECT_FALSE(grand_child->should_check_backface_visibility()); |
| 6178 | // As there are no 3d rendering contexts, all layers should use their local |
| 6179 | // transform for backface visibility. |
| 6180 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6181 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6182 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6183 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6184 | gfx::Transform rotation_transform; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6185 | rotation_transform.RotateAboutXAxis(180.0); |
| 6186 | |
| 6187 | child->SetTransform(rotation_transform); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6188 | child->Set3dSortingContextId(1); |
| 6189 | grand_child->Set3dSortingContextId(1); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6190 | child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6191 | |
| 6192 | ExecuteCalculateDrawProperties(root); |
| 6193 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6194 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6195 | ->at(0) |
| 6196 | ->render_surface() |
| 6197 | ->layer_list() |
| 6198 | .size()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6199 | |
| 6200 | // We should check for backface visibilty of child as it has a rotation |
| 6201 | // transform. We should also check for grand_child as it uses the backface |
| 6202 | // visibility of its parent. |
| 6203 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6204 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6205 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6206 | // child uses its local transform for backface visibility as it is the root of |
| 6207 | // a 3d rendering context. grand_child is in a 3d rendering context and is not |
| 6208 | // the root, but it derives its backface visibility from its parent which uses |
| 6209 | // its local transform. |
| 6210 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6211 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6212 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6213 | |
| 6214 | grand_child->SetUseParentBackfaceVisibility(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6215 | grand_child->test_properties()->double_sided = false; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6216 | grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6217 | |
| 6218 | ExecuteCalculateDrawProperties(root); |
| 6219 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6220 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6221 | ->at(0) |
| 6222 | ->render_surface() |
| 6223 | ->layer_list() |
| 6224 | .size()); |
| 6225 | |
| 6226 | // We should check the backface visibility of child as it has a rotation |
| 6227 | // transform and for grand_child as it is in a 3d rendering context and not |
| 6228 | // the root of it. |
| 6229 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6230 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6231 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6232 | // grand_child is in an existing 3d rendering context, so it should not use |
| 6233 | // local transform for backface visibility. |
| 6234 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6235 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6236 | EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility()); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6237 | } |
| 6238 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6239 | TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6240 | LayerImpl* root = root_layer_for_testing(); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6241 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6242 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6243 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6244 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6245 | gfx::Transform rotate_about_y; |
| 6246 | rotate_about_y.RotateAboutYAxis(180.0); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6247 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6248 | root->SetBounds(gfx::Size(50, 50)); |
| 6249 | root->Set3dSortingContextId(1); |
| 6250 | root->test_properties()->should_flatten_transform = false; |
| 6251 | back_facing->SetTransform(rotate_about_y); |
| 6252 | back_facing->SetBounds(gfx::Size(50, 50)); |
| 6253 | back_facing->Set3dSortingContextId(1); |
| 6254 | back_facing->test_properties()->should_flatten_transform = false; |
| 6255 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 6256 | render_surface1->Set3dSortingContextId(1); |
| 6257 | render_surface1->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6258 | render_surface1->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6259 | render_surface1->test_properties()->force_render_surface = true; |
| 6260 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 6261 | render_surface2->Set3dSortingContextId(1); |
| 6262 | render_surface2->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6263 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6264 | render_surface2->test_properties()->force_render_surface = true; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6265 | ExecuteCalculateDrawProperties(root); |
| 6266 | |
| 6267 | const EffectTree& tree = |
| 6268 | root->layer_tree_impl()->property_trees()->effect_tree; |
| 6269 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6270 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6271 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6272 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6273 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6274 | back_facing->OnTransformAnimated(gfx::Transform()); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6275 | render_surface2->OnTransformAnimated(rotate_about_y); |
| 6276 | ExecuteCalculateDrawProperties(root); |
| 6277 | EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6278 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6279 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6280 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6281 | |
| 6282 | render_surface1->OnTransformAnimated(rotate_about_y); |
| 6283 | ExecuteCalculateDrawProperties(root); |
| 6284 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6285 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6286 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6287 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6288 | } |
| 6289 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6290 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 6291 | // Checks that the simple case (being clipped by a scroll parent that would |
| 6292 | // have been processed before you anyhow) results in the right clips. |
| 6293 | // |
| 6294 | // + root |
| 6295 | // + scroll_parent_border |
| 6296 | // | + scroll_parent_clip |
| 6297 | // | + scroll_parent |
| 6298 | // + scroll_child |
| 6299 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6300 | LayerImpl* root = root_layer_for_testing(); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6301 | LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>(); |
| 6302 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6303 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6304 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6305 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6306 | scroll_parent->SetDrawsContent(true); |
| 6307 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6308 | scroll_parent_clip->SetMasksToBounds(true); |
| 6309 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6310 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6311 | scroll_parent->test_properties()->scroll_children = |
| 6312 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6313 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6314 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6315 | root->SetBounds(gfx::Size(50, 50)); |
| 6316 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6317 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6318 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6319 | scroll_child->SetBounds(gfx::Size(50, 50)); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6320 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6321 | |
| 6322 | EXPECT_TRUE(root->render_surface()); |
| 6323 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6324 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6325 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6326 | } |
| 6327 | |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6328 | TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) { |
| 6329 | // Tests the computation of draw transform for the scroll child when its |
| 6330 | // target is different from its scroll parent's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6331 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6332 | LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); |
| 6333 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); |
| 6334 | LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target); |
| 6335 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); |
| 6336 | |
| 6337 | scroll_parent->SetDrawsContent(true); |
| 6338 | scroll_child->SetDrawsContent(true); |
| 6339 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6340 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6341 | scroll_parent->test_properties()->scroll_children = |
| 6342 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6343 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6344 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6345 | root->SetBounds(gfx::Size(50, 50)); |
| 6346 | scroll_child_target->SetBounds(gfx::Size(50, 50)); |
| 6347 | scroll_child_target->test_properties()->force_render_surface = true; |
| 6348 | scroll_child->SetBounds(gfx::Size(50, 50)); |
| 6349 | scroll_parent_target->SetPosition(gfx::PointF(10, 10)); |
| 6350 | scroll_parent_target->SetBounds(gfx::Size(50, 50)); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6351 | scroll_parent_target->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6352 | scroll_parent_target->test_properties()->force_render_surface = true; |
| 6353 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6354 | |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6355 | float device_scale_factor = 1.5f; |
| 6356 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6357 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6358 | root, root->bounds(), gfx::Transform(), &render_surface_layer_list_impl); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6359 | inputs.device_scale_factor = device_scale_factor; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6360 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6361 | |
weiliangc | 1da3fb89 | 2016-03-14 20:23:52 | [diff] [blame] | 6362 | EXPECT_EQ(scroll_child->effect_tree_index(), |
| 6363 | scroll_child_target->effect_tree_index()); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6364 | EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); |
| 6365 | EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); |
| 6366 | gfx::Transform scale; |
| 6367 | scale.Scale(1.5f, 1.5f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6368 | EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6369 | } |
| 6370 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6371 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6372 | LayerImpl* root = root_layer_for_testing(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6373 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6374 | LayerImpl* child = AddChild<LayerImpl>(parent); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6375 | |
| 6376 | root->SetBounds(gfx::Size(50, 50)); |
| 6377 | root->SetDrawsContent(true); |
| 6378 | root->Set3dSortingContextId(1); |
| 6379 | parent->SetBounds(gfx::Size(30, 30)); |
| 6380 | parent->SetDrawsContent(true); |
| 6381 | parent->Set3dSortingContextId(1); |
| 6382 | parent->test_properties()->force_render_surface = true; |
| 6383 | child->SetBounds(gfx::Size(20, 20)); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6384 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6385 | child->Set3dSortingContextId(1); |
| 6386 | child->test_properties()->force_render_surface = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6387 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6388 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6389 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6390 | |
| 6391 | gfx::Transform singular_transform; |
| 6392 | singular_transform.Scale3d( |
| 6393 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 6394 | |
| 6395 | child->SetTransform(singular_transform); |
| 6396 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6397 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6398 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6399 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6400 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6401 | |
| 6402 | // Ensure that the entire subtree under a layer with singular transform does |
| 6403 | // not get rendered. |
| 6404 | parent->SetTransform(singular_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6405 | child->SetTransform(gfx::Transform()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6406 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6407 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6408 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6409 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6410 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6411 | } |
| 6412 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6413 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 6414 | // Checks that clipping by a scroll parent that follows you in paint order |
| 6415 | // still results in correct clipping. |
| 6416 | // |
| 6417 | // + root |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6418 | // + scroll_parent_border |
| 6419 | // + scroll_parent_clip |
| 6420 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6421 | // + scroll_child |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6422 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6423 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6424 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6425 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6426 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6427 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6428 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6429 | scroll_parent->SetDrawsContent(true); |
| 6430 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6431 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6432 | root->SetBounds(gfx::Size(50, 50)); |
| 6433 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6434 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6435 | scroll_parent_clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6436 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6437 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6438 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6439 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6440 | scroll_parent->test_properties()->scroll_children = |
| 6441 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6442 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6443 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6444 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6445 | |
| 6446 | EXPECT_TRUE(root->render_surface()); |
| 6447 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6448 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6449 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6450 | } |
| 6451 | |
| 6452 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 6453 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 6454 | // you in paint order still results in correct clipping. |
| 6455 | // |
| 6456 | // + root |
| 6457 | // + scroll_child |
| 6458 | // + scroll_parent_border |
| 6459 | // | + scroll_parent_clip |
| 6460 | // | + scroll_parent |
| 6461 | // + scroll_grandparent_border |
| 6462 | // + scroll_grandparent_clip |
| 6463 | // + scroll_grandparent |
| 6464 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6465 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6466 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6467 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6468 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6469 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6470 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6471 | LayerImpl* scroll_grandparent_clip = |
| 6472 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6473 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6474 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6475 | scroll_parent->SetDrawsContent(true); |
| 6476 | scroll_grandparent->SetDrawsContent(true); |
| 6477 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6478 | |
| 6479 | scroll_parent_clip->SetMasksToBounds(true); |
| 6480 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6481 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6482 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6483 | scroll_parent->test_properties()->scroll_children = |
| 6484 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6485 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6486 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6487 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6488 | scroll_grandparent->test_properties()->scroll_children = |
| 6489 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6490 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 6491 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6492 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6493 | root->SetBounds(gfx::Size(50, 50)); |
| 6494 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 6495 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 6496 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 6497 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6498 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6499 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6500 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6501 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6502 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6503 | |
| 6504 | EXPECT_TRUE(root->render_surface()); |
| 6505 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6506 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6507 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6508 | |
| 6509 | // Despite the fact that we visited the above layers out of order to get the |
| 6510 | // correct clip, the layer lists should be unaffected. |
| 6511 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6512 | EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0)); |
| 6513 | EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1)); |
| 6514 | EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6515 | } |
| 6516 | |
| 6517 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 6518 | // 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] | 6519 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6520 | // + root |
| 6521 | // + scroll_child |
| 6522 | // + scroll_parent_border |
| 6523 | // + scroll_parent_clip |
| 6524 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6525 | // + render_surface2 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6526 | // + scroll_grandparent_border |
| 6527 | // + scroll_grandparent_clip |
| 6528 | // + scroll_grandparent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6529 | // + render_surface1 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6530 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6531 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6532 | root->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6533 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6534 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6535 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6536 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6537 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6538 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6539 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6540 | LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent); |
| 6541 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6542 | LayerImpl* scroll_grandparent_clip = |
| 6543 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6544 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
| 6545 | LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6546 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6547 | scroll_parent->SetDrawsContent(true); |
| 6548 | render_surface1->SetDrawsContent(true); |
| 6549 | scroll_grandparent->SetDrawsContent(true); |
| 6550 | render_surface2->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6551 | |
| 6552 | scroll_parent_clip->SetMasksToBounds(true); |
| 6553 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6554 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6555 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6556 | scroll_parent->test_properties()->scroll_children = |
| 6557 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6558 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6559 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6560 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6561 | scroll_grandparent->test_properties()->scroll_children = |
| 6562 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6563 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 6564 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6565 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6566 | root->SetBounds(gfx::Size(50, 50)); |
| 6567 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 6568 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 6569 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 6570 | render_surface1->SetBounds(gfx::Size(50, 50)); |
| 6571 | render_surface1->test_properties()->force_render_surface = true; |
| 6572 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6573 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6574 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6575 | render_surface2->SetBounds(gfx::Size(50, 50)); |
| 6576 | render_surface2->test_properties()->force_render_surface = true; |
| 6577 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6578 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6579 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6580 | |
| 6581 | EXPECT_TRUE(root->render_surface()); |
| 6582 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6583 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6584 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6585 | |
| 6586 | // Despite the fact that we had to process the layers out of order to get the |
| 6587 | // right clip, our render_surface_layer_list's order should be unaffected. |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6588 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6589 | EXPECT_EQ(root, render_surface_layer_list_impl()->at(0)); |
| 6590 | EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1)); |
| 6591 | EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2)); |
| 6592 | EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface()); |
| 6593 | EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface()); |
| 6594 | EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6595 | } |
| 6596 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6597 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 6598 | // Ensures that when we have a render surface between a fixed position layer |
| 6599 | // and its container, we compute the fixed position layer's draw transform |
| 6600 | // with respect to that intervening render surface, not with respect to its |
| 6601 | // container's render target. |
| 6602 | // |
| 6603 | // + root |
| 6604 | // + render_surface |
| 6605 | // + fixed |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6606 | // + child |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6607 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6608 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6609 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 6610 | LayerImpl* fixed = AddChild<LayerImpl>(render_surface); |
| 6611 | LayerImpl* child = AddChild<LayerImpl>(fixed); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6612 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6613 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6614 | root->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6615 | |
| 6616 | LayerPositionConstraint constraint; |
| 6617 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6618 | fixed->test_properties()->position_constraint = constraint; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6619 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6620 | root->SetBounds(gfx::Size(50, 50)); |
| 6621 | render_surface->SetPosition(gfx::PointF(7.f, 9.f)); |
| 6622 | render_surface->SetBounds(gfx::Size(50, 50)); |
| 6623 | render_surface->SetDrawsContent(true); |
| 6624 | fixed->SetPosition(gfx::PointF(10.f, 15.f)); |
| 6625 | fixed->SetBounds(gfx::Size(50, 50)); |
| 6626 | fixed->SetDrawsContent(true); |
| 6627 | child->SetPosition(gfx::PointF(1.f, 2.f)); |
| 6628 | child->SetBounds(gfx::Size(50, 50)); |
| 6629 | child->SetDrawsContent(true); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6630 | ExecuteCalculateDrawProperties(root); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6631 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6632 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6633 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6634 | EffectTree& effect_tree = |
| 6635 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6636 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6637 | gfx::Transform expected_fixed_draw_transform; |
| 6638 | expected_fixed_draw_transform.Translate(10.f, 15.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6639 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6640 | expected_fixed_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6641 | draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6642 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6643 | gfx::Transform expected_fixed_screen_space_transform; |
| 6644 | expected_fixed_screen_space_transform.Translate(17.f, 24.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6645 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6646 | expected_fixed_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6647 | draw_property_utils::ScreenSpaceTransform(fixed, transform_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6648 | |
| 6649 | gfx::Transform expected_child_draw_transform; |
| 6650 | expected_child_draw_transform.Translate(11.f, 17.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6651 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6652 | expected_child_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6653 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6654 | |
| 6655 | gfx::Transform expected_child_screen_space_transform; |
| 6656 | expected_child_screen_space_transform.Translate(18.f, 26.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6657 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6658 | expected_child_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6659 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6660 | } |
| 6661 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6662 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 6663 | // This test verifies that a scrolling layer that gets snapped to |
| 6664 | // integer coordinates doesn't move a fixed position child. |
| 6665 | // |
| 6666 | // + root |
| 6667 | // + container |
| 6668 | // + scroller |
| 6669 | // + fixed |
| 6670 | // |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6671 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6672 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6673 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6674 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6675 | &task_graph_runner); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6676 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6677 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6678 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 6679 | LayerImpl* root = root_ptr.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6680 | std::unique_ptr<LayerImpl> container = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6681 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 6682 | LayerImpl* container_layer = container.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6683 | std::unique_ptr<LayerImpl> scroller = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6684 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 6685 | LayerImpl* scroll_layer = scroller.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6686 | std::unique_ptr<LayerImpl> fixed = |
| 6687 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6688 | LayerImpl* fixed_layer = fixed.get(); |
| 6689 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6690 | container->test_properties()->is_container_for_fixed_position_layers = true; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6691 | |
| 6692 | LayerPositionConstraint constraint; |
| 6693 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6694 | fixed->test_properties()->position_constraint = constraint; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6695 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6696 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6697 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6698 | gfx::Transform container_transform; |
| 6699 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 6700 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 6701 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6702 | root->SetBounds(gfx::Size(50, 50)); |
| 6703 | container->SetTransform(container_transform); |
| 6704 | container->SetBounds(gfx::Size(40, 40)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6705 | container->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6706 | scroller->SetBounds(gfx::Size(30, 30)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6707 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6708 | fixed->SetBounds(gfx::Size(50, 50)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6709 | fixed->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6710 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6711 | scroller->test_properties()->AddChild(std::move(fixed)); |
| 6712 | container->test_properties()->AddChild(std::move(scroller)); |
| 6713 | root->test_properties()->AddChild(std::move(container)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6714 | root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr)); |
| 6715 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6716 | |
| 6717 | // Rounded to integers already. |
| 6718 | { |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6719 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6720 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6721 | |
| 6722 | LayerImplList render_surface_layer_list; |
| 6723 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6724 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6725 | root->layer_tree_impl() |
| 6726 | ->property_trees() |
| 6727 | ->transform_tree.set_source_to_parent_updates_allowed(false); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6728 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6729 | |
| 6730 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6731 | container_layer->draw_properties().screen_space_transform, |
| 6732 | fixed_layer->draw_properties().screen_space_transform); |
| 6733 | EXPECT_VECTOR_EQ( |
| 6734 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6735 | container_offset); |
| 6736 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6737 | .screen_space_transform.To2dTranslation(), |
| 6738 | container_offset - scroll_delta); |
| 6739 | } |
| 6740 | |
| 6741 | // Scroll delta requiring rounding. |
| 6742 | { |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6743 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6744 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6745 | |
| 6746 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 6747 | |
| 6748 | LayerImplList render_surface_layer_list; |
| 6749 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6750 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6751 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6752 | |
| 6753 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6754 | container_layer->draw_properties().screen_space_transform, |
| 6755 | fixed_layer->draw_properties().screen_space_transform); |
| 6756 | EXPECT_VECTOR_EQ( |
| 6757 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6758 | container_offset); |
| 6759 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6760 | .screen_space_transform.To2dTranslation(), |
| 6761 | container_offset - rounded_scroll_delta); |
| 6762 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6763 | |
| 6764 | // Scale is applied earlier in the tree. |
| 6765 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6766 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6767 | gfx::Transform scaled_container_transform = container_transform; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6768 | scaled_container_transform.Scale3d(2.0, 2.0, 1.0); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6769 | container_layer->SetTransform(scaled_container_transform); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6770 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6771 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6772 | |
| 6773 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6774 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6775 | |
| 6776 | LayerImplList render_surface_layer_list; |
| 6777 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6778 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6779 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6780 | |
| 6781 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6782 | container_layer->draw_properties().screen_space_transform, |
| 6783 | fixed_layer->draw_properties().screen_space_transform); |
| 6784 | EXPECT_VECTOR_EQ( |
| 6785 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6786 | container_offset); |
| 6787 | |
| 6788 | container_layer->SetTransform(container_transform); |
| 6789 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6790 | } |
| 6791 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 6792 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6793 | ScrollSnappingWithAnimatedScreenSpaceTransform) { |
| 6794 | // This test verifies that a scrolling layer whose screen space transform is |
| 6795 | // animating doesn't get snapped to integer coordinates. |
| 6796 | // |
| 6797 | // + root |
| 6798 | // + animated layer |
| 6799 | // + surface |
| 6800 | // + container |
| 6801 | // + scroller |
| 6802 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6803 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6804 | LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>(); |
| 6805 | LayerImpl* surface = AddChild<LayerImpl>(animated_layer); |
| 6806 | LayerImpl* container = AddChild<LayerImpl>(surface); |
| 6807 | LayerImpl* scroller = AddChild<LayerImpl>(container); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6808 | |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6809 | gfx::Transform start_scale; |
| 6810 | start_scale.Scale(1.5f, 1.5f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6811 | |
| 6812 | root->SetBounds(gfx::Size(50, 50)); |
| 6813 | animated_layer->SetTransform(start_scale); |
| 6814 | animated_layer->SetBounds(gfx::Size(50, 50)); |
| 6815 | surface->SetBounds(gfx::Size(50, 50)); |
| 6816 | surface->test_properties()->force_render_surface = true; |
| 6817 | container->SetBounds(gfx::Size(50, 50)); |
| 6818 | scroller->SetBounds(gfx::Size(100, 100)); |
| 6819 | scroller->SetScrollClipLayer(container->id()); |
| 6820 | scroller->SetDrawsContent(true); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6821 | |
| 6822 | gfx::Transform end_scale; |
| 6823 | end_scale.Scale(2.f, 2.f); |
| 6824 | TransformOperations start_operations; |
| 6825 | start_operations.AppendMatrix(start_scale); |
| 6826 | TransformOperations end_operations; |
| 6827 | end_operations.AppendMatrix(end_scale); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 6828 | SetElementIdsForTesting(); |
| 6829 | |
| 6830 | AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(), |
| 6831 | timeline_impl(), 1.0, |
| 6832 | start_operations, end_operations); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6833 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6834 | SetScrollOffsetDelta(scroller, scroll_delta); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6835 | |
| 6836 | ExecuteCalculateDrawProperties(root); |
| 6837 | |
| 6838 | gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); |
| 6839 | EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 6840 | scroller->DrawTransform().To2dTranslation()); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6841 | } |
| 6842 | |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 6843 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) { |
| 6844 | // This test verifies that a scrolling child of a scrolling layer doesn't get |
| 6845 | // snapped to integer coordinates. |
| 6846 | // |
| 6847 | // + root |
| 6848 | // + container |
| 6849 | // + scroller |
| 6850 | // + scroll_child |
| 6851 | // |
| 6852 | scoped_refptr<Layer> root = Layer::Create(); |
| 6853 | scoped_refptr<Layer> container = Layer::Create(); |
| 6854 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6855 | scoped_refptr<Layer> scroll_child = Layer::Create(); |
| 6856 | root->AddChild(container); |
| 6857 | root->AddChild(scroll_child); |
| 6858 | container->AddChild(scroller); |
| 6859 | host()->SetRootLayer(root); |
| 6860 | |
| 6861 | scroller->SetScrollClipLayerId(container->id()); |
| 6862 | scroll_child->SetScrollParent(scroller.get()); |
| 6863 | |
| 6864 | gfx::Transform rotate; |
| 6865 | rotate.RotateAboutYAxis(30); |
| 6866 | root->SetBounds(gfx::Size(50, 50)); |
| 6867 | container->SetBounds(gfx::Size(50, 50)); |
| 6868 | scroller->SetBounds(gfx::Size(100, 100)); |
| 6869 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 6870 | scroll_child->SetBounds(gfx::Size(10, 10)); |
| 6871 | scroll_child->SetTransform(rotate); |
| 6872 | |
| 6873 | ExecuteCalculateDrawProperties(root.get()); |
| 6874 | |
| 6875 | host()->host_impl()->CreatePendingTree(); |
| 6876 | host()->CommitAndCreatePendingTree(); |
| 6877 | host()->host_impl()->ActivateSyncTree(); |
| 6878 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6879 | |
| 6880 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6881 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6882 | LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id()); |
| 6883 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 6884 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 6885 | |
| 6886 | ExecuteCalculateDrawProperties(root_impl); |
| 6887 | |
| 6888 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 6889 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 6890 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6891 | |
| 6892 | gfx::Transform expected_scroll_child_screen_space_transform; |
| 6893 | expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); |
| 6894 | expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); |
| 6895 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, |
| 6896 | scroll_child_impl->ScreenSpaceTransform()); |
| 6897 | } |
| 6898 | |
| 6899 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) { |
| 6900 | // This test verifies that a fixed pos child of a scrolling layer doesn't get |
| 6901 | // snapped to integer coordinates. |
| 6902 | // |
| 6903 | // + root |
| 6904 | // + container |
| 6905 | // + scroller |
| 6906 | // + fixed_pos |
| 6907 | // |
| 6908 | scoped_refptr<Layer> root = Layer::Create(); |
| 6909 | scoped_refptr<Layer> container = Layer::Create(); |
| 6910 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6911 | scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 6912 | |
| 6913 | scroller->SetIsContainerForFixedPositionLayers(true); |
| 6914 | |
| 6915 | root->AddChild(container); |
| 6916 | container->AddChild(scroller); |
| 6917 | scroller->AddChild(fixed_pos); |
| 6918 | host()->SetRootLayer(root); |
| 6919 | |
| 6920 | LayerPositionConstraint fixed_position; |
| 6921 | fixed_position.set_is_fixed_position(true); |
| 6922 | scroller->SetScrollClipLayerId(container->id()); |
| 6923 | fixed_pos->SetPositionConstraint(fixed_position); |
| 6924 | |
| 6925 | root->SetBounds(gfx::Size(50, 50)); |
| 6926 | container->SetBounds(gfx::Size(50, 50)); |
| 6927 | scroller->SetBounds(gfx::Size(100, 100)); |
| 6928 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 6929 | fixed_pos->SetBounds(gfx::Size(10, 10)); |
| 6930 | |
| 6931 | ExecuteCalculateDrawProperties(root.get()); |
| 6932 | |
| 6933 | host()->host_impl()->CreatePendingTree(); |
| 6934 | host()->CommitAndCreatePendingTree(); |
| 6935 | host()->host_impl()->ActivateSyncTree(); |
| 6936 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6937 | |
| 6938 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6939 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6940 | LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id()); |
| 6941 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 6942 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 6943 | |
| 6944 | ExecuteCalculateDrawProperties(root_impl); |
| 6945 | |
| 6946 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 6947 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 6948 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6949 | |
| 6950 | gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f, |
| 6951 | 10.3f); |
| 6952 | EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation, |
| 6953 | fixed_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6954 | } |
| 6955 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6956 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 6957 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6958 | static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6959 | LayerTreeImpl* tree_impl, |
| 6960 | int id) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6961 | return base::WrapUnique( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6962 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 6963 | } |
| 6964 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 6965 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6966 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6967 | private: |
| 6968 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 6969 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 6970 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6971 | SetDrawsContent(true); |
| 6972 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6973 | }; |
| 6974 | |
| 6975 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6976 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6977 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6978 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 6979 | LayerTreeSettings settings = host()->settings(); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 6980 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6981 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 6982 | &shared_bitmap_manager, &task_graph_runner); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6983 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6984 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6985 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6986 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6987 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6988 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6989 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6990 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 6991 | |
| 6992 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 6993 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 6994 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 6995 | AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get(); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6996 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6997 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 6998 | parent->SetBounds(gfx::Size(1, 2)); |
| 6999 | child->SetBounds(gfx::Size(1, 2)); |
| 7000 | grand_child->SetBounds(gfx::Size(1, 2)); |
| 7001 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7002 | child->test_properties()->AddChild(std::move(grand_child)); |
| 7003 | parent->test_properties()->AddChild(std::move(child)); |
| 7004 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7005 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 7006 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7007 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7008 | |
| 7009 | // No layers have animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7010 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7011 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7012 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7013 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7014 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7015 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7016 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7017 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7018 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7019 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7020 | TransformOperations translation; |
| 7021 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7022 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7023 | scoped_refptr<AnimationTimeline> timeline; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7024 | timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7025 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7026 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7027 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 7028 | AddAnimatedTransformToElementWithPlayer(parent_raw->element_id(), timeline, |
| 7029 | 1.0, TransformOperations(), |
| 7030 | translation); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7031 | |
| 7032 | // No layers have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7033 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7034 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7035 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7036 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7037 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7038 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7039 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7040 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7041 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7042 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7043 | TransformOperations scale; |
| 7044 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7045 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7046 | AddAnimatedTransformToElementWithPlayer(child_raw->element_id(), timeline, |
| 7047 | 1.0, TransformOperations(), scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7048 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7049 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7050 | |
| 7051 | // Only |child| has a scale-affecting animation. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7052 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7053 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7054 | EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw)); |
| 7055 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7056 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7057 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7058 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7059 | EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw)); |
| 7060 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7061 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7062 | AddAnimatedTransformToElementWithPlayer(grand_parent_raw->element_id(), |
| 7063 | timeline, 1.0, TransformOperations(), |
| 7064 | scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7065 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7066 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7067 | |
| 7068 | // |grand_parent| and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7069 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7070 | EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7071 | // We don't support combining animated scales from two nodes; 0.f means |
| 7072 | // that the maximum scale could not be computed. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7073 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7074 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7075 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7076 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7077 | EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw)); |
| 7078 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7079 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7080 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7081 | AddAnimatedTransformToElementWithPlayer(parent_raw->element_id(), timeline, |
| 7082 | 1.0, TransformOperations(), scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7083 | parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7084 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7085 | |
| 7086 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7087 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7088 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7089 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7090 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7091 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7092 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7093 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7094 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7095 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7096 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7097 | AbortAnimationsOnElementWithPlayer(grand_parent_raw->element_id(), timeline, |
| 7098 | TargetProperty::TRANSFORM); |
| 7099 | AbortAnimationsOnElementWithPlayer(parent_raw->element_id(), timeline, |
| 7100 | TargetProperty::TRANSFORM); |
| 7101 | AbortAnimationsOnElementWithPlayer(child_raw->element_id(), timeline, |
| 7102 | TargetProperty::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7103 | |
| 7104 | TransformOperations perspective; |
| 7105 | perspective.AppendPerspective(10.f); |
| 7106 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7107 | AddAnimatedTransformToElementWithPlayer(child_raw->element_id(), timeline, |
| 7108 | 1.0, TransformOperations(), |
| 7109 | perspective); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7110 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7111 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7112 | |
| 7113 | // |child| has a scale-affecting animation but computing the maximum of this |
| 7114 | // animation is not supported. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7115 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7116 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7117 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7118 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7119 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7120 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7121 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7122 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7123 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7124 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7125 | AbortAnimationsOnElementWithPlayer(child_raw->element_id(), timeline, |
| 7126 | TargetProperty::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7127 | gfx::Transform scale_matrix; |
| 7128 | scale_matrix.Scale(1.f, 2.f); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7129 | grand_parent_raw->SetTransform(scale_matrix); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7130 | parent_raw->SetTransform(scale_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7131 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7132 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7133 | AddAnimatedTransformToElementWithPlayer(parent_raw->element_id(), timeline, |
| 7134 | 1.0, TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7135 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7136 | |
| 7137 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 7138 | // animation with maximum scale 5.f. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7139 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7140 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 7141 | EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw)); |
| 7142 | EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7143 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7144 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7145 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 7146 | EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw)); |
| 7147 | EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7148 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7149 | gfx::Transform perspective_matrix; |
| 7150 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 7151 | child_raw->SetTransform(perspective_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7152 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7153 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7154 | |
| 7155 | // |child| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7156 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7157 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 7158 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7159 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7160 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7161 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7162 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 7163 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7164 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7165 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7166 | parent_raw->SetTransform(perspective_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7167 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7168 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7169 | |
| 7170 | // |parent| and |child| have transforms that are neither translations nor |
| 7171 | // scales. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7172 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7173 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7174 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7175 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7176 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7177 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7178 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7179 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7180 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7181 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7182 | parent_raw->SetTransform(gfx::Transform()); |
| 7183 | child_raw->SetTransform(gfx::Transform()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7184 | grand_parent_raw->SetTransform(perspective_matrix); |
| 7185 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7186 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7187 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7188 | |
| 7189 | // |grand_parent| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7190 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7191 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7192 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7193 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7194 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7195 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7196 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7197 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7198 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7199 | } |
| 7200 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 7201 | static void GatherDrawnLayers(const LayerImplList* rsll, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7202 | std::set<LayerImpl*>* drawn_layers) { |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 7203 | for (LayerIterator it = LayerIterator::Begin(rsll), |
| 7204 | end = LayerIterator::End(rsll); |
| 7205 | it != end; ++it) { |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7206 | LayerImpl* layer = *it; |
| 7207 | if (it.represents_itself()) |
| 7208 | drawn_layers->insert(layer); |
| 7209 | |
| 7210 | if (!it.represents_contributing_render_surface()) |
| 7211 | continue; |
| 7212 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7213 | if (layer->render_surface()->MaskLayer()) |
| 7214 | drawn_layers->insert(layer->render_surface()->MaskLayer()); |
| 7215 | if (layer->render_surface()->ReplicaMaskLayer()) |
| 7216 | drawn_layers->insert(layer->render_surface()->ReplicaMaskLayer()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7217 | } |
| 7218 | } |
| 7219 | |
| 7220 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7221 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7222 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7223 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7224 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7225 | &task_graph_runner); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7226 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7227 | std::unique_ptr<LayerImpl> grand_parent = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7228 | LayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7229 | std::unique_ptr<LayerImpl> parent = |
| 7230 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7231 | std::unique_ptr<LayerImpl> child = |
| 7232 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7233 | std::unique_ptr<LayerImpl> grand_child1 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7234 | LayerImpl::Create(host_impl.active_tree(), 7); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7235 | std::unique_ptr<LayerImpl> grand_child2 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7236 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 7237 | |
| 7238 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 7239 | LayerImpl* parent_raw = parent.get(); |
| 7240 | LayerImpl* child_raw = child.get(); |
| 7241 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 7242 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 7243 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7244 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 7245 | parent->SetBounds(gfx::Size(1, 2)); |
| 7246 | child->SetBounds(gfx::Size(1, 2)); |
| 7247 | grand_child1->SetBounds(gfx::Size(1, 2)); |
| 7248 | grand_child2->SetBounds(gfx::Size(1, 2)); |
| 7249 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7250 | child->test_properties()->AddChild(std::move(grand_child1)); |
| 7251 | child->test_properties()->AddChild(std::move(grand_child2)); |
| 7252 | parent->test_properties()->AddChild(std::move(child)); |
| 7253 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7254 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7255 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7256 | // Start with nothing being drawn. |
| 7257 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7258 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7259 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7260 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7261 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7262 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7263 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7264 | |
| 7265 | std::set<LayerImpl*> expected; |
| 7266 | std::set<LayerImpl*> actual; |
| 7267 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7268 | EXPECT_EQ(expected, actual); |
| 7269 | |
| 7270 | // If we force render surface, but none of the layers are in the layer list, |
| 7271 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7272 | grand_child1_raw->SetHasRenderSurface(true); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7273 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7274 | |
| 7275 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7276 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7277 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7278 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7279 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7280 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7281 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7282 | |
| 7283 | expected.clear(); |
| 7284 | actual.clear(); |
| 7285 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7286 | EXPECT_EQ(expected, actual); |
| 7287 | |
| 7288 | // However, if we say that this layer also draws content, it will appear in |
| 7289 | // RSLL. |
| 7290 | grand_child1_raw->SetDrawsContent(true); |
| 7291 | |
| 7292 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7293 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7294 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7295 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7296 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7297 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7298 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7299 | |
| 7300 | expected.clear(); |
| 7301 | expected.insert(grand_child1_raw); |
| 7302 | |
| 7303 | actual.clear(); |
| 7304 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7305 | EXPECT_EQ(expected, actual); |
| 7306 | |
| 7307 | // Now child is forced to have a render surface, and one if its children draws |
| 7308 | // content. |
| 7309 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7310 | grand_child1_raw->SetHasRenderSurface(false); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7311 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7312 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7313 | grand_child2_raw->SetDrawsContent(true); |
| 7314 | |
| 7315 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7316 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7317 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7318 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7319 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7320 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7321 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7322 | |
| 7323 | expected.clear(); |
| 7324 | expected.insert(grand_child2_raw); |
| 7325 | |
| 7326 | actual.clear(); |
| 7327 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7328 | EXPECT_EQ(expected, actual); |
| 7329 | |
| 7330 | // Add a mask layer to child. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7331 | child_raw->test_properties()->SetMaskLayer( |
| 7332 | LayerImpl::Create(host_impl.active_tree(), 6)); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7333 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7334 | |
| 7335 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7336 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7337 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7338 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7339 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7340 | EXPECT_TRUE(child_raw->test_properties() |
| 7341 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7342 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7343 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7344 | |
| 7345 | expected.clear(); |
| 7346 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7347 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7348 | |
| 7349 | expected.clear(); |
| 7350 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7351 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7352 | |
| 7353 | actual.clear(); |
| 7354 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7355 | EXPECT_EQ(expected, actual); |
| 7356 | |
| 7357 | // Add replica mask layer. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7358 | std::unique_ptr<LayerImpl> replica_layer = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7359 | LayerImpl::Create(host_impl.active_tree(), 20); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7360 | replica_layer->test_properties()->SetMaskLayer( |
| 7361 | LayerImpl::Create(host_impl.active_tree(), 21)); |
| 7362 | child_raw->test_properties()->SetReplicaLayer(std::move(replica_layer)); |
jaydasika | 23fb382 | 2015-08-25 03:22:59 | [diff] [blame] | 7363 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7364 | |
| 7365 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7366 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7367 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7368 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7369 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7370 | EXPECT_TRUE(child_raw->test_properties() |
| 7371 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
| 7372 | EXPECT_TRUE(child_raw->test_properties() |
| 7373 | ->replica_layer->test_properties() |
| 7374 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7375 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7376 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7377 | |
| 7378 | expected.clear(); |
| 7379 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7380 | expected.insert(child_raw->test_properties()->mask_layer); |
| 7381 | expected.insert(child_raw->test_properties() |
| 7382 | ->replica_layer->test_properties() |
| 7383 | ->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7384 | |
| 7385 | actual.clear(); |
| 7386 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7387 | EXPECT_EQ(expected, actual); |
| 7388 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7389 | child_raw->test_properties()->SetReplicaLayer(nullptr); |
| 7390 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7391 | |
| 7392 | // With nothing drawing, we should have no layers. |
| 7393 | grand_child2_raw->SetDrawsContent(false); |
| 7394 | |
| 7395 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7396 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7397 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7398 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7399 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7400 | EXPECT_FALSE(child_raw->test_properties() |
| 7401 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7402 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7403 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7404 | |
| 7405 | expected.clear(); |
| 7406 | actual.clear(); |
| 7407 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7408 | EXPECT_EQ(expected, actual); |
| 7409 | |
| 7410 | // Child itself draws means that we should have the child and the mask in the |
| 7411 | // list. |
| 7412 | child_raw->SetDrawsContent(true); |
| 7413 | |
| 7414 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7415 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7416 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7417 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7418 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7419 | EXPECT_TRUE(child_raw->test_properties() |
| 7420 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7421 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7422 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7423 | |
| 7424 | expected.clear(); |
| 7425 | expected.insert(child_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7426 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7427 | actual.clear(); |
| 7428 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7429 | EXPECT_EQ(expected, actual); |
| 7430 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7431 | child_raw->test_properties()->SetMaskLayer(nullptr); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7432 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7433 | |
| 7434 | // Now everyone's a member! |
| 7435 | grand_parent_raw->SetDrawsContent(true); |
| 7436 | parent_raw->SetDrawsContent(true); |
| 7437 | child_raw->SetDrawsContent(true); |
| 7438 | grand_child1_raw->SetDrawsContent(true); |
| 7439 | grand_child2_raw->SetDrawsContent(true); |
| 7440 | |
| 7441 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7442 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7443 | EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7444 | EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7445 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7446 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7447 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7448 | |
| 7449 | expected.clear(); |
| 7450 | expected.insert(grand_parent_raw); |
| 7451 | expected.insert(parent_raw); |
| 7452 | expected.insert(child_raw); |
| 7453 | expected.insert(grand_child1_raw); |
| 7454 | expected.insert(grand_child2_raw); |
| 7455 | |
| 7456 | actual.clear(); |
| 7457 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7458 | EXPECT_EQ(expected, actual); |
| 7459 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7460 | |
| 7461 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7462 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7463 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7464 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7465 | LayerTreeSettings settings = host()->settings(); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7466 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7467 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7468 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7469 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7470 | std::unique_ptr<LayerImpl> root = |
| 7471 | LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7472 | LayerImpl* root_layer = root.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7473 | std::unique_ptr<LayerImpl> child1 = |
| 7474 | LayerImpl::Create(host_impl.active_tree(), 2); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7475 | LayerImpl* child1_layer = child1.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7476 | std::unique_ptr<LayerImpl> child2 = |
| 7477 | LayerImpl::Create(host_impl.active_tree(), 3); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7478 | LayerImpl* child2_layer = child2.get(); |
| 7479 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7480 | gfx::Transform scale_transform_child1, scale_transform_child2; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7481 | scale_transform_child1.Scale(2, 3); |
| 7482 | scale_transform_child2.Scale(4, 5); |
| 7483 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7484 | root->SetBounds(gfx::Size(1, 1)); |
| 7485 | root->SetDrawsContent(true); |
| 7486 | child1_layer->SetTransform(scale_transform_child1); |
| 7487 | child1_layer->SetBounds(gfx::Size(1, 1)); |
| 7488 | child1_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7489 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7490 | child1_layer->test_properties()->SetMaskLayer( |
| 7491 | LayerImpl::Create(host_impl.active_tree(), 4)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7492 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7493 | std::unique_ptr<LayerImpl> replica_layer = |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7494 | LayerImpl::Create(host_impl.active_tree(), 5); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7495 | replica_layer->test_properties()->SetMaskLayer( |
| 7496 | LayerImpl::Create(host_impl.active_tree(), 6)); |
| 7497 | child1_layer->test_properties()->SetReplicaLayer(std::move(replica_layer)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7498 | |
| 7499 | root->test_properties()->AddChild(std::move(child1)); |
| 7500 | root->test_properties()->AddChild(std::move(child2)); |
| 7501 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 7502 | host_impl.active_tree()->SetElementIdsForTesting(); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7503 | |
| 7504 | ExecuteCalculateDrawProperties(root_layer); |
| 7505 | |
| 7506 | TransformOperations scale; |
| 7507 | scale.AppendScale(5.f, 8.f, 3.f); |
| 7508 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7509 | scoped_refptr<AnimationTimeline> timeline = |
| 7510 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7511 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7512 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7513 | child2_layer->SetTransform(scale_transform_child2); |
| 7514 | child2_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7515 | child2_layer->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7516 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 7517 | 1.0, TransformOperations(), scale); |
| 7518 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7519 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7520 | ExecuteCalculateDrawProperties(root_layer); |
| 7521 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7522 | EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale()); |
| 7523 | EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7524 | EXPECT_FLOAT_EQ( |
| 7525 | 3.f, |
| 7526 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7527 | EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7528 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7529 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 7530 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 7531 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7532 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7533 | // Changing page-scale would affect ideal_contents_scale and |
| 7534 | // maximum_animation_contents_scale. |
| 7535 | |
| 7536 | float page_scale_factor = 3.f; |
| 7537 | float device_scale_factor = 1.0f; |
| 7538 | std::vector<LayerImpl*> render_surface_layer_list; |
| 7539 | gfx::Size device_viewport_size = |
| 7540 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 7541 | root_layer->bounds().height() * device_scale_factor); |
| 7542 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7543 | root_layer, device_viewport_size, &render_surface_layer_list); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7544 | |
| 7545 | inputs.page_scale_factor = page_scale_factor; |
| 7546 | inputs.can_adjust_raster_scales = true; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 7547 | inputs.page_scale_layer = root_layer; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7548 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7549 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7550 | EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale()); |
| 7551 | EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7552 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7553 | 9.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7554 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
| 7555 | EXPECT_FLOAT_EQ(9.f, child1_layer->test_properties() |
| 7556 | ->replica_layer->test_properties() |
| 7557 | ->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7558 | EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7559 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7560 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 7561 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 7562 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7563 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7564 | // Changing device-scale would affect ideal_contents_scale and |
| 7565 | // maximum_animation_contents_scale. |
| 7566 | |
| 7567 | device_scale_factor = 4.0f; |
| 7568 | inputs.device_scale_factor = device_scale_factor; |
| 7569 | inputs.can_adjust_raster_scales = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7570 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7571 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7572 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7573 | EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale()); |
| 7574 | EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7575 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7576 | 36.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7577 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
| 7578 | EXPECT_FLOAT_EQ(36.f, child1_layer->test_properties() |
| 7579 | ->replica_layer->test_properties() |
| 7580 | ->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7581 | EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7582 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7583 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 7584 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 7585 | EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer)); |
| 7586 | } |
| 7587 | |
| 7588 | TEST_F(LayerTreeHostCommonTest, AnimationScales) { |
| 7589 | FakeImplTaskRunnerProvider task_runner_provider; |
| 7590 | TestSharedBitmapManager shared_bitmap_manager; |
| 7591 | TestTaskGraphRunner task_graph_runner; |
| 7592 | LayerTreeSettings settings = host()->settings(); |
| 7593 | settings.layer_transforms_should_scale_layer_contents = true; |
| 7594 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7595 | &shared_bitmap_manager, &task_graph_runner); |
| 7596 | |
| 7597 | std::unique_ptr<LayerImpl> root = |
| 7598 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 7599 | LayerImpl* root_layer = root.get(); |
| 7600 | std::unique_ptr<LayerImpl> child1 = |
| 7601 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7602 | LayerImpl* child1_layer = child1.get(); |
| 7603 | std::unique_ptr<LayerImpl> child2 = |
| 7604 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7605 | LayerImpl* child2_layer = child2.get(); |
| 7606 | |
| 7607 | root->test_properties()->AddChild(std::move(child1)); |
| 7608 | child1_layer->test_properties()->AddChild(std::move(child2)); |
| 7609 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 7610 | |
| 7611 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 7612 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7613 | gfx::Transform scale_transform_child1, scale_transform_child2; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7614 | scale_transform_child1.Scale(2, 3); |
| 7615 | scale_transform_child2.Scale(4, 5); |
| 7616 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7617 | root_layer->SetBounds(gfx::Size(1, 1)); |
| 7618 | child1_layer->SetTransform(scale_transform_child1); |
| 7619 | child1_layer->SetBounds(gfx::Size(1, 1)); |
| 7620 | child2_layer->SetTransform(scale_transform_child2); |
| 7621 | child2_layer->SetBounds(gfx::Size(1, 1)); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7622 | |
| 7623 | TransformOperations scale; |
| 7624 | scale.AppendScale(5.f, 8.f, 3.f); |
| 7625 | |
| 7626 | scoped_refptr<AnimationTimeline> timeline = |
| 7627 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7628 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 7629 | |
| 7630 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 7631 | 1.0, TransformOperations(), scale); |
| 7632 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7633 | // Correctly computes animation scale when rebuilding property trees. |
| 7634 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7635 | ExecuteCalculateDrawProperties(root_layer); |
| 7636 | |
| 7637 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 7638 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 7639 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
| 7640 | |
| 7641 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 7642 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer)); |
| 7643 | EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer)); |
| 7644 | |
| 7645 | // Correctly updates animation scale when layer property changes. |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7646 | child1_layer->SetTransform(gfx::Transform()); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7647 | child1_layer->UpdatePropertyTreeTransform(); |
| 7648 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false; |
| 7649 | ExecuteCalculateDrawProperties(root_layer); |
| 7650 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
| 7651 | EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer)); |
| 7652 | |
| 7653 | // Do not update animation scale if already updated. |
| 7654 | host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting( |
| 7655 | child2_layer->transform_tree_index(), 100.f, 100.f); |
| 7656 | EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer)); |
| 7657 | EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer)); |
| 7658 | } |
| 7659 | |
| 7660 | TEST_F(LayerTreeHostCommonTest, |
| 7661 | AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) { |
| 7662 | // Returns empty scale if layer_transforms_should_scale_layer_contents is |
| 7663 | // false. |
| 7664 | FakeImplTaskRunnerProvider task_runner_provider; |
| 7665 | TestSharedBitmapManager shared_bitmap_manager; |
| 7666 | TestTaskGraphRunner task_graph_runner; |
| 7667 | LayerTreeSettings settings = host()->settings(); |
| 7668 | settings.layer_transforms_should_scale_layer_contents = false; |
| 7669 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7670 | &shared_bitmap_manager, &task_graph_runner); |
| 7671 | |
| 7672 | std::unique_ptr<LayerImpl> root = |
| 7673 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 7674 | LayerImpl* root_layer = root.get(); |
| 7675 | std::unique_ptr<LayerImpl> child = |
| 7676 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7677 | LayerImpl* child_layer = child.get(); |
| 7678 | |
| 7679 | root->test_properties()->AddChild(std::move(child)); |
| 7680 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 7681 | |
| 7682 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 7683 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7684 | gfx::Transform scale_transform_child; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7685 | scale_transform_child.Scale(4, 5); |
| 7686 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7687 | root_layer->SetBounds(gfx::Size(1, 1)); |
| 7688 | child_layer->SetTransform(scale_transform_child); |
| 7689 | child_layer->SetBounds(gfx::Size(1, 1)); |
| 7690 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7691 | TransformOperations scale; |
| 7692 | scale.AppendScale(5.f, 8.f, 3.f); |
| 7693 | |
| 7694 | scoped_refptr<AnimationTimeline> timeline = |
| 7695 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7696 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 7697 | |
| 7698 | AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline, |
| 7699 | 1.0, TransformOperations(), scale); |
| 7700 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7701 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7702 | ExecuteCalculateDrawProperties(root_layer); |
| 7703 | |
| 7704 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 7705 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer)); |
| 7706 | |
| 7707 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 7708 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7709 | } |
| 7710 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7711 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7712 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7713 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 7714 | LayerImpl* content = AddChild<LayerImpl>(clip); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7715 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7716 | root->SetBounds(gfx::Size(768 / 2, 3000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7717 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7718 | clip->SetBounds(gfx::Size(768 / 2, 10000)); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7719 | clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7720 | content->SetBounds(gfx::Size(768 / 2, 10000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7721 | content->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7722 | content->test_properties()->force_render_surface = true; |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7723 | |
| 7724 | gfx::Size device_viewport_size(768, 582); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7725 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7726 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7727 | root, device_viewport_size, gfx::Transform(), |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7728 | &render_surface_layer_list_impl); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7729 | inputs.device_scale_factor = 2.f; |
| 7730 | inputs.page_scale_factor = 1.f; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 7731 | inputs.page_scale_layer = nullptr; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7732 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7733 | |
| 7734 | // Layers in the root render surface have their visible content rect clipped |
| 7735 | // by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7736 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7737 | |
| 7738 | // Layers drawing to a child render surface should still have their visible |
| 7739 | // content rect clipped by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7740 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7741 | } |
| 7742 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7743 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7744 | FakeImplTaskRunnerProvider task_runner_provider; |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7745 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7746 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7747 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7748 | &task_graph_runner); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7749 | |
| 7750 | // Set two layers: the root layer clips it's child, |
| 7751 | // the child draws its content. |
| 7752 | |
| 7753 | gfx::Size root_size = gfx::Size(300, 500); |
| 7754 | |
| 7755 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 7756 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 7757 | |
| 7758 | // Device viewport accomidated the root and the top controls. |
| 7759 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7760 | |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 7761 | host_impl.SetViewportSize(device_viewport_size); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7762 | host_impl.active_tree()->SetRootLayerForTesting( |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7763 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 7764 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7765 | LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7766 | root->SetBounds(root_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7767 | root->SetMasksToBounds(true); |
| 7768 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7769 | root->test_properties()->AddChild( |
| 7770 | LayerImpl::Create(host_impl.active_tree(), 2)); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7771 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 7772 | LayerImpl* sublayer = root->test_properties()->children[0]; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7773 | sublayer->SetBounds(sublayer_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7774 | sublayer->SetDrawsContent(true); |
| 7775 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7776 | host_impl.active_tree()->BuildPropertyTreesForTesting(); |
| 7777 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7778 | LayerImplList layer_impl_list; |
| 7779 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7780 | root, device_viewport_size, &layer_impl_list); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7781 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7782 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7783 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7784 | |
| 7785 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7786 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7787 | |
| 7788 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 7789 | root_size.height() + 50); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7790 | EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7791 | } |
| 7792 | |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 7793 | TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 7794 | scoped_refptr<Layer> root = Layer::Create(); |
| 7795 | scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create(); |
| 7796 | scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); |
| 7797 | scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create(); |
| 7798 | scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 7799 | |
| 7800 | root->AddChild(inner_viewport_container_layer); |
| 7801 | inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer); |
| 7802 | inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); |
| 7803 | outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); |
| 7804 | |
| 7805 | inner_viewport_scroll_layer->SetScrollClipLayerId( |
| 7806 | inner_viewport_container_layer->id()); |
| 7807 | outer_viewport_scroll_layer->SetScrollClipLayerId( |
| 7808 | outer_viewport_container_layer->id()); |
| 7809 | |
| 7810 | inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 7811 | outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 7812 | |
| 7813 | host()->SetRootLayer(root); |
| 7814 | host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer, |
| 7815 | outer_viewport_scroll_layer); |
| 7816 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 7817 | scoped_refptr<Layer> fixed_to_inner = Layer::Create(); |
| 7818 | scoped_refptr<Layer> fixed_to_outer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 7819 | |
| 7820 | inner_viewport_scroll_layer->AddChild(fixed_to_inner); |
| 7821 | outer_viewport_scroll_layer->AddChild(fixed_to_outer); |
| 7822 | |
| 7823 | LayerPositionConstraint fixed_to_right; |
| 7824 | fixed_to_right.set_is_fixed_position(true); |
| 7825 | fixed_to_right.set_is_fixed_to_right_edge(true); |
| 7826 | |
| 7827 | fixed_to_inner->SetPositionConstraint(fixed_to_right); |
| 7828 | fixed_to_outer->SetPositionConstraint(fixed_to_right); |
| 7829 | |
| 7830 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 7831 | |
| 7832 | TransformTree& transform_tree = host()->property_trees()->transform_tree; |
| 7833 | EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 7834 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 7835 | |
| 7836 | LayerPositionConstraint fixed_to_left; |
| 7837 | fixed_to_left.set_is_fixed_position(true); |
| 7838 | fixed_to_inner->SetPositionConstraint(fixed_to_left); |
| 7839 | |
| 7840 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 7841 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 7842 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 7843 | |
| 7844 | fixed_to_outer->SetPositionConstraint(fixed_to_left); |
| 7845 | |
| 7846 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 7847 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 7848 | EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 7849 | } |
| 7850 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 7851 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 7852 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 7853 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 7854 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 7855 | |
| 7856 | root->AddChild(animated); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 7857 | host()->SetRootLayer(root); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7858 | host()->SetElementIdsForTesting(); |
| 7859 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7860 | root->SetBounds(gfx::Size(100, 100)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 7861 | root->SetMasksToBounds(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7862 | root->SetForceRenderSurfaceForTesting(true); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 7863 | animated->SetOpacity(0.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7864 | animated->SetBounds(gfx::Size(20, 20)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 7865 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7866 | AddOpacityTransitionToElementWithPlayer(animated->element_id(), timeline(), |
| 7867 | 10.0, 0.f, 1.f, false); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 7868 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 7869 | |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 7870 | EXPECT_FALSE(animated->visible_layer_rect_for_testing().IsEmpty()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 7871 | } |
| 7872 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7873 | TEST_F(LayerTreeHostCommonTest, |
| 7874 | VisibleContentRectForAnimatedLayerWithSingularTransform) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 7875 | scoped_refptr<Layer> root = Layer::Create(); |
| 7876 | scoped_refptr<Layer> clip = Layer::Create(); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7877 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 7878 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7879 | scoped_refptr<LayerWithForcedDrawsContent> surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 7880 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7881 | scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 7882 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7883 | |
| 7884 | root->AddChild(clip); |
| 7885 | clip->AddChild(animated); |
| 7886 | animated->AddChild(surface); |
| 7887 | surface->AddChild(descendant_of_animation); |
| 7888 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 7889 | host()->SetRootLayer(root); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7890 | host()->SetElementIdsForTesting(); |
| 7891 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7892 | gfx::Transform uninvertible_matrix; |
| 7893 | uninvertible_matrix.Scale3d(6.f, 6.f, 0.f); |
| 7894 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7895 | root->SetBounds(gfx::Size(100, 100)); |
| 7896 | clip->SetBounds(gfx::Size(10, 10)); |
| 7897 | clip->SetMasksToBounds(true); |
| 7898 | animated->SetTransform(uninvertible_matrix); |
| 7899 | animated->SetBounds(gfx::Size(120, 120)); |
| 7900 | surface->SetBounds(gfx::Size(100, 100)); |
| 7901 | surface->SetForceRenderSurfaceForTesting(true); |
| 7902 | descendant_of_animation->SetBounds(gfx::Size(200, 200)); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7903 | |
| 7904 | TransformOperations start_transform_operations; |
| 7905 | start_transform_operations.AppendMatrix(uninvertible_matrix); |
| 7906 | TransformOperations end_transform_operations; |
| 7907 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7908 | SetElementIdsForTesting(); |
| 7909 | AddAnimatedTransformToElementWithPlayer(animated->element_id(), timeline(), |
| 7910 | 10.0, start_transform_operations, |
| 7911 | end_transform_operations); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 7912 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7913 | |
| 7914 | // The animated layer has a singular transform and maps to a non-empty rect in |
| 7915 | // clipped target space, so is treated as fully visible. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 7916 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7917 | |
| 7918 | // The singular transform on |animated| is flattened when inherited by |
| 7919 | // |surface|, and this happens to make it invertible. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 7920 | EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect_for_testing()); |
| 7921 | EXPECT_EQ(gfx::Rect(2, 2), |
| 7922 | descendant_of_animation->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7923 | |
| 7924 | gfx::Transform zero_matrix; |
| 7925 | zero_matrix.Scale3d(0.f, 0.f, 0.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7926 | animated->SetTransform(zero_matrix); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 7927 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7928 | |
| 7929 | // The animated layer maps to the empty rect in clipped target space, so is |
| 7930 | // treated as having an empty visible rect. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 7931 | EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7932 | |
| 7933 | // This time, flattening does not make |animated|'s transform invertible. This |
| 7934 | // means the clip cannot be projected into |surface|'s space, so we treat |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 7935 | // |surface| and layers that draw into it as having empty visible rect. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 7936 | EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect_for_testing()); |
| 7937 | EXPECT_EQ(gfx::Rect(), |
| 7938 | descendant_of_animation->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 7939 | } |
| 7940 | |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 7941 | // Verify that having animated opacity but current opacity 1 still creates |
| 7942 | // a render surface. |
| 7943 | TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) { |
| 7944 | LayerImpl* root = root_layer_for_testing(); |
| 7945 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 7946 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 7947 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7948 | root->SetBounds(gfx::Size(50, 50)); |
| 7949 | child->SetBounds(gfx::Size(50, 50)); |
| 7950 | child->SetDrawsContent(true); |
| 7951 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 7952 | grandchild->SetDrawsContent(true); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 7953 | |
| 7954 | SetElementIdsForTesting(); |
| 7955 | AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(), |
| 7956 | 10.0, 1.f, 0.2f, false); |
| 7957 | ExecuteCalculateDrawProperties(root); |
| 7958 | |
| 7959 | EXPECT_EQ(1.f, child->Opacity()); |
| 7960 | EXPECT_TRUE(root->has_render_surface()); |
| 7961 | EXPECT_TRUE(child->has_render_surface()); |
| 7962 | EXPECT_FALSE(grandchild->has_render_surface()); |
| 7963 | } |
| 7964 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 7965 | // Verify that having an animated filter (but no current filter, as these |
| 7966 | // are mutually exclusive) correctly creates a render surface. |
| 7967 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7968 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 7969 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 7970 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 7971 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7972 | root->SetBounds(gfx::Size(50, 50)); |
| 7973 | child->SetBounds(gfx::Size(50, 50)); |
| 7974 | grandchild->SetBounds(gfx::Size(50, 50)); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 7975 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7976 | SetElementIdsForTesting(); |
| 7977 | AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(), |
| 7978 | 10.0, 0.1f, 0.2f); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 7979 | ExecuteCalculateDrawProperties(root); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 7980 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 7981 | EXPECT_TRUE(root->has_render_surface()); |
| 7982 | EXPECT_TRUE(child->has_render_surface()); |
| 7983 | EXPECT_FALSE(grandchild->has_render_surface()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 7984 | |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 7985 | EXPECT_TRUE(root->render_surface()->Filters().IsEmpty()); |
| 7986 | EXPECT_TRUE(child->render_surface()->Filters().IsEmpty()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 7987 | |
| 7988 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 7989 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 7990 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 7991 | } |
| 7992 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 7993 | // Verify that having a filter animation with a delayed start time creates a |
| 7994 | // render surface. |
| 7995 | TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7996 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 7997 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 7998 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 7999 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8000 | root->SetBounds(gfx::Size(50, 50)); |
| 8001 | child->SetBounds(gfx::Size(50, 50)); |
| 8002 | grandchild->SetBounds(gfx::Size(50, 50)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8003 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8004 | SetElementIdsForTesting(); |
| 8005 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8006 | std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8007 | KeyframedFilterAnimationCurve::Create()); |
| 8008 | FilterOperations start_filters; |
| 8009 | start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f)); |
| 8010 | FilterOperations end_filters; |
| 8011 | end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f)); |
| 8012 | curve->AddKeyframe( |
| 8013 | FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 8014 | curve->AddKeyframe(FilterKeyframe::Create( |
| 8015 | base::TimeDelta::FromMilliseconds(100), end_filters, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8016 | std::unique_ptr<Animation> animation = |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8017 | Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8018 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8019 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8020 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8021 | AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8022 | std::move(animation)); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8023 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8024 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8025 | EXPECT_TRUE(root->has_render_surface()); |
| 8026 | EXPECT_TRUE(child->has_render_surface()); |
| 8027 | EXPECT_FALSE(grandchild->has_render_surface()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8028 | |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 8029 | EXPECT_TRUE(root->render_surface()->Filters().IsEmpty()); |
| 8030 | EXPECT_TRUE(child->render_surface()->Filters().IsEmpty()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8031 | |
| 8032 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8033 | EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation()); |
| 8034 | EXPECT_FALSE(child->FilterIsAnimating()); |
| 8035 | EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation()); |
| 8036 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8037 | EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation()); |
| 8038 | } |
| 8039 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8040 | // Ensures that the property tree code accounts for offsets between fixed |
| 8041 | // position layers and their respective containers. |
| 8042 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8043 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8044 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8045 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8046 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8047 | root->SetBounds(gfx::Size(50, 50)); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8048 | root->SetMasksToBounds(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8049 | root->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8050 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 8051 | child->SetBounds(gfx::Size(50, 50)); |
| 8052 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 8053 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8054 | grandchild->SetDrawsContent(true); |
| 8055 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8056 | LayerPositionConstraint constraint; |
| 8057 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8058 | grandchild->test_properties()->position_constraint = constraint; |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8059 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8060 | ExecuteCalculateDrawProperties(root); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8061 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8062 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8063 | } |
| 8064 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8065 | // Ensures that the property tree code accounts for offsets between fixed |
| 8066 | // position containers and their transform tree parents, when a fixed position |
| 8067 | // layer's container is its layer tree parent, but this parent doesn't have its |
| 8068 | // own transform tree node. |
| 8069 | TEST_F(LayerTreeHostCommonTest, |
| 8070 | PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8071 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8072 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8073 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8074 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8075 | root->SetBounds(gfx::Size(50, 50)); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8076 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8077 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 8078 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 8079 | child->SetBounds(gfx::Size(50, 50)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8080 | child->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8081 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 8082 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8083 | grandchild->SetDrawsContent(true); |
| 8084 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8085 | LayerPositionConstraint constraint; |
| 8086 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8087 | grandchild->test_properties()->position_constraint = constraint; |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8088 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8089 | ExecuteCalculateDrawProperties(root); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8090 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8091 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8092 | } |
| 8093 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8094 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8095 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8096 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8097 | LayerImpl* fixed = AddChild<LayerImpl>(frame_clip); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8098 | gfx::Transform translate_z; |
| 8099 | translate_z.Translate3d(0, 0, 10); |
| 8100 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8101 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8102 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8103 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8104 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 8105 | frame_clip->SetBounds(gfx::Size(100, 100)); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8106 | frame_clip->SetMasksToBounds(true); |
| 8107 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8108 | fixed->SetBounds(gfx::Size(1000, 1000)); |
| 8109 | fixed->SetDrawsContent(true); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8110 | |
| 8111 | LayerPositionConstraint constraint; |
| 8112 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8113 | fixed->test_properties()->position_constraint = constraint; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8114 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8115 | ExecuteCalculateDrawProperties(root); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8116 | |
| 8117 | gfx::Rect expected(0, 0, 100, 100); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8118 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8119 | } |
| 8120 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8121 | TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8122 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8123 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8124 | LayerImpl* scroller = AddChild<LayerImpl>(frame_clip); |
| 8125 | LayerImpl* fixed = AddChild<LayerImpl>(scroller); |
| 8126 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8127 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8128 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8129 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 8130 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 8131 | frame_clip->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8132 | frame_clip->SetMasksToBounds(true); |
| 8133 | frame_clip->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8134 | scroller->SetBounds(gfx::Size(1000, 1000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8135 | scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100)); |
| 8136 | scroller->SetScrollClipLayer(frame_clip->id()); |
| 8137 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8138 | fixed->SetPosition(gfx::PointF(100, 100)); |
| 8139 | fixed->SetBounds(gfx::Size(50, 50)); |
| 8140 | fixed->SetMasksToBounds(true); |
| 8141 | fixed->SetDrawsContent(true); |
| 8142 | fixed->test_properties()->force_render_surface = true; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8143 | |
| 8144 | LayerPositionConstraint constraint; |
| 8145 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8146 | fixed->test_properties()->position_constraint = constraint; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8147 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8148 | ExecuteCalculateDrawProperties(root); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8149 | |
| 8150 | gfx::Rect expected(0, 0, 50, 50); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8151 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8152 | } |
| 8153 | |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8154 | TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) { |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8155 | gfx::Transform translate; |
| 8156 | gfx::Transform rotate; |
| 8157 | |
| 8158 | translate.Translate(10, 10); |
| 8159 | rotate.Rotate(45); |
| 8160 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8161 | scoped_refptr<Layer> root = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8162 | root->SetBounds(gfx::Size(800, 800)); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8163 | root->SetIsContainerForFixedPositionLayers(true); |
| 8164 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8165 | host()->SetRootLayer(root); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8166 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8167 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8168 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8169 | |
| 8170 | root->SetTransform(translate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8171 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8172 | |
| 8173 | root->SetTransform(rotate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8174 | EXPECT_TRUE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8175 | } |
| 8176 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8177 | TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8178 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8179 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8180 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8181 | gfx::Transform scale_matrix; |
| 8182 | scale_matrix.Scale(2.f, 2.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8183 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8184 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8185 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8186 | child->SetTransform(scale_matrix); |
| 8187 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8188 | child->SetDrawsContent(true); |
| 8189 | |
| 8190 | ExecuteCalculateDrawProperties(root); |
| 8191 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8192 | |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 8193 | child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8194 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8195 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8196 | ExecuteCalculateDrawProperties(root); |
| 8197 | EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8198 | } |
| 8199 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8200 | TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8201 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8202 | LayerImpl* scroll_parent = AddChild<LayerImpl>(root); |
| 8203 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8204 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8205 | gfx::Transform scale; |
| 8206 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8207 | |
| 8208 | root->SetBounds(gfx::Size(50, 50)); |
| 8209 | scroll_child->SetTransform(scale); |
| 8210 | scroll_child->SetBounds(gfx::Size(40, 40)); |
| 8211 | scroll_child->SetDrawsContent(true); |
| 8212 | scroll_parent->SetBounds(gfx::Size(30, 30)); |
| 8213 | scroll_parent->SetDrawsContent(true); |
| 8214 | |
| 8215 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 8216 | scroll_parent->test_properties()->scroll_children = |
| 8217 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 8218 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8219 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8220 | ExecuteCalculateDrawProperties(root); |
| 8221 | EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8222 | |
| 8223 | scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8224 | scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
| 8225 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8226 | ExecuteCalculateDrawProperties(root); |
| 8227 | EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8228 | } |
| 8229 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8230 | static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8231 | |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8232 | TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) { |
| 8233 | // If the layer has a node in effect_tree, the return value of |
| 8234 | // num_copy_requests_in_target_subtree() must be equal to the actual number |
| 8235 | // of copy requests in the sub-layer_tree; Otherwise, the number is expected |
| 8236 | // to be the value of its nearest ancestor that owns an effect node and |
| 8237 | // greater than or equal to the actual number of copy requests in the |
| 8238 | // sub-layer_tree. |
| 8239 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8240 | scoped_refptr<Layer> root = Layer::Create(); |
| 8241 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 8242 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 8243 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 8244 | scoped_refptr<Layer> greatgrandchild = Layer::Create(); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8245 | |
| 8246 | root->AddChild(child1); |
| 8247 | root->AddChild(child2); |
| 8248 | child1->AddChild(grandchild); |
| 8249 | grandchild->AddChild(greatgrandchild); |
| 8250 | host()->SetRootLayer(root); |
| 8251 | |
| 8252 | child1->RequestCopyOfOutput( |
| 8253 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8254 | greatgrandchild->RequestCopyOfOutput( |
| 8255 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8256 | child2->SetOpacity(0.f); |
| 8257 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8258 | |
| 8259 | EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2); |
| 8260 | EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2); |
| 8261 | EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0); |
| 8262 | EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2); |
| 8263 | EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1); |
| 8264 | } |
| 8265 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8266 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8267 | scoped_refptr<Layer> root = Layer::Create(); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 8268 | FakeContentLayerClient client; |
| 8269 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8270 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8271 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8272 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8273 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8274 | scoped_refptr<FakePictureLayer> greatgrandchild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8275 | FakePictureLayer::Create(&client)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8276 | |
| 8277 | root->SetBounds(gfx::Size(100, 100)); |
| 8278 | child->SetBounds(gfx::Size(10, 10)); |
| 8279 | grandchild->SetBounds(gfx::Size(10, 10)); |
| 8280 | greatgrandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8281 | |
| 8282 | root->AddChild(child); |
| 8283 | child->AddChild(grandchild); |
| 8284 | grandchild->AddChild(greatgrandchild); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8285 | host()->SetRootLayer(root); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8286 | host()->SetElementIdsForTesting(); |
| 8287 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8288 | // Check the non-skipped case. |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8289 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8290 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8291 | |
| 8292 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8293 | // and we will configure |child| in several ways that should force the subtree |
| 8294 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8295 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8296 | grandchild->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8297 | gfx::Transform singular; |
| 8298 | singular.matrix().set(0, 0, 0); |
| 8299 | |
| 8300 | child->SetTransform(singular); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8301 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8302 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8303 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8304 | |
| 8305 | child->SetHideLayerAndSubtree(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8306 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8307 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8308 | child->SetHideLayerAndSubtree(false); |
| 8309 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8310 | gfx::Transform zero_z_scale; |
| 8311 | zero_z_scale.Scale3d(1, 1, 0); |
| 8312 | child->SetTransform(zero_z_scale); |
| 8313 | |
| 8314 | // Add a transform animation with a start delay. Now, even though |child| has |
| 8315 | // a singular transform, the subtree should still get processed. |
| 8316 | int animation_id = 0; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8317 | std::unique_ptr<Animation> animation = Animation::Create( |
| 8318 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8319 | animation_id, 1, TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8320 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8321 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8322 | AddAnimationToElementWithPlayer(child->element_id(), timeline(), |
| 8323 | std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8324 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8325 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8326 | grandchild->set_visible_layer_rect(gfx::Rect()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8327 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8328 | RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(), |
| 8329 | animation_id); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8330 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8331 | child->SetOpacity(0.f); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8332 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8333 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8334 | |
| 8335 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8336 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8337 | // processed anyhow. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 8338 | grandchild->RequestCopyOfOutput( |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8339 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8340 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8341 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8342 | greatgrandchild->set_visible_layer_rect(gfx::Rect()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8343 | |
| 8344 | // Add an opacity animation with a start delay. |
| 8345 | animation_id = 1; |
| 8346 | animation = Animation::Create( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8347 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8348 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8349 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8350 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8351 | AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(), |
| 8352 | std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8353 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8354 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8355 | } |
| 8356 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8357 | TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8358 | FakeImplTaskRunnerProvider task_runner_provider; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8359 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8360 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8361 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8362 | &task_graph_runner); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8363 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8364 | std::unique_ptr<LayerImpl> root = |
| 8365 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8366 | std::unique_ptr<LayerImpl> child = |
| 8367 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8368 | std::unique_ptr<LayerImpl> grandchild = |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8369 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 8370 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8371 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8372 | FakePictureLayerImpl::Create(host_impl.active_tree(), 4)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8373 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8374 | root->SetBounds(gfx::Size(100, 100)); |
| 8375 | child->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8376 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8377 | grandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8378 | grandchild->SetDrawsContent(true); |
| 8379 | greatgrandchild->SetDrawsContent(true); |
| 8380 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8381 | LayerImpl* root_ptr = root.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8382 | LayerImpl* child_ptr = child.get(); |
| 8383 | LayerImpl* grandchild_ptr = grandchild.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8384 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8385 | child->test_properties()->AddChild(std::move(grandchild)); |
| 8386 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8387 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8388 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8389 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 8390 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8391 | // Check the non-skipped case. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8392 | // ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8393 | // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8394 | |
| 8395 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8396 | // and we will configure |child| in several ways that should force the subtree |
| 8397 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8398 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8399 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8400 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8401 | gfx::Transform singular; |
| 8402 | singular.matrix().set(0, 0, 0); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8403 | // This line is used to make the results of skipping and not skipping layers |
| 8404 | // different. |
| 8405 | singular.matrix().set(0, 1, 1); |
| 8406 | |
| 8407 | gfx::Transform rotate; |
| 8408 | rotate.Rotate(90); |
| 8409 | |
| 8410 | gfx::Transform rotate_back_and_translate; |
| 8411 | rotate_back_and_translate.RotateAboutYAxis(180); |
| 8412 | rotate_back_and_translate.Translate(-10, 0); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8413 | |
| 8414 | child_ptr->SetTransform(singular); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8415 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8416 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8417 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8418 | child_ptr->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8419 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8420 | child_ptr->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8421 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8422 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8423 | child_ptr->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8424 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8425 | child_ptr->OnOpacityAnimated(0.f); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8426 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8427 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8428 | child_ptr->test_properties()->opacity = 1.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8429 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8430 | root_ptr->SetTransform(singular); |
| 8431 | // Force transform tree to have a node for child, so that ancestor's |
| 8432 | // invertible transform can be tested. |
| 8433 | child_ptr->SetTransform(rotate); |
| 8434 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
| 8435 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8436 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8437 | root_ptr->SetTransform(gfx::Transform()); |
| 8438 | child_ptr->SetTransform(gfx::Transform()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8439 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8440 | root_ptr->test_properties()->opacity = 0.f; |
| 8441 | child_ptr->test_properties()->opacity = 0.7f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8442 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
| 8443 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8444 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8445 | root_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8446 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8447 | child_ptr->test_properties()->opacity = 0.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8448 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8449 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8450 | // processed anyhow. |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 8451 | grandchild_ptr->test_properties()->copy_requests.push_back( |
| 8452 | CopyOutputRequest::CreateEmptyRequest()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8453 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8454 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8455 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 8456 | |
| 8457 | host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests(); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8458 | child_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8459 | |
| 8460 | // A double sided render surface with backface visible should not be skipped |
| 8461 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8462 | child_ptr->SetHasRenderSurface(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8463 | child_ptr->test_properties()->double_sided = true; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8464 | child_ptr->SetTransform(rotate_back_and_translate); |
| 8465 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8466 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8467 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8468 | child_ptr->SetTransform(gfx::Transform()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8469 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8470 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8471 | KeyframedTransformAnimationCurve::Create()); |
| 8472 | TransformOperations start; |
| 8473 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 8474 | gfx::Transform transform; |
| 8475 | transform.Scale3d(1.0, 2.0, 3.0); |
| 8476 | TransformOperations operation; |
| 8477 | operation.AppendMatrix(transform); |
| 8478 | curve->AddKeyframe( |
| 8479 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 8480 | curve->AddKeyframe(TransformKeyframe::Create( |
| 8481 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8482 | std::unique_ptr<Animation> transform_animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8483 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 8484 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8485 | host_impl.active_tree()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8486 | root_ptr->element_id(), player.get()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8487 | host_impl.active_tree() |
| 8488 | ->animation_host() |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8489 | ->GetElementAnimationsForElementId(root_ptr->element_id()) |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8490 | ->AddAnimation(std::move(transform_animation)); |
| 8491 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8492 | child_ptr->SetScrollClipLayer(root_ptr->id()); |
| 8493 | root_ptr->SetTransform(singular); |
| 8494 | child_ptr->SetTransform(singular); |
| 8495 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8496 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8497 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8498 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8499 | host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8500 | root_ptr->element_id(), player.get()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8501 | } |
| 8502 | |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8503 | TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8504 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8505 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8506 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 8507 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8508 | SetElementIdsForTesting(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8509 | |
| 8510 | gfx::Transform singular; |
| 8511 | singular.matrix().set(0, 0, 0); |
| 8512 | singular.matrix().set(0, 1, 1); |
| 8513 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8514 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8515 | child->SetTransform(singular); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8516 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8517 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8518 | grand_child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8519 | grand_child->SetDrawsContent(true); |
| 8520 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8521 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8522 | KeyframedTransformAnimationCurve::Create()); |
| 8523 | TransformOperations start; |
| 8524 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 8525 | gfx::Transform transform; |
| 8526 | transform.Scale3d(1.0, 2.0, 3.0); |
| 8527 | TransformOperations operation; |
| 8528 | operation.AppendMatrix(transform); |
| 8529 | curve->AddKeyframe( |
| 8530 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 8531 | curve->AddKeyframe(TransformKeyframe::Create( |
| 8532 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8533 | std::unique_ptr<Animation> transform_animation( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8534 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 8535 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8536 | host_impl()->active_tree()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8537 | grand_child->element_id(), player.get()); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8538 | host_impl() |
| 8539 | ->active_tree() |
| 8540 | ->animation_host() |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8541 | ->GetElementAnimationsForElementId(grand_child->element_id()) |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8542 | ->AddAnimation(std::move(transform_animation)); |
| 8543 | |
| 8544 | ExecuteCalculateDrawProperties(root); |
| 8545 | EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect()); |
| 8546 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
| 8547 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8548 | host_impl()->active_tree()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8549 | grand_child->element_id(), player.get()); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8550 | } |
| 8551 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8552 | TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { |
| 8553 | FakeImplTaskRunnerProvider task_runner_provider; |
| 8554 | TestSharedBitmapManager shared_bitmap_manager; |
| 8555 | TestTaskGraphRunner task_graph_runner; |
| 8556 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 8557 | &task_graph_runner); |
| 8558 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8559 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8560 | std::unique_ptr<LayerImpl> root = |
| 8561 | LayerImpl::Create(host_impl.pending_tree(), 1); |
| 8562 | std::unique_ptr<LayerImpl> child = |
| 8563 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 8564 | std::unique_ptr<LayerImpl> grandchild = |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8565 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 8566 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8567 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8568 | FakePictureLayerImpl::Create(host_impl.pending_tree(), 4)); |
| 8569 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8570 | root->SetBounds(gfx::Size(100, 100)); |
| 8571 | child->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8572 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8573 | grandchild->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8574 | grandchild->SetDrawsContent(true); |
| 8575 | greatgrandchild->SetDrawsContent(true); |
| 8576 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8577 | LayerImpl* root_ptr = root.get(); |
| 8578 | LayerImpl* grandchild_ptr = grandchild.get(); |
| 8579 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8580 | child->test_properties()->AddChild(std::move(grandchild)); |
| 8581 | root->test_properties()->AddChild(std::move(child)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8582 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8583 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8584 | host_impl.pending_tree()->SetElementIdsForTesting(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8585 | |
| 8586 | // Check the non-skipped case. |
| 8587 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8588 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 8589 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8590 | std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8591 | KeyframedFloatAnimationCurve::Create()); |
loyso | 1e4e7ee | 2016-06-03 03:04:49 | [diff] [blame] | 8592 | std::unique_ptr<TimingFunction> func = |
| 8593 | CubicBezierTimingFunction::CreatePreset( |
| 8594 | CubicBezierTimingFunction::EaseType::EASE); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8595 | curve->AddKeyframe( |
| 8596 | FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func))); |
| 8597 | curve->AddKeyframe( |
| 8598 | FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8599 | std::unique_ptr<Animation> animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8600 | Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY)); |
| 8601 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8602 | host_impl.active_tree()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8603 | root_ptr->element_id(), player.get()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8604 | host_impl.active_tree() |
| 8605 | ->animation_host() |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8606 | ->GetElementAnimationsForElementId(root_ptr->element_id()) |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8607 | ->AddAnimation(std::move(animation)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8608 | root_ptr->test_properties()->opacity = 0.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8609 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8610 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8611 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8612 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 8613 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8614 | host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8615 | root_ptr->element_id(), player.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8616 | } |
| 8617 | |
| 8618 | TEST_F(LayerTreeHostCommonTest, SkippingLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8619 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8620 | LayerImpl* child = AddChild<LayerImpl>(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8621 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8622 | root->SetBounds(gfx::Size(100, 100)); |
| 8623 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8624 | child->SetDrawsContent(true); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8625 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8626 | ExecuteCalculateDrawProperties(root); |
| 8627 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8628 | child->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8629 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8630 | child->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8631 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8632 | ExecuteCalculateDrawProperties(root); |
| 8633 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8634 | child->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8635 | |
| 8636 | child->SetBounds(gfx::Size()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8637 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8638 | ExecuteCalculateDrawProperties(root); |
| 8639 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8640 | child->SetBounds(gfx::Size(10, 10)); |
| 8641 | |
| 8642 | gfx::Transform rotate; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8643 | child->test_properties()->double_sided = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8644 | rotate.RotateAboutXAxis(180.f); |
| 8645 | child->SetTransform(rotate); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8646 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8647 | ExecuteCalculateDrawProperties(root); |
| 8648 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8649 | child->test_properties()->double_sided = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8650 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8651 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8652 | child->test_properties()->opacity = 0.f; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8653 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8654 | ExecuteCalculateDrawProperties(root); |
| 8655 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8656 | } |
| 8657 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 8658 | TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) { |
| 8659 | // Ensure that the treewalk in LayerTreeHostCommom:: |
| 8660 | // PreCalculateMetaInformation happens when its required. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8661 | scoped_refptr<Layer> root = Layer::Create(); |
| 8662 | scoped_refptr<Layer> parent = Layer::Create(); |
| 8663 | scoped_refptr<Layer> child = Layer::Create(); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 8664 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8665 | root->SetBounds(gfx::Size(100, 100)); |
| 8666 | parent->SetBounds(gfx::Size(100, 100)); |
| 8667 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 8668 | child->SetClipParent(root.get()); |
| 8669 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8670 | root->AddChild(parent); |
| 8671 | parent->AddChild(child); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8672 | host()->SetRootLayer(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 8673 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 8674 | child->RequestCopyOfOutput( |
| 8675 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8676 | |
| 8677 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8678 | EXPECT_EQ(parent->num_unclipped_descendants(), 1u); |
| 8679 | |
| 8680 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
| 8681 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8682 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 8683 | } |
| 8684 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 8685 | TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) { |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8686 | scoped_refptr<Layer> root = Layer::Create(); |
| 8687 | root->SetBounds(gfx::Size(800, 800)); |
| 8688 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 8689 | gfx::Transform translate_z; |
| 8690 | translate_z.Translate3d(0, 0, 10); |
| 8691 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8692 | scoped_refptr<Layer> child = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8693 | child->SetTransform(translate_z); |
| 8694 | child->SetBounds(gfx::Size(100, 100)); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 8695 | |
| 8696 | root->AddChild(child); |
| 8697 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8698 | host()->SetRootLayer(root); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 8699 | |
| 8700 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8701 | EXPECT_NE(-1, child->transform_tree_index()); |
| 8702 | |
| 8703 | child->RemoveFromParent(); |
| 8704 | |
| 8705 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8706 | EXPECT_EQ(-1, child->transform_tree_index()); |
| 8707 | } |
| 8708 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8709 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { |
| 8710 | // Ensure that a Clip Node is added when a render surface applies clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8711 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8712 | LayerImpl* significant_transform = AddChildToRoot<LayerImpl>(); |
| 8713 | LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform); |
| 8714 | LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree); |
| 8715 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 8716 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8717 | // This transform should be a significant one so that a transform node is |
| 8718 | // formed for it. |
| 8719 | gfx::Transform transform1; |
| 8720 | transform1.RotateAboutYAxis(45); |
| 8721 | transform1.RotateAboutXAxis(30); |
| 8722 | // This transform should be a 3d transform as we want the render surface |
| 8723 | // to flatten the transform |
| 8724 | gfx::Transform transform2; |
| 8725 | transform2.Translate3d(10, 10, 10); |
| 8726 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8727 | root->SetBounds(gfx::Size(30, 30)); |
| 8728 | significant_transform->SetTransform(transform1); |
| 8729 | significant_transform->SetBounds(gfx::Size(30, 30)); |
| 8730 | layer_clips_subtree->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8731 | layer_clips_subtree->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8732 | layer_clips_subtree->test_properties()->force_render_surface = true; |
| 8733 | render_surface->SetTransform(transform2); |
| 8734 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 8735 | render_surface->test_properties()->force_render_surface = true; |
| 8736 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8737 | test_layer->SetDrawsContent(true); |
| 8738 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8739 | ExecuteCalculateDrawProperties(root); |
| 8740 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 8741 | TransformTree& transform_tree = |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8742 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 8743 | TransformNode* transform_node = |
| 8744 | transform_tree.Node(significant_transform->transform_tree_index()); |
| 8745 | EXPECT_EQ(transform_node->owner_id, significant_transform->id()); |
| 8746 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 8747 | EXPECT_TRUE(root->has_render_surface()); |
| 8748 | EXPECT_FALSE(significant_transform->has_render_surface()); |
| 8749 | EXPECT_TRUE(layer_clips_subtree->has_render_surface()); |
| 8750 | EXPECT_TRUE(render_surface->has_render_surface()); |
| 8751 | EXPECT_FALSE(test_layer->has_render_surface()); |
| 8752 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 8753 | ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8754 | ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 8755 | EXPECT_FALSE(clip_node->applies_local_clip); |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 8756 | EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8757 | } |
| 8758 | |
| 8759 | TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 8760 | // Ensure that when parent clip node's transform is an ancestor of current |
| 8761 | // clip node's target, clip is 'projected' from parent space to current |
| 8762 | // target space and visible rects are calculated correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8763 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8764 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 8765 | LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 8766 | LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| 8767 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8768 | gfx::Transform transform; |
| 8769 | transform.RotateAboutYAxis(45); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8770 | |
| 8771 | root->SetBounds(gfx::Size(30, 30)); |
| 8772 | clip_layer->SetTransform(transform); |
| 8773 | clip_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8774 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8775 | target_layer->SetTransform(transform); |
| 8776 | target_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8777 | target_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8778 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8779 | test_layer->SetDrawsContent(true); |
| 8780 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8781 | ExecuteCalculateDrawProperties(root); |
| 8782 | |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8783 | EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8784 | } |
| 8785 | |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 8786 | TEST_F(LayerTreeHostCommonTest, |
| 8787 | RenderSurfaceWithUnclippedDescendantsClipsSubtree) { |
| 8788 | // Ensure clip rect is calculated correctly when render surface has unclipped |
| 8789 | // descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8790 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 8791 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 8792 | LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); |
| 8793 | LayerImpl* render_surface = |
| 8794 | AddChild<LayerImpl>(between_clip_parent_and_child); |
| 8795 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 8796 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 8797 | gfx::Transform translate; |
| 8798 | translate.Translate(2.0, 2.0); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 8799 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8800 | root->SetBounds(gfx::Size(30, 30)); |
| 8801 | clip_parent->SetTransform(translate); |
| 8802 | clip_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 8803 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8804 | between_clip_parent_and_child->SetTransform(translate); |
| 8805 | between_clip_parent_and_child->SetBounds(gfx::Size(30, 30)); |
| 8806 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 8807 | render_surface->test_properties()->force_render_surface = true; |
| 8808 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 8809 | test_layer->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8810 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 8811 | render_surface->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8812 | clip_parent->test_properties()->clip_children = |
| 8813 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 8814 | clip_parent->test_properties()->clip_children->insert(render_surface); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 8815 | |
| 8816 | ExecuteCalculateDrawProperties(root); |
| 8817 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 8818 | EXPECT_TRUE(test_layer->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 8819 | EXPECT_FALSE(test_layer->render_target()->is_clipped()); |
weiliangc | 0b41eaf | 2016-03-14 21:35:56 | [diff] [blame] | 8820 | EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect()); |
| 8821 | EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 8822 | } |
| 8823 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 8824 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 8825 | RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) { |
| 8826 | // Ensure that the visible layer rect of a descendant of a surface with |
| 8827 | // unclipped descendants is computed correctly, when the surface doesn't apply |
| 8828 | // a clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8829 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 8830 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 8831 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 8832 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 8833 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 8834 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8835 | root->SetBounds(gfx::Size(30, 10)); |
| 8836 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 8837 | render_surface->SetBounds(gfx::Size(10, 15)); |
| 8838 | render_surface->test_properties()->force_render_surface = true; |
| 8839 | clip_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 8840 | clip_child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8841 | child->SetBounds(gfx::Size(40, 40)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 8842 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8843 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 8844 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8845 | clip_parent->test_properties()->clip_children = |
| 8846 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 8847 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 8848 | |
| 8849 | ExecuteCalculateDrawProperties(root); |
| 8850 | EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect()); |
| 8851 | } |
| 8852 | |
| 8853 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 8854 | RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8855 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 8856 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 8857 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 8858 | LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface); |
| 8859 | LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1); |
| 8860 | LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child); |
| 8861 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8862 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 8863 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8864 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 8865 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 8866 | render_surface->SetMasksToBounds(true); |
| 8867 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8868 | render_surface->test_properties()->force_render_surface = true; |
| 8869 | test_layer1->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 8870 | test_layer1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8871 | clip_child->SetBounds(gfx::Size(50, 50)); |
| 8872 | clip_child->SetDrawsContent(true); |
| 8873 | test_layer2->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 8874 | test_layer2->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 8875 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8876 | clip_child->test_properties()->clip_parent = clip_parent; |
| 8877 | clip_parent->test_properties()->clip_children = |
| 8878 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 8879 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 8880 | |
| 8881 | ExecuteCalculateDrawProperties(root); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 8882 | EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect()); |
| 8883 | EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect()); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 8884 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
| 8885 | EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect()); |
| 8886 | } |
| 8887 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 8888 | TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8889 | LayerImpl* root = root_layer_for_testing(); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 8890 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 8891 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 8892 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 8893 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8894 | root->SetBounds(gfx::Size(50, 50)); |
| 8895 | clip_parent->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 8896 | clip_parent->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8897 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 8898 | render_surface->test_properties()->force_render_surface = true; |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 8899 | render_surface->SetMasksToBounds(true); |
| 8900 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8901 | clip_child->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 8902 | clip_child->SetDrawsContent(true); |
| 8903 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 8904 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8905 | clip_parent->test_properties()->clip_children = |
| 8906 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 8907 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 8908 | |
| 8909 | ExecuteCalculateDrawProperties(root); |
| 8910 | |
| 8911 | // The clip child should inherit its clip parent's clipping state, not its |
| 8912 | // tree parent's clipping state. |
| 8913 | EXPECT_FALSE(clip_parent->is_clipped()); |
| 8914 | EXPECT_TRUE(render_surface->is_clipped()); |
| 8915 | EXPECT_FALSE(clip_child->is_clipped()); |
| 8916 | } |
| 8917 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 8918 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) { |
| 8919 | // Tests the value of render surface content rect when we have multiple types |
| 8920 | // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and |
| 8921 | // clipped surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8922 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 8923 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 8924 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 8925 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 8926 | LayerImpl* unclipped_desc_surface2 = |
| 8927 | AddChild<LayerImpl>(unclipped_desc_surface); |
| 8928 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2); |
| 8929 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 8930 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8931 | root->SetBounds(gfx::Size(80, 80)); |
| 8932 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 8933 | unclipped_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8934 | unclipped_surface->SetDrawsContent(true); |
| 8935 | unclipped_surface->test_properties()->force_render_surface = true; |
| 8936 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 8937 | clip_parent->SetMasksToBounds(true); |
| 8938 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 8939 | unclipped_desc_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8940 | unclipped_desc_surface->SetDrawsContent(true); |
| 8941 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 8942 | unclipped_desc_surface2->SetBounds(gfx::Size(60, 60)); |
| 8943 | unclipped_desc_surface2->SetDrawsContent(true); |
| 8944 | unclipped_desc_surface2->test_properties()->force_render_surface = true; |
| 8945 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 8946 | clipped_surface->SetBounds(gfx::Size(70, 70)); |
| 8947 | clipped_surface->SetDrawsContent(true); |
| 8948 | clipped_surface->test_properties()->force_render_surface = true; |
| 8949 | |
| 8950 | clip_child->test_properties()->clip_parent = clip_parent; |
| 8951 | clip_parent->test_properties()->clip_children = |
| 8952 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 8953 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 8954 | |
| 8955 | ExecuteCalculateDrawProperties(root); |
| 8956 | EXPECT_EQ(gfx::Rect(50, 50), |
| 8957 | unclipped_surface->render_surface()->content_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 8958 | EXPECT_EQ(gfx::Rect(50, 50), |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 8959 | unclipped_desc_surface->render_surface()->content_rect()); |
| 8960 | EXPECT_EQ(gfx::Rect(50, 50), |
| 8961 | unclipped_desc_surface2->render_surface()->content_rect()); |
| 8962 | EXPECT_EQ(gfx::Rect(50, 50), |
| 8963 | clipped_surface->render_surface()->content_rect()); |
| 8964 | } |
| 8965 | |
| 8966 | TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) { |
| 8967 | // Tests the value of render surface content rect when we have a layer that |
| 8968 | // clips between the clip parent's target and clip child's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8969 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 8970 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 8971 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 8972 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 8973 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 8974 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 8975 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 8976 | gfx::Transform translate; |
| 8977 | translate.Translate(10, 10); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8978 | |
| 8979 | root->SetBounds(gfx::Size(100, 100)); |
| 8980 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 8981 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8982 | surface->test_properties()->force_render_surface = true; |
| 8983 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 8984 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8985 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 8986 | unclipped_desc_surface->SetTransform(translate); |
| 8987 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 8988 | unclipped_desc_surface->SetDrawsContent(true); |
| 8989 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 8990 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 8991 | clip_child->SetDrawsContent(true); |
| 8992 | |
| 8993 | clip_child->test_properties()->clip_parent = clip_parent; |
| 8994 | clip_parent->test_properties()->clip_children = |
| 8995 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 8996 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 8997 | |
| 8998 | ExecuteCalculateDrawProperties(root); |
| 8999 | |
| 9000 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9001 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9002 | } |
| 9003 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9004 | TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9005 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9006 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9007 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9008 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9009 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9010 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9011 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9012 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9013 | gfx::Transform scale; |
| 9014 | scale.Scale(2, 2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9015 | |
| 9016 | root->SetBounds(gfx::Size(100, 100)); |
| 9017 | surface->SetTransform(scale); |
| 9018 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9019 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9020 | surface->test_properties()->force_render_surface = true; |
| 9021 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9022 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9023 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 9024 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 9025 | unclipped_desc_surface->SetDrawsContent(true); |
| 9026 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9027 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9028 | clip_child->SetDrawsContent(true); |
| 9029 | |
| 9030 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9031 | clip_parent->test_properties()->clip_children = |
| 9032 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9033 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9034 | |
| 9035 | ExecuteCalculateDrawProperties(root); |
| 9036 | |
| 9037 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 9038 | } |
| 9039 | |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9040 | TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9041 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9042 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9043 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9044 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9045 | gfx::Transform translation; |
| 9046 | translation.Translate(10, 10); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9047 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9048 | root->SetBounds(gfx::Size(30, 30)); |
| 9049 | render_surface->SetBounds(gfx::Size(30, 30)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9050 | render_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9051 | render_surface->test_properties()->force_render_surface = true; |
| 9052 | test_layer->SetTransform(translation); |
| 9053 | test_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9054 | test_layer->SetDrawsContent(true); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9055 | test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9056 | test_layer->test_properties()->opacity = 0.f; |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9057 | |
| 9058 | ExecuteCalculateDrawProperties(root); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 9059 | EXPECT_TRANSFORMATION_MATRIX_EQ(translation, |
| 9060 | test_layer->ScreenSpaceTransform()); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9061 | } |
| 9062 | |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9063 | TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9064 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9065 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9066 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9067 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9068 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9069 | root->SetBounds(gfx::Size(30, 30)); |
| 9070 | clip_parent->SetBounds(gfx::Size(40, 40)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9071 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9072 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9073 | render_surface->SetMasksToBounds(true); |
| 9074 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9075 | render_surface->test_properties()->force_render_surface = true; |
| 9076 | clip_child->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9077 | clip_child->SetDrawsContent(true); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9078 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9079 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9080 | clip_parent->test_properties()->clip_children = |
| 9081 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9082 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9083 | |
| 9084 | ExecuteCalculateDrawProperties(root); |
| 9085 | EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect()); |
| 9086 | } |
| 9087 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9088 | TEST_F(LayerTreeHostCommonTest, |
| 9089 | LayerClipRectLargerThanClippingRenderSurfaceRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9090 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9091 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9092 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9093 | |
| 9094 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9095 | root->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9096 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9097 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9098 | render_surface->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9099 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9100 | render_surface->test_properties()->force_render_surface = true; |
| 9101 | test_layer->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9102 | test_layer->SetMasksToBounds(true); |
| 9103 | test_layer->SetDrawsContent(true); |
| 9104 | ExecuteCalculateDrawProperties(root); |
| 9105 | |
| 9106 | EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect()); |
| 9107 | EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect()); |
| 9108 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect()); |
| 9109 | } |
| 9110 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9111 | TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) { |
| 9112 | // Tests that subtree is hidden is updated. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9113 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9114 | LayerImpl* hidden = AddChild<LayerImpl>(root); |
| 9115 | LayerImpl* test = AddChild<LayerImpl>(hidden); |
| 9116 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9117 | root->SetBounds(gfx::Size(30, 30)); |
| 9118 | hidden->SetBounds(gfx::Size(30, 30)); |
| 9119 | hidden->test_properties()->force_render_surface = true; |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9120 | hidden->test_properties()->hide_layer_and_subtree = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9121 | test->SetBounds(gfx::Size(30, 30)); |
| 9122 | test->test_properties()->force_render_surface = true; |
| 9123 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9124 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9125 | EXPECT_TRUE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9126 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9127 | hidden->test_properties()->hide_layer_and_subtree = false; |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9128 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9129 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9130 | EXPECT_FALSE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9131 | } |
| 9132 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9133 | TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9134 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9135 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9136 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 9137 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
| 9138 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9139 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9140 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9141 | render_surface1->SetPosition(gfx::PointF(10, 10)); |
| 9142 | render_surface1->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9143 | render_surface1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9144 | render_surface1->test_properties()->force_render_surface = true; |
| 9145 | render_surface2->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9146 | render_surface2->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9147 | render_surface2->test_properties()->force_render_surface = true; |
| 9148 | clip_child->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9149 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9150 | clip_child->test_properties()->clip_parent = root; |
| 9151 | root->test_properties()->clip_children = |
| 9152 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9153 | root->test_properties()->clip_children->insert(clip_child); |
| 9154 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9155 | ExecuteCalculateDrawProperties(root); |
| 9156 | |
| 9157 | EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); |
jaydasika | daf0af0 | 2016-01-06 15:33:37 | [diff] [blame] | 9158 | // A clip node is created for every render surface and for layers that have |
| 9159 | // local clip. So, here it should be craeted for every layer. |
| 9160 | EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9161 | } |
| 9162 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9163 | TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) { |
| 9164 | // Tests that a mask layer's draw properties are computed correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9165 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9166 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9167 | child->test_properties()->SetMaskLayer( |
| 9168 | LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 9169 | LayerImpl* mask = child->test_properties()->mask_layer; |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9170 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9171 | gfx::Transform transform; |
| 9172 | transform.Translate(10, 10); |
| 9173 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9174 | root->SetBounds(gfx::Size(40, 40)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9175 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9176 | child->SetTransform(transform); |
| 9177 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9178 | child->SetDrawsContent(false); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9179 | mask->SetBounds(gfx::Size(20, 20)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9180 | ExecuteCalculateDrawProperties(root); |
| 9181 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9182 | // The render surface created for the mask has no contributing content, so the |
| 9183 | // mask isn't a drawn RSLL member. This means it has an empty visible rect, |
| 9184 | // but its screen space transform can still be computed correctly on-demand. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9185 | EXPECT_FALSE(mask->is_drawn_render_surface_layer_list_member()); |
| 9186 | EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect()); |
| 9187 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9188 | |
| 9189 | // Make the child's render surface have contributing content. |
| 9190 | child->SetDrawsContent(true); |
| 9191 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9192 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9193 | EXPECT_TRUE(mask->is_drawn_render_surface_layer_list_member()); |
| 9194 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
| 9195 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9196 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9197 | transform.Translate(10, 10); |
| 9198 | child->SetTransform(transform); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9199 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9200 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9201 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
| 9202 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9203 | } |
| 9204 | |
| 9205 | TEST_F(LayerTreeHostCommonTest, ReplicaMaskLayerDrawProperties) { |
| 9206 | // Tests that a replica mask layer's draw properties are computed correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9207 | LayerImpl* root = root_layer_for_testing(); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9208 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9209 | child->test_properties()->SetReplicaLayer( |
| 9210 | LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 9211 | LayerImpl* replica = child->test_properties()->replica_layer; |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 9212 | replica->test_properties()->parent = child; |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9213 | replica->test_properties()->SetMaskLayer( |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9214 | LayerImpl::Create(root->layer_tree_impl(), 200)); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9215 | LayerImpl* replica_mask = replica->test_properties()->mask_layer; |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9216 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9217 | gfx::Transform transform; |
| 9218 | transform.Translate(10, 10); |
| 9219 | |
| 9220 | gfx::PointF replica_position(3.f, 3.f); |
| 9221 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9222 | root->SetBounds(gfx::Size(40, 40)); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9223 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9224 | child->SetTransform(transform); |
| 9225 | child->SetBounds(gfx::Size(30, 30)); |
| 9226 | replica->SetPosition(replica_position); |
| 9227 | replica_mask->SetBounds(gfx::Size(20, 20)); |
| 9228 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9229 | ExecuteCalculateDrawProperties(root); |
| 9230 | |
| 9231 | // The render surface created for the replica has no contributing content, so |
| 9232 | // the replica's mask isn't a drawn RSLL member. This means it has an empty |
| 9233 | // visible rect, but its screen space transform can still be computed |
| 9234 | // correctly on-demand. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9235 | EXPECT_FALSE(replica_mask->is_drawn_render_surface_layer_list_member()); |
| 9236 | EXPECT_EQ(gfx::Rect(), replica_mask->visible_layer_rect()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9237 | |
| 9238 | gfx::Transform expected_screen_space_transform = transform; |
| 9239 | expected_screen_space_transform.Translate(replica_position.x(), |
| 9240 | replica_position.y()); |
| 9241 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9242 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 9243 | replica_mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9244 | |
| 9245 | // Make the child's render surface have contributing content. |
| 9246 | child->SetDrawsContent(true); |
| 9247 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9248 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9249 | EXPECT_TRUE(replica_mask->is_drawn_render_surface_layer_list_member()); |
| 9250 | EXPECT_EQ(gfx::Rect(20, 20), replica_mask->visible_layer_rect()); |
| 9251 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 9252 | replica_mask->ScreenSpaceTransform()); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9253 | } |
| 9254 | |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9255 | TEST_F(LayerTreeHostCommonTest, |
| 9256 | SublayerScaleWithTransformNodeBetweenTwoTargets) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9257 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9258 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9259 | LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1); |
| 9260 | LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets); |
| 9261 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9262 | |
| 9263 | gfx::Transform scale; |
| 9264 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9265 | |
| 9266 | root->SetBounds(gfx::Size(30, 30)); |
| 9267 | render_surface1->SetTransform(scale); |
| 9268 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 9269 | render_surface1->test_properties()->force_render_surface = true; |
| 9270 | between_targets->SetBounds(gfx::Size(30, 30)); |
| 9271 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 9272 | render_surface2->test_properties()->force_render_surface = true; |
| 9273 | test_layer->SetBounds(gfx::Size(30, 30)); |
| 9274 | test_layer->SetDrawsContent(true); |
| 9275 | |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9276 | // We want layer between the two targets to create a clip node and transform |
| 9277 | // node but it shouldn't create a render surface. |
| 9278 | between_targets->SetMasksToBounds(true); |
| 9279 | between_targets->Set3dSortingContextId(2); |
| 9280 | |
| 9281 | ExecuteCalculateDrawProperties(root); |
| 9282 | |
| 9283 | TransformTree& tree = |
| 9284 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9285 | TransformNode* node = tree.Node(render_surface1->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9286 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9287 | |
| 9288 | node = tree.Node(between_targets->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9289 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9290 | |
| 9291 | node = tree.Node(render_surface2->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9292 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9293 | |
| 9294 | EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect()); |
| 9295 | } |
| 9296 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9297 | TEST_F(LayerTreeHostCommonTest, LargeTransformTest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9298 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9299 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9300 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9301 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9302 | child->SetDrawsContent(true); |
| 9303 | child->SetMasksToBounds(true); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9304 | |
| 9305 | gfx::Transform large_transform; |
| 9306 | large_transform.Scale(99999999999999999999.f, 99999999999999999999.f); |
| 9307 | large_transform.Scale(9999999999999999999.f, 9999999999999999999.f); |
| 9308 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0))); |
| 9309 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1))); |
| 9310 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9311 | root->SetBounds(gfx::Size(30, 30)); |
| 9312 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 9313 | render_surface1->test_properties()->force_render_surface = true; |
| 9314 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9315 | // TODO(sunxd): we make child have no render surface, because if the |
| 9316 | // child has one, the large transform applied to child will result in NaNs in |
| 9317 | // the draw_transform of the render_surface, thus make draw property updates |
| 9318 | // skip the child layer. We need further investigation into this to know |
| 9319 | // what exactly happens here. |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9320 | child->SetTransform(large_transform); |
| 9321 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9322 | |
| 9323 | ExecuteCalculateDrawProperties(root); |
| 9324 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9325 | EXPECT_EQ(gfx::RectF(), |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9326 | render_surface1->render_surface()->DrawableContentRect()); |
| 9327 | |
| 9328 | bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) || |
| 9329 | std::isnan(child->DrawTransform().matrix().get(0, 0)); |
| 9330 | EXPECT_TRUE(is_inf_or_nan); |
| 9331 | |
| 9332 | is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) || |
| 9333 | std::isnan(child->DrawTransform().matrix().get(1, 1)); |
| 9334 | EXPECT_TRUE(is_inf_or_nan); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9335 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 9336 | // The root layer should be in the RenderSurfaceLayerListImpl. |
| 9337 | const auto* rsll = render_surface_layer_list_impl(); |
| 9338 | EXPECT_NE(std::find(rsll->begin(), rsll->end(), root), rsll->end()); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9339 | } |
| 9340 | |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9341 | TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) { |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9342 | scoped_refptr<Layer> root = Layer::Create(); |
| 9343 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 9344 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9345 | root->AddChild(child); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9346 | host()->SetRootLayer(root); |
| 9347 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9348 | root->SetBounds(gfx::Size(100, 100)); |
| 9349 | child->SetBounds(gfx::Size(20, 20)); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9350 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9351 | |
| 9352 | // Changing the opacity from 1 to non-1 value should trigger rebuild of |
| 9353 | // property trees as a new effect node will be created. |
| 9354 | child->SetOpacity(0.5f); |
| 9355 | PropertyTrees* property_trees = host()->property_trees(); |
| 9356 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 9357 | |
| 9358 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9359 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 9360 | property_trees->effect_id_to_index_map.end()); |
| 9361 | |
| 9362 | // child already has an effect node. Changing its opacity shouldn't trigger |
| 9363 | // a property trees rebuild. |
| 9364 | child->SetOpacity(0.8f); |
| 9365 | property_trees = host()->property_trees(); |
| 9366 | EXPECT_FALSE(property_trees->needs_rebuild); |
| 9367 | |
| 9368 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9369 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 9370 | property_trees->effect_id_to_index_map.end()); |
| 9371 | |
| 9372 | // Changing the opacity from non-1 value to 1 should trigger a rebuild of |
| 9373 | // property trees as the effect node may no longer be needed. |
| 9374 | child->SetOpacity(1.f); |
| 9375 | property_trees = host()->property_trees(); |
| 9376 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 9377 | |
| 9378 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9379 | EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()), |
| 9380 | property_trees->effect_id_to_index_map.end()); |
| 9381 | } |
| 9382 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9383 | TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) { |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9384 | scoped_refptr<Layer> root = Layer::Create(); |
| 9385 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 9386 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9387 | root->AddChild(animated); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9388 | host()->SetRootLayer(root); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9389 | host()->SetElementIdsForTesting(); |
| 9390 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9391 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9392 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9393 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9394 | animated->SetOpacity(0.f); |
| 9395 | |
| 9396 | scoped_refptr<AnimationPlayer> player = |
| 9397 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 9398 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9399 | |
| 9400 | player->AttachElement(animated->element_id()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9401 | |
| 9402 | int animation_id = 0; |
| 9403 | std::unique_ptr<Animation> animation = Animation::Create( |
| 9404 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 9405 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 9406 | animation->set_fill_mode(Animation::FillMode::NONE); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9407 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 9408 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9409 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 9410 | std::move(animation)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9411 | |
| 9412 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9413 | |
| 9414 | EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree; |
| 9415 | EffectNode* node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9416 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 9417 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9418 | |
| 9419 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
| 9420 | root->layer_tree_host()->AnimateLayers( |
| 9421 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 9422 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9423 | EXPECT_TRUE(node->is_currently_animating_opacity); |
| 9424 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9425 | |
| 9426 | player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/); |
| 9427 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9428 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 9429 | EXPECT_FALSE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9430 | } |
| 9431 | |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9432 | TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) { |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9433 | scoped_refptr<Layer> root = Layer::Create(); |
| 9434 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 9435 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9436 | root->AddChild(animated); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9437 | host()->SetRootLayer(root); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9438 | host()->SetElementIdsForTesting(); |
| 9439 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9440 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9441 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9442 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9443 | |
| 9444 | scoped_refptr<AnimationPlayer> player = |
| 9445 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 9446 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9447 | player->AttachElement(animated->element_id()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9448 | |
| 9449 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 9450 | KeyframedTransformAnimationCurve::Create()); |
| 9451 | TransformOperations start; |
| 9452 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 9453 | gfx::Transform transform; |
| 9454 | transform.Scale3d(1.0, 2.0, 3.0); |
| 9455 | TransformOperations operation; |
| 9456 | operation.AppendMatrix(transform); |
| 9457 | curve->AddKeyframe( |
| 9458 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 9459 | curve->AddKeyframe(TransformKeyframe::Create( |
| 9460 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
| 9461 | std::unique_ptr<Animation> animation( |
| 9462 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 9463 | animation->set_fill_mode(Animation::FillMode::NONE); |
| 9464 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 9465 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9466 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 9467 | std::move(animation)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9468 | |
| 9469 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9470 | |
| 9471 | TransformTree& tree = |
| 9472 | root->layer_tree_host()->property_trees()->transform_tree; |
| 9473 | TransformNode* node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9474 | EXPECT_FALSE(node->is_currently_animating); |
| 9475 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9476 | |
| 9477 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
| 9478 | root->layer_tree_host()->AnimateLayers( |
| 9479 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 9480 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9481 | EXPECT_TRUE(node->is_currently_animating); |
| 9482 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9483 | |
| 9484 | player->AbortAnimations(TargetProperty::TRANSFORM, |
| 9485 | false /*needs_completion*/); |
| 9486 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9487 | EXPECT_FALSE(node->is_currently_animating); |
| 9488 | EXPECT_FALSE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9489 | } |
| 9490 | |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 9491 | TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) { |
| 9492 | LayerTreeHostCommon::ScrollUpdateInfo scroll; |
| 9493 | scroll.layer_id = 2; |
| 9494 | scroll.scroll_delta = gfx::Vector2d(5, 10); |
| 9495 | |
| 9496 | proto::ScrollUpdateInfo proto; |
| 9497 | scroll.ToProtobuf(&proto); |
| 9498 | LayerTreeHostCommon::ScrollUpdateInfo new_scroll; |
| 9499 | new_scroll.FromProtobuf(proto); |
| 9500 | |
| 9501 | EXPECT_EQ(scroll, new_scroll); |
| 9502 | } |
| 9503 | |
| 9504 | TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) { |
| 9505 | ScrollAndScaleSet scroll_and_scale_set; |
| 9506 | |
| 9507 | LayerTreeHostCommon::ScrollUpdateInfo scroll1; |
| 9508 | scroll1.layer_id = 1; |
| 9509 | scroll1.scroll_delta = gfx::Vector2d(5, 10); |
| 9510 | LayerTreeHostCommon::ScrollUpdateInfo scroll2; |
| 9511 | scroll2.layer_id = 2; |
| 9512 | scroll2.scroll_delta = gfx::Vector2d(1, 5); |
| 9513 | scroll_and_scale_set.scrolls.push_back(scroll1); |
| 9514 | scroll_and_scale_set.scrolls.push_back(scroll2); |
| 9515 | |
| 9516 | scroll_and_scale_set.page_scale_delta = 0.3f; |
| 9517 | scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f); |
| 9518 | scroll_and_scale_set.top_controls_delta = 0.9f; |
| 9519 | |
| 9520 | proto::ScrollAndScaleSet proto; |
| 9521 | scroll_and_scale_set.ToProtobuf(&proto); |
| 9522 | ScrollAndScaleSet new_scroll_and_scale_set; |
| 9523 | new_scroll_and_scale_set.FromProtobuf(proto); |
| 9524 | |
| 9525 | EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); |
| 9526 | } |
| 9527 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9528 | TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 9529 | // Test the behavior of scroll tree builder |
| 9530 | // Topology: |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9531 | // +root1(1)[inner_viewport_container_layer] |
| 9532 | // +-page_scale_layer |
| 9533 | // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling & |
| 9534 | // scrollable, inner_viewport_scroll_layer] |
| 9535 | // +------child6(6)[kScrollbarScrolling] |
| 9536 | // +--------grand_child10(10)[kScrollbarScrolling] |
| 9537 | // +----parent3(3) |
| 9538 | // +------child7(7)[scrollable] |
| 9539 | // +------child8(8)[scroll_parent=7] |
| 9540 | // +--------grand_child11(11)[scrollable] |
| 9541 | // +----parent4(4) |
| 9542 | // +------child9(9) |
| 9543 | // +--------grand_child12(12) |
| 9544 | // +----parent5(5)[contains_non_fast_scrollable_region] |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9545 | // |
| 9546 | // Expected scroll tree topology: |
| 9547 | // +property_tree_root---owner:-1 |
| 9548 | // +--root---owner:1, id:1 |
| 9549 | // +----node---owner:2, id:2 |
| 9550 | // +------node---owner:6, id:3 |
| 9551 | // +----node---owner:7, id:4 |
| 9552 | // +------node---owner:11, id:5 |
| 9553 | // +----node---owner:5, id:6 |
| 9554 | // |
| 9555 | // Extra check: |
| 9556 | // scroll_tree_index() of: |
| 9557 | // grand_child10:3 |
| 9558 | // parent3:1 |
| 9559 | // child8:4 |
| 9560 | // parent4:1 |
| 9561 | // child9:1 |
| 9562 | // grand_child12:1 |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9563 | scoped_refptr<Layer> root1 = Layer::Create(); |
| 9564 | scoped_refptr<Layer> page_scale_layer = Layer::Create(); |
| 9565 | scoped_refptr<Layer> parent2 = Layer::Create(); |
| 9566 | scoped_refptr<Layer> parent3 = Layer::Create(); |
| 9567 | scoped_refptr<Layer> parent4 = Layer::Create(); |
| 9568 | scoped_refptr<Layer> parent5 = Layer::Create(); |
| 9569 | scoped_refptr<Layer> child6 = Layer::Create(); |
| 9570 | scoped_refptr<Layer> child7 = Layer::Create(); |
| 9571 | scoped_refptr<Layer> child8 = Layer::Create(); |
| 9572 | scoped_refptr<Layer> child9 = Layer::Create(); |
| 9573 | scoped_refptr<Layer> grand_child10 = Layer::Create(); |
| 9574 | scoped_refptr<Layer> grand_child11 = Layer::Create(); |
| 9575 | scoped_refptr<Layer> grand_child12 = Layer::Create(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9576 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9577 | root1->AddChild(page_scale_layer); |
| 9578 | page_scale_layer->AddChild(parent2); |
| 9579 | page_scale_layer->AddChild(parent3); |
| 9580 | page_scale_layer->AddChild(parent4); |
| 9581 | page_scale_layer->AddChild(parent5); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9582 | parent2->AddChild(child6); |
| 9583 | parent3->AddChild(child7); |
| 9584 | parent3->AddChild(child8); |
| 9585 | parent4->AddChild(child9); |
| 9586 | child6->AddChild(grand_child10); |
| 9587 | child8->AddChild(grand_child11); |
| 9588 | child9->AddChild(grand_child12); |
| 9589 | host()->SetRootLayer(root1); |
| 9590 | |
| 9591 | parent2->AddMainThreadScrollingReasons( |
| 9592 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9593 | parent2->AddMainThreadScrollingReasons( |
| 9594 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9595 | parent2->SetScrollClipLayerId(root1->id()); |
| 9596 | child6->AddMainThreadScrollingReasons( |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9597 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9598 | grand_child10->AddMainThreadScrollingReasons( |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9599 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9600 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9601 | child7->SetScrollClipLayerId(parent3->id()); |
| 9602 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9603 | child8->SetScrollParent(child7.get()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9604 | grand_child11->SetScrollClipLayerId(parent3->id()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9605 | |
| 9606 | parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9607 | parent5->SetBounds(gfx::Size(10, 10)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9608 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 9609 | host()->RegisterViewportLayers(nullptr, page_scale_layer, parent2, nullptr); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9610 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get()); |
| 9611 | |
| 9612 | const int kInvalidPropertyTreeNodeId = -1; |
| 9613 | const int kRootPropertyTreeNodeId = 0; |
| 9614 | |
| 9615 | // Property tree root |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9616 | ScrollTree& scroll_tree = host()->property_trees()->scroll_tree; |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 9617 | PropertyTrees property_trees; |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 9618 | property_trees.is_main_thread = true; |
| 9619 | property_trees.is_active = false; |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9620 | ScrollTree& expected_scroll_tree = property_trees.scroll_tree; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9621 | ScrollNode* property_tree_root = expected_scroll_tree.Node(0); |
| 9622 | property_tree_root->id = kRootPropertyTreeNodeId; |
| 9623 | property_tree_root->parent_id = kInvalidPropertyTreeNodeId; |
| 9624 | property_tree_root->owner_id = kInvalidPropertyTreeNodeId; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9625 | property_tree_root->scrollable = false; |
| 9626 | property_tree_root->main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9627 | MainThreadScrollingReason::kNotScrollingOnMain; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9628 | property_tree_root->contains_non_fast_scrollable_region = false; |
| 9629 | property_tree_root->transform_id = kRootPropertyTreeNodeId; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9630 | |
| 9631 | // The node owned by root1 |
| 9632 | ScrollNode scroll_root1; |
| 9633 | scroll_root1.id = 1; |
| 9634 | scroll_root1.owner_id = root1->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9635 | scroll_root1.user_scrollable_horizontal = true; |
| 9636 | scroll_root1.user_scrollable_vertical = true; |
| 9637 | scroll_root1.transform_id = root1->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9638 | expected_scroll_tree.Insert(scroll_root1, 0); |
| 9639 | |
| 9640 | // The node owned by parent2 |
| 9641 | ScrollNode scroll_parent2; |
| 9642 | scroll_parent2.id = 2; |
| 9643 | scroll_parent2.owner_id = parent2->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9644 | scroll_parent2.scrollable = true; |
| 9645 | scroll_parent2.main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9646 | parent2->main_thread_scrolling_reasons(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9647 | scroll_parent2.scroll_clip_layer_bounds = root1->bounds(); |
| 9648 | scroll_parent2.bounds = parent2->bounds(); |
| 9649 | scroll_parent2.max_scroll_offset_affected_by_page_scale = true; |
| 9650 | scroll_parent2.is_inner_viewport_scroll_layer = true; |
| 9651 | scroll_parent2.user_scrollable_horizontal = true; |
| 9652 | scroll_parent2.user_scrollable_vertical = true; |
| 9653 | scroll_parent2.transform_id = parent2->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9654 | expected_scroll_tree.Insert(scroll_parent2, 1); |
| 9655 | |
| 9656 | // The node owned by child6 |
| 9657 | ScrollNode scroll_child6; |
| 9658 | scroll_child6.id = 3; |
| 9659 | scroll_child6.owner_id = child6->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9660 | scroll_child6.main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9661 | child6->main_thread_scrolling_reasons(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9662 | scroll_child6.should_flatten = true; |
| 9663 | scroll_child6.user_scrollable_horizontal = true; |
| 9664 | scroll_child6.user_scrollable_vertical = true; |
| 9665 | scroll_child6.transform_id = child6->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9666 | expected_scroll_tree.Insert(scroll_child6, 2); |
| 9667 | |
| 9668 | // The node owned by child7, child7 also owns a transform node |
| 9669 | ScrollNode scroll_child7; |
| 9670 | scroll_child7.id = 4; |
| 9671 | scroll_child7.owner_id = child7->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9672 | scroll_child7.scrollable = true; |
| 9673 | scroll_child7.scroll_clip_layer_bounds = parent3->bounds(); |
| 9674 | scroll_child7.bounds = child7->bounds(); |
| 9675 | scroll_child7.user_scrollable_horizontal = true; |
| 9676 | scroll_child7.user_scrollable_vertical = true; |
| 9677 | scroll_child7.transform_id = child7->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9678 | expected_scroll_tree.Insert(scroll_child7, 1); |
| 9679 | |
| 9680 | // The node owned by grand_child11, grand_child11 also owns a transform node |
| 9681 | ScrollNode scroll_grand_child11; |
| 9682 | scroll_grand_child11.id = 5; |
| 9683 | scroll_grand_child11.owner_id = grand_child11->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9684 | scroll_grand_child11.scrollable = true; |
| 9685 | scroll_grand_child11.user_scrollable_horizontal = true; |
| 9686 | scroll_grand_child11.user_scrollable_vertical = true; |
| 9687 | scroll_grand_child11.transform_id = grand_child11->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9688 | expected_scroll_tree.Insert(scroll_grand_child11, 4); |
| 9689 | |
| 9690 | // The node owned by parent5 |
| 9691 | ScrollNode scroll_parent5; |
| 9692 | scroll_parent5.id = 8; |
| 9693 | scroll_parent5.owner_id = parent5->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9694 | scroll_parent5.contains_non_fast_scrollable_region = true; |
| 9695 | scroll_parent5.bounds = gfx::Size(10, 10); |
| 9696 | scroll_parent5.should_flatten = true; |
| 9697 | scroll_parent5.user_scrollable_horizontal = true; |
| 9698 | scroll_parent5.user_scrollable_vertical = true; |
| 9699 | scroll_parent5.transform_id = parent5->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9700 | expected_scroll_tree.Insert(scroll_parent5, 1); |
| 9701 | |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 9702 | expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0)); |
| 9703 | expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0)); |
| 9704 | expected_scroll_tree.SetScrollOffset(grand_child11->id(), |
| 9705 | gfx::ScrollOffset(0, 0)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9706 | expected_scroll_tree.set_needs_update(false); |
| 9707 | |
| 9708 | EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 9709 | |
| 9710 | // Check other layers' scroll_tree_index |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9711 | EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9712 | EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 9713 | EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 9714 | EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 9715 | EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 9716 | EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 9717 | EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 9718 | } |
| 9719 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 9720 | } // namespace |
| 9721 | } // namespace cc |