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 | 29f17bf | 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" |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 23 | #include "cc/layers/effect_tree_layer_list_iterator.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 24 | #include "cc/layers/layer.h" |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 25 | #include "cc/layers/layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 26 | #include "cc/layers/layer_impl.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] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 29 | #include "cc/test/animation_test_common.h" |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 30 | #include "cc/test/fake_content_layer_client.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 31 | #include "cc/test/fake_impl_task_runner_provider.h" |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 32 | #include "cc/test/fake_layer_tree_frame_sink.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 33 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 34 | #include "cc/test/fake_layer_tree_host_impl.h" |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 35 | #include "cc/test/fake_picture_layer.h" |
| 36 | #include "cc/test/fake_picture_layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 37 | #include "cc/test/geometry_test_utils.h" |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 38 | #include "cc/test/layer_test_common.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 39 | #include "cc/test/test_task_graph_runner.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 40 | #include "cc/trees/clip_node.h" |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 41 | #include "cc/trees/draw_property_utils.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 42 | #include "cc/trees/effect_node.h" |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 43 | #include "cc/trees/property_tree_builder.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 44 | #include "cc/trees/scroll_node.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 45 | #include "cc/trees/single_thread_proxy.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 46 | #include "cc/trees/task_runner_provider.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 47 | #include "cc/trees/transform_node.h" |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 48 | #include "components/viz/common/quads/copy_output_request.h" |
| 49 | #include "components/viz/common/quads/copy_output_result.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 50 | #include "testing/gtest/include/gtest/gtest.h" |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 51 | #include "third_party/skia/include/core/SkImageFilter.h" |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 52 | #include "third_party/skia/include/effects/SkOffsetImageFilter.h" |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 53 | #include "third_party/skia/include/effects/SkXfermodeImageFilter.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 54 | #include "ui/gfx/geometry/quad_f.h" |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 55 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 56 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 57 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 58 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 59 | namespace { |
| 60 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 61 | class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings { |
| 62 | public: |
| 63 | VerifyTreeCalcsLayerTreeSettings() { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 64 | } |
| 65 | }; |
| 66 | |
| 67 | class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { |
| 68 | public: |
| 69 | LayerTreeHostCommonTestBase() |
| 70 | : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {} |
| 71 | explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings) |
| 72 | : LayerTestCommon::LayerImplTest(settings) {} |
| 73 | |
| 74 | static void SetScrollOffsetDelta(LayerImpl* layer_impl, |
| 75 | const gfx::Vector2dF& delta) { |
| 76 | if (layer_impl->layer_tree_impl() |
| 77 | ->property_trees() |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 78 | ->scroll_tree.SetScrollOffsetDeltaForTesting( |
| 79 | layer_impl->element_id(), delta)) |
| 80 | layer_impl->layer_tree_impl()->DidUpdateScrollOffset( |
| 81 | layer_impl->element_id()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static float GetMaximumAnimationScale(LayerImpl* layer_impl) { |
| 85 | return layer_impl->layer_tree_impl() |
| 86 | ->property_trees() |
| 87 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 88 | layer_impl->layer_tree_impl()) |
| 89 | .maximum_animation_scale; |
| 90 | } |
| 91 | |
| 92 | static float GetStartingAnimationScale(LayerImpl* layer_impl) { |
| 93 | return layer_impl->layer_tree_impl() |
| 94 | ->property_trees() |
| 95 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 96 | layer_impl->layer_tree_impl()) |
| 97 | .starting_animation_scale; |
| 98 | } |
| 99 | |
| 100 | void ExecuteCalculateDrawProperties(Layer* root_layer, |
| 101 | float device_scale_factor, |
| 102 | float page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 103 | Layer* page_scale_layer, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 104 | Layer* inner_viewport_scroll_layer, |
| 105 | Layer* outer_viewport_scroll_layer) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 106 | EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 107 | gfx::Size device_viewport_size = |
| 108 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 109 | root_layer->bounds().height() * device_scale_factor); |
| 110 | |
| 111 | // We are probably not testing what is intended if the root_layer bounds are |
| 112 | // empty. |
| 113 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 114 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 115 | root_layer, device_viewport_size); |
| 116 | inputs.device_scale_factor = device_scale_factor; |
| 117 | inputs.page_scale_factor = page_scale_factor; |
| 118 | inputs.page_scale_layer = page_scale_layer; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 119 | inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 120 | inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 121 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 122 | } |
| 123 | |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 124 | void ExecuteCalculateDrawProperties(LayerImpl* root_layer, |
| 125 | float device_scale_factor, |
| 126 | float page_scale_factor, |
| 127 | LayerImpl* page_scale_layer, |
| 128 | LayerImpl* inner_viewport_scroll_layer, |
| 129 | LayerImpl* outer_viewport_scroll_layer) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 130 | if (device_scale_factor != |
| 131 | root_layer->layer_tree_impl()->device_scale_factor()) |
| 132 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 133 | |
| 134 | root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); |
| 135 | |
| 136 | EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 137 | |
| 138 | gfx::Size device_viewport_size = |
| 139 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 140 | root_layer->bounds().height() * device_scale_factor); |
| 141 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 142 | render_surface_list_impl_.reset(new RenderSurfaceList); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 143 | |
| 144 | // We are probably not testing what is intended if the root_layer bounds are |
| 145 | // empty. |
| 146 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 147 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 148 | root_layer, device_viewport_size, render_surface_list_impl_.get()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 149 | inputs.device_scale_factor = device_scale_factor; |
| 150 | inputs.page_scale_factor = page_scale_factor; |
| 151 | inputs.page_scale_layer = page_scale_layer; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 152 | inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 153 | inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 154 | inputs.can_adjust_raster_scales = true; |
| 155 | |
| 156 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 157 | } |
| 158 | |
| 159 | template <class LayerType> |
| 160 | void ExecuteCalculateDrawProperties(LayerType* root_layer) { |
| 161 | LayerType* page_scale_application_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 162 | LayerType* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 163 | LayerType* outer_viewport_scroll_layer = nullptr; |
| 164 | ExecuteCalculateDrawProperties( |
| 165 | root_layer, 1.f, 1.f, page_scale_application_layer, |
| 166 | inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | template <class LayerType> |
| 170 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 171 | float device_scale_factor) { |
| 172 | LayerType* page_scale_application_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 173 | LayerType* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 174 | LayerType* outer_viewport_scroll_layer = nullptr; |
| 175 | ExecuteCalculateDrawProperties( |
| 176 | root_layer, device_scale_factor, 1.f, page_scale_application_layer, |
| 177 | inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 178 | } |
| 179 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 180 | const LayerList* GetUpdateLayerList() { return &update_layer_list_; } |
| 181 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 182 | void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) { |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 183 | DCHECK(root_layer->layer_tree_host()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 184 | const Layer* page_scale_layer = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 185 | root_layer->layer_tree_host()->page_scale_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 186 | Layer* inner_viewport_scroll_layer = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 187 | root_layer->layer_tree_host()->inner_viewport_scroll_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 188 | Layer* outer_viewport_scroll_layer = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 189 | root_layer->layer_tree_host()->outer_viewport_scroll_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 190 | const Layer* overscroll_elasticity_layer = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 191 | root_layer->layer_tree_host()->overscroll_elasticity_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 192 | gfx::Vector2dF elastic_overscroll = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 193 | root_layer->layer_tree_host()->elastic_overscroll(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 194 | float page_scale_factor = 1.f; |
| 195 | float device_scale_factor = 1.f; |
| 196 | gfx::Size device_viewport_size = |
| 197 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 198 | root_layer->bounds().height() * device_scale_factor); |
| 199 | PropertyTrees* property_trees = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 200 | root_layer->layer_tree_host()->property_trees(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 201 | update_layer_list_.clear(); |
| 202 | PropertyTreeBuilder::BuildPropertyTrees( |
| 203 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 204 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 205 | elastic_overscroll, page_scale_factor, device_scale_factor, |
| 206 | gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
weiliangc | 1c0802c3 | 2017-03-21 19:53:17 | [diff] [blame] | 207 | draw_property_utils::UpdatePropertyTrees(root_layer->layer_tree_host(), |
danakj | dc24211f2 | 2017-05-09 18:58:25 | [diff] [blame] | 208 | property_trees); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 209 | draw_property_utils::FindLayersThatNeedUpdates( |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 210 | root_layer->layer_tree_host(), property_trees, &update_layer_list_); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 211 | } |
| 212 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 213 | void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 214 | LayerImpl* root_layer) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 215 | DCHECK(root_layer->layer_tree_impl()); |
reveman | b2b99a3b | 2017-04-06 23:39:08 | [diff] [blame] | 216 | bool can_adjust_raster_scales = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 217 | |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 218 | const LayerImpl* page_scale_layer = nullptr; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 219 | LayerImpl* inner_viewport_scroll_layer = |
| 220 | root_layer->layer_tree_impl()->InnerViewportScrollLayer(); |
| 221 | LayerImpl* outer_viewport_scroll_layer = |
| 222 | root_layer->layer_tree_impl()->OuterViewportScrollLayer(); |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 223 | const LayerImpl* overscroll_elasticity_layer = |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 224 | root_layer->layer_tree_impl()->OverscrollElasticityLayer(); |
| 225 | gfx::Vector2dF elastic_overscroll = |
| 226 | root_layer->layer_tree_impl()->elastic_overscroll()->Current( |
| 227 | root_layer->layer_tree_impl()->IsActiveTree()); |
| 228 | float page_scale_factor = 1.f; |
| 229 | float device_scale_factor = 1.f; |
| 230 | gfx::Size device_viewport_size = |
| 231 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 232 | root_layer->bounds().height() * device_scale_factor); |
| 233 | update_layer_list_impl_.reset(new LayerImplList); |
| 234 | root_layer->layer_tree_impl()->BuildLayerListForTesting(); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 235 | PropertyTrees* property_trees = |
| 236 | root_layer->layer_tree_impl()->property_trees(); |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 237 | PropertyTreeBuilder::BuildPropertyTrees( |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 238 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 239 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 240 | elastic_overscroll, page_scale_factor, device_scale_factor, |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 241 | gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
| 242 | draw_property_utils::UpdatePropertyTreesAndRenderSurfaces( |
danakj | dc24211f2 | 2017-05-09 18:58:25 | [diff] [blame] | 243 | root_layer, property_trees, can_adjust_raster_scales); |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 244 | draw_property_utils::FindLayersThatNeedUpdates( |
| 245 | root_layer->layer_tree_impl(), property_trees, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 246 | update_layer_list_impl_.get()); |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 247 | draw_property_utils::ComputeDrawPropertiesOfVisibleLayers( |
| 248 | update_layer_list_impl(), property_trees); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 249 | } |
| 250 | |
reveman | b2b99a3b | 2017-04-06 23:39:08 | [diff] [blame] | 251 | void ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales( |
| 252 | LayerImpl* root_layer) { |
| 253 | gfx::Size device_viewport_size = |
| 254 | gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 255 | render_surface_list_impl_.reset(new RenderSurfaceList); |
reveman | b2b99a3b | 2017-04-06 23:39:08 | [diff] [blame] | 256 | |
| 257 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 258 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 259 | root_layer, device_viewport_size, render_surface_list_impl_.get()); |
reveman | b2b99a3b | 2017-04-06 23:39:08 | [diff] [blame] | 260 | inputs.can_adjust_raster_scales = false; |
| 261 | |
| 262 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 263 | } |
| 264 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 265 | bool UpdateLayerListImplContains(int id) const { |
| 266 | for (auto* layer : *update_layer_list_impl_) { |
| 267 | if (layer->id() == id) |
| 268 | return true; |
| 269 | } |
| 270 | return false; |
| 271 | } |
| 272 | |
| 273 | bool UpdateLayerListContains(int id) const { |
| 274 | for (const auto& layer : update_layer_list_) { |
| 275 | if (layer->id() == id) |
| 276 | return true; |
| 277 | } |
| 278 | return false; |
| 279 | } |
| 280 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 281 | const RenderSurfaceList* render_surface_list_impl() const { |
| 282 | return render_surface_list_impl_.get(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 283 | } |
| 284 | const LayerImplList* update_layer_list_impl() const { |
| 285 | return update_layer_list_impl_.get(); |
| 286 | } |
| 287 | const LayerList& update_layer_list() const { return update_layer_list_; } |
| 288 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 289 | bool VerifyLayerInList(scoped_refptr<Layer> layer, |
| 290 | const LayerList* layer_list) { |
| 291 | return std::find(layer_list->begin(), layer_list->end(), layer) != |
| 292 | layer_list->end(); |
| 293 | } |
| 294 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 295 | private: |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 296 | std::unique_ptr<RenderSurfaceList> render_surface_list_impl_; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 297 | LayerList update_layer_list_; |
| 298 | std::unique_ptr<LayerImplList> update_layer_list_impl_; |
| 299 | }; |
| 300 | |
| 301 | class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase, |
| 302 | public testing::Test {}; |
| 303 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 304 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 305 | public: |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 306 | LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 307 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 308 | bool DrawsContent() const override { return true; } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 309 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 310 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 311 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 312 | }; |
| 313 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 314 | class LayerTreeSettingsScaleContent : public VerifyTreeCalcsLayerTreeSettings { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 315 | public: |
| 316 | LayerTreeSettingsScaleContent() { |
| 317 | layer_transforms_should_scale_layer_contents = true; |
| 318 | } |
| 319 | }; |
| 320 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 321 | class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTestBase, |
| 322 | public testing::Test { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 323 | public: |
| 324 | LayerTreeHostCommonScalingTest() |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 325 | : LayerTreeHostCommonTestBase(LayerTreeSettingsScaleContent()) {} |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 326 | }; |
| 327 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 328 | class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest { |
| 329 | public: |
| 330 | LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {} |
| 331 | |
| 332 | LayerImpl* TestVisibleRectAndDrawableContentRect( |
| 333 | const gfx::Rect& target_rect, |
| 334 | const gfx::Transform& layer_transform, |
| 335 | const gfx::Rect& layer_rect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 336 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 337 | LayerImpl* target = AddChild<LayerImpl>(root); |
| 338 | LayerImpl* drawing_layer = AddChild<LayerImpl>(target); |
| 339 | |
| 340 | root->SetDrawsContent(true); |
| 341 | target->SetDrawsContent(true); |
| 342 | target->SetMasksToBounds(true); |
| 343 | drawing_layer->SetDrawsContent(true); |
| 344 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 345 | root->SetBounds(gfx::Size(500, 500)); |
| 346 | root->test_properties()->force_render_surface = true; |
| 347 | target->SetPosition(gfx::PointF(target_rect.origin())); |
| 348 | target->SetBounds(target_rect.size()); |
| 349 | target->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 350 | drawing_layer->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 351 | drawing_layer->SetPosition(gfx::PointF(layer_rect.origin())); |
| 352 | drawing_layer->SetBounds(layer_rect.size()); |
| 353 | drawing_layer->test_properties()->should_flatten_transform = false; |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 354 | |
| 355 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 356 | ExecuteCalculateDrawProperties(root); |
| 357 | |
| 358 | return drawing_layer; |
| 359 | } |
| 360 | }; |
| 361 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 362 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 363 | // Sanity check: For layers positioned at zero, with zero size, |
| 364 | // and with identity transforms, then the draw transform, |
| 365 | // screen space transform, and the hierarchy passed on to children |
| 366 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 367 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 368 | LayerImpl* parent = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 369 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 370 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 371 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 372 | parent->SetBounds(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 373 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 374 | ExecuteCalculateDrawProperties(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 375 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 376 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 377 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 378 | child->ScreenSpaceTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 379 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 380 | grand_child->DrawTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 381 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 382 | grand_child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 383 | } |
| 384 | |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 385 | TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) { |
| 386 | // Tests that effect tree node gets a valid transform id when a layer |
| 387 | // has opacity but doesn't create a render surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 388 | LayerImpl* parent = root_layer_for_testing(); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 389 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 390 | child->SetDrawsContent(true); |
| 391 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 392 | parent->SetBounds(gfx::Size(100, 100)); |
| 393 | child->SetPosition(gfx::PointF(10, 10)); |
| 394 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 395 | child->test_properties()->opacity = 0.f; |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 396 | ExecuteCalculateDrawProperties(parent); |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 397 | EffectTree& effect_tree = |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 398 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 399 | EffectNode* node = effect_tree.Node(child->effect_tree_index()); |
| 400 | const int transform_tree_size = parent->layer_tree_impl() |
| 401 | ->property_trees() |
| 402 | ->transform_tree.next_available_id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 403 | EXPECT_LT(node->transform_id, transform_tree_size); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 404 | } |
| 405 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 406 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 407 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 408 | LayerImpl* layer = AddChild<LayerImpl>(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 409 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 410 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 411 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 412 | EffectTree& effect_tree = |
| 413 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 414 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 415 | root->SetBounds(gfx::Size(1, 2)); |
| 416 | |
| 417 | // 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] | 418 | // transform or the screenspace transform. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 419 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 420 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 421 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 422 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 423 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 424 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 425 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 426 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 427 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 428 | // Case 2: The anchor point by itself (without a layer transform) should have |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 429 | // no effect on the transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 430 | layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 431 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 432 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 433 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 434 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 435 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 436 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 437 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 438 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 439 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 440 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 441 | // Case 3: A change in actual position affects both the draw transform and |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 442 | // screen space transform. |
| 443 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 444 | position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 445 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 446 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 447 | ExecuteCalculateDrawProperties(root); |
| 448 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 449 | position_transform, |
| 450 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 451 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 452 | position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 453 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 454 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 455 | // Case 4: In the correct sequence of transforms, the layer transform should |
| 456 | // pre-multiply the translation-to-center. This is easily tested by using a |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 457 | // scale transform, because scale and translation are not commutative. |
| 458 | gfx::Transform layer_transform; |
| 459 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 460 | layer->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 461 | layer->test_properties()->transform_origin = gfx::Point3F(); |
| 462 | layer->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 463 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 464 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 465 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 466 | layer_transform, |
| 467 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 468 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 469 | layer_transform, |
| 470 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 471 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 472 | // Case 5: The layer transform should occur with respect to the anchor point. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 473 | gfx::Transform translation_to_anchor; |
| 474 | translation_to_anchor.Translate(5.0, 0.0); |
| 475 | gfx::Transform expected_result = |
| 476 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 477 | layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 478 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 479 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 480 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 481 | expected_result, |
| 482 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
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::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 486 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 487 | // Case 6: Verify that position pre-multiplies the layer transform. The |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 488 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 489 | // it is still worth testing to detect accidental regressions. |
| 490 | expected_result = position_transform * translation_to_anchor * |
| 491 | layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 492 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 493 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 494 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 495 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 496 | expected_result, |
| 497 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 498 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 499 | expected_result, |
| 500 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 501 | } |
| 502 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 503 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 504 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 505 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 506 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 507 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 508 | -kScrollOffset.y()); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 509 | float page_scale = 0.888f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 510 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 511 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 512 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 513 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 514 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 515 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 516 | std::unique_ptr<LayerImpl> sublayer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 517 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 518 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 519 | sublayer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 520 | sublayer->SetBounds(gfx::Size(500, 500)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 521 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 522 | std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 523 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 524 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 525 | scroll_layer->SetBounds(gfx::Size(10, 20)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 526 | |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 527 | scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id())); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 528 | scroll_layer->SetScrollable( |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 529 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 530 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
Philip Rogers | 4131a1c1 | 2017-07-21 19:36:50 | [diff] [blame] | 531 | SetScrollOffsetDelta(scroll_layer, kScrollDelta); |
| 532 | gfx::Transform impl_transform; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 533 | scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr)); |
Philip Rogers | 4131a1c1 | 2017-07-21 19:36:50 | [diff] [blame] | 534 | scroll_layer_scoped_ptr->layer_tree_impl() |
| 535 | ->property_trees() |
| 536 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 537 | scroll_layer_scoped_ptr->element_id(), kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 538 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 539 | std::unique_ptr<LayerImpl> root( |
| 540 | LayerImpl::Create(host_impl.active_tree(), 3)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 541 | root->SetBounds(gfx::Size(3, 4)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 542 | root->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 543 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 544 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 545 | |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 546 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 547 | scroll_layer->test_properties()->parent, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 548 | nullptr, nullptr); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 549 | gfx::Transform expected_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 550 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 551 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 552 | page_scale * kDeviceScale), |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 553 | MathUtil::Round(sub_layer_screen_position.y() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 554 | page_scale * kDeviceScale)); |
| 555 | expected_transform.Scale(page_scale * kDeviceScale, |
| 556 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 557 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 558 | sublayer->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 559 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 560 | sublayer->ScreenSpaceTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 561 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 562 | gfx::Transform arbitrary_translate; |
| 563 | const float kTranslateX = 10.6f; |
| 564 | const float kTranslateY = 20.6f; |
| 565 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 566 | scroll_layer->test_properties()->transform = arbitrary_translate; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 567 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 568 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 569 | scroll_layer->test_properties()->parent, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 570 | nullptr, nullptr); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 571 | expected_transform.MakeIdentity(); |
| 572 | expected_transform.Translate( |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 573 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 574 | sub_layer_screen_position.x() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 575 | kDeviceScale), |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 576 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 577 | sub_layer_screen_position.y() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 578 | kDeviceScale)); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 579 | expected_transform.Scale(page_scale * kDeviceScale, |
| 580 | page_scale * kDeviceScale); |
| 581 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 582 | sublayer->DrawTransform()); |
| 583 | |
| 584 | // Test that page scale is updated even when we don't rebuild property trees. |
| 585 | page_scale = 1.888f; |
pdr | 53abb45 | 2017-05-19 01:59:42 | [diff] [blame] | 586 | |
| 587 | LayerTreeImpl::ViewportLayerIds viewport_ids; |
| 588 | viewport_ids.page_scale = scroll_layer->test_properties()->parent->id(); |
| 589 | root_layer->layer_tree_impl()->SetViewportLayersFromIds(viewport_ids); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 590 | root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 591 | EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 592 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 593 | scroll_layer->test_properties()->parent, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 594 | nullptr, nullptr); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 595 | |
| 596 | expected_transform.MakeIdentity(); |
| 597 | expected_transform.Translate( |
| 598 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 599 | sub_layer_screen_position.x() * page_scale * |
| 600 | kDeviceScale), |
| 601 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 602 | sub_layer_screen_position.y() * page_scale * |
| 603 | kDeviceScale)); |
| 604 | expected_transform.Scale(page_scale * kDeviceScale, |
| 605 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 606 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 607 | sublayer->DrawTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 608 | } |
| 609 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 610 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 611 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 612 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 613 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 614 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 615 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 616 | // One-time setup of root layer |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 617 | root->SetBounds(gfx::Size(1, 2)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 618 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 619 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 620 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 621 | EffectTree& effect_tree = |
| 622 | host_impl()->active_tree()->property_trees()->effect_tree; |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 623 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 624 | // Case 1: parent's anchor point should not affect child or grand_child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 625 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 626 | parent->SetBounds(gfx::Size(10, 12)); |
| 627 | child->SetBounds(gfx::Size(16, 18)); |
| 628 | grand_child->SetBounds(gfx::Size(76, 78)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 629 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 630 | |
| 631 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 632 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 633 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 634 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 635 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 636 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 637 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 638 | gfx::Transform(), draw_property_utils::DrawTransform( |
| 639 | grand_child, transform_tree, effect_tree)); |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 640 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 641 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 642 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 643 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 644 | // Case 2: parent's position affects child and grand_child. |
| 645 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 646 | parent_position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 647 | parent->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 648 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 649 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 650 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 651 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 652 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 653 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 654 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 655 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 656 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 657 | parent_position_transform, draw_property_utils::DrawTransform( |
| 658 | grand_child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 659 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 660 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 661 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 662 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 663 | // Case 3: parent's local transform affects child and grandchild |
| 664 | gfx::Transform parent_layer_transform; |
| 665 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 666 | gfx::Transform parent_translation_to_anchor; |
| 667 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 668 | gfx::Transform parent_composite_transform = |
| 669 | parent_translation_to_anchor * parent_layer_transform * |
| 670 | Inverse(parent_translation_to_anchor); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 671 | parent->test_properties()->transform = parent_layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 672 | parent->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 673 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 674 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 675 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 676 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 677 | draw_property_utils::DrawTransform(child, transform_tree, 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(child, transform_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 681 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 682 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 683 | draw_property_utils::DrawTransform(grand_child, transform_tree, |
| 684 | effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 685 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 686 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 687 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 688 | } |
| 689 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 690 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 691 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 692 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 693 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 694 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 695 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 696 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 697 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 698 | gfx::Transform parent_translation_to_anchor; |
| 699 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 700 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 701 | gfx::Transform parent_composite_transform = |
| 702 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 703 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 704 | gfx::Vector2dF parent_composite_scale = |
| 705 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 706 | 1.f); |
| 707 | gfx::Transform surface_sublayer_transform; |
| 708 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 709 | parent_composite_scale.y()); |
| 710 | gfx::Transform surface_sublayer_composite_transform = |
| 711 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 712 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 713 | root->SetBounds(gfx::Size(1, 2)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 714 | parent->test_properties()->transform = parent_layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 715 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f); |
| 716 | parent->SetBounds(gfx::Size(100, 120)); |
| 717 | child->SetBounds(gfx::Size(16, 18)); |
| 718 | child->test_properties()->force_render_surface = true; |
| 719 | grand_child->SetBounds(gfx::Size(8, 10)); |
| 720 | grand_child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 721 | ExecuteCalculateDrawProperties(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 722 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 723 | // Render surface should have been created now. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 724 | ASSERT_TRUE(GetRenderSurface(child)); |
| 725 | ASSERT_EQ(GetRenderSurface(child), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 726 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 727 | // The child layer's draw transform should refer to its new render surface. |
| 728 | // The screen-space transform, however, should still refer to the root. |
| 729 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 730 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 731 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 732 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 733 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 734 | // Because the grand_child is the only drawable content, the child's render |
| 735 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 736 | // surface's subtree is drawn must be removed from the composite transform. |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 737 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, |
| 738 | child->render_target()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 739 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 740 | // The screen space is the same as the target since the child surface draws |
| 741 | // into the root. |
| 742 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 743 | surface_sublayer_composite_transform, |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 744 | child->render_target()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 745 | } |
| 746 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 747 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 748 | // This test creates a more complex tree and verifies it all at once. This |
| 749 | // covers the following cases: |
| 750 | // - layers that are described w.r.t. a render surface: should have draw |
| 751 | // transforms described w.r.t. that surface |
| 752 | // - A render surface described w.r.t. an ancestor render surface: should |
| 753 | // have a draw transform described w.r.t. that ancestor surface |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 754 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 755 | // a render surface that is described w.r.t. an ancestor render surface. |
| 756 | // - verifying that each layer has a reference to the correct render surface |
| 757 | // and render target values. |
| 758 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 759 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 760 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 761 | parent->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 762 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 763 | render_surface1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 764 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 765 | render_surface2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 766 | LayerImpl* child_of_root = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 767 | child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 768 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 769 | child_of_rs1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 770 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 771 | child_of_rs2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 772 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 773 | grand_child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 774 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 775 | grand_child_of_rs1->SetDrawsContent(true); |
| 776 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 777 | grand_child_of_rs2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 778 | |
| 779 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 780 | // to have a new render surface. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 781 | render_surface1->test_properties()->opacity = 0.5f; |
| 782 | render_surface2->test_properties()->opacity = 0.33f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 783 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 784 | // All layers in the tree are initialized with an anchor at .25 and a size of |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 785 | // (10,10). Matrix "A" is the composite layer transform used in all layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 786 | gfx::Transform translation_to_anchor; |
| 787 | translation_to_anchor.Translate(2.5, 0.0); |
| 788 | gfx::Transform layer_transform; |
| 789 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 790 | |
| 791 | gfx::Transform A = |
| 792 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 793 | |
| 794 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 795 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 796 | gfx::Transform surface1_sublayer_transform; |
| 797 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 798 | surface1_parent_transform_scale.y()); |
| 799 | |
| 800 | // SS1 = transform given to the subtree of render_surface1 |
| 801 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 802 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 803 | // the owning layer |
| 804 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 805 | |
| 806 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 807 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 808 | gfx::Transform surface2_sublayer_transform; |
| 809 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 810 | surface2_parent_transform_scale.y()); |
| 811 | |
| 812 | // SS2 = transform given to the subtree of render_surface2 |
| 813 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 814 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 815 | // the owning layer |
| 816 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 817 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 818 | root->SetBounds(gfx::Size(1, 2)); |
| 819 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 820 | parent->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 821 | parent->SetBounds(gfx::Size(10, 10)); |
| 822 | render_surface1->test_properties()->transform_origin = |
| 823 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 824 | render_surface1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 825 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 826 | render_surface1->test_properties()->force_render_surface = true; |
| 827 | render_surface2->test_properties()->transform_origin = |
| 828 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 829 | render_surface2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 830 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 831 | render_surface2->test_properties()->force_render_surface = true; |
| 832 | child_of_root->test_properties()->transform_origin = |
| 833 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 834 | child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 835 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 836 | child_of_rs1->test_properties()->transform_origin = |
| 837 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 838 | child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 839 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 840 | child_of_rs2->test_properties()->transform_origin = |
| 841 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 842 | child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 843 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 844 | grand_child_of_root->test_properties()->transform_origin = |
| 845 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 846 | grand_child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 847 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 848 | grand_child_of_rs1->test_properties()->transform_origin = |
| 849 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 850 | grand_child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 851 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 852 | grand_child_of_rs2->test_properties()->transform_origin = |
| 853 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 854 | grand_child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 855 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 856 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 857 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 858 | |
| 859 | // Only layers that are associated with render surfaces should have an actual |
| 860 | // RenderSurface() value. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 861 | ASSERT_TRUE(GetRenderSurface(root)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 862 | ASSERT_EQ(GetRenderSurface(child_of_root), GetRenderSurface(root)); |
| 863 | ASSERT_EQ(GetRenderSurface(grand_child_of_root), GetRenderSurface(root)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 864 | |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 865 | ASSERT_NE(GetRenderSurface(render_surface1), GetRenderSurface(root)); |
| 866 | ASSERT_EQ(GetRenderSurface(child_of_rs1), GetRenderSurface(render_surface1)); |
| 867 | ASSERT_EQ(GetRenderSurface(grand_child_of_rs1), |
| 868 | GetRenderSurface(render_surface1)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 869 | |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 870 | ASSERT_NE(GetRenderSurface(render_surface2), GetRenderSurface(root)); |
| 871 | ASSERT_NE(GetRenderSurface(render_surface2), |
| 872 | GetRenderSurface(render_surface1)); |
| 873 | ASSERT_EQ(GetRenderSurface(child_of_rs2), GetRenderSurface(render_surface2)); |
| 874 | ASSERT_EQ(GetRenderSurface(grand_child_of_rs2), |
| 875 | GetRenderSurface(render_surface2)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 876 | |
| 877 | // Verify all render target accessors |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 878 | EXPECT_EQ(GetRenderSurface(root), parent->render_target()); |
| 879 | EXPECT_EQ(GetRenderSurface(root), child_of_root->render_target()); |
| 880 | EXPECT_EQ(GetRenderSurface(root), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 881 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 882 | EXPECT_EQ(GetRenderSurface(render_surface1), |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 883 | render_surface1->render_target()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 884 | EXPECT_EQ(GetRenderSurface(render_surface1), child_of_rs1->render_target()); |
| 885 | EXPECT_EQ(GetRenderSurface(render_surface1), |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 886 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 887 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 888 | EXPECT_EQ(GetRenderSurface(render_surface2), |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 889 | render_surface2->render_target()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 890 | EXPECT_EQ(GetRenderSurface(render_surface2), child_of_rs2->render_target()); |
| 891 | EXPECT_EQ(GetRenderSurface(render_surface2), |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 892 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 893 | |
| 894 | // Verify layer draw transforms note that draw transforms are described with |
| 895 | // respect to the nearest ancestor render surface but screen space transforms |
| 896 | // are described with respect to the root. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 897 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform()); |
| 898 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 899 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 900 | grand_child_of_root->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 901 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 902 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform()); |
| 903 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 904 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 905 | grand_child_of_rs1->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 906 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 907 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform()); |
| 908 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 909 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 910 | grand_child_of_rs2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 911 | |
| 912 | // Verify layer screen-space transforms |
| 913 | // |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 914 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform()); |
| 915 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform()); |
| 916 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
| 917 | grand_child_of_root->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 918 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 919 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 920 | render_surface1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 921 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 922 | child_of_rs1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 923 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 924 | grand_child_of_rs1->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 925 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 926 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 927 | render_surface2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 928 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 929 | child_of_rs2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 930 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 931 | grand_child_of_rs2->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 932 | |
| 933 | // Verify render surface transforms. |
| 934 | // |
| 935 | // Draw transform of render surface 1 is described with respect to root. |
| 936 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 937 | A * A * S1, GetRenderSurface(render_surface1)->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 938 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 939 | A * A * S1, GetRenderSurface(render_surface1)->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 940 | // Draw transform of render surface 2 is described with respect to render |
| 941 | // surface 1. |
| 942 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 943 | SS1 * A * S2, GetRenderSurface(render_surface2)->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 944 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 945 | A * A * A * S2, |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 946 | GetRenderSurface(render_surface2)->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 947 | |
| 948 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 949 | // is expected that we correctly set up transforms so that the y-component of |
| 950 | // the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 951 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 952 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 953 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 954 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 955 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 956 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 957 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 958 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 959 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 960 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 961 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 962 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 963 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 964 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 965 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 966 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 967 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 968 | } |
| 969 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 970 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 971 | // For layers that flatten their subtree, there should be an orthographic |
| 972 | // projection (for x and y values) in the middle of the transform sequence. |
| 973 | // Note that the way the code is currently implemented, it is not expected to |
| 974 | // use a canonical orthographic projection. |
| 975 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 976 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 977 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 978 | child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 979 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 980 | grand_child->SetDrawsContent(true); |
| 981 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 982 | great_grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 983 | |
| 984 | gfx::Transform rotation_about_y_axis; |
| 985 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 986 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 987 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 988 | child->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 989 | child->SetBounds(gfx::Size(10, 10)); |
| 990 | child->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 991 | grand_child->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 992 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 993 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 994 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 995 | // No layers in this test should preserve 3d. |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 996 | ASSERT_TRUE(root->test_properties()->should_flatten_transform); |
| 997 | ASSERT_TRUE(child->test_properties()->should_flatten_transform); |
| 998 | ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform); |
| 999 | ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1000 | |
| 1001 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1002 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1003 | gfx::Transform expected_grand_child_draw_transform = |
| 1004 | rotation_about_y_axis; // draws onto child's render surface |
| 1005 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1006 | flattened_rotation_about_y.FlattenTo2d(); |
| 1007 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1008 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1009 | gfx::Transform expected_great_grand_child_draw_transform = |
| 1010 | flattened_rotation_about_y; |
| 1011 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 1012 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1013 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1014 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1015 | |
| 1016 | // The child's draw transform should have been taken by its surface. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1017 | ASSERT_TRUE(GetRenderSurface(child)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1018 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1019 | GetRenderSurface(child)->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1020 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1021 | expected_child_screen_space_transform, |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1022 | GetRenderSurface(child)->screen_space_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1023 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1024 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1025 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1026 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1027 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1028 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1029 | grand_child->ScreenSpaceTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1030 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1031 | great_grand_child->DrawTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1032 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1033 | expected_great_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1034 | great_grand_child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1035 | } |
| 1036 | |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1037 | TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1038 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1039 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1040 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1041 | |
| 1042 | gfx::Transform child_transform; |
| 1043 | child_transform.Translate(50.0, 50.0); |
| 1044 | child_transform.RotateAboutZAxis(30.0); |
| 1045 | |
| 1046 | gfx::Transform grand_child_transform; |
| 1047 | grand_child_transform.RotateAboutYAxis(90.0); |
| 1048 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1049 | root->SetBounds(gfx::Size(200, 200)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1050 | child->test_properties()->transform = child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1051 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1052 | grand_child->test_properties()->transform = grand_child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1053 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1054 | grand_child->test_properties()->should_flatten_transform = false; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1055 | grand_child->SetDrawsContent(true); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1056 | float device_scale_factor = 1.f; |
| 1057 | float page_scale_factor = 1.f; |
| 1058 | LayerImpl* page_scale_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 1059 | LayerImpl* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 1060 | LayerImpl* outer_viewport_scroll_layer = nullptr; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1061 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 1062 | page_scale_layer, inner_viewport_scroll_layer, |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 1063 | outer_viewport_scroll_layer); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1064 | |
petermayo | 9711f03 | 2017-03-30 19:17:26 | [diff] [blame] | 1065 | // Mapping grand_child's bounds to screen space produces an empty rect, but |
| 1066 | // only because it is turned sideways. The entire rect is contained inside |
| 1067 | // the clip, and is only empty so long as the numerical precision of the |
| 1068 | // transform is effectively perfect. Currently we do the calculation the |
| 1069 | // other way around, and the Projection of the screen space clip into layer |
| 1070 | // space includes the entire bounds. |
| 1071 | EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
| 1072 | grand_child->visible_layer_rect()); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1073 | } |
| 1074 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1075 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1076 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1077 | // skipping a necessary translation. Without that translation, the coordinate |
| 1078 | // space of the layer's draw transform is incorrect. |
| 1079 | // |
| 1080 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1081 | // but if that layer becomes a render surface, then its draw transform is |
| 1082 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1083 | // incorrectly as a result. |
| 1084 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1085 | LayerImpl* root = root_layer_for_testing(); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1086 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1087 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1088 | grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1089 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1090 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1091 | // The child height is zero, but has non-zero width that should be accounted |
| 1092 | // for while computing draw transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1093 | child->SetBounds(gfx::Size(10, 0)); |
| 1094 | child->test_properties()->force_render_surface = true; |
| 1095 | grand_child->SetBounds(gfx::Size(10, 10)); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1096 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1097 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1098 | ASSERT_TRUE(GetRenderSurface(child)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1099 | // This is the real test, the rest are sanity checks. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1100 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1101 | GetRenderSurface(child)->draw_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1102 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1103 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1104 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1105 | } |
| 1106 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1107 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1108 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1109 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 1110 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 1111 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1112 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1113 | gfx::Transform translate; |
| 1114 | translate.Translate3d(5, 5, 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1115 | |
| 1116 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1117 | render_surface->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1118 | render_surface->SetBounds(gfx::Size(100, 100)); |
| 1119 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1120 | child->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1121 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1122 | grand_child->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1123 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1124 | grand_child->SetDrawsContent(true); |
| 1125 | |
| 1126 | // render_surface will have a sublayer scale because of device scale factor. |
| 1127 | float device_scale_factor = 2.0f; |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1128 | RenderSurfaceList render_surface_list_impl; |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1129 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1130 | root, root->bounds(), translate, &render_surface_list_impl); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1131 | inputs.device_scale_factor = device_scale_factor; |
| 1132 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1133 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1134 | |
| 1135 | // Between grand_child and render_surface, we translate by (10, 10) and scale |
| 1136 | // by a factor of 2. |
| 1137 | gfx::Vector2dF expected_translation(20.0f, 20.0f); |
| 1138 | EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(), |
| 1139 | expected_translation); |
| 1140 | } |
| 1141 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1142 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1143 | // Transformations applied at the root of the tree should be forwarded |
| 1144 | // to child layers instead of applied to the root RenderSurface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1145 | LayerImpl* root = root_layer_for_testing(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1146 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1147 | |
| 1148 | root->SetDrawsContent(true); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1149 | root->SetBounds(gfx::Size(100, 100)); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1150 | child->SetDrawsContent(true); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1151 | child->SetBounds(gfx::Size(100, 100)); |
| 1152 | child->SetMasksToBounds(true); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1153 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1154 | gfx::Transform translate; |
| 1155 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1156 | { |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1157 | RenderSurfaceList render_surface_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1158 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1159 | root, root->bounds(), translate, &render_surface_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1160 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1161 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1162 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1163 | translate, root->draw_properties().target_space_transform); |
| 1164 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1165 | translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1166 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1167 | GetRenderSurface(root)->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1168 | EXPECT_TRANSFORMATION_MATRIX_EQ(translate, child->ScreenSpaceTransform()); |
| 1169 | EXPECT_EQ(gfx::Rect(50, 50, 100, 100), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1170 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1171 | |
| 1172 | gfx::Transform scale; |
| 1173 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1174 | { |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1175 | RenderSurfaceList render_surface_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1176 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1177 | root, root->bounds(), scale, &render_surface_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1178 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1179 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1180 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1181 | scale, root->draw_properties().target_space_transform); |
| 1182 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1183 | scale, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1184 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1185 | GetRenderSurface(root)->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1186 | EXPECT_TRANSFORMATION_MATRIX_EQ(scale, child->ScreenSpaceTransform()); |
| 1187 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1188 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1189 | |
| 1190 | gfx::Transform rotate; |
| 1191 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1192 | { |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1193 | RenderSurfaceList render_surface_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1194 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1195 | root, root->bounds(), rotate, &render_surface_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1196 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1197 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1198 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1199 | rotate, root->draw_properties().target_space_transform); |
| 1200 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1201 | rotate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1202 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1203 | GetRenderSurface(root)->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1204 | EXPECT_TRANSFORMATION_MATRIX_EQ(rotate, child->ScreenSpaceTransform()); |
| 1205 | EXPECT_EQ(gfx::Rect(-4, 0, 104, 104), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1206 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1207 | |
| 1208 | gfx::Transform composite; |
| 1209 | composite.ConcatTransform(translate); |
| 1210 | composite.ConcatTransform(scale); |
| 1211 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1212 | { |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1213 | RenderSurfaceList render_surface_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1214 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1215 | root, root->bounds(), composite, &render_surface_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1216 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1217 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1218 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1219 | composite, root->draw_properties().target_space_transform); |
| 1220 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1221 | composite, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1222 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1223 | GetRenderSurface(root)->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1224 | EXPECT_TRANSFORMATION_MATRIX_EQ(composite, child->ScreenSpaceTransform()); |
| 1225 | EXPECT_EQ(gfx::Rect(89, 103, 208, 208), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1226 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1227 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1228 | // Verify it composes correctly with device scale. |
| 1229 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1230 | |
| 1231 | { |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1232 | RenderSurfaceList render_surface_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1233 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1234 | root, root->bounds(), translate, &render_surface_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1235 | inputs.device_scale_factor = device_scale_factor; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1236 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1237 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1238 | gfx::Transform device_scaled_translate = translate; |
jaydasika | 18ea272 | 2016-10-27 23:47:10 | [diff] [blame] | 1239 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1240 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1241 | device_scaled_translate, |
| 1242 | root->draw_properties().target_space_transform); |
| 1243 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1244 | device_scaled_translate, |
| 1245 | child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1246 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1247 | GetRenderSurface(root)->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1248 | EXPECT_TRANSFORMATION_MATRIX_EQ(device_scaled_translate, |
| 1249 | child->ScreenSpaceTransform()); |
| 1250 | EXPECT_EQ(gfx::Rect(50, 50, 150, 150), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1251 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1252 | |
| 1253 | // Verify it composes correctly with page scale. |
| 1254 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1255 | |
| 1256 | { |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1257 | RenderSurfaceList render_surface_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1258 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1259 | root, root->bounds(), translate, &render_surface_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1260 | inputs.page_scale_factor = page_scale_factor; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1261 | inputs.page_scale_layer = root; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1262 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1263 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1264 | gfx::Transform page_scaled_translate = translate; |
jaydasika | 18ea272 | 2016-10-27 23:47:10 | [diff] [blame] | 1265 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1266 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1267 | page_scaled_translate, root->draw_properties().target_space_transform); |
| 1268 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1269 | page_scaled_translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1270 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1271 | GetRenderSurface(root)->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1272 | EXPECT_TRANSFORMATION_MATRIX_EQ(page_scaled_translate, |
| 1273 | child->ScreenSpaceTransform()); |
| 1274 | EXPECT_EQ(gfx::Rect(50, 50, 200, 200), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1275 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1276 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1277 | // Verify that it composes correctly with transforms directly on root layer. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1278 | root->test_properties()->transform = composite; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1279 | |
| 1280 | { |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1281 | RenderSurfaceList render_surface_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1282 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1283 | root, root->bounds(), composite, &render_surface_list_impl); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1284 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1285 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1286 | gfx::Transform compositeSquared = composite; |
| 1287 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1288 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1289 | compositeSquared, root->draw_properties().target_space_transform); |
| 1290 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1291 | compositeSquared, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1292 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1293 | GetRenderSurface(root)->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1294 | EXPECT_TRANSFORMATION_MATRIX_EQ(compositeSquared, |
| 1295 | child->ScreenSpaceTransform()); |
| 1296 | EXPECT_EQ(gfx::Rect(254, 316, 428, 428), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1297 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1298 | } |
| 1299 | |
jaydasika | 2cde7b51 | 2017-05-16 23:45:57 | [diff] [blame] | 1300 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForNonAxisAlignedClipping) { |
| 1301 | LayerImpl* root = root_layer_for_testing(); |
| 1302 | LayerImpl* rotated_and_transparent = AddChildToRoot<LayerImpl>(); |
| 1303 | LayerImpl* clips_subtree = AddChild<LayerImpl>(rotated_and_transparent); |
| 1304 | LayerImpl* draws_content = AddChild<LayerImpl>(clips_subtree); |
| 1305 | |
| 1306 | root->SetBounds(gfx::Size(10, 10)); |
| 1307 | rotated_and_transparent->SetBounds(gfx::Size(10, 10)); |
| 1308 | rotated_and_transparent->test_properties()->opacity = 0.5f; |
| 1309 | gfx::Transform rotate; |
| 1310 | rotate.Rotate(2); |
| 1311 | rotated_and_transparent->test_properties()->transform = rotate; |
| 1312 | clips_subtree->SetBounds(gfx::Size(10, 10)); |
| 1313 | clips_subtree->SetMasksToBounds(true); |
| 1314 | draws_content->SetBounds(gfx::Size(10, 10)); |
| 1315 | draws_content->SetDrawsContent(true); |
| 1316 | |
| 1317 | ExecuteCalculateDrawProperties(root); |
| 1318 | EffectTree& effect_tree = |
| 1319 | root->layer_tree_impl()->property_trees()->effect_tree; |
| 1320 | EffectNode* node = effect_tree.Node(clips_subtree->effect_tree_index()); |
| 1321 | EXPECT_TRUE(node->has_render_surface); |
| 1322 | } |
| 1323 | |
jaydasika | fbc951d | 2017-05-24 04:22:52 | [diff] [blame] | 1324 | TEST_F(LayerTreeHostCommonTest, EffectNodesForNonAxisAlignedClips) { |
| 1325 | LayerImpl* root = root_layer_for_testing(); |
| 1326 | LayerImpl* rotate_and_clip = AddChildToRoot<LayerImpl>(); |
| 1327 | LayerImpl* only_clip = AddChild<LayerImpl>(rotate_and_clip); |
| 1328 | LayerImpl* rotate_and_clip2 = AddChild<LayerImpl>(only_clip); |
| 1329 | |
| 1330 | gfx::Transform rotate; |
| 1331 | rotate.Rotate(2); |
| 1332 | root->SetBounds(gfx::Size(10, 10)); |
| 1333 | rotate_and_clip->SetBounds(gfx::Size(10, 10)); |
| 1334 | rotate_and_clip->test_properties()->transform = rotate; |
| 1335 | rotate_and_clip->SetMasksToBounds(true); |
| 1336 | only_clip->SetBounds(gfx::Size(10, 10)); |
| 1337 | only_clip->SetMasksToBounds(true); |
| 1338 | rotate_and_clip2->SetBounds(gfx::Size(10, 10)); |
| 1339 | rotate_and_clip2->test_properties()->transform = rotate; |
| 1340 | rotate_and_clip2->SetMasksToBounds(true); |
| 1341 | |
| 1342 | ExecuteCalculateDrawProperties(root); |
| 1343 | // non-axis aligned clip should create an effect node |
| 1344 | EXPECT_NE(root->effect_tree_index(), rotate_and_clip->effect_tree_index()); |
| 1345 | // Since only_clip's clip is in the same non-axis aligned space as |
| 1346 | // rotate_and_clip's clip, no new effect node should be created. |
| 1347 | EXPECT_EQ(rotate_and_clip->effect_tree_index(), |
| 1348 | only_clip->effect_tree_index()); |
| 1349 | // rotate_and_clip2's clip and only_clip's clip are in different non-axis |
| 1350 | // aligned spaces. So, new effect node should be created. |
| 1351 | EXPECT_NE(rotate_and_clip2->effect_tree_index(), |
| 1352 | only_clip->effect_tree_index()); |
| 1353 | } |
| 1354 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1355 | TEST_F(LayerTreeHostCommonTest, |
| 1356 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1357 | LayerImpl* root = root_layer_for_testing(); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1358 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1359 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1360 | |
| 1361 | root->SetBounds(gfx::Size(10, 10)); |
| 1362 | root->SetMasksToBounds(true); |
| 1363 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1364 | render_surface1->test_properties()->force_render_surface = true; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1365 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1366 | child->SetPosition(gfx::PointF(30.f, 30.f)); |
| 1367 | child->SetBounds(gfx::Size(10, 10)); |
| 1368 | ExecuteCalculateDrawProperties(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1369 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1370 | // 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] | 1371 | // the intermediate render surface should not be listed here, even if it was |
| 1372 | // forced to be created. Render surfaces without children or visible content |
| 1373 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1374 | // of size 0). |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1375 | ASSERT_TRUE(GetRenderSurface(root)); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1376 | EXPECT_EQ(1U, render_surface_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1377 | } |
| 1378 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1379 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1380 | LayerImpl* root = root_layer_for_testing(); |
| 1381 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1382 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1383 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1384 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1385 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1386 | render_surface1->test_properties()->opacity = 0.f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1387 | child->SetBounds(gfx::Size(10, 10)); |
| 1388 | child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1389 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1390 | RenderSurfaceList render_surface_list; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1391 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1392 | root, root->bounds(), &render_surface_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1393 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1394 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1395 | |
ajuma | ac2d3079 | 2017-02-24 23:00:31 | [diff] [blame] | 1396 | // Since the layer is transparent, render_surface1->GetRenderSurface() should |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1397 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1398 | // have been extended by the children. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1399 | ASSERT_TRUE(GetRenderSurface(root)); |
| 1400 | EXPECT_EQ(0, GetRenderSurface(root)->num_contributors()); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1401 | EXPECT_EQ(1U, render_surface_list.size()); |
Chris Harrelson | 9bdbcce | 2017-06-02 03:12:14 | [diff] [blame] | 1402 | EXPECT_EQ(static_cast<RenderPassId>(root->id()), |
| 1403 | render_surface_list.at(0)->id()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1404 | EXPECT_EQ(gfx::Rect(), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1405 | } |
| 1406 | |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1407 | TEST_F(LayerTreeHostCommonTest, |
| 1408 | RenderSurfaceListForTransparentChildWithBackgroundFilter) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1409 | LayerImpl* root = root_layer_for_testing(); |
| 1410 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1411 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1412 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1413 | root->SetBounds(gfx::Size(10, 10)); |
| 1414 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1415 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1416 | render_surface1->test_properties()->opacity = 0.f; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 1417 | render_surface1->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1418 | FilterOperations filters; |
| 1419 | filters.Append(FilterOperation::CreateBlurFilter(1.5f)); |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 1420 | render_surface1->test_properties()->background_filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1421 | child->SetBounds(gfx::Size(10, 10)); |
| 1422 | child->SetDrawsContent(true); |
weiliangc | ea09f337 | 2017-03-29 16:43:24 | [diff] [blame] | 1423 | root->layer_tree_impl()->SetElementIdsForTesting(); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1424 | |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1425 | { |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1426 | RenderSurfaceList render_surface_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1427 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1428 | root, root->bounds(), &render_surface_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1429 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1430 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1431 | EXPECT_EQ(2U, render_surface_list.size()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1432 | } |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1433 | // The layer is fully transparent, but has a background filter, so it |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1434 | // shouldn't be skipped and should be drawn. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1435 | ASSERT_TRUE(GetRenderSurface(root)); |
| 1436 | EXPECT_EQ(1, GetRenderSurface(root)->num_contributors()); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1437 | EXPECT_EQ(gfx::RectF(0, 0, 10, 10), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1438 | GetRenderSurface(root)->DrawableContentRect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1439 | EffectTree& effect_tree = |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1440 | root->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1441 | EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1442 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1443 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1444 | // When root is transparent, the layer should not be drawn. |
weiliangc | ea09f337 | 2017-03-29 16:43:24 | [diff] [blame] | 1445 | root->layer_tree_impl()->SetOpacityMutated(root->element_id(), 0.f); |
| 1446 | root->layer_tree_impl()->SetOpacityMutated(render_surface1->element_id(), |
| 1447 | 1.f); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1448 | render_surface1->set_visible_layer_rect(gfx::Rect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1449 | { |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1450 | RenderSurfaceList render_surface_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1451 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1452 | root, root->bounds(), &render_surface_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1453 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1454 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1458 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1459 | EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect()); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1460 | } |
| 1461 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1462 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1463 | LayerImpl* root = root_layer_for_testing(); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1464 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1465 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1466 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1467 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1468 | gfx::Transform scale_matrix; |
| 1469 | scale_matrix.Scale(2.0f, 2.0f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1470 | |
| 1471 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1472 | parent->test_properties()->transform = scale_matrix; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1473 | FilterOperations filters; |
| 1474 | filters.Append(FilterOperation::CreateBlurFilter(10.0f)); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1475 | parent->test_properties()->filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1476 | parent->test_properties()->force_render_surface = true; |
| 1477 | child1->SetBounds(gfx::Size(25, 25)); |
| 1478 | child1->SetDrawsContent(true); |
| 1479 | child1->test_properties()->force_render_surface = true; |
| 1480 | child2->SetPosition(gfx::PointF(25, 25)); |
| 1481 | child2->SetBounds(gfx::Size(25, 25)); |
| 1482 | child2->SetDrawsContent(true); |
| 1483 | child2->test_properties()->force_render_surface = true; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1484 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1485 | RenderSurfaceList render_surface_list; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1486 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1487 | root, root->bounds(), &render_surface_list); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1488 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1489 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1490 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1491 | ASSERT_TRUE(GetRenderSurface(parent)); |
| 1492 | EXPECT_EQ(2, GetRenderSurface(parent)->num_contributors()); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1493 | EXPECT_EQ(4U, render_surface_list.size()); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1494 | |
| 1495 | // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the |
| 1496 | // blur (-30,-30 110x110), and then scaled by the scale matrix |
| 1497 | // (-60,-60 220x220). |
| 1498 | EXPECT_EQ(gfx::RectF(-60, -60, 220, 220), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1499 | GetRenderSurface(parent)->DrawableContentRect()); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1500 | } |
| 1501 | |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1502 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1503 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1504 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1505 | |
| 1506 | root->SetBounds(gfx::Size(100, 100)); |
| 1507 | child->SetBounds(gfx::Size(25, 25)); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1508 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1509 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1510 | FilterOperations filters; |
| 1511 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1512 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1513 | child->test_properties()->filters = filters; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1514 | ExecuteCalculateDrawProperties(root); |
| 1515 | |
| 1516 | // The render surface's size should be unaffected by the offset image filter; |
| 1517 | // it need only have a drawable content rect large enough to contain the |
| 1518 | // contents (at the new offset). |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1519 | ASSERT_TRUE(GetRenderSurface(child)); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1520 | EXPECT_EQ(gfx::RectF(50, 50, 25, 25), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1521 | GetRenderSurface(child)->DrawableContentRect()); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) { |
| 1525 | const float device_scale_factor = 2.0f; |
| 1526 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1527 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1528 | LayerImpl* child = AddChild<LayerImpl>(root); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1529 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1530 | root->SetBounds(gfx::Size(100, 100)); |
| 1531 | child->SetBounds(gfx::Size(25, 25)); |
| 1532 | child->SetDrawsContent(true); |
| 1533 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1534 | |
| 1535 | FilterOperations filters; |
| 1536 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1537 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1538 | child->test_properties()->filters = filters; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1539 | |
| 1540 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 1541 | |
| 1542 | // The render surface's size should be unaffected by the offset image filter; |
| 1543 | // it need only have a drawable content rect large enough to contain the |
| 1544 | // contents (at the new offset). All coordinates should be scaled by 2, |
| 1545 | // corresponding to the device scale factor. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1546 | ASSERT_TRUE(GetRenderSurface(child)); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1547 | EXPECT_EQ(gfx::RectF(100, 100, 50, 50), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1548 | GetRenderSurface(child)->DrawableContentRect()); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1549 | } |
| 1550 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1551 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1552 | LayerImpl* root = root_layer_for_testing(); |
| 1553 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1554 | |
| 1555 | root->SetBounds(gfx::Size(10, 10)); |
| 1556 | child->SetBounds(gfx::Size(10, 10)); |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1557 | child->SetDrawsContent(true); |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 1558 | child->test_properties()->blend_mode = SkBlendMode::kMultiply; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1559 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1560 | child->test_properties()->force_render_surface = true; |
| 1561 | ExecuteCalculateDrawProperties(root); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1562 | |
| 1563 | // Since the child layer has a blend mode other than normal, it should get |
jaydasika | 815ffdb8 | 2017-04-10 18:19:46 | [diff] [blame] | 1564 | // its own render surface. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1565 | ASSERT_TRUE(GetRenderSurface(child)); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1566 | EXPECT_EQ(1.0f, child->draw_opacity()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1567 | EXPECT_EQ(0.5f, GetRenderSurface(child)->draw_opacity()); |
| 1568 | EXPECT_EQ(SkBlendMode::kMultiply, GetRenderSurface(child)->BlendMode()); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1569 | } |
| 1570 | |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1571 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1572 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1573 | LayerImpl* surface1 = AddChildToRoot<LayerImpl>(); |
| 1574 | LayerImpl* not_surface = AddChild<LayerImpl>(surface1); |
| 1575 | LayerImpl* surface2 = AddChild<LayerImpl>(not_surface); |
| 1576 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1577 | root->SetBounds(gfx::Size(10, 10)); |
| 1578 | surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1579 | surface1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1580 | surface1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1581 | surface1->test_properties()->force_render_surface = true; |
| 1582 | not_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1583 | not_surface->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1584 | surface2->SetBounds(gfx::Size(10, 10)); |
| 1585 | surface2->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1586 | surface2->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1587 | surface2->test_properties()->force_render_surface = true; |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1588 | ExecuteCalculateDrawProperties(root); |
| 1589 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1590 | ASSERT_TRUE(GetRenderSurface(surface1)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 1591 | ASSERT_EQ(GetRenderSurface(not_surface), GetRenderSurface(surface1)); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1592 | ASSERT_TRUE(GetRenderSurface(surface2)); |
| 1593 | EXPECT_EQ(0.5f, GetRenderSurface(surface1)->draw_opacity()); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1594 | // surface2's draw opacity should include the opacity of not-surface and |
| 1595 | // itself, but not the opacity of surface1. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1596 | EXPECT_EQ(0.25f, GetRenderSurface(surface2)->draw_opacity()); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1597 | } |
| 1598 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1599 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1600 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1601 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1602 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1603 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1604 | root->SetBounds(gfx::Size(10, 10)); |
| 1605 | render_surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1606 | render_surface1->test_properties()->force_render_surface = true; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1607 | child->SetBounds(gfx::Size(10, 10)); |
| 1608 | child->SetDrawsContent(true); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1609 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1610 | { |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1611 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1612 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1613 | // The root layer always creates a render surface |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1614 | EXPECT_TRUE(GetRenderSurface(root)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 1615 | EXPECT_NE(GetRenderSurface(render_surface1), GetRenderSurface(root)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1616 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1617 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1618 | { |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1619 | render_surface1->test_properties()->force_render_surface = false; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1620 | render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1621 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1622 | EXPECT_TRUE(GetRenderSurface(root)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 1623 | EXPECT_EQ(GetRenderSurface(render_surface1), GetRenderSurface(root)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1624 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1625 | } |
| 1626 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1627 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1628 | // Render surfaces act as a flattening point for their subtree, so should |
| 1629 | // always flatten the target-to-screen space transform seen by descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1630 | LayerImpl* root = root_layer_for_testing(); |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1631 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1632 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1633 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1634 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1635 | gfx::Transform rotation_about_y_axis; |
| 1636 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1637 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1638 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1639 | parent->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1640 | parent->SetBounds(gfx::Size(10, 10)); |
| 1641 | parent->test_properties()->force_render_surface = true; |
| 1642 | child->SetBounds(gfx::Size(10, 10)); |
| 1643 | child->SetDrawsContent(true); |
| 1644 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1645 | grand_child->SetDrawsContent(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1646 | grand_child->test_properties()->should_flatten_transform = false; |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1647 | ExecuteCalculateDrawProperties(root); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1648 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1649 | EXPECT_TRUE(GetRenderSurface(parent)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 1650 | EXPECT_EQ(GetRenderSurface(child), GetRenderSurface(parent)); |
| 1651 | EXPECT_EQ(GetRenderSurface(grand_child), GetRenderSurface(parent)); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1652 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1653 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1654 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1655 | grand_child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1656 | |
| 1657 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1658 | // have been flattened at their render target. In particular, the fact that |
| 1659 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1660 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1661 | flattened_rotation_about_y.FlattenTo2d(); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1662 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1663 | child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1664 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1665 | grand_child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1666 | } |
| 1667 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1668 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1669 | // The entire subtree of layers that are outside the clip rect should be |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1670 | // culled away, and should not affect the render_surface_list. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1671 | // |
| 1672 | // The test tree is set up as follows: |
| 1673 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1674 | // that have something to draw. |
| 1675 | // - parent is a large container layer. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1676 | // - child has MasksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1677 | // - grand_child is positioned outside of the child's bounds |
| 1678 | // - great_grand_child is also kept outside child's bounds. |
| 1679 | // |
| 1680 | // In this configuration, grand_child and great_grand_child are completely |
| 1681 | // outside the clip rect, and they should never get scheduled on the list of |
| 1682 | // render surfaces. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1683 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1684 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1685 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1686 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1687 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1688 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1689 | // leaf_node1 ensures that root and child are kept on the render_surface_list, |
| 1690 | // even though grand_child and great_grand_child should be clipped. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1691 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(child); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1692 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1693 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1694 | root->SetBounds(gfx::Size(500, 500)); |
| 1695 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1696 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1697 | child->test_properties()->force_render_surface = true; |
| 1698 | grand_child->SetPosition(gfx::PointF(45.f, 45.f)); |
| 1699 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1700 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
| 1701 | leaf_node1->SetBounds(gfx::Size(500, 500)); |
| 1702 | leaf_node1->SetDrawsContent(true); |
| 1703 | leaf_node1->SetBounds(gfx::Size(20, 20)); |
| 1704 | leaf_node2->SetDrawsContent(true); |
| 1705 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1706 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1707 | ASSERT_EQ(2U, render_surface_list_impl()->size()); |
Chris Harrelson | 9bdbcce | 2017-06-02 03:12:14 | [diff] [blame] | 1708 | EXPECT_EQ(static_cast<uint64_t>(root->id()), |
| 1709 | render_surface_list_impl()->at(0)->id()); |
| 1710 | EXPECT_EQ(static_cast<uint64_t>(child->id()), |
| 1711 | render_surface_list_impl()->at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1712 | } |
| 1713 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1714 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1715 | // 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] | 1716 | // of the surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1717 | |
| 1718 | // The test tree is set up as follows: |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1719 | // - root is a container layer that masksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1720 | // - 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] | 1721 | // the root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1722 | // - grand_child is a render surface, and the only visible content in child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1723 | // It is positioned outside of the clip rect from root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1724 | |
| 1725 | // In this configuration, grand_child should be outside the clipped |
| 1726 | // content rect of the child, making grand_child not appear in the |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1727 | // render_surface_list. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1728 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1729 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1730 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1731 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1732 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1733 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1734 | root->SetMasksToBounds(true); |
| 1735 | root->SetBounds(gfx::Size(100, 100)); |
| 1736 | child->SetBounds(gfx::Size(20, 20)); |
| 1737 | child->test_properties()->force_render_surface = true; |
| 1738 | grand_child->SetPosition(gfx::PointF(200.f, 200.f)); |
| 1739 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1740 | grand_child->test_properties()->force_render_surface = true; |
| 1741 | leaf_node->SetBounds(gfx::Size(10, 10)); |
| 1742 | leaf_node->SetDrawsContent(true); |
| 1743 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1744 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1745 | // We should cull child and grand_child from the |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 1746 | // render_surface_list. |
| 1747 | ASSERT_EQ(1U, render_surface_list_impl()->size()); |
Chris Harrelson | 9bdbcce | 2017-06-02 03:12:14 | [diff] [blame] | 1748 | EXPECT_EQ(static_cast<uint64_t>(root->id()), |
| 1749 | render_surface_list_impl()->at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1750 | } |
| 1751 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1752 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) { |
| 1753 | // Tests that LayerImpl's IsClipped() property is set to true when: |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1754 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1755 | // - the layer is clipped by an ancestor that contributes to the same |
| 1756 | // render target, |
| 1757 | // - a surface is clipped by an ancestor that contributes to the same |
| 1758 | // render target. |
| 1759 | // |
| 1760 | // In particular, for a layer that owns a render surface: |
| 1761 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1762 | // pass that clipped status to the layer itself. |
| 1763 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1764 | // and propagates the clip to the subtree. |
| 1765 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1766 | LayerImpl* root = root_layer_for_testing(); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1767 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1768 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1769 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1770 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1771 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1772 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1773 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1774 | root->SetBounds(gfx::Size(100, 100)); |
| 1775 | parent->SetBounds(gfx::Size(100, 100)); |
| 1776 | parent->SetDrawsContent(true); |
| 1777 | child1->SetBounds(gfx::Size(100, 100)); |
| 1778 | child1->SetDrawsContent(true); |
| 1779 | child2->SetBounds(gfx::Size(100, 100)); |
| 1780 | child2->SetDrawsContent(true); |
| 1781 | child2->test_properties()->force_render_surface = true; |
| 1782 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 1783 | grand_child->SetDrawsContent(true); |
| 1784 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
| 1785 | leaf_node1->SetDrawsContent(true); |
| 1786 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
| 1787 | leaf_node2->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1788 | |
| 1789 | // Case 1: nothing is clipped except the root render surface. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1790 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1791 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1792 | ASSERT_TRUE(GetRenderSurface(root)); |
| 1793 | ASSERT_TRUE(GetRenderSurface(child2)); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1794 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1795 | EXPECT_FALSE(root->is_clipped()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1796 | EXPECT_TRUE(GetRenderSurface(root)->is_clipped()); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1797 | EXPECT_FALSE(parent->is_clipped()); |
| 1798 | EXPECT_FALSE(child1->is_clipped()); |
| 1799 | EXPECT_FALSE(child2->is_clipped()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1800 | EXPECT_FALSE(GetRenderSurface(child2)->is_clipped()); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1801 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1802 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1803 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1804 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1805 | // Case 2: parent MasksToBounds, so the parent, child1, and child2's |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1806 | // surface are clipped. But layers that contribute to child2's surface are |
| 1807 | // not clipped explicitly because child2's surface already accounts for |
| 1808 | // that clip. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1809 | parent->SetMasksToBounds(true); |
| 1810 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1811 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1812 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1813 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1814 | ASSERT_TRUE(GetRenderSurface(root)); |
| 1815 | ASSERT_TRUE(GetRenderSurface(child2)); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1816 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1817 | EXPECT_FALSE(root->is_clipped()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1818 | EXPECT_TRUE(GetRenderSurface(root)->is_clipped()); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1819 | EXPECT_TRUE(parent->is_clipped()); |
| 1820 | EXPECT_TRUE(child1->is_clipped()); |
| 1821 | EXPECT_FALSE(child2->is_clipped()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1822 | EXPECT_TRUE(GetRenderSurface(child2)->is_clipped()); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1823 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1824 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1825 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1826 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1827 | parent->SetMasksToBounds(false); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1828 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1829 | // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1830 | // child2's render surface is not clipped. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1831 | child2->SetMasksToBounds(true); |
| 1832 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1833 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1834 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1835 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1836 | ASSERT_TRUE(GetRenderSurface(root)); |
| 1837 | ASSERT_TRUE(GetRenderSurface(child2)); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1838 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1839 | EXPECT_FALSE(root->is_clipped()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1840 | EXPECT_TRUE(GetRenderSurface(root)->is_clipped()); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1841 | EXPECT_FALSE(parent->is_clipped()); |
| 1842 | EXPECT_FALSE(child1->is_clipped()); |
| 1843 | EXPECT_TRUE(child2->is_clipped()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1844 | EXPECT_FALSE(GetRenderSurface(child2)->is_clipped()); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1845 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1846 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1847 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1848 | } |
| 1849 | |
| 1850 | TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) { |
| 1851 | // Tests that when as long as layer is clipped, it's clip rect is set to |
| 1852 | // correct value. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1853 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1854 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1855 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1856 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1857 | root->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1858 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1859 | parent->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1860 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1861 | child->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1862 | child->SetDrawsContent(true); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1863 | child->SetMasksToBounds(true); |
| 1864 | |
| 1865 | ExecuteCalculateDrawProperties(root); |
| 1866 | |
| 1867 | EXPECT_FALSE(root->is_clipped()); |
| 1868 | EXPECT_FALSE(parent->is_clipped()); |
| 1869 | EXPECT_TRUE(child->is_clipped()); |
| 1870 | EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect()); |
| 1871 | |
| 1872 | parent->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1873 | child->SetPosition(gfx::PointF(100.f, 100.f)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1874 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1875 | |
| 1876 | ExecuteCalculateDrawProperties(root); |
| 1877 | |
| 1878 | EXPECT_FALSE(root->is_clipped()); |
| 1879 | EXPECT_TRUE(parent->is_clipped()); |
| 1880 | EXPECT_TRUE(child->is_clipped()); |
| 1881 | EXPECT_EQ(gfx::Rect(), child->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1882 | } |
| 1883 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 1884 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1885 | // Verify that layers get the appropriate DrawableContentRect when their |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1886 | // parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1887 | // |
| 1888 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 1889 | // be the layer rect expressed in target space. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1890 | // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1891 | // will be the intersection of layer bounds and the mask region. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1892 | // grand_child3 - partially clipped and MasksToBounds; the |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1893 | // DrawableContentRect will still be the intersection of layer bounds and |
| 1894 | // the mask region. |
| 1895 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 1896 | // be empty. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1897 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1898 | LayerImpl* parent = root_layer_for_testing(); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 1899 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1900 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 1901 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 1902 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 1903 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1904 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1905 | parent->SetBounds(gfx::Size(500, 500)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1906 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1907 | child->SetBounds(gfx::Size(20, 20)); |
| 1908 | child->test_properties()->force_render_surface = true; |
| 1909 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 1910 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 1911 | grand_child1->SetDrawsContent(true); |
| 1912 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 1913 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 1914 | grand_child2->SetDrawsContent(true); |
| 1915 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1916 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1917 | grand_child3->SetBounds(gfx::Size(10, 10)); |
| 1918 | grand_child3->SetDrawsContent(true); |
| 1919 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 1920 | grand_child4->SetBounds(gfx::Size(10, 10)); |
| 1921 | grand_child4->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 1922 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1923 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 1924 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 1925 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 1926 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1927 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 1928 | } |
| 1929 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1930 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1931 | // Verify that render surfaces (and their layers) get the appropriate |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1932 | // clip rects when their parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1933 | // |
| 1934 | // Layers that own render surfaces (at least for now) do not inherit any |
| 1935 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 1936 | // They may still have a clip rect of their own layer bounds, however, if |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1937 | // MasksToBounds was true. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1938 | LayerImpl* parent = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1939 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1940 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 1941 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 1942 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 1943 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1944 | // The leaf nodes ensure that these grand_children become render surfaces for |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1945 | // this test. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1946 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1947 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1948 | LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1949 | LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1950 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1951 | parent->SetBounds(gfx::Size(500, 500)); |
| 1952 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1953 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1954 | child->test_properties()->force_render_surface = true; |
| 1955 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 1956 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 1957 | grand_child1->test_properties()->force_render_surface = true; |
| 1958 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 1959 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 1960 | grand_child2->test_properties()->force_render_surface = true; |
| 1961 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
| 1962 | grand_child3->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1963 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1964 | grand_child3->test_properties()->force_render_surface = true; |
| 1965 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 1966 | grand_child4->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1967 | grand_child4->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1968 | grand_child4->test_properties()->force_render_surface = true; |
| 1969 | leaf_node1->SetBounds(gfx::Size(10, 10)); |
| 1970 | leaf_node1->SetDrawsContent(true); |
| 1971 | leaf_node2->SetBounds(gfx::Size(10, 10)); |
| 1972 | leaf_node2->SetDrawsContent(true); |
| 1973 | leaf_node3->SetBounds(gfx::Size(10, 10)); |
| 1974 | leaf_node3->SetDrawsContent(true); |
| 1975 | leaf_node4->SetBounds(gfx::Size(10, 10)); |
| 1976 | leaf_node4->SetDrawsContent(true); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1977 | ExecuteCalculateDrawProperties(parent); |
| 1978 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1979 | ASSERT_TRUE(GetRenderSurface(grand_child1)); |
| 1980 | ASSERT_TRUE(GetRenderSurface(grand_child2)); |
| 1981 | ASSERT_TRUE(GetRenderSurface(grand_child3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1982 | |
| 1983 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1984 | // MasksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 1985 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1986 | GetRenderSurface(grand_child1)->clip_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 1987 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1988 | GetRenderSurface(grand_child2)->clip_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 1989 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 1990 | GetRenderSurface(grand_child3)->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1991 | } |
| 1992 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1993 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1994 | LayerImpl* root = root_layer_for_testing(); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 1995 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1996 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
| 1997 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 1998 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 1999 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
| 2000 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 2001 | LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
| 2002 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2003 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2004 | root->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2005 | render_surface1->SetDrawsContent(true); |
| 2006 | child_of_rs1->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2007 | grand_child_of_rs1->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2008 | render_surface2->SetDrawsContent(true); |
| 2009 | child_of_rs2->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2010 | grand_child_of_rs2->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2011 | child_of_root->SetDrawsContent(true); |
| 2012 | grand_child_of_root->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2013 | |
| 2014 | gfx::Transform layer_transform; |
| 2015 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2016 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2017 | root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2018 | root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2019 | root->SetBounds(gfx::Size(10, 10)); |
| 2020 | root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2021 | render_surface1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2022 | render_surface1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2023 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 2024 | render_surface1->test_properties()->transform_origin = |
| 2025 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2026 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2027 | render_surface2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2028 | render_surface2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2029 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 2030 | render_surface2->test_properties()->transform_origin = |
| 2031 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2032 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2033 | child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2034 | child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2035 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2036 | child_of_root->test_properties()->transform_origin = |
| 2037 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2038 | child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2039 | child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2040 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2041 | child_of_rs1->test_properties()->transform_origin = |
| 2042 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2043 | child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2044 | child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2045 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2046 | child_of_rs2->test_properties()->transform_origin = |
| 2047 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2048 | grand_child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2049 | grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2050 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2051 | grand_child_of_root->test_properties()->transform_origin = |
| 2052 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2053 | grand_child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2054 | grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2055 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2056 | grand_child_of_rs1->test_properties()->transform_origin = |
| 2057 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2058 | grand_child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2059 | grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2060 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2061 | grand_child_of_rs2->test_properties()->transform_origin = |
| 2062 | gfx::Point3F(0.25f, 0.f, 0.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2063 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2064 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 2065 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2066 | // Put an animated opacity on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2067 | AddOpacityTransitionToElementWithPlayer( |
| 2068 | render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2069 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2070 | // Also put an animated opacity on a layer without descendants. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2071 | AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(), |
| 2072 | timeline_impl(), 10.0, 1.f, 0.f, |
| 2073 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2074 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2075 | // Put a transform animation on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2076 | AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(), |
| 2077 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2078 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2079 | // Also put transform animations on grand_child_of_root, and |
| 2080 | // grand_child_of_rs2 |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2081 | AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(), |
| 2082 | timeline_impl(), 10.0, 30, 0); |
| 2083 | AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(), |
| 2084 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2085 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2086 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 2087 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2088 | |
| 2089 | // Only layers that are associated with render surfaces should have an actual |
| 2090 | // RenderSurface() value. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2091 | ASSERT_TRUE(GetRenderSurface(root)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 2092 | ASSERT_EQ(GetRenderSurface(child_of_root), GetRenderSurface(root)); |
| 2093 | ASSERT_EQ(GetRenderSurface(grand_child_of_root), GetRenderSurface(root)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2094 | |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 2095 | ASSERT_NE(GetRenderSurface(render_surface1), GetRenderSurface(root)); |
| 2096 | ASSERT_EQ(GetRenderSurface(child_of_rs1), GetRenderSurface(render_surface1)); |
| 2097 | ASSERT_EQ(GetRenderSurface(grand_child_of_rs1), |
| 2098 | GetRenderSurface(render_surface1)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2099 | |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 2100 | ASSERT_NE(GetRenderSurface(render_surface2), GetRenderSurface(root)); |
| 2101 | ASSERT_NE(GetRenderSurface(render_surface2), |
| 2102 | GetRenderSurface(render_surface1)); |
| 2103 | ASSERT_EQ(GetRenderSurface(child_of_rs2), GetRenderSurface(render_surface2)); |
| 2104 | ASSERT_EQ(GetRenderSurface(grand_child_of_rs2), |
| 2105 | GetRenderSurface(render_surface2)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2106 | |
| 2107 | // Verify all render target accessors |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2108 | EXPECT_EQ(GetRenderSurface(root), root->render_target()); |
| 2109 | EXPECT_EQ(GetRenderSurface(root), child_of_root->render_target()); |
| 2110 | EXPECT_EQ(GetRenderSurface(root), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2111 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2112 | EXPECT_EQ(GetRenderSurface(render_surface1), |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2113 | render_surface1->render_target()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2114 | EXPECT_EQ(GetRenderSurface(render_surface1), child_of_rs1->render_target()); |
| 2115 | EXPECT_EQ(GetRenderSurface(render_surface1), |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2116 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2117 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2118 | EXPECT_EQ(GetRenderSurface(render_surface2), |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2119 | render_surface2->render_target()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2120 | EXPECT_EQ(GetRenderSurface(render_surface2), child_of_rs2->render_target()); |
| 2121 | EXPECT_EQ(GetRenderSurface(render_surface2), |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2122 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2123 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2124 | // Verify screen_space_transform_is_animating values |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2125 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2126 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2127 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2128 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2129 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2130 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2131 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2132 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2133 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2134 | |
| 2135 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2136 | // It is expected that we correctly set up transforms so that the y-component |
| 2137 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2138 | EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2139 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2140 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2141 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2142 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2143 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2144 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2145 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2146 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2147 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2148 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2149 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2150 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2151 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2152 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2153 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2154 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2155 | } |
| 2156 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2157 | TEST_F(LayerTreeHostCommonTest, LargeTransforms) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2158 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2159 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2160 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2161 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2162 | gfx::Transform large_transform; |
| 2163 | large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); |
| 2164 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2165 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2166 | child->test_properties()->transform = large_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2167 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2168 | grand_child->test_properties()->transform = large_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2169 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2170 | grand_child->SetDrawsContent(true); |
| 2171 | ExecuteCalculateDrawProperties(root); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2172 | |
| 2173 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
| 2174 | } |
| 2175 | |
wkorman | 15d8686 | 2017-05-12 18:18:24 | [diff] [blame] | 2176 | static bool TransformIsAnimating(LayerImpl* layer) { |
| 2177 | return layer->GetMutatorHost()->IsAnimatingTransformProperty( |
| 2178 | layer->element_id(), layer->GetElementTypeForAnimation()); |
| 2179 | } |
| 2180 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2181 | TEST_F(LayerTreeHostCommonTest, |
| 2182 | ScreenSpaceTransformIsAnimatingWithDelayedAnimation) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2183 | LayerImpl* root = root_layer_for_testing(); |
| 2184 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2185 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2186 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 2187 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2188 | root->SetDrawsContent(true); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2189 | child->SetDrawsContent(true); |
| 2190 | grand_child->SetDrawsContent(true); |
| 2191 | great_grand_child->SetDrawsContent(true); |
| 2192 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2193 | root->SetBounds(gfx::Size(10, 10)); |
| 2194 | child->SetBounds(gfx::Size(10, 10)); |
| 2195 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2196 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2197 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2198 | SetElementIdsForTesting(); |
| 2199 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2200 | // Add a transform animation with a start delay to |grand_child|. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2201 | std::unique_ptr<Animation> animation = Animation::Create( |
| 2202 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1, |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 2203 | TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 2204 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2205 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2206 | AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(), |
| 2207 | std::move(animation)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2208 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2209 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2210 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2211 | EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 2212 | |
wkorman | 15d8686 | 2017-05-12 18:18:24 | [diff] [blame] | 2213 | EXPECT_FALSE(TransformIsAnimating(grand_child)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2214 | EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation()); |
| 2215 | EXPECT_TRUE(grand_child->screen_space_transform_is_animating()); |
| 2216 | EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating()); |
| 2217 | } |
| 2218 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2219 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) { |
| 2220 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2221 | // correctly for identity transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2222 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2223 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2224 | gfx::Transform layer_to_surface_transform; |
| 2225 | |
| 2226 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2227 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2228 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2229 | gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30); |
| 2230 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2231 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2232 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2233 | EXPECT_EQ(expected_drawable_content_rect, |
| 2234 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2235 | |
| 2236 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2237 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2238 | expected_visible_layer_rect = gfx::Rect(); |
| 2239 | expected_drawable_content_rect = gfx::Rect(); |
| 2240 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2241 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2242 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2243 | EXPECT_EQ(expected_drawable_content_rect, |
| 2244 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2245 | |
| 2246 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2247 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2248 | expected_visible_layer_rect = gfx::Rect(20, 20); |
| 2249 | expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20); |
| 2250 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2251 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2252 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2253 | EXPECT_EQ(expected_drawable_content_rect, |
| 2254 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2255 | } |
| 2256 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2257 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) { |
| 2258 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2259 | // for rotations about z-axis (i.e. 2D rotations). |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2260 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2261 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2262 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2263 | gfx::Transform layer_to_surface_transform; |
| 2264 | |
| 2265 | // Case 1: Layer is contained within the surface. |
| 2266 | layer_to_surface_transform.MakeIdentity(); |
| 2267 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2268 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2269 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2270 | gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43); |
| 2271 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2272 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2273 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2274 | EXPECT_EQ(expected_drawable_content_rect, |
| 2275 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2276 | |
| 2277 | // Case 2: Layer is outside the surface rect. |
| 2278 | layer_to_surface_transform.MakeIdentity(); |
| 2279 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2280 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2281 | expected_visible_layer_rect = gfx::Rect(); |
| 2282 | expected_drawable_content_rect = gfx::Rect(); |
| 2283 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2284 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2285 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2286 | EXPECT_EQ(expected_drawable_content_rect, |
| 2287 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2288 | |
| 2289 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2290 | // the layer is oriented diagonally, with the left half outside of the render |
| 2291 | // surface. In this case, the g should still be the entire layer |
| 2292 | // (remember the g is computed in layer space); both the top-left |
| 2293 | // and bottom-right corners of the layer are still visible. |
| 2294 | layer_to_surface_transform.MakeIdentity(); |
| 2295 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2296 | expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2297 | expected_drawable_content_rect = gfx::Rect(22, 43); |
| 2298 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2299 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2300 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2301 | EXPECT_EQ(expected_drawable_content_rect, |
| 2302 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2303 | |
| 2304 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2305 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2306 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2307 | // surface overlaps the right side of the layer. The g should be |
| 2308 | // the layer's right half. |
| 2309 | layer_to_surface_transform.MakeIdentity(); |
| 2310 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2311 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2312 | // Right half of layer bounds. |
| 2313 | expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30); |
| 2314 | expected_drawable_content_rect = gfx::Rect(22, 22); |
| 2315 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2316 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2317 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2318 | EXPECT_EQ(expected_drawable_content_rect, |
| 2319 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2320 | } |
| 2321 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2322 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) { |
| 2323 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2324 | // for 3d transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2325 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2326 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2327 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2328 | gfx::Transform layer_to_surface_transform; |
| 2329 | |
| 2330 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2331 | // degrees, should be fully contained in the render surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2332 | // 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] | 2333 | layer_to_surface_transform.MakeIdentity(); |
| 2334 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2335 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2336 | gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100); |
| 2337 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2338 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2339 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2340 | EXPECT_EQ(expected_drawable_content_rect, |
| 2341 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2342 | |
| 2343 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2344 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2345 | // visible on the surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2346 | // 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] | 2347 | SkMScalar half_width_of_rotated_layer = |
| 2348 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2349 | layer_to_surface_transform.MakeIdentity(); |
| 2350 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2351 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2352 | // edge of the layer. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2353 | // Tight half of the layer. |
| 2354 | expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100); |
| 2355 | expected_drawable_content_rect = gfx::Rect(36, 100); |
| 2356 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2357 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2358 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2359 | EXPECT_EQ(expected_drawable_content_rect, |
| 2360 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2361 | } |
| 2362 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2363 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) { |
| 2364 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2365 | // when the layer has a perspective projection onto the target surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2366 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2367 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2368 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2369 | gfx::Transform layer_to_surface_transform; |
| 2370 | |
| 2371 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2372 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2373 | // its translated more than the perspective amount. |
| 2374 | layer_to_surface_transform.MakeIdentity(); |
| 2375 | |
| 2376 | // The following sequence of transforms applies the perspective about the |
| 2377 | // center of the surface. |
| 2378 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2379 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2380 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2381 | |
| 2382 | // This translate places the layer in front of the surface's projection plane. |
| 2383 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2384 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2385 | // Layer position is (-50, -50), visible rect in layer space is layer bounds |
| 2386 | // offset by layer position. |
| 2387 | gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150); |
| 2388 | gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38); |
| 2389 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2390 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2391 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2392 | EXPECT_EQ(expected_drawable_content_rect, |
| 2393 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2394 | |
| 2395 | // Case 2: same projection as before, except that the layer is also translated |
| 2396 | // to the side, so that only the right half of the layer should be visible. |
| 2397 | // |
| 2398 | // Explanation of expected result: The perspective ratio is (z distance |
| 2399 | // between layer and camera origin) / (z distance between projection plane and |
| 2400 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2401 | // move a layer by translating -25 units in projected surface units (so that |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2402 | // 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] | 2403 | // -25 == -100 in the layer's units. |
| 2404 | layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0); |
| 2405 | // Visible layer rect is moved by 100, and drawable content rect is in target |
| 2406 | // space and is moved by 25. |
| 2407 | expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150); |
| 2408 | expected_drawable_content_rect = gfx::Rect(13, 38); |
| 2409 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2410 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2411 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2412 | EXPECT_EQ(expected_drawable_content_rect, |
| 2413 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2414 | } |
| 2415 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2416 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2417 | DrawRectsFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2418 | // There is currently no explicit concept of an orthographic projection plane |
| 2419 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2420 | // are technically behind the surface in an orthographic world should not be |
| 2421 | // clipped when they are flattened to the surface. |
| 2422 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2423 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2424 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2425 | gfx::Transform layer_to_surface_transform; |
| 2426 | |
| 2427 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2428 | // at the center of the layer. |
| 2429 | layer_to_surface_transform.MakeIdentity(); |
| 2430 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2431 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2432 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2433 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2434 | // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface |
| 2435 | // space. |
| 2436 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2437 | gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100); |
| 2438 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2439 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2440 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2441 | EXPECT_EQ(expected_drawable_content_rect, |
| 2442 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2443 | } |
| 2444 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2445 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2446 | DrawRectsFor3dPerspectiveWhenClippedByW) { |
| 2447 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2448 | // when projecting a surface onto a layer, but the layer is partially behind |
| 2449 | // the camera (not just behind the projection plane). In this case, the |
| 2450 | // cartesian coordinates may seem to be valid, but actually they are not. The |
| 2451 | // visible rect needs to be properly clipped by the w = 0 plane in homogeneous |
| 2452 | // coordinates before converting to cartesian coordinates. The drawable |
| 2453 | // content rect would be entire surface rect because layer is rotated at the |
| 2454 | // camera position. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2455 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2456 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200); |
| 2457 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2458 | gfx::Transform layer_to_surface_transform; |
| 2459 | |
| 2460 | // The layer is positioned so that the right half of the layer should be in |
| 2461 | // front of the camera, while the other half is behind the surface's |
| 2462 | // projection plane. The following sequence of transforms applies the |
| 2463 | // perspective and rotation about the center of the layer. |
| 2464 | layer_to_surface_transform.MakeIdentity(); |
| 2465 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2466 | layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0); |
| 2467 | layer_to_surface_transform.RotateAboutYAxis(-45.0); |
| 2468 | layer_to_surface_transform.Translate(-10, -1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2469 | |
| 2470 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2471 | // transform, otherwise this code is not testing the intended scenario. |
| 2472 | bool clipped; |
| 2473 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2474 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2475 | &clipped); |
| 2476 | ASSERT_TRUE(clipped); |
| 2477 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2478 | gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1); |
| 2479 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 2480 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2481 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2482 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2483 | EXPECT_EQ(expected_drawable_content_rect, |
| 2484 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2485 | } |
| 2486 | |
petermayo | ca9b820 | 2017-03-17 18:54:10 | [diff] [blame] | 2487 | static bool ProjectionClips(const gfx::Transform& map_transform, |
| 2488 | const gfx::RectF& mapped_rect) { |
| 2489 | gfx::Transform inverse(Inverse(map_transform)); |
| 2490 | bool clipped = false; |
| 2491 | if (!clipped) |
| 2492 | MathUtil::ProjectPoint(inverse, mapped_rect.top_right(), &clipped); |
| 2493 | if (!clipped) |
| 2494 | MathUtil::ProjectPoint(inverse, mapped_rect.origin(), &clipped); |
| 2495 | if (!clipped) |
| 2496 | MathUtil::ProjectPoint(inverse, mapped_rect.bottom_right(), &clipped); |
| 2497 | if (!clipped) |
| 2498 | MathUtil::ProjectPoint(inverse, mapped_rect.bottom_left(), &clipped); |
| 2499 | return clipped; |
| 2500 | } |
| 2501 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2502 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2503 | // To determine visible rect in layer space, there needs to be an |
| 2504 | // un-projection from surface space to layer space. When the original |
| 2505 | // transform was a perspective projection that was clipped, it returns a rect |
| 2506 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2507 | // clipping again. |
| 2508 | |
| 2509 | // This sequence of transforms causes one corner of the layer to protrude |
| 2510 | // across the w = 0 plane, and should be clipped. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2511 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150); |
| 2512 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2513 | gfx::Transform layer_to_surface_transform; |
| 2514 | layer_to_surface_transform.MakeIdentity(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2515 | layer_to_surface_transform.Translate(10, 10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2516 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2517 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2518 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2519 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2520 | layer_to_surface_transform.Translate(-10, -10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2521 | |
| 2522 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2523 | // code is not testing the intended scenario. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2524 | gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
| 2525 | layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
petermayo | ca9b820 | 2017-03-17 18:54:10 | [diff] [blame] | 2526 | ASSERT_TRUE(ProjectionClips(layer_to_surface_transform, clipped_rect)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2527 | |
| 2528 | // Only the corner of the layer is not visible on the surface because of being |
| 2529 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2530 | // rect is that the entire layer should still be considered visible. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2531 | gfx::Rect expected_visible_layer_rect = layer_content_rect; |
| 2532 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 2533 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2534 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2535 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2536 | EXPECT_EQ(expected_drawable_content_rect, |
| 2537 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2538 | } |
| 2539 | |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2540 | TEST_F(LayerTreeHostCommonTest, |
| 2541 | VisibleRectsForPositionedRootLayerClippedByViewport) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2542 | LayerImpl* root = root_layer_for_testing(); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2543 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2544 | root->SetPosition(gfx::PointF(60, 70)); |
| 2545 | root->SetBounds(gfx::Size(100, 100)); |
| 2546 | root->SetDrawsContent(true); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 2547 | ExecuteCalculateDrawProperties(root); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2548 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2549 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2550 | GetRenderSurface(root)->DrawableContentRect()); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2551 | // In target space, not clipped. |
| 2552 | EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 2553 | // In layer space, clipped. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2554 | EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2555 | } |
| 2556 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2557 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2558 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2559 | LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2560 | LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2561 | LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2562 | |
| 2563 | root->SetBounds(gfx::Size(100, 100)); |
| 2564 | child1_layer->SetBounds(gfx::Size(50, 50)); |
| 2565 | child1_layer->SetDrawsContent(true); |
| 2566 | child2_layer->SetPosition(gfx::PointF(75.f, 75.f)); |
| 2567 | child2_layer->SetBounds(gfx::Size(50, 50)); |
| 2568 | child2_layer->SetDrawsContent(true); |
| 2569 | child3_layer->SetPosition(gfx::PointF(125.f, 125.f)); |
| 2570 | child3_layer->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2571 | child3_layer->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2572 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2573 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2574 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2575 | GetRenderSurface(root)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2576 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2577 | // Layers that do not draw content should have empty visible_layer_rects. |
| 2578 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2579 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2580 | // layer visible_layer_rects are clipped by their target surface. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2581 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); |
| 2582 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); |
| 2583 | EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2584 | |
| 2585 | // layer drawable_content_rects are not clipped. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2586 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect()); |
| 2587 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect()); |
| 2588 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2589 | } |
| 2590 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2591 | TEST_F(LayerTreeHostCommonTest, |
| 2592 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2593 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2594 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2595 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2596 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2597 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2598 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2599 | root->SetBounds(gfx::Size(100, 100)); |
| 2600 | child->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2601 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2602 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2603 | grand_child1->SetBounds(gfx::Size(50, 50)); |
| 2604 | grand_child1->SetDrawsContent(true); |
| 2605 | grand_child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 2606 | grand_child2->SetBounds(gfx::Size(50, 50)); |
| 2607 | grand_child2->SetDrawsContent(true); |
| 2608 | grand_child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 2609 | grand_child3->SetBounds(gfx::Size(50, 50)); |
| 2610 | grand_child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2611 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2612 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2613 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2614 | GetRenderSurface(root)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2615 | |
| 2616 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2617 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 2618 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2619 | |
| 2620 | // All grandchild visible content rects should be clipped by child. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2621 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); |
| 2622 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); |
| 2623 | EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2624 | |
| 2625 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2626 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 2627 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2628 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 2629 | } |
| 2630 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 2631 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2632 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 2633 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 2634 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 2635 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 2636 | gfx::Transform child_scale_matrix; |
| 2637 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 2638 | gfx::Transform grand_child_scale_matrix; |
| 2639 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 2640 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2641 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2642 | child->test_properties()->transform = child_scale_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2643 | child->SetBounds(gfx::Size(10, 10)); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 2644 | child->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2645 | grand_child->test_properties()->transform = grand_child_scale_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2646 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 2647 | grand_child->SetDrawsContent(true); |
| 2648 | ExecuteCalculateDrawProperties(root); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 2649 | |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 2650 | // The visible rect is expanded to integer coordinates. |
| 2651 | EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 2652 | } |
| 2653 | |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 2654 | TEST_F(LayerTreeHostCommonTest, VisibleRectWithClippingAndFilters) { |
| 2655 | LayerImpl* root = root_layer_for_testing(); |
| 2656 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 2657 | LayerImpl* filter = AddChild<LayerImpl>(clip); |
| 2658 | LayerImpl* filter_child = AddChild<LayerImpl>(filter); |
| 2659 | |
| 2660 | root->SetBounds(gfx::Size(100, 100)); |
| 2661 | clip->SetBounds(gfx::Size(10, 10)); |
| 2662 | filter->test_properties()->force_render_surface = true; |
| 2663 | filter_child->SetBounds(gfx::Size(2000, 2000)); |
| 2664 | filter_child->SetPosition(gfx::PointF(-50, -50)); |
| 2665 | filter_child->SetDrawsContent(true); |
| 2666 | |
| 2667 | clip->SetMasksToBounds(true); |
| 2668 | |
| 2669 | ExecuteCalculateDrawProperties(root); |
| 2670 | EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2671 | EXPECT_EQ(gfx::Rect(10, 10), GetRenderSurface(filter)->content_rect()); |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 2672 | |
| 2673 | FilterOperations blur_filter; |
| 2674 | blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); |
| 2675 | filter->test_properties()->filters = blur_filter; |
| 2676 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2677 | |
| 2678 | ExecuteCalculateDrawProperties(root); |
| 2679 | |
| 2680 | EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect()); |
| 2681 | EXPECT_EQ(gfx::Rect(-12, -12, 34, 34), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2682 | GetRenderSurface(filter)->content_rect()); |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 2683 | |
| 2684 | gfx::Transform vertical_flip; |
| 2685 | vertical_flip.Scale(1, -1); |
| 2686 | sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter( |
| 2687 | vertical_flip.matrix(), kLow_SkFilterQuality, nullptr); |
| 2688 | FilterOperations reflection_filter; |
| 2689 | reflection_filter.Append( |
| 2690 | FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make( |
| 2691 | SkBlendMode::kSrcOver, std::move(flip_filter)))); |
| 2692 | filter->test_properties()->filters = reflection_filter; |
| 2693 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2694 | |
| 2695 | ExecuteCalculateDrawProperties(root); |
| 2696 | |
| 2697 | EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect()); |
| 2698 | EXPECT_EQ(gfx::Rect(0, -10, 10, 20), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2699 | GetRenderSurface(filter)->content_rect()); |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | TEST_F(LayerTreeHostCommonTest, VisibleRectWithScalingClippingAndFilters) { |
| 2703 | LayerImpl* root = root_layer_for_testing(); |
| 2704 | LayerImpl* scale = AddChild<LayerImpl>(root); |
| 2705 | LayerImpl* clip = AddChild<LayerImpl>(scale); |
| 2706 | LayerImpl* filter = AddChild<LayerImpl>(clip); |
| 2707 | LayerImpl* filter_child = AddChild<LayerImpl>(filter); |
| 2708 | |
| 2709 | root->SetBounds(gfx::Size(100, 100)); |
| 2710 | clip->SetBounds(gfx::Size(10, 10)); |
| 2711 | filter->test_properties()->force_render_surface = true; |
| 2712 | filter_child->SetBounds(gfx::Size(2000, 2000)); |
| 2713 | filter_child->SetPosition(gfx::PointF(-50, -50)); |
| 2714 | filter_child->SetDrawsContent(true); |
| 2715 | |
| 2716 | clip->SetMasksToBounds(true); |
| 2717 | |
| 2718 | gfx::Transform scale_transform; |
| 2719 | scale_transform.Scale(3, 3); |
| 2720 | scale->test_properties()->transform = scale_transform; |
| 2721 | |
| 2722 | ExecuteCalculateDrawProperties(root); |
| 2723 | EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2724 | EXPECT_EQ(gfx::Rect(30, 30), GetRenderSurface(filter)->content_rect()); |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 2725 | |
| 2726 | FilterOperations blur_filter; |
| 2727 | blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); |
| 2728 | filter->test_properties()->filters = blur_filter; |
| 2729 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2730 | |
| 2731 | ExecuteCalculateDrawProperties(root); |
| 2732 | |
| 2733 | EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect()); |
| 2734 | EXPECT_EQ(gfx::Rect(-36, -36, 102, 102), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2735 | GetRenderSurface(filter)->content_rect()); |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 2736 | |
| 2737 | gfx::Transform vertical_flip; |
| 2738 | vertical_flip.Scale(1, -1); |
| 2739 | sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter( |
| 2740 | vertical_flip.matrix(), kLow_SkFilterQuality, nullptr); |
| 2741 | FilterOperations reflection_filter; |
| 2742 | reflection_filter.Append( |
| 2743 | FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make( |
| 2744 | SkBlendMode::kSrcOver, std::move(flip_filter)))); |
| 2745 | filter->test_properties()->filters = reflection_filter; |
| 2746 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2747 | |
| 2748 | ExecuteCalculateDrawProperties(root); |
| 2749 | |
| 2750 | EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect()); |
| 2751 | EXPECT_EQ(gfx::Rect(0, -30, 30, 60), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2752 | GetRenderSurface(filter)->content_rect()); |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | TEST_F(LayerTreeHostCommonTest, ClipRectWithClipParentAndFilters) { |
| 2756 | LayerImpl* root = root_layer_for_testing(); |
| 2757 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 2758 | LayerImpl* filter = AddChild<LayerImpl>(clip); |
| 2759 | LayerImpl* filter_child_1 = AddChild<LayerImpl>(filter); |
| 2760 | LayerImpl* filter_child_2 = AddChild<LayerImpl>(filter); |
| 2761 | |
| 2762 | root->SetBounds(gfx::Size(100, 100)); |
| 2763 | clip->SetBounds(gfx::Size(10, 10)); |
| 2764 | filter->test_properties()->force_render_surface = true; |
| 2765 | |
| 2766 | filter_child_1->SetBounds(gfx::Size(20, 20)); |
| 2767 | filter_child_1->SetDrawsContent(true); |
| 2768 | filter_child_2->SetBounds(gfx::Size(20, 20)); |
| 2769 | filter_child_2->SetDrawsContent(true); |
| 2770 | |
| 2771 | root->SetMasksToBounds(true); |
| 2772 | clip->SetMasksToBounds(true); |
| 2773 | |
| 2774 | root->test_properties()->clip_children = |
| 2775 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 2776 | root->test_properties()->clip_children->insert(filter_child_1); |
| 2777 | filter_child_1->test_properties()->clip_parent = root; |
| 2778 | |
| 2779 | ExecuteCalculateDrawProperties(root); |
| 2780 | EXPECT_TRUE(filter_child_1->is_clipped()); |
| 2781 | EXPECT_TRUE(filter_child_2->is_clipped()); |
| 2782 | EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect()); |
| 2783 | EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect()); |
| 2784 | |
| 2785 | FilterOperations blur_filter; |
| 2786 | blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); |
| 2787 | filter->test_properties()->filters = blur_filter; |
| 2788 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2789 | |
| 2790 | ExecuteCalculateDrawProperties(root); |
| 2791 | |
| 2792 | EXPECT_TRUE(filter_child_1->is_clipped()); |
| 2793 | EXPECT_TRUE(filter_child_2->is_clipped()); |
| 2794 | EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect()); |
| 2795 | EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect()); |
| 2796 | } |
| 2797 | |
| 2798 | TEST_F(LayerTreeHostCommonTest, ClipRectWithClippedDescendantOfFilter) { |
| 2799 | LayerImpl* root = root_layer_for_testing(); |
| 2800 | LayerImpl* filter = AddChild<LayerImpl>(root); |
| 2801 | LayerImpl* clip = AddChild<LayerImpl>(filter); |
| 2802 | LayerImpl* filter_grand_child = AddChild<LayerImpl>(clip); |
| 2803 | |
| 2804 | root->SetBounds(gfx::Size(100, 100)); |
| 2805 | filter->test_properties()->force_render_surface = true; |
| 2806 | |
| 2807 | clip->SetBounds(gfx::Size(10, 10)); |
| 2808 | clip->SetMasksToBounds(true); |
| 2809 | |
| 2810 | filter_grand_child->SetBounds(gfx::Size(20, 20)); |
| 2811 | filter_grand_child->SetDrawsContent(true); |
| 2812 | |
| 2813 | ExecuteCalculateDrawProperties(root); |
| 2814 | EXPECT_TRUE(filter_grand_child->is_clipped()); |
| 2815 | EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect()); |
| 2816 | |
| 2817 | FilterOperations blur_filter; |
| 2818 | blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); |
| 2819 | filter->test_properties()->filters = blur_filter; |
| 2820 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2821 | |
| 2822 | ExecuteCalculateDrawProperties(root); |
| 2823 | |
| 2824 | EXPECT_TRUE(filter_grand_child->is_clipped()); |
| 2825 | EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect()); |
| 2826 | } |
| 2827 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2828 | TEST_F(LayerTreeHostCommonTest, |
| 2829 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2830 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2831 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 2832 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2833 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2834 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2835 | |
| 2836 | root->SetBounds(gfx::Size(100, 100)); |
| 2837 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 2838 | render_surface->test_properties()->force_render_surface = true; |
| 2839 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2840 | child1->SetBounds(gfx::Size(50, 50)); |
| 2841 | child1->SetDrawsContent(true); |
| 2842 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 2843 | child2->SetBounds(gfx::Size(50, 50)); |
| 2844 | child2->SetDrawsContent(true); |
| 2845 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 2846 | child3->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2847 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2848 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2849 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2850 | ASSERT_TRUE(GetRenderSurface(render_surface)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2851 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2852 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2853 | GetRenderSurface(root)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2854 | |
| 2855 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2856 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2857 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2858 | |
| 2859 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 2860 | // regions of the subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2861 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2862 | GetRenderSurface(render_surface)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2863 | |
| 2864 | // All layers that draw content into the unclipped surface are also unclipped. |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 2865 | // Only the viewport clip should apply |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2866 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 2867 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 2868 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2869 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2870 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2871 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2872 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2873 | } |
| 2874 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2875 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2876 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2877 | LayerImpl* root = root_layer_for_testing(); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 2878 | LayerImpl* child1 = AddChild<LayerImpl>(root); |
| 2879 | LayerImpl* child2 = AddChild<LayerImpl>(root); |
| 2880 | LayerImpl* child3 = AddChild<LayerImpl>(root); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2881 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2882 | root->SetBounds(gfx::Size(100, 100)); |
| 2883 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2884 | child1->SetBounds(gfx::Size(50, 50)); |
| 2885 | child1->SetDrawsContent(true); |
| 2886 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 2887 | child2->SetBounds(gfx::Size(50, 50)); |
| 2888 | child2->SetDrawsContent(true); |
| 2889 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 2890 | child3->SetBounds(gfx::Size(50, 50)); |
| 2891 | child3->SetDrawsContent(true); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2892 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 2893 | RenderSurfaceList render_surface_list_impl; |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2894 | // Now set the root render surface an empty clip. |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 2895 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 2896 | root, gfx::Size(), &render_surface_list_impl); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2897 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 2898 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2899 | ASSERT_TRUE(GetRenderSurface(root)); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2900 | EXPECT_FALSE(root->is_clipped()); |
| 2901 | |
| 2902 | gfx::Rect empty; |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 2903 | EXPECT_EQ(empty, GetRenderSurface(root)->clip_rect()); |
| 2904 | EXPECT_TRUE(GetRenderSurface(root)->is_clipped()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2905 | |
| 2906 | // Visible content rect calculation will check if the target surface is |
| 2907 | // clipped or not. An empty clip rect does not indicate the render surface |
| 2908 | // is unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2909 | EXPECT_EQ(empty, child1->visible_layer_rect()); |
| 2910 | EXPECT_EQ(empty, child2->visible_layer_rect()); |
| 2911 | EXPECT_EQ(empty, child3->visible_layer_rect()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2915 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2916 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2917 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2918 | |
| 2919 | root->SetBounds(gfx::Size(100, 100)); |
| 2920 | child->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2921 | child->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2922 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2923 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2924 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2925 | 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] | 2926 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2927 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2928 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2929 | ExecuteCalculateDrawProperties(root); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2930 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2931 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2932 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2933 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2934 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 2935 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2936 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2937 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2938 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2939 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2940 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2941 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2942 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2943 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2944 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2945 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2946 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2947 | uninvertible_matrix.MakeIdentity(); |
| 2948 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2949 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2950 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2951 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2952 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2953 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2954 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2955 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2956 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2957 | } |
| 2958 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2959 | TEST_F(LayerTreeHostCommonTest, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 2960 | VisibleContentRectForLayerWithUninvertibleDrawTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2961 | LayerImpl* root = root_layer_for_testing(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 2962 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2963 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 2964 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 2965 | gfx::Transform perspective; |
| 2966 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 2967 | |
| 2968 | gfx::Transform rotation; |
| 2969 | rotation.RotateAboutYAxis(45.0); |
| 2970 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2971 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2972 | child->test_properties()->transform = perspective; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2973 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 2974 | child->SetBounds(gfx::Size(100, 100)); |
| 2975 | child->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 2976 | child->test_properties()->sorting_context_id = 1; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2977 | child->test_properties()->should_flatten_transform = false; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2978 | grand_child->test_properties()->transform = rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2979 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 2980 | grand_child->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 2981 | child->test_properties()->sorting_context_id = 1; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2982 | grand_child->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 2983 | grand_child->test_properties()->sorting_context_id = 1; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 2984 | ExecuteCalculateDrawProperties(root); |
| 2985 | |
| 2986 | // Though all layers have invertible transforms, matrix multiplication using |
| 2987 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 2988 | EXPECT_FALSE(root->layer_tree_impl() |
| 2989 | ->property_trees() |
| 2990 | ->transform_tree.Node(grand_child->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 2991 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 2992 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 2993 | // CalcDrawProps skips a subtree when a layer's screen space transform is |
| 2994 | // uninvertible |
| 2995 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 2996 | } |
| 2997 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 2998 | TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) { |
| 2999 | FakeImplTaskRunnerProvider task_runner_provider; |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3000 | TestTaskGraphRunner task_graph_runner; |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 3001 | std::unique_ptr<LayerTreeFrameSink> layer_tree_frame_sink = |
| 3002 | FakeLayerTreeFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 3003 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3004 | |
| 3005 | std::unique_ptr<LayerImpl> root = |
| 3006 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3007 | std::unique_ptr<LayerImpl> child = |
| 3008 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3009 | std::unique_ptr<TextureLayerImpl> surface = |
| 3010 | TextureLayerImpl::Create(host_impl.active_tree(), 3); |
| 3011 | std::unique_ptr<TextureLayerImpl> surface_child = |
| 3012 | TextureLayerImpl::Create(host_impl.active_tree(), 4); |
| 3013 | std::unique_ptr<TextureLayerImpl> surface_sibling = |
| 3014 | TextureLayerImpl::Create(host_impl.active_tree(), 5); |
| 3015 | std::unique_ptr<TextureLayerImpl> surface_child_mask = |
| 3016 | TextureLayerImpl::Create(host_impl.active_tree(), 6); |
| 3017 | |
| 3018 | surface->SetDrawsContent(true); |
| 3019 | surface_child->SetDrawsContent(true); |
| 3020 | surface_sibling->SetDrawsContent(true); |
| 3021 | surface_child_mask->SetDrawsContent(true); |
| 3022 | surface->SetContentsOpaque(true); |
| 3023 | surface_child->SetContentsOpaque(true); |
| 3024 | surface_sibling->SetContentsOpaque(true); |
| 3025 | surface_child_mask->SetContentsOpaque(true); |
| 3026 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3027 | gfx::Transform translate; |
| 3028 | translate.Translate(20.f, 20.f); |
| 3029 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3030 | root->SetBounds(gfx::Size(1000, 1000)); |
| 3031 | child->SetBounds(gfx::Size(300, 300)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3032 | surface->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3033 | surface->SetBounds(gfx::Size(300, 300)); |
| 3034 | surface->test_properties()->force_render_surface = true; |
| 3035 | surface_child->SetBounds(gfx::Size(300, 300)); |
| 3036 | surface_child->test_properties()->force_render_surface = true; |
| 3037 | surface_sibling->SetBounds(gfx::Size(200, 200)); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3038 | |
| 3039 | LayerImpl* surface_ptr = surface.get(); |
| 3040 | LayerImpl* surface_child_ptr = surface_child.get(); |
| 3041 | LayerImpl* surface_child_mask_ptr = surface_child_mask.get(); |
| 3042 | |
| 3043 | host_impl.SetViewportSize(root->bounds()); |
| 3044 | |
| 3045 | surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask)); |
| 3046 | surface->test_properties()->AddChild(std::move(surface_child)); |
| 3047 | child->test_properties()->AddChild(std::move(surface)); |
| 3048 | child->test_properties()->AddChild(std::move(surface_sibling)); |
| 3049 | root->test_properties()->AddChild(std::move(child)); |
| 3050 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 3051 | host_impl.SetVisible(true); |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 3052 | host_impl.InitializeRenderer(layer_tree_frame_sink.get()); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3053 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
Vladimir Levin | 55c6640 | 2017-07-13 02:21:06 | [diff] [blame] | 3054 | host_impl.active_tree()->UpdateDrawProperties(); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3055 | |
| 3056 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3057 | GetRenderSurface(surface_ptr)->draw_transform(), translate); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3058 | // surface_sibling draws into the root render surface and occludes |
| 3059 | // surface_child's contents. |
| 3060 | Occlusion actual_occlusion = |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3061 | GetRenderSurface(surface_child_ptr)->occlusion_in_content_space(); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3062 | Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()), |
| 3063 | SimpleEnclosedRegion(gfx::Rect(200, 200))); |
| 3064 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3065 | |
| 3066 | // Mask layer should have the same occlusion. |
| 3067 | actual_occlusion = |
| 3068 | surface_child_mask_ptr->draw_properties().occlusion_in_content_space; |
| 3069 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3070 | } |
| 3071 | |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3072 | TEST_F(LayerTreeHostCommonTest, TextureLayerSnapping) { |
| 3073 | FakeImplTaskRunnerProvider task_runner_provider; |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3074 | TestTaskGraphRunner task_graph_runner; |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 3075 | std::unique_ptr<LayerTreeFrameSink> layer_tree_frame_sink = |
| 3076 | FakeLayerTreeFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 3077 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3078 | |
| 3079 | std::unique_ptr<LayerImpl> root = |
| 3080 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3081 | std::unique_ptr<TextureLayerImpl> child = |
| 3082 | TextureLayerImpl::Create(host_impl.active_tree(), 2); |
| 3083 | |
| 3084 | LayerImpl* child_ptr = child.get(); |
| 3085 | |
| 3086 | root->SetBounds(gfx::Size(100, 100)); |
| 3087 | child->SetBounds(gfx::Size(100, 100)); |
| 3088 | child->SetDrawsContent(true); |
| 3089 | gfx::Transform fractional_translate; |
| 3090 | fractional_translate.Translate(10.5f, 20.3f); |
| 3091 | child->test_properties()->transform = fractional_translate; |
| 3092 | |
| 3093 | host_impl.SetViewportSize(root->bounds()); |
| 3094 | |
| 3095 | root->test_properties()->AddChild(std::move(child)); |
| 3096 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 3097 | host_impl.SetVisible(true); |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 3098 | host_impl.InitializeRenderer(layer_tree_frame_sink.get()); |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3099 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
Vladimir Levin | 55c6640 | 2017-07-13 02:21:06 | [diff] [blame] | 3100 | host_impl.active_tree()->UpdateDrawProperties(); |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3101 | |
| 3102 | EXPECT_NE(child_ptr->ScreenSpaceTransform(), fractional_translate); |
| 3103 | fractional_translate.RoundTranslationComponents(); |
| 3104 | EXPECT_TRANSFORMATION_MATRIX_EQ(child_ptr->ScreenSpaceTransform(), |
| 3105 | fractional_translate); |
| 3106 | gfx::RectF layer_bounds_in_screen_space = |
| 3107 | MathUtil::MapClippedRect(child_ptr->ScreenSpaceTransform(), |
| 3108 | gfx::RectF(gfx::SizeF(child_ptr->bounds()))); |
| 3109 | EXPECT_EQ(layer_bounds_in_screen_space, gfx::RectF(11.f, 20.f, 100.f, 100.f)); |
| 3110 | } |
| 3111 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3112 | TEST_F(LayerTreeHostCommonTest, |
| 3113 | OcclusionForLayerWithUninvertibleDrawTransform) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3114 | FakeImplTaskRunnerProvider task_runner_provider; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3115 | TestTaskGraphRunner task_graph_runner; |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 3116 | std::unique_ptr<LayerTreeFrameSink> layer_tree_frame_sink = |
| 3117 | FakeLayerTreeFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 3118 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3119 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3120 | std::unique_ptr<LayerImpl> root = |
| 3121 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3122 | std::unique_ptr<LayerImpl> child = |
| 3123 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3124 | std::unique_ptr<LayerImpl> grand_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3125 | LayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3126 | std::unique_ptr<LayerImpl> occluding_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3127 | LayerImpl::Create(host_impl.active_tree(), 4); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3128 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3129 | gfx::Transform perspective; |
| 3130 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3131 | |
| 3132 | gfx::Transform rotation; |
| 3133 | rotation.RotateAboutYAxis(45.0); |
| 3134 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3135 | root->SetBounds(gfx::Size(1000, 1000)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3136 | child->test_properties()->transform = perspective; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3137 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 3138 | child->SetBounds(gfx::Size(300, 300)); |
| 3139 | child->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 3140 | child->test_properties()->sorting_context_id = 1; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3141 | grand_child->test_properties()->transform = rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3142 | grand_child->SetBounds(gfx::Size(200, 200)); |
| 3143 | grand_child->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 3144 | grand_child->test_properties()->sorting_context_id = 1; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3145 | occluding_child->SetBounds(gfx::Size(200, 200)); |
| 3146 | occluding_child->test_properties()->should_flatten_transform = false; |
| 3147 | |
| 3148 | child->SetDrawsContent(true); |
| 3149 | grand_child->SetDrawsContent(true); |
| 3150 | occluding_child->SetDrawsContent(true); |
| 3151 | occluding_child->SetContentsOpaque(true); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3152 | |
| 3153 | host_impl.SetViewportSize(root->bounds()); |
| 3154 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3155 | child->test_properties()->AddChild(std::move(grand_child)); |
| 3156 | root->test_properties()->AddChild(std::move(child)); |
| 3157 | root->test_properties()->AddChild(std::move(occluding_child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3158 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 3159 | host_impl.SetVisible(true); |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 3160 | host_impl.InitializeRenderer(layer_tree_frame_sink.get()); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 3161 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
Vladimir Levin | 55c6640 | 2017-07-13 02:21:06 | [diff] [blame] | 3162 | host_impl.active_tree()->UpdateDrawProperties(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3163 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3164 | LayerImpl* grand_child_ptr = host_impl.active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3165 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3166 | ->test_properties() |
| 3167 | ->children[0] |
| 3168 | ->test_properties() |
| 3169 | ->children[0]; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3170 | |
| 3171 | // Though all layers have invertible transforms, matrix multiplication using |
| 3172 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3173 | EXPECT_FALSE( |
| 3174 | host_impl.active_tree() |
| 3175 | ->property_trees() |
| 3176 | ->transform_tree.Node(grand_child_ptr->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3177 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3178 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3179 | // Since |grand_child| has an uninvertible screen space transform, it is |
| 3180 | // skipped so |
| 3181 | // that we are not computing its occlusion_in_content_space. |
| 3182 | gfx::Rect layer_bounds = gfx::Rect(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3183 | EXPECT_EQ( |
| 3184 | layer_bounds, |
| 3185 | grand_child_ptr->draw_properties() |
| 3186 | .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds)); |
| 3187 | } |
| 3188 | |
| 3189 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3190 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3191 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3192 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3193 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3194 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3195 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3196 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3197 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3198 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3199 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3200 | render_surface->test_properties()->force_render_surface = true; |
| 3201 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3202 | child1->SetBounds(gfx::Size(50, 50)); |
| 3203 | child1->SetDrawsContent(true); |
| 3204 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3205 | child2->SetBounds(gfx::Size(50, 50)); |
| 3206 | child2->SetDrawsContent(true); |
| 3207 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3208 | child3->SetBounds(gfx::Size(50, 50)); |
| 3209 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3210 | ExecuteCalculateDrawProperties(root); |
| 3211 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3212 | ASSERT_TRUE(GetRenderSurface(render_surface)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3213 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3214 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3215 | GetRenderSurface(root)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3216 | |
| 3217 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3218 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3219 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3220 | |
| 3221 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3222 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3223 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3224 | GetRenderSurface(render_surface)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3225 | |
| 3226 | // All layers that draw content into the surface have their visible content |
| 3227 | // rect clipped by the surface clip rect. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3228 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3229 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3230 | EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3231 | |
| 3232 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3233 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3234 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3235 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3236 | } |
| 3237 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3238 | TEST_F(LayerTreeHostCommonTest, |
| 3239 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3240 | // Check that clipping does not propagate down surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3241 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3242 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3243 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 3244 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3245 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3246 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3247 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3248 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3249 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3250 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 3251 | render_surface1->test_properties()->force_render_surface = true; |
| 3252 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 3253 | render_surface2->test_properties()->force_render_surface = true; |
| 3254 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3255 | child1->SetBounds(gfx::Size(50, 50)); |
| 3256 | child1->SetDrawsContent(true); |
| 3257 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3258 | child2->SetBounds(gfx::Size(50, 50)); |
| 3259 | child2->SetDrawsContent(true); |
| 3260 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3261 | child3->SetBounds(gfx::Size(50, 50)); |
| 3262 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3263 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3264 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3265 | ASSERT_TRUE(GetRenderSurface(render_surface1)); |
| 3266 | ASSERT_TRUE(GetRenderSurface(render_surface2)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3267 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3268 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3269 | GetRenderSurface(root)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3270 | |
| 3271 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3272 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3273 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); |
| 3274 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3275 | |
| 3276 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3277 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3278 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3279 | GetRenderSurface(render_surface1)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3280 | |
| 3281 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3282 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3283 | // render_surface2 grows to enclose all drawable content of its subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3284 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3285 | GetRenderSurface(render_surface2)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3286 | |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3287 | // All layers that draw content into render_surface2 think they are unclipped |
| 3288 | // by the surface. So, only the viewport clip applies. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3289 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3290 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3291 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3292 | |
| 3293 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3294 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3295 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3296 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3297 | } |
| 3298 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3299 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3300 | VisibleRectsForClippedDescendantsOfUnclippedSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3301 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3302 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3303 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 3304 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 3305 | LayerImpl* render_surface2 = AddChild<LayerImpl>(child2); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3306 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3307 | root->SetBounds(gfx::Size(100, 100)); |
| 3308 | render_surface1->SetBounds(gfx::Size(100, 100)); |
| 3309 | render_surface1->test_properties()->force_render_surface = true; |
| 3310 | child1->SetBounds(gfx::Size(500, 500)); |
| 3311 | child1->SetDrawsContent(true); |
| 3312 | child2->SetBounds(gfx::Size(700, 700)); |
| 3313 | child2->SetDrawsContent(true); |
| 3314 | render_surface2->SetBounds(gfx::Size(1000, 1000)); |
| 3315 | render_surface2->test_properties()->force_render_surface = true; |
| 3316 | render_surface2->SetDrawsContent(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3317 | |
| 3318 | child1->SetMasksToBounds(true); |
| 3319 | child2->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3320 | ExecuteCalculateDrawProperties(root); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3321 | EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3322 | EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3323 | } |
| 3324 | |
| 3325 | TEST_F(LayerTreeHostCommonTest, |
| 3326 | VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3327 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3328 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3329 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3330 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3331 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3332 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3333 | root->SetBounds(gfx::Size(100, 100)); |
| 3334 | |
| 3335 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3336 | clip_parent->SetMasksToBounds(true); |
| 3337 | clip_parent->test_properties()->clip_children = |
| 3338 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3339 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3340 | |
| 3341 | render_surface1->SetBounds(gfx::Size(20, 20)); |
| 3342 | render_surface1->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3343 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3344 | render_surface1->test_properties()->force_render_surface = true; |
| 3345 | |
| 3346 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3347 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3348 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3349 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3350 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 3351 | render_surface2->SetDrawsContent(true); |
| 3352 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3353 | |
| 3354 | ExecuteCalculateDrawProperties(root); |
| 3355 | EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect()); |
| 3356 | EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect()); |
| 3357 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect()); |
| 3358 | } |
| 3359 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3360 | TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3361 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3362 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 3363 | LayerImpl* clip_layer = AddChild<LayerImpl>(clip_parent); |
| 3364 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_layer); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3365 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3366 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3367 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3368 | root->SetBounds(gfx::Size(100, 100)); |
| 3369 | |
| 3370 | clip_parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 3371 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3372 | clip_parent->test_properties()->clip_children = |
| 3373 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3374 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3375 | |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 3376 | clip_layer->SetBounds(gfx::Size(50, 50)); |
| 3377 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3378 | render_surface1->SetBounds(gfx::Size(20, 20)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3379 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3380 | render_surface1->test_properties()->force_render_surface = true; |
| 3381 | |
| 3382 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3383 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3384 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3385 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3386 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 3387 | render_surface2->SetDrawsContent(true); |
| 3388 | render_surface2->test_properties()->force_render_surface = true; |
| 3389 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3390 | clip_parent->SetMasksToBounds(true); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 3391 | clip_layer->SetMasksToBounds(true); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3392 | render_surface1->SetMasksToBounds(true); |
| 3393 | |
jaydasika | 44b074e | 2017-03-07 21:11:38 | [diff] [blame] | 3394 | float device_scale_factor = 1.f; |
| 3395 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3396 | EXPECT_EQ(gfx::Rect(50, 50), GetRenderSurface(render_surface2)->clip_rect()); |
jaydasika | 44b074e | 2017-03-07 21:11:38 | [diff] [blame] | 3397 | device_scale_factor = 2.f; |
| 3398 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 3399 | EXPECT_EQ(gfx::Rect(100, 100), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3400 | GetRenderSurface(render_surface2)->clip_rect()); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3401 | } |
| 3402 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3403 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) { |
| 3404 | // Test that only drawn layers contribute to render surface content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3405 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3406 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 3407 | LayerImpl* test_layer = AddChild<LayerImpl>(surface); |
| 3408 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3409 | root->SetBounds(gfx::Size(200, 200)); |
| 3410 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3411 | surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3412 | surface->test_properties()->force_render_surface = true; |
| 3413 | test_layer->SetBounds(gfx::Size(150, 150)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3414 | |
| 3415 | ExecuteCalculateDrawProperties(root); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3416 | EXPECT_EQ(gfx::Rect(100, 100), GetRenderSurface(surface)->content_rect()); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3417 | |
| 3418 | test_layer->SetDrawsContent(true); |
| 3419 | ExecuteCalculateDrawProperties(root); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3420 | EXPECT_EQ(gfx::Rect(150, 150), GetRenderSurface(surface)->content_rect()); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3421 | } |
| 3422 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3423 | TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) { |
| 3424 | // Tests visible rects computation when we have unclipped_surface-> |
| 3425 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3426 | // of surface_with_unclipped_descendants doesn't propagate to the |
| 3427 | // clipped_surface below it. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3428 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3429 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3430 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3431 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3432 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3433 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3434 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3435 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3436 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3437 | unclipped_surface->SetBounds(gfx::Size(30, 30)); |
| 3438 | unclipped_surface->SetDrawsContent(true); |
| 3439 | unclipped_surface->test_properties()->force_render_surface = true; |
| 3440 | |
| 3441 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3442 | clip_parent->test_properties()->clip_children = |
| 3443 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3444 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3445 | |
| 3446 | unclipped_desc_surface->SetBounds(gfx::Size(20, 20)); |
| 3447 | unclipped_desc_surface->SetDrawsContent(true); |
| 3448 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 3449 | |
| 3450 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 3451 | clip_child->test_properties()->clip_parent = clip_parent; |
| 3452 | |
| 3453 | clipped_surface->SetBounds(gfx::Size(60, 60)); |
| 3454 | clipped_surface->SetDrawsContent(true); |
| 3455 | clipped_surface->test_properties()->force_render_surface = true; |
| 3456 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3457 | clip_parent->SetMasksToBounds(true); |
| 3458 | |
| 3459 | ExecuteCalculateDrawProperties(root); |
| 3460 | EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect()); |
| 3461 | EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect()); |
| 3462 | EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect()); |
| 3463 | } |
| 3464 | |
| 3465 | TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) { |
| 3466 | // Tests visible rects computation when we have unclipped_surface-> |
| 3467 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3468 | // of root propagate to the clipped_surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3469 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3470 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3471 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3472 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3473 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3474 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3475 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3476 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3477 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3478 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
| 3479 | unclipped_surface->SetDrawsContent(true); |
| 3480 | unclipped_surface->test_properties()->force_render_surface = true; |
| 3481 | |
| 3482 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3483 | clip_parent->test_properties()->clip_children = |
| 3484 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3485 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3486 | |
| 3487 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 3488 | unclipped_desc_surface->SetDrawsContent(true); |
| 3489 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 3490 | |
| 3491 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 3492 | clip_child->test_properties()->clip_parent = clip_parent; |
| 3493 | |
| 3494 | clipped_surface->SetBounds(gfx::Size(50, 50)); |
| 3495 | clipped_surface->SetDrawsContent(true); |
| 3496 | clipped_surface->test_properties()->force_render_surface = true; |
| 3497 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3498 | clip_parent->SetMasksToBounds(true); |
| 3499 | unclipped_desc_surface->SetMasksToBounds(true); |
| 3500 | |
| 3501 | ExecuteCalculateDrawProperties(root); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3502 | EXPECT_EQ(gfx::Rect(10, 10), unclipped_surface->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3503 | EXPECT_EQ(gfx::Rect(10, 10), unclipped_desc_surface->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3504 | EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect()); |
| 3505 | } |
| 3506 | |
| 3507 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3508 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3509 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3510 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3511 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3512 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3513 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3514 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3515 | gfx::Transform child_rotation; |
| 3516 | child_rotation.Rotate(45.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3517 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3518 | root->SetBounds(gfx::Size(100, 100)); |
| 3519 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3520 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3521 | child1->test_properties()->transform = child_rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3522 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 3523 | child1->SetBounds(gfx::Size(50, 50)); |
| 3524 | child1->SetDrawsContent(true); |
| 3525 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3526 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3527 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3528 | ASSERT_TRUE(GetRenderSurface(render_surface)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3529 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3530 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3531 | GetRenderSurface(root)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3532 | |
| 3533 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3534 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3535 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3536 | |
| 3537 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3538 | // regions of the subtree. |
| 3539 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3540 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3541 | gfx::Rect(50 - diagonal_radius, |
| 3542 | 50 - diagonal_radius, |
| 3543 | diagonal_radius * 2, |
| 3544 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3545 | EXPECT_EQ(gfx::RectF(expected_surface_drawable_content), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3546 | GetRenderSurface(render_surface)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3547 | |
| 3548 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3549 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3550 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3551 | } |
| 3552 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3553 | TEST_F(LayerTreeHostCommonTest, |
| 3554 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3555 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3556 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3557 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3558 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3559 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3560 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3561 | gfx::Transform child_rotation; |
| 3562 | child_rotation.Rotate(45.0); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3563 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3564 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3565 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3566 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3567 | render_surface->test_properties()->force_render_surface = true; |
| 3568 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 3569 | child1->SetBounds(gfx::Size(50, 50)); |
| 3570 | child1->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3571 | child1->test_properties()->transform = child_rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3572 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3573 | ExecuteCalculateDrawProperties(root); |
| 3574 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3575 | ASSERT_TRUE(GetRenderSurface(render_surface)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3576 | |
| 3577 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3578 | // rotated layer. |
| 3579 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3580 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3581 | 50 - diagonal_radius, |
| 3582 | diagonal_radius * 2, |
| 3583 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3584 | gfx::RectF expected_surface_drawable_content( |
| 3585 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3586 | EXPECT_EQ(expected_surface_drawable_content, |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3587 | GetRenderSurface(render_surface)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3588 | |
| 3589 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3590 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3591 | // up covering the full left half of child1. |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 3592 | EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3593 | |
| 3594 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3595 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3596 | } |
| 3597 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3598 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3599 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3600 | FakePictureLayerImpl* render_surface1 = |
| 3601 | AddChildToRoot<FakePictureLayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3602 | FakePictureLayerImpl* render_surface2 = |
| 3603 | AddChild<FakePictureLayerImpl>(render_surface1); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3604 | FakePictureLayerImpl* child1 = |
| 3605 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3606 | FakePictureLayerImpl* child2 = |
| 3607 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3608 | FakePictureLayerImpl* child3 = |
| 3609 | AddChild<FakePictureLayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3610 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3611 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3612 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3613 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 3614 | render_surface1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3615 | render_surface1->SetDrawsContent(true); |
| 3616 | render_surface1->test_properties()->force_render_surface = true; |
| 3617 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 3618 | render_surface2->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3619 | render_surface2->SetDrawsContent(true); |
| 3620 | render_surface2->test_properties()->force_render_surface = true; |
| 3621 | child1->SetBounds(gfx::Size(50, 50)); |
| 3622 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3623 | child1->SetDrawsContent(true); |
| 3624 | child2->SetBounds(gfx::Size(50, 50)); |
| 3625 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3626 | child2->SetDrawsContent(true); |
| 3627 | child3->SetBounds(gfx::Size(50, 50)); |
| 3628 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3629 | child3->SetDrawsContent(true); |
| 3630 | float device_scale_factor = 2.f; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3631 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3632 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3633 | ASSERT_TRUE(GetRenderSurface(render_surface1)); |
| 3634 | ASSERT_TRUE(GetRenderSurface(render_surface2)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3635 | |
| 3636 | // drawable_content_rects for all layers and surfaces are scaled by |
| 3637 | // device_scale_factor. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3638 | EXPECT_EQ(gfx::RectF(200.f, 200.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3639 | GetRenderSurface(root)->DrawableContentRect()); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3640 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3641 | GetRenderSurface(render_surface1)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3642 | |
| 3643 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3644 | // is only implicitly clipped by render_surface1. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3645 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3646 | GetRenderSurface(render_surface2)->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3647 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3648 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3649 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 3650 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3651 | |
| 3652 | // The root layer does not actually draw content of its own. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3653 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3654 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3655 | // All layer visible content rects are not expressed in content space of each |
| 3656 | // layer, so they are not scaled by the device_scale_factor. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3657 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect()); |
| 3658 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect()); |
| 3659 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3660 | EXPECT_EQ(gfx::Rect(0, 0, 15, 15), child2->visible_layer_rect()); |
| 3661 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3662 | } |
| 3663 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3664 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3665 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 3666 | // layers. Note that 3d transforms still apply in this case, but they are |
| 3667 | // "flattened" to each parent layer according to current W3C spec. |
| 3668 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3669 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 3670 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 3671 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 3672 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 3673 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 3674 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 3675 | AddChild<LayerImpl>(front_facing_surface); |
| 3676 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 3677 | AddChild<LayerImpl>(front_facing_surface); |
| 3678 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 3679 | AddChild<LayerImpl>(back_facing_surface); |
| 3680 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 3681 | AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3682 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3683 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 3684 | front_facing_child->test_properties()->double_sided = false; |
| 3685 | back_facing_child->test_properties()->double_sided = false; |
| 3686 | front_facing_surface->test_properties()->double_sided = false; |
| 3687 | back_facing_surface->test_properties()->double_sided = false; |
| 3688 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 3689 | false; |
| 3690 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 3691 | false; |
| 3692 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 3693 | false; |
| 3694 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 3695 | false; |
| 3696 | |
| 3697 | // Everything draws content. |
| 3698 | front_facing_child->SetDrawsContent(true); |
| 3699 | back_facing_child->SetDrawsContent(true); |
| 3700 | front_facing_surface->SetDrawsContent(true); |
| 3701 | back_facing_surface->SetDrawsContent(true); |
| 3702 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 3703 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 3704 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 3705 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3706 | |
| 3707 | gfx::Transform backface_matrix; |
| 3708 | backface_matrix.Translate(50.0, 50.0); |
| 3709 | backface_matrix.RotateAboutYAxis(180.0); |
| 3710 | backface_matrix.Translate(-50.0, -50.0); |
| 3711 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3712 | root->SetBounds(gfx::Size(100, 100)); |
| 3713 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 3714 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 3715 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3716 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3717 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3718 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3719 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3720 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3721 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3722 | front_facing_surface->test_properties()->force_render_surface = true; |
| 3723 | back_facing_surface->test_properties()->force_render_surface = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3724 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3725 | back_facing_child->test_properties()->transform = backface_matrix; |
| 3726 | back_facing_surface->test_properties()->transform = backface_matrix; |
| 3727 | back_facing_child_of_front_facing_surface->test_properties()->transform = |
| 3728 | backface_matrix; |
| 3729 | back_facing_child_of_back_facing_surface->test_properties()->transform = |
| 3730 | backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3731 | |
| 3732 | // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms |
| 3733 | // spec, these layers should blindly use their own local transforms to |
| 3734 | // determine back-face culling. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 3735 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3736 | |
| 3737 | // Verify which render surfaces were created. |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 3738 | EXPECT_EQ(GetRenderSurface(front_facing_child), GetRenderSurface(root)); |
| 3739 | EXPECT_EQ(GetRenderSurface(back_facing_child), GetRenderSurface(root)); |
| 3740 | EXPECT_NE(GetRenderSurface(front_facing_surface), GetRenderSurface(root)); |
| 3741 | EXPECT_NE(GetRenderSurface(back_facing_surface), GetRenderSurface(root)); |
| 3742 | EXPECT_NE(GetRenderSurface(back_facing_surface), |
| 3743 | GetRenderSurface(front_facing_surface)); |
| 3744 | EXPECT_EQ(GetRenderSurface(front_facing_child_of_front_facing_surface), |
| 3745 | GetRenderSurface(front_facing_surface)); |
| 3746 | EXPECT_EQ(GetRenderSurface(back_facing_child_of_front_facing_surface), |
| 3747 | GetRenderSurface(front_facing_surface)); |
| 3748 | EXPECT_EQ(GetRenderSurface(front_facing_child_of_back_facing_surface), |
| 3749 | GetRenderSurface(back_facing_surface)); |
| 3750 | EXPECT_EQ(GetRenderSurface(back_facing_child_of_back_facing_surface), |
| 3751 | GetRenderSurface(back_facing_surface)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3752 | |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame] | 3753 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 3754 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 3755 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 3756 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 3757 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3758 | } |
| 3759 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3760 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3761 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 3762 | // is used. |
| 3763 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3764 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3765 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 3766 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 3767 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 3768 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 3769 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 3770 | AddChild<LayerImpl>(front_facing_surface); |
| 3771 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 3772 | AddChild<LayerImpl>(front_facing_surface); |
| 3773 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 3774 | AddChild<LayerImpl>(back_facing_surface); |
| 3775 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 3776 | AddChild<LayerImpl>(back_facing_surface); |
| 3777 | // Opacity will not force creation of render surfaces in this case because of |
| 3778 | // the preserve-3d transform style. Instead, an example of when a surface |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 3779 | // would be created with preserve-3d is when there is a mask layer. |
| 3780 | LayerImpl* dummy_mask_layer1 = AddMaskLayer<LayerImpl>(front_facing_surface); |
| 3781 | LayerImpl* dummy_mask_layer2 = AddMaskLayer<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3782 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3783 | // Nothing is double-sided |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3784 | front_facing_child->test_properties()->double_sided = false; |
| 3785 | back_facing_child->test_properties()->double_sided = false; |
| 3786 | front_facing_surface->test_properties()->double_sided = false; |
| 3787 | back_facing_surface->test_properties()->double_sided = false; |
| 3788 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 3789 | false; |
| 3790 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 3791 | false; |
| 3792 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 3793 | false; |
| 3794 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 3795 | false; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3796 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3797 | // Everything draws content. |
| 3798 | front_facing_child->SetDrawsContent(true); |
| 3799 | back_facing_child->SetDrawsContent(true); |
| 3800 | front_facing_surface->SetDrawsContent(true); |
| 3801 | back_facing_surface->SetDrawsContent(true); |
| 3802 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 3803 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 3804 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 3805 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 3806 | dummy_mask_layer1->SetDrawsContent(true); |
| 3807 | dummy_mask_layer2->SetDrawsContent(true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3808 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3809 | gfx::Transform backface_matrix; |
| 3810 | backface_matrix.Translate(50.0, 50.0); |
| 3811 | backface_matrix.RotateAboutYAxis(180.0); |
| 3812 | backface_matrix.Translate(-50.0, -50.0); |
| 3813 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3814 | root->SetBounds(gfx::Size(100, 100)); |
| 3815 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 3816 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 3817 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3818 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3819 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3820 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3821 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3822 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3823 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3824 | back_facing_child->test_properties()->transform = backface_matrix; |
| 3825 | back_facing_surface->test_properties()->transform = backface_matrix; |
| 3826 | back_facing_child_of_front_facing_surface->test_properties()->transform = |
| 3827 | backface_matrix; |
| 3828 | back_facing_child_of_back_facing_surface->test_properties()->transform = |
| 3829 | backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3830 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3831 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 3832 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 3833 | // rendering context should use the transform with respect to that context. |
| 3834 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 3835 | // and (b) the layer's transform style is preserve-3d. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3836 | front_facing_surface->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 3837 | front_facing_surface->test_properties()->sorting_context_id = 1; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3838 | back_facing_surface->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 3839 | back_facing_surface->test_properties()->sorting_context_id = 1; |
| 3840 | front_facing_child_of_front_facing_surface->test_properties() |
| 3841 | ->sorting_context_id = 1; |
| 3842 | back_facing_child_of_front_facing_surface->test_properties() |
| 3843 | ->sorting_context_id = 1; |
| 3844 | front_facing_child_of_back_facing_surface->test_properties() |
| 3845 | ->sorting_context_id = 1; |
| 3846 | back_facing_child_of_back_facing_surface->test_properties() |
| 3847 | ->sorting_context_id = 1; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3848 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 3849 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3850 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3851 | // Verify which render surfaces were created and used. |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 3852 | EXPECT_EQ(GetRenderSurface(front_facing_child), GetRenderSurface(root)); |
| 3853 | EXPECT_EQ(GetRenderSurface(back_facing_child), GetRenderSurface(root)); |
| 3854 | EXPECT_NE(GetRenderSurface(front_facing_surface), GetRenderSurface(root)); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 3855 | // We expect that a has_render_surface was created but not used. |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 3856 | EXPECT_NE(GetRenderSurface(back_facing_surface), GetRenderSurface(root)); |
| 3857 | EXPECT_NE(GetRenderSurface(back_facing_surface), |
| 3858 | GetRenderSurface(front_facing_surface)); |
| 3859 | EXPECT_EQ(GetRenderSurface(front_facing_child_of_front_facing_surface), |
| 3860 | GetRenderSurface(front_facing_surface)); |
| 3861 | EXPECT_EQ(GetRenderSurface(back_facing_child_of_front_facing_surface), |
| 3862 | GetRenderSurface(front_facing_surface)); |
| 3863 | EXPECT_EQ(GetRenderSurface(front_facing_child_of_back_facing_surface), |
| 3864 | GetRenderSurface(back_facing_surface)); |
| 3865 | EXPECT_EQ(GetRenderSurface(back_facing_child_of_back_facing_surface), |
| 3866 | GetRenderSurface(back_facing_surface)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3867 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3868 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3869 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3870 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 3871 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 3872 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 3873 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3874 | } |
| 3875 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3876 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3877 | // Verify that layers are appropriately culled when their back face is showing |
| 3878 | // and they are not double sided, while animations are going on. |
| 3879 | // |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 3880 | // Even layers that are animating get culled if their back face is showing and |
| 3881 | // they are not double sided. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3882 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 3883 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3884 | LayerImpl* animating_surface = AddChildToRoot<LayerImpl>(); |
| 3885 | LayerImpl* child_of_animating_surface = |
| 3886 | AddChild<LayerImpl>(animating_surface); |
| 3887 | LayerImpl* animating_child = AddChildToRoot<LayerImpl>(); |
| 3888 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3889 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3890 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 3891 | child->test_properties()->double_sided = false; |
| 3892 | child2->test_properties()->double_sided = false; |
| 3893 | animating_surface->test_properties()->double_sided = false; |
| 3894 | child_of_animating_surface->test_properties()->double_sided = false; |
| 3895 | animating_child->test_properties()->double_sided = false; |
| 3896 | |
| 3897 | // Everything draws content. |
| 3898 | child->SetDrawsContent(true); |
| 3899 | child2->SetDrawsContent(true); |
| 3900 | animating_surface->SetDrawsContent(true); |
| 3901 | child_of_animating_surface->SetDrawsContent(true); |
| 3902 | animating_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3903 | |
| 3904 | gfx::Transform backface_matrix; |
| 3905 | backface_matrix.Translate(50.0, 50.0); |
| 3906 | backface_matrix.RotateAboutYAxis(180.0); |
| 3907 | backface_matrix.Translate(-50.0, -50.0); |
| 3908 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 3909 | SetElementIdsForTesting(); |
| 3910 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 3911 | // Animate the transform on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 3912 | AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(), |
| 3913 | timeline_impl(), 10.0, 30, 0); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 3914 | // This is just an animating layer, not a surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 3915 | AddAnimatedTransformToElementWithPlayer(animating_child->element_id(), |
| 3916 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3917 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3918 | root->SetBounds(gfx::Size(100, 100)); |
| 3919 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3920 | child->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3921 | animating_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3922 | animating_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3923 | animating_surface->test_properties()->force_render_surface = true; |
| 3924 | child_of_animating_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3925 | child_of_animating_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3926 | animating_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3927 | animating_child->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3928 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3929 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 3930 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3931 | |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 3932 | EXPECT_EQ(GetRenderSurface(child), GetRenderSurface(root)); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3933 | EXPECT_TRUE(GetRenderSurface(animating_surface)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 3934 | EXPECT_EQ(GetRenderSurface(child_of_animating_surface), |
| 3935 | GetRenderSurface(animating_surface)); |
| 3936 | EXPECT_EQ(GetRenderSurface(animating_child), GetRenderSurface(root)); |
| 3937 | EXPECT_EQ(GetRenderSurface(child2), GetRenderSurface(root)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3938 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 3939 | EXPECT_EQ(1u, update_layer_list_impl()->size()); |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 3940 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 3941 | // The back facing layers are culled from the layer list, and have an empty |
| 3942 | // visible rect. |
| 3943 | EXPECT_TRUE(UpdateLayerListImplContains(child2->id())); |
| 3944 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
| 3945 | EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty()); |
| 3946 | EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty()); |
| 3947 | EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3948 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 3949 | EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3950 | } |
| 3951 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3952 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3953 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 3954 | // Verify the behavior of back-face culling for a render surface that is |
| 3955 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 3956 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3957 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 3958 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 3959 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 3960 | LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface); |
| 3961 | LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3962 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3963 | // RenderSurfaces are not double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 3964 | front_facing_surface->test_properties()->double_sided = false; |
| 3965 | back_facing_surface->test_properties()->double_sided = false; |
| 3966 | |
| 3967 | // Everything draws content. |
| 3968 | front_facing_surface->SetDrawsContent(true); |
| 3969 | back_facing_surface->SetDrawsContent(true); |
| 3970 | child1->SetDrawsContent(true); |
| 3971 | child2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3972 | |
| 3973 | gfx::Transform backface_matrix; |
| 3974 | backface_matrix.Translate(50.0, 50.0); |
| 3975 | backface_matrix.RotateAboutYAxis(180.0); |
| 3976 | backface_matrix.Translate(-50.0, -50.0); |
| 3977 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3978 | root->SetBounds(gfx::Size(100, 100)); |
| 3979 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 3980 | front_facing_surface->test_properties()->force_render_surface = true; |
| 3981 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3982 | back_facing_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3983 | back_facing_surface->test_properties()->force_render_surface = true; |
| 3984 | child1->SetBounds(gfx::Size(100, 100)); |
| 3985 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3986 | |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 3987 | front_facing_surface->test_properties()->sorting_context_id = 1; |
| 3988 | back_facing_surface->test_properties()->sorting_context_id = 1; |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3989 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 3990 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3991 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3992 | // Verify which render surfaces were created and used. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 3993 | EXPECT_TRUE(GetRenderSurface(front_facing_surface)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3994 | |
| 3995 | // We expect the render surface to have been created, but remain unused. |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 3996 | EXPECT_NE(GetRenderSurface(back_facing_surface), GetRenderSurface(root)); |
| 3997 | EXPECT_EQ(GetRenderSurface(child1), GetRenderSurface(front_facing_surface)); |
| 3998 | EXPECT_EQ(GetRenderSurface(child2), GetRenderSurface(back_facing_surface)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3999 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4000 | EXPECT_EQ(2u, update_layer_list_impl()->size()); |
| 4001 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4002 | EXPECT_TRUE(UpdateLayerListImplContains(child1->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4003 | } |
| 4004 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4005 | TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4006 | // Verify draw and screen space transforms of layers not in a surface. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4007 | LayerImpl* root = root_layer_for_testing(); |
| 4008 | root->SetBounds(gfx::Size(100, 100)); |
| 4009 | root->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4010 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4011 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4012 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4013 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4014 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4015 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4016 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4017 | child2->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4018 | child2->SetBounds(gfx::Size(5, 5)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4019 | child2->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4020 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4021 | float device_scale_factor = 2.5f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4022 | gfx::Size viewport_size(100, 100); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4023 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4024 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4025 | EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale()); |
| 4026 | EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale()); |
| 4027 | EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale()); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4028 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4029 | EXPECT_EQ(1u, render_surface_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4030 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4031 | // Verify root transforms |
| 4032 | gfx::Transform expected_root_transform; |
| 4033 | expected_root_transform.Scale(device_scale_factor, device_scale_factor); |
| 4034 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4035 | root->ScreenSpaceTransform()); |
| 4036 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4037 | root->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4038 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4039 | // Verify results of transformed root rects |
| 4040 | gfx::RectF root_bounds(gfx::SizeF(root->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4041 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4042 | gfx::RectF root_draw_rect = |
| 4043 | MathUtil::MapClippedRect(root->DrawTransform(), root_bounds); |
| 4044 | gfx::RectF root_screen_space_rect = |
| 4045 | MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4046 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4047 | gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds())); |
| 4048 | expected_root_draw_rect.Scale(device_scale_factor); |
| 4049 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect); |
| 4050 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4051 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4052 | // Verify child and child2 transforms. They should match. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4053 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4054 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4055 | expected_child_transform.Translate(child->position().x(), |
| 4056 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4057 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4058 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4059 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4060 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4061 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4062 | child2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4063 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4064 | child2->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4065 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4066 | // Verify results of transformed child and child2 rects. They should |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4067 | // match. |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4068 | gfx::RectF child_bounds(gfx::SizeF(child->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4069 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4070 | gfx::RectF child_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4071 | MathUtil::MapClippedRect(child->DrawTransform(), child_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4072 | gfx::RectF child_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4073 | MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4074 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4075 | gfx::RectF child2_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4076 | MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4077 | gfx::RectF child2_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4078 | MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4079 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4080 | gfx::RectF expected_child_draw_rect(child->position(), |
| 4081 | gfx::SizeF(child->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4082 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4083 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4084 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4085 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect); |
| 4086 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4087 | } |
| 4088 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4089 | TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4090 | // Verify draw and screen space transforms of layers in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4091 | gfx::Transform perspective_matrix; |
| 4092 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4093 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4094 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4095 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4096 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4097 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4098 | root->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4099 | |
| 4100 | LayerImpl* page_scale = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4101 | page_scale->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4102 | |
| 4103 | LayerImpl* parent = AddChild<LayerImpl>(page_scale); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4104 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4105 | parent->SetDrawsContent(true); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4106 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4107 | LayerImpl* perspective_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4108 | perspective_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4109 | perspective_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4110 | perspective_surface->test_properties()->transform = |
| 4111 | perspective_matrix * scale_small_matrix; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4112 | perspective_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4113 | perspective_surface->test_properties()->force_render_surface = true; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4114 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4115 | LayerImpl* scale_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4116 | scale_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4117 | scale_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4118 | scale_surface->test_properties()->transform = scale_small_matrix; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4119 | scale_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4120 | scale_surface->test_properties()->force_render_surface = true; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4121 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4122 | float device_scale_factor = 2.5f; |
| 4123 | float page_scale_factor = 3.f; |
pdr | 53abb45 | 2017-05-19 01:59:42 | [diff] [blame] | 4124 | LayerTreeImpl::ViewportLayerIds viewport_ids; |
| 4125 | viewport_ids.page_scale = page_scale->id(); |
| 4126 | root->layer_tree_impl()->SetViewportLayersFromIds(viewport_ids); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4127 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4128 | root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4129 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4130 | root, nullptr, nullptr); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4131 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4132 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4133 | parent->GetIdealContentsScale()); |
| 4134 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4135 | perspective_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4136 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4137 | // the nearest render target. Here this includes the layer transform as well |
| 4138 | // as the device and page scale factors. |
| 4139 | gfx::Transform transform = scale_small_matrix; |
| 4140 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4141 | device_scale_factor * page_scale_factor); |
| 4142 | gfx::Vector2dF scales = |
| 4143 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4144 | float max_2d_scale = std::max(scales.x(), scales.y()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4145 | EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4146 | |
| 4147 | // The ideal scale will draw 1:1 with its render target space along |
| 4148 | // the larger-scale axis. |
| 4149 | gfx::Vector2dF target_space_transform_scales = |
| 4150 | MathUtil::ComputeTransform2dScaleComponents( |
| 4151 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4152 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4153 | std::max(target_space_transform_scales.x(), |
| 4154 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4155 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4156 | EXPECT_EQ(3u, render_surface_list_impl()->size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4157 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4158 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4159 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4160 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4161 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4162 | parent->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4163 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4164 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4165 | // with the screen, and then scaled during drawing. |
| 4166 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4167 | expected_perspective_surface_draw_transform.Translate( |
| 4168 | device_scale_factor * page_scale_factor * |
| 4169 | perspective_surface->position().x(), |
| 4170 | device_scale_factor * page_scale_factor * |
| 4171 | perspective_surface->position().y()); |
| 4172 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4173 | perspective_matrix); |
| 4174 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4175 | scale_small_matrix); |
| 4176 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4177 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4178 | device_scale_factor * page_scale_factor, |
| 4179 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4180 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4181 | expected_perspective_surface_draw_transform, |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4182 | GetRenderSurface(perspective_surface)->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4183 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4184 | expected_perspective_surface_layer_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4185 | perspective_surface->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4186 | } |
| 4187 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4188 | TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4189 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4190 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4191 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4192 | |
| 4193 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4194 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4195 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4196 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4197 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4198 | root->SetBounds(gfx::Size(100, 100)); |
| 4199 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4200 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4201 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4202 | parent->test_properties()->transform = parent_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4203 | parent->SetDrawsContent(true); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4204 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4205 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4206 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4207 | child_scale->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4208 | child_scale->test_properties()->transform = child_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4209 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4210 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4211 | float device_scale_factor = 2.5f; |
| 4212 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4213 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4214 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4215 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4216 | root, nullptr, nullptr); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4217 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4218 | // The ideal scale is able to go below 1. |
| 4219 | float expected_ideal_scale = |
| 4220 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4221 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4222 | EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale()); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4223 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4224 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4225 | initial_parent_scale * initial_child_scale; |
| 4226 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4227 | EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4228 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4229 | } |
| 4230 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4231 | TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4232 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4233 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4234 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4235 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4236 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4237 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4238 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4239 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4240 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4241 | root->SetBounds(gfx::Size(100, 100)); |
| 4242 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4243 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4244 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4245 | parent->test_properties()->transform = parent_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4246 | parent->SetDrawsContent(true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4247 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4248 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4249 | child_scale->SetBounds(gfx::Size(10, 10)); |
| 4250 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4251 | child_scale->test_properties()->transform = child_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4252 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4253 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4254 | ExecuteCalculateDrawProperties(root); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4255 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4256 | EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4257 | // Animating layers compute ideal scale in the same way as when |
| 4258 | // they are static. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4259 | EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale, |
| 4260 | child_scale->GetIdealContentsScale()); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4261 | } |
| 4262 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4263 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4264 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4265 | parent->SetBounds(gfx::Size(30, 30)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4266 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4267 | parent->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 4268 | parent->test_properties()->sorting_context_id = 1; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4269 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4270 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4271 | child->SetBounds(gfx::Size(10, 10)); |
| 4272 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4273 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4274 | child->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4275 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4276 | // This layer should end up in the same surface as child, with the same draw |
| 4277 | // and screen space transforms. |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4278 | LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4279 | duplicate_child_non_owner->SetBounds(gfx::Size(10, 10)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4280 | duplicate_child_non_owner->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4281 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4282 | float device_scale_factor = 1.5f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4283 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4284 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4285 | // We should have two render surfaces. The root's render surface and child's |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4286 | // render surface (it needs one because of force_render_surface). |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4287 | EXPECT_EQ(2u, render_surface_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4288 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4289 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4290 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4291 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4292 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4293 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4294 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4295 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4296 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4297 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4298 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4299 | child->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4300 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4301 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4302 | expected_screen_space_transform.Scale(device_scale_factor, |
| 4303 | device_scale_factor); |
| 4304 | expected_screen_space_transform.Translate(child->position().x(), |
| 4305 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4306 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4307 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4308 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4309 | gfx::Transform expected_duplicate_child_draw_transform = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4310 | child->DrawTransform(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4311 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4312 | duplicate_child_non_owner->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4313 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4314 | child->ScreenSpaceTransform(), |
| 4315 | duplicate_child_non_owner->ScreenSpaceTransform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4316 | EXPECT_EQ(child->drawable_content_rect(), |
| 4317 | duplicate_child_non_owner->drawable_content_rect()); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4318 | EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4319 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4320 | gfx::Transform expected_render_surface_draw_transform; |
| 4321 | expected_render_surface_draw_transform.Translate( |
| 4322 | device_scale_factor * child->position().x(), |
| 4323 | device_scale_factor * child->position().y()); |
| 4324 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4325 | GetRenderSurface(child)->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4326 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4327 | gfx::Transform expected_surface_draw_transform; |
| 4328 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 4329 | device_scale_factor * 2.f); |
| 4330 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4331 | GetRenderSurface(child)->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4332 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4333 | gfx::Transform expected_surface_screen_space_transform; |
| 4334 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 4335 | device_scale_factor * 2.f); |
| 4336 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4337 | expected_surface_screen_space_transform, |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4338 | GetRenderSurface(child)->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4339 | } |
| 4340 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4341 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4342 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4343 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4344 | parent->SetBounds(gfx::Size(33, 31)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4345 | parent->SetDrawsContent(true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4346 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4347 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4348 | child->SetBounds(gfx::Size(13, 11)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4349 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4350 | child->test_properties()->force_render_surface = true; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4351 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 4352 | float device_scale_factor = 1.7f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4353 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4354 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4355 | // We should have two render surfaces. The root's render surface and child's |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4356 | // render surface (it needs one because of force_render_surface). |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4357 | EXPECT_EQ(2u, render_surface_list_impl()->size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4358 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4359 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4360 | GetRenderSurface(child)->draw_transform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4361 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4362 | GetRenderSurface(child)->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4363 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4364 | gfx::Transform(), GetRenderSurface(child)->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4365 | } |
| 4366 | |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 4367 | TEST_F(LayerTreeHostCommonTest, LayerSearch) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4368 | scoped_refptr<Layer> root = Layer::Create(); |
| 4369 | scoped_refptr<Layer> child = Layer::Create(); |
| 4370 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 4371 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4372 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4373 | child->AddChild(grand_child.get()); |
| 4374 | child->SetMaskLayer(mask_layer.get()); |
| 4375 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4376 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4377 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4378 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4379 | int nonexistent_id = -1; |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 4380 | EXPECT_EQ(root.get(), host()->LayerById(root->id())); |
| 4381 | EXPECT_EQ(child.get(), host()->LayerById(child->id())); |
| 4382 | EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id())); |
| 4383 | EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id())); |
| 4384 | EXPECT_FALSE(host()->LayerById(nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4385 | } |
| 4386 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4387 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4388 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4389 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 4390 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4391 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4392 | root->SetBounds(gfx::Size(100, 100)); |
| 4393 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4394 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4395 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 4396 | grand_child->SetDrawsContent(true); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4397 | ExecuteCalculateDrawProperties(root); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 4398 | EXPECT_EQ(GetRenderSurface(child), GetRenderSurface(root)); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4399 | } |
| 4400 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4401 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4402 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 4403 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 4404 | FakeLayerTreeHostImpl host_impl(host()->GetSettings(), &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 4405 | &task_graph_runner); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4406 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4407 | std::unique_ptr<LayerImpl> root = |
| 4408 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4409 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4410 | root->SetDrawsContent(true); |
| 4411 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4412 | std::unique_ptr<LayerImpl> child = |
| 4413 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4414 | child->SetBounds(gfx::Size(50, 50)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4415 | child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4416 | child->test_properties()->opacity = 0.0f; |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4417 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 4418 | const int child_id = child->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4419 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 4420 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4421 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4422 | host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4423 | |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4424 | // Add opacity animation. |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4425 | scoped_refptr<AnimationTimeline> timeline = |
| 4426 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 4427 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4428 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4429 | ElementId child_element_id = |
| 4430 | host_impl.pending_tree()->LayerById(child_id)->element_id(); |
| 4431 | |
| 4432 | AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0, |
| 4433 | 0.0f, 1.0f, false); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4434 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4435 | RenderSurfaceList render_surface_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4436 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4437 | root_layer, root_layer->bounds(), &render_surface_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4438 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4439 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4440 | |
jaydasika | 50612fa0 | 2017-05-19 20:56:02 | [diff] [blame] | 4441 | // We should have one render surface and two layers. The child |
| 4442 | // layer should be included even though it is transparent. |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4443 | ASSERT_EQ(1u, render_surface_list.size()); |
jaydasika | 50612fa0 | 2017-05-19 20:56:02 | [diff] [blame] | 4444 | ASSERT_EQ(2, GetRenderSurface(root_layer)->num_contributors()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4445 | |
jaydasika | 50612fa0 | 2017-05-19 20:56:02 | [diff] [blame] | 4446 | // If the root itself is hidden, the child should not be drawn even if it has |
| 4447 | // an animating opacity. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4448 | root_layer->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4449 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4450 | RenderSurfaceList render_surface_list2; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4451 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4452 | root_layer, root_layer->bounds(), &render_surface_list2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4453 | inputs2.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4454 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4455 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4456 | LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
jaydasika | 50612fa0 | 2017-05-19 20:56:02 | [diff] [blame] | 4457 | EffectTree& tree = |
| 4458 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
| 4459 | EffectNode* node = tree.Node(child_ptr->effect_tree_index()); |
| 4460 | EXPECT_FALSE(node->is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4461 | |
jaydasika | 50612fa0 | 2017-05-19 20:56:02 | [diff] [blame] | 4462 | // A layer should be drawn and it should contribute to drawn surface when |
| 4463 | // it has animating opacity even if it has opacity 0. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4464 | root_layer->test_properties()->opacity = 1.0f; |
| 4465 | child_ptr->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4466 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4467 | RenderSurfaceList render_surface_list3; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4468 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4469 | root_layer, root_layer->bounds(), &render_surface_list3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4470 | inputs3.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4471 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4472 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4473 | child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
jaydasika | 50612fa0 | 2017-05-19 20:56:02 | [diff] [blame] | 4474 | tree = root_layer->layer_tree_impl()->property_trees()->effect_tree; |
| 4475 | node = tree.Node(child_ptr->effect_tree_index()); |
| 4476 | EXPECT_TRUE(node->is_drawn); |
| 4477 | EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index())); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4478 | |
jaydasika | 50612fa0 | 2017-05-19 20:56:02 | [diff] [blame] | 4479 | // But if the opacity of the layer remains 0 after activation, it should not |
| 4480 | // be drawn. |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4481 | host_impl.ActivateSyncTree(); |
danakj | 0da42ca6 | 2016-07-01 19:42:33 | [diff] [blame] | 4482 | LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id()); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4483 | LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id()); |
| 4484 | |
jaydasika | 50612fa0 | 2017-05-19 20:56:02 | [diff] [blame] | 4485 | EffectTree& active_effect_tree = |
| 4486 | host_impl.active_tree()->property_trees()->effect_tree; |
| 4487 | EXPECT_TRUE(active_effect_tree.needs_update()); |
| 4488 | |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4489 | ExecuteCalculateDrawProperties(active_root); |
| 4490 | |
jaydasika | 50612fa0 | 2017-05-19 20:56:02 | [diff] [blame] | 4491 | node = active_effect_tree.Node(active_child->effect_tree_index()); |
| 4492 | EXPECT_FALSE(node->is_drawn); |
| 4493 | EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface( |
| 4494 | active_child->effect_tree_index())); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4495 | } |
| 4496 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4497 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4498 | class LCDTextTest : public LayerTreeHostCommonTestBase, |
| 4499 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4500 | public: |
| 4501 | LCDTextTest() |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4502 | : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()), |
| 4503 | host_impl_(LCDTextTestLayerTreeSettings(), |
| 4504 | &task_runner_provider_, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4505 | &task_graph_runner_) {} |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4506 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4507 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 4508 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4509 | protected: |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4510 | LayerTreeSettings LCDTextTestLayerTreeSettings() { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4511 | LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings(); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4512 | |
| 4513 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
| 4514 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
| 4515 | settings.can_use_lcd_text = can_use_lcd_text_; |
| 4516 | settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_; |
| 4517 | return settings; |
| 4518 | } |
| 4519 | |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 4520 | void SetUp() override { |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4521 | timeline_ = |
| 4522 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 4523 | host_impl_.animation_host()->AddAnimationTimeline(timeline_); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4524 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4525 | std::unique_ptr<LayerImpl> root_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4526 | LayerImpl::Create(host_impl_.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4527 | std::unique_ptr<LayerImpl> child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4528 | LayerImpl::Create(host_impl_.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4529 | std::unique_ptr<LayerImpl> grand_child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4530 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 4531 | |
| 4532 | // Stash raw pointers to look at later. |
| 4533 | root_ = root_ptr.get(); |
| 4534 | child_ = child_ptr.get(); |
| 4535 | grand_child_ = grand_child_ptr.get(); |
| 4536 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4537 | child_->test_properties()->AddChild(std::move(grand_child_ptr)); |
| 4538 | root_->test_properties()->AddChild(std::move(child_ptr)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4539 | host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4540 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4541 | host_impl_.active_tree()->SetElementIdsForTesting(); |
| 4542 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 4543 | root_->SetContentsOpaque(true); |
| 4544 | child_->SetContentsOpaque(true); |
| 4545 | grand_child_->SetContentsOpaque(true); |
| 4546 | |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4547 | root_->SetDrawsContent(true); |
| 4548 | child_->SetDrawsContent(true); |
| 4549 | grand_child_->SetDrawsContent(true); |
| 4550 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4551 | root_->SetBounds(gfx::Size(1, 1)); |
| 4552 | child_->SetBounds(gfx::Size(1, 1)); |
| 4553 | grand_child_->SetBounds(gfx::Size(1, 1)); |
| 4554 | |
| 4555 | child_->test_properties()->force_render_surface = |
| 4556 | std::tr1::get<2>(GetParam()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4557 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4558 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4559 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4560 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4561 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4562 | FakeImplTaskRunnerProvider task_runner_provider_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 4563 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4564 | FakeLayerTreeHostImpl host_impl_; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4565 | scoped_refptr<AnimationTimeline> timeline_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4566 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4567 | LayerImpl* root_ = nullptr; |
| 4568 | LayerImpl* child_ = nullptr; |
| 4569 | LayerImpl* grand_child_ = nullptr; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4570 | }; |
| 4571 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4572 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4573 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 4574 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 4575 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4576 | // Case 1: Identity transform. |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4577 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4578 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4579 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 4580 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4581 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4582 | // Case 2: Integral translation. |
| 4583 | gfx::Transform integral_translation; |
| 4584 | integral_translation.Translate(1.0, 2.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4585 | child_->test_properties()->transform = integral_translation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4586 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4587 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4588 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4589 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 4590 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4591 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4592 | // Case 3: Non-integral translation. |
| 4593 | gfx::Transform non_integral_translation; |
| 4594 | non_integral_translation.Translate(1.5, 2.5); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4595 | child_->test_properties()->transform = non_integral_translation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4596 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4597 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4598 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4599 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 4600 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4601 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4602 | // Case 4: Rotation. |
| 4603 | gfx::Transform rotation; |
| 4604 | rotation.Rotate(10.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4605 | child_->test_properties()->transform = rotation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4606 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4607 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4608 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4609 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 4610 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4611 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4612 | // Case 5: Scale. |
| 4613 | gfx::Transform scale; |
| 4614 | scale.Scale(2.0, 2.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4615 | child_->test_properties()->transform = scale; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4616 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4617 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4618 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4619 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 4620 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4621 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4622 | // Case 6: Skew. |
| 4623 | gfx::Transform skew; |
nainar | 8ca8ee6 | 2015-09-03 01:04:10 | [diff] [blame] | 4624 | skew.Skew(10.0, 0.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4625 | child_->test_properties()->transform = skew; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4626 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4627 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4628 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4629 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 4630 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4631 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4632 | // Case 7: Translucent. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4633 | child_->test_properties()->transform = gfx::Transform(); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4634 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4635 | child_->test_properties()->opacity = 0.5f; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4636 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4637 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4638 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 4639 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4640 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4641 | // Case 8: Sanity check: restore transform and opacity. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4642 | child_->test_properties()->transform = gfx::Transform(); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4643 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4644 | child_->test_properties()->opacity = 1.f; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4645 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4646 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4647 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 4648 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 4649 | |
| 4650 | // Case 9: Non-opaque content. |
| 4651 | child_->SetContentsOpaque(false); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4652 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4653 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4654 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 4655 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 4656 | |
| 4657 | // Case 10: Sanity check: restore content opaqueness. |
| 4658 | child_->SetContentsOpaque(true); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4659 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4660 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4661 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 4662 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4663 | } |
| 4664 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 4665 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4666 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 4667 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4668 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4669 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4670 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4671 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4672 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 4673 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4674 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4675 | // Add opacity animation. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4676 | child_->test_properties()->opacity = 0.9f; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4677 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4678 | |
| 4679 | SetElementIdsForTesting(); |
| 4680 | |
| 4681 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 4682 | 10.0, 0.9f, 0.1f, false); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4683 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 4684 | // Text LCD should be adjusted while animation is active. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4685 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4686 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 4687 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 4688 | } |
| 4689 | |
| 4690 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 4691 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 4692 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 4693 | |
| 4694 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4695 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4696 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4697 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 4698 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4699 | SetElementIdsForTesting(); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 4700 | |
| 4701 | // Mark contents non-opaque within the first animation frame. |
| 4702 | child_->SetContentsOpaque(false); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4703 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 4704 | 10.0, 0.9f, 0.1f, false); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4705 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 4706 | // LCD text should be disabled for non-opaque layers even during animations. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4707 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4708 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 4709 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 4713 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4714 | testing::Combine(testing::Bool(), |
| 4715 | testing::Bool(), |
| 4716 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4717 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4718 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4719 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 4720 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 4721 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4722 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4723 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4724 | std::unique_ptr<LayerImpl> root = |
| 4725 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4726 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4727 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4728 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4729 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4730 | std::unique_ptr<LayerImpl> child = |
| 4731 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4732 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4733 | child->SetDrawsContent(true); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4734 | LayerImpl* child_layer = child.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4735 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4736 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4737 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4738 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4739 | grand_child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 4740 | grand_child->test_properties()->hide_layer_and_subtree = true; |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4741 | LayerImpl* grand_child_layer = grand_child.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4742 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4743 | child->test_properties()->AddChild(std::move(grand_child)); |
| 4744 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4745 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4746 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4747 | RenderSurfaceList render_surface_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4748 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4749 | root_layer, root_layer->bounds(), &render_surface_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4750 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4751 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4752 | |
| 4753 | // We should have one render surface and two layers. The grand child has |
| 4754 | // hidden itself. |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4755 | ASSERT_EQ(1u, render_surface_list.size()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4756 | ASSERT_EQ(2, GetRenderSurface(root_layer)->num_contributors()); |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 4757 | EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface()); |
| 4758 | EXPECT_TRUE(child_layer->contributes_to_drawn_render_surface()); |
| 4759 | EXPECT_FALSE(grand_child_layer->contributes_to_drawn_render_surface()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4760 | } |
| 4761 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4762 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4763 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 4764 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 4765 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4766 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4767 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4768 | std::unique_ptr<LayerImpl> root = |
| 4769 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4770 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4771 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 4772 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4773 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4774 | std::unique_ptr<LayerImpl> child = |
| 4775 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4776 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4777 | child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 4778 | child->test_properties()->hide_layer_and_subtree = true; |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4779 | LayerImpl* child_layer = child.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4780 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4781 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4782 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4783 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4784 | grand_child->SetDrawsContent(true); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4785 | LayerImpl* grand_child_layer = grand_child.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4786 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4787 | child->test_properties()->AddChild(std::move(grand_child)); |
| 4788 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4789 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4790 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4791 | RenderSurfaceList render_surface_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4792 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4793 | root_layer, root_layer->bounds(), &render_surface_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4794 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4795 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4796 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4797 | // We should have one render surface and one layer. The child has |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4798 | // hidden itself and the grand child. |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4799 | ASSERT_EQ(1u, render_surface_list.size()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4800 | ASSERT_EQ(1, GetRenderSurface(root_layer)->num_contributors()); |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 4801 | EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface()); |
| 4802 | EXPECT_FALSE(child_layer->contributes_to_drawn_render_surface()); |
| 4803 | EXPECT_FALSE(grand_child_layer->contributes_to_drawn_render_surface()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4804 | } |
| 4805 | |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 4806 | void EmptyCopyOutputCallback(std::unique_ptr<viz::CopyOutputResult> result) {} |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4807 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4808 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4809 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 4810 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 4811 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4812 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4813 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4814 | std::unique_ptr<LayerImpl> root = |
| 4815 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4816 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4817 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 4818 | LayerImpl* root_layer = root.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4819 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4820 | std::unique_ptr<LayerImpl> copy_grand_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4821 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4822 | copy_grand_parent->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4823 | copy_grand_parent->SetDrawsContent(true); |
| 4824 | LayerImpl* copy_grand_parent_layer = copy_grand_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4825 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4826 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4827 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4828 | copy_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4829 | copy_parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4830 | copy_parent->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4831 | LayerImpl* copy_parent_layer = copy_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4832 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4833 | std::unique_ptr<LayerImpl> copy_request = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4834 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4835 | copy_request->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4836 | copy_request->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4837 | copy_request->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4838 | LayerImpl* copy_layer = copy_request.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4839 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4840 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4841 | LayerImpl::Create(host_impl.pending_tree(), 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4842 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4843 | copy_child->SetDrawsContent(true); |
| 4844 | LayerImpl* copy_child_layer = copy_child.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4845 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4846 | std::unique_ptr<LayerImpl> copy_grand_child = |
thakis | e53c527 | 2016-01-24 01:20:40 | [diff] [blame] | 4847 | LayerImpl::Create(host_impl.pending_tree(), 6); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4848 | copy_grand_child->SetBounds(gfx::Size(20, 20)); |
| 4849 | copy_grand_child->SetDrawsContent(true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4850 | LayerImpl* copy_grand_child_layer = copy_grand_child.get(); |
| 4851 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4852 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4853 | LayerImpl::Create(host_impl.pending_tree(), 7); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4854 | copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4855 | copy_grand_parent_sibling_before->SetDrawsContent(true); |
| 4856 | LayerImpl* copy_grand_parent_sibling_before_layer = |
| 4857 | copy_grand_parent_sibling_before.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 4858 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4859 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4860 | LayerImpl::Create(host_impl.pending_tree(), 8); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4861 | copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4862 | copy_grand_parent_sibling_after->SetDrawsContent(true); |
| 4863 | LayerImpl* copy_grand_parent_sibling_after_layer = |
| 4864 | copy_grand_parent_sibling_after.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 4865 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4866 | copy_child->test_properties()->AddChild(std::move(copy_grand_child)); |
| 4867 | copy_request->test_properties()->AddChild(std::move(copy_child)); |
| 4868 | copy_parent->test_properties()->AddChild(std::move(copy_request)); |
| 4869 | copy_grand_parent->test_properties()->AddChild(std::move(copy_parent)); |
| 4870 | root->test_properties()->AddChild( |
| 4871 | std::move(copy_grand_parent_sibling_before)); |
| 4872 | root->test_properties()->AddChild(std::move(copy_grand_parent)); |
| 4873 | root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4874 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4875 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4876 | // 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] | 4877 | // hidden subtree on copy_layer. Also hide the copy grand child and its |
| 4878 | // subtree. |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 4879 | copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true; |
| 4880 | copy_grand_parent_sibling_before_layer->test_properties() |
| 4881 | ->hide_layer_and_subtree = true; |
| 4882 | copy_grand_parent_sibling_after_layer->test_properties() |
| 4883 | ->hide_layer_and_subtree = true; |
| 4884 | copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4885 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 4886 | copy_layer->test_properties()->copy_requests.push_back( |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 4887 | viz::CopyOutputRequest::CreateRequest( |
Yuri Wiitala | b251176 | 2017-07-19 00:17:53 | [diff] [blame] | 4888 | base::BindOnce(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4889 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4890 | RenderSurfaceList render_surface_list; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4891 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4892 | root_layer, root_layer->bounds(), &render_surface_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4893 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4894 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4895 | |
jaydasika | ebc9428 | 2017-04-24 20:34:01 | [diff] [blame] | 4896 | EXPECT_TRUE(root_layer->has_copy_requests_in_target_subtree()); |
| 4897 | EXPECT_TRUE(copy_grand_parent_layer->has_copy_requests_in_target_subtree()); |
| 4898 | EXPECT_TRUE(copy_parent_layer->has_copy_requests_in_target_subtree()); |
| 4899 | EXPECT_TRUE(copy_layer->has_copy_requests_in_target_subtree()); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 4900 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4901 | // We should have four render surfaces, one for the root, one for the grand |
| 4902 | // parent since it has opacity and two drawing descendants, one for the parent |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4903 | // since it owns a surface, and one for the copy_layer. |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4904 | ASSERT_EQ(4u, render_surface_list.size()); |
Chris Harrelson | 9bdbcce | 2017-06-02 03:12:14 | [diff] [blame] | 4905 | EXPECT_EQ(static_cast<uint64_t>(root_layer->id()), |
| 4906 | render_surface_list.at(0)->id()); |
| 4907 | EXPECT_EQ(static_cast<uint64_t>(copy_grand_parent_layer->id()), |
| 4908 | render_surface_list.at(1)->id()); |
| 4909 | EXPECT_EQ(static_cast<uint64_t>(copy_parent_layer->id()), |
| 4910 | render_surface_list.at(2)->id()); |
| 4911 | EXPECT_EQ(static_cast<uint64_t>(copy_layer->id()), |
| 4912 | render_surface_list.at(3)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4913 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4914 | // The root render surface should have 2 contributing layers. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4915 | EXPECT_EQ(2, GetRenderSurface(root_layer)->num_contributors()); |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 4916 | EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface()); |
| 4917 | EXPECT_FALSE(copy_grand_parent_layer->contributes_to_drawn_render_surface()); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4918 | EXPECT_FALSE(copy_grand_parent_sibling_before_layer |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 4919 | ->contributes_to_drawn_render_surface()); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4920 | EXPECT_FALSE(copy_grand_parent_sibling_after_layer |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 4921 | ->contributes_to_drawn_render_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4922 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 4923 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4924 | // appear in its list, since it needs to be drawn for the copy request. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4925 | ASSERT_EQ(1, GetRenderSurface(copy_parent_layer)->num_contributors()); |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 4926 | EXPECT_FALSE(copy_parent_layer->contributes_to_drawn_render_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4927 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4928 | // The copy layer's render surface should have 2 contributing layers. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4929 | ASSERT_EQ(2, GetRenderSurface(copy_layer)->num_contributors()); |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 4930 | EXPECT_TRUE(copy_layer->contributes_to_drawn_render_surface()); |
| 4931 | EXPECT_TRUE(copy_child_layer->contributes_to_drawn_render_surface()); |
| 4932 | EXPECT_FALSE(copy_grand_child_layer->contributes_to_drawn_render_surface()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4933 | |
| 4934 | // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden, |
| 4935 | // but the copy_layer and copy_child should be drawn for the copy request. |
| 4936 | // copy grand child should not be drawn as its hidden even in the copy |
| 4937 | // request. |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 4938 | EffectTree& tree = |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 4939 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4940 | EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4941 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4942 | node = tree.Node(copy_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4943 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4944 | node = tree.Node(copy_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4945 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4946 | node = tree.Node(copy_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4947 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4948 | node = tree.Node(copy_grand_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4949 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4950 | |
| 4951 | // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its |
| 4952 | // actually hidden. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 4953 | EXPECT_FALSE(GetRenderSurface(copy_layer)->contributes_to_drawn_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4954 | } |
| 4955 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4956 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4957 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 4958 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 4959 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4960 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4961 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4962 | std::unique_ptr<LayerImpl> root = |
| 4963 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4964 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4965 | root->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4966 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4967 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4968 | LayerImpl::Create(host_impl.pending_tree(), 2); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4969 | copy_parent->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4970 | copy_parent->SetMasksToBounds(true); |
| 4971 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4972 | std::unique_ptr<LayerImpl> copy_layer = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4973 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4974 | copy_layer->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4975 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4976 | copy_layer->test_properties()->force_render_surface = true; |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4977 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4978 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4979 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4980 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4981 | copy_child->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4982 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 4983 | copy_layer->test_properties()->copy_requests.push_back( |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 4984 | viz::CopyOutputRequest::CreateRequest( |
Yuri Wiitala | b251176 | 2017-07-19 00:17:53 | [diff] [blame] | 4985 | base::BindOnce(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4986 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4987 | copy_layer->test_properties()->AddChild(std::move(copy_child)); |
| 4988 | copy_parent->test_properties()->AddChild(std::move(copy_layer)); |
| 4989 | root->test_properties()->AddChild(std::move(copy_parent)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4990 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4991 | RenderSurfaceList render_surface_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 4992 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4993 | root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 4994 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 4995 | root_layer, root_layer->bounds(), &render_surface_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4996 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4997 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 4998 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 4999 | // We should have two render surface, as the others are clipped out. |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5000 | ASSERT_EQ(2u, render_surface_list.size()); |
Chris Harrelson | 9bdbcce | 2017-06-02 03:12:14 | [diff] [blame] | 5001 | EXPECT_EQ(static_cast<uint64_t>(root_layer->id()), |
| 5002 | render_surface_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5003 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5004 | // The root render surface should have only 2 contributing layer, since the |
| 5005 | // other layers are clipped away. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5006 | ASSERT_EQ(2, GetRenderSurface(root_layer)->num_contributors()); |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 5007 | EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5008 | } |
| 5009 | |
jaydasika | 96e6946 | 2017-05-03 23:06:45 | [diff] [blame] | 5010 | TEST_F(LayerTreeHostCommonTest, SingularTransformAndCopyRequests) { |
| 5011 | LayerImpl* root = root_layer_for_testing(); |
| 5012 | root->SetBounds(gfx::Size(50, 50)); |
| 5013 | root->SetDrawsContent(true); |
| 5014 | |
| 5015 | LayerImpl* singular_transform_layer = AddChild<LayerImpl>(root); |
| 5016 | singular_transform_layer->SetBounds(gfx::Size(100, 100)); |
| 5017 | singular_transform_layer->SetDrawsContent(true); |
| 5018 | gfx::Transform singular; |
| 5019 | singular.Scale3d(6.f, 6.f, 0.f); |
| 5020 | singular_transform_layer->test_properties()->transform = singular; |
| 5021 | |
| 5022 | LayerImpl* copy_layer = AddChild<LayerImpl>(singular_transform_layer); |
| 5023 | copy_layer->SetBounds(gfx::Size(100, 100)); |
| 5024 | copy_layer->SetDrawsContent(true); |
| 5025 | copy_layer->test_properties()->copy_requests.push_back( |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 5026 | viz::CopyOutputRequest::CreateRequest( |
Yuri Wiitala | b251176 | 2017-07-19 00:17:53 | [diff] [blame] | 5027 | base::BindOnce(&EmptyCopyOutputCallback))); |
jaydasika | 96e6946 | 2017-05-03 23:06:45 | [diff] [blame] | 5028 | |
| 5029 | LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer); |
| 5030 | copy_child->SetBounds(gfx::Size(100, 100)); |
| 5031 | copy_child->SetDrawsContent(true); |
| 5032 | |
| 5033 | LayerImpl* copy_grand_child = AddChild<LayerImpl>(copy_child); |
| 5034 | copy_grand_child->SetBounds(gfx::Size(100, 100)); |
| 5035 | copy_grand_child->SetDrawsContent(true); |
| 5036 | copy_grand_child->test_properties()->transform = singular; |
| 5037 | |
| 5038 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
| 5039 | ExecuteCalculateDrawProperties(root); |
| 5040 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
| 5041 | |
| 5042 | // A layer with singular transform should not contribute to drawn render |
| 5043 | // surface. |
| 5044 | EXPECT_FALSE(singular_transform_layer->contributes_to_drawn_render_surface()); |
| 5045 | // Even though copy_layer and copy_child have singular screen space transform, |
| 5046 | // they still contribute to drawn render surface as their transform to the |
| 5047 | // closest ancestor with copy request is not singular. |
| 5048 | EXPECT_TRUE(copy_layer->contributes_to_drawn_render_surface()); |
| 5049 | EXPECT_TRUE(copy_child->contributes_to_drawn_render_surface()); |
| 5050 | // copy_grand_child's transform to its closest ancestor with copy request is |
| 5051 | // also singular. So, it doesn't contribute to drawn render surface. |
| 5052 | EXPECT_FALSE(copy_grand_child->contributes_to_drawn_render_surface()); |
| 5053 | } |
| 5054 | |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5055 | TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5056 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5057 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5058 | root->SetDrawsContent(true); |
| 5059 | root->SetMasksToBounds(true); |
| 5060 | |
| 5061 | LayerImpl* copy_layer = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5062 | copy_layer->SetBounds(gfx::Size(100, 100)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5063 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5064 | copy_layer->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5065 | |
| 5066 | LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5067 | copy_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5068 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5069 | copy_child->SetDrawsContent(true); |
| 5070 | |
| 5071 | LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5072 | copy_clip->SetBounds(gfx::Size(55, 55)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5073 | copy_clip->SetMasksToBounds(true); |
| 5074 | |
| 5075 | LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5076 | copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5077 | copy_clipped_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5078 | copy_clipped_child->SetDrawsContent(true); |
| 5079 | |
| 5080 | LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5081 | copy_surface->SetPosition(gfx::PointF(45.f, 45.f)); |
| 5082 | copy_surface->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5083 | copy_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5084 | copy_surface->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5085 | |
| 5086 | copy_layer->test_properties()->copy_requests.push_back( |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 5087 | viz::CopyOutputRequest::CreateRequest( |
Yuri Wiitala | b251176 | 2017-07-19 00:17:53 | [diff] [blame] | 5088 | base::BindOnce(&EmptyCopyOutputCallback))); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5089 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5090 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5091 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5092 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5093 | |
| 5094 | EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect()); |
| 5095 | EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect()); |
| 5096 | EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect()); |
| 5097 | EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect()); |
| 5098 | |
| 5099 | // Case 2: When the non root copy request layer is clipped. |
| 5100 | copy_layer->SetBounds(gfx::Size(50, 50)); |
| 5101 | copy_layer->SetMasksToBounds(true); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5102 | copy_layer->test_properties()->copy_requests.push_back( |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 5103 | viz::CopyOutputRequest::CreateRequest( |
Yuri Wiitala | b251176 | 2017-07-19 00:17:53 | [diff] [blame] | 5104 | base::BindOnce(&EmptyCopyOutputCallback))); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5105 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5106 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5107 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5108 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5109 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5110 | |
| 5111 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5112 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5113 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5114 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | 296dd9f | 2016-07-05 14:59:51 | [diff] [blame] | 5115 | |
| 5116 | // Case 3: When there is device scale factor. |
| 5117 | float device_scale_factor = 2.f; |
| 5118 | copy_layer->test_properties()->copy_requests.push_back( |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 5119 | viz::CopyOutputRequest::CreateRequest( |
Yuri Wiitala | b251176 | 2017-07-19 00:17:53 | [diff] [blame] | 5120 | base::BindOnce(&EmptyCopyOutputCallback))); |
weiliangc | 296dd9f | 2016-07-05 14:59:51 | [diff] [blame] | 5121 | |
| 5122 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
| 5123 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 5124 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
| 5125 | |
| 5126 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5127 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5128 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5129 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5130 | } |
| 5131 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5132 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 5133 | // Ensure that a transform between the layer and its render surface is not a |
| 5134 | // problem. Constructs the following layer tree. |
| 5135 | // |
| 5136 | // root (a render surface) |
| 5137 | // + render_surface |
| 5138 | // + clip_parent (scaled) |
| 5139 | // + intervening_clipping_layer |
| 5140 | // + clip_child |
| 5141 | // |
| 5142 | // The render surface should be resized correctly and the clip child should |
| 5143 | // inherit the right clip rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5144 | LayerImpl* root = root_layer_for_testing(); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5145 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 5146 | LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5147 | clip_parent->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5148 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5149 | intervening->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5150 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5151 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5152 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5153 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5154 | clip_children->insert(clip_child); |
gogag2 | 1788915 | 2017-03-13 14:34:42 | [diff] [blame] | 5155 | clip_parent->test_properties()->clip_children = std::move(clip_children); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5156 | |
| 5157 | intervening->SetMasksToBounds(true); |
| 5158 | clip_parent->SetMasksToBounds(true); |
| 5159 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5160 | gfx::Transform scale_transform; |
| 5161 | scale_transform.Scale(2, 2); |
| 5162 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5163 | root->SetBounds(gfx::Size(50, 50)); |
| 5164 | render_surface->SetBounds(gfx::Size(10, 10)); |
| 5165 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5166 | clip_parent->test_properties()->transform = scale_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5167 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5168 | clip_parent->SetBounds(gfx::Size(10, 10)); |
| 5169 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5170 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5171 | clip_child->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5172 | clip_child->SetBounds(gfx::Size(10, 10)); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5173 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5174 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5175 | ASSERT_TRUE(GetRenderSurface(root)); |
| 5176 | ASSERT_TRUE(GetRenderSurface(render_surface)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5177 | |
| 5178 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 5179 | // by the intervening clip layer. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5180 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect()); |
| 5181 | ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect()); |
| 5182 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5183 | |
| 5184 | // Ensure that the render surface reports a content rect that has been grown |
| 5185 | // to accomodate for the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5186 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5187 | GetRenderSurface(render_surface)->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5188 | |
| 5189 | // The above check implies the two below, but they nicely demonstrate that |
| 5190 | // we've grown, despite the intervening layer's clip. |
| 5191 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5192 | GetRenderSurface(render_surface)->content_rect())); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5193 | ASSERT_FALSE(intervening->clip_rect().Contains( |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5194 | GetRenderSurface(render_surface)->content_rect())); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 5198 | // Ensure that intervening render surfaces are not a problem in the basic |
| 5199 | // case. In the following tree, both render surfaces should be resized to |
| 5200 | // accomodate for the clip child, despite an intervening clip. |
| 5201 | // |
| 5202 | // root (a render surface) |
| 5203 | // + clip_parent (masks to bounds) |
| 5204 | // + render_surface1 (sets opacity) |
| 5205 | // + intervening (masks to bounds) |
| 5206 | // + render_surface2 (also sets opacity) |
| 5207 | // + clip_child |
| 5208 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5209 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5210 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5211 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5212 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5213 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5214 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5215 | render_surface1->SetDrawsContent(true); |
| 5216 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5217 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5218 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5219 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5220 | |
| 5221 | intervening->SetMasksToBounds(true); |
| 5222 | clip_parent->SetMasksToBounds(true); |
| 5223 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5224 | gfx::Transform translation_transform; |
| 5225 | translation_transform.Translate(2, 2); |
| 5226 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5227 | root->SetBounds(gfx::Size(50, 50)); |
| 5228 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5229 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5230 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5231 | render_surface1->test_properties()->force_render_surface = true; |
| 5232 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5233 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5234 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5235 | render_surface2->test_properties()->force_render_surface = true; |
| 5236 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5237 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5238 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5239 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5240 | EXPECT_TRUE(GetRenderSurface(root)); |
| 5241 | EXPECT_TRUE(GetRenderSurface(render_surface1)); |
| 5242 | EXPECT_TRUE(GetRenderSurface(render_surface2)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5243 | |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5244 | // render_surface1 should apply the clip from clip_parent. Though there is a |
| 5245 | // clip child, render_surface1 can apply the clip as there are no clips |
| 5246 | // between the clip parent and render_surface1 |
| 5247 | EXPECT_EQ(gfx::Rect(1, 1, 40, 40), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5248 | GetRenderSurface(render_surface1)->clip_rect()); |
| 5249 | EXPECT_TRUE(GetRenderSurface(render_surface1)->is_clipped()); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5250 | EXPECT_EQ(gfx::Rect(), render_surface1->clip_rect()); |
| 5251 | EXPECT_FALSE(render_surface1->is_clipped()); |
| 5252 | |
| 5253 | // render_surface2 could have expanded, as there is a clip between |
| 5254 | // clip_child's clip (clip_parent) and render_surface2's clip (intervening). |
| 5255 | // So, it should not be clipped (their bounds would no longer be reliable). |
| 5256 | // We should resort to layer clipping in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5257 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5258 | GetRenderSurface(render_surface2)->clip_rect()); |
| 5259 | EXPECT_FALSE(GetRenderSurface(render_surface2)->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5260 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5261 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5262 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5263 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5264 | |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5265 | // The content rects of render_surface2 should have expanded to contain the |
| 5266 | // clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5267 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5268 | GetRenderSurface(render_surface1)->content_rect()); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5269 | EXPECT_EQ(gfx::Rect(-10, -10, 60, 60), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5270 | GetRenderSurface(render_surface2)->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5271 | |
| 5272 | // The clip child should have inherited the clip parent's clip (projected to |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5273 | // the right space, of course), but as render_surface1 already applies that |
| 5274 | // clip, clip_child need not apply it again. |
| 5275 | EXPECT_EQ(gfx::Rect(), clip_child->clip_rect()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5276 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect()); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5277 | EXPECT_FALSE(clip_child->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5278 | } |
| 5279 | |
| 5280 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 5281 | // Ensure that intervening render surfaces are not a problem, even if there |
| 5282 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 5283 | // of transform. |
| 5284 | // |
| 5285 | // root (a render surface) |
| 5286 | // + clip_parent (masks to bounds) |
| 5287 | // + render_surface1 (sets opacity) |
| 5288 | // + intervening (masks to bounds AND scrolls) |
| 5289 | // + render_surface2 (also sets opacity) |
| 5290 | // + clip_child |
| 5291 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5292 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5293 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5294 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5295 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5296 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5297 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5298 | render_surface1->SetDrawsContent(true); |
| 5299 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5300 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5301 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5302 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5303 | |
| 5304 | intervening->SetMasksToBounds(true); |
| 5305 | clip_parent->SetMasksToBounds(true); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 5306 | intervening->SetScrollable(gfx::Size(1, 1)); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 5307 | intervening->SetElementId(LayerIdToElementIdForTesting(intervening->id())); |
Philip Rogers | 4131a1c1 | 2017-07-21 19:36:50 | [diff] [blame] | 5308 | intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5309 | |
| 5310 | gfx::Transform translation_transform; |
| 5311 | translation_transform.Translate(2, 2); |
| 5312 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5313 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5314 | clip_parent->test_properties()->transform = translation_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5315 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5316 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5317 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5318 | render_surface1->test_properties()->force_render_surface = true; |
| 5319 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5320 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5321 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5322 | render_surface2->test_properties()->force_render_surface = true; |
| 5323 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5324 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5325 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5326 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5327 | EXPECT_TRUE(GetRenderSurface(root)); |
| 5328 | EXPECT_TRUE(GetRenderSurface(render_surface1)); |
| 5329 | EXPECT_TRUE(GetRenderSurface(render_surface2)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5330 | |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5331 | // render_surface1 should apply the clip from clip_parent. Though there is a |
| 5332 | // clip child, render_surface1 can apply the clip as there are no clips |
| 5333 | // between the clip parent and render_surface1 |
| 5334 | EXPECT_EQ(gfx::Rect(3, 3, 40, 40), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5335 | GetRenderSurface(render_surface1)->clip_rect()); |
| 5336 | EXPECT_TRUE(GetRenderSurface(render_surface1)->is_clipped()); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5337 | EXPECT_EQ(gfx::Rect(), render_surface1->clip_rect()); |
| 5338 | EXPECT_FALSE(render_surface1->is_clipped()); |
| 5339 | |
| 5340 | // render_surface2 could have expanded, as there is a clip between |
| 5341 | // clip_child's clip (clip_parent) and render_surface2's clip (intervening). |
| 5342 | // So, it should not be clipped (their bounds would no longer be reliable). |
| 5343 | // We should resort to layer clipping in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5344 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5345 | GetRenderSurface(render_surface2)->clip_rect()); |
| 5346 | EXPECT_FALSE(GetRenderSurface(render_surface2)->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5347 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5348 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5349 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5350 | |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5351 | // The content rects of render_surface2 should have expanded to contain the |
| 5352 | // clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5353 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5354 | GetRenderSurface(render_surface1)->content_rect()); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5355 | EXPECT_EQ(gfx::Rect(-10, -10, 60, 60), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5356 | GetRenderSurface(render_surface2)->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5357 | |
| 5358 | // The clip child should have inherited the clip parent's clip (projected to |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5359 | // the right space, of course), but as render_surface1 already applies that |
| 5360 | // clip, clip_child need not apply it again. |
| 5361 | EXPECT_EQ(gfx::Rect(), clip_child->clip_rect()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5362 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect()); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5363 | EXPECT_FALSE(clip_child->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5364 | } |
| 5365 | |
| 5366 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 5367 | // Ensures that descendants of the clip child inherit the correct clip. |
| 5368 | // |
| 5369 | // root (a render surface) |
| 5370 | // + clip_parent (masks to bounds) |
| 5371 | // + intervening (masks to bounds) |
| 5372 | // + clip_child |
| 5373 | // + child |
| 5374 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5375 | LayerImpl* root = root_layer_for_testing(); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5376 | LayerImpl* clip_parent = AddChild<LayerImpl>(root); |
| 5377 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
| 5378 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5379 | LayerImpl* child = AddChild<LayerImpl>(clip_child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5380 | clip_child->SetDrawsContent(true); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5381 | child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5382 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5383 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5384 | clip_parent->test_properties()->clip_children = |
| 5385 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5386 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5387 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5388 | root->SetBounds(gfx::Size(50, 50)); |
| 5389 | clip_parent->SetBounds(gfx::Size(40, 40)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5390 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5391 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5392 | intervening->SetMasksToBounds(true); |
| 5393 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 5394 | child->SetBounds(gfx::Size(60, 60)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5395 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5396 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5397 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5398 | EXPECT_TRUE(GetRenderSurface(root)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5399 | |
| 5400 | // Neither the clip child nor its descendant should have inherited the clip |
| 5401 | // from |intervening|. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5402 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5403 | EXPECT_TRUE(clip_child->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5404 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5405 | EXPECT_TRUE(child->is_clipped()); |
| 5406 | } |
| 5407 | |
| 5408 | TEST_F(LayerTreeHostCommonTest, |
| 5409 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 5410 | // Ensures that non-descendant clip children in the tree do not affect |
| 5411 | // render surfaces. |
| 5412 | // |
| 5413 | // root (a render surface) |
| 5414 | // + clip_parent (masks to bounds) |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5415 | // + clip_layer (masks to bounds) |
| 5416 | // + render_surface1 |
| 5417 | // + clip_child |
| 5418 | // + render_surface2 |
| 5419 | // + non_clip_child |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5420 | // |
| 5421 | // In this example render_surface2 should be unaffected by clip_child. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5422 | LayerImpl* root = root_layer_for_testing(); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5423 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5424 | LayerImpl* clip_layer = AddChild<LayerImpl>(clip_parent); |
| 5425 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_layer); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5426 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5427 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_layer); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5428 | LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5429 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5430 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5431 | clip_parent->test_properties()->clip_children = |
| 5432 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5433 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5434 | |
| 5435 | clip_parent->SetMasksToBounds(true); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5436 | clip_layer->SetMasksToBounds(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5437 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5438 | render_surface1->SetDrawsContent(true); |
| 5439 | clip_child->SetDrawsContent(true); |
| 5440 | render_surface2->SetDrawsContent(true); |
| 5441 | non_clip_child->SetDrawsContent(true); |
| 5442 | |
| 5443 | root->SetBounds(gfx::Size(15, 15)); |
| 5444 | clip_parent->SetBounds(gfx::Size(10, 10)); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5445 | clip_layer->SetBounds(gfx::Size(10, 10)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5446 | render_surface1->SetPosition(gfx::PointF(5, 5)); |
| 5447 | render_surface1->SetBounds(gfx::Size(5, 5)); |
| 5448 | render_surface1->test_properties()->force_render_surface = true; |
| 5449 | render_surface2->SetBounds(gfx::Size(5, 5)); |
| 5450 | render_surface2->test_properties()->force_render_surface = true; |
| 5451 | clip_child->SetPosition(gfx::PointF(-1, 1)); |
| 5452 | clip_child->SetBounds(gfx::Size(10, 10)); |
| 5453 | non_clip_child->SetBounds(gfx::Size(5, 5)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5454 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5455 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5456 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5457 | EXPECT_TRUE(GetRenderSurface(root)); |
| 5458 | EXPECT_TRUE(GetRenderSurface(render_surface1)); |
| 5459 | EXPECT_TRUE(GetRenderSurface(render_surface2)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5460 | |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 5461 | EXPECT_EQ(gfx::Rect(-5, -5, 10, 10), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5462 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5463 | |
| 5464 | // The render surface should not clip (it has unclipped descendants), instead |
| 5465 | // it should rely on layer clipping. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5466 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5467 | GetRenderSurface(render_surface1)->clip_rect()); |
| 5468 | EXPECT_FALSE(GetRenderSurface(render_surface1)->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5469 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5470 | // That said, it should have grown to accomodate the unclipped descendant and |
| 5471 | // its own size. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5472 | EXPECT_EQ(gfx::Rect(-1, 0, 6, 5), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5473 | GetRenderSurface(render_surface1)->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5474 | |
| 5475 | // This render surface should clip. It has no unclipped descendants. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5476 | EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5477 | GetRenderSurface(render_surface2)->clip_rect()); |
| 5478 | EXPECT_TRUE(GetRenderSurface(render_surface2)->is_clipped()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 5479 | EXPECT_FALSE(render_surface2->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5480 | |
| 5481 | // It also shouldn't have grown to accomodate the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5482 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5483 | GetRenderSurface(render_surface2)->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5484 | } |
| 5485 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5486 | TEST_F(LayerTreeHostCommonTest, |
| 5487 | CreateRenderSurfaceWhenFlattenInsideRenderingContext) { |
| 5488 | // Verifies that Render Surfaces are created at the edge of rendering context. |
| 5489 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5490 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5491 | LayerImpl* child1 = AddChildToRoot<LayerImpl>(); |
| 5492 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 5493 | LayerImpl* child3 = AddChild<LayerImpl>(child2); |
| 5494 | root->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5495 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5496 | gfx::Size bounds(100, 100); |
| 5497 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5498 | root->SetBounds(bounds); |
| 5499 | child1->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5500 | child1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5501 | child1->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 5502 | child1->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5503 | child2->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5504 | child2->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 5505 | child2->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5506 | child3->SetBounds(bounds); |
| 5507 | child3->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 5508 | child3->test_properties()->sorting_context_id = 1; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 5509 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5510 | |
| 5511 | // Verify which render surfaces were created. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5512 | EXPECT_TRUE(GetRenderSurface(root)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 5513 | EXPECT_EQ(GetRenderSurface(child1), GetRenderSurface(root)); |
| 5514 | EXPECT_NE(GetRenderSurface(child2), GetRenderSurface(root)); |
| 5515 | EXPECT_EQ(GetRenderSurface(child3), GetRenderSurface(child2)); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5516 | } |
| 5517 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5518 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5519 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5520 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame] | 5521 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5522 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5523 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame] | 5524 | |
| 5525 | LayerImpl* flattener = AddChild<LayerImpl>(back_facing); |
| 5526 | LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5527 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5528 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5529 | child1->SetDrawsContent(true); |
| 5530 | child2->SetDrawsContent(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5531 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5532 | root->SetBounds(gfx::Size(50, 50)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5533 | back_facing->SetBounds(gfx::Size(50, 50)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 5534 | back_facing->test_properties()->should_flatten_transform = false; |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame] | 5535 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5536 | render_surface1->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5537 | render_surface1->test_properties()->should_flatten_transform = false; |
| 5538 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5539 | render_surface1->test_properties()->double_sided = false; |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame] | 5540 | child1->SetBounds(gfx::Size(20, 20)); |
| 5541 | |
| 5542 | flattener->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5543 | render_surface2->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5544 | render_surface2->test_properties()->should_flatten_transform = false; |
| 5545 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5546 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5547 | child2->SetBounds(gfx::Size(20, 20)); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5548 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5549 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5550 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5551 | EXPECT_EQ(3u, render_surface_list_impl()->size()); |
| 5552 | EXPECT_EQ(2, render_surface_list_impl()->at(0)->num_contributors()); |
| 5553 | EXPECT_EQ(1, render_surface_list_impl()->at(1)->num_contributors()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5554 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5555 | gfx::Transform rotation_transform; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5556 | rotation_transform.RotateAboutXAxis(180.0); |
| 5557 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5558 | back_facing->test_properties()->transform = rotation_transform; |
jaydasika | 5aa88b8 | 2015-11-10 01:48:03 | [diff] [blame] | 5559 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5560 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5561 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5562 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5563 | // render_surface1 is in the same 3d rendering context as back_facing and is |
| 5564 | // not double sided, so it should not be in RSLL. render_surface2 is also not |
| 5565 | // double-sided, but will still be in RSLL as it's in a different 3d rendering |
| 5566 | // context. |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5567 | EXPECT_EQ(2u, render_surface_list_impl()->size()); |
| 5568 | EXPECT_EQ(1, render_surface_list_impl()->at(0)->num_contributors()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5569 | } |
| 5570 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 5571 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5572 | LayerImpl* root = root_layer_for_testing(); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 5573 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 5574 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 5575 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5576 | root->SetBounds(gfx::Size(50, 50)); |
| 5577 | root->test_properties()->should_flatten_transform = false; |
| 5578 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5579 | child->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5580 | child->test_properties()->should_flatten_transform = false; |
| 5581 | grand_child->SetBounds(gfx::Size(20, 20)); |
| 5582 | grand_child->SetDrawsContent(true); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 5583 | grand_child->SetUseParentBackfaceVisibility(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5584 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 5585 | ExecuteCalculateDrawProperties(root); |
| 5586 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5587 | EXPECT_EQ(1u, render_surface_list_impl()->size()); |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 5588 | EXPECT_TRUE(grand_child->contributes_to_drawn_render_surface()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 5589 | |
Chris Harrelson | daececa4 | 2017-06-16 20:42:02 | [diff] [blame] | 5590 | // A ll layers with invisible backfgaces should be checked. |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 5591 | EXPECT_FALSE(root->should_check_backface_visibility()); |
Chris Harrelson | daececa4 | 2017-06-16 20:42:02 | [diff] [blame] | 5592 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 5593 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 5594 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5595 | gfx::Transform rotation_transform; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 5596 | rotation_transform.RotateAboutXAxis(180.0); |
| 5597 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5598 | child->test_properties()->transform = rotation_transform; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 5599 | child->test_properties()->sorting_context_id = 1; |
| 5600 | grand_child->test_properties()->sorting_context_id = 1; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 5601 | child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5602 | |
| 5603 | ExecuteCalculateDrawProperties(root); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5604 | EXPECT_EQ(1u, render_surface_list_impl()->size()); |
| 5605 | EXPECT_EQ(0, render_surface_list_impl()->at(0)->num_contributors()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 5606 | |
| 5607 | // We should check for backface visibilty of child as it has a rotation |
| 5608 | // transform. We should also check for grand_child as it uses the backface |
| 5609 | // visibility of its parent. |
| 5610 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 5611 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 5612 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 5613 | |
| 5614 | grand_child->SetUseParentBackfaceVisibility(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5615 | grand_child->test_properties()->double_sided = false; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 5616 | grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5617 | |
| 5618 | ExecuteCalculateDrawProperties(root); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5619 | EXPECT_EQ(1u, render_surface_list_impl()->size()); |
| 5620 | EXPECT_EQ(0, render_surface_list_impl()->at(0)->num_contributors()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 5621 | |
| 5622 | // We should check the backface visibility of child as it has a rotation |
| 5623 | // transform and for grand_child as it is in a 3d rendering context and not |
| 5624 | // the root of it. |
| 5625 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 5626 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 5627 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 5628 | } |
| 5629 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5630 | TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5631 | LayerImpl* root = root_layer_for_testing(); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5632 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 5633 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 5634 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 5635 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5636 | gfx::Transform rotate_about_y; |
| 5637 | rotate_about_y.RotateAboutYAxis(180.0); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5638 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5639 | root->SetBounds(gfx::Size(50, 50)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5640 | root->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 5641 | root->test_properties()->sorting_context_id = 1; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5642 | back_facing->test_properties()->transform = rotate_about_y; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5643 | back_facing->SetBounds(gfx::Size(50, 50)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5644 | back_facing->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 5645 | back_facing->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5646 | render_surface1->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5647 | render_surface1->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5648 | render_surface1->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5649 | render_surface1->test_properties()->force_render_surface = true; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 5650 | render_surface1->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5651 | render_surface2->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5652 | render_surface2->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5653 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5654 | render_surface2->test_properties()->force_render_surface = true; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 5655 | render_surface2->test_properties()->sorting_context_id = 1; |
weiliangc | ea09f337 | 2017-03-29 16:43:24 | [diff] [blame] | 5656 | SetElementIdsForTesting(); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5657 | ExecuteCalculateDrawProperties(root); |
| 5658 | |
| 5659 | const EffectTree& tree = |
| 5660 | root->layer_tree_impl()->property_trees()->effect_tree; |
| 5661 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5662 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5663 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5664 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5665 | |
weiliangc | ea09f337 | 2017-03-29 16:43:24 | [diff] [blame] | 5666 | root->layer_tree_impl()->SetTransformMutated(back_facing->element_id(), |
| 5667 | gfx::Transform()); |
| 5668 | root->layer_tree_impl()->SetTransformMutated(render_surface2->element_id(), |
| 5669 | rotate_about_y); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5670 | ExecuteCalculateDrawProperties(root); |
| 5671 | EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5672 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5673 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5674 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5675 | |
weiliangc | ea09f337 | 2017-03-29 16:43:24 | [diff] [blame] | 5676 | root->layer_tree_impl()->SetTransformMutated(render_surface1->element_id(), |
| 5677 | rotate_about_y); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5678 | ExecuteCalculateDrawProperties(root); |
| 5679 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5680 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5681 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5682 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 5683 | } |
| 5684 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5685 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 5686 | // Checks that the simple case (being clipped by a scroll parent that would |
| 5687 | // have been processed before you anyhow) results in the right clips. |
| 5688 | // |
| 5689 | // + root |
| 5690 | // + scroll_parent_border |
| 5691 | // | + scroll_parent_clip |
| 5692 | // | + scroll_parent |
| 5693 | // + scroll_child |
| 5694 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5695 | LayerImpl* root = root_layer_for_testing(); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 5696 | LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>(); |
| 5697 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 5698 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 5699 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5700 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 5701 | scroll_parent->SetDrawsContent(true); |
| 5702 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5703 | scroll_parent_clip->SetMasksToBounds(true); |
| 5704 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5705 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5706 | scroll_parent->test_properties()->scroll_children = |
| 5707 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5708 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5709 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5710 | root->SetBounds(gfx::Size(50, 50)); |
| 5711 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 5712 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 5713 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 5714 | scroll_child->SetBounds(gfx::Size(50, 50)); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 5715 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5716 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5717 | EXPECT_TRUE(GetRenderSurface(root)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5718 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5719 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5720 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 5721 | } |
| 5722 | |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 5723 | TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) { |
| 5724 | // Tests the computation of draw transform for the scroll child when its |
| 5725 | // target is different from its scroll parent's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5726 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 5727 | LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); |
| 5728 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); |
| 5729 | LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target); |
| 5730 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); |
| 5731 | |
| 5732 | scroll_parent->SetDrawsContent(true); |
| 5733 | scroll_child->SetDrawsContent(true); |
| 5734 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5735 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5736 | scroll_parent->test_properties()->scroll_children = |
| 5737 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5738 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 5739 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5740 | root->SetBounds(gfx::Size(50, 50)); |
| 5741 | scroll_child_target->SetBounds(gfx::Size(50, 50)); |
| 5742 | scroll_child_target->test_properties()->force_render_surface = true; |
| 5743 | scroll_child->SetBounds(gfx::Size(50, 50)); |
| 5744 | scroll_parent_target->SetPosition(gfx::PointF(10, 10)); |
| 5745 | scroll_parent_target->SetBounds(gfx::Size(50, 50)); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 5746 | scroll_parent_target->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5747 | scroll_parent_target->test_properties()->force_render_surface = true; |
| 5748 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 5749 | |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 5750 | float device_scale_factor = 1.5f; |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5751 | RenderSurfaceList render_surface_list_impl; |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 5752 | gfx::Size device_viewport_size = |
| 5753 | gfx::Size(root->bounds().width() * device_scale_factor, |
| 5754 | root->bounds().height() * device_scale_factor); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 5755 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5756 | root, device_viewport_size, gfx::Transform(), &render_surface_list_impl); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 5757 | inputs.device_scale_factor = device_scale_factor; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5758 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 5759 | |
weiliangc | 1da3fb89 | 2016-03-14 20:23:52 | [diff] [blame] | 5760 | EXPECT_EQ(scroll_child->effect_tree_index(), |
| 5761 | scroll_child_target->effect_tree_index()); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 5762 | EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); |
| 5763 | EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); |
| 5764 | gfx::Transform scale; |
| 5765 | scale.Scale(1.5f, 1.5f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 5766 | EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 5767 | } |
| 5768 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 5769 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5770 | LayerImpl* root = root_layer_for_testing(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 5771 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 5772 | LayerImpl* child = AddChild<LayerImpl>(parent); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5773 | |
| 5774 | root->SetBounds(gfx::Size(50, 50)); |
| 5775 | root->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 5776 | root->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5777 | parent->SetBounds(gfx::Size(30, 30)); |
| 5778 | parent->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5779 | parent->test_properties()->force_render_surface = true; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 5780 | parent->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5781 | child->SetBounds(gfx::Size(20, 20)); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 5782 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5783 | child->test_properties()->force_render_surface = true; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 5784 | child->test_properties()->sorting_context_id = 1; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 5785 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 5786 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5787 | EXPECT_EQ(3u, render_surface_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 5788 | |
| 5789 | gfx::Transform singular_transform; |
| 5790 | singular_transform.Scale3d( |
| 5791 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 5792 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5793 | child->test_properties()->transform = singular_transform; |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 5794 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5795 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 5796 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 5797 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5798 | EXPECT_EQ(2u, render_surface_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 5799 | |
| 5800 | // Ensure that the entire subtree under a layer with singular transform does |
| 5801 | // not get rendered. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5802 | parent->test_properties()->transform = singular_transform; |
| 5803 | child->test_properties()->transform = gfx::Transform(); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 5804 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5805 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 5806 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 5807 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5808 | EXPECT_EQ(1u, render_surface_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 5809 | } |
| 5810 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5811 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 5812 | // Checks that clipping by a scroll parent that follows you in paint order |
| 5813 | // still results in correct clipping. |
| 5814 | // |
| 5815 | // + root |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5816 | // + scroll_parent_border |
| 5817 | // + scroll_parent_clip |
| 5818 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5819 | // + scroll_child |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5820 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5821 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5822 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 5823 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 5824 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 5825 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5826 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5827 | scroll_parent->SetDrawsContent(true); |
| 5828 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5829 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5830 | root->SetBounds(gfx::Size(50, 50)); |
| 5831 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 5832 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5833 | scroll_parent_clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5834 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 5835 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5836 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5837 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5838 | scroll_parent->test_properties()->scroll_children = |
| 5839 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5840 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5841 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5842 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5843 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5844 | EXPECT_TRUE(GetRenderSurface(root)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5845 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5846 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5847 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 5848 | } |
| 5849 | |
| 5850 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 5851 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 5852 | // you in paint order still results in correct clipping. |
| 5853 | // |
| 5854 | // + root |
| 5855 | // + scroll_child |
| 5856 | // + scroll_parent_border |
| 5857 | // | + scroll_parent_clip |
| 5858 | // | + scroll_parent |
| 5859 | // + scroll_grandparent_border |
| 5860 | // + scroll_grandparent_clip |
| 5861 | // + scroll_grandparent |
| 5862 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5863 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5864 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 5865 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 5866 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 5867 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 5868 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 5869 | LayerImpl* scroll_grandparent_clip = |
| 5870 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 5871 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5872 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5873 | scroll_parent->SetDrawsContent(true); |
| 5874 | scroll_grandparent->SetDrawsContent(true); |
| 5875 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5876 | |
| 5877 | scroll_parent_clip->SetMasksToBounds(true); |
| 5878 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 5879 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5880 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5881 | scroll_parent->test_properties()->scroll_children = |
| 5882 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5883 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 5884 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5885 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5886 | scroll_grandparent->test_properties()->scroll_children = |
| 5887 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5888 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 5889 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5890 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5891 | root->SetBounds(gfx::Size(50, 50)); |
| 5892 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 5893 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 5894 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 5895 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 5896 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 5897 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 5898 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5899 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5900 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5901 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5902 | EXPECT_TRUE(GetRenderSurface(root)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5903 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5904 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5905 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 5906 | |
| 5907 | // Despite the fact that we visited the above layers out of order to get the |
| 5908 | // correct clip, the layer lists should be unaffected. |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5909 | EXPECT_EQ(3, GetRenderSurface(root)->num_contributors()); |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 5910 | EXPECT_TRUE(scroll_child->contributes_to_drawn_render_surface()); |
| 5911 | EXPECT_TRUE(scroll_parent->contributes_to_drawn_render_surface()); |
| 5912 | EXPECT_TRUE(scroll_grandparent->contributes_to_drawn_render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5913 | } |
| 5914 | |
| 5915 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 5916 | // 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] | 5917 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5918 | // + root |
| 5919 | // + scroll_child |
| 5920 | // + scroll_parent_border |
| 5921 | // + scroll_parent_clip |
| 5922 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5923 | // + render_surface2 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5924 | // + scroll_grandparent_border |
| 5925 | // + scroll_grandparent_clip |
| 5926 | // + scroll_grandparent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5927 | // + render_surface1 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5928 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5929 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5930 | root->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5931 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5932 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 5933 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5934 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5935 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 5936 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 5937 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 5938 | LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent); |
| 5939 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 5940 | LayerImpl* scroll_grandparent_clip = |
| 5941 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 5942 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
| 5943 | LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5944 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5945 | scroll_parent->SetDrawsContent(true); |
| 5946 | render_surface1->SetDrawsContent(true); |
| 5947 | scroll_grandparent->SetDrawsContent(true); |
| 5948 | render_surface2->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5949 | |
| 5950 | scroll_parent_clip->SetMasksToBounds(true); |
| 5951 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 5952 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5953 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5954 | scroll_parent->test_properties()->scroll_children = |
| 5955 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5956 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 5957 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5958 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5959 | scroll_grandparent->test_properties()->scroll_children = |
| 5960 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5961 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 5962 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5963 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5964 | root->SetBounds(gfx::Size(50, 50)); |
| 5965 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 5966 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 5967 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 5968 | render_surface1->SetBounds(gfx::Size(50, 50)); |
| 5969 | render_surface1->test_properties()->force_render_surface = true; |
| 5970 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 5971 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 5972 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 5973 | render_surface2->SetBounds(gfx::Size(50, 50)); |
| 5974 | render_surface2->test_properties()->force_render_surface = true; |
| 5975 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5976 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5977 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5978 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5979 | EXPECT_TRUE(GetRenderSurface(root)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5980 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5981 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5982 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 5983 | |
| 5984 | // Despite the fact that we had to process the layers out of order to get the |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5985 | // right clip, our render_surface_list's order should be unaffected. |
| 5986 | EXPECT_EQ(3u, render_surface_list_impl()->size()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5987 | EXPECT_EQ(GetRenderSurface(root), render_surface_list_impl()->at(0)); |
| 5988 | EXPECT_EQ(GetRenderSurface(render_surface2), |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5989 | render_surface_list_impl()->at(1)); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 5990 | EXPECT_EQ(GetRenderSurface(render_surface1), |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 5991 | render_surface_list_impl()->at(2)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 5992 | } |
| 5993 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 5994 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 5995 | // Ensures that when we have a render surface between a fixed position layer |
| 5996 | // and its container, we compute the fixed position layer's draw transform |
| 5997 | // with respect to that intervening render surface, not with respect to its |
| 5998 | // container's render target. |
| 5999 | // |
| 6000 | // + root |
| 6001 | // + render_surface |
| 6002 | // + fixed |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6003 | // + child |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6004 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6005 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6006 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 6007 | LayerImpl* fixed = AddChild<LayerImpl>(render_surface); |
| 6008 | LayerImpl* child = AddChild<LayerImpl>(fixed); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6009 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6010 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6011 | root->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6012 | |
| 6013 | LayerPositionConstraint constraint; |
| 6014 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6015 | fixed->test_properties()->position_constraint = constraint; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6016 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6017 | root->SetBounds(gfx::Size(50, 50)); |
| 6018 | render_surface->SetPosition(gfx::PointF(7.f, 9.f)); |
| 6019 | render_surface->SetBounds(gfx::Size(50, 50)); |
| 6020 | render_surface->SetDrawsContent(true); |
| 6021 | fixed->SetPosition(gfx::PointF(10.f, 15.f)); |
| 6022 | fixed->SetBounds(gfx::Size(50, 50)); |
| 6023 | fixed->SetDrawsContent(true); |
| 6024 | child->SetPosition(gfx::PointF(1.f, 2.f)); |
| 6025 | child->SetBounds(gfx::Size(50, 50)); |
| 6026 | child->SetDrawsContent(true); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6027 | ExecuteCalculateDrawProperties(root); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6028 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6029 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6030 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6031 | EffectTree& effect_tree = |
| 6032 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6033 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6034 | gfx::Transform expected_fixed_draw_transform; |
| 6035 | expected_fixed_draw_transform.Translate(10.f, 15.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6036 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6037 | expected_fixed_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6038 | draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6039 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6040 | gfx::Transform expected_fixed_screen_space_transform; |
| 6041 | expected_fixed_screen_space_transform.Translate(17.f, 24.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6042 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6043 | expected_fixed_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6044 | draw_property_utils::ScreenSpaceTransform(fixed, transform_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6045 | |
| 6046 | gfx::Transform expected_child_draw_transform; |
| 6047 | expected_child_draw_transform.Translate(11.f, 17.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6048 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6049 | expected_child_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6050 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6051 | |
| 6052 | gfx::Transform expected_child_screen_space_transform; |
| 6053 | expected_child_screen_space_transform.Translate(18.f, 26.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6054 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6055 | expected_child_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6056 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6057 | } |
| 6058 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6059 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 6060 | // This test verifies that a scrolling layer that gets snapped to |
| 6061 | // integer coordinates doesn't move a fixed position child. |
| 6062 | // |
| 6063 | // + root |
| 6064 | // + container |
| 6065 | // + scroller |
| 6066 | // + fixed |
| 6067 | // |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6068 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6069 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 6070 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6071 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6072 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6073 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 6074 | LayerImpl* root = root_ptr.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6075 | std::unique_ptr<LayerImpl> container = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6076 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 6077 | LayerImpl* container_layer = container.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6078 | std::unique_ptr<LayerImpl> scroller = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6079 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 6080 | LayerImpl* scroll_layer = scroller.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6081 | std::unique_ptr<LayerImpl> fixed = |
| 6082 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6083 | LayerImpl* fixed_layer = fixed.get(); |
| 6084 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6085 | container->test_properties()->is_container_for_fixed_position_layers = true; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6086 | |
| 6087 | LayerPositionConstraint constraint; |
| 6088 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6089 | fixed->test_properties()->position_constraint = constraint; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6090 | |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6091 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6092 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6093 | gfx::Transform container_transform; |
| 6094 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 6095 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 6096 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6097 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6098 | container->test_properties()->transform = container_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6099 | container->SetBounds(gfx::Size(40, 40)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6100 | container->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6101 | scroller->SetBounds(gfx::Size(30, 30)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6102 | scroller->SetScrollable(container->bounds()); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6103 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6104 | fixed->SetBounds(gfx::Size(50, 50)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6105 | fixed->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6106 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6107 | scroller->test_properties()->AddChild(std::move(fixed)); |
| 6108 | container->test_properties()->AddChild(std::move(scroller)); |
| 6109 | root->test_properties()->AddChild(std::move(container)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6110 | root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr)); |
| 6111 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6112 | |
| 6113 | // Rounded to integers already. |
| 6114 | { |
| 6115 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6116 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6117 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 6118 | RenderSurfaceList render_surface_list; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6119 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 6120 | root, root->bounds(), &render_surface_list); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6121 | root->layer_tree_impl() |
| 6122 | ->property_trees() |
| 6123 | ->transform_tree.set_source_to_parent_updates_allowed(false); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6124 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6125 | |
| 6126 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6127 | container_layer->draw_properties().screen_space_transform, |
| 6128 | fixed_layer->draw_properties().screen_space_transform); |
| 6129 | EXPECT_VECTOR_EQ( |
| 6130 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6131 | container_offset); |
| 6132 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6133 | .screen_space_transform.To2dTranslation(), |
| 6134 | container_offset - scroll_delta); |
| 6135 | } |
| 6136 | |
| 6137 | // Scroll delta requiring rounding. |
| 6138 | { |
| 6139 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6140 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6141 | |
| 6142 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 6143 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 6144 | RenderSurfaceList render_surface_list; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6145 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 6146 | root, root->bounds(), &render_surface_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6147 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6148 | |
| 6149 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6150 | container_layer->draw_properties().screen_space_transform, |
| 6151 | fixed_layer->draw_properties().screen_space_transform); |
| 6152 | EXPECT_VECTOR_EQ( |
| 6153 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6154 | container_offset); |
| 6155 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6156 | .screen_space_transform.To2dTranslation(), |
| 6157 | container_offset - rounded_scroll_delta); |
| 6158 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6159 | |
| 6160 | // Scale is applied earlier in the tree. |
| 6161 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6162 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6163 | gfx::Transform scaled_container_transform = container_transform; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6164 | scaled_container_transform.Scale3d(2.0, 2.0, 1.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6165 | container_layer->test_properties()->transform = scaled_container_transform; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6166 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6167 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6168 | |
| 6169 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6170 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6171 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 6172 | RenderSurfaceList render_surface_list; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6173 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 6174 | root, root->bounds(), &render_surface_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6175 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6176 | |
| 6177 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6178 | container_layer->draw_properties().screen_space_transform, |
| 6179 | fixed_layer->draw_properties().screen_space_transform); |
| 6180 | EXPECT_VECTOR_EQ( |
| 6181 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6182 | container_offset); |
| 6183 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6184 | container_layer->test_properties()->transform = container_transform; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6185 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6186 | } |
| 6187 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 6188 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6189 | ScrollSnappingWithAnimatedScreenSpaceTransform) { |
| 6190 | // This test verifies that a scrolling layer whose screen space transform is |
| 6191 | // animating doesn't get snapped to integer coordinates. |
| 6192 | // |
| 6193 | // + root |
| 6194 | // + animated layer |
| 6195 | // + surface |
| 6196 | // + container |
| 6197 | // + scroller |
| 6198 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6199 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6200 | LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>(); |
| 6201 | LayerImpl* surface = AddChild<LayerImpl>(animated_layer); |
| 6202 | LayerImpl* container = AddChild<LayerImpl>(surface); |
| 6203 | LayerImpl* scroller = AddChild<LayerImpl>(container); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6204 | |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6205 | gfx::Transform start_scale; |
| 6206 | start_scale.Scale(1.5f, 1.5f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6207 | |
| 6208 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6209 | animated_layer->test_properties()->transform = start_scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6210 | animated_layer->SetBounds(gfx::Size(50, 50)); |
| 6211 | surface->SetBounds(gfx::Size(50, 50)); |
| 6212 | surface->test_properties()->force_render_surface = true; |
| 6213 | container->SetBounds(gfx::Size(50, 50)); |
| 6214 | scroller->SetBounds(gfx::Size(100, 100)); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6215 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6216 | scroller->SetScrollable(container->bounds()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6217 | scroller->SetDrawsContent(true); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6218 | |
| 6219 | gfx::Transform end_scale; |
| 6220 | end_scale.Scale(2.f, 2.f); |
| 6221 | TransformOperations start_operations; |
| 6222 | start_operations.AppendMatrix(start_scale); |
| 6223 | TransformOperations end_operations; |
| 6224 | end_operations.AppendMatrix(end_scale); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 6225 | SetElementIdsForTesting(); |
| 6226 | |
| 6227 | AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(), |
| 6228 | timeline_impl(), 1.0, |
| 6229 | start_operations, end_operations); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6230 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6231 | SetScrollOffsetDelta(scroller, scroll_delta); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6232 | |
| 6233 | ExecuteCalculateDrawProperties(root); |
| 6234 | |
| 6235 | gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); |
| 6236 | EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 6237 | scroller->DrawTransform().To2dTranslation()); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6238 | } |
| 6239 | |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 6240 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) { |
| 6241 | // This test verifies that a scrolling child of a scrolling layer doesn't get |
| 6242 | // snapped to integer coordinates. |
| 6243 | // |
| 6244 | // + root |
| 6245 | // + container |
| 6246 | // + scroller |
| 6247 | // + scroll_child |
| 6248 | // |
| 6249 | scoped_refptr<Layer> root = Layer::Create(); |
| 6250 | scoped_refptr<Layer> container = Layer::Create(); |
| 6251 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6252 | scoped_refptr<Layer> scroll_child = Layer::Create(); |
| 6253 | root->AddChild(container); |
| 6254 | root->AddChild(scroll_child); |
| 6255 | container->AddChild(scroller); |
| 6256 | host()->SetRootLayer(root); |
| 6257 | |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6258 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 6259 | scroll_child->SetScrollParent(scroller.get()); |
| 6260 | |
| 6261 | gfx::Transform rotate; |
| 6262 | rotate.RotateAboutYAxis(30); |
| 6263 | root->SetBounds(gfx::Size(50, 50)); |
| 6264 | container->SetBounds(gfx::Size(50, 50)); |
| 6265 | scroller->SetBounds(gfx::Size(100, 100)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6266 | scroller->SetScrollable(container->bounds()); |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 6267 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 6268 | scroll_child->SetBounds(gfx::Size(10, 10)); |
| 6269 | scroll_child->SetTransform(rotate); |
| 6270 | |
| 6271 | ExecuteCalculateDrawProperties(root.get()); |
| 6272 | |
| 6273 | host()->host_impl()->CreatePendingTree(); |
| 6274 | host()->CommitAndCreatePendingTree(); |
| 6275 | host()->host_impl()->ActivateSyncTree(); |
| 6276 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6277 | |
| 6278 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6279 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6280 | LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id()); |
| 6281 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 6282 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 6283 | |
| 6284 | ExecuteCalculateDrawProperties(root_impl); |
| 6285 | |
| 6286 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 6287 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 6288 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6289 | |
| 6290 | gfx::Transform expected_scroll_child_screen_space_transform; |
| 6291 | expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); |
| 6292 | expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); |
| 6293 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, |
| 6294 | scroll_child_impl->ScreenSpaceTransform()); |
| 6295 | } |
| 6296 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6297 | TEST_F(LayerTreeHostCommonTest, StickyPositionTop) { |
| 6298 | scoped_refptr<Layer> root = Layer::Create(); |
| 6299 | scoped_refptr<Layer> container = Layer::Create(); |
| 6300 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6301 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6302 | root->AddChild(container); |
| 6303 | container->AddChild(scroller); |
| 6304 | scroller->AddChild(sticky_pos); |
| 6305 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6306 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6307 | |
| 6308 | LayerStickyPositionConstraint sticky_position; |
| 6309 | sticky_position.is_sticky = true; |
| 6310 | sticky_position.is_anchored_top = true; |
| 6311 | sticky_position.top_offset = 10.0f; |
| 6312 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6313 | gfx::Rect(10, 20, 10, 10); |
| 6314 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6315 | gfx::Rect(0, 0, 50, 50); |
| 6316 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6317 | |
| 6318 | root->SetBounds(gfx::Size(100, 100)); |
| 6319 | container->SetBounds(gfx::Size(100, 100)); |
| 6320 | scroller->SetBounds(gfx::Size(1000, 1000)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6321 | scroller->SetScrollable(container->bounds()); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6322 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6323 | sticky_pos->SetPosition(gfx::PointF(10, 20)); |
| 6324 | |
| 6325 | ExecuteCalculateDrawProperties(root.get()); |
| 6326 | host()->host_impl()->CreatePendingTree(); |
| 6327 | host()->CommitAndCreatePendingTree(); |
| 6328 | host()->host_impl()->ActivateSyncTree(); |
| 6329 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6330 | |
| 6331 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6332 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6333 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6334 | |
| 6335 | ExecuteCalculateDrawProperties(root_impl); |
| 6336 | EXPECT_VECTOR2DF_EQ( |
| 6337 | gfx::Vector2dF(10.f, 20.f), |
| 6338 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6339 | |
| 6340 | // Scroll less than sticking point, sticky element should move with scroll as |
| 6341 | // we haven't gotten to the initial sticky item location yet. |
| 6342 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 6343 | ExecuteCalculateDrawProperties(root_impl); |
| 6344 | EXPECT_VECTOR2DF_EQ( |
| 6345 | gfx::Vector2dF(5.f, 15.f), |
| 6346 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6347 | |
| 6348 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 6349 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 6350 | ExecuteCalculateDrawProperties(root_impl); |
| 6351 | EXPECT_VECTOR2DF_EQ( |
| 6352 | gfx::Vector2dF(-5.f, 10.f), |
| 6353 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6354 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f)); |
| 6355 | ExecuteCalculateDrawProperties(root_impl); |
| 6356 | EXPECT_VECTOR2DF_EQ( |
| 6357 | gfx::Vector2dF(-5.f, 10.f), |
| 6358 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6359 | |
| 6360 | // Scroll past the end of the sticky container (note: this element does not |
| 6361 | // have its own layer as it does not need to be composited). |
| 6362 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); |
| 6363 | ExecuteCalculateDrawProperties(root_impl); |
| 6364 | EXPECT_VECTOR2DF_EQ( |
| 6365 | gfx::Vector2dF(-5.f, -10.f), |
| 6366 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6367 | } |
| 6368 | |
flackr | d2ae03f | 2016-11-14 19:22:05 | [diff] [blame] | 6369 | TEST_F(LayerTreeHostCommonTest, StickyPositionTopScrollParent) { |
| 6370 | scoped_refptr<Layer> root = Layer::Create(); |
| 6371 | scoped_refptr<Layer> container = Layer::Create(); |
| 6372 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6373 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6374 | root->AddChild(container); |
| 6375 | container->AddChild(scroller); |
| 6376 | root->AddChild(sticky_pos); |
| 6377 | sticky_pos->SetScrollParent(scroller.get()); |
| 6378 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6379 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
flackr | d2ae03f | 2016-11-14 19:22:05 | [diff] [blame] | 6380 | |
smcgruer | 29014ff | 2017-03-24 14:34:43 | [diff] [blame] | 6381 | // The sticky layer has already been scrolled on the main thread side, and has |
| 6382 | // stuck. This test then checks that further changes from cc-only scrolling |
| 6383 | // are handled correctly. |
flackr | d2ae03f | 2016-11-14 19:22:05 | [diff] [blame] | 6384 | LayerStickyPositionConstraint sticky_position; |
| 6385 | sticky_position.is_sticky = true; |
| 6386 | sticky_position.is_anchored_top = true; |
| 6387 | sticky_position.top_offset = 10.0f; |
flackr | d2ae03f | 2016-11-14 19:22:05 | [diff] [blame] | 6388 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6389 | gfx::Rect(10, 20, 10, 10); |
| 6390 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6391 | gfx::Rect(0, 0, 50, 50); |
| 6392 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6393 | |
| 6394 | root->SetBounds(gfx::Size(200, 200)); |
| 6395 | container->SetBounds(gfx::Size(100, 100)); |
| 6396 | container->SetPosition(gfx::PointF(50, 50)); |
| 6397 | scroller->SetBounds(gfx::Size(1000, 1000)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6398 | scroller->SetScrollable(container->bounds()); |
flackr | d2ae03f | 2016-11-14 19:22:05 | [diff] [blame] | 6399 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6400 | sticky_pos->SetPosition(gfx::PointF(60, 70)); |
| 6401 | |
| 6402 | ExecuteCalculateDrawProperties(root.get()); |
| 6403 | host()->host_impl()->CreatePendingTree(); |
| 6404 | host()->CommitAndCreatePendingTree(); |
| 6405 | host()->host_impl()->ActivateSyncTree(); |
| 6406 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6407 | |
| 6408 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6409 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6410 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6411 | |
| 6412 | ExecuteCalculateDrawProperties(root_impl); |
| 6413 | EXPECT_VECTOR2DF_EQ( |
| 6414 | gfx::Vector2dF(60.f, 70.f), |
| 6415 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6416 | |
| 6417 | // Scroll less than sticking point, sticky element should move with scroll as |
| 6418 | // we haven't gotten to the initial sticky item location yet. |
| 6419 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 6420 | ExecuteCalculateDrawProperties(root_impl); |
| 6421 | EXPECT_VECTOR2DF_EQ( |
| 6422 | gfx::Vector2dF(55.f, 65.f), |
| 6423 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6424 | |
| 6425 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 6426 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 6427 | ExecuteCalculateDrawProperties(root_impl); |
| 6428 | EXPECT_VECTOR2DF_EQ( |
| 6429 | gfx::Vector2dF(45.f, 60.f), |
| 6430 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6431 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f)); |
| 6432 | ExecuteCalculateDrawProperties(root_impl); |
| 6433 | EXPECT_VECTOR2DF_EQ( |
| 6434 | gfx::Vector2dF(45.f, 60.f), |
| 6435 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6436 | |
| 6437 | // Scroll past the end of the sticky container (note: this element does not |
| 6438 | // have its own layer as it does not need to be composited). |
| 6439 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); |
| 6440 | ExecuteCalculateDrawProperties(root_impl); |
| 6441 | EXPECT_VECTOR2DF_EQ( |
| 6442 | gfx::Vector2dF(45.f, 40.f), |
| 6443 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6444 | } |
| 6445 | |
flackr | dc5dfbe | 2016-10-24 21:43:38 | [diff] [blame] | 6446 | TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) { |
| 6447 | scoped_refptr<Layer> root = Layer::Create(); |
| 6448 | scoped_refptr<Layer> container = Layer::Create(); |
| 6449 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6450 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6451 | root->AddChild(container); |
| 6452 | container->AddChild(scroller); |
| 6453 | scroller->AddChild(sticky_pos); |
| 6454 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6455 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
flackr | dc5dfbe | 2016-10-24 21:43:38 | [diff] [blame] | 6456 | |
| 6457 | LayerStickyPositionConstraint sticky_position; |
| 6458 | sticky_position.is_sticky = true; |
| 6459 | sticky_position.is_anchored_bottom = true; |
| 6460 | sticky_position.bottom_offset = 10.0f; |
flackr | dc5dfbe | 2016-10-24 21:43:38 | [diff] [blame] | 6461 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6462 | gfx::Rect(0, 200, 10, 10); |
| 6463 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6464 | gfx::Rect(0, 0, 100, 500); |
| 6465 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6466 | |
| 6467 | root->SetBounds(gfx::Size(100, 100)); |
| 6468 | container->SetBounds(gfx::Size(100, 100)); |
| 6469 | scroller->SetBounds(gfx::Size(100, 1000)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6470 | scroller->SetScrollable(container->bounds()); |
flackr | dc5dfbe | 2016-10-24 21:43:38 | [diff] [blame] | 6471 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6472 | sticky_pos->SetPosition(gfx::PointF(0, 200)); |
| 6473 | |
| 6474 | ExecuteCalculateDrawProperties(root.get()); |
| 6475 | host()->host_impl()->CreatePendingTree(); |
| 6476 | host()->CommitAndCreatePendingTree(); |
| 6477 | host()->host_impl()->ActivateSyncTree(); |
| 6478 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6479 | |
| 6480 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6481 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6482 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6483 | |
| 6484 | ExecuteCalculateDrawProperties(root_impl); |
| 6485 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.8f)); |
| 6486 | ExecuteCalculateDrawProperties(root_impl); |
| 6487 | EXPECT_VECTOR2DF_EQ( |
| 6488 | gfx::Vector2dF(0.f, 80.f), |
| 6489 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6490 | } |
| 6491 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6492 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) { |
| 6493 | scoped_refptr<Layer> root = Layer::Create(); |
| 6494 | scoped_refptr<Layer> container = Layer::Create(); |
| 6495 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6496 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6497 | root->AddChild(container); |
| 6498 | container->AddChild(scroller); |
| 6499 | scroller->AddChild(sticky_pos); |
| 6500 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6501 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6502 | |
| 6503 | LayerStickyPositionConstraint sticky_position; |
| 6504 | sticky_position.is_sticky = true; |
| 6505 | sticky_position.is_anchored_bottom = true; |
| 6506 | sticky_position.bottom_offset = 10.0f; |
| 6507 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6508 | gfx::Rect(0, 150, 10, 10); |
| 6509 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6510 | gfx::Rect(0, 100, 50, 50); |
| 6511 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6512 | |
| 6513 | root->SetBounds(gfx::Size(100, 100)); |
| 6514 | container->SetBounds(gfx::Size(100, 100)); |
| 6515 | scroller->SetBounds(gfx::Size(1000, 1000)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6516 | scroller->SetScrollable(container->bounds()); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6517 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6518 | sticky_pos->SetPosition(gfx::PointF(0, 150)); |
| 6519 | |
| 6520 | ExecuteCalculateDrawProperties(root.get()); |
| 6521 | host()->host_impl()->CreatePendingTree(); |
| 6522 | host()->CommitAndCreatePendingTree(); |
| 6523 | host()->host_impl()->ActivateSyncTree(); |
| 6524 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6525 | |
| 6526 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6527 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6528 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6529 | |
| 6530 | // Initially the sticky element is moved up to the top of the container. |
| 6531 | ExecuteCalculateDrawProperties(root_impl); |
| 6532 | EXPECT_VECTOR2DF_EQ( |
| 6533 | gfx::Vector2dF(0.f, 100.f), |
| 6534 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6535 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 6536 | ExecuteCalculateDrawProperties(root_impl); |
| 6537 | EXPECT_VECTOR2DF_EQ( |
| 6538 | gfx::Vector2dF(0.f, 95.f), |
| 6539 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6540 | |
| 6541 | // Once we get past the top of the container it moves to be aligned 10px |
| 6542 | // up from the the bottom of the scroller. |
| 6543 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 6544 | ExecuteCalculateDrawProperties(root_impl); |
| 6545 | EXPECT_VECTOR2DF_EQ( |
| 6546 | gfx::Vector2dF(0.f, 80.f), |
| 6547 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6548 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 6549 | ExecuteCalculateDrawProperties(root_impl); |
| 6550 | EXPECT_VECTOR2DF_EQ( |
| 6551 | gfx::Vector2dF(0.f, 80.f), |
| 6552 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6553 | |
| 6554 | // Once we scroll past its initial location, it sticks there. |
| 6555 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f)); |
| 6556 | ExecuteCalculateDrawProperties(root_impl); |
| 6557 | EXPECT_VECTOR2DF_EQ( |
| 6558 | gfx::Vector2dF(0.f, 0.f), |
| 6559 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6560 | } |
| 6561 | |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6562 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) { |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 6563 | scoped_refptr<Layer> root = Layer::Create(); |
| 6564 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6565 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6566 | root->AddChild(scroller); |
| 6567 | scroller->AddChild(sticky_pos); |
| 6568 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6569 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
pdr | 5200a05 | 2017-05-21 22:50:58 | [diff] [blame] | 6570 | LayerTreeHost::ViewportLayers viewport_layers; |
| 6571 | viewport_layers.page_scale = root; |
| 6572 | viewport_layers.inner_viewport_container = root; |
| 6573 | viewport_layers.inner_viewport_scroll = scroller; |
| 6574 | host()->RegisterViewportLayers(viewport_layers); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 6575 | |
| 6576 | LayerStickyPositionConstraint sticky_position; |
| 6577 | sticky_position.is_sticky = true; |
| 6578 | sticky_position.is_anchored_bottom = true; |
| 6579 | sticky_position.bottom_offset = 10.0f; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 6580 | sticky_position.scroll_container_relative_sticky_box_rect = |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6581 | gfx::Rect(0, 70, 10, 10); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 6582 | sticky_position.scroll_container_relative_containing_block_rect = |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6583 | gfx::Rect(0, 60, 100, 100); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 6584 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6585 | |
| 6586 | root->SetBounds(gfx::Size(100, 100)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6587 | scroller->SetScrollable(gfx::Size(100, 100)); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 6588 | scroller->SetBounds(gfx::Size(100, 1000)); |
| 6589 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6590 | sticky_pos->SetPosition(gfx::PointF(0, 70)); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 6591 | |
| 6592 | ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6593 | scroller.get(), nullptr); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 6594 | host()->CommitAndCreateLayerImplTree(); |
| 6595 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6596 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6597 | ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id()); |
| 6598 | |
| 6599 | LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
| 6600 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6601 | |
| 6602 | // Initially the sticky element is moved to the bottom of the container. |
| 6603 | EXPECT_VECTOR2DF_EQ( |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6604 | gfx::Vector2dF(0.f, 70.f), |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 6605 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6606 | |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6607 | // We start to hide the toolbar, but not far enough that the sticky element |
| 6608 | // should be moved up yet. |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 6609 | root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6610 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 6611 | nullptr); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 6612 | EXPECT_VECTOR2DF_EQ( |
| 6613 | gfx::Vector2dF(0.f, 70.f), |
| 6614 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6615 | |
| 6616 | // On hiding more of the toolbar the sticky element starts to stick. |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 6617 | root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6618 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 6619 | nullptr); |
| 6620 | EXPECT_VECTOR2DF_EQ( |
| 6621 | gfx::Vector2dF(0.f, 60.f), |
| 6622 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6623 | |
| 6624 | // On hiding more the sticky element stops moving as it has reached its |
| 6625 | // limit. |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 6626 | root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6627 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 6628 | nullptr); |
| 6629 | EXPECT_VECTOR2DF_EQ( |
| 6630 | gfx::Vector2dF(0.f, 60.f), |
| 6631 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6632 | } |
| 6633 | |
| 6634 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) { |
| 6635 | scoped_refptr<Layer> root = Layer::Create(); |
| 6636 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6637 | scoped_refptr<Layer> outer_clip = Layer::Create(); |
| 6638 | scoped_refptr<Layer> outer_viewport = Layer::Create(); |
| 6639 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6640 | root->AddChild(scroller); |
| 6641 | scroller->AddChild(outer_clip); |
| 6642 | outer_clip->AddChild(outer_viewport); |
| 6643 | outer_viewport->AddChild(sticky_pos); |
| 6644 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6645 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
pdr | 5200a05 | 2017-05-21 22:50:58 | [diff] [blame] | 6646 | LayerTreeHost::ViewportLayers viewport_layers; |
| 6647 | viewport_layers.page_scale = root; |
| 6648 | viewport_layers.inner_viewport_container = root; |
| 6649 | viewport_layers.outer_viewport_container = outer_clip; |
| 6650 | viewport_layers.inner_viewport_scroll = scroller; |
| 6651 | viewport_layers.outer_viewport_scroll = outer_viewport; |
| 6652 | host()->RegisterViewportLayers(viewport_layers); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6653 | |
| 6654 | LayerStickyPositionConstraint sticky_position; |
| 6655 | sticky_position.is_sticky = true; |
| 6656 | sticky_position.is_anchored_bottom = true; |
| 6657 | sticky_position.bottom_offset = 10.0f; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6658 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6659 | gfx::Rect(0, 70, 10, 10); |
| 6660 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6661 | gfx::Rect(0, 60, 100, 100); |
| 6662 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6663 | |
| 6664 | root->SetBounds(gfx::Size(100, 100)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6665 | scroller->SetScrollable(gfx::Size(100, 100)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6666 | scroller->SetBounds(gfx::Size(100, 1000)); |
| 6667 | outer_clip->SetBounds(gfx::Size(100, 100)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6668 | outer_viewport->SetScrollable(gfx::Size(100, 100)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6669 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6670 | sticky_pos->SetPosition(gfx::PointF(0, 70)); |
| 6671 | |
| 6672 | ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), |
| 6673 | scroller.get(), outer_viewport.get()); |
| 6674 | host()->CommitAndCreateLayerImplTree(); |
| 6675 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6676 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6677 | ASSERT_EQ(outer_viewport->id(), |
| 6678 | layer_tree_impl->OuterViewportScrollLayer()->id()); |
| 6679 | |
| 6680 | LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
| 6681 | LayerImpl* outer_scroll = layer_tree_impl->OuterViewportScrollLayer(); |
| 6682 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6683 | LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id()); |
| 6684 | |
| 6685 | // Initially the sticky element is moved to the bottom of the container. |
| 6686 | EXPECT_VECTOR2DF_EQ( |
| 6687 | gfx::Vector2dF(0.f, 70.f), |
| 6688 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6689 | |
| 6690 | // We start to hide the toolbar, but not far enough that the sticky element |
| 6691 | // should be moved up yet. |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 6692 | outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6693 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 6694 | outer_scroll); |
| 6695 | EXPECT_VECTOR2DF_EQ( |
| 6696 | gfx::Vector2dF(0.f, 70.f), |
| 6697 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6698 | |
| 6699 | // On hiding more of the toolbar the sticky element starts to stick. |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 6700 | outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6701 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 6702 | outer_scroll); |
| 6703 | |
| 6704 | // On hiding more the sticky element stops moving as it has reached its |
| 6705 | // limit. |
| 6706 | EXPECT_VECTOR2DF_EQ( |
| 6707 | gfx::Vector2dF(0.f, 60.f), |
| 6708 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6709 | |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 6710 | outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 6711 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 6712 | outer_scroll); |
| 6713 | |
| 6714 | EXPECT_VECTOR2DF_EQ( |
| 6715 | gfx::Vector2dF(0.f, 60.f), |
| 6716 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 6717 | } |
| 6718 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6719 | TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { |
| 6720 | scoped_refptr<Layer> root = Layer::Create(); |
| 6721 | scoped_refptr<Layer> container = Layer::Create(); |
| 6722 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6723 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6724 | root->AddChild(container); |
| 6725 | container->AddChild(scroller); |
| 6726 | scroller->AddChild(sticky_pos); |
| 6727 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6728 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6729 | |
| 6730 | LayerStickyPositionConstraint sticky_position; |
| 6731 | sticky_position.is_sticky = true; |
| 6732 | sticky_position.is_anchored_left = true; |
| 6733 | sticky_position.is_anchored_right = true; |
| 6734 | sticky_position.left_offset = 10.f; |
| 6735 | sticky_position.right_offset = 10.f; |
| 6736 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6737 | gfx::Rect(145, 0, 10, 10); |
| 6738 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6739 | gfx::Rect(100, 0, 100, 100); |
| 6740 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6741 | |
| 6742 | root->SetBounds(gfx::Size(100, 100)); |
| 6743 | container->SetBounds(gfx::Size(100, 100)); |
| 6744 | scroller->SetBounds(gfx::Size(1000, 1000)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6745 | scroller->SetScrollable(container->bounds()); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6746 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6747 | sticky_pos->SetPosition(gfx::PointF(145, 0)); |
| 6748 | |
| 6749 | ExecuteCalculateDrawProperties(root.get()); |
| 6750 | host()->host_impl()->CreatePendingTree(); |
| 6751 | host()->CommitAndCreatePendingTree(); |
| 6752 | host()->host_impl()->ActivateSyncTree(); |
| 6753 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6754 | |
| 6755 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6756 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6757 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6758 | |
| 6759 | // Initially the sticky element is moved the leftmost side of the container. |
| 6760 | ExecuteCalculateDrawProperties(root_impl); |
| 6761 | EXPECT_VECTOR2DF_EQ( |
| 6762 | gfx::Vector2dF(100.f, 0.f), |
| 6763 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6764 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f)); |
| 6765 | ExecuteCalculateDrawProperties(root_impl); |
| 6766 | EXPECT_VECTOR2DF_EQ( |
| 6767 | gfx::Vector2dF(95.f, 0.f), |
| 6768 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6769 | |
| 6770 | // Once we get past the left side of the container it moves to be aligned 10px |
| 6771 | // up from the the right of the scroller. |
| 6772 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f)); |
| 6773 | ExecuteCalculateDrawProperties(root_impl); |
| 6774 | EXPECT_VECTOR2DF_EQ( |
| 6775 | gfx::Vector2dF(80.f, 0.f), |
| 6776 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6777 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f)); |
| 6778 | ExecuteCalculateDrawProperties(root_impl); |
| 6779 | EXPECT_VECTOR2DF_EQ( |
| 6780 | gfx::Vector2dF(80.f, 0.f), |
| 6781 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6782 | |
| 6783 | // When we get to the sticky element's original position we stop sticking |
| 6784 | // to the right. |
| 6785 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f)); |
| 6786 | ExecuteCalculateDrawProperties(root_impl); |
| 6787 | EXPECT_VECTOR2DF_EQ( |
| 6788 | gfx::Vector2dF(50.f, 0.f), |
| 6789 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6790 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f)); |
| 6791 | ExecuteCalculateDrawProperties(root_impl); |
| 6792 | EXPECT_VECTOR2DF_EQ( |
| 6793 | gfx::Vector2dF(40.f, 0.f), |
| 6794 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6795 | |
| 6796 | // The element starts sticking to the left once we scroll far enough. |
| 6797 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f)); |
| 6798 | ExecuteCalculateDrawProperties(root_impl); |
| 6799 | EXPECT_VECTOR2DF_EQ( |
| 6800 | gfx::Vector2dF(10.f, 0.f), |
| 6801 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6802 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f)); |
| 6803 | ExecuteCalculateDrawProperties(root_impl); |
| 6804 | EXPECT_VECTOR2DF_EQ( |
| 6805 | gfx::Vector2dF(10.f, 0.f), |
| 6806 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6807 | |
| 6808 | // Finally it stops sticking when it hits the right side of the container. |
| 6809 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f)); |
| 6810 | ExecuteCalculateDrawProperties(root_impl); |
| 6811 | EXPECT_VECTOR2DF_EQ( |
| 6812 | gfx::Vector2dF(0.f, 0.f), |
| 6813 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6814 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f)); |
| 6815 | ExecuteCalculateDrawProperties(root_impl); |
| 6816 | EXPECT_VECTOR2DF_EQ( |
| 6817 | gfx::Vector2dF(-5.f, 0.f), |
| 6818 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6819 | } |
| 6820 | |
| 6821 | // This test ensures that the compositor sticky position code correctly accounts |
| 6822 | // for the element having been given a position from the main thread sticky |
| 6823 | // position code. |
| 6824 | TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) { |
| 6825 | scoped_refptr<Layer> root = Layer::Create(); |
| 6826 | scoped_refptr<Layer> container = Layer::Create(); |
| 6827 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6828 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6829 | root->AddChild(container); |
| 6830 | container->AddChild(scroller); |
| 6831 | scroller->AddChild(sticky_pos); |
| 6832 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6833 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6834 | |
| 6835 | LayerStickyPositionConstraint sticky_position; |
| 6836 | sticky_position.is_sticky = true; |
| 6837 | sticky_position.is_anchored_top = true; |
| 6838 | sticky_position.top_offset = 10.0f; |
| 6839 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6840 | gfx::Rect(10, 20, 10, 10); |
| 6841 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6842 | gfx::Rect(0, 0, 50, 50); |
| 6843 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6844 | |
| 6845 | root->SetBounds(gfx::Size(100, 100)); |
| 6846 | container->SetBounds(gfx::Size(100, 100)); |
| 6847 | scroller->SetBounds(gfx::Size(1000, 1000)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6848 | scroller->SetScrollable(container->bounds()); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6849 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6850 | sticky_pos->SetPosition(gfx::PointF(10, 20)); |
| 6851 | |
| 6852 | ExecuteCalculateDrawProperties(root.get()); |
| 6853 | host()->host_impl()->CreatePendingTree(); |
| 6854 | host()->CommitAndCreatePendingTree(); |
| 6855 | host()->host_impl()->ActivateSyncTree(); |
| 6856 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6857 | |
| 6858 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6859 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6860 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6861 | |
| 6862 | ExecuteCalculateDrawProperties(root_impl); |
| 6863 | EXPECT_VECTOR2DF_EQ( |
| 6864 | gfx::Vector2dF(10.f, 20.f), |
| 6865 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6866 | |
| 6867 | // Scroll less than sticking point, sticky element should move with scroll as |
| 6868 | // we haven't gotten to the initial sticky item location yet. |
| 6869 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 6870 | ExecuteCalculateDrawProperties(root_impl); |
| 6871 | EXPECT_VECTOR2DF_EQ( |
| 6872 | gfx::Vector2dF(5.f, 15.f), |
| 6873 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6874 | |
| 6875 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 6876 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 6877 | ExecuteCalculateDrawProperties(root_impl); |
| 6878 | EXPECT_VECTOR2DF_EQ( |
| 6879 | gfx::Vector2dF(-5.f, 10.f), |
| 6880 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6881 | |
| 6882 | // Now the main thread commits the new position of the sticky element. |
| 6883 | scroller->SetScrollOffset(gfx::ScrollOffset(15, 15)); |
yigu | 23b68f6 | 2017-06-13 12:35:07 | [diff] [blame] | 6884 | // Shift the layer by -offset_for_position_sticky. |
| 6885 | sticky_pos->SetPosition(gfx::PointF(10, 25) - gfx::Vector2dF(0, 5)); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6886 | ExecuteCalculateDrawProperties(root.get()); |
| 6887 | host()->host_impl()->CreatePendingTree(); |
| 6888 | host()->CommitAndCreatePendingTree(); |
| 6889 | host()->host_impl()->ActivateSyncTree(); |
| 6890 | layer_tree_impl = host()->host_impl()->active_tree(); |
| 6891 | root_impl = layer_tree_impl->LayerById(root->id()); |
| 6892 | scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6893 | sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6894 | |
| 6895 | // The element should still be where it was before. We reset the delta to |
| 6896 | // (0, 0) because we have synced a scroll offset of (15, 15) from the main |
| 6897 | // thread. |
| 6898 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); |
| 6899 | ExecuteCalculateDrawProperties(root_impl); |
| 6900 | EXPECT_VECTOR2DF_EQ( |
| 6901 | gfx::Vector2dF(-5.f, 10.f), |
| 6902 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6903 | |
| 6904 | // And if we scroll a little further it remains there. |
| 6905 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); |
| 6906 | ExecuteCalculateDrawProperties(root_impl); |
| 6907 | EXPECT_VECTOR2DF_EQ( |
| 6908 | gfx::Vector2dF(-5.f, 10.f), |
| 6909 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6910 | } |
| 6911 | |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 6912 | // This tests the main thread updates with a composited sticky container. In |
| 6913 | // this case the position received from main is relative to the container but |
| 6914 | // the constraint rects are relative to the ancestor scroller. |
| 6915 | TEST_F(LayerTreeHostCommonTest, StickyPositionCompositedContainer) { |
| 6916 | scoped_refptr<Layer> root = Layer::Create(); |
| 6917 | scoped_refptr<Layer> container = Layer::Create(); |
| 6918 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6919 | scoped_refptr<Layer> sticky_container = Layer::Create(); |
| 6920 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6921 | root->AddChild(container); |
| 6922 | container->AddChild(scroller); |
| 6923 | scroller->AddChild(sticky_container); |
| 6924 | sticky_container->AddChild(sticky_pos); |
| 6925 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 6926 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 6927 | |
| 6928 | LayerStickyPositionConstraint sticky_position; |
| 6929 | sticky_position.is_sticky = true; |
| 6930 | sticky_position.is_anchored_top = true; |
| 6931 | sticky_position.top_offset = 10.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 6932 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6933 | gfx::Rect(20, 30, 10, 10); |
| 6934 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6935 | gfx::Rect(20, 20, 30, 30); |
| 6936 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6937 | |
| 6938 | root->SetBounds(gfx::Size(100, 100)); |
| 6939 | container->SetBounds(gfx::Size(100, 100)); |
| 6940 | scroller->SetBounds(gfx::Size(1000, 1000)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 6941 | scroller->SetScrollable(container->bounds()); |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 6942 | sticky_container->SetPosition(gfx::PointF(20, 20)); |
| 6943 | sticky_container->SetBounds(gfx::Size(30, 30)); |
| 6944 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6945 | sticky_pos->SetPosition(gfx::PointF(0, 10)); |
| 6946 | |
| 6947 | ExecuteCalculateDrawProperties(root.get()); |
| 6948 | host()->host_impl()->CreatePendingTree(); |
| 6949 | host()->CommitAndCreatePendingTree(); |
| 6950 | host()->host_impl()->ActivateSyncTree(); |
| 6951 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6952 | |
| 6953 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6954 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6955 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6956 | |
| 6957 | ExecuteCalculateDrawProperties(root_impl); |
| 6958 | EXPECT_VECTOR2DF_EQ( |
| 6959 | gfx::Vector2dF(20.f, 30.f), |
| 6960 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6961 | |
| 6962 | // Scroll less than sticking point, sticky element should move with scroll as |
| 6963 | // we haven't gotten to the initial sticky item location yet. |
| 6964 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 6965 | ExecuteCalculateDrawProperties(root_impl); |
| 6966 | EXPECT_VECTOR2DF_EQ( |
| 6967 | gfx::Vector2dF(20.f, 25.f), |
| 6968 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6969 | |
| 6970 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 6971 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 6972 | ExecuteCalculateDrawProperties(root_impl); |
| 6973 | EXPECT_VECTOR2DF_EQ( |
| 6974 | gfx::Vector2dF(20.f, 10.f), |
| 6975 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6976 | |
| 6977 | // Now the main thread commits the new position of the sticky element. |
| 6978 | scroller->SetScrollOffset(gfx::ScrollOffset(0, 25)); |
yigu | 23b68f6 | 2017-06-13 12:35:07 | [diff] [blame] | 6979 | // Shift the layer by -offset_for_position_sticky. |
| 6980 | sticky_pos->SetPosition(gfx::PointF(0, 15) - gfx::Vector2dF(0, 5)); |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 6981 | ExecuteCalculateDrawProperties(root.get()); |
| 6982 | host()->host_impl()->CreatePendingTree(); |
| 6983 | host()->CommitAndCreatePendingTree(); |
| 6984 | host()->host_impl()->ActivateSyncTree(); |
| 6985 | layer_tree_impl = host()->host_impl()->active_tree(); |
| 6986 | root_impl = layer_tree_impl->LayerById(root->id()); |
| 6987 | scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6988 | sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6989 | |
| 6990 | // The element should still be where it was before. We reset the delta to |
| 6991 | // (0, 0) because we have synced a scroll offset of (0, 25) from the main |
| 6992 | // thread. |
| 6993 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); |
| 6994 | ExecuteCalculateDrawProperties(root_impl); |
| 6995 | EXPECT_VECTOR2DF_EQ( |
| 6996 | gfx::Vector2dF(20.f, 10.f), |
| 6997 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6998 | |
| 6999 | // And if we scroll a little further it remains there. |
| 7000 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 7001 | ExecuteCalculateDrawProperties(root_impl); |
| 7002 | EXPECT_VECTOR2DF_EQ( |
| 7003 | gfx::Vector2dF(20.f, 10.f), |
| 7004 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7005 | |
| 7006 | // And hits the bottom of the container. |
| 7007 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); |
| 7008 | ExecuteCalculateDrawProperties(root_impl); |
| 7009 | EXPECT_VECTOR2DF_EQ( |
| 7010 | gfx::Vector2dF(20.f, 5.f), |
| 7011 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7012 | } |
| 7013 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7014 | // A transform on a sticky element should not affect its sticky position. |
| 7015 | TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) { |
| 7016 | scoped_refptr<Layer> root = Layer::Create(); |
| 7017 | scoped_refptr<Layer> container = Layer::Create(); |
| 7018 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7019 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7020 | root->AddChild(container); |
| 7021 | container->AddChild(scroller); |
| 7022 | scroller->AddChild(sticky_pos); |
| 7023 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 7024 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7025 | gfx::Transform t; |
| 7026 | t.Scale(2, 2); |
| 7027 | sticky_pos->SetTransform(t); |
| 7028 | |
| 7029 | LayerStickyPositionConstraint sticky_position; |
| 7030 | sticky_position.is_sticky = true; |
| 7031 | sticky_position.is_anchored_top = true; |
| 7032 | sticky_position.top_offset = 0.0f; |
| 7033 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7034 | gfx::Rect(0, 20, 10, 10); |
| 7035 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7036 | gfx::Rect(0, 0, 50, 50); |
| 7037 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7038 | |
| 7039 | root->SetBounds(gfx::Size(100, 100)); |
| 7040 | container->SetBounds(gfx::Size(100, 100)); |
| 7041 | scroller->SetBounds(gfx::Size(1000, 1000)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 7042 | scroller->SetScrollable(container->bounds()); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7043 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7044 | sticky_pos->SetPosition(gfx::PointF(0, 20)); |
| 7045 | |
| 7046 | ExecuteCalculateDrawProperties(root.get()); |
| 7047 | host()->host_impl()->CreatePendingTree(); |
| 7048 | host()->CommitAndCreatePendingTree(); |
| 7049 | host()->host_impl()->ActivateSyncTree(); |
| 7050 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7051 | |
| 7052 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7053 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7054 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7055 | |
| 7056 | ExecuteCalculateDrawProperties(root_impl); |
| 7057 | EXPECT_VECTOR2DF_EQ( |
| 7058 | gfx::Vector2dF(0.f, 20.f), |
| 7059 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7060 | |
| 7061 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7062 | // we haven't gotten to the initial sticky item location yet. |
| 7063 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f)); |
| 7064 | ExecuteCalculateDrawProperties(root_impl); |
| 7065 | EXPECT_VECTOR2DF_EQ( |
| 7066 | gfx::Vector2dF(0.f, 5.f), |
| 7067 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7068 | |
| 7069 | // Scroll past the sticking point, the box is positioned at the scroller |
| 7070 | // edge. |
| 7071 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7072 | ExecuteCalculateDrawProperties(root_impl); |
| 7073 | EXPECT_VECTOR2DF_EQ( |
| 7074 | gfx::Vector2dF(0.f, 0.f), |
| 7075 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7076 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7077 | ExecuteCalculateDrawProperties(root_impl); |
| 7078 | EXPECT_VECTOR2DF_EQ( |
| 7079 | gfx::Vector2dF(0.f, 0.f), |
| 7080 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7081 | |
| 7082 | // Scroll past the end of the sticky container. |
| 7083 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); |
| 7084 | ExecuteCalculateDrawProperties(root_impl); |
| 7085 | EXPECT_VECTOR2DF_EQ( |
| 7086 | gfx::Vector2dF(0.f, -10.f), |
| 7087 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7088 | } |
| 7089 | |
| 7090 | // Tests that a transform does not affect the sticking points. The sticky |
| 7091 | // element will however move relative to the viewport due to its transform. |
| 7092 | TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) { |
| 7093 | scoped_refptr<Layer> root = Layer::Create(); |
| 7094 | scoped_refptr<Layer> container = Layer::Create(); |
| 7095 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7096 | scoped_refptr<Layer> sticky_container = Layer::Create(); |
| 7097 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7098 | root->AddChild(container); |
| 7099 | container->AddChild(scroller); |
| 7100 | scroller->AddChild(sticky_container); |
| 7101 | sticky_container->AddChild(sticky_pos); |
| 7102 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 7103 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7104 | gfx::Transform t; |
| 7105 | t.Scale(2, 2); |
| 7106 | sticky_container->SetTransform(t); |
| 7107 | |
| 7108 | LayerStickyPositionConstraint sticky_position; |
| 7109 | sticky_position.is_sticky = true; |
| 7110 | sticky_position.is_anchored_top = true; |
| 7111 | sticky_position.top_offset = 0.0f; |
| 7112 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7113 | gfx::Rect(0, 20, 10, 10); |
| 7114 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7115 | gfx::Rect(0, 0, 50, 50); |
| 7116 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7117 | |
| 7118 | root->SetBounds(gfx::Size(100, 100)); |
| 7119 | container->SetBounds(gfx::Size(100, 100)); |
| 7120 | scroller->SetBounds(gfx::Size(1000, 1000)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 7121 | scroller->SetScrollable(container->bounds()); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7122 | sticky_container->SetBounds(gfx::Size(50, 50)); |
| 7123 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7124 | sticky_pos->SetPosition(gfx::PointF(0, 20)); |
| 7125 | |
| 7126 | ExecuteCalculateDrawProperties(root.get()); |
| 7127 | host()->host_impl()->CreatePendingTree(); |
| 7128 | host()->CommitAndCreatePendingTree(); |
| 7129 | host()->host_impl()->ActivateSyncTree(); |
| 7130 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7131 | |
| 7132 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7133 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7134 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7135 | |
| 7136 | ExecuteCalculateDrawProperties(root_impl); |
| 7137 | EXPECT_VECTOR2DF_EQ( |
| 7138 | gfx::Vector2dF(0.f, 40.f), |
| 7139 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7140 | |
| 7141 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7142 | // we haven't gotten to the initial sticky item location yet. |
| 7143 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f)); |
| 7144 | ExecuteCalculateDrawProperties(root_impl); |
| 7145 | EXPECT_VECTOR2DF_EQ( |
| 7146 | gfx::Vector2dF(0.f, 25.f), |
| 7147 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7148 | |
| 7149 | // Scroll past the sticking point, the box is positioned at the scroller |
| 7150 | // edge but is also scaled by its container so it begins to move down. |
| 7151 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7152 | ExecuteCalculateDrawProperties(root_impl); |
| 7153 | EXPECT_VECTOR2DF_EQ( |
| 7154 | gfx::Vector2dF(0.f, 25.f), |
| 7155 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7156 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7157 | ExecuteCalculateDrawProperties(root_impl); |
| 7158 | EXPECT_VECTOR2DF_EQ( |
| 7159 | gfx::Vector2dF(0.f, 30.f), |
| 7160 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7161 | |
| 7162 | // Scroll past the end of the sticky container. |
| 7163 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); |
| 7164 | ExecuteCalculateDrawProperties(root_impl); |
| 7165 | EXPECT_VECTOR2DF_EQ( |
| 7166 | gfx::Vector2dF(0.f, 30.f), |
| 7167 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7168 | } |
| 7169 | |
smcgruer | 29014ff | 2017-03-24 14:34:43 | [diff] [blame] | 7170 | TEST_F(LayerTreeHostCommonTest, StickyPositionNested) { |
| 7171 | scoped_refptr<Layer> root = Layer::Create(); |
| 7172 | scoped_refptr<Layer> container = Layer::Create(); |
| 7173 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7174 | scoped_refptr<Layer> outer_sticky = Layer::Create(); |
| 7175 | scoped_refptr<Layer> inner_sticky = Layer::Create(); |
| 7176 | |
| 7177 | root->AddChild(container); |
| 7178 | container->AddChild(scroller); |
| 7179 | scroller->AddChild(outer_sticky); |
| 7180 | outer_sticky->AddChild(inner_sticky); |
| 7181 | host()->SetRootLayer(root); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 7182 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
smcgruer | 29014ff | 2017-03-24 14:34:43 | [diff] [blame] | 7183 | |
| 7184 | root->SetBounds(gfx::Size(100, 100)); |
| 7185 | container->SetBounds(gfx::Size(100, 100)); |
| 7186 | scroller->SetBounds(gfx::Size(100, 1000)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 7187 | scroller->SetScrollable(container->bounds()); |
smcgruer | 29014ff | 2017-03-24 14:34:43 | [diff] [blame] | 7188 | outer_sticky->SetBounds(gfx::Size(10, 50)); |
| 7189 | outer_sticky->SetPosition(gfx::PointF(0, 50)); |
| 7190 | inner_sticky->SetBounds(gfx::Size(10, 10)); |
| 7191 | inner_sticky->SetPosition(gfx::PointF(0, 0)); |
| 7192 | |
| 7193 | LayerStickyPositionConstraint outer_sticky_pos; |
| 7194 | outer_sticky_pos.is_sticky = true; |
| 7195 | outer_sticky_pos.is_anchored_top = true; |
| 7196 | outer_sticky_pos.top_offset = 10.0f; |
smcgruer | 29014ff | 2017-03-24 14:34:43 | [diff] [blame] | 7197 | outer_sticky_pos.scroll_container_relative_sticky_box_rect = |
| 7198 | gfx::Rect(0, 50, 10, 50); |
| 7199 | outer_sticky_pos.scroll_container_relative_containing_block_rect = |
| 7200 | gfx::Rect(0, 0, 50, 400); |
| 7201 | outer_sticky->SetStickyPositionConstraint(outer_sticky_pos); |
| 7202 | |
| 7203 | LayerStickyPositionConstraint inner_sticky_pos; |
| 7204 | inner_sticky_pos.is_sticky = true; |
| 7205 | inner_sticky_pos.is_anchored_top = true; |
| 7206 | inner_sticky_pos.top_offset = 25.0f; |
smcgruer | 29014ff | 2017-03-24 14:34:43 | [diff] [blame] | 7207 | inner_sticky_pos.scroll_container_relative_sticky_box_rect = |
| 7208 | gfx::Rect(0, 50, 10, 10); |
| 7209 | inner_sticky_pos.scroll_container_relative_containing_block_rect = |
| 7210 | gfx::Rect(0, 50, 10, 50); |
| 7211 | inner_sticky_pos.nearest_layer_shifting_containing_block = outer_sticky->id(); |
| 7212 | inner_sticky->SetStickyPositionConstraint(inner_sticky_pos); |
| 7213 | |
| 7214 | ExecuteCalculateDrawProperties(root.get()); |
| 7215 | host()->host_impl()->CreatePendingTree(); |
| 7216 | host()->CommitAndCreatePendingTree(); |
| 7217 | host()->host_impl()->ActivateSyncTree(); |
| 7218 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7219 | |
| 7220 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7221 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7222 | LayerImpl* outer_sticky_impl = layer_tree_impl->LayerById(outer_sticky->id()); |
| 7223 | LayerImpl* inner_sticky_impl = layer_tree_impl->LayerById(inner_sticky->id()); |
| 7224 | |
| 7225 | ExecuteCalculateDrawProperties(root_impl); |
| 7226 | |
| 7227 | // Before any scrolling is done, the sticky elements should still be at their |
| 7228 | // original positions. |
| 7229 | EXPECT_VECTOR2DF_EQ( |
| 7230 | gfx::Vector2dF(0.f, 50.f), |
| 7231 | outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7232 | EXPECT_VECTOR2DF_EQ( |
| 7233 | gfx::Vector2dF(0.f, 50.f), |
| 7234 | inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7235 | |
| 7236 | // Scroll less than the sticking point. Both sticky elements should move with |
| 7237 | // scroll as we haven't gotten to the sticky item locations yet. |
| 7238 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 7239 | ExecuteCalculateDrawProperties(root_impl); |
| 7240 | EXPECT_VECTOR2DF_EQ( |
| 7241 | gfx::Vector2dF(0.f, 45.f), |
| 7242 | outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7243 | EXPECT_VECTOR2DF_EQ( |
| 7244 | gfx::Vector2dF(0.f, 45.f), |
| 7245 | inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7246 | |
| 7247 | // Scroll such that the inner sticky should stick, but the outer one should |
| 7248 | // keep going as it hasn't reached its position yet. |
| 7249 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7250 | ExecuteCalculateDrawProperties(root_impl); |
| 7251 | EXPECT_VECTOR2DF_EQ( |
| 7252 | gfx::Vector2dF(0.f, 20.f), |
| 7253 | outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7254 | EXPECT_VECTOR2DF_EQ( |
| 7255 | gfx::Vector2dF(0.f, 25.f), |
| 7256 | inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7257 | |
| 7258 | // Keep going, both should stick. |
| 7259 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 100.f)); |
| 7260 | ExecuteCalculateDrawProperties(root_impl); |
| 7261 | EXPECT_VECTOR2DF_EQ( |
| 7262 | gfx::Vector2dF(0.f, 10.f), |
| 7263 | outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7264 | EXPECT_VECTOR2DF_EQ( |
| 7265 | gfx::Vector2dF(0.f, 25.f), |
| 7266 | inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7267 | } |
| 7268 | |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7269 | TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { |
| 7270 | scoped_refptr<Layer> root = Layer::Create(); |
| 7271 | scoped_refptr<Layer> container = Layer::Create(); |
| 7272 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7273 | scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 7274 | |
| 7275 | scroller->SetIsContainerForFixedPositionLayers(true); |
| 7276 | root->AddChild(container); |
| 7277 | container->AddChild(scroller); |
| 7278 | scroller->AddChild(fixed_pos); |
| 7279 | host()->SetRootLayer(root); |
| 7280 | |
| 7281 | LayerPositionConstraint fixed_position; |
| 7282 | fixed_position.set_is_fixed_position(true); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 7283 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7284 | fixed_pos->SetPositionConstraint(fixed_position); |
| 7285 | |
| 7286 | root->SetBounds(gfx::Size(50, 50)); |
| 7287 | container->SetBounds(gfx::Size(50, 50)); |
| 7288 | scroller->SetBounds(gfx::Size(50, 50)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 7289 | scroller->SetScrollable(container->bounds()); |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7290 | fixed_pos->SetBounds(gfx::Size(50, 50)); |
| 7291 | |
| 7292 | gfx::Transform rotate; |
| 7293 | rotate.RotateAboutXAxis(20); |
| 7294 | container->SetTransform(rotate); |
| 7295 | |
| 7296 | ExecuteCalculateDrawProperties(root.get()); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 7297 | TransformTree& tree = |
| 7298 | root->layer_tree_host()->property_trees()->transform_tree; |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7299 | gfx::Transform transform; |
| 7300 | tree.ComputeTranslation(fixed_pos->transform_tree_index(), |
| 7301 | container->transform_tree_index(), &transform); |
| 7302 | EXPECT_TRUE(transform.IsIdentity()); |
| 7303 | } |
| 7304 | |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 7305 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) { |
| 7306 | // This test verifies that a fixed pos child of a scrolling layer doesn't get |
| 7307 | // snapped to integer coordinates. |
| 7308 | // |
| 7309 | // + root |
| 7310 | // + container |
| 7311 | // + scroller |
| 7312 | // + fixed_pos |
| 7313 | // |
| 7314 | scoped_refptr<Layer> root = Layer::Create(); |
| 7315 | scoped_refptr<Layer> container = Layer::Create(); |
| 7316 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7317 | scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 7318 | |
| 7319 | scroller->SetIsContainerForFixedPositionLayers(true); |
| 7320 | |
| 7321 | root->AddChild(container); |
| 7322 | container->AddChild(scroller); |
| 7323 | scroller->AddChild(fixed_pos); |
| 7324 | host()->SetRootLayer(root); |
| 7325 | |
| 7326 | LayerPositionConstraint fixed_position; |
| 7327 | fixed_position.set_is_fixed_position(true); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 7328 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 7329 | fixed_pos->SetPositionConstraint(fixed_position); |
| 7330 | |
| 7331 | root->SetBounds(gfx::Size(50, 50)); |
| 7332 | container->SetBounds(gfx::Size(50, 50)); |
| 7333 | scroller->SetBounds(gfx::Size(100, 100)); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 7334 | scroller->SetScrollable(container->bounds()); |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 7335 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 7336 | fixed_pos->SetBounds(gfx::Size(10, 10)); |
| 7337 | |
| 7338 | ExecuteCalculateDrawProperties(root.get()); |
| 7339 | |
| 7340 | host()->host_impl()->CreatePendingTree(); |
| 7341 | host()->CommitAndCreatePendingTree(); |
| 7342 | host()->host_impl()->ActivateSyncTree(); |
| 7343 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7344 | |
| 7345 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7346 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7347 | LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id()); |
| 7348 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 7349 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 7350 | |
| 7351 | ExecuteCalculateDrawProperties(root_impl); |
| 7352 | |
| 7353 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 7354 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 7355 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7356 | |
| 7357 | gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f, |
| 7358 | 10.3f); |
| 7359 | EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation, |
| 7360 | fixed_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7361 | } |
| 7362 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7363 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7364 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7365 | static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7366 | LayerTreeImpl* tree_impl, |
| 7367 | int id) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7368 | return base::WrapUnique( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7369 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7370 | } |
| 7371 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7372 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7373 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7374 | private: |
| 7375 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7376 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7377 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7378 | SetDrawsContent(true); |
| 7379 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7380 | }; |
| 7381 | |
| 7382 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7383 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7384 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 7385 | LayerTreeSettings settings = host()->GetSettings(); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7386 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7387 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 7388 | &task_graph_runner); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7389 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7390 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7391 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7392 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7393 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7394 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7395 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7396 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7397 | |
| 7398 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7399 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7400 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7401 | AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get(); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7402 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7403 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 7404 | parent->SetBounds(gfx::Size(1, 2)); |
| 7405 | child->SetBounds(gfx::Size(1, 2)); |
| 7406 | grand_child->SetBounds(gfx::Size(1, 2)); |
| 7407 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7408 | child->test_properties()->AddChild(std::move(grand_child)); |
| 7409 | parent->test_properties()->AddChild(std::move(child)); |
| 7410 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7411 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 7412 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7413 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7414 | |
| 7415 | // No layers have animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7416 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7417 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7418 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7419 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7420 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7421 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7422 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7423 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7424 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7425 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7426 | TransformOperations translation; |
| 7427 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7428 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7429 | scoped_refptr<AnimationTimeline> timeline; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7430 | timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7431 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7432 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7433 | host_impl.active_tree()->SetElementIdsForTesting(); |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7434 | |
| 7435 | scoped_refptr<AnimationPlayer> grand_parent_player = |
| 7436 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7437 | timeline->AttachPlayer(grand_parent_player); |
| 7438 | grand_parent_player->AttachElement(grand_parent_raw->element_id()); |
| 7439 | |
| 7440 | scoped_refptr<AnimationPlayer> parent_player = |
| 7441 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7442 | timeline->AttachPlayer(parent_player); |
| 7443 | parent_player->AttachElement(parent_raw->element_id()); |
| 7444 | |
| 7445 | scoped_refptr<AnimationPlayer> child_player = |
| 7446 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7447 | timeline->AttachPlayer(child_player); |
| 7448 | child_player->AttachElement(child_raw->element_id()); |
| 7449 | |
| 7450 | scoped_refptr<AnimationPlayer> grand_child_player = |
| 7451 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7452 | timeline->AttachPlayer(grand_child_player); |
| 7453 | grand_child_player->AttachElement(grand_child_raw->element_id()); |
| 7454 | |
| 7455 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7456 | translation); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7457 | |
| 7458 | // No layers have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7459 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7460 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7461 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7462 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7463 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7464 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7465 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7466 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7467 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7468 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7469 | TransformOperations scale; |
| 7470 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7471 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7472 | AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(), |
| 7473 | scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7474 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7475 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7476 | |
| 7477 | // Only |child| has a scale-affecting animation. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7478 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7479 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7480 | EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw)); |
| 7481 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7482 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7483 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7484 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7485 | EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw)); |
| 7486 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7487 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7488 | AddAnimatedTransformToPlayer(grand_parent_player.get(), 1.0, |
| 7489 | TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7490 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7491 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7492 | |
| 7493 | // |grand_parent| and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7494 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7495 | EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7496 | // We don't support combining animated scales from two nodes; 0.f means |
| 7497 | // that the maximum scale could not be computed. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7498 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7499 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7500 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7501 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7502 | EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw)); |
| 7503 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7504 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7505 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7506 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7507 | scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7508 | parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7509 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7510 | |
| 7511 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7512 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7513 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7514 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7515 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7516 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7517 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7518 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7519 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7520 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7521 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7522 | grand_parent_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 7523 | parent_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 7524 | child_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7525 | |
| 7526 | TransformOperations perspective; |
| 7527 | perspective.AppendPerspective(10.f); |
| 7528 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7529 | AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(), |
| 7530 | perspective); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7531 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7532 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7533 | |
| 7534 | // |child| has a scale-affecting animation but computing the maximum of this |
| 7535 | // animation is not supported. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7536 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7537 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7538 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7539 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7540 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7541 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7542 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7543 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7544 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7545 | |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 7546 | child_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 7547 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7548 | gfx::Transform scale_matrix; |
| 7549 | scale_matrix.Scale(1.f, 2.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7550 | grand_parent_raw->test_properties()->transform = scale_matrix; |
| 7551 | parent_raw->test_properties()->transform = scale_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7552 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7553 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7554 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7555 | scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7556 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7557 | |
| 7558 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 7559 | // animation with maximum scale 5.f. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7560 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7561 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 7562 | EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw)); |
| 7563 | EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7564 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7565 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7566 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 7567 | EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw)); |
| 7568 | EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7569 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7570 | gfx::Transform perspective_matrix; |
| 7571 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7572 | child_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7573 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7574 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7575 | |
| 7576 | // |child| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7577 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7578 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 7579 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7580 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7581 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7582 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7583 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 7584 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7585 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7586 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7587 | parent_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7588 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7589 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7590 | |
| 7591 | // |parent| and |child| have transforms that are neither translations nor |
| 7592 | // scales. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7593 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7594 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7595 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7596 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7597 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7598 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7599 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7600 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7601 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7602 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7603 | parent_raw->test_properties()->transform = gfx::Transform(); |
| 7604 | child_raw->test_properties()->transform = gfx::Transform(); |
| 7605 | grand_parent_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7606 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7607 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7608 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7609 | |
| 7610 | // |grand_parent| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7611 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7612 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7613 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7614 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7615 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7616 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7617 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7618 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7619 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7620 | } |
| 7621 | |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7622 | static void GatherDrawnLayers(LayerTreeImpl* tree_impl, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7623 | std::set<LayerImpl*>* drawn_layers) { |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7624 | for (EffectTreeLayerListIterator it(tree_impl); |
| 7625 | it.state() != EffectTreeLayerListIterator::State::END; ++it) { |
| 7626 | if (it.state() == EffectTreeLayerListIterator::State::LAYER) |
| 7627 | drawn_layers->insert(it.current_layer()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7628 | |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7629 | if (it.state() != EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE) |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7630 | continue; |
| 7631 | |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7632 | if (it.current_render_surface()->MaskLayer()) |
| 7633 | drawn_layers->insert(it.current_render_surface()->MaskLayer()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7634 | } |
| 7635 | } |
| 7636 | |
| 7637 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7638 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7639 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 7640 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7641 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7642 | std::unique_ptr<LayerImpl> grand_parent = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7643 | LayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7644 | std::unique_ptr<LayerImpl> parent = |
| 7645 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7646 | std::unique_ptr<LayerImpl> child = |
| 7647 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7648 | std::unique_ptr<LayerImpl> grand_child1 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7649 | LayerImpl::Create(host_impl.active_tree(), 7); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7650 | std::unique_ptr<LayerImpl> grand_child2 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7651 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 7652 | |
| 7653 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 7654 | LayerImpl* parent_raw = parent.get(); |
| 7655 | LayerImpl* child_raw = child.get(); |
| 7656 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 7657 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 7658 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7659 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 7660 | parent->SetBounds(gfx::Size(1, 2)); |
| 7661 | child->SetBounds(gfx::Size(1, 2)); |
| 7662 | grand_child1->SetBounds(gfx::Size(1, 2)); |
| 7663 | grand_child2->SetBounds(gfx::Size(1, 2)); |
| 7664 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7665 | child->test_properties()->AddChild(std::move(grand_child1)); |
| 7666 | child->test_properties()->AddChild(std::move(grand_child2)); |
| 7667 | parent->test_properties()->AddChild(std::move(child)); |
| 7668 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7669 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7670 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7671 | // Start with nothing being drawn. |
| 7672 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7673 | |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7674 | EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface()); |
| 7675 | EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface()); |
| 7676 | EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface()); |
| 7677 | EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface()); |
| 7678 | EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7679 | |
| 7680 | std::set<LayerImpl*> expected; |
| 7681 | std::set<LayerImpl*> actual; |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7682 | GatherDrawnLayers(host_impl.active_tree(), &actual); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7683 | EXPECT_EQ(expected, actual); |
| 7684 | |
| 7685 | // If we force render surface, but none of the layers are in the layer list, |
| 7686 | // then this layer should not appear in RSLL. |
ajuma | 35b24f6 | 2017-01-27 21:23:09 | [diff] [blame] | 7687 | grand_child1_raw->test_properties()->force_render_surface = true; |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7688 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7689 | |
| 7690 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7691 | |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7692 | EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface()); |
| 7693 | EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface()); |
| 7694 | EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface()); |
| 7695 | EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface()); |
| 7696 | EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7697 | |
| 7698 | expected.clear(); |
| 7699 | actual.clear(); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7700 | GatherDrawnLayers(host_impl.active_tree(), &actual); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7701 | EXPECT_EQ(expected, actual); |
| 7702 | |
| 7703 | // However, if we say that this layer also draws content, it will appear in |
| 7704 | // RSLL. |
| 7705 | grand_child1_raw->SetDrawsContent(true); |
| 7706 | |
| 7707 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7708 | |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7709 | EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface()); |
| 7710 | EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface()); |
| 7711 | EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface()); |
| 7712 | EXPECT_TRUE(grand_child1_raw->contributes_to_drawn_render_surface()); |
| 7713 | EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7714 | |
| 7715 | expected.clear(); |
| 7716 | expected.insert(grand_child1_raw); |
| 7717 | |
| 7718 | actual.clear(); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7719 | GatherDrawnLayers(host_impl.active_tree(), &actual); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7720 | EXPECT_EQ(expected, actual); |
| 7721 | |
| 7722 | // Now child is forced to have a render surface, and one if its children draws |
| 7723 | // content. |
| 7724 | grand_child1_raw->SetDrawsContent(false); |
ajuma | 35b24f6 | 2017-01-27 21:23:09 | [diff] [blame] | 7725 | grand_child1_raw->test_properties()->force_render_surface = false; |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7726 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
ajuma | 35b24f6 | 2017-01-27 21:23:09 | [diff] [blame] | 7727 | child_raw->test_properties()->force_render_surface = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7728 | grand_child2_raw->SetDrawsContent(true); |
| 7729 | |
| 7730 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7731 | |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7732 | EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface()); |
| 7733 | EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface()); |
| 7734 | EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface()); |
| 7735 | EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface()); |
| 7736 | EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7737 | |
| 7738 | expected.clear(); |
| 7739 | expected.insert(grand_child2_raw); |
| 7740 | |
| 7741 | actual.clear(); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7742 | GatherDrawnLayers(host_impl.active_tree(), &actual); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7743 | EXPECT_EQ(expected, actual); |
| 7744 | |
| 7745 | // Add a mask layer to child. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7746 | child_raw->test_properties()->SetMaskLayer( |
| 7747 | LayerImpl::Create(host_impl.active_tree(), 6)); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7748 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7749 | |
| 7750 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7751 | |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7752 | EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface()); |
| 7753 | EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface()); |
| 7754 | EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7755 | EXPECT_TRUE(child_raw->test_properties() |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7756 | ->mask_layer->contributes_to_drawn_render_surface()); |
| 7757 | EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface()); |
| 7758 | EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7759 | |
| 7760 | expected.clear(); |
| 7761 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7762 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7763 | |
| 7764 | expected.clear(); |
| 7765 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7766 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7767 | |
| 7768 | actual.clear(); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7769 | GatherDrawnLayers(host_impl.active_tree(), &actual); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7770 | EXPECT_EQ(expected, actual); |
| 7771 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7772 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7773 | |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7774 | EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface()); |
| 7775 | EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface()); |
| 7776 | EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7777 | EXPECT_TRUE(child_raw->test_properties() |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7778 | ->mask_layer->contributes_to_drawn_render_surface()); |
| 7779 | EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface()); |
| 7780 | EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7781 | |
| 7782 | expected.clear(); |
| 7783 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7784 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7785 | |
| 7786 | actual.clear(); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7787 | GatherDrawnLayers(host_impl.active_tree(), &actual); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7788 | EXPECT_EQ(expected, actual); |
| 7789 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7790 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7791 | |
| 7792 | // With nothing drawing, we should have no layers. |
| 7793 | grand_child2_raw->SetDrawsContent(false); |
| 7794 | |
| 7795 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7796 | |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7797 | EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface()); |
| 7798 | EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface()); |
| 7799 | EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7800 | EXPECT_FALSE(child_raw->test_properties() |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7801 | ->mask_layer->contributes_to_drawn_render_surface()); |
| 7802 | EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface()); |
| 7803 | EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7804 | |
| 7805 | expected.clear(); |
| 7806 | actual.clear(); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7807 | GatherDrawnLayers(host_impl.active_tree(), &actual); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7808 | EXPECT_EQ(expected, actual); |
| 7809 | |
| 7810 | // Child itself draws means that we should have the child and the mask in the |
| 7811 | // list. |
| 7812 | child_raw->SetDrawsContent(true); |
| 7813 | |
| 7814 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7815 | |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7816 | EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface()); |
| 7817 | EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface()); |
| 7818 | EXPECT_TRUE(child_raw->contributes_to_drawn_render_surface()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7819 | EXPECT_TRUE(child_raw->test_properties() |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7820 | ->mask_layer->contributes_to_drawn_render_surface()); |
| 7821 | EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface()); |
| 7822 | EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7823 | |
| 7824 | expected.clear(); |
| 7825 | expected.insert(child_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7826 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7827 | actual.clear(); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7828 | GatherDrawnLayers(host_impl.active_tree(), &actual); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7829 | EXPECT_EQ(expected, actual); |
| 7830 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7831 | child_raw->test_properties()->SetMaskLayer(nullptr); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7832 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7833 | |
| 7834 | // Now everyone's a member! |
| 7835 | grand_parent_raw->SetDrawsContent(true); |
| 7836 | parent_raw->SetDrawsContent(true); |
| 7837 | child_raw->SetDrawsContent(true); |
| 7838 | grand_child1_raw->SetDrawsContent(true); |
| 7839 | grand_child2_raw->SetDrawsContent(true); |
| 7840 | |
| 7841 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7842 | |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 7843 | EXPECT_TRUE(grand_parent_raw->contributes_to_drawn_render_surface()); |
| 7844 | EXPECT_TRUE(parent_raw->contributes_to_drawn_render_surface()); |
| 7845 | EXPECT_TRUE(child_raw->contributes_to_drawn_render_surface()); |
| 7846 | EXPECT_TRUE(grand_child1_raw->contributes_to_drawn_render_surface()); |
| 7847 | EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7848 | |
| 7849 | expected.clear(); |
| 7850 | expected.insert(grand_parent_raw); |
| 7851 | expected.insert(parent_raw); |
| 7852 | expected.insert(child_raw); |
| 7853 | expected.insert(grand_child1_raw); |
| 7854 | expected.insert(grand_child2_raw); |
| 7855 | |
| 7856 | actual.clear(); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 7857 | GatherDrawnLayers(host_impl.active_tree(), &actual); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7858 | EXPECT_EQ(expected, actual); |
| 7859 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7860 | |
| 7861 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7862 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7863 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 7864 | LayerTreeSettings settings = host()->GetSettings(); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7865 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7866 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 7867 | &task_graph_runner); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7868 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7869 | std::unique_ptr<LayerImpl> root = |
| 7870 | LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7871 | LayerImpl* root_layer = root.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7872 | std::unique_ptr<LayerImpl> child1 = |
| 7873 | LayerImpl::Create(host_impl.active_tree(), 2); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7874 | LayerImpl* child1_layer = child1.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7875 | std::unique_ptr<LayerImpl> child2 = |
| 7876 | LayerImpl::Create(host_impl.active_tree(), 3); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7877 | LayerImpl* child2_layer = child2.get(); |
| 7878 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7879 | gfx::Transform scale_transform_child1, scale_transform_child2; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7880 | scale_transform_child1.Scale(2, 3); |
| 7881 | scale_transform_child2.Scale(4, 5); |
| 7882 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7883 | root->SetBounds(gfx::Size(1, 1)); |
| 7884 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7885 | child1_layer->test_properties()->transform = scale_transform_child1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7886 | child1_layer->SetBounds(gfx::Size(1, 1)); |
| 7887 | child1_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7888 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7889 | child1_layer->test_properties()->SetMaskLayer( |
| 7890 | LayerImpl::Create(host_impl.active_tree(), 4)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7891 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7892 | root->test_properties()->AddChild(std::move(child1)); |
| 7893 | root->test_properties()->AddChild(std::move(child2)); |
| 7894 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 7895 | host_impl.active_tree()->SetElementIdsForTesting(); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7896 | |
| 7897 | ExecuteCalculateDrawProperties(root_layer); |
| 7898 | |
| 7899 | TransformOperations scale; |
| 7900 | scale.AppendScale(5.f, 8.f, 3.f); |
| 7901 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7902 | scoped_refptr<AnimationTimeline> timeline = |
| 7903 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7904 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7905 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7906 | child2_layer->test_properties()->transform = scale_transform_child2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7907 | child2_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7908 | child2_layer->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7909 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 7910 | 1.0, TransformOperations(), scale); |
| 7911 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7912 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7913 | ExecuteCalculateDrawProperties(root_layer); |
| 7914 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7915 | EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale()); |
| 7916 | EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7917 | EXPECT_FLOAT_EQ( |
| 7918 | 3.f, |
| 7919 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7920 | EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7921 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7922 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 7923 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 7924 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7925 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7926 | // Changing page-scale would affect ideal_contents_scale and |
| 7927 | // maximum_animation_contents_scale. |
| 7928 | |
| 7929 | float page_scale_factor = 3.f; |
| 7930 | float device_scale_factor = 1.0f; |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 7931 | RenderSurfaceList render_surface_list; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7932 | gfx::Size device_viewport_size = |
| 7933 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 7934 | root_layer->bounds().height() * device_scale_factor); |
| 7935 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 7936 | root_layer, device_viewport_size, &render_surface_list); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7937 | |
| 7938 | inputs.page_scale_factor = page_scale_factor; |
| 7939 | inputs.can_adjust_raster_scales = true; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 7940 | inputs.page_scale_layer = root_layer; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7941 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7942 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7943 | EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale()); |
| 7944 | EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7945 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7946 | 9.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7947 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7948 | EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7949 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7950 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 7951 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 7952 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7953 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7954 | // Changing device-scale would affect ideal_contents_scale and |
| 7955 | // maximum_animation_contents_scale. |
| 7956 | |
| 7957 | device_scale_factor = 4.0f; |
| 7958 | inputs.device_scale_factor = device_scale_factor; |
| 7959 | inputs.can_adjust_raster_scales = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7960 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7961 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7962 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7963 | EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale()); |
| 7964 | EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7965 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7966 | 36.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7967 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7968 | EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7969 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7970 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 7971 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 7972 | EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer)); |
| 7973 | } |
| 7974 | |
| 7975 | TEST_F(LayerTreeHostCommonTest, AnimationScales) { |
| 7976 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7977 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 7978 | LayerTreeSettings settings = host()->GetSettings(); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7979 | settings.layer_transforms_should_scale_layer_contents = true; |
| 7980 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 7981 | &task_graph_runner); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7982 | |
| 7983 | std::unique_ptr<LayerImpl> root = |
| 7984 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 7985 | LayerImpl* root_layer = root.get(); |
| 7986 | std::unique_ptr<LayerImpl> child1 = |
| 7987 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7988 | LayerImpl* child1_layer = child1.get(); |
| 7989 | std::unique_ptr<LayerImpl> child2 = |
| 7990 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7991 | LayerImpl* child2_layer = child2.get(); |
| 7992 | |
| 7993 | root->test_properties()->AddChild(std::move(child1)); |
| 7994 | child1_layer->test_properties()->AddChild(std::move(child2)); |
| 7995 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 7996 | |
| 7997 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 7998 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7999 | gfx::Transform scale_transform_child1, scale_transform_child2; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8000 | scale_transform_child1.Scale(2, 3); |
| 8001 | scale_transform_child2.Scale(4, 5); |
| 8002 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8003 | root_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8004 | child1_layer->test_properties()->transform = scale_transform_child1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8005 | child1_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8006 | child2_layer->test_properties()->transform = scale_transform_child2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8007 | child2_layer->SetBounds(gfx::Size(1, 1)); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8008 | |
| 8009 | TransformOperations scale; |
| 8010 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8011 | |
| 8012 | scoped_refptr<AnimationTimeline> timeline = |
| 8013 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8014 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 8015 | |
| 8016 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 8017 | 1.0, TransformOperations(), scale); |
| 8018 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8019 | // Correctly computes animation scale when rebuilding property trees. |
| 8020 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8021 | ExecuteCalculateDrawProperties(root_layer); |
| 8022 | |
| 8023 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8024 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8025 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
| 8026 | |
| 8027 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 8028 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer)); |
| 8029 | EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer)); |
| 8030 | |
| 8031 | // Correctly updates animation scale when layer property changes. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8032 | child1_layer->test_properties()->transform = gfx::Transform(); |
weiliangc | ea09f337 | 2017-03-29 16:43:24 | [diff] [blame] | 8033 | root_layer->layer_tree_impl()->SetTransformMutated(child1_layer->element_id(), |
| 8034 | gfx::Transform()); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8035 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false; |
| 8036 | ExecuteCalculateDrawProperties(root_layer); |
| 8037 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
| 8038 | EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer)); |
| 8039 | |
| 8040 | // Do not update animation scale if already updated. |
| 8041 | host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting( |
| 8042 | child2_layer->transform_tree_index(), 100.f, 100.f); |
| 8043 | EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer)); |
| 8044 | EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer)); |
| 8045 | } |
| 8046 | |
| 8047 | TEST_F(LayerTreeHostCommonTest, |
| 8048 | AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) { |
| 8049 | // Returns empty scale if layer_transforms_should_scale_layer_contents is |
| 8050 | // false. |
| 8051 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8052 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8053 | LayerTreeSettings settings = host()->GetSettings(); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8054 | settings.layer_transforms_should_scale_layer_contents = false; |
| 8055 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8056 | &task_graph_runner); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8057 | |
| 8058 | std::unique_ptr<LayerImpl> root = |
| 8059 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8060 | LayerImpl* root_layer = root.get(); |
| 8061 | std::unique_ptr<LayerImpl> child = |
| 8062 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8063 | LayerImpl* child_layer = child.get(); |
| 8064 | |
| 8065 | root->test_properties()->AddChild(std::move(child)); |
| 8066 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8067 | |
| 8068 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 8069 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8070 | gfx::Transform scale_transform_child; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8071 | scale_transform_child.Scale(4, 5); |
| 8072 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8073 | root_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8074 | child_layer->test_properties()->transform = scale_transform_child; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8075 | child_layer->SetBounds(gfx::Size(1, 1)); |
| 8076 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8077 | TransformOperations scale; |
| 8078 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8079 | |
| 8080 | scoped_refptr<AnimationTimeline> timeline = |
| 8081 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8082 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 8083 | |
| 8084 | AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline, |
| 8085 | 1.0, TransformOperations(), scale); |
| 8086 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8087 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8088 | ExecuteCalculateDrawProperties(root_layer); |
| 8089 | |
| 8090 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8091 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer)); |
| 8092 | |
| 8093 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 8094 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8095 | } |
| 8096 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8097 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8098 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8099 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 8100 | LayerImpl* content = AddChild<LayerImpl>(clip); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8101 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8102 | root->SetBounds(gfx::Size(768 / 2, 3000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8103 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8104 | clip->SetBounds(gfx::Size(768 / 2, 10000)); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8105 | clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8106 | content->SetBounds(gfx::Size(768 / 2, 10000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8107 | content->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8108 | content->test_properties()->force_render_surface = true; |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8109 | |
| 8110 | gfx::Size device_viewport_size(768, 582); |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 8111 | RenderSurfaceList render_surface_list_impl; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8112 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 8113 | root, device_viewport_size, gfx::Transform(), &render_surface_list_impl); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8114 | inputs.device_scale_factor = 2.f; |
| 8115 | inputs.page_scale_factor = 1.f; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 8116 | inputs.page_scale_layer = nullptr; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8117 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8118 | |
| 8119 | // Layers in the root render surface have their visible content rect clipped |
| 8120 | // by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8121 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8122 | |
| 8123 | // Layers drawing to a child render surface should still have their visible |
| 8124 | // content rect clipped by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8125 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8126 | } |
| 8127 | |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 8128 | TEST_F(LayerTreeHostCommonTest, ViewportBoundsDeltaAffectVisibleContentRect) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8129 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8130 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8131 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8132 | |
| 8133 | // Set two layers: the root layer clips it's child, |
| 8134 | // the child draws its content. |
| 8135 | |
| 8136 | gfx::Size root_size = gfx::Size(300, 500); |
| 8137 | |
| 8138 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8139 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8140 | |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 8141 | // Device viewport accomidated the root and the browser controls. |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8142 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8143 | |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 8144 | host_impl.SetViewportSize(device_viewport_size); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8145 | host_impl.active_tree()->SetRootLayerForTesting( |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8146 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8147 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8148 | LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8149 | root->SetBounds(root_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8150 | root->SetMasksToBounds(true); |
| 8151 | |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 8152 | // Make root the inner viewport scroll layer. This ensures the later call to |
| 8153 | // |SetViewportBoundsDelta| will be on a viewport layer. |
pdr | 53abb45 | 2017-05-19 01:59:42 | [diff] [blame] | 8154 | LayerTreeImpl::ViewportLayerIds viewport_ids; |
| 8155 | viewport_ids.inner_viewport_scroll = root->id(); |
| 8156 | host_impl.active_tree()->SetViewportLayersFromIds(viewport_ids); |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 8157 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8158 | root->test_properties()->AddChild( |
| 8159 | LayerImpl::Create(host_impl.active_tree(), 2)); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8160 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 8161 | LayerImpl* sublayer = root->test_properties()->children[0]; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8162 | sublayer->SetBounds(sublayer_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8163 | sublayer->SetDrawsContent(true); |
| 8164 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8165 | host_impl.active_tree()->BuildPropertyTreesForTesting(); |
| 8166 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 8167 | RenderSurfaceList render_surface_list; |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8168 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 8169 | root, device_viewport_size, &render_surface_list); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8170 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8171 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8172 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8173 | |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 8174 | root->SetViewportBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8175 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8176 | |
| 8177 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8178 | root_size.height() + 50); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8179 | EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8180 | } |
| 8181 | |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 8182 | TEST_F(LayerTreeHostCommonTest, NodesAffectedByViewportBoundsDeltaGetUpdated) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8183 | scoped_refptr<Layer> root = Layer::Create(); |
Philip Rogers | d9e5ffd | 2017-06-16 00:10:53 | [diff] [blame] | 8184 | scoped_refptr<Layer> page_scale_layer = Layer::Create(); |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8185 | scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create(); |
| 8186 | scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); |
| 8187 | scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create(); |
| 8188 | scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8189 | |
| 8190 | root->AddChild(inner_viewport_container_layer); |
Philip Rogers | d9e5ffd | 2017-06-16 00:10:53 | [diff] [blame] | 8191 | inner_viewport_container_layer->AddChild(page_scale_layer); |
| 8192 | page_scale_layer->AddChild(inner_viewport_scroll_layer); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8193 | inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); |
| 8194 | outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); |
| 8195 | |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8196 | inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8197 | outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8198 | |
| 8199 | host()->SetRootLayer(root); |
pdr | 5200a05 | 2017-05-21 22:50:58 | [diff] [blame] | 8200 | LayerTreeHost::ViewportLayers viewport_layers; |
Philip Rogers | d9e5ffd | 2017-06-16 00:10:53 | [diff] [blame] | 8201 | viewport_layers.page_scale = page_scale_layer; |
pdr | 5200a05 | 2017-05-21 22:50:58 | [diff] [blame] | 8202 | viewport_layers.inner_viewport_container = inner_viewport_container_layer; |
| 8203 | viewport_layers.outer_viewport_container = outer_viewport_container_layer; |
| 8204 | viewport_layers.inner_viewport_scroll = inner_viewport_scroll_layer; |
| 8205 | viewport_layers.outer_viewport_scroll = outer_viewport_scroll_layer; |
| 8206 | host()->RegisterViewportLayers(viewport_layers); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8207 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8208 | scoped_refptr<Layer> fixed_to_inner = Layer::Create(); |
| 8209 | scoped_refptr<Layer> fixed_to_outer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8210 | |
| 8211 | inner_viewport_scroll_layer->AddChild(fixed_to_inner); |
| 8212 | outer_viewport_scroll_layer->AddChild(fixed_to_outer); |
| 8213 | |
| 8214 | LayerPositionConstraint fixed_to_right; |
| 8215 | fixed_to_right.set_is_fixed_position(true); |
| 8216 | fixed_to_right.set_is_fixed_to_right_edge(true); |
| 8217 | |
| 8218 | fixed_to_inner->SetPositionConstraint(fixed_to_right); |
| 8219 | fixed_to_outer->SetPositionConstraint(fixed_to_right); |
| 8220 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8221 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8222 | |
| 8223 | TransformTree& transform_tree = host()->property_trees()->transform_tree; |
| 8224 | EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8225 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8226 | |
| 8227 | LayerPositionConstraint fixed_to_left; |
| 8228 | fixed_to_left.set_is_fixed_position(true); |
| 8229 | fixed_to_inner->SetPositionConstraint(fixed_to_left); |
| 8230 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8231 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8232 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8233 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8234 | |
| 8235 | fixed_to_outer->SetPositionConstraint(fixed_to_left); |
| 8236 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8237 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8238 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8239 | EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8240 | } |
| 8241 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8242 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8243 | host_impl()->CreatePendingTree(); |
| 8244 | std::unique_ptr<LayerImpl> pending_root = |
| 8245 | LayerImpl::Create(host_impl()->pending_tree(), 1); |
| 8246 | LayerImpl* root = pending_root.get(); |
| 8247 | host_impl()->pending_tree()->SetRootLayerForTesting(std::move(pending_root)); |
| 8248 | std::unique_ptr<LayerImpl> animated_ptr = |
| 8249 | LayerImpl::Create(host_impl()->pending_tree(), 2); |
| 8250 | LayerImpl* animated = animated_ptr.get(); |
| 8251 | root->test_properties()->AddChild(std::move(animated_ptr)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8252 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8253 | animated->SetDrawsContent(true); |
| 8254 | host_impl()->pending_tree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8255 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8256 | root->SetBounds(gfx::Size(100, 100)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8257 | root->SetMasksToBounds(true); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8258 | root->test_properties()->force_render_surface = true; |
| 8259 | animated->test_properties()->opacity = 0.f; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8260 | animated->SetBounds(gfx::Size(20, 20)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8261 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8262 | AddOpacityTransitionToElementWithPlayer( |
| 8263 | animated->element_id(), timeline_impl(), 10.0, 0.f, 1.f, false); |
| 8264 | animated->test_properties()->opacity_can_animate = true; |
| 8265 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8266 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8267 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8268 | EXPECT_FALSE(animated->visible_layer_rect().IsEmpty()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8269 | } |
| 8270 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8271 | TEST_F(LayerTreeHostCommonTest, |
| 8272 | VisibleContentRectForAnimatedLayerWithSingularTransform) { |
jaydasika | af0dcd17 | 2017-05-01 17:37:17 | [diff] [blame] | 8273 | host_impl()->CreatePendingTree(); |
| 8274 | std::unique_ptr<LayerImpl> root_ptr = |
| 8275 | LayerImpl::Create(host_impl()->pending_tree(), 1); |
| 8276 | LayerImpl* root = root_ptr.get(); |
| 8277 | host_impl()->pending_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
| 8278 | std::unique_ptr<LayerImpl> clip_ptr = |
| 8279 | LayerImpl::Create(host_impl()->pending_tree(), 2); |
| 8280 | LayerImpl* clip = clip_ptr.get(); |
| 8281 | root->test_properties()->AddChild(std::move(clip_ptr)); |
| 8282 | std::unique_ptr<LayerImpl> animated_ptr = |
| 8283 | LayerImpl::Create(host_impl()->pending_tree(), 3); |
| 8284 | LayerImpl* animated = animated_ptr.get(); |
| 8285 | clip->test_properties()->AddChild(std::move(animated_ptr)); |
| 8286 | std::unique_ptr<LayerImpl> surface_ptr = |
| 8287 | LayerImpl::Create(host_impl()->pending_tree(), 4); |
| 8288 | LayerImpl* surface = surface_ptr.get(); |
| 8289 | animated->test_properties()->AddChild(std::move(surface_ptr)); |
| 8290 | std::unique_ptr<LayerImpl> descendant_of_animation_ptr = |
| 8291 | LayerImpl::Create(host_impl()->pending_tree(), 5); |
| 8292 | LayerImpl* descendant_of_animation = descendant_of_animation_ptr.get(); |
| 8293 | surface->test_properties()->AddChild(std::move(descendant_of_animation_ptr)); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8294 | |
jaydasika | af0dcd17 | 2017-05-01 17:37:17 | [diff] [blame] | 8295 | host_impl()->pending_tree()->SetElementIdsForTesting(); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8296 | |
jaydasika | af0dcd17 | 2017-05-01 17:37:17 | [diff] [blame] | 8297 | root->SetDrawsContent(true); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8298 | animated->SetDrawsContent(true); |
| 8299 | surface->SetDrawsContent(true); |
| 8300 | descendant_of_animation->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8301 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8302 | gfx::Transform uninvertible_matrix; |
| 8303 | uninvertible_matrix.Scale3d(6.f, 6.f, 0.f); |
| 8304 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8305 | root->SetBounds(gfx::Size(100, 100)); |
| 8306 | clip->SetBounds(gfx::Size(10, 10)); |
| 8307 | clip->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8308 | animated->test_properties()->transform = uninvertible_matrix; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8309 | animated->SetBounds(gfx::Size(120, 120)); |
| 8310 | surface->SetBounds(gfx::Size(100, 100)); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8311 | surface->test_properties()->force_render_surface = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8312 | descendant_of_animation->SetBounds(gfx::Size(200, 200)); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8313 | |
| 8314 | TransformOperations start_transform_operations; |
| 8315 | start_transform_operations.AppendMatrix(uninvertible_matrix); |
| 8316 | TransformOperations end_transform_operations; |
| 8317 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8318 | AddAnimatedTransformToElementWithPlayer( |
| 8319 | animated->element_id(), timeline_impl(), 10.0, start_transform_operations, |
| 8320 | end_transform_operations); |
jaydasika | af0dcd17 | 2017-05-01 17:37:17 | [diff] [blame] | 8321 | ExecuteCalculateDrawProperties(root); |
| 8322 | // Since animated has singular transform, it is not be part of render |
| 8323 | // surface layer list but should be rastered. |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 8324 | EXPECT_FALSE(animated->contributes_to_drawn_render_surface()); |
khushalsagar | 2fc1dbd | 2017-05-26 21:48:16 | [diff] [blame] | 8325 | EXPECT_TRUE(animated->raster_even_if_not_drawn()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8326 | |
| 8327 | // The animated layer has a singular transform and maps to a non-empty rect in |
| 8328 | // clipped target space, so is treated as fully visible. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8329 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8330 | |
| 8331 | // The singular transform on |animated| is flattened when inherited by |
| 8332 | // |surface|, and this happens to make it invertible. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8333 | EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect()); |
| 8334 | EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8335 | |
| 8336 | gfx::Transform zero_matrix; |
| 8337 | zero_matrix.Scale3d(0.f, 0.f, 0.f); |
weiliangc | ea09f337 | 2017-03-29 16:43:24 | [diff] [blame] | 8338 | root->layer_tree_impl()->SetTransformMutated(animated->element_id(), |
| 8339 | zero_matrix); |
jaydasika | af0dcd17 | 2017-05-01 17:37:17 | [diff] [blame] | 8340 | ExecuteCalculateDrawProperties(root); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8341 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8342 | // The animated layer will be treated as fully visible when we combine clips |
| 8343 | // in screen space. |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 8344 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8345 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8346 | // This time, flattening does not make |animated|'s transform invertible. This |
| 8347 | // means the clip cannot be projected into |surface|'s space, so we treat |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8348 | // |surface| and layers that draw into it as having empty visible rect. |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 8349 | EXPECT_EQ(gfx::Rect(100, 100), surface->visible_layer_rect()); |
| 8350 | EXPECT_EQ(gfx::Rect(200, 200), descendant_of_animation->visible_layer_rect()); |
jaydasika | af0dcd17 | 2017-05-01 17:37:17 | [diff] [blame] | 8351 | |
| 8352 | host_impl()->ActivateSyncTree(); |
| 8353 | LayerImpl* active_root = host_impl()->active_tree()->LayerById(root->id()); |
| 8354 | ExecuteCalculateDrawProperties(active_root); |
| 8355 | |
| 8356 | // Since the animated has singular transform, it is not be part of render |
| 8357 | // surface layer list. |
| 8358 | LayerImpl* active_animated = |
| 8359 | host_impl()->active_tree()->LayerById(animated->id()); |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 8360 | EXPECT_TRUE(active_root->contributes_to_drawn_render_surface()); |
| 8361 | EXPECT_FALSE(active_animated->contributes_to_drawn_render_surface()); |
jaydasika | af0dcd17 | 2017-05-01 17:37:17 | [diff] [blame] | 8362 | |
| 8363 | // Since animated has singular transform, it is not be part of render |
| 8364 | // surface layer list but should be rastered. |
khushalsagar | 2fc1dbd | 2017-05-26 21:48:16 | [diff] [blame] | 8365 | EXPECT_TRUE(animated->raster_even_if_not_drawn()); |
jaydasika | af0dcd17 | 2017-05-01 17:37:17 | [diff] [blame] | 8366 | EXPECT_EQ(gfx::Rect(120, 120), active_animated->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8367 | } |
| 8368 | |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8369 | // Verify that having animated opacity but current opacity 1 still creates |
| 8370 | // a render surface. |
| 8371 | TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) { |
| 8372 | LayerImpl* root = root_layer_for_testing(); |
| 8373 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8374 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8375 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8376 | root->SetBounds(gfx::Size(50, 50)); |
| 8377 | child->SetBounds(gfx::Size(50, 50)); |
| 8378 | child->SetDrawsContent(true); |
| 8379 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8380 | grandchild->SetDrawsContent(true); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8381 | |
| 8382 | SetElementIdsForTesting(); |
| 8383 | AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8384 | 10.0, 1.f, 0.2f, false); |
| 8385 | ExecuteCalculateDrawProperties(root); |
| 8386 | |
| 8387 | EXPECT_EQ(1.f, child->Opacity()); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 8388 | EXPECT_TRUE(GetRenderSurface(root)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 8389 | EXPECT_NE(GetRenderSurface(child), GetRenderSurface(root)); |
| 8390 | EXPECT_EQ(GetRenderSurface(grandchild), GetRenderSurface(child)); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8391 | } |
| 8392 | |
wkorman | 53a4432 | 2017-05-12 15:39:23 | [diff] [blame] | 8393 | static bool FilterIsAnimating(LayerImpl* layer) { |
| 8394 | return layer->GetMutatorHost()->IsAnimatingFilterProperty( |
| 8395 | layer->element_id(), layer->GetElementTypeForAnimation()); |
| 8396 | } |
| 8397 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8398 | // Verify that having an animated filter (but no current filter, as these |
| 8399 | // are mutually exclusive) correctly creates a render surface. |
| 8400 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8401 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8402 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8403 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8404 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8405 | root->SetBounds(gfx::Size(50, 50)); |
| 8406 | child->SetBounds(gfx::Size(50, 50)); |
| 8407 | grandchild->SetBounds(gfx::Size(50, 50)); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8408 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8409 | SetElementIdsForTesting(); |
| 8410 | AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8411 | 10.0, 0.1f, 0.2f); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8412 | ExecuteCalculateDrawProperties(root); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8413 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 8414 | EXPECT_TRUE(GetRenderSurface(root)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 8415 | EXPECT_NE(GetRenderSurface(child), GetRenderSurface(root)); |
| 8416 | EXPECT_EQ(GetRenderSurface(grandchild), GetRenderSurface(child)); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8417 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 8418 | EXPECT_TRUE(GetRenderSurface(root)->Filters().IsEmpty()); |
| 8419 | EXPECT_TRUE(GetRenderSurface(child)->Filters().IsEmpty()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8420 | |
wkorman | 53a4432 | 2017-05-12 15:39:23 | [diff] [blame] | 8421 | EXPECT_FALSE(FilterIsAnimating(root)); |
| 8422 | EXPECT_TRUE(FilterIsAnimating(child)); |
| 8423 | EXPECT_FALSE(FilterIsAnimating(grandchild)); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8424 | } |
| 8425 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8426 | // Verify that having a filter animation with a delayed start time creates a |
| 8427 | // render surface. |
| 8428 | TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8429 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8430 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8431 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8432 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8433 | root->SetBounds(gfx::Size(50, 50)); |
| 8434 | child->SetBounds(gfx::Size(50, 50)); |
| 8435 | grandchild->SetBounds(gfx::Size(50, 50)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8436 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8437 | SetElementIdsForTesting(); |
| 8438 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8439 | std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8440 | KeyframedFilterAnimationCurve::Create()); |
| 8441 | FilterOperations start_filters; |
| 8442 | start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f)); |
| 8443 | FilterOperations end_filters; |
| 8444 | end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f)); |
| 8445 | curve->AddKeyframe( |
| 8446 | FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 8447 | curve->AddKeyframe(FilterKeyframe::Create( |
| 8448 | base::TimeDelta::FromMilliseconds(100), end_filters, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8449 | std::unique_ptr<Animation> animation = |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8450 | Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8451 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8452 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8453 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8454 | AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8455 | std::move(animation)); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8456 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8457 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 8458 | EXPECT_TRUE(GetRenderSurface(root)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 8459 | EXPECT_NE(GetRenderSurface(child), GetRenderSurface(root)); |
| 8460 | EXPECT_EQ(GetRenderSurface(grandchild), GetRenderSurface(child)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8461 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 8462 | EXPECT_TRUE(GetRenderSurface(root)->Filters().IsEmpty()); |
| 8463 | EXPECT_TRUE(GetRenderSurface(child)->Filters().IsEmpty()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8464 | |
wkorman | 53a4432 | 2017-05-12 15:39:23 | [diff] [blame] | 8465 | EXPECT_FALSE(FilterIsAnimating(root)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8466 | EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation()); |
wkorman | 53a4432 | 2017-05-12 15:39:23 | [diff] [blame] | 8467 | EXPECT_FALSE(FilterIsAnimating(child)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8468 | EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation()); |
wkorman | 53a4432 | 2017-05-12 15:39:23 | [diff] [blame] | 8469 | EXPECT_FALSE(FilterIsAnimating(grandchild)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8470 | EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation()); |
| 8471 | } |
| 8472 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8473 | // Ensures that the property tree code accounts for offsets between fixed |
| 8474 | // position layers and their respective containers. |
| 8475 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8476 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8477 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8478 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8479 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8480 | root->SetBounds(gfx::Size(50, 50)); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8481 | root->SetMasksToBounds(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8482 | root->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8483 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 8484 | child->SetBounds(gfx::Size(50, 50)); |
| 8485 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 8486 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8487 | grandchild->SetDrawsContent(true); |
| 8488 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8489 | LayerPositionConstraint constraint; |
| 8490 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8491 | grandchild->test_properties()->position_constraint = constraint; |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8492 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8493 | ExecuteCalculateDrawProperties(root); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8494 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8495 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8496 | } |
| 8497 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8498 | // Ensures that the property tree code accounts for offsets between fixed |
| 8499 | // position containers and their transform tree parents, when a fixed position |
| 8500 | // layer's container is its layer tree parent, but this parent doesn't have its |
| 8501 | // own transform tree node. |
| 8502 | TEST_F(LayerTreeHostCommonTest, |
| 8503 | PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8504 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8505 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8506 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8507 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8508 | root->SetBounds(gfx::Size(50, 50)); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8509 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8510 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 8511 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 8512 | child->SetBounds(gfx::Size(50, 50)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8513 | child->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8514 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 8515 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8516 | grandchild->SetDrawsContent(true); |
| 8517 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8518 | LayerPositionConstraint constraint; |
| 8519 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8520 | grandchild->test_properties()->position_constraint = constraint; |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8521 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8522 | ExecuteCalculateDrawProperties(root); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8523 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8524 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8525 | } |
| 8526 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8527 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8528 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8529 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8530 | LayerImpl* fixed = AddChild<LayerImpl>(frame_clip); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8531 | gfx::Transform translate_z; |
| 8532 | translate_z.Translate3d(0, 0, 10); |
| 8533 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8534 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8535 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8536 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8537 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 8538 | frame_clip->SetBounds(gfx::Size(100, 100)); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8539 | frame_clip->SetMasksToBounds(true); |
| 8540 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8541 | fixed->SetBounds(gfx::Size(1000, 1000)); |
| 8542 | fixed->SetDrawsContent(true); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8543 | |
| 8544 | LayerPositionConstraint constraint; |
| 8545 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8546 | fixed->test_properties()->position_constraint = constraint; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8547 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8548 | ExecuteCalculateDrawProperties(root); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8549 | |
| 8550 | gfx::Rect expected(0, 0, 100, 100); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8551 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8552 | } |
| 8553 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8554 | TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8555 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8556 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8557 | LayerImpl* scroller = AddChild<LayerImpl>(frame_clip); |
| 8558 | LayerImpl* fixed = AddChild<LayerImpl>(scroller); |
| 8559 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8560 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8561 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8562 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 8563 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 8564 | frame_clip->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8565 | frame_clip->SetMasksToBounds(true); |
| 8566 | frame_clip->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8567 | scroller->SetBounds(gfx::Size(1000, 1000)); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 8568 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
Philip Rogers | 4131a1c1 | 2017-07-21 19:36:50 | [diff] [blame] | 8569 | scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100)); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 8570 | scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id())); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 8571 | scroller->SetScrollable(frame_clip->bounds()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8572 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8573 | fixed->SetPosition(gfx::PointF(100, 100)); |
| 8574 | fixed->SetBounds(gfx::Size(50, 50)); |
| 8575 | fixed->SetMasksToBounds(true); |
| 8576 | fixed->SetDrawsContent(true); |
| 8577 | fixed->test_properties()->force_render_surface = true; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8578 | |
| 8579 | LayerPositionConstraint constraint; |
| 8580 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8581 | fixed->test_properties()->position_constraint = constraint; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8582 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8583 | ExecuteCalculateDrawProperties(root); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8584 | |
| 8585 | gfx::Rect expected(0, 0, 50, 50); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8586 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8587 | } |
| 8588 | |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8589 | TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) { |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8590 | gfx::Transform translate; |
| 8591 | gfx::Transform rotate; |
| 8592 | |
| 8593 | translate.Translate(10, 10); |
| 8594 | rotate.Rotate(45); |
| 8595 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8596 | scoped_refptr<Layer> root = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8597 | root->SetBounds(gfx::Size(800, 800)); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8598 | root->SetIsContainerForFixedPositionLayers(true); |
| 8599 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8600 | host()->SetRootLayer(root); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8601 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8602 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8603 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8604 | |
| 8605 | root->SetTransform(translate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8606 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8607 | |
| 8608 | root->SetTransform(rotate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8609 | EXPECT_TRUE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8610 | } |
| 8611 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8612 | TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8613 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8614 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8615 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8616 | gfx::Transform scale_matrix; |
| 8617 | scale_matrix.Scale(2.f, 2.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8618 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8619 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8620 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8621 | child->test_properties()->transform = scale_matrix; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8622 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8623 | child->SetDrawsContent(true); |
| 8624 | |
| 8625 | ExecuteCalculateDrawProperties(root); |
| 8626 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8627 | |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 8628 | child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8629 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8630 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8631 | ExecuteCalculateDrawProperties(root); |
| 8632 | EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8633 | } |
| 8634 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8635 | TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8636 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8637 | LayerImpl* scroll_parent = AddChild<LayerImpl>(root); |
| 8638 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8639 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8640 | gfx::Transform scale; |
| 8641 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8642 | |
| 8643 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8644 | scroll_child->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8645 | scroll_child->SetBounds(gfx::Size(40, 40)); |
| 8646 | scroll_child->SetDrawsContent(true); |
| 8647 | scroll_parent->SetBounds(gfx::Size(30, 30)); |
| 8648 | scroll_parent->SetDrawsContent(true); |
| 8649 | |
| 8650 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 8651 | scroll_parent->test_properties()->scroll_children = |
| 8652 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 8653 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8654 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8655 | ExecuteCalculateDrawProperties(root); |
| 8656 | EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8657 | |
| 8658 | scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
Philip Rogers | 4131a1c1 | 2017-07-21 19:36:50 | [diff] [blame] | 8659 | scroll_parent->SetElementId( |
| 8660 | LayerIdToElementIdForTesting(scroll_parent->id())); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8661 | scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
pdr | 80d5a3e | 2017-07-17 19:04:07 | [diff] [blame] | 8662 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8663 | ExecuteCalculateDrawProperties(root); |
Philip Rogers | 4131a1c1 | 2017-07-21 19:36:50 | [diff] [blame] | 8664 | EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8665 | } |
| 8666 | |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 8667 | static void CopyOutputCallback(std::unique_ptr<viz::CopyOutputResult> result) {} |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8668 | |
jaydasika | ebc9428 | 2017-04-24 20:34:01 | [diff] [blame] | 8669 | TEST_F(LayerTreeHostCommonTest, HasCopyRequestsInTargetSubtree) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8670 | scoped_refptr<Layer> root = Layer::Create(); |
| 8671 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 8672 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 8673 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 8674 | scoped_refptr<Layer> greatgrandchild = Layer::Create(); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8675 | |
| 8676 | root->AddChild(child1); |
| 8677 | root->AddChild(child2); |
| 8678 | child1->AddChild(grandchild); |
| 8679 | grandchild->AddChild(greatgrandchild); |
| 8680 | host()->SetRootLayer(root); |
| 8681 | |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 8682 | child1->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest( |
Yuri Wiitala | b251176 | 2017-07-19 00:17:53 | [diff] [blame] | 8683 | base::BindOnce(&CopyOutputCallback))); |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 8684 | greatgrandchild->RequestCopyOfOutput( |
| 8685 | viz::CopyOutputRequest::CreateBitmapRequest( |
| 8686 | base::BindOnce(&CopyOutputCallback))); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8687 | child2->SetOpacity(0.f); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8688 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8689 | |
jaydasika | ebc9428 | 2017-04-24 20:34:01 | [diff] [blame] | 8690 | EXPECT_TRUE(root->has_copy_requests_in_target_subtree()); |
| 8691 | EXPECT_TRUE(child1->has_copy_requests_in_target_subtree()); |
| 8692 | EXPECT_FALSE(child2->has_copy_requests_in_target_subtree()); |
| 8693 | EXPECT_TRUE(grandchild->has_copy_requests_in_target_subtree()); |
| 8694 | EXPECT_TRUE(greatgrandchild->has_copy_requests_in_target_subtree()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8695 | } |
| 8696 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8697 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8698 | scoped_refptr<Layer> root = Layer::Create(); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 8699 | FakeContentLayerClient client; |
| 8700 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8701 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8702 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8703 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8704 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8705 | scoped_refptr<FakePictureLayer> greatgrandchild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8706 | FakePictureLayer::Create(&client)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8707 | |
| 8708 | root->SetBounds(gfx::Size(100, 100)); |
| 8709 | child->SetBounds(gfx::Size(10, 10)); |
| 8710 | grandchild->SetBounds(gfx::Size(10, 10)); |
| 8711 | greatgrandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8712 | |
| 8713 | root->AddChild(child); |
| 8714 | child->AddChild(grandchild); |
| 8715 | grandchild->AddChild(greatgrandchild); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8716 | host()->SetRootLayer(root); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 8717 | host()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8718 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8719 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8720 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8721 | const LayerList* update_list = GetUpdateLayerList(); |
| 8722 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8723 | |
| 8724 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8725 | // and we will configure |child| in several ways that should force the subtree |
| 8726 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8727 | // remain empty. |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8728 | gfx::Transform singular; |
| 8729 | singular.matrix().set(0, 0, 0); |
| 8730 | |
| 8731 | child->SetTransform(singular); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8732 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8733 | update_list = GetUpdateLayerList(); |
| 8734 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8735 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8736 | |
| 8737 | child->SetHideLayerAndSubtree(true); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8738 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8739 | update_list = GetUpdateLayerList(); |
| 8740 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8741 | child->SetHideLayerAndSubtree(false); |
| 8742 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8743 | gfx::Transform zero_z_scale; |
| 8744 | zero_z_scale.Scale3d(1, 1, 0); |
| 8745 | child->SetTransform(zero_z_scale); |
| 8746 | |
| 8747 | // Add a transform animation with a start delay. Now, even though |child| has |
| 8748 | // a singular transform, the subtree should still get processed. |
| 8749 | int animation_id = 0; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8750 | std::unique_ptr<Animation> animation = Animation::Create( |
| 8751 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8752 | animation_id, 1, TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8753 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8754 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8755 | AddAnimationToElementWithPlayer(child->element_id(), timeline(), |
| 8756 | std::move(animation)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8757 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8758 | update_list = GetUpdateLayerList(); |
| 8759 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8760 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8761 | RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(), |
| 8762 | animation_id); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8763 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8764 | child->SetOpacity(0.f); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8765 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8766 | update_list = GetUpdateLayerList(); |
| 8767 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8768 | |
| 8769 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8770 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8771 | // processed anyhow. |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 8772 | grandchild->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest( |
Yuri Wiitala | b251176 | 2017-07-19 00:17:53 | [diff] [blame] | 8773 | base::BindOnce(&CopyOutputCallback))); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8774 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8775 | update_list = GetUpdateLayerList(); |
| 8776 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8777 | |
| 8778 | // Add an opacity animation with a start delay. |
| 8779 | animation_id = 1; |
| 8780 | animation = Animation::Create( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8781 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8782 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8783 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8784 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8785 | AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(), |
| 8786 | std::move(animation)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8787 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8788 | update_list = GetUpdateLayerList(); |
| 8789 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8790 | } |
| 8791 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8792 | TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8793 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8794 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8795 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8796 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8797 | std::unique_ptr<LayerImpl> root = |
| 8798 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8799 | std::unique_ptr<LayerImpl> child = |
| 8800 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8801 | std::unique_ptr<LayerImpl> grandchild = |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8802 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 8803 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8804 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8805 | FakePictureLayerImpl::Create(host_impl.active_tree(), 4)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8806 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8807 | root->SetBounds(gfx::Size(100, 100)); |
| 8808 | child->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8809 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8810 | grandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8811 | grandchild->SetDrawsContent(true); |
| 8812 | greatgrandchild->SetDrawsContent(true); |
| 8813 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8814 | LayerImpl* root_ptr = root.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8815 | LayerImpl* child_ptr = child.get(); |
| 8816 | LayerImpl* grandchild_ptr = grandchild.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8817 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8818 | child->test_properties()->AddChild(std::move(grandchild)); |
| 8819 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8820 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8821 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8822 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 8823 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8824 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8825 | // ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8826 | // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8827 | |
| 8828 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8829 | // and we will configure |child| in several ways that should force the subtree |
| 8830 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8831 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8832 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8833 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8834 | gfx::Transform singular; |
| 8835 | singular.matrix().set(0, 0, 0); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8836 | // This line is used to make the results of skipping and not skipping layers |
| 8837 | // different. |
| 8838 | singular.matrix().set(0, 1, 1); |
| 8839 | |
| 8840 | gfx::Transform rotate; |
| 8841 | rotate.Rotate(90); |
| 8842 | |
| 8843 | gfx::Transform rotate_back_and_translate; |
| 8844 | rotate_back_and_translate.RotateAboutYAxis(180); |
| 8845 | rotate_back_and_translate.Translate(-10, 0); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8846 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8847 | child_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8848 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8849 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8850 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8851 | child_ptr->test_properties()->transform = gfx::Transform(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8852 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8853 | child_ptr->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8854 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8855 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8856 | child_ptr->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8857 | |
weiliangc | ea09f337 | 2017-03-29 16:43:24 | [diff] [blame] | 8858 | child_ptr->test_properties()->opacity = 0.f; |
| 8859 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8860 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8861 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8862 | child_ptr->test_properties()->opacity = 1.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8863 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8864 | root_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8865 | // Force transform tree to have a node for child, so that ancestor's |
| 8866 | // invertible transform can be tested. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8867 | child_ptr->test_properties()->transform = rotate; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8868 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8869 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8870 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8871 | root_ptr->test_properties()->transform = gfx::Transform(); |
| 8872 | child_ptr->test_properties()->transform = gfx::Transform(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8873 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8874 | root_ptr->test_properties()->opacity = 0.f; |
| 8875 | child_ptr->test_properties()->opacity = 0.7f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8876 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8877 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8878 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8879 | root_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8880 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8881 | child_ptr->test_properties()->opacity = 0.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8882 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8883 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8884 | // processed anyhow. |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 8885 | grandchild_ptr->test_properties()->copy_requests.push_back( |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 8886 | viz::CopyOutputRequest::CreateEmptyRequest()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8887 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8888 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8889 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 8890 | |
| 8891 | host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests(); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8892 | child_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8893 | |
| 8894 | // A double sided render surface with backface visible should not be skipped |
| 8895 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
ajuma | 35b24f6 | 2017-01-27 21:23:09 | [diff] [blame] | 8896 | child_ptr->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8897 | child_ptr->test_properties()->double_sided = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8898 | child_ptr->test_properties()->transform = rotate_back_and_translate; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8899 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8900 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8901 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8902 | child_ptr->test_properties()->transform = gfx::Transform(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8903 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8904 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8905 | KeyframedTransformAnimationCurve::Create()); |
| 8906 | TransformOperations start; |
| 8907 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 8908 | gfx::Transform transform; |
| 8909 | transform.Scale3d(1.0, 2.0, 3.0); |
| 8910 | TransformOperations operation; |
| 8911 | operation.AppendMatrix(transform); |
| 8912 | curve->AddKeyframe( |
| 8913 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 8914 | curve->AddKeyframe(TransformKeyframe::Create( |
| 8915 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8916 | std::unique_ptr<Animation> transform_animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8917 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 8918 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 8919 | host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(), |
| 8920 | player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 8921 | player->AddAnimation(std::move(transform_animation)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8922 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8923 | root_ptr->test_properties()->transform = singular; |
| 8924 | child_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8925 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8926 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8927 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8928 | |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 8929 | host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(), |
| 8930 | player.get()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8931 | } |
| 8932 | |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8933 | TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8934 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8935 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8936 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 8937 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8938 | SetElementIdsForTesting(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8939 | |
| 8940 | gfx::Transform singular; |
| 8941 | singular.matrix().set(0, 0, 0); |
| 8942 | singular.matrix().set(0, 1, 1); |
| 8943 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8944 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8945 | child->test_properties()->transform = singular; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8946 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8947 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8948 | grand_child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8949 | grand_child->SetDrawsContent(true); |
| 8950 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8951 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8952 | KeyframedTransformAnimationCurve::Create()); |
| 8953 | TransformOperations start; |
| 8954 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 8955 | gfx::Transform transform; |
| 8956 | transform.Scale3d(1.0, 2.0, 3.0); |
| 8957 | TransformOperations operation; |
| 8958 | operation.AppendMatrix(transform); |
| 8959 | curve->AddKeyframe( |
| 8960 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 8961 | curve->AddKeyframe(TransformKeyframe::Create( |
| 8962 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8963 | std::unique_ptr<Animation> transform_animation( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8964 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 8965 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 8966 | host_impl()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8967 | grand_child->element_id(), player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 8968 | player->AddAnimation(std::move(transform_animation)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8969 | |
| 8970 | ExecuteCalculateDrawProperties(root); |
| 8971 | EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect()); |
| 8972 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
| 8973 | |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 8974 | host_impl()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8975 | grand_child->element_id(), player.get()); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8976 | } |
| 8977 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8978 | TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { |
| 8979 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8980 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8981 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8982 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8983 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8984 | std::unique_ptr<LayerImpl> root = |
| 8985 | LayerImpl::Create(host_impl.pending_tree(), 1); |
| 8986 | std::unique_ptr<LayerImpl> child = |
| 8987 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 8988 | std::unique_ptr<LayerImpl> grandchild = |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8989 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 8990 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8991 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8992 | FakePictureLayerImpl::Create(host_impl.pending_tree(), 4)); |
| 8993 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8994 | root->SetBounds(gfx::Size(100, 100)); |
| 8995 | child->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8996 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8997 | grandchild->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8998 | grandchild->SetDrawsContent(true); |
| 8999 | greatgrandchild->SetDrawsContent(true); |
| 9000 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9001 | LayerImpl* root_ptr = root.get(); |
| 9002 | LayerImpl* grandchild_ptr = grandchild.get(); |
| 9003 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9004 | child->test_properties()->AddChild(std::move(grandchild)); |
| 9005 | root->test_properties()->AddChild(std::move(child)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9006 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9007 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9008 | host_impl.pending_tree()->SetElementIdsForTesting(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9009 | |
| 9010 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9011 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9012 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9013 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9014 | std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9015 | KeyframedFloatAnimationCurve::Create()); |
loyso | 1e4e7ee | 2016-06-03 03:04:49 | [diff] [blame] | 9016 | std::unique_ptr<TimingFunction> func = |
| 9017 | CubicBezierTimingFunction::CreatePreset( |
| 9018 | CubicBezierTimingFunction::EaseType::EASE); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9019 | curve->AddKeyframe( |
| 9020 | FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func))); |
| 9021 | curve->AddKeyframe( |
| 9022 | FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9023 | std::unique_ptr<Animation> animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9024 | Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY)); |
| 9025 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9026 | host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(), |
| 9027 | player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 9028 | player->AddAnimation(std::move(animation)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9029 | root_ptr->test_properties()->opacity = 0.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9030 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9031 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9032 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9033 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9034 | |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9035 | host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(), |
| 9036 | player.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9037 | } |
| 9038 | |
| 9039 | TEST_F(LayerTreeHostCommonTest, SkippingLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9040 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9041 | LayerImpl* child = AddChild<LayerImpl>(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9042 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9043 | root->SetBounds(gfx::Size(100, 100)); |
| 9044 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9045 | child->SetDrawsContent(true); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9046 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9047 | ExecuteCalculateDrawProperties(root); |
| 9048 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9049 | child->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9050 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9051 | child->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9052 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9053 | ExecuteCalculateDrawProperties(root); |
| 9054 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9055 | child->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9056 | |
| 9057 | child->SetBounds(gfx::Size()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9058 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9059 | ExecuteCalculateDrawProperties(root); |
| 9060 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9061 | child->SetBounds(gfx::Size(10, 10)); |
| 9062 | |
| 9063 | gfx::Transform rotate; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9064 | child->test_properties()->double_sided = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9065 | rotate.RotateAboutXAxis(180.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9066 | child->test_properties()->transform = rotate; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9067 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9068 | ExecuteCalculateDrawProperties(root); |
| 9069 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9070 | child->test_properties()->double_sided = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9071 | child->test_properties()->transform = gfx::Transform(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9072 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9073 | child->test_properties()->opacity = 0.f; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9074 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9075 | ExecuteCalculateDrawProperties(root); |
| 9076 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9077 | } |
| 9078 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9079 | TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) { |
| 9080 | // Ensure that the treewalk in LayerTreeHostCommom:: |
| 9081 | // PreCalculateMetaInformation happens when its required. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9082 | scoped_refptr<Layer> root = Layer::Create(); |
| 9083 | scoped_refptr<Layer> parent = Layer::Create(); |
| 9084 | scoped_refptr<Layer> child = Layer::Create(); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9085 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9086 | root->SetBounds(gfx::Size(100, 100)); |
| 9087 | parent->SetBounds(gfx::Size(100, 100)); |
| 9088 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9089 | child->SetClipParent(root.get()); |
| 9090 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9091 | root->AddChild(parent); |
| 9092 | parent->AddChild(child); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9093 | host()->SetRootLayer(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9094 | |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 9095 | child->RequestCopyOfOutput(viz::CopyOutputRequest::CreateRequest( |
Yuri Wiitala | b251176 | 2017-07-19 00:17:53 | [diff] [blame] | 9096 | base::BindOnce(&EmptyCopyOutputCallback))); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9097 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9098 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | ebc9428 | 2017-04-24 20:34:01 | [diff] [blame] | 9099 | EXPECT_TRUE(root->has_copy_requests_in_target_subtree()); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 9100 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9101 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | ebc9428 | 2017-04-24 20:34:01 | [diff] [blame] | 9102 | EXPECT_TRUE(root->has_copy_requests_in_target_subtree()); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9103 | } |
| 9104 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9105 | TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) { |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9106 | scoped_refptr<Layer> root = Layer::Create(); |
| 9107 | root->SetBounds(gfx::Size(800, 800)); |
| 9108 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9109 | gfx::Transform translate_z; |
| 9110 | translate_z.Translate3d(0, 0, 10); |
| 9111 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9112 | scoped_refptr<Layer> child = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9113 | child->SetTransform(translate_z); |
| 9114 | child->SetBounds(gfx::Size(100, 100)); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9115 | |
| 9116 | root->AddChild(child); |
| 9117 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9118 | host()->SetRootLayer(root); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9119 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9120 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9121 | EXPECT_NE(-1, child->transform_tree_index()); |
| 9122 | |
| 9123 | child->RemoveFromParent(); |
| 9124 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9125 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9126 | EXPECT_EQ(-1, child->transform_tree_index()); |
| 9127 | } |
| 9128 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9129 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { |
| 9130 | // Ensure that a Clip Node is added when a render surface applies clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9131 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9132 | LayerImpl* significant_transform = AddChildToRoot<LayerImpl>(); |
| 9133 | LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform); |
| 9134 | LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree); |
| 9135 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9136 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9137 | // This transform should be a significant one so that a transform node is |
| 9138 | // formed for it. |
| 9139 | gfx::Transform transform1; |
| 9140 | transform1.RotateAboutYAxis(45); |
| 9141 | transform1.RotateAboutXAxis(30); |
| 9142 | // This transform should be a 3d transform as we want the render surface |
| 9143 | // to flatten the transform |
| 9144 | gfx::Transform transform2; |
| 9145 | transform2.Translate3d(10, 10, 10); |
| 9146 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9147 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9148 | significant_transform->test_properties()->transform = transform1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9149 | significant_transform->SetBounds(gfx::Size(30, 30)); |
| 9150 | layer_clips_subtree->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9151 | layer_clips_subtree->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9152 | layer_clips_subtree->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9153 | render_surface->test_properties()->transform = transform2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9154 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9155 | render_surface->test_properties()->force_render_surface = true; |
| 9156 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9157 | test_layer->SetDrawsContent(true); |
| 9158 | |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9159 | float device_scale_factor = 1.f; |
| 9160 | float page_scale_factor = 1.f; |
| 9161 | LayerImpl* page_scale_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 9162 | LayerImpl* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 9163 | LayerImpl* outer_viewport_scroll_layer = nullptr; |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9164 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 9165 | page_scale_layer, inner_viewport_scroll_layer, |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 9166 | outer_viewport_scroll_layer); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9167 | |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 9168 | EXPECT_TRUE(GetRenderSurface(root)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 9169 | EXPECT_EQ(GetRenderSurface(significant_transform), GetRenderSurface(root)); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 9170 | EXPECT_TRUE(GetRenderSurface(layer_clips_subtree)); |
chrishtr | 5f60ca0 | 2017-05-11 23:09:49 | [diff] [blame] | 9171 | EXPECT_NE(GetRenderSurface(render_surface), GetRenderSurface(root)); |
| 9172 | EXPECT_EQ(GetRenderSurface(test_layer), GetRenderSurface(render_surface)); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9173 | |
jaydasika | 3a6b1443 | 2017-03-21 23:11:19 | [diff] [blame] | 9174 | EXPECT_EQ(gfx::Rect(30, 20), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9175 | } |
| 9176 | |
| 9177 | TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 9178 | // Ensure that when parent clip node's transform is an ancestor of current |
| 9179 | // clip node's target, clip is 'projected' from parent space to current |
| 9180 | // target space and visible rects are calculated correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9181 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9182 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9183 | LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 9184 | LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| 9185 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9186 | gfx::Transform transform; |
| 9187 | transform.RotateAboutYAxis(45); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9188 | |
| 9189 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9190 | clip_layer->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9191 | clip_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9192 | clip_layer->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9193 | target_layer->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9194 | target_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9195 | target_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9196 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9197 | test_layer->SetDrawsContent(true); |
| 9198 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9199 | ExecuteCalculateDrawProperties(root); |
| 9200 | |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9201 | EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9202 | } |
| 9203 | |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9204 | TEST_F(LayerTreeHostCommonTest, |
| 9205 | RenderSurfaceWithUnclippedDescendantsClipsSubtree) { |
| 9206 | // Ensure clip rect is calculated correctly when render surface has unclipped |
| 9207 | // descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9208 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9209 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9210 | LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); |
| 9211 | LayerImpl* render_surface = |
| 9212 | AddChild<LayerImpl>(between_clip_parent_and_child); |
| 9213 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9214 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9215 | gfx::Transform translate; |
| 9216 | translate.Translate(2.0, 2.0); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9217 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9218 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9219 | clip_parent->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9220 | clip_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9221 | clip_parent->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9222 | between_clip_parent_and_child->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9223 | between_clip_parent_and_child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 9224 | between_clip_parent_and_child->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9225 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9226 | render_surface->test_properties()->force_render_surface = true; |
| 9227 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9228 | test_layer->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9229 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9230 | render_surface->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9231 | clip_parent->test_properties()->clip_children = |
| 9232 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9233 | clip_parent->test_properties()->clip_children->insert(render_surface); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9234 | |
| 9235 | ExecuteCalculateDrawProperties(root); |
| 9236 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9237 | EXPECT_TRUE(test_layer->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 9238 | EXPECT_FALSE(test_layer->render_target()->is_clipped()); |
weiliangc | 0b41eaf | 2016-03-14 21:35:56 | [diff] [blame] | 9239 | EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect()); |
| 9240 | EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9241 | } |
| 9242 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9243 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9244 | RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) { |
| 9245 | // Ensure that the visible layer rect of a descendant of a surface with |
| 9246 | // unclipped descendants is computed correctly, when the surface doesn't apply |
| 9247 | // a clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9248 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9249 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9250 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9251 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9252 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 9253 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9254 | root->SetBounds(gfx::Size(30, 10)); |
| 9255 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 9256 | render_surface->SetBounds(gfx::Size(10, 15)); |
| 9257 | render_surface->test_properties()->force_render_surface = true; |
| 9258 | clip_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9259 | clip_child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9260 | child->SetBounds(gfx::Size(40, 40)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9261 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9262 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9263 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9264 | clip_parent->test_properties()->clip_children = |
| 9265 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9266 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9267 | |
| 9268 | ExecuteCalculateDrawProperties(root); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 9269 | EXPECT_EQ(gfx::Rect(30, 10), child->visible_layer_rect()); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9270 | } |
| 9271 | |
| 9272 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9273 | RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9274 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9275 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9276 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9277 | LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface); |
| 9278 | LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1); |
| 9279 | LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child); |
| 9280 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9281 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9282 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9283 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 9284 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9285 | render_surface->SetMasksToBounds(true); |
| 9286 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9287 | render_surface->test_properties()->force_render_surface = true; |
| 9288 | test_layer1->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9289 | test_layer1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9290 | clip_child->SetBounds(gfx::Size(50, 50)); |
| 9291 | clip_child->SetDrawsContent(true); |
| 9292 | test_layer2->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9293 | test_layer2->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9294 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9295 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9296 | clip_parent->test_properties()->clip_children = |
| 9297 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9298 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9299 | |
| 9300 | ExecuteCalculateDrawProperties(root); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9301 | EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect()); |
| 9302 | EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect()); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9303 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
| 9304 | EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect()); |
| 9305 | } |
| 9306 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9307 | TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9308 | LayerImpl* root = root_layer_for_testing(); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9309 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9310 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9311 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9312 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9313 | root->SetBounds(gfx::Size(50, 50)); |
| 9314 | clip_parent->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9315 | clip_parent->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9316 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9317 | render_surface->test_properties()->force_render_surface = true; |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9318 | render_surface->SetMasksToBounds(true); |
| 9319 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9320 | clip_child->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9321 | clip_child->SetDrawsContent(true); |
| 9322 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9323 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9324 | clip_parent->test_properties()->clip_children = |
| 9325 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9326 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9327 | |
| 9328 | ExecuteCalculateDrawProperties(root); |
| 9329 | |
| 9330 | // The clip child should inherit its clip parent's clipping state, not its |
| 9331 | // tree parent's clipping state. |
| 9332 | EXPECT_FALSE(clip_parent->is_clipped()); |
| 9333 | EXPECT_TRUE(render_surface->is_clipped()); |
| 9334 | EXPECT_FALSE(clip_child->is_clipped()); |
| 9335 | } |
| 9336 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9337 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) { |
| 9338 | // Tests the value of render surface content rect when we have multiple types |
| 9339 | // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and |
| 9340 | // clipped surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9341 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9342 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 9343 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 9344 | LayerImpl* clip_layer = AddChild<LayerImpl>(clip_parent); |
| 9345 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_layer); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9346 | LayerImpl* unclipped_desc_surface2 = |
| 9347 | AddChild<LayerImpl>(unclipped_desc_surface); |
| 9348 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2); |
| 9349 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 9350 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9351 | root->SetBounds(gfx::Size(80, 80)); |
| 9352 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9353 | unclipped_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9354 | unclipped_surface->SetDrawsContent(true); |
| 9355 | unclipped_surface->test_properties()->force_render_surface = true; |
| 9356 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 9357 | clip_parent->SetMasksToBounds(true); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 9358 | clip_layer->SetMasksToBounds(true); |
| 9359 | clip_layer->SetBounds(gfx::Size(100, 100)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9360 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9361 | unclipped_desc_surface->SetDrawsContent(true); |
| 9362 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9363 | unclipped_desc_surface2->SetBounds(gfx::Size(60, 60)); |
| 9364 | unclipped_desc_surface2->SetDrawsContent(true); |
| 9365 | unclipped_desc_surface2->test_properties()->force_render_surface = true; |
| 9366 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9367 | clipped_surface->SetBounds(gfx::Size(70, 70)); |
| 9368 | clipped_surface->SetDrawsContent(true); |
| 9369 | clipped_surface->test_properties()->force_render_surface = true; |
| 9370 | |
| 9371 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9372 | clip_parent->test_properties()->clip_children = |
| 9373 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9374 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9375 | |
| 9376 | ExecuteCalculateDrawProperties(root); |
| 9377 | EXPECT_EQ(gfx::Rect(50, 50), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 9378 | GetRenderSurface(unclipped_surface)->content_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9379 | EXPECT_EQ(gfx::Rect(50, 50), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 9380 | GetRenderSurface(unclipped_desc_surface)->content_rect()); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 9381 | EXPECT_EQ(gfx::Rect(60, 60), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 9382 | GetRenderSurface(unclipped_desc_surface2)->content_rect()); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9383 | EXPECT_EQ(gfx::Rect(50, 50), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 9384 | GetRenderSurface(clipped_surface)->content_rect()); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9385 | } |
| 9386 | |
| 9387 | TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) { |
| 9388 | // Tests the value of render surface content rect when we have a layer that |
| 9389 | // clips between the clip parent's target and clip child's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9390 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9391 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9392 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9393 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9394 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9395 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9396 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9397 | gfx::Transform translate; |
| 9398 | translate.Translate(10, 10); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9399 | |
jaydasika | 778cb27 | 2016-08-15 19:00:54 | [diff] [blame] | 9400 | gfx::Transform rotate; |
| 9401 | rotate.RotateAboutXAxis(10); |
| 9402 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9403 | root->SetBounds(gfx::Size(100, 100)); |
| 9404 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9405 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9406 | surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9407 | surface->test_properties()->transform = rotate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9408 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9409 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9410 | clip_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9411 | unclipped_desc_surface->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9412 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 9413 | unclipped_desc_surface->SetDrawsContent(true); |
| 9414 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9415 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9416 | clip_child->SetDrawsContent(true); |
| 9417 | |
| 9418 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9419 | clip_parent->test_properties()->clip_children = |
| 9420 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9421 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9422 | |
| 9423 | ExecuteCalculateDrawProperties(root); |
| 9424 | |
| 9425 | EXPECT_EQ(gfx::Rect(10, 10), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 9426 | GetRenderSurface(unclipped_desc_surface)->content_rect()); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9427 | } |
| 9428 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9429 | TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9430 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9431 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9432 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9433 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9434 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9435 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9436 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9437 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9438 | gfx::Transform scale; |
| 9439 | scale.Scale(2, 2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9440 | |
| 9441 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9442 | surface->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9443 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9444 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9445 | surface->test_properties()->force_render_surface = true; |
| 9446 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9447 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9448 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 9449 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 9450 | unclipped_desc_surface->SetDrawsContent(true); |
| 9451 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9452 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9453 | clip_child->SetDrawsContent(true); |
| 9454 | |
| 9455 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9456 | clip_parent->test_properties()->clip_children = |
| 9457 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9458 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9459 | |
| 9460 | ExecuteCalculateDrawProperties(root); |
| 9461 | |
| 9462 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 9463 | } |
| 9464 | |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9465 | TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9466 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9467 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9468 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9469 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9470 | gfx::Transform translation; |
| 9471 | translation.Translate(10, 10); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9472 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9473 | root->SetBounds(gfx::Size(30, 30)); |
| 9474 | render_surface->SetBounds(gfx::Size(30, 30)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9475 | render_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9476 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9477 | test_layer->test_properties()->transform = translation; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9478 | test_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9479 | test_layer->SetDrawsContent(true); |
Hayley Ferr | d9ee3a7 | 2017-06-16 14:16:09 | [diff] [blame] | 9480 | |
| 9481 | TouchActionRegion touch_action_region; |
| 9482 | touch_action_region.Union(kTouchActionNone, gfx::Rect(0, 0, 20, 20)); |
| 9483 | test_layer->SetTouchActionRegion(std::move(touch_action_region)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9484 | test_layer->test_properties()->opacity = 0.f; |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9485 | |
| 9486 | ExecuteCalculateDrawProperties(root); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 9487 | EXPECT_TRANSFORMATION_MATRIX_EQ(translation, |
| 9488 | test_layer->ScreenSpaceTransform()); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9489 | } |
| 9490 | |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 9491 | TEST_F(LayerTreeHostCommonTest, ClipParentDrawsIntoScaledRootSurface) { |
| 9492 | LayerImpl* root = root_layer_for_testing(); |
| 9493 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9494 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 9495 | LayerImpl* clip_parent_child = AddChild<LayerImpl>(clip_parent); |
| 9496 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent_child); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 9497 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9498 | |
| 9499 | root->SetBounds(gfx::Size(100, 100)); |
| 9500 | clip_layer->SetBounds(gfx::Size(20, 20)); |
| 9501 | clip_layer->SetMasksToBounds(true); |
| 9502 | clip_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 9503 | clip_parent_child->SetBounds(gfx::Size(20, 20)); |
| 9504 | clip_parent_child->SetMasksToBounds(true); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 9505 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 9506 | unclipped_desc_surface->SetDrawsContent(true); |
| 9507 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9508 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9509 | clip_child->SetDrawsContent(true); |
jaydasika | 264a0dd | 2017-02-24 23:17:27 | [diff] [blame] | 9510 | gfx::Transform translate; |
| 9511 | translate.Translate(10, 10); |
| 9512 | unclipped_desc_surface->test_properties()->transform = translate; |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 9513 | |
| 9514 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9515 | clip_parent->test_properties()->clip_children = |
| 9516 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9517 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 9518 | |
| 9519 | float device_scale_factor = 1.f; |
| 9520 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
jaydasika | 264a0dd | 2017-02-24 23:17:27 | [diff] [blame] | 9521 | EXPECT_EQ(gfx::Rect(-10, -10, 20, 20), clip_child->clip_rect()); |
| 9522 | EXPECT_EQ(gfx::Rect(10, 10), clip_child->visible_layer_rect()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 9523 | |
| 9524 | device_scale_factor = 2.f; |
| 9525 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
jaydasika | 264a0dd | 2017-02-24 23:17:27 | [diff] [blame] | 9526 | EXPECT_EQ(gfx::Rect(-20, -20, 40, 40), clip_child->clip_rect()); |
| 9527 | EXPECT_EQ(gfx::Rect(10, 10), clip_child->visible_layer_rect()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 9528 | } |
| 9529 | |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9530 | TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9531 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9532 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9533 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9534 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9535 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9536 | root->SetBounds(gfx::Size(30, 30)); |
| 9537 | clip_parent->SetBounds(gfx::Size(40, 40)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9538 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9539 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9540 | render_surface->SetMasksToBounds(true); |
| 9541 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9542 | render_surface->test_properties()->force_render_surface = true; |
| 9543 | clip_child->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9544 | clip_child->SetDrawsContent(true); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9545 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9546 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9547 | clip_parent->test_properties()->clip_children = |
| 9548 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9549 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9550 | |
| 9551 | ExecuteCalculateDrawProperties(root); |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 9552 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9553 | } |
| 9554 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9555 | TEST_F(LayerTreeHostCommonTest, |
| 9556 | LayerClipRectLargerThanClippingRenderSurfaceRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9557 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9558 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9559 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9560 | |
| 9561 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9562 | root->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9563 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9564 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9565 | render_surface->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9566 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9567 | render_surface->test_properties()->force_render_surface = true; |
| 9568 | test_layer->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9569 | test_layer->SetMasksToBounds(true); |
| 9570 | test_layer->SetDrawsContent(true); |
| 9571 | ExecuteCalculateDrawProperties(root); |
| 9572 | |
| 9573 | EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect()); |
| 9574 | EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect()); |
| 9575 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect()); |
| 9576 | } |
| 9577 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9578 | TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) { |
| 9579 | // Tests that subtree is hidden is updated. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9580 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9581 | LayerImpl* hidden = AddChild<LayerImpl>(root); |
| 9582 | LayerImpl* test = AddChild<LayerImpl>(hidden); |
| 9583 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9584 | root->SetBounds(gfx::Size(30, 30)); |
| 9585 | hidden->SetBounds(gfx::Size(30, 30)); |
| 9586 | hidden->test_properties()->force_render_surface = true; |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9587 | hidden->test_properties()->hide_layer_and_subtree = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9588 | test->SetBounds(gfx::Size(30, 30)); |
| 9589 | test->test_properties()->force_render_surface = true; |
| 9590 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9591 | ExecuteCalculateDrawProperties(root); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 9592 | EXPECT_EQ(0.f, |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 9593 | GetRenderSurface(test)->OwningEffectNode()->screen_space_opacity); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9594 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9595 | hidden->test_properties()->hide_layer_and_subtree = false; |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9596 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9597 | ExecuteCalculateDrawProperties(root); |
ajuma | 95621958 | 2017-04-04 19:58:14 | [diff] [blame] | 9598 | EXPECT_EQ(1.f, |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 9599 | GetRenderSurface(test)->OwningEffectNode()->screen_space_opacity); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9600 | } |
| 9601 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9602 | TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9603 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 9604 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9605 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_layer); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9606 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 9607 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
| 9608 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9609 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9610 | root->SetMasksToBounds(true); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 9611 | clip_layer->SetBounds(gfx::Size(30, 30)); |
| 9612 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9613 | render_surface1->SetPosition(gfx::PointF(10, 10)); |
| 9614 | render_surface1->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9615 | render_surface1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9616 | render_surface1->test_properties()->force_render_surface = true; |
| 9617 | render_surface2->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9618 | render_surface2->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9619 | render_surface2->test_properties()->force_render_surface = true; |
| 9620 | clip_child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 1553a14 | 2017-04-05 00:37:09 | [diff] [blame] | 9621 | clip_child->SetDrawsContent(true); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9622 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9623 | clip_child->test_properties()->clip_parent = root; |
| 9624 | root->test_properties()->clip_children = |
| 9625 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9626 | root->test_properties()->clip_children->insert(clip_child); |
| 9627 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9628 | ExecuteCalculateDrawProperties(root); |
| 9629 | |
| 9630 | EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); |
| 9631 | } |
| 9632 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9633 | TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) { |
| 9634 | // Tests that a mask layer's draw properties are computed correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9635 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9636 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9637 | child->test_properties()->SetMaskLayer( |
| 9638 | LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 9639 | LayerImpl* mask = child->test_properties()->mask_layer; |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9640 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9641 | gfx::Transform transform; |
| 9642 | transform.Translate(10, 10); |
| 9643 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9644 | root->SetBounds(gfx::Size(40, 40)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9645 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9646 | child->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9647 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9648 | child->SetDrawsContent(false); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9649 | mask->SetBounds(gfx::Size(20, 20)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9650 | ExecuteCalculateDrawProperties(root); |
| 9651 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9652 | // The render surface created for the mask has no contributing content, so the |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 9653 | // mask doesn't contribute to a drawn render surface. This means it has an |
| 9654 | // empty visible rect, but its screen space transform can still be computed |
| 9655 | // correctly on-demand. |
| 9656 | EXPECT_FALSE(mask->contributes_to_drawn_render_surface()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9657 | EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect()); |
| 9658 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9659 | |
| 9660 | // Make the child's render surface have contributing content. |
| 9661 | child->SetDrawsContent(true); |
| 9662 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9663 | ExecuteCalculateDrawProperties(root); |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 9664 | EXPECT_TRUE(mask->contributes_to_drawn_render_surface()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9665 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
| 9666 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9667 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9668 | transform.Translate(10, 10); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9669 | child->test_properties()->transform = transform; |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9670 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9671 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9672 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
| 9673 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9674 | } |
| 9675 | |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9676 | TEST_F(LayerTreeHostCommonTest, |
| 9677 | SublayerScaleWithTransformNodeBetweenTwoTargets) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9678 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9679 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9680 | LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1); |
| 9681 | LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets); |
| 9682 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9683 | |
| 9684 | gfx::Transform scale; |
| 9685 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9686 | |
| 9687 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9688 | render_surface1->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9689 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 9690 | render_surface1->test_properties()->force_render_surface = true; |
| 9691 | between_targets->SetBounds(gfx::Size(30, 30)); |
| 9692 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 9693 | render_surface2->test_properties()->force_render_surface = true; |
| 9694 | test_layer->SetBounds(gfx::Size(30, 30)); |
| 9695 | test_layer->SetDrawsContent(true); |
| 9696 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 9697 | // We want layer between the two targets to create a clip node and effect |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9698 | // node but it shouldn't create a render surface. |
| 9699 | between_targets->SetMasksToBounds(true); |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 9700 | between_targets->test_properties()->opacity = 0.5f; |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9701 | |
| 9702 | ExecuteCalculateDrawProperties(root); |
| 9703 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 9704 | EffectTree& tree = root->layer_tree_impl()->property_trees()->effect_tree; |
| 9705 | EffectNode* node = tree.Node(render_surface1->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9706 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9707 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 9708 | node = tree.Node(between_targets->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9709 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9710 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 9711 | node = tree.Node(render_surface2->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9712 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9713 | |
| 9714 | EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect()); |
| 9715 | } |
| 9716 | |
jaydasika | 3c5633d | 2016-08-25 00:39:22 | [diff] [blame] | 9717 | TEST_F(LayerTreeHostCommonTest, NoisyTransform) { |
| 9718 | LayerImpl* root = root_layer_for_testing(); |
| 9719 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9720 | LayerImpl* scroll_child = AddChild<LayerImpl>(render_surface); |
| 9721 | LayerImpl* scroll_clip = AddChild<LayerImpl>(render_surface); |
| 9722 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_clip); |
| 9723 | |
| 9724 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 9725 | scroll_parent->test_properties()->scroll_children = |
| 9726 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9727 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
jaydasika | 3c5633d | 2016-08-25 00:39:22 | [diff] [blame] | 9728 | |
| 9729 | scroll_parent->SetDrawsContent(true); |
| 9730 | scroll_child->SetDrawsContent(true); |
| 9731 | render_surface->test_properties()->force_render_surface = true; |
| 9732 | |
| 9733 | // A noisy transform that's invertible. |
| 9734 | gfx::Transform transform; |
| 9735 | transform.matrix().setDouble(0, 0, 6.12323e-17); |
| 9736 | transform.matrix().setDouble(0, 2, 1); |
| 9737 | transform.matrix().setDouble(2, 2, 6.12323e-17); |
| 9738 | transform.matrix().setDouble(2, 0, -1); |
| 9739 | |
| 9740 | scroll_child->test_properties()->transform = transform; |
| 9741 | render_surface->test_properties()->transform = transform; |
| 9742 | |
| 9743 | root->SetBounds(gfx::Size(30, 30)); |
| 9744 | scroll_child->SetBounds(gfx::Size(30, 30)); |
| 9745 | scroll_parent->SetBounds(gfx::Size(30, 30)); |
| 9746 | ExecuteCalculateDrawProperties(root); |
| 9747 | |
| 9748 | gfx::Transform expected; |
| 9749 | expected.matrix().setDouble(0, 0, 3.749395e-33); |
| 9750 | expected.matrix().setDouble(0, 2, 6.12323e-17); |
| 9751 | expected.matrix().setDouble(2, 0, -1); |
| 9752 | expected.matrix().setDouble(2, 2, 6.12323e-17); |
| 9753 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
| 9754 | scroll_child->ScreenSpaceTransform()); |
| 9755 | } |
| 9756 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9757 | TEST_F(LayerTreeHostCommonTest, LargeTransformTest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9758 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9759 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9760 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9761 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9762 | child->SetDrawsContent(true); |
| 9763 | child->SetMasksToBounds(true); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9764 | |
| 9765 | gfx::Transform large_transform; |
| 9766 | large_transform.Scale(99999999999999999999.f, 99999999999999999999.f); |
| 9767 | large_transform.Scale(9999999999999999999.f, 9999999999999999999.f); |
| 9768 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0))); |
| 9769 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1))); |
| 9770 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9771 | root->SetBounds(gfx::Size(30, 30)); |
| 9772 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 9773 | render_surface1->test_properties()->force_render_surface = true; |
| 9774 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9775 | // TODO(sunxd): we make child have no render surface, because if the |
| 9776 | // child has one, the large transform applied to child will result in NaNs in |
| 9777 | // the draw_transform of the render_surface, thus make draw property updates |
| 9778 | // skip the child layer. We need further investigation into this to know |
| 9779 | // what exactly happens here. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9780 | child->test_properties()->transform = large_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9781 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9782 | |
| 9783 | ExecuteCalculateDrawProperties(root); |
| 9784 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9785 | EXPECT_EQ(gfx::RectF(), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 9786 | GetRenderSurface(render_surface1)->DrawableContentRect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9787 | |
| 9788 | bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) || |
| 9789 | std::isnan(child->DrawTransform().matrix().get(0, 0)); |
| 9790 | EXPECT_TRUE(is_inf_or_nan); |
| 9791 | |
| 9792 | is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) || |
| 9793 | std::isnan(child->DrawTransform().matrix().get(1, 1)); |
| 9794 | EXPECT_TRUE(is_inf_or_nan); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9795 | |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 9796 | // The root layer should be in the RenderSurfaceList. |
| 9797 | const auto* rsl = render_surface_list_impl(); |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 9798 | EXPECT_NE(std::find(rsl->begin(), rsl->end(), GetRenderSurface(root)), |
ajuma | b784ef4 | 2017-04-28 23:01:52 | [diff] [blame] | 9799 | rsl->end()); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9800 | } |
| 9801 | |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9802 | TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) { |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9803 | scoped_refptr<Layer> root = Layer::Create(); |
| 9804 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 9805 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9806 | root->AddChild(child); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9807 | host()->SetRootLayer(root); |
| 9808 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9809 | root->SetBounds(gfx::Size(100, 100)); |
| 9810 | child->SetBounds(gfx::Size(20, 20)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9811 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9812 | |
| 9813 | // Changing the opacity from 1 to non-1 value should trigger rebuild of |
| 9814 | // property trees as a new effect node will be created. |
| 9815 | child->SetOpacity(0.5f); |
| 9816 | PropertyTrees* property_trees = host()->property_trees(); |
| 9817 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 9818 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9819 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
Chris Harrelson | 84670c9 | 2017-06-06 05:39:06 | [diff] [blame] | 9820 | EXPECT_NE(property_trees->effect_tree.Node(child->effect_tree_index()), |
| 9821 | property_trees->effect_tree.Node(root->effect_tree_index())); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9822 | |
| 9823 | // child already has an effect node. Changing its opacity shouldn't trigger |
| 9824 | // a property trees rebuild. |
| 9825 | child->SetOpacity(0.8f); |
| 9826 | property_trees = host()->property_trees(); |
| 9827 | EXPECT_FALSE(property_trees->needs_rebuild); |
| 9828 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9829 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
Chris Harrelson | 84670c9 | 2017-06-06 05:39:06 | [diff] [blame] | 9830 | EXPECT_NE(property_trees->effect_tree.Node(child->effect_tree_index()), |
| 9831 | property_trees->effect_tree.Node(root->effect_tree_index())); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9832 | |
| 9833 | // Changing the opacity from non-1 value to 1 should trigger a rebuild of |
| 9834 | // property trees as the effect node may no longer be needed. |
| 9835 | child->SetOpacity(1.f); |
| 9836 | property_trees = host()->property_trees(); |
| 9837 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 9838 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9839 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
Chris Harrelson | 84670c9 | 2017-06-06 05:39:06 | [diff] [blame] | 9840 | EXPECT_EQ(property_trees->effect_tree.Node(child->effect_tree_index()), |
| 9841 | property_trees->effect_tree.Node(root->effect_tree_index())); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9842 | } |
| 9843 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9844 | TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) { |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9845 | scoped_refptr<Layer> root = Layer::Create(); |
| 9846 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 9847 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9848 | root->AddChild(animated); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9849 | host()->SetRootLayer(root); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 9850 | host()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9851 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9852 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9853 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9854 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9855 | animated->SetOpacity(0.f); |
| 9856 | |
| 9857 | scoped_refptr<AnimationPlayer> player = |
| 9858 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 9859 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9860 | |
| 9861 | player->AttachElement(animated->element_id()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9862 | |
| 9863 | int animation_id = 0; |
| 9864 | std::unique_ptr<Animation> animation = Animation::Create( |
| 9865 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 9866 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 9867 | animation->set_fill_mode(Animation::FillMode::NONE); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9868 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 9869 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9870 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 9871 | std::move(animation)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9872 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9873 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9874 | |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 9875 | EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree; |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9876 | EffectNode* node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9877 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 9878 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9879 | |
| 9880 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 9881 | host()->AnimateLayers(base::TimeTicks::Max()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9882 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9883 | EXPECT_TRUE(node->is_currently_animating_opacity); |
| 9884 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9885 | |
| 9886 | player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/); |
| 9887 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9888 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 9889 | EXPECT_FALSE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9890 | } |
| 9891 | |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9892 | TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) { |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9893 | scoped_refptr<Layer> root = Layer::Create(); |
| 9894 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 9895 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9896 | root->AddChild(animated); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9897 | host()->SetRootLayer(root); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 9898 | host()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9899 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9900 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9901 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9902 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9903 | |
| 9904 | scoped_refptr<AnimationPlayer> player = |
| 9905 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 9906 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9907 | player->AttachElement(animated->element_id()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9908 | |
| 9909 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 9910 | KeyframedTransformAnimationCurve::Create()); |
| 9911 | TransformOperations start; |
| 9912 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 9913 | gfx::Transform transform; |
| 9914 | transform.Scale3d(1.0, 2.0, 3.0); |
| 9915 | TransformOperations operation; |
| 9916 | operation.AppendMatrix(transform); |
| 9917 | curve->AddKeyframe( |
| 9918 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 9919 | curve->AddKeyframe(TransformKeyframe::Create( |
| 9920 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
| 9921 | std::unique_ptr<Animation> animation( |
| 9922 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 9923 | animation->set_fill_mode(Animation::FillMode::NONE); |
| 9924 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 9925 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9926 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 9927 | std::move(animation)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9928 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9929 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9930 | |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 9931 | TransformTree& tree = |
| 9932 | root->layer_tree_host()->property_trees()->transform_tree; |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9933 | TransformNode* node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9934 | EXPECT_FALSE(node->is_currently_animating); |
| 9935 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9936 | |
| 9937 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
Yuri Wiitala | d061176 | 2017-07-22 02:33:21 | [diff] [blame] | 9938 | host()->AnimateLayers(base::TimeTicks::Max()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9939 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9940 | EXPECT_TRUE(node->is_currently_animating); |
| 9941 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9942 | |
| 9943 | player->AbortAnimations(TargetProperty::TRANSFORM, |
| 9944 | false /*needs_completion*/); |
| 9945 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9946 | EXPECT_FALSE(node->is_currently_animating); |
| 9947 | EXPECT_FALSE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9948 | } |
| 9949 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9950 | TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 9951 | // Test the behavior of scroll tree builder |
| 9952 | // Topology: |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9953 | // +root1(1)[inner_viewport_container_layer] |
| 9954 | // +-page_scale_layer |
| 9955 | // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling & |
| 9956 | // scrollable, inner_viewport_scroll_layer] |
| 9957 | // +------child6(6)[kScrollbarScrolling] |
| 9958 | // +--------grand_child10(10)[kScrollbarScrolling] |
| 9959 | // +----parent3(3) |
| 9960 | // +------child7(7)[scrollable] |
| 9961 | // +------child8(8)[scroll_parent=7] |
| 9962 | // +--------grand_child11(11)[scrollable] |
| 9963 | // +----parent4(4) |
| 9964 | // +------child9(9) |
| 9965 | // +--------grand_child12(12) |
| 9966 | // +----parent5(5)[contains_non_fast_scrollable_region] |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9967 | // |
| 9968 | // Expected scroll tree topology: |
| 9969 | // +property_tree_root---owner:-1 |
| 9970 | // +--root---owner:1, id:1 |
| 9971 | // +----node---owner:2, id:2 |
| 9972 | // +------node---owner:6, id:3 |
| 9973 | // +----node---owner:7, id:4 |
| 9974 | // +------node---owner:11, id:5 |
| 9975 | // +----node---owner:5, id:6 |
| 9976 | // |
| 9977 | // Extra check: |
| 9978 | // scroll_tree_index() of: |
| 9979 | // grand_child10:3 |
| 9980 | // parent3:1 |
| 9981 | // child8:4 |
| 9982 | // parent4:1 |
| 9983 | // child9:1 |
| 9984 | // grand_child12:1 |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9985 | scoped_refptr<Layer> root1 = Layer::Create(); |
| 9986 | scoped_refptr<Layer> page_scale_layer = Layer::Create(); |
| 9987 | scoped_refptr<Layer> parent2 = Layer::Create(); |
| 9988 | scoped_refptr<Layer> parent3 = Layer::Create(); |
| 9989 | scoped_refptr<Layer> parent4 = Layer::Create(); |
| 9990 | scoped_refptr<Layer> parent5 = Layer::Create(); |
| 9991 | scoped_refptr<Layer> child6 = Layer::Create(); |
| 9992 | scoped_refptr<Layer> child7 = Layer::Create(); |
| 9993 | scoped_refptr<Layer> child8 = Layer::Create(); |
| 9994 | scoped_refptr<Layer> child9 = Layer::Create(); |
| 9995 | scoped_refptr<Layer> grand_child10 = Layer::Create(); |
| 9996 | scoped_refptr<Layer> grand_child11 = Layer::Create(); |
| 9997 | scoped_refptr<Layer> grand_child12 = Layer::Create(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9998 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9999 | root1->AddChild(page_scale_layer); |
| 10000 | page_scale_layer->AddChild(parent2); |
| 10001 | page_scale_layer->AddChild(parent3); |
| 10002 | page_scale_layer->AddChild(parent4); |
| 10003 | page_scale_layer->AddChild(parent5); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10004 | parent2->AddChild(child6); |
| 10005 | parent3->AddChild(child7); |
| 10006 | parent3->AddChild(child8); |
| 10007 | parent4->AddChild(child9); |
| 10008 | child6->AddChild(grand_child10); |
| 10009 | child8->AddChild(grand_child11); |
| 10010 | child9->AddChild(grand_child12); |
| 10011 | host()->SetRootLayer(root1); |
| 10012 | |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 10013 | root1->SetBounds(gfx::Size(1, 1)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10014 | parent2->AddMainThreadScrollingReasons( |
| 10015 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10016 | parent2->AddMainThreadScrollingReasons( |
| 10017 | MainThreadScrollingReason::kScrollbarScrolling); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 10018 | parent2->SetElementId(LayerIdToElementIdForTesting(parent2->id())); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 10019 | parent2->SetScrollable(root1->bounds()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10020 | child6->AddMainThreadScrollingReasons( |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10021 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10022 | grand_child10->AddMainThreadScrollingReasons( |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10023 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10024 | |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 10025 | parent3->SetBounds(gfx::Size(2, 2)); |
| 10026 | child7->SetScrollable(parent3->bounds()); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 10027 | child7->SetElementId(LayerIdToElementIdForTesting(child7->id())); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10028 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10029 | child8->SetScrollParent(child7.get()); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 10030 | child8->SetBounds(gfx::Size(3, 3)); |
| 10031 | grand_child11->SetScrollable(child8->bounds()); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 10032 | grand_child11->SetElementId( |
| 10033 | LayerIdToElementIdForTesting(grand_child11->id())); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10034 | |
| 10035 | parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10036 | parent5->SetBounds(gfx::Size(10, 10)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10037 | |
pdr | 5200a05 | 2017-05-21 22:50:58 | [diff] [blame] | 10038 | LayerTreeHost::ViewportLayers viewport_layers; |
| 10039 | viewport_layers.page_scale = page_scale_layer; |
| 10040 | viewport_layers.inner_viewport_container = root1; |
| 10041 | viewport_layers.inner_viewport_scroll = parent2; |
| 10042 | host()->RegisterViewportLayers(viewport_layers); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10043 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10044 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10045 | const int kRootPropertyTreeNodeId = 0; |
| 10046 | |
| 10047 | // Property tree root |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10048 | ScrollTree& scroll_tree = host()->property_trees()->scroll_tree; |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 10049 | PropertyTrees property_trees; |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10050 | property_trees.is_main_thread = true; |
| 10051 | property_trees.is_active = false; |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10052 | ScrollTree& expected_scroll_tree = property_trees.scroll_tree; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10053 | ScrollNode* property_tree_root = expected_scroll_tree.Node(0); |
| 10054 | property_tree_root->id = kRootPropertyTreeNodeId; |
ajuma | f884cfb | 2017-01-16 22:27:52 | [diff] [blame] | 10055 | property_tree_root->parent_id = ScrollTree::kInvalidNodeId; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10056 | property_tree_root->scrollable = false; |
| 10057 | property_tree_root->main_thread_scrolling_reasons = |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10058 | MainThreadScrollingReason::kNotScrollingOnMain; |
pdr | 0283fabf | 2017-02-28 23:53:24 | [diff] [blame] | 10059 | property_tree_root->non_fast_scrollable_region = Region(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10060 | property_tree_root->transform_id = kRootPropertyTreeNodeId; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10061 | |
| 10062 | // The node owned by root1 |
| 10063 | ScrollNode scroll_root1; |
| 10064 | scroll_root1.id = 1; |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 10065 | scroll_root1.bounds = root1->bounds(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10066 | scroll_root1.user_scrollable_horizontal = true; |
| 10067 | scroll_root1.user_scrollable_vertical = true; |
| 10068 | scroll_root1.transform_id = root1->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10069 | expected_scroll_tree.Insert(scroll_root1, 0); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10070 | |
| 10071 | // The node owned by parent2 |
| 10072 | ScrollNode scroll_parent2; |
| 10073 | scroll_parent2.id = 2; |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 10074 | scroll_parent2.element_id = parent2->element_id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10075 | scroll_parent2.scrollable = true; |
| 10076 | scroll_parent2.main_thread_scrolling_reasons = |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10077 | parent2->main_thread_scrolling_reasons(); |
Philip Rogers | 0dd36f4 | 2017-06-30 23:33:37 | [diff] [blame] | 10078 | scroll_parent2.container_bounds = root1->bounds(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10079 | scroll_parent2.bounds = parent2->bounds(); |
| 10080 | scroll_parent2.max_scroll_offset_affected_by_page_scale = true; |
pdr | abe1552 | 2017-02-24 19:15:56 | [diff] [blame] | 10081 | scroll_parent2.scrolls_inner_viewport = true; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10082 | scroll_parent2.user_scrollable_horizontal = true; |
| 10083 | scroll_parent2.user_scrollable_vertical = true; |
| 10084 | scroll_parent2.transform_id = parent2->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10085 | expected_scroll_tree.Insert(scroll_parent2, 1); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10086 | |
| 10087 | // The node owned by child6 |
| 10088 | ScrollNode scroll_child6; |
| 10089 | scroll_child6.id = 3; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10090 | scroll_child6.main_thread_scrolling_reasons = |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10091 | child6->main_thread_scrolling_reasons(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10092 | scroll_child6.should_flatten = true; |
| 10093 | scroll_child6.user_scrollable_horizontal = true; |
| 10094 | scroll_child6.user_scrollable_vertical = true; |
| 10095 | scroll_child6.transform_id = child6->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10096 | expected_scroll_tree.Insert(scroll_child6, 2); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10097 | |
| 10098 | // The node owned by child7, child7 also owns a transform node |
| 10099 | ScrollNode scroll_child7; |
| 10100 | scroll_child7.id = 4; |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 10101 | scroll_child7.element_id = child7->element_id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10102 | scroll_child7.scrollable = true; |
Philip Rogers | 0dd36f4 | 2017-06-30 23:33:37 | [diff] [blame] | 10103 | scroll_child7.container_bounds = parent3->bounds(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10104 | scroll_child7.bounds = child7->bounds(); |
| 10105 | scroll_child7.user_scrollable_horizontal = true; |
| 10106 | scroll_child7.user_scrollable_vertical = true; |
| 10107 | scroll_child7.transform_id = child7->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10108 | expected_scroll_tree.Insert(scroll_child7, 1); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10109 | |
| 10110 | // The node owned by grand_child11, grand_child11 also owns a transform node |
| 10111 | ScrollNode scroll_grand_child11; |
| 10112 | scroll_grand_child11.id = 5; |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 10113 | scroll_grand_child11.element_id = grand_child11->element_id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10114 | scroll_grand_child11.scrollable = true; |
Philip Rogers | 0dd36f4 | 2017-06-30 23:33:37 | [diff] [blame] | 10115 | scroll_grand_child11.container_bounds = child8->bounds(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10116 | scroll_grand_child11.user_scrollable_horizontal = true; |
| 10117 | scroll_grand_child11.user_scrollable_vertical = true; |
| 10118 | scroll_grand_child11.transform_id = grand_child11->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10119 | expected_scroll_tree.Insert(scroll_grand_child11, 4); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10120 | |
| 10121 | // The node owned by parent5 |
| 10122 | ScrollNode scroll_parent5; |
| 10123 | scroll_parent5.id = 8; |
pdr | 0283fabf | 2017-02-28 23:53:24 | [diff] [blame] | 10124 | scroll_parent5.non_fast_scrollable_region = gfx::Rect(0, 0, 50, 50); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10125 | scroll_parent5.bounds = gfx::Size(10, 10); |
| 10126 | scroll_parent5.should_flatten = true; |
| 10127 | scroll_parent5.user_scrollable_horizontal = true; |
| 10128 | scroll_parent5.user_scrollable_vertical = true; |
| 10129 | scroll_parent5.transform_id = parent5->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10130 | expected_scroll_tree.Insert(scroll_parent5, 1); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10131 | |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 10132 | expected_scroll_tree.SetScrollOffset(parent2->element_id(), |
| 10133 | gfx::ScrollOffset(0, 0)); |
| 10134 | expected_scroll_tree.SetScrollOffset(child7->element_id(), |
| 10135 | gfx::ScrollOffset(0, 0)); |
| 10136 | expected_scroll_tree.SetScrollOffset(grand_child11->element_id(), |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10137 | gfx::ScrollOffset(0, 0)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10138 | expected_scroll_tree.set_needs_update(false); |
| 10139 | |
| 10140 | EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 10141 | |
| 10142 | // Check other layers' scroll_tree_index |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10143 | EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10144 | EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10145 | EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10146 | EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10147 | EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10148 | EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10149 | EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10150 | } |
| 10151 | |
reveman | b2b99a3b | 2017-04-06 23:39:08 | [diff] [blame] | 10152 | TEST_F(LayerTreeHostCommonTest, CanAdjustRasterScaleTest) { |
| 10153 | LayerImpl* root = root_layer_for_testing(); |
| 10154 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 10155 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 10156 | |
| 10157 | root->SetBounds(gfx::Size(50, 50)); |
| 10158 | |
| 10159 | render_surface->SetBounds(gfx::Size(10, 10)); |
| 10160 | render_surface->test_properties()->force_render_surface = true; |
| 10161 | gfx::Transform transform; |
| 10162 | transform.Scale(5.f, 5.f); |
| 10163 | render_surface->test_properties()->transform = transform; |
| 10164 | |
| 10165 | child->SetDrawsContent(true); |
| 10166 | child->SetMasksToBounds(true); |
| 10167 | child->SetBounds(gfx::Size(10, 10)); |
| 10168 | |
| 10169 | ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales(root); |
| 10170 | |
| 10171 | // Check surface draw properties. |
| 10172 | EXPECT_EQ(gfx::Rect(10, 10), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 10173 | GetRenderSurface(render_surface)->content_rect()); |
| 10174 | EXPECT_EQ(transform, GetRenderSurface(render_surface)->draw_transform()); |
reveman | b2b99a3b | 2017-04-06 23:39:08 | [diff] [blame] | 10175 | EXPECT_EQ(gfx::RectF(50.0f, 50.0f), |
chrishtr | 7e3aaf2 | 2017-05-04 15:04:01 | [diff] [blame] | 10176 | GetRenderSurface(render_surface)->DrawableContentRect()); |
reveman | b2b99a3b | 2017-04-06 23:39:08 | [diff] [blame] | 10177 | |
| 10178 | // Check child layer draw properties. |
| 10179 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
| 10180 | EXPECT_EQ(gfx::Transform(), child->DrawTransform()); |
| 10181 | EXPECT_EQ(gfx::Rect(10, 10), child->clip_rect()); |
| 10182 | EXPECT_EQ(gfx::Rect(10, 10), child->drawable_content_rect()); |
| 10183 | } |
| 10184 | |
wutao | 834bd20 | 2017-07-14 01:12:53 | [diff] [blame] | 10185 | TEST_F(LayerTreeHostCommonTest, SurfaceContentsScaleChangeWithCopyRequestTest) { |
| 10186 | LayerImpl* root = root_layer_for_testing(); |
| 10187 | LayerImpl* scale_layer = AddChild<LayerImpl>(root); |
| 10188 | LayerImpl* copy_layer = AddChild<LayerImpl>(scale_layer); |
| 10189 | LayerImpl* clip_layer = AddChild<LayerImpl>(copy_layer); |
| 10190 | LayerImpl* test_layer = AddChild<LayerImpl>(clip_layer); |
| 10191 | |
| 10192 | root->SetBounds(gfx::Size(150, 150)); |
| 10193 | |
| 10194 | scale_layer->SetBounds(gfx::Size(30, 30)); |
| 10195 | gfx::Transform transform; |
| 10196 | transform.Scale(5.f, 5.f); |
| 10197 | scale_layer->test_properties()->transform = transform; |
| 10198 | |
| 10199 | // Need to persist the render surface after copy request is cleared. |
| 10200 | copy_layer->test_properties()->force_render_surface = true; |
| 10201 | copy_layer->test_properties()->copy_requests.push_back( |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame^] | 10202 | viz::CopyOutputRequest::CreateRequest( |
| 10203 | base::Bind(&EmptyCopyOutputCallback))); |
wutao | 834bd20 | 2017-07-14 01:12:53 | [diff] [blame] | 10204 | |
| 10205 | clip_layer->SetDrawsContent(true); |
| 10206 | clip_layer->SetMasksToBounds(true); |
| 10207 | clip_layer->SetBounds(gfx::Size(10, 10)); |
| 10208 | |
| 10209 | test_layer->SetDrawsContent(true); |
| 10210 | test_layer->SetMasksToBounds(true); |
| 10211 | test_layer->SetBounds(gfx::Size(20, 20)); |
| 10212 | |
| 10213 | ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales(root); |
| 10214 | |
| 10215 | // Check surface with copy request draw properties. |
| 10216 | EXPECT_EQ(gfx::Rect(50, 50), GetRenderSurface(copy_layer)->content_rect()); |
| 10217 | EXPECT_EQ(gfx::Transform(), GetRenderSurface(copy_layer)->draw_transform()); |
| 10218 | EXPECT_EQ(gfx::RectF(50.0f, 50.0f), |
| 10219 | GetRenderSurface(copy_layer)->DrawableContentRect()); |
| 10220 | |
| 10221 | // Check test layer draw properties. |
| 10222 | EXPECT_EQ(gfx::Rect(10, 10), test_layer->visible_layer_rect()); |
| 10223 | EXPECT_EQ(transform, test_layer->DrawTransform()); |
| 10224 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect()); |
| 10225 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->drawable_content_rect()); |
| 10226 | |
| 10227 | // Clear the copy request and call UpdateSurfaceContentsScale. |
| 10228 | host_impl()->active_tree()->property_trees()->effect_tree.ClearCopyRequests(); |
| 10229 | ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales(root); |
| 10230 | |
| 10231 | // Check surface draw properties without copy request. |
| 10232 | EXPECT_EQ(gfx::Rect(10, 10), GetRenderSurface(copy_layer)->content_rect()); |
| 10233 | EXPECT_EQ(transform, GetRenderSurface(copy_layer)->draw_transform()); |
| 10234 | EXPECT_EQ(gfx::RectF(50.0f, 50.0f), |
| 10235 | GetRenderSurface(copy_layer)->DrawableContentRect()); |
| 10236 | |
| 10237 | // Check test layer draw properties without copy request. |
| 10238 | EXPECT_EQ(gfx::Rect(10, 10), test_layer->visible_layer_rect()); |
| 10239 | EXPECT_EQ(gfx::Transform(), test_layer->DrawTransform()); |
| 10240 | EXPECT_EQ(gfx::Rect(10, 10), test_layer->clip_rect()); |
| 10241 | EXPECT_EQ(gfx::Rect(10, 10), test_layer->drawable_content_rect()); |
| 10242 | } |
| 10243 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 10244 | } // namespace |
| 10245 | } // namespace cc |