ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
danakj | 6496cba | 2014-10-16 01:31:08 | [diff] [blame] | 9 | #include <algorithm> |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 11 | #include <set> |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 13 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 14 | #include "base/memory/ptr_util.h" |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 15 | #include "cc/animation/animation_host.h" |
| 16 | #include "cc/animation/animation_id_provider.h" |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 17 | #include "cc/animation/animation_player.h" |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 18 | #include "cc/animation/keyframed_animation_curve.h" |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 19 | #include "cc/animation/transform_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 20 | #include "cc/base/math_util.h" |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 21 | #include "cc/input/main_thread_scrolling_reason.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 22 | #include "cc/layers/content_layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 23 | #include "cc/layers/layer.h" |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 24 | #include "cc/layers/layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 25 | #include "cc/layers/layer_impl.h" |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 26 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 27 | #include "cc/layers/render_surface_impl.h" |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 28 | #include "cc/layers/texture_layer_impl.h" |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 29 | #include "cc/output/copy_output_request.h" |
| 30 | #include "cc/output/copy_output_result.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 31 | #include "cc/test/animation_test_common.h" |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 32 | #include "cc/test/fake_compositor_frame_sink.h" |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 33 | #include "cc/test/fake_content_layer_client.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 34 | #include "cc/test/fake_impl_task_runner_provider.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 35 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 36 | #include "cc/test/fake_layer_tree_host_impl.h" |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 37 | #include "cc/test/fake_picture_layer.h" |
| 38 | #include "cc/test/fake_picture_layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 39 | #include "cc/test/geometry_test_utils.h" |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 40 | #include "cc/test/layer_test_common.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 41 | #include "cc/test/test_task_graph_runner.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 42 | #include "cc/trees/clip_node.h" |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 43 | #include "cc/trees/draw_property_utils.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 44 | #include "cc/trees/effect_node.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 45 | #include "cc/trees/layer_tree_impl.h" |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 46 | #include "cc/trees/property_tree_builder.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 47 | #include "cc/trees/scroll_node.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 48 | #include "cc/trees/single_thread_proxy.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 49 | #include "cc/trees/task_runner_provider.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 50 | #include "cc/trees/transform_node.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 51 | #include "testing/gtest/include/gtest/gtest.h" |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 52 | #include "third_party/skia/include/core/SkImageFilter.h" |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 53 | #include "third_party/skia/include/effects/SkOffsetImageFilter.h" |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 54 | #include "third_party/skia/include/effects/SkXfermodeImageFilter.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 55 | #include "ui/gfx/geometry/quad_f.h" |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 56 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 57 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 58 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 59 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 60 | namespace { |
| 61 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 62 | class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings { |
| 63 | public: |
| 64 | VerifyTreeCalcsLayerTreeSettings() { |
jaydasika | 853306a | 2016-07-29 19:28:34 | [diff] [blame] | 65 | verify_clip_tree_calculations = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 66 | } |
| 67 | }; |
| 68 | |
| 69 | class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { |
| 70 | public: |
| 71 | LayerTreeHostCommonTestBase() |
| 72 | : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {} |
| 73 | explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings) |
| 74 | : LayerTestCommon::LayerImplTest(settings) {} |
| 75 | |
| 76 | static void SetScrollOffsetDelta(LayerImpl* layer_impl, |
| 77 | const gfx::Vector2dF& delta) { |
| 78 | if (layer_impl->layer_tree_impl() |
| 79 | ->property_trees() |
| 80 | ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(), |
| 81 | delta)) |
vollick | c969691 | 2016-09-16 16:02:47 | [diff] [blame] | 82 | layer_impl->layer_tree_impl()->DidUpdateScrollOffset(layer_impl->id()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static float GetMaximumAnimationScale(LayerImpl* layer_impl) { |
| 86 | return layer_impl->layer_tree_impl() |
| 87 | ->property_trees() |
| 88 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 89 | layer_impl->layer_tree_impl()) |
| 90 | .maximum_animation_scale; |
| 91 | } |
| 92 | |
| 93 | static float GetStartingAnimationScale(LayerImpl* layer_impl) { |
| 94 | return layer_impl->layer_tree_impl() |
| 95 | ->property_trees() |
| 96 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 97 | layer_impl->layer_tree_impl()) |
| 98 | .starting_animation_scale; |
| 99 | } |
| 100 | |
| 101 | void ExecuteCalculateDrawProperties(Layer* root_layer, |
| 102 | float device_scale_factor, |
| 103 | float page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 104 | Layer* page_scale_layer, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 105 | Layer* inner_viewport_scroll_layer, |
| 106 | Layer* outer_viewport_scroll_layer) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 107 | PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 108 | |
| 109 | EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 110 | gfx::Size device_viewport_size = |
| 111 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 112 | root_layer->bounds().height() * device_scale_factor); |
| 113 | |
| 114 | // We are probably not testing what is intended if the root_layer bounds are |
| 115 | // empty. |
| 116 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 117 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 118 | root_layer, device_viewport_size); |
| 119 | inputs.device_scale_factor = device_scale_factor; |
| 120 | inputs.page_scale_factor = page_scale_factor; |
| 121 | inputs.page_scale_layer = page_scale_layer; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 122 | inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 123 | inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 124 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 125 | } |
| 126 | |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 127 | void ExecuteCalculateDrawProperties( |
| 128 | LayerImpl* root_layer, |
| 129 | float device_scale_factor, |
| 130 | float page_scale_factor, |
| 131 | LayerImpl* page_scale_layer, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 132 | LayerImpl* inner_viewport_scroll_layer, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 133 | LayerImpl* outer_viewport_scroll_layer, |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 134 | bool skip_verify_visible_rect_calculations = false) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 135 | if (device_scale_factor != |
| 136 | root_layer->layer_tree_impl()->device_scale_factor()) |
| 137 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 138 | |
| 139 | root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); |
| 140 | |
| 141 | EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 142 | |
| 143 | gfx::Size device_viewport_size = |
| 144 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 145 | root_layer->bounds().height() * device_scale_factor); |
| 146 | |
| 147 | render_surface_layer_list_impl_.reset(new LayerImplList); |
| 148 | |
| 149 | // We are probably not testing what is intended if the root_layer bounds are |
| 150 | // empty. |
| 151 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 152 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 153 | root_layer, device_viewport_size, |
| 154 | render_surface_layer_list_impl_.get()); |
| 155 | inputs.device_scale_factor = device_scale_factor; |
| 156 | inputs.page_scale_factor = page_scale_factor; |
| 157 | inputs.page_scale_layer = page_scale_layer; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 158 | inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 159 | inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 160 | inputs.can_adjust_raster_scales = true; |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 161 | if (skip_verify_visible_rect_calculations) |
| 162 | inputs.verify_visible_rect_calculations = false; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 163 | |
| 164 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 165 | } |
| 166 | |
| 167 | template <class LayerType> |
| 168 | void ExecuteCalculateDrawProperties(LayerType* root_layer) { |
| 169 | LayerType* page_scale_application_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 170 | LayerType* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 171 | LayerType* outer_viewport_scroll_layer = nullptr; |
| 172 | ExecuteCalculateDrawProperties( |
| 173 | root_layer, 1.f, 1.f, page_scale_application_layer, |
| 174 | inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | template <class LayerType> |
| 178 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 179 | float device_scale_factor) { |
| 180 | LayerType* page_scale_application_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 181 | LayerType* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 182 | LayerType* outer_viewport_scroll_layer = nullptr; |
| 183 | ExecuteCalculateDrawProperties( |
| 184 | root_layer, device_scale_factor, 1.f, page_scale_application_layer, |
| 185 | inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 186 | } |
| 187 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 188 | const LayerList* GetUpdateLayerList() { return &update_layer_list_; } |
| 189 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 190 | void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) { |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 191 | DCHECK(root_layer->layer_tree_host()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 192 | PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 193 | |
| 194 | bool can_render_to_separate_surface = true; |
| 195 | |
| 196 | const Layer* page_scale_layer = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 197 | root_layer->layer_tree_host()->page_scale_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 198 | Layer* inner_viewport_scroll_layer = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 199 | root_layer->layer_tree_host()->inner_viewport_scroll_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 200 | Layer* outer_viewport_scroll_layer = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 201 | root_layer->layer_tree_host()->outer_viewport_scroll_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 202 | const Layer* overscroll_elasticity_layer = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 203 | root_layer->layer_tree_host()->overscroll_elasticity_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 204 | gfx::Vector2dF elastic_overscroll = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 205 | root_layer->layer_tree_host()->elastic_overscroll(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 206 | float page_scale_factor = 1.f; |
| 207 | float device_scale_factor = 1.f; |
| 208 | gfx::Size device_viewport_size = |
| 209 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 210 | root_layer->bounds().height() * device_scale_factor); |
| 211 | PropertyTrees* property_trees = |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 212 | root_layer->layer_tree_host()->property_trees(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 213 | update_layer_list_.clear(); |
| 214 | PropertyTreeBuilder::BuildPropertyTrees( |
| 215 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 216 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 217 | elastic_overscroll, page_scale_factor, device_scale_factor, |
| 218 | gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
| 219 | draw_property_utils::UpdatePropertyTrees(property_trees, |
| 220 | can_render_to_separate_surface); |
| 221 | draw_property_utils::FindLayersThatNeedUpdates( |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 222 | root_layer->layer_tree_host(), property_trees, &update_layer_list_); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 223 | } |
| 224 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 225 | void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
| 226 | LayerImpl* root_layer, |
| 227 | bool skip_verify_visible_rect_calculations = false) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 228 | DCHECK(root_layer->layer_tree_impl()); |
| 229 | PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer); |
| 230 | |
| 231 | bool can_render_to_separate_surface = true; |
| 232 | |
| 233 | LayerImpl* page_scale_layer = nullptr; |
| 234 | LayerImpl* inner_viewport_scroll_layer = |
| 235 | root_layer->layer_tree_impl()->InnerViewportScrollLayer(); |
| 236 | LayerImpl* outer_viewport_scroll_layer = |
| 237 | root_layer->layer_tree_impl()->OuterViewportScrollLayer(); |
| 238 | LayerImpl* overscroll_elasticity_layer = |
| 239 | root_layer->layer_tree_impl()->OverscrollElasticityLayer(); |
| 240 | gfx::Vector2dF elastic_overscroll = |
| 241 | root_layer->layer_tree_impl()->elastic_overscroll()->Current( |
| 242 | root_layer->layer_tree_impl()->IsActiveTree()); |
| 243 | float page_scale_factor = 1.f; |
| 244 | float device_scale_factor = 1.f; |
| 245 | gfx::Size device_viewport_size = |
| 246 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 247 | root_layer->bounds().height() * device_scale_factor); |
| 248 | update_layer_list_impl_.reset(new LayerImplList); |
| 249 | root_layer->layer_tree_impl()->BuildLayerListForTesting(); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 250 | PropertyTrees* property_trees = |
| 251 | root_layer->layer_tree_impl()->property_trees(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 252 | draw_property_utils::BuildPropertyTreesAndComputeVisibleRects( |
| 253 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 254 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 255 | elastic_overscroll, page_scale_factor, device_scale_factor, |
| 256 | gfx::Rect(device_viewport_size), gfx::Transform(), |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 257 | can_render_to_separate_surface, property_trees, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 258 | update_layer_list_impl_.get()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 259 | draw_property_utils::VerifyClipTreeCalculations(*update_layer_list_impl_, |
| 260 | property_trees); |
| 261 | if (!skip_verify_visible_rect_calculations) |
| 262 | draw_property_utils::VerifyVisibleRectsCalculations( |
| 263 | *update_layer_list_impl_, property_trees); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces( |
| 267 | LayerImpl* root_layer) { |
| 268 | gfx::Size device_viewport_size = |
| 269 | gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); |
| 270 | render_surface_layer_list_impl_.reset(new LayerImplList); |
| 271 | |
| 272 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 273 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 274 | root_layer, device_viewport_size, |
| 275 | render_surface_layer_list_impl_.get()); |
| 276 | inputs.can_adjust_raster_scales = true; |
| 277 | inputs.can_render_to_separate_surface = false; |
| 278 | |
| 279 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 280 | } |
| 281 | |
| 282 | bool UpdateLayerListImplContains(int id) const { |
| 283 | for (auto* layer : *update_layer_list_impl_) { |
| 284 | if (layer->id() == id) |
| 285 | return true; |
| 286 | } |
| 287 | return false; |
| 288 | } |
| 289 | |
| 290 | bool UpdateLayerListContains(int id) const { |
| 291 | for (const auto& layer : update_layer_list_) { |
| 292 | if (layer->id() == id) |
| 293 | return true; |
| 294 | } |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | const LayerImplList* render_surface_layer_list_impl() const { |
| 299 | return render_surface_layer_list_impl_.get(); |
| 300 | } |
| 301 | const LayerImplList* update_layer_list_impl() const { |
| 302 | return update_layer_list_impl_.get(); |
| 303 | } |
| 304 | const LayerList& update_layer_list() const { return update_layer_list_; } |
| 305 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 306 | bool VerifyLayerInList(scoped_refptr<Layer> layer, |
| 307 | const LayerList* layer_list) { |
| 308 | return std::find(layer_list->begin(), layer_list->end(), layer) != |
| 309 | layer_list->end(); |
| 310 | } |
| 311 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 312 | private: |
| 313 | std::unique_ptr<std::vector<LayerImpl*>> render_surface_layer_list_impl_; |
| 314 | LayerList update_layer_list_; |
| 315 | std::unique_ptr<LayerImplList> update_layer_list_impl_; |
| 316 | }; |
| 317 | |
| 318 | class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase, |
| 319 | public testing::Test {}; |
| 320 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 321 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 322 | public: |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 323 | LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 324 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 325 | bool DrawsContent() const override { return true; } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 326 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 327 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 328 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 329 | }; |
| 330 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 331 | class LayerTreeSettingsScaleContent : public VerifyTreeCalcsLayerTreeSettings { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 332 | public: |
| 333 | LayerTreeSettingsScaleContent() { |
| 334 | layer_transforms_should_scale_layer_contents = true; |
| 335 | } |
| 336 | }; |
| 337 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 338 | class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTestBase, |
| 339 | public testing::Test { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 340 | public: |
| 341 | LayerTreeHostCommonScalingTest() |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 342 | : LayerTreeHostCommonTestBase(LayerTreeSettingsScaleContent()) {} |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 343 | }; |
| 344 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 345 | class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest { |
| 346 | public: |
| 347 | LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {} |
| 348 | |
| 349 | LayerImpl* TestVisibleRectAndDrawableContentRect( |
| 350 | const gfx::Rect& target_rect, |
| 351 | const gfx::Transform& layer_transform, |
| 352 | const gfx::Rect& layer_rect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 353 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 354 | LayerImpl* target = AddChild<LayerImpl>(root); |
| 355 | LayerImpl* drawing_layer = AddChild<LayerImpl>(target); |
| 356 | |
| 357 | root->SetDrawsContent(true); |
| 358 | target->SetDrawsContent(true); |
| 359 | target->SetMasksToBounds(true); |
| 360 | drawing_layer->SetDrawsContent(true); |
| 361 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 362 | root->SetBounds(gfx::Size(500, 500)); |
| 363 | root->test_properties()->force_render_surface = true; |
| 364 | target->SetPosition(gfx::PointF(target_rect.origin())); |
| 365 | target->SetBounds(target_rect.size()); |
| 366 | target->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 367 | drawing_layer->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 368 | drawing_layer->SetPosition(gfx::PointF(layer_rect.origin())); |
| 369 | drawing_layer->SetBounds(layer_rect.size()); |
| 370 | drawing_layer->test_properties()->should_flatten_transform = false; |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 371 | |
| 372 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 373 | ExecuteCalculateDrawProperties(root); |
| 374 | |
| 375 | return drawing_layer; |
| 376 | } |
| 377 | }; |
| 378 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 379 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 380 | // Sanity check: For layers positioned at zero, with zero size, |
| 381 | // and with identity transforms, then the draw transform, |
| 382 | // screen space transform, and the hierarchy passed on to children |
| 383 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 384 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 385 | LayerImpl* parent = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 386 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 387 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 388 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 389 | parent->SetBounds(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 390 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 391 | ExecuteCalculateDrawProperties(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 392 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 393 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 394 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 395 | child->ScreenSpaceTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 396 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 397 | grand_child->DrawTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 398 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 399 | grand_child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 400 | } |
| 401 | |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 402 | TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) { |
| 403 | // Tests that effect tree node gets a valid transform id when a layer |
| 404 | // has opacity but doesn't create a render surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 405 | LayerImpl* parent = root_layer_for_testing(); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 406 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 407 | child->SetDrawsContent(true); |
| 408 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 409 | parent->SetBounds(gfx::Size(100, 100)); |
| 410 | child->SetPosition(gfx::PointF(10, 10)); |
| 411 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 412 | child->test_properties()->opacity = 0.f; |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 413 | ExecuteCalculateDrawProperties(parent); |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 414 | EffectTree& effect_tree = |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 415 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 416 | EffectNode* node = effect_tree.Node(child->effect_tree_index()); |
| 417 | const int transform_tree_size = parent->layer_tree_impl() |
| 418 | ->property_trees() |
| 419 | ->transform_tree.next_available_id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 420 | EXPECT_LT(node->transform_id, transform_tree_size); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 421 | } |
| 422 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 423 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 424 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 425 | LayerImpl* layer = AddChild<LayerImpl>(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 426 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 427 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 428 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 429 | EffectTree& effect_tree = |
| 430 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 431 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 432 | root->SetBounds(gfx::Size(1, 2)); |
| 433 | |
| 434 | // Case 1: Setting the bounds of the layer should not affect either the draw |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 435 | // transform or the screenspace transform. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 436 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 437 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 438 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 439 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 440 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 441 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 442 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 443 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 444 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 445 | // Case 2: The anchor point by itself (without a layer transform) should have |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 446 | // no effect on the transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 447 | layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 448 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 449 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 450 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 451 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 452 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 453 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 454 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 455 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 456 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 457 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 458 | // Case 3: A change in actual position affects both the draw transform and |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 459 | // screen space transform. |
| 460 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 461 | position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 462 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 463 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 464 | ExecuteCalculateDrawProperties(root); |
| 465 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 466 | position_transform, |
| 467 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 468 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 469 | position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 470 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 471 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 472 | // Case 4: In the correct sequence of transforms, the layer transform should |
| 473 | // pre-multiply the translation-to-center. This is easily tested by using a |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 474 | // scale transform, because scale and translation are not commutative. |
| 475 | gfx::Transform layer_transform; |
| 476 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 477 | layer->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 478 | layer->test_properties()->transform_origin = gfx::Point3F(); |
| 479 | layer->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 480 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 481 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 482 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 483 | layer_transform, |
| 484 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 485 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 486 | layer_transform, |
| 487 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 488 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 489 | // Case 5: The layer transform should occur with respect to the anchor point. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 490 | gfx::Transform translation_to_anchor; |
| 491 | translation_to_anchor.Translate(5.0, 0.0); |
| 492 | gfx::Transform expected_result = |
| 493 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 494 | layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 495 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 496 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 497 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 498 | expected_result, |
| 499 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 500 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 501 | expected_result, |
| 502 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 503 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 504 | // Case 6: Verify that position pre-multiplies the layer transform. The |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 505 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 506 | // it is still worth testing to detect accidental regressions. |
| 507 | expected_result = position_transform * translation_to_anchor * |
| 508 | layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 509 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 510 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 511 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 512 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 513 | expected_result, |
| 514 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 515 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 516 | expected_result, |
| 517 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 518 | } |
| 519 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 520 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 521 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 522 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 523 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 524 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 525 | -kScrollOffset.y()); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 526 | float page_scale = 0.888f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 527 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 528 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 529 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 530 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 531 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 532 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 533 | std::unique_ptr<LayerImpl> sublayer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 534 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 535 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 536 | sublayer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 537 | sublayer->SetBounds(gfx::Size(500, 500)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 538 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 539 | std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 540 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 541 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 542 | scroll_layer->SetBounds(gfx::Size(10, 20)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 543 | std::unique_ptr<LayerImpl> clip_layer_scoped_ptr( |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 544 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 545 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 546 | |
| 547 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 548 | clip_layer->SetBounds( |
| 549 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 550 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 551 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 552 | SetScrollOffsetDelta(scroll_layer, kScrollDelta); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 553 | gfx::Transform impl_transform; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 554 | scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 555 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 556 | clip_layer->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr)); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 557 | scroll_layer_raw_ptr->layer_tree_impl() |
| 558 | ->property_trees() |
| 559 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(), |
| 560 | kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 561 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 562 | std::unique_ptr<LayerImpl> root( |
| 563 | LayerImpl::Create(host_impl.active_tree(), 3)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 564 | root->SetBounds(gfx::Size(3, 4)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 565 | root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 566 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 567 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 568 | |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 569 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 570 | scroll_layer->test_properties()->parent, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 571 | nullptr, nullptr); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 572 | gfx::Transform expected_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 573 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 574 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 575 | page_scale * kDeviceScale), |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 576 | MathUtil::Round(sub_layer_screen_position.y() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 577 | page_scale * kDeviceScale)); |
| 578 | expected_transform.Scale(page_scale * kDeviceScale, |
| 579 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 580 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 581 | sublayer->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 582 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 583 | sublayer->ScreenSpaceTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 584 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 585 | gfx::Transform arbitrary_translate; |
| 586 | const float kTranslateX = 10.6f; |
| 587 | const float kTranslateY = 20.6f; |
| 588 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 589 | scroll_layer->test_properties()->transform = arbitrary_translate; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 590 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 591 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 592 | scroll_layer->test_properties()->parent, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 593 | nullptr, nullptr); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 594 | expected_transform.MakeIdentity(); |
| 595 | expected_transform.Translate( |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 596 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 597 | sub_layer_screen_position.x() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 598 | kDeviceScale), |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 599 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 600 | sub_layer_screen_position.y() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 601 | kDeviceScale)); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 602 | expected_transform.Scale(page_scale * kDeviceScale, |
| 603 | page_scale * kDeviceScale); |
| 604 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 605 | sublayer->DrawTransform()); |
| 606 | |
| 607 | // Test that page scale is updated even when we don't rebuild property trees. |
| 608 | page_scale = 1.888f; |
| 609 | root_layer->layer_tree_impl()->SetViewportLayersFromIds( |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 610 | Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(), |
| 611 | Layer::INVALID_ID, Layer::INVALID_ID); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 612 | root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 613 | EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 614 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 615 | scroll_layer->test_properties()->parent, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 616 | nullptr, nullptr); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 617 | |
| 618 | expected_transform.MakeIdentity(); |
| 619 | expected_transform.Translate( |
| 620 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 621 | sub_layer_screen_position.x() * page_scale * |
| 622 | kDeviceScale), |
| 623 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 624 | sub_layer_screen_position.y() * page_scale * |
| 625 | kDeviceScale)); |
| 626 | expected_transform.Scale(page_scale * kDeviceScale, |
| 627 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 628 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 629 | sublayer->DrawTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 630 | } |
| 631 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 632 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 633 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 634 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 635 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 636 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 637 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 638 | // One-time setup of root layer |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 639 | root->SetBounds(gfx::Size(1, 2)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 640 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 641 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 642 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 643 | EffectTree& effect_tree = |
| 644 | host_impl()->active_tree()->property_trees()->effect_tree; |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 645 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 646 | // Case 1: parent's anchor point should not affect child or grand_child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 647 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 648 | parent->SetBounds(gfx::Size(10, 12)); |
| 649 | child->SetBounds(gfx::Size(16, 18)); |
| 650 | grand_child->SetBounds(gfx::Size(76, 78)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 651 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 652 | |
| 653 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 654 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 655 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 656 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 657 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 658 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 659 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 660 | gfx::Transform(), draw_property_utils::DrawTransform( |
| 661 | grand_child, transform_tree, effect_tree)); |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 662 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 663 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 664 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 665 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 666 | // Case 2: parent's position affects child and grand_child. |
| 667 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 668 | parent_position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 669 | parent->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 670 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 671 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 672 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 673 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 674 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 675 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 676 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 677 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 678 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 679 | parent_position_transform, draw_property_utils::DrawTransform( |
| 680 | grand_child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 681 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 682 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 683 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 684 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 685 | // Case 3: parent's local transform affects child and grandchild |
| 686 | gfx::Transform parent_layer_transform; |
| 687 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 688 | gfx::Transform parent_translation_to_anchor; |
| 689 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 690 | gfx::Transform parent_composite_transform = |
| 691 | parent_translation_to_anchor * parent_layer_transform * |
| 692 | Inverse(parent_translation_to_anchor); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 693 | parent->test_properties()->transform = parent_layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 694 | parent->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 695 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 696 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 697 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 698 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 699 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 700 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 701 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 702 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 703 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 704 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 705 | draw_property_utils::DrawTransform(grand_child, transform_tree, |
| 706 | effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 707 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 708 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 709 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 710 | } |
| 711 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 712 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 713 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 714 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 715 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 716 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 717 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 718 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 719 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 720 | gfx::Transform parent_translation_to_anchor; |
| 721 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 722 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 723 | gfx::Transform parent_composite_transform = |
| 724 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 725 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 726 | gfx::Vector2dF parent_composite_scale = |
| 727 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 728 | 1.f); |
| 729 | gfx::Transform surface_sublayer_transform; |
| 730 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 731 | parent_composite_scale.y()); |
| 732 | gfx::Transform surface_sublayer_composite_transform = |
| 733 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 734 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 735 | root->SetBounds(gfx::Size(1, 2)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 736 | parent->test_properties()->transform = parent_layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 737 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f); |
| 738 | parent->SetBounds(gfx::Size(100, 120)); |
| 739 | child->SetBounds(gfx::Size(16, 18)); |
| 740 | child->test_properties()->force_render_surface = true; |
| 741 | grand_child->SetBounds(gfx::Size(8, 10)); |
| 742 | grand_child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 743 | ExecuteCalculateDrawProperties(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 744 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 745 | // Render surface should have been created now. |
| 746 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 747 | ASSERT_EQ(child->render_surface(), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 748 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 749 | // The child layer's draw transform should refer to its new render surface. |
| 750 | // The screen-space transform, however, should still refer to the root. |
| 751 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 752 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 753 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 754 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 755 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 756 | // Because the grand_child is the only drawable content, the child's render |
| 757 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 758 | // surface's subtree is drawn must be removed from the composite transform. |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 759 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, |
| 760 | child->render_target()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 761 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 762 | // The screen space is the same as the target since the child surface draws |
| 763 | // into the root. |
| 764 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 765 | surface_sublayer_composite_transform, |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 766 | child->render_target()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 767 | } |
| 768 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 769 | TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 770 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 771 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 772 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 773 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 774 | |
| 775 | gfx::Transform parent_transform; |
| 776 | parent_transform.Translate(10.0, 10.0); |
| 777 | |
| 778 | gfx::Transform child_transform; |
| 779 | child_transform.Rotate(45.0); |
| 780 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 781 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 782 | parent->test_properties()->transform = parent_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 783 | parent->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 784 | child->test_properties()->transform = child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 785 | child->SetBounds(gfx::Size(10, 10)); |
| 786 | child->test_properties()->force_render_surface = true; |
| 787 | grand_child->SetPosition(gfx::PointF(2.f, 2.f)); |
| 788 | grand_child->SetBounds(gfx::Size(20, 20)); |
| 789 | grand_child->SetDrawsContent(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 790 | |
| 791 | gfx::Transform expected_grand_child_screen_space_transform; |
| 792 | expected_grand_child_screen_space_transform.Translate(10.0, 10.0); |
| 793 | expected_grand_child_screen_space_transform.Rotate(45.0); |
| 794 | expected_grand_child_screen_space_transform.Translate(2.0, 2.0); |
| 795 | |
| 796 | // First compute draw properties with separate surfaces enabled. |
| 797 | ExecuteCalculateDrawProperties(root); |
| 798 | |
| 799 | // The grand child's draw transform should be its offset wrt the child. |
| 800 | gfx::Transform expected_grand_child_draw_transform; |
| 801 | expected_grand_child_draw_transform.Translate(2.0, 2.0); |
| 802 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 803 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 804 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 805 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 806 | |
| 807 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 808 | |
| 809 | // With separate surfaces disabled, the grand child's draw transform should be |
| 810 | // the same as its screen space transform. |
| 811 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 812 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 813 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 814 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 815 | } |
| 816 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 817 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 818 | // This test creates a more complex tree and verifies it all at once. This |
| 819 | // covers the following cases: |
| 820 | // - layers that are described w.r.t. a render surface: should have draw |
| 821 | // transforms described w.r.t. that surface |
| 822 | // - A render surface described w.r.t. an ancestor render surface: should |
| 823 | // have a draw transform described w.r.t. that ancestor surface |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 824 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 825 | // a render surface that is described w.r.t. an ancestor render surface. |
| 826 | // - verifying that each layer has a reference to the correct render surface |
| 827 | // and render target values. |
| 828 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 829 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 830 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 831 | parent->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 832 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 833 | render_surface1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 834 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 835 | render_surface2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 836 | LayerImpl* child_of_root = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 837 | child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 838 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 839 | child_of_rs1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 840 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 841 | child_of_rs2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 842 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 843 | grand_child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 844 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 845 | grand_child_of_rs1->SetDrawsContent(true); |
| 846 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 847 | grand_child_of_rs2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 848 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 849 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 850 | // to have a new render surface. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 851 | render_surface1->test_properties()->opacity = 0.5f; |
| 852 | render_surface2->test_properties()->opacity = 0.33f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 853 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 854 | // 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] | 855 | // (10,10). Matrix "A" is the composite layer transform used in all layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 856 | gfx::Transform translation_to_anchor; |
| 857 | translation_to_anchor.Translate(2.5, 0.0); |
| 858 | gfx::Transform layer_transform; |
| 859 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 860 | |
| 861 | gfx::Transform A = |
| 862 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 863 | |
| 864 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 865 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 866 | gfx::Transform surface1_sublayer_transform; |
| 867 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 868 | surface1_parent_transform_scale.y()); |
| 869 | |
| 870 | // SS1 = transform given to the subtree of render_surface1 |
| 871 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 872 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 873 | // the owning layer |
| 874 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 875 | |
| 876 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 877 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 878 | gfx::Transform surface2_sublayer_transform; |
| 879 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 880 | surface2_parent_transform_scale.y()); |
| 881 | |
| 882 | // SS2 = transform given to the subtree of render_surface2 |
| 883 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 884 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 885 | // the owning layer |
| 886 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 887 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 888 | root->SetBounds(gfx::Size(1, 2)); |
| 889 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 890 | parent->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 891 | parent->SetBounds(gfx::Size(10, 10)); |
| 892 | render_surface1->test_properties()->transform_origin = |
| 893 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 894 | render_surface1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 895 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 896 | render_surface1->test_properties()->force_render_surface = true; |
| 897 | render_surface2->test_properties()->transform_origin = |
| 898 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 899 | render_surface2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 900 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 901 | render_surface2->test_properties()->force_render_surface = true; |
| 902 | child_of_root->test_properties()->transform_origin = |
| 903 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 904 | child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 905 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 906 | child_of_rs1->test_properties()->transform_origin = |
| 907 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 908 | child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 909 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 910 | child_of_rs2->test_properties()->transform_origin = |
| 911 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 912 | child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 913 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 914 | grand_child_of_root->test_properties()->transform_origin = |
| 915 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 916 | grand_child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 917 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 918 | grand_child_of_rs1->test_properties()->transform_origin = |
| 919 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 920 | grand_child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 921 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 922 | grand_child_of_rs2->test_properties()->transform_origin = |
| 923 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 924 | grand_child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 925 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 926 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 927 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 928 | |
| 929 | // Only layers that are associated with render surfaces should have an actual |
| 930 | // RenderSurface() value. |
| 931 | ASSERT_TRUE(root->render_surface()); |
| 932 | ASSERT_FALSE(child_of_root->render_surface()); |
| 933 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 934 | |
| 935 | ASSERT_TRUE(render_surface1->render_surface()); |
| 936 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 937 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 938 | |
| 939 | ASSERT_TRUE(render_surface2->render_surface()); |
| 940 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 941 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 942 | |
| 943 | // Verify all render target accessors |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 944 | EXPECT_EQ(root->render_surface(), parent->render_target()); |
| 945 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 946 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 947 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 948 | EXPECT_EQ(render_surface1->render_surface(), |
| 949 | render_surface1->render_target()); |
| 950 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 951 | EXPECT_EQ(render_surface1->render_surface(), |
| 952 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 953 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 954 | EXPECT_EQ(render_surface2->render_surface(), |
| 955 | render_surface2->render_target()); |
| 956 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 957 | EXPECT_EQ(render_surface2->render_surface(), |
| 958 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 959 | |
| 960 | // Verify layer draw transforms note that draw transforms are described with |
| 961 | // respect to the nearest ancestor render surface but screen space transforms |
| 962 | // are described with respect to the root. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 963 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform()); |
| 964 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 965 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 966 | grand_child_of_root->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 967 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 968 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform()); |
| 969 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 970 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 971 | grand_child_of_rs1->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 972 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 973 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform()); |
| 974 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 975 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 976 | grand_child_of_rs2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 977 | |
| 978 | // Verify layer screen-space transforms |
| 979 | // |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 980 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform()); |
| 981 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform()); |
| 982 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
| 983 | grand_child_of_root->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 984 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 985 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 986 | render_surface1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 987 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 988 | child_of_rs1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 989 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 990 | grand_child_of_rs1->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 991 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 992 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 993 | render_surface2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 994 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 995 | child_of_rs2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 996 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 997 | grand_child_of_rs2->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 998 | |
| 999 | // Verify render surface transforms. |
| 1000 | // |
| 1001 | // Draw transform of render surface 1 is described with respect to root. |
| 1002 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1003 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1004 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1005 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1006 | // Draw transform of render surface 2 is described with respect to render |
| 1007 | // surface 1. |
| 1008 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1009 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1010 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1011 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1012 | render_surface2->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1013 | |
| 1014 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 1015 | // is expected that we correctly set up transforms so that the y-component of |
| 1016 | // the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1017 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1018 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1019 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1020 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1021 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1022 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1023 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1024 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 1025 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1026 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1027 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1028 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1029 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1030 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 1031 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1032 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1033 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1034 | } |
| 1035 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1036 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1037 | // For layers that flatten their subtree, there should be an orthographic |
| 1038 | // projection (for x and y values) in the middle of the transform sequence. |
| 1039 | // Note that the way the code is currently implemented, it is not expected to |
| 1040 | // use a canonical orthographic projection. |
| 1041 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1042 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1043 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1044 | child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1045 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1046 | grand_child->SetDrawsContent(true); |
| 1047 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 1048 | great_grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1049 | |
| 1050 | gfx::Transform rotation_about_y_axis; |
| 1051 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1052 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1053 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1054 | child->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1055 | child->SetBounds(gfx::Size(10, 10)); |
| 1056 | child->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1057 | grand_child->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1058 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1059 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1060 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1061 | // No layers in this test should preserve 3d. |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1062 | ASSERT_TRUE(root->test_properties()->should_flatten_transform); |
| 1063 | ASSERT_TRUE(child->test_properties()->should_flatten_transform); |
| 1064 | ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform); |
| 1065 | ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1066 | |
| 1067 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1068 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1069 | gfx::Transform expected_grand_child_draw_transform = |
| 1070 | rotation_about_y_axis; // draws onto child's render surface |
| 1071 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1072 | flattened_rotation_about_y.FlattenTo2d(); |
| 1073 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1074 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1075 | gfx::Transform expected_great_grand_child_draw_transform = |
| 1076 | flattened_rotation_about_y; |
| 1077 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 1078 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1079 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1080 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1081 | |
| 1082 | // The child's draw transform should have been taken by its surface. |
| 1083 | ASSERT_TRUE(child->render_surface()); |
| 1084 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1085 | child->render_surface()->draw_transform()); |
| 1086 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1087 | expected_child_screen_space_transform, |
| 1088 | child->render_surface()->screen_space_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1089 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1090 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1091 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1092 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1093 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1094 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1095 | grand_child->ScreenSpaceTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1096 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1097 | great_grand_child->DrawTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1098 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1099 | expected_great_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1100 | great_grand_child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1101 | } |
| 1102 | |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1103 | TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1104 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1105 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1106 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1107 | |
| 1108 | gfx::Transform child_transform; |
| 1109 | child_transform.Translate(50.0, 50.0); |
| 1110 | child_transform.RotateAboutZAxis(30.0); |
| 1111 | |
| 1112 | gfx::Transform grand_child_transform; |
| 1113 | grand_child_transform.RotateAboutYAxis(90.0); |
| 1114 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1115 | root->SetBounds(gfx::Size(200, 200)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1116 | child->test_properties()->transform = child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1117 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1118 | grand_child->test_properties()->transform = grand_child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1119 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1120 | grand_child->test_properties()->should_flatten_transform = false; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1121 | grand_child->SetDrawsContent(true); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1122 | float device_scale_factor = 1.f; |
| 1123 | float page_scale_factor = 1.f; |
| 1124 | LayerImpl* page_scale_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 1125 | LayerImpl* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 1126 | LayerImpl* outer_viewport_scroll_layer = nullptr; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1127 | // Visible rects computed by combining clips in target space and root space |
| 1128 | // don't match because of rotation transforms. So, we skip |
| 1129 | // verify_visible_rect_calculations. |
| 1130 | bool skip_verify_visible_rect_calculations = true; |
| 1131 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 1132 | page_scale_layer, inner_viewport_scroll_layer, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 1133 | outer_viewport_scroll_layer, |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1134 | skip_verify_visible_rect_calculations); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1135 | |
| 1136 | // Mapping grand_child's bounds to target space produces a non-empty rect |
| 1137 | // that is fully contained within the target's bounds, so grand_child should |
| 1138 | // be considered fully visible. |
| 1139 | EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1140 | grand_child->visible_layer_rect()); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1141 | } |
| 1142 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1143 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1144 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1145 | // skipping a necessary translation. Without that translation, the coordinate |
| 1146 | // space of the layer's draw transform is incorrect. |
| 1147 | // |
| 1148 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1149 | // but if that layer becomes a render surface, then its draw transform is |
| 1150 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1151 | // incorrectly as a result. |
| 1152 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1153 | LayerImpl* root = root_layer_for_testing(); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1154 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1155 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1156 | grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1157 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1158 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1159 | // The child height is zero, but has non-zero width that should be accounted |
| 1160 | // for while computing draw transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1161 | child->SetBounds(gfx::Size(10, 0)); |
| 1162 | child->test_properties()->force_render_surface = true; |
| 1163 | grand_child->SetBounds(gfx::Size(10, 10)); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1164 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1165 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1166 | ASSERT_TRUE(child->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1167 | // This is the real test, the rest are sanity checks. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1168 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1169 | child->render_surface()->draw_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1170 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1171 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1172 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1173 | } |
| 1174 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1175 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1176 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1177 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 1178 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 1179 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1180 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1181 | gfx::Transform translate; |
| 1182 | translate.Translate3d(5, 5, 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1183 | |
| 1184 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1185 | render_surface->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1186 | render_surface->SetBounds(gfx::Size(100, 100)); |
| 1187 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1188 | child->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1189 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1190 | grand_child->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1191 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1192 | grand_child->SetDrawsContent(true); |
| 1193 | |
| 1194 | // render_surface will have a sublayer scale because of device scale factor. |
| 1195 | float device_scale_factor = 2.0f; |
| 1196 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1197 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1198 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1199 | inputs.device_scale_factor = device_scale_factor; |
| 1200 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1201 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1202 | |
| 1203 | // Between grand_child and render_surface, we translate by (10, 10) and scale |
| 1204 | // by a factor of 2. |
| 1205 | gfx::Vector2dF expected_translation(20.0f, 20.0f); |
| 1206 | EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(), |
| 1207 | expected_translation); |
| 1208 | } |
| 1209 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1210 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1211 | // Transformations applied at the root of the tree should be forwarded |
| 1212 | // to child layers instead of applied to the root RenderSurface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1213 | LayerImpl* root = root_layer_for_testing(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1214 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1215 | |
| 1216 | root->SetDrawsContent(true); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1217 | root->SetBounds(gfx::Size(100, 100)); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1218 | child->SetDrawsContent(true); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1219 | child->SetScrollClipLayer(root->id()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1220 | child->SetBounds(gfx::Size(100, 100)); |
| 1221 | child->SetMasksToBounds(true); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1222 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1223 | gfx::Transform translate; |
| 1224 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1225 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1226 | LayerImplList render_surface_layer_list_impl; |
| 1227 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1228 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1229 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1230 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1231 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1232 | translate, root->draw_properties().target_space_transform); |
| 1233 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1234 | translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1235 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1236 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1237 | EXPECT_TRANSFORMATION_MATRIX_EQ(translate, child->ScreenSpaceTransform()); |
| 1238 | EXPECT_EQ(gfx::Rect(50, 50, 100, 100), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1239 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1240 | |
| 1241 | gfx::Transform scale; |
| 1242 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1243 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1244 | LayerImplList render_surface_layer_list_impl; |
| 1245 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1246 | root, root->bounds(), scale, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1247 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1248 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1249 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1250 | scale, root->draw_properties().target_space_transform); |
| 1251 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1252 | scale, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1253 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1254 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1255 | EXPECT_TRANSFORMATION_MATRIX_EQ(scale, child->ScreenSpaceTransform()); |
| 1256 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1257 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1258 | |
| 1259 | gfx::Transform rotate; |
| 1260 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1261 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1262 | LayerImplList render_surface_layer_list_impl; |
| 1263 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1264 | root, root->bounds(), rotate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1265 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1266 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1267 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1268 | rotate, root->draw_properties().target_space_transform); |
| 1269 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1270 | rotate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1271 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1272 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1273 | EXPECT_TRANSFORMATION_MATRIX_EQ(rotate, child->ScreenSpaceTransform()); |
| 1274 | EXPECT_EQ(gfx::Rect(-4, 0, 104, 104), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1275 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1276 | |
| 1277 | gfx::Transform composite; |
| 1278 | composite.ConcatTransform(translate); |
| 1279 | composite.ConcatTransform(scale); |
| 1280 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1281 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1282 | LayerImplList render_surface_layer_list_impl; |
| 1283 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1284 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1285 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1286 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1287 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1288 | composite, root->draw_properties().target_space_transform); |
| 1289 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1290 | composite, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1291 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1292 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1293 | EXPECT_TRANSFORMATION_MATRIX_EQ(composite, child->ScreenSpaceTransform()); |
| 1294 | EXPECT_EQ(gfx::Rect(89, 103, 208, 208), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1295 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1296 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1297 | // Verify it composes correctly with device scale. |
| 1298 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1299 | |
| 1300 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1301 | LayerImplList render_surface_layer_list_impl; |
| 1302 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1303 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1304 | inputs.device_scale_factor = device_scale_factor; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1305 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1306 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1307 | gfx::Transform device_scaled_translate = translate; |
jaydasika | 18ea272 | 2016-10-27 23:47:10 | [diff] [blame] | 1308 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1309 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1310 | device_scaled_translate, |
| 1311 | root->draw_properties().target_space_transform); |
| 1312 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1313 | device_scaled_translate, |
| 1314 | child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1315 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1316 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1317 | EXPECT_TRANSFORMATION_MATRIX_EQ(device_scaled_translate, |
| 1318 | child->ScreenSpaceTransform()); |
| 1319 | EXPECT_EQ(gfx::Rect(50, 50, 150, 150), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1320 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1321 | |
| 1322 | // Verify it composes correctly with page scale. |
| 1323 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1324 | |
| 1325 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1326 | LayerImplList render_surface_layer_list_impl; |
| 1327 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1328 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1329 | inputs.page_scale_factor = page_scale_factor; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1330 | inputs.page_scale_layer = root; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1331 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1332 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1333 | gfx::Transform page_scaled_translate = translate; |
jaydasika | 18ea272 | 2016-10-27 23:47:10 | [diff] [blame] | 1334 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1335 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1336 | page_scaled_translate, root->draw_properties().target_space_transform); |
| 1337 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1338 | page_scaled_translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1339 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1340 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1341 | EXPECT_TRANSFORMATION_MATRIX_EQ(page_scaled_translate, |
| 1342 | child->ScreenSpaceTransform()); |
| 1343 | EXPECT_EQ(gfx::Rect(50, 50, 200, 200), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1344 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1345 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1346 | // Verify that it composes correctly with transforms directly on root layer. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1347 | root->test_properties()->transform = composite; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1348 | |
| 1349 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1350 | LayerImplList render_surface_layer_list_impl; |
| 1351 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1352 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1353 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1354 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1355 | gfx::Transform compositeSquared = composite; |
| 1356 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1357 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1358 | compositeSquared, root->draw_properties().target_space_transform); |
| 1359 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1360 | compositeSquared, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1361 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1362 | root->render_surface()->draw_transform()); |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 1363 | EXPECT_TRANSFORMATION_MATRIX_EQ(compositeSquared, |
| 1364 | child->ScreenSpaceTransform()); |
| 1365 | EXPECT_EQ(gfx::Rect(254, 316, 428, 428), child->clip_rect()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1366 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1367 | } |
| 1368 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1369 | TEST_F(LayerTreeHostCommonTest, |
| 1370 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1371 | LayerImpl* root = root_layer_for_testing(); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1372 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1373 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1374 | |
| 1375 | root->SetBounds(gfx::Size(10, 10)); |
| 1376 | root->SetMasksToBounds(true); |
| 1377 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1378 | render_surface1->test_properties()->force_render_surface = true; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1379 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1380 | child->SetPosition(gfx::PointF(30.f, 30.f)); |
| 1381 | child->SetBounds(gfx::Size(10, 10)); |
| 1382 | ExecuteCalculateDrawProperties(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1383 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1384 | // 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] | 1385 | // the intermediate render surface should not be listed here, even if it was |
| 1386 | // forced to be created. Render surfaces without children or visible content |
| 1387 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1388 | // of size 0). |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1389 | ASSERT_TRUE(root->render_surface()); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1390 | EXPECT_EQ(1U, render_surface_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1391 | } |
| 1392 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1393 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1394 | LayerImpl* root = root_layer_for_testing(); |
| 1395 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1396 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1397 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1398 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1399 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1400 | render_surface1->test_properties()->opacity = 0.f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1401 | child->SetBounds(gfx::Size(10, 10)); |
| 1402 | child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1403 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1404 | LayerImplList render_surface_layer_list; |
| 1405 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1406 | root, root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1407 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1408 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1409 | |
| 1410 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1411 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1412 | // have been extended by the children. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1413 | ASSERT_TRUE(root->render_surface()); |
| 1414 | EXPECT_EQ(0U, root->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1415 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1416 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 1417 | EXPECT_EQ(gfx::Rect(), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1418 | } |
| 1419 | |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1420 | TEST_F(LayerTreeHostCommonTest, |
| 1421 | RenderSurfaceListForTransparentChildWithBackgroundFilter) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1422 | LayerImpl* root = root_layer_for_testing(); |
| 1423 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1424 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1425 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1426 | root->SetBounds(gfx::Size(10, 10)); |
| 1427 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1428 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1429 | render_surface1->test_properties()->opacity = 0.f; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 1430 | render_surface1->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1431 | FilterOperations filters; |
| 1432 | filters.Append(FilterOperation::CreateBlurFilter(1.5f)); |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 1433 | render_surface1->test_properties()->background_filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1434 | child->SetBounds(gfx::Size(10, 10)); |
| 1435 | child->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1436 | |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1437 | { |
| 1438 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1439 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1440 | root, root->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1441 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1442 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1443 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1444 | } |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1445 | // The layer is fully transparent, but has a background filter, so it |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1446 | // shouldn't be skipped and should be drawn. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1447 | ASSERT_TRUE(root->render_surface()); |
| 1448 | EXPECT_EQ(1U, root->render_surface()->layer_list().size()); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1449 | EXPECT_EQ(gfx::RectF(0, 0, 10, 10), |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1450 | root->render_surface()->DrawableContentRect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1451 | EffectTree& effect_tree = |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1452 | root->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1453 | EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1454 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1455 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1456 | // When root is transparent, the layer should not be drawn. |
jaydasika | 898b2f1 | 2016-08-20 04:22:09 | [diff] [blame] | 1457 | effect_tree.OnOpacityAnimated(0.f, root->effect_tree_index(), |
| 1458 | root->layer_tree_impl()); |
| 1459 | effect_tree.OnOpacityAnimated(1.f, render_surface1->effect_tree_index(), |
| 1460 | root->layer_tree_impl()); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1461 | render_surface1->set_visible_layer_rect(gfx::Rect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1462 | { |
| 1463 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1464 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1465 | root, root->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1466 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1467 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1471 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1472 | EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect()); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1473 | } |
| 1474 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1475 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1476 | LayerImpl* root = root_layer_for_testing(); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1477 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1478 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1479 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1480 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1481 | gfx::Transform scale_matrix; |
| 1482 | scale_matrix.Scale(2.0f, 2.0f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1483 | |
| 1484 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1485 | parent->test_properties()->transform = scale_matrix; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1486 | FilterOperations filters; |
| 1487 | filters.Append(FilterOperation::CreateBlurFilter(10.0f)); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1488 | parent->test_properties()->filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1489 | parent->test_properties()->force_render_surface = true; |
| 1490 | child1->SetBounds(gfx::Size(25, 25)); |
| 1491 | child1->SetDrawsContent(true); |
| 1492 | child1->test_properties()->force_render_surface = true; |
| 1493 | child2->SetPosition(gfx::PointF(25, 25)); |
| 1494 | child2->SetBounds(gfx::Size(25, 25)); |
| 1495 | child2->SetDrawsContent(true); |
| 1496 | child2->test_properties()->force_render_surface = true; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1497 | |
| 1498 | LayerImplList render_surface_layer_list; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1499 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1500 | root, root->bounds(), &render_surface_layer_list); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1501 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1502 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1503 | |
| 1504 | ASSERT_TRUE(parent->render_surface()); |
| 1505 | EXPECT_EQ(2U, parent->render_surface()->layer_list().size()); |
| 1506 | EXPECT_EQ(4U, render_surface_layer_list.size()); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1507 | |
| 1508 | // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the |
| 1509 | // blur (-30,-30 110x110), and then scaled by the scale matrix |
| 1510 | // (-60,-60 220x220). |
| 1511 | EXPECT_EQ(gfx::RectF(-60, -60, 220, 220), |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1512 | parent->render_surface()->DrawableContentRect()); |
| 1513 | } |
| 1514 | |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1515 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1516 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1517 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1518 | |
| 1519 | root->SetBounds(gfx::Size(100, 100)); |
| 1520 | child->SetBounds(gfx::Size(25, 25)); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1521 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1522 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1523 | FilterOperations filters; |
| 1524 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1525 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1526 | child->test_properties()->filters = filters; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1527 | ExecuteCalculateDrawProperties(root); |
| 1528 | |
| 1529 | // The render surface's size should be unaffected by the offset image filter; |
| 1530 | // it need only have a drawable content rect large enough to contain the |
| 1531 | // contents (at the new offset). |
| 1532 | ASSERT_TRUE(child->render_surface()); |
| 1533 | EXPECT_EQ(gfx::RectF(50, 50, 25, 25), |
| 1534 | child->render_surface()->DrawableContentRect()); |
| 1535 | } |
| 1536 | |
| 1537 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) { |
| 1538 | const float device_scale_factor = 2.0f; |
| 1539 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1540 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1541 | LayerImpl* child = AddChild<LayerImpl>(root); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1542 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1543 | root->SetBounds(gfx::Size(100, 100)); |
| 1544 | child->SetBounds(gfx::Size(25, 25)); |
| 1545 | child->SetDrawsContent(true); |
| 1546 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1547 | |
| 1548 | FilterOperations filters; |
| 1549 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1550 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1551 | child->test_properties()->filters = filters; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1552 | |
| 1553 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 1554 | |
| 1555 | // The render surface's size should be unaffected by the offset image filter; |
| 1556 | // it need only have a drawable content rect large enough to contain the |
| 1557 | // contents (at the new offset). All coordinates should be scaled by 2, |
| 1558 | // corresponding to the device scale factor. |
| 1559 | ASSERT_TRUE(child->render_surface()); |
| 1560 | EXPECT_EQ(gfx::RectF(100, 100, 50, 50), |
| 1561 | child->render_surface()->DrawableContentRect()); |
| 1562 | } |
| 1563 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1564 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1565 | LayerImpl* root = root_layer_for_testing(); |
| 1566 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1567 | |
| 1568 | root->SetBounds(gfx::Size(10, 10)); |
| 1569 | child->SetBounds(gfx::Size(10, 10)); |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1570 | child->SetDrawsContent(true); |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 1571 | child->test_properties()->blend_mode = SkBlendMode::kMultiply; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1572 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1573 | child->test_properties()->force_render_surface = true; |
| 1574 | ExecuteCalculateDrawProperties(root); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1575 | |
| 1576 | // Since the child layer has a blend mode other than normal, it should get |
| 1577 | // its own render surface. Also, layer's draw_properties should contain the |
| 1578 | // default blend mode, since the render surface becomes responsible for |
| 1579 | // applying the blend mode. |
| 1580 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1581 | EXPECT_EQ(1.0f, child->draw_opacity()); |
| 1582 | EXPECT_EQ(0.5f, child->render_surface()->draw_opacity()); |
reed | cc9c70f | 2016-11-22 04:26:01 | [diff] [blame] | 1583 | EXPECT_EQ(SkBlendMode::kSrcOver, child->draw_blend_mode()); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1584 | } |
| 1585 | |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1586 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1587 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1588 | LayerImpl* surface1 = AddChildToRoot<LayerImpl>(); |
| 1589 | LayerImpl* not_surface = AddChild<LayerImpl>(surface1); |
| 1590 | LayerImpl* surface2 = AddChild<LayerImpl>(not_surface); |
| 1591 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1592 | root->SetBounds(gfx::Size(10, 10)); |
| 1593 | surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1594 | surface1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1595 | surface1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1596 | surface1->test_properties()->force_render_surface = true; |
| 1597 | not_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1598 | not_surface->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1599 | surface2->SetBounds(gfx::Size(10, 10)); |
| 1600 | surface2->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1601 | surface2->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1602 | surface2->test_properties()->force_render_surface = true; |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1603 | ExecuteCalculateDrawProperties(root); |
| 1604 | |
| 1605 | ASSERT_TRUE(surface1->render_surface()); |
| 1606 | ASSERT_FALSE(not_surface->render_surface()); |
| 1607 | ASSERT_TRUE(surface2->render_surface()); |
| 1608 | EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); |
| 1609 | // surface2's draw opacity should include the opacity of not-surface and |
| 1610 | // itself, but not the opacity of surface1. |
| 1611 | EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); |
| 1612 | } |
| 1613 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1614 | TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) { |
| 1615 | // Tests that when separate surfaces are disabled, a layer's draw opacity is |
| 1616 | // the product of all ancestor layer opacties and the layer's own opacity. |
| 1617 | // (Rendering will still be incorrect in situations where we really do need |
| 1618 | // surfaces to apply opacity, such as when we have overlapping layers with an |
| 1619 | // ancestor whose opacity is <1.) |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1620 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1621 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1622 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1623 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1624 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1625 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1626 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1627 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1628 | root->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1629 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1630 | parent->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1631 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1632 | child1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1633 | child1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1634 | child1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1635 | child1->test_properties()->force_render_surface = true; |
| 1636 | child2->SetBounds(gfx::Size(100, 100)); |
| 1637 | child2->SetDrawsContent(true); |
| 1638 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 1639 | grand_child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1640 | grand_child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1641 | grand_child->test_properties()->force_render_surface = true; |
| 1642 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
| 1643 | leaf_node1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1644 | leaf_node1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1645 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
| 1646 | leaf_node2->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1647 | leaf_node2->test_properties()->opacity = 0.5f; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1648 | |
| 1649 | // With surfaces enabled, each layer's draw opacity is the product of layer |
| 1650 | // opacities on the path from the layer to its render target, not including |
| 1651 | // the opacity of the layer that owns the target surface (since that opacity |
| 1652 | // is applied by the surface). |
| 1653 | ExecuteCalculateDrawProperties(root); |
| 1654 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1655 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1656 | EXPECT_EQ(1.f, child1->draw_opacity()); |
| 1657 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1658 | EXPECT_EQ(1.f, grand_child->draw_opacity()); |
| 1659 | EXPECT_EQ(0.5f, leaf_node1->draw_opacity()); |
| 1660 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1661 | |
| 1662 | // With surfaces disabled, each layer's draw opacity is the product of layer |
| 1663 | // opacities on the path from the layer to the root. |
| 1664 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1665 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1666 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1667 | EXPECT_EQ(0.5f, child1->draw_opacity()); |
| 1668 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1669 | EXPECT_EQ(0.25f, grand_child->draw_opacity()); |
| 1670 | EXPECT_EQ(0.125f, leaf_node1->draw_opacity()); |
| 1671 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1672 | } |
| 1673 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1674 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1675 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1676 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1677 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1678 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1679 | root->SetBounds(gfx::Size(10, 10)); |
| 1680 | render_surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1681 | render_surface1->test_properties()->force_render_surface = true; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1682 | child->SetBounds(gfx::Size(10, 10)); |
| 1683 | child->SetDrawsContent(true); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1684 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1685 | { |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1686 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1687 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1688 | // The root layer always creates a render surface |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1689 | EXPECT_TRUE(root->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1690 | EXPECT_TRUE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1691 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1692 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1693 | { |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1694 | render_surface1->test_properties()->force_render_surface = false; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1695 | render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1696 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1697 | EXPECT_TRUE(root->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1698 | EXPECT_FALSE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1699 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1700 | } |
| 1701 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1702 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1703 | // Render surfaces act as a flattening point for their subtree, so should |
| 1704 | // always flatten the target-to-screen space transform seen by descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1705 | LayerImpl* root = root_layer_for_testing(); |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1706 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1707 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1708 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1709 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1710 | gfx::Transform rotation_about_y_axis; |
| 1711 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1712 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1713 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1714 | parent->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1715 | parent->SetBounds(gfx::Size(10, 10)); |
| 1716 | parent->test_properties()->force_render_surface = true; |
| 1717 | child->SetBounds(gfx::Size(10, 10)); |
| 1718 | child->SetDrawsContent(true); |
| 1719 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1720 | grand_child->SetDrawsContent(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1721 | grand_child->test_properties()->should_flatten_transform = false; |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1722 | ExecuteCalculateDrawProperties(root); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1723 | |
| 1724 | EXPECT_TRUE(parent->render_surface()); |
| 1725 | EXPECT_FALSE(child->render_surface()); |
| 1726 | EXPECT_FALSE(grand_child->render_surface()); |
| 1727 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1728 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1729 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1730 | grand_child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1731 | |
| 1732 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1733 | // have been flattened at their render target. In particular, the fact that |
| 1734 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1735 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1736 | flattened_rotation_about_y.FlattenTo2d(); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1737 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1738 | child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1739 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1740 | grand_child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1741 | } |
| 1742 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1743 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1744 | // The entire subtree of layers that are outside the clip rect should be |
| 1745 | // culled away, and should not affect the render_surface_layer_list. |
| 1746 | // |
| 1747 | // The test tree is set up as follows: |
| 1748 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1749 | // that have something to draw. |
| 1750 | // - parent is a large container layer. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1751 | // - child has MasksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1752 | // - grand_child is positioned outside of the child's bounds |
| 1753 | // - great_grand_child is also kept outside child's bounds. |
| 1754 | // |
| 1755 | // In this configuration, grand_child and great_grand_child are completely |
| 1756 | // outside the clip rect, and they should never get scheduled on the list of |
| 1757 | // render surfaces. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1758 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1759 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1760 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1761 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1762 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1763 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1764 | // leaf_node1 ensures that root and child are kept on the |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1765 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1766 | // should be clipped. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1767 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(child); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1768 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1769 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1770 | root->SetBounds(gfx::Size(500, 500)); |
| 1771 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1772 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1773 | child->test_properties()->force_render_surface = true; |
| 1774 | grand_child->SetPosition(gfx::PointF(45.f, 45.f)); |
| 1775 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1776 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
| 1777 | leaf_node1->SetBounds(gfx::Size(500, 500)); |
| 1778 | leaf_node1->SetDrawsContent(true); |
| 1779 | leaf_node1->SetBounds(gfx::Size(20, 20)); |
| 1780 | leaf_node2->SetDrawsContent(true); |
| 1781 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1782 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1783 | ASSERT_EQ(2U, render_surface_layer_list_impl()->size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1784 | EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id()); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1785 | EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1786 | } |
| 1787 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1788 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1789 | // 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] | 1790 | // of the surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1791 | |
| 1792 | // The test tree is set up as follows: |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1793 | // - root is a container layer that masksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1794 | // - 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] | 1795 | // the root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1796 | // - grand_child is a render surface, and the only visible content in child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1797 | // It is positioned outside of the clip rect from root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1798 | |
| 1799 | // In this configuration, grand_child should be outside the clipped |
| 1800 | // content rect of the child, making grand_child not appear in the |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1801 | // render_surface_layer_list. |
| 1802 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1803 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1804 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1805 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1806 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1807 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1808 | root->SetMasksToBounds(true); |
| 1809 | root->SetBounds(gfx::Size(100, 100)); |
| 1810 | child->SetBounds(gfx::Size(20, 20)); |
| 1811 | child->test_properties()->force_render_surface = true; |
| 1812 | grand_child->SetPosition(gfx::PointF(200.f, 200.f)); |
| 1813 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1814 | grand_child->test_properties()->force_render_surface = true; |
| 1815 | leaf_node->SetBounds(gfx::Size(10, 10)); |
| 1816 | leaf_node->SetDrawsContent(true); |
| 1817 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1818 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1819 | // We should cull child and grand_child from the |
| 1820 | // render_surface_layer_list. |
| 1821 | ASSERT_EQ(1U, render_surface_layer_list_impl()->size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1822 | EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1823 | } |
| 1824 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1825 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) { |
| 1826 | // Tests that LayerImpl's IsClipped() property is set to true when: |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1827 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1828 | // - the layer is clipped by an ancestor that contributes to the same |
| 1829 | // render target, |
| 1830 | // - a surface is clipped by an ancestor that contributes to the same |
| 1831 | // render target. |
| 1832 | // |
| 1833 | // In particular, for a layer that owns a render surface: |
| 1834 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1835 | // pass that clipped status to the layer itself. |
| 1836 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1837 | // and propagates the clip to the subtree. |
| 1838 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1839 | LayerImpl* root = root_layer_for_testing(); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1840 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1841 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1842 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1843 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1844 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1845 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1846 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1847 | root->SetBounds(gfx::Size(100, 100)); |
| 1848 | parent->SetBounds(gfx::Size(100, 100)); |
| 1849 | parent->SetDrawsContent(true); |
| 1850 | child1->SetBounds(gfx::Size(100, 100)); |
| 1851 | child1->SetDrawsContent(true); |
| 1852 | child2->SetBounds(gfx::Size(100, 100)); |
| 1853 | child2->SetDrawsContent(true); |
| 1854 | child2->test_properties()->force_render_surface = true; |
| 1855 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 1856 | grand_child->SetDrawsContent(true); |
| 1857 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
| 1858 | leaf_node1->SetDrawsContent(true); |
| 1859 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
| 1860 | leaf_node2->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1861 | |
| 1862 | // Case 1: nothing is clipped except the root render surface. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1863 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1864 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1865 | ASSERT_TRUE(root->render_surface()); |
| 1866 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1867 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1868 | EXPECT_FALSE(root->is_clipped()); |
| 1869 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1870 | EXPECT_FALSE(parent->is_clipped()); |
| 1871 | EXPECT_FALSE(child1->is_clipped()); |
| 1872 | EXPECT_FALSE(child2->is_clipped()); |
| 1873 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1874 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1875 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1876 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1877 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1878 | // Case 2: parent MasksToBounds, so the parent, child1, and child2's |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1879 | // surface are clipped. But layers that contribute to child2's surface are |
| 1880 | // not clipped explicitly because child2's surface already accounts for |
| 1881 | // that clip. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1882 | parent->SetMasksToBounds(true); |
| 1883 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1884 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1885 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1886 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1887 | ASSERT_TRUE(root->render_surface()); |
| 1888 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1889 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1890 | EXPECT_FALSE(root->is_clipped()); |
| 1891 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1892 | EXPECT_TRUE(parent->is_clipped()); |
| 1893 | EXPECT_TRUE(child1->is_clipped()); |
| 1894 | EXPECT_FALSE(child2->is_clipped()); |
| 1895 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1896 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1897 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1898 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1899 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1900 | parent->SetMasksToBounds(false); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1901 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1902 | // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1903 | // child2's render surface is not clipped. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1904 | child2->SetMasksToBounds(true); |
| 1905 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1906 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1907 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1908 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1909 | ASSERT_TRUE(root->render_surface()); |
| 1910 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1911 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1912 | EXPECT_FALSE(root->is_clipped()); |
| 1913 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1914 | EXPECT_FALSE(parent->is_clipped()); |
| 1915 | EXPECT_FALSE(child1->is_clipped()); |
| 1916 | EXPECT_TRUE(child2->is_clipped()); |
| 1917 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1918 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1919 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1920 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1921 | } |
| 1922 | |
| 1923 | TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) { |
| 1924 | // Tests that when as long as layer is clipped, it's clip rect is set to |
| 1925 | // correct value. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1926 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1927 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1928 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1929 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1930 | root->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1931 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1932 | parent->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1933 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1934 | child->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1935 | child->SetDrawsContent(true); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1936 | child->SetMasksToBounds(true); |
| 1937 | |
| 1938 | ExecuteCalculateDrawProperties(root); |
| 1939 | |
| 1940 | EXPECT_FALSE(root->is_clipped()); |
| 1941 | EXPECT_FALSE(parent->is_clipped()); |
| 1942 | EXPECT_TRUE(child->is_clipped()); |
| 1943 | EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect()); |
| 1944 | |
| 1945 | parent->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1946 | child->SetPosition(gfx::PointF(100.f, 100.f)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1947 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1948 | |
| 1949 | ExecuteCalculateDrawProperties(root); |
| 1950 | |
| 1951 | EXPECT_FALSE(root->is_clipped()); |
| 1952 | EXPECT_TRUE(parent->is_clipped()); |
| 1953 | EXPECT_TRUE(child->is_clipped()); |
| 1954 | EXPECT_EQ(gfx::Rect(), child->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1955 | } |
| 1956 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1957 | TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { |
| 1958 | // Tests that when separate surfaces are disabled, is_clipped is true exactly |
| 1959 | // when a layer or its ancestor has a clip; in particular, if a layer |
| 1960 | // is_clipped, so is its entire subtree (since there are no render surfaces |
| 1961 | // that can reset is_clipped). |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1962 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1963 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1964 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1965 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1966 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1967 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1968 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1969 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1970 | root->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1971 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1972 | parent->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1973 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1974 | child1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1975 | child1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1976 | child1->test_properties()->force_render_surface = true; |
| 1977 | child2->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1978 | child2->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1979 | grand_child->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1980 | grand_child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1981 | grand_child->test_properties()->force_render_surface = true; |
| 1982 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1983 | leaf_node1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1984 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1985 | leaf_node2->SetDrawsContent(true); |
| 1986 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1987 | // Case 1: Nothing is clipped. In this case, is_clipped is always false, with |
| 1988 | // or without surfaces. |
| 1989 | ExecuteCalculateDrawProperties(root); |
| 1990 | EXPECT_FALSE(root->is_clipped()); |
| 1991 | EXPECT_FALSE(parent->is_clipped()); |
| 1992 | EXPECT_FALSE(child1->is_clipped()); |
| 1993 | EXPECT_FALSE(child2->is_clipped()); |
| 1994 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1995 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1996 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1997 | |
| 1998 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1999 | EXPECT_FALSE(root->is_clipped()); |
| 2000 | EXPECT_FALSE(parent->is_clipped()); |
| 2001 | EXPECT_FALSE(child1->is_clipped()); |
| 2002 | EXPECT_FALSE(child2->is_clipped()); |
| 2003 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2004 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2005 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2006 | |
| 2007 | // Case 2: The root is clipped. With surfaces, this only persists until the |
| 2008 | // next render surface. Without surfaces, the entire tree is clipped. |
| 2009 | root->SetMasksToBounds(true); |
| 2010 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2011 | ExecuteCalculateDrawProperties(root); |
| 2012 | EXPECT_TRUE(root->is_clipped()); |
| 2013 | EXPECT_TRUE(parent->is_clipped()); |
| 2014 | EXPECT_FALSE(child1->is_clipped()); |
| 2015 | EXPECT_TRUE(child2->is_clipped()); |
| 2016 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2017 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2018 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2019 | |
| 2020 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2021 | EXPECT_TRUE(root->is_clipped()); |
| 2022 | EXPECT_TRUE(parent->is_clipped()); |
| 2023 | EXPECT_TRUE(child1->is_clipped()); |
| 2024 | EXPECT_TRUE(child2->is_clipped()); |
| 2025 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2026 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2027 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2028 | |
| 2029 | root->SetMasksToBounds(false); |
| 2030 | |
| 2031 | // Case 3: The parent is clipped. Again, with surfaces, this only persists |
| 2032 | // until the next render surface. Without surfaces, parent's entire subtree is |
| 2033 | // clipped. |
| 2034 | parent->SetMasksToBounds(true); |
| 2035 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2036 | ExecuteCalculateDrawProperties(root); |
| 2037 | EXPECT_FALSE(root->is_clipped()); |
| 2038 | EXPECT_TRUE(parent->is_clipped()); |
| 2039 | EXPECT_FALSE(child1->is_clipped()); |
| 2040 | EXPECT_TRUE(child2->is_clipped()); |
| 2041 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2042 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2043 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2044 | |
| 2045 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2046 | EXPECT_FALSE(root->is_clipped()); |
| 2047 | EXPECT_TRUE(parent->is_clipped()); |
| 2048 | EXPECT_TRUE(child1->is_clipped()); |
| 2049 | EXPECT_TRUE(child2->is_clipped()); |
| 2050 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2051 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2052 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2053 | |
| 2054 | parent->SetMasksToBounds(false); |
| 2055 | |
| 2056 | // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it |
| 2057 | // has no non-surface children. Without surfaces, child1's entire subtree is |
| 2058 | // clipped. |
| 2059 | child1->SetMasksToBounds(true); |
| 2060 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2061 | ExecuteCalculateDrawProperties(root); |
| 2062 | EXPECT_FALSE(root->is_clipped()); |
| 2063 | EXPECT_FALSE(parent->is_clipped()); |
| 2064 | EXPECT_TRUE(child1->is_clipped()); |
| 2065 | EXPECT_FALSE(child2->is_clipped()); |
| 2066 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2067 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2068 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2069 | |
| 2070 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2071 | EXPECT_FALSE(root->is_clipped()); |
| 2072 | EXPECT_FALSE(parent->is_clipped()); |
| 2073 | EXPECT_TRUE(child1->is_clipped()); |
| 2074 | EXPECT_FALSE(child2->is_clipped()); |
| 2075 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2076 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2077 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2078 | |
| 2079 | child1->SetMasksToBounds(false); |
| 2080 | |
| 2081 | // Case 5: Only the leaf nodes are clipped. The behavior with and without |
| 2082 | // surfaces is the same. |
| 2083 | leaf_node1->SetMasksToBounds(true); |
| 2084 | leaf_node2->SetMasksToBounds(true); |
| 2085 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2086 | ExecuteCalculateDrawProperties(root); |
| 2087 | EXPECT_FALSE(root->is_clipped()); |
| 2088 | EXPECT_FALSE(parent->is_clipped()); |
| 2089 | EXPECT_FALSE(child1->is_clipped()); |
| 2090 | EXPECT_FALSE(child2->is_clipped()); |
| 2091 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2092 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2093 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2094 | |
| 2095 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2096 | EXPECT_FALSE(root->is_clipped()); |
| 2097 | EXPECT_FALSE(parent->is_clipped()); |
| 2098 | EXPECT_FALSE(child1->is_clipped()); |
| 2099 | EXPECT_FALSE(child2->is_clipped()); |
| 2100 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2101 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2102 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2103 | } |
| 2104 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 2105 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2106 | // Verify that layers get the appropriate DrawableContentRect when their |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2107 | // parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2108 | // |
| 2109 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 2110 | // be the layer rect expressed in target space. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2111 | // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2112 | // will be the intersection of layer bounds and the mask region. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2113 | // grand_child3 - partially clipped and MasksToBounds; the |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2114 | // DrawableContentRect will still be the intersection of layer bounds and |
| 2115 | // the mask region. |
| 2116 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 2117 | // be empty. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2118 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2119 | LayerImpl* parent = root_layer_for_testing(); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2120 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2121 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2122 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2123 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2124 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2125 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2126 | parent->SetBounds(gfx::Size(500, 500)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2127 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2128 | child->SetBounds(gfx::Size(20, 20)); |
| 2129 | child->test_properties()->force_render_surface = true; |
| 2130 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2131 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 2132 | grand_child1->SetDrawsContent(true); |
| 2133 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2134 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 2135 | grand_child2->SetDrawsContent(true); |
| 2136 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2137 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2138 | grand_child3->SetBounds(gfx::Size(10, 10)); |
| 2139 | grand_child3->SetDrawsContent(true); |
| 2140 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 2141 | grand_child4->SetBounds(gfx::Size(10, 10)); |
| 2142 | grand_child4->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2143 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2144 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2145 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2146 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2147 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2148 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2149 | } |
| 2150 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2151 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2152 | // Verify that render surfaces (and their layers) get the appropriate |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2153 | // clip rects when their parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2154 | // |
| 2155 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2156 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2157 | // They may still have a clip rect of their own layer bounds, however, if |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2158 | // MasksToBounds was true. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2159 | LayerImpl* parent = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2160 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2161 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2162 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2163 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2164 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2165 | // The leaf nodes ensure that these grand_children become render surfaces for |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2166 | // this test. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2167 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2168 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2169 | LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2170 | LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2171 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2172 | parent->SetBounds(gfx::Size(500, 500)); |
| 2173 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2174 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2175 | child->test_properties()->force_render_surface = true; |
| 2176 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2177 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 2178 | grand_child1->test_properties()->force_render_surface = true; |
| 2179 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2180 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 2181 | grand_child2->test_properties()->force_render_surface = true; |
| 2182 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2183 | grand_child3->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2184 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2185 | grand_child3->test_properties()->force_render_surface = true; |
| 2186 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 2187 | grand_child4->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2188 | grand_child4->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2189 | grand_child4->test_properties()->force_render_surface = true; |
| 2190 | leaf_node1->SetBounds(gfx::Size(10, 10)); |
| 2191 | leaf_node1->SetDrawsContent(true); |
| 2192 | leaf_node2->SetBounds(gfx::Size(10, 10)); |
| 2193 | leaf_node2->SetDrawsContent(true); |
| 2194 | leaf_node3->SetBounds(gfx::Size(10, 10)); |
| 2195 | leaf_node3->SetDrawsContent(true); |
| 2196 | leaf_node4->SetBounds(gfx::Size(10, 10)); |
| 2197 | leaf_node4->SetDrawsContent(true); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2198 | ExecuteCalculateDrawProperties(parent); |
| 2199 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2200 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2201 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2202 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2203 | |
| 2204 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2205 | // MasksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2206 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2207 | grand_child1->render_surface()->clip_rect()); |
| 2208 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2209 | grand_child2->render_surface()->clip_rect()); |
| 2210 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2211 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2212 | } |
| 2213 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2214 | TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { |
| 2215 | // Tests that when separate surfaces are disabled, a layer's clip_rect is the |
| 2216 | // intersection of all ancestor clips in screen space; in particular, if a |
| 2217 | // layer masks to bounds, it contributes to the clip_rect of all layers in its |
| 2218 | // subtree (since there are no render surfaces that can reset the clip_rect). |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2219 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2220 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2221 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 2222 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 2223 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 2224 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 2225 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 2226 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2227 | root->SetBounds(gfx::Size(100, 100)); |
| 2228 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2229 | parent->SetBounds(gfx::Size(400, 400)); |
| 2230 | child1->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2231 | child1->SetBounds(gfx::Size(800, 800)); |
| 2232 | child2->SetPosition(gfx::PointF(3.f, 3.f)); |
| 2233 | child2->SetBounds(gfx::Size(800, 800)); |
| 2234 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2235 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2236 | leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2237 | leaf_node1->SetBounds(gfx::Size(2000, 2000)); |
| 2238 | leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); |
| 2239 | leaf_node2->SetBounds(gfx::Size(2000, 2000)); |
| 2240 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2241 | root->SetDrawsContent(true); |
| 2242 | parent->SetDrawsContent(true); |
| 2243 | child1->SetDrawsContent(true); |
| 2244 | child2->SetDrawsContent(true); |
| 2245 | grand_child->SetDrawsContent(true); |
| 2246 | leaf_node1->SetDrawsContent(true); |
| 2247 | leaf_node2->SetDrawsContent(true); |
| 2248 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2249 | root->test_properties()->force_render_surface = true; |
| 2250 | child1->test_properties()->force_render_surface = true; |
| 2251 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2252 | |
| 2253 | // Case 1: Nothing is clipped. In this case, each layer's clip rect is its |
| 2254 | // bounds in target space. The only thing that changes when surfaces are |
| 2255 | // disabled is that target space is always screen space. |
| 2256 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2257 | EXPECT_TRUE(root->has_render_surface()); |
| 2258 | EXPECT_FALSE(parent->has_render_surface()); |
| 2259 | EXPECT_TRUE(child1->has_render_surface()); |
| 2260 | EXPECT_FALSE(child2->has_render_surface()); |
| 2261 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2262 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2263 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2264 | EXPECT_FALSE(root->is_clipped()); |
| 2265 | EXPECT_FALSE(parent->is_clipped()); |
| 2266 | EXPECT_FALSE(child1->is_clipped()); |
| 2267 | EXPECT_FALSE(child2->is_clipped()); |
| 2268 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2269 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2270 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2271 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2272 | EXPECT_FALSE(child1->render_surface()->is_clipped()); |
| 2273 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2274 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2275 | |
| 2276 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2277 | EXPECT_FALSE(root->is_clipped()); |
| 2278 | EXPECT_FALSE(parent->is_clipped()); |
| 2279 | EXPECT_FALSE(child1->is_clipped()); |
| 2280 | EXPECT_FALSE(child2->is_clipped()); |
| 2281 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2282 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2283 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2284 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2285 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2286 | |
| 2287 | // Case 2: The root is clipped. In this case, layers that draw into the root |
| 2288 | // render surface are clipped by the root's bounds. |
| 2289 | root->SetMasksToBounds(true); |
| 2290 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2291 | root->test_properties()->force_render_surface = true; |
| 2292 | child1->test_properties()->force_render_surface = true; |
| 2293 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2294 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2295 | EXPECT_TRUE(root->has_render_surface()); |
| 2296 | EXPECT_FALSE(parent->has_render_surface()); |
| 2297 | EXPECT_TRUE(child1->has_render_surface()); |
| 2298 | EXPECT_FALSE(child2->has_render_surface()); |
| 2299 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2300 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2301 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2302 | EXPECT_TRUE(root->is_clipped()); |
| 2303 | EXPECT_TRUE(parent->is_clipped()); |
| 2304 | EXPECT_FALSE(child1->is_clipped()); |
| 2305 | EXPECT_TRUE(child1->render_surface()->is_clipped()); |
| 2306 | EXPECT_TRUE(child2->is_clipped()); |
| 2307 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2308 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2309 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2310 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2311 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2312 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2313 | EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2314 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2315 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2316 | |
| 2317 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2318 | EXPECT_TRUE(root->is_clipped()); |
| 2319 | EXPECT_TRUE(parent->is_clipped()); |
| 2320 | EXPECT_TRUE(child1->is_clipped()); |
| 2321 | EXPECT_TRUE(child2->is_clipped()); |
| 2322 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2323 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2324 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2325 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2326 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
| 2327 | EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect()); |
| 2328 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
| 2329 | EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect()); |
| 2330 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect()); |
| 2331 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2332 | |
| 2333 | root->SetMasksToBounds(false); |
| 2334 | |
| 2335 | // Case 3: The parent and child1 are clipped. When surfaces are enabled, the |
| 2336 | // parent clip rect only contributes to the subtree rooted at child2, since |
| 2337 | // the subtree rooted at child1 renders into a separate surface. Similarly, |
| 2338 | // child1's clip rect doesn't contribute to its descendants, since its only |
| 2339 | // child is a render surface. However, without surfaces, these clip rects |
| 2340 | // contribute to all descendants. |
| 2341 | parent->SetMasksToBounds(true); |
| 2342 | child1->SetMasksToBounds(true); |
| 2343 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2344 | root->test_properties()->force_render_surface = true; |
| 2345 | child1->test_properties()->force_render_surface = true; |
| 2346 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2347 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2348 | EXPECT_TRUE(root->has_render_surface()); |
| 2349 | EXPECT_FALSE(parent->has_render_surface()); |
| 2350 | EXPECT_TRUE(child1->has_render_surface()); |
| 2351 | EXPECT_FALSE(child2->has_render_surface()); |
| 2352 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2353 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2354 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2355 | EXPECT_FALSE(root->is_clipped()); |
| 2356 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2357 | EXPECT_TRUE(parent->is_clipped()); |
| 2358 | EXPECT_TRUE(child1->is_clipped()); |
| 2359 | EXPECT_TRUE(child2->is_clipped()); |
| 2360 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2361 | EXPECT_TRUE(grand_child->render_surface()->is_clipped()); |
| 2362 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2363 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2364 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2365 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2366 | EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); |
| 2367 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2368 | EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2369 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2370 | |
| 2371 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2372 | EXPECT_FALSE(root->is_clipped()); |
| 2373 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2374 | EXPECT_TRUE(parent->is_clipped()); |
| 2375 | EXPECT_TRUE(child1->is_clipped()); |
| 2376 | EXPECT_TRUE(child2->is_clipped()); |
| 2377 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2378 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2379 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2380 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2381 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2382 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect()); |
| 2383 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
| 2384 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect()); |
| 2385 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect()); |
| 2386 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2387 | } |
| 2388 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2389 | TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2390 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2391 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2392 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2393 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2394 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2395 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2396 | root->SetBounds(gfx::Size(100, 100)); |
| 2397 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2398 | parent->SetBounds(gfx::Size(400, 400)); |
| 2399 | parent->SetMasksToBounds(true); |
| 2400 | child->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2401 | child->SetBounds(gfx::Size(800, 800)); |
| 2402 | child->SetMasksToBounds(true); |
| 2403 | child->test_properties()->force_render_surface = true; |
| 2404 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2405 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2406 | grand_child->test_properties()->force_render_surface = true; |
| 2407 | leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2408 | leaf_node->SetBounds(gfx::Size(2000, 2000)); |
| 2409 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2410 | root->SetDrawsContent(true); |
| 2411 | parent->SetDrawsContent(true); |
| 2412 | child->SetDrawsContent(true); |
| 2413 | grand_child->SetDrawsContent(true); |
| 2414 | leaf_node->SetDrawsContent(true); |
| 2415 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2416 | host_impl()->set_resourceless_software_draw_for_testing(); |
| 2417 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2418 | gfx::PointF test_point(90.f, 90.f); |
| 2419 | LayerImpl* result_layer = |
| 2420 | root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point); |
| 2421 | ASSERT_TRUE(result_layer); |
| 2422 | EXPECT_EQ(leaf_node, result_layer); |
| 2423 | } |
| 2424 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2425 | TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { |
| 2426 | // Tests that draw properties are computed correctly when we disable and then |
| 2427 | // re-enable separate surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2428 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2429 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2430 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2431 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2432 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2433 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2434 | root->SetBounds(gfx::Size(100, 100)); |
| 2435 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2436 | parent->SetBounds(gfx::Size(400, 400)); |
| 2437 | parent->SetMasksToBounds(true); |
| 2438 | child->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2439 | child->SetBounds(gfx::Size(800, 800)); |
| 2440 | child->SetMasksToBounds(true); |
| 2441 | child->test_properties()->force_render_surface = true; |
| 2442 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2443 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2444 | grand_child->test_properties()->force_render_surface = true; |
| 2445 | leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2446 | leaf_node->SetBounds(gfx::Size(2000, 2000)); |
| 2447 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2448 | root->SetDrawsContent(true); |
| 2449 | parent->SetDrawsContent(true); |
| 2450 | child->SetDrawsContent(true); |
| 2451 | grand_child->SetDrawsContent(true); |
| 2452 | leaf_node->SetDrawsContent(true); |
| 2453 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2454 | gfx::Transform expected_leaf_draw_transform_with_surfaces; |
| 2455 | expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); |
| 2456 | |
| 2457 | gfx::Transform expected_leaf_draw_transform_without_surfaces; |
| 2458 | expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); |
| 2459 | |
| 2460 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2461 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2462 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2463 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2464 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, |
| 2465 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2466 | |
| 2467 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2468 | EXPECT_TRUE(leaf_node->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2469 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); |
| 2470 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2471 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces, |
| 2472 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2473 | |
| 2474 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2475 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2476 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2477 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2478 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, |
| 2479 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2480 | } |
| 2481 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2482 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2483 | LayerImpl* root = root_layer_for_testing(); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2484 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 2485 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
| 2486 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 2487 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 2488 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
| 2489 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 2490 | LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
| 2491 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2492 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2493 | root->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2494 | render_surface1->SetDrawsContent(true); |
| 2495 | child_of_rs1->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2496 | grand_child_of_rs1->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2497 | render_surface2->SetDrawsContent(true); |
| 2498 | child_of_rs2->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2499 | grand_child_of_rs2->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2500 | child_of_root->SetDrawsContent(true); |
| 2501 | grand_child_of_root->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2502 | |
| 2503 | gfx::Transform layer_transform; |
| 2504 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2505 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2506 | root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2507 | root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2508 | root->SetBounds(gfx::Size(10, 10)); |
| 2509 | root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2510 | render_surface1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2511 | render_surface1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2512 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 2513 | render_surface1->test_properties()->transform_origin = |
| 2514 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2515 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2516 | render_surface2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2517 | render_surface2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2518 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 2519 | render_surface2->test_properties()->transform_origin = |
| 2520 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2521 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2522 | child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2523 | child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2524 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2525 | child_of_root->test_properties()->transform_origin = |
| 2526 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2527 | child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2528 | child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2529 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2530 | child_of_rs1->test_properties()->transform_origin = |
| 2531 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2532 | child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2533 | child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2534 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2535 | child_of_rs2->test_properties()->transform_origin = |
| 2536 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2537 | grand_child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2538 | grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2539 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2540 | grand_child_of_root->test_properties()->transform_origin = |
| 2541 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2542 | grand_child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2543 | grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2544 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2545 | grand_child_of_rs1->test_properties()->transform_origin = |
| 2546 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2547 | grand_child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2548 | grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2549 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2550 | grand_child_of_rs2->test_properties()->transform_origin = |
| 2551 | gfx::Point3F(0.25f, 0.f, 0.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2552 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2553 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2554 | SetElementIdsForTesting(); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 2555 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2556 | // Put an animated opacity on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2557 | AddOpacityTransitionToElementWithPlayer( |
| 2558 | render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2559 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2560 | // Also put an animated opacity on a layer without descendants. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2561 | AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(), |
| 2562 | timeline_impl(), 10.0, 1.f, 0.f, |
| 2563 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2564 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2565 | // Put a transform animation on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2566 | AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(), |
| 2567 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2568 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2569 | // Also put transform animations on grand_child_of_root, and |
| 2570 | // grand_child_of_rs2 |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2571 | AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(), |
| 2572 | timeline_impl(), 10.0, 30, 0); |
| 2573 | AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(), |
| 2574 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2575 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2576 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 2577 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2578 | |
| 2579 | // Only layers that are associated with render surfaces should have an actual |
| 2580 | // RenderSurface() value. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2581 | ASSERT_TRUE(root->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2582 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2583 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2584 | |
| 2585 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2586 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2587 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2588 | |
| 2589 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2590 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2591 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2592 | |
| 2593 | // Verify all render target accessors |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2594 | EXPECT_EQ(root->render_surface(), root->render_target()); |
| 2595 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 2596 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2597 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2598 | EXPECT_EQ(render_surface1->render_surface(), |
| 2599 | render_surface1->render_target()); |
| 2600 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 2601 | EXPECT_EQ(render_surface1->render_surface(), |
| 2602 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2603 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2604 | EXPECT_EQ(render_surface2->render_surface(), |
| 2605 | render_surface2->render_target()); |
| 2606 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 2607 | EXPECT_EQ(render_surface2->render_surface(), |
| 2608 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2609 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2610 | // Verify screen_space_transform_is_animating values |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2611 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2612 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2613 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2614 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2615 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2616 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2617 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2618 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2619 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2620 | |
| 2621 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2622 | // It is expected that we correctly set up transforms so that the y-component |
| 2623 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2624 | EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2625 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2626 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2627 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2628 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2629 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2630 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2631 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2632 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2633 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2634 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2635 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2636 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2637 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2638 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2639 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2640 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2641 | } |
| 2642 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2643 | TEST_F(LayerTreeHostCommonTest, LargeTransforms) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2644 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2645 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2646 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2647 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2648 | gfx::Transform large_transform; |
| 2649 | large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); |
| 2650 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2651 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2652 | child->test_properties()->transform = large_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2653 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2654 | grand_child->test_properties()->transform = large_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2655 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2656 | grand_child->SetDrawsContent(true); |
| 2657 | ExecuteCalculateDrawProperties(root); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2658 | |
| 2659 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
| 2660 | } |
| 2661 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2662 | TEST_F(LayerTreeHostCommonTest, |
| 2663 | ScreenSpaceTransformIsAnimatingWithDelayedAnimation) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2664 | LayerImpl* root = root_layer_for_testing(); |
| 2665 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2666 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2667 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 2668 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2669 | root->SetDrawsContent(true); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2670 | child->SetDrawsContent(true); |
| 2671 | grand_child->SetDrawsContent(true); |
| 2672 | great_grand_child->SetDrawsContent(true); |
| 2673 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2674 | root->SetBounds(gfx::Size(10, 10)); |
| 2675 | child->SetBounds(gfx::Size(10, 10)); |
| 2676 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2677 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2678 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2679 | SetElementIdsForTesting(); |
| 2680 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2681 | // Add a transform animation with a start delay to |grand_child|. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2682 | std::unique_ptr<Animation> animation = Animation::Create( |
| 2683 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1, |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 2684 | TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 2685 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2686 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2687 | AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(), |
| 2688 | std::move(animation)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2689 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2690 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2691 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2692 | EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 2693 | |
| 2694 | EXPECT_FALSE(grand_child->TransformIsAnimating()); |
| 2695 | EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation()); |
| 2696 | EXPECT_TRUE(grand_child->screen_space_transform_is_animating()); |
| 2697 | EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating()); |
| 2698 | } |
| 2699 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2700 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) { |
| 2701 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2702 | // correctly for identity transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2703 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2704 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2705 | gfx::Transform layer_to_surface_transform; |
| 2706 | |
| 2707 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2708 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2709 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2710 | gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30); |
| 2711 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2712 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2713 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2714 | EXPECT_EQ(expected_drawable_content_rect, |
| 2715 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2716 | |
| 2717 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2718 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2719 | expected_visible_layer_rect = gfx::Rect(); |
| 2720 | expected_drawable_content_rect = gfx::Rect(); |
| 2721 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2722 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2723 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2724 | EXPECT_EQ(expected_drawable_content_rect, |
| 2725 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2726 | |
| 2727 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2728 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2729 | expected_visible_layer_rect = gfx::Rect(20, 20); |
| 2730 | expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20); |
| 2731 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2732 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2733 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2734 | EXPECT_EQ(expected_drawable_content_rect, |
| 2735 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2736 | } |
| 2737 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2738 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) { |
| 2739 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2740 | // for rotations about z-axis (i.e. 2D rotations). |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2741 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2742 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2743 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2744 | gfx::Transform layer_to_surface_transform; |
| 2745 | |
| 2746 | // Case 1: Layer is contained within the surface. |
| 2747 | layer_to_surface_transform.MakeIdentity(); |
| 2748 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2749 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2750 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2751 | gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43); |
| 2752 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2753 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2754 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2755 | EXPECT_EQ(expected_drawable_content_rect, |
| 2756 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2757 | |
| 2758 | // Case 2: Layer is outside the surface rect. |
| 2759 | layer_to_surface_transform.MakeIdentity(); |
| 2760 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2761 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2762 | expected_visible_layer_rect = gfx::Rect(); |
| 2763 | expected_drawable_content_rect = gfx::Rect(); |
| 2764 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2765 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2766 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2767 | EXPECT_EQ(expected_drawable_content_rect, |
| 2768 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2769 | |
| 2770 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2771 | // the layer is oriented diagonally, with the left half outside of the render |
| 2772 | // surface. In this case, the g should still be the entire layer |
| 2773 | // (remember the g is computed in layer space); both the top-left |
| 2774 | // and bottom-right corners of the layer are still visible. |
| 2775 | layer_to_surface_transform.MakeIdentity(); |
| 2776 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2777 | expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2778 | expected_drawable_content_rect = gfx::Rect(22, 43); |
| 2779 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2780 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2781 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2782 | EXPECT_EQ(expected_drawable_content_rect, |
| 2783 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2784 | |
| 2785 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2786 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2787 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2788 | // surface overlaps the right side of the layer. The g should be |
| 2789 | // the layer's right half. |
| 2790 | layer_to_surface_transform.MakeIdentity(); |
| 2791 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2792 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2793 | // Right half of layer bounds. |
| 2794 | expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30); |
| 2795 | expected_drawable_content_rect = gfx::Rect(22, 22); |
| 2796 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2797 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2798 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2799 | EXPECT_EQ(expected_drawable_content_rect, |
| 2800 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2801 | } |
| 2802 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2803 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) { |
| 2804 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2805 | // for 3d transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2806 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2807 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2808 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2809 | gfx::Transform layer_to_surface_transform; |
| 2810 | |
| 2811 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2812 | // degrees, should be fully contained in the render surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2813 | // 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] | 2814 | layer_to_surface_transform.MakeIdentity(); |
| 2815 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2816 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2817 | gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100); |
| 2818 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2819 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2820 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2821 | EXPECT_EQ(expected_drawable_content_rect, |
| 2822 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2823 | |
| 2824 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2825 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2826 | // visible on the surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2827 | // 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] | 2828 | SkMScalar half_width_of_rotated_layer = |
| 2829 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2830 | layer_to_surface_transform.MakeIdentity(); |
| 2831 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2832 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2833 | // edge of the layer. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2834 | // Tight half of the layer. |
| 2835 | expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100); |
| 2836 | expected_drawable_content_rect = gfx::Rect(36, 100); |
| 2837 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2838 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2839 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2840 | EXPECT_EQ(expected_drawable_content_rect, |
| 2841 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2842 | } |
| 2843 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2844 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) { |
| 2845 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2846 | // when the layer has a perspective projection onto the target surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2847 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2848 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2849 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2850 | gfx::Transform layer_to_surface_transform; |
| 2851 | |
| 2852 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2853 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2854 | // its translated more than the perspective amount. |
| 2855 | layer_to_surface_transform.MakeIdentity(); |
| 2856 | |
| 2857 | // The following sequence of transforms applies the perspective about the |
| 2858 | // center of the surface. |
| 2859 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2860 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2861 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2862 | |
| 2863 | // This translate places the layer in front of the surface's projection plane. |
| 2864 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2865 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2866 | // Layer position is (-50, -50), visible rect in layer space is layer bounds |
| 2867 | // offset by layer position. |
| 2868 | gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150); |
| 2869 | gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38); |
| 2870 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2871 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2872 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2873 | EXPECT_EQ(expected_drawable_content_rect, |
| 2874 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2875 | |
| 2876 | // Case 2: same projection as before, except that the layer is also translated |
| 2877 | // to the side, so that only the right half of the layer should be visible. |
| 2878 | // |
| 2879 | // Explanation of expected result: The perspective ratio is (z distance |
| 2880 | // between layer and camera origin) / (z distance between projection plane and |
| 2881 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2882 | // move a layer by translating -25 units in projected surface units (so that |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2883 | // 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] | 2884 | // -25 == -100 in the layer's units. |
| 2885 | layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0); |
| 2886 | // Visible layer rect is moved by 100, and drawable content rect is in target |
| 2887 | // space and is moved by 25. |
| 2888 | expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150); |
| 2889 | expected_drawable_content_rect = gfx::Rect(13, 38); |
| 2890 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2891 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2892 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2893 | EXPECT_EQ(expected_drawable_content_rect, |
| 2894 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2895 | } |
| 2896 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2897 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2898 | DrawRectsFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2899 | // There is currently no explicit concept of an orthographic projection plane |
| 2900 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2901 | // are technically behind the surface in an orthographic world should not be |
| 2902 | // clipped when they are flattened to the surface. |
| 2903 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2904 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2905 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2906 | gfx::Transform layer_to_surface_transform; |
| 2907 | |
| 2908 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2909 | // at the center of the layer. |
| 2910 | layer_to_surface_transform.MakeIdentity(); |
| 2911 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2912 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2913 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2914 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2915 | // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface |
| 2916 | // space. |
| 2917 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2918 | gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100); |
| 2919 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2920 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2921 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2922 | EXPECT_EQ(expected_drawable_content_rect, |
| 2923 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2924 | } |
| 2925 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2926 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2927 | DrawRectsFor3dPerspectiveWhenClippedByW) { |
| 2928 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2929 | // when projecting a surface onto a layer, but the layer is partially behind |
| 2930 | // the camera (not just behind the projection plane). In this case, the |
| 2931 | // cartesian coordinates may seem to be valid, but actually they are not. The |
| 2932 | // visible rect needs to be properly clipped by the w = 0 plane in homogeneous |
| 2933 | // coordinates before converting to cartesian coordinates. The drawable |
| 2934 | // content rect would be entire surface rect because layer is rotated at the |
| 2935 | // camera position. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2936 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2937 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200); |
| 2938 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2939 | gfx::Transform layer_to_surface_transform; |
| 2940 | |
| 2941 | // The layer is positioned so that the right half of the layer should be in |
| 2942 | // front of the camera, while the other half is behind the surface's |
| 2943 | // projection plane. The following sequence of transforms applies the |
| 2944 | // perspective and rotation about the center of the layer. |
| 2945 | layer_to_surface_transform.MakeIdentity(); |
| 2946 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2947 | layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0); |
| 2948 | layer_to_surface_transform.RotateAboutYAxis(-45.0); |
| 2949 | layer_to_surface_transform.Translate(-10, -1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2950 | |
| 2951 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2952 | // transform, otherwise this code is not testing the intended scenario. |
| 2953 | bool clipped; |
| 2954 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2955 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2956 | &clipped); |
| 2957 | ASSERT_TRUE(clipped); |
| 2958 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2959 | gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1); |
| 2960 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 2961 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2962 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2963 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2964 | EXPECT_EQ(expected_drawable_content_rect, |
| 2965 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2966 | } |
| 2967 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2968 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2969 | // To determine visible rect in layer space, there needs to be an |
| 2970 | // un-projection from surface space to layer space. When the original |
| 2971 | // transform was a perspective projection that was clipped, it returns a rect |
| 2972 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2973 | // clipping again. |
| 2974 | |
| 2975 | // This sequence of transforms causes one corner of the layer to protrude |
| 2976 | // across the w = 0 plane, and should be clipped. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2977 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150); |
| 2978 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2979 | gfx::Transform layer_to_surface_transform; |
| 2980 | layer_to_surface_transform.MakeIdentity(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2981 | layer_to_surface_transform.Translate(10, 10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2982 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2983 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2984 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2985 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2986 | layer_to_surface_transform.Translate(-10, -10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2987 | |
| 2988 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2989 | // code is not testing the intended scenario. |
| 2990 | bool clipped; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2991 | gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
| 2992 | layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2993 | MathUtil::ProjectQuad( |
| 2994 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2995 | ASSERT_TRUE(clipped); |
| 2996 | |
| 2997 | // Only the corner of the layer is not visible on the surface because of being |
| 2998 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2999 | // rect is that the entire layer should still be considered visible. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3000 | gfx::Rect expected_visible_layer_rect = layer_content_rect; |
| 3001 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 3002 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 3003 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 3004 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 3005 | EXPECT_EQ(expected_drawable_content_rect, |
| 3006 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3007 | } |
| 3008 | |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3009 | TEST_F(LayerTreeHostCommonTest, |
| 3010 | VisibleRectsForPositionedRootLayerClippedByViewport) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3011 | LayerImpl* root = root_layer_for_testing(); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3012 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3013 | root->SetPosition(gfx::PointF(60, 70)); |
| 3014 | root->SetBounds(gfx::Size(100, 100)); |
| 3015 | root->SetDrawsContent(true); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3016 | ExecuteCalculateDrawProperties(root); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3017 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3018 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3019 | root->render_surface()->DrawableContentRect()); |
| 3020 | // In target space, not clipped. |
| 3021 | EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 3022 | // In layer space, clipped. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3023 | EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3024 | } |
| 3025 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3026 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3027 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3028 | LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3029 | LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3030 | LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3031 | |
| 3032 | root->SetBounds(gfx::Size(100, 100)); |
| 3033 | child1_layer->SetBounds(gfx::Size(50, 50)); |
| 3034 | child1_layer->SetDrawsContent(true); |
| 3035 | child2_layer->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3036 | child2_layer->SetBounds(gfx::Size(50, 50)); |
| 3037 | child2_layer->SetDrawsContent(true); |
| 3038 | child3_layer->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3039 | child3_layer->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3040 | child3_layer->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3041 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3042 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3043 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3044 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3045 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3046 | // Layers that do not draw content should have empty visible_layer_rects. |
| 3047 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3048 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3049 | // layer visible_layer_rects are clipped by their target surface. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3050 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); |
| 3051 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); |
| 3052 | EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3053 | |
| 3054 | // layer drawable_content_rects are not clipped. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3055 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect()); |
| 3056 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect()); |
| 3057 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3058 | } |
| 3059 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3060 | TEST_F(LayerTreeHostCommonTest, |
| 3061 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3062 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3063 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3064 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3065 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3066 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3067 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3068 | root->SetBounds(gfx::Size(100, 100)); |
| 3069 | child->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3070 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3071 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3072 | grand_child1->SetBounds(gfx::Size(50, 50)); |
| 3073 | grand_child1->SetDrawsContent(true); |
| 3074 | grand_child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3075 | grand_child2->SetBounds(gfx::Size(50, 50)); |
| 3076 | grand_child2->SetDrawsContent(true); |
| 3077 | grand_child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3078 | grand_child3->SetBounds(gfx::Size(50, 50)); |
| 3079 | grand_child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3080 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3081 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3082 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3083 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3084 | |
| 3085 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3086 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3087 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3088 | |
| 3089 | // All grandchild visible content rects should be clipped by child. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3090 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); |
| 3091 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); |
| 3092 | EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3093 | |
| 3094 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3095 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 3096 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3097 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 3098 | } |
| 3099 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3100 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3101 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3102 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 3103 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3104 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3105 | gfx::Transform child_scale_matrix; |
| 3106 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 3107 | gfx::Transform grand_child_scale_matrix; |
| 3108 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3109 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3110 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3111 | child->test_properties()->transform = child_scale_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3112 | child->SetBounds(gfx::Size(10, 10)); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3113 | child->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3114 | grand_child->test_properties()->transform = grand_child_scale_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3115 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3116 | grand_child->SetDrawsContent(true); |
| 3117 | ExecuteCalculateDrawProperties(root); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3118 | |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 3119 | // The visible rect is expanded to integer coordinates. |
| 3120 | EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3121 | } |
| 3122 | |
ajuma | e947a35 | 2017-01-10 19:17:49 | [diff] [blame] | 3123 | TEST_F(LayerTreeHostCommonTest, VisibleRectWithClippingAndFilters) { |
| 3124 | LayerImpl* root = root_layer_for_testing(); |
| 3125 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 3126 | LayerImpl* filter = AddChild<LayerImpl>(clip); |
| 3127 | LayerImpl* filter_child = AddChild<LayerImpl>(filter); |
| 3128 | |
| 3129 | root->SetBounds(gfx::Size(100, 100)); |
| 3130 | clip->SetBounds(gfx::Size(10, 10)); |
| 3131 | filter->test_properties()->force_render_surface = true; |
| 3132 | filter_child->SetBounds(gfx::Size(2000, 2000)); |
| 3133 | filter_child->SetPosition(gfx::PointF(-50, -50)); |
| 3134 | filter_child->SetDrawsContent(true); |
| 3135 | |
| 3136 | clip->SetMasksToBounds(true); |
| 3137 | |
| 3138 | ExecuteCalculateDrawProperties(root); |
| 3139 | EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect()); |
| 3140 | EXPECT_EQ(gfx::Rect(10, 10), filter->render_surface()->content_rect()); |
| 3141 | |
| 3142 | FilterOperations blur_filter; |
| 3143 | blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); |
| 3144 | filter->test_properties()->filters = blur_filter; |
| 3145 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3146 | |
| 3147 | ExecuteCalculateDrawProperties(root); |
| 3148 | |
| 3149 | EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect()); |
| 3150 | EXPECT_EQ(gfx::Rect(-12, -12, 34, 34), |
| 3151 | filter->render_surface()->content_rect()); |
| 3152 | |
| 3153 | gfx::Transform vertical_flip; |
| 3154 | vertical_flip.Scale(1, -1); |
| 3155 | sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter( |
| 3156 | vertical_flip.matrix(), kLow_SkFilterQuality, nullptr); |
| 3157 | FilterOperations reflection_filter; |
| 3158 | reflection_filter.Append( |
| 3159 | FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make( |
| 3160 | SkBlendMode::kSrcOver, std::move(flip_filter)))); |
| 3161 | filter->test_properties()->filters = reflection_filter; |
| 3162 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3163 | |
| 3164 | ExecuteCalculateDrawProperties(root); |
| 3165 | |
| 3166 | EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect()); |
| 3167 | EXPECT_EQ(gfx::Rect(0, -10, 10, 20), |
| 3168 | filter->render_surface()->content_rect()); |
| 3169 | } |
| 3170 | |
| 3171 | TEST_F(LayerTreeHostCommonTest, VisibleRectWithScalingClippingAndFilters) { |
| 3172 | LayerImpl* root = root_layer_for_testing(); |
| 3173 | LayerImpl* scale = AddChild<LayerImpl>(root); |
| 3174 | LayerImpl* clip = AddChild<LayerImpl>(scale); |
| 3175 | LayerImpl* filter = AddChild<LayerImpl>(clip); |
| 3176 | LayerImpl* filter_child = AddChild<LayerImpl>(filter); |
| 3177 | |
| 3178 | root->SetBounds(gfx::Size(100, 100)); |
| 3179 | clip->SetBounds(gfx::Size(10, 10)); |
| 3180 | filter->test_properties()->force_render_surface = true; |
| 3181 | filter_child->SetBounds(gfx::Size(2000, 2000)); |
| 3182 | filter_child->SetPosition(gfx::PointF(-50, -50)); |
| 3183 | filter_child->SetDrawsContent(true); |
| 3184 | |
| 3185 | clip->SetMasksToBounds(true); |
| 3186 | |
| 3187 | gfx::Transform scale_transform; |
| 3188 | scale_transform.Scale(3, 3); |
| 3189 | scale->test_properties()->transform = scale_transform; |
| 3190 | |
| 3191 | ExecuteCalculateDrawProperties(root); |
| 3192 | EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect()); |
| 3193 | EXPECT_EQ(gfx::Rect(30, 30), filter->render_surface()->content_rect()); |
| 3194 | |
| 3195 | FilterOperations blur_filter; |
| 3196 | blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); |
| 3197 | filter->test_properties()->filters = blur_filter; |
| 3198 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3199 | |
| 3200 | ExecuteCalculateDrawProperties(root); |
| 3201 | |
| 3202 | EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect()); |
| 3203 | EXPECT_EQ(gfx::Rect(-36, -36, 102, 102), |
| 3204 | filter->render_surface()->content_rect()); |
| 3205 | |
| 3206 | gfx::Transform vertical_flip; |
| 3207 | vertical_flip.Scale(1, -1); |
| 3208 | sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter( |
| 3209 | vertical_flip.matrix(), kLow_SkFilterQuality, nullptr); |
| 3210 | FilterOperations reflection_filter; |
| 3211 | reflection_filter.Append( |
| 3212 | FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make( |
| 3213 | SkBlendMode::kSrcOver, std::move(flip_filter)))); |
| 3214 | filter->test_properties()->filters = reflection_filter; |
| 3215 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3216 | |
| 3217 | ExecuteCalculateDrawProperties(root); |
| 3218 | |
| 3219 | EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect()); |
| 3220 | EXPECT_EQ(gfx::Rect(0, -30, 30, 60), |
| 3221 | filter->render_surface()->content_rect()); |
| 3222 | } |
| 3223 | |
| 3224 | TEST_F(LayerTreeHostCommonTest, ClipRectWithClipParentAndFilters) { |
| 3225 | LayerImpl* root = root_layer_for_testing(); |
| 3226 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 3227 | LayerImpl* filter = AddChild<LayerImpl>(clip); |
| 3228 | LayerImpl* filter_child_1 = AddChild<LayerImpl>(filter); |
| 3229 | LayerImpl* filter_child_2 = AddChild<LayerImpl>(filter); |
| 3230 | |
| 3231 | root->SetBounds(gfx::Size(100, 100)); |
| 3232 | clip->SetBounds(gfx::Size(10, 10)); |
| 3233 | filter->test_properties()->force_render_surface = true; |
| 3234 | |
| 3235 | filter_child_1->SetBounds(gfx::Size(20, 20)); |
| 3236 | filter_child_1->SetDrawsContent(true); |
| 3237 | filter_child_2->SetBounds(gfx::Size(20, 20)); |
| 3238 | filter_child_2->SetDrawsContent(true); |
| 3239 | |
| 3240 | root->SetMasksToBounds(true); |
| 3241 | clip->SetMasksToBounds(true); |
| 3242 | |
| 3243 | root->test_properties()->clip_children = |
| 3244 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3245 | root->test_properties()->clip_children->insert(filter_child_1); |
| 3246 | filter_child_1->test_properties()->clip_parent = root; |
| 3247 | |
| 3248 | ExecuteCalculateDrawProperties(root); |
| 3249 | EXPECT_TRUE(filter_child_1->is_clipped()); |
| 3250 | EXPECT_TRUE(filter_child_2->is_clipped()); |
| 3251 | EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect()); |
| 3252 | EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect()); |
| 3253 | |
| 3254 | FilterOperations blur_filter; |
| 3255 | blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); |
| 3256 | filter->test_properties()->filters = blur_filter; |
| 3257 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3258 | |
| 3259 | ExecuteCalculateDrawProperties(root); |
| 3260 | |
| 3261 | EXPECT_TRUE(filter_child_1->is_clipped()); |
| 3262 | EXPECT_TRUE(filter_child_2->is_clipped()); |
| 3263 | EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect()); |
| 3264 | EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect()); |
| 3265 | } |
| 3266 | |
| 3267 | TEST_F(LayerTreeHostCommonTest, ClipRectWithClippedDescendantOfFilter) { |
| 3268 | LayerImpl* root = root_layer_for_testing(); |
| 3269 | LayerImpl* filter = AddChild<LayerImpl>(root); |
| 3270 | LayerImpl* clip = AddChild<LayerImpl>(filter); |
| 3271 | LayerImpl* filter_grand_child = AddChild<LayerImpl>(clip); |
| 3272 | |
| 3273 | root->SetBounds(gfx::Size(100, 100)); |
| 3274 | filter->test_properties()->force_render_surface = true; |
| 3275 | |
| 3276 | clip->SetBounds(gfx::Size(10, 10)); |
| 3277 | clip->SetMasksToBounds(true); |
| 3278 | |
| 3279 | filter_grand_child->SetBounds(gfx::Size(20, 20)); |
| 3280 | filter_grand_child->SetDrawsContent(true); |
| 3281 | |
| 3282 | ExecuteCalculateDrawProperties(root); |
| 3283 | EXPECT_TRUE(filter_grand_child->is_clipped()); |
| 3284 | EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect()); |
| 3285 | |
| 3286 | FilterOperations blur_filter; |
| 3287 | blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f)); |
| 3288 | filter->test_properties()->filters = blur_filter; |
| 3289 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3290 | |
| 3291 | ExecuteCalculateDrawProperties(root); |
| 3292 | |
| 3293 | EXPECT_TRUE(filter_grand_child->is_clipped()); |
| 3294 | EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect()); |
| 3295 | } |
| 3296 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3297 | TEST_F(LayerTreeHostCommonTest, |
| 3298 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3299 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3300 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3301 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3302 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3303 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3304 | |
| 3305 | root->SetBounds(gfx::Size(100, 100)); |
| 3306 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3307 | render_surface->test_properties()->force_render_surface = true; |
| 3308 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3309 | child1->SetBounds(gfx::Size(50, 50)); |
| 3310 | child1->SetDrawsContent(true); |
| 3311 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3312 | child2->SetBounds(gfx::Size(50, 50)); |
| 3313 | child2->SetDrawsContent(true); |
| 3314 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3315 | child3->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3316 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3317 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3318 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3319 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3320 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3321 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3322 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3323 | |
| 3324 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3325 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3326 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3327 | |
| 3328 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 3329 | // regions of the subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3330 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3331 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3332 | |
| 3333 | // All layers that draw content into the unclipped surface are also unclipped. |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3334 | // Only the viewport clip should apply |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3335 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3336 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3337 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3338 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3339 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3340 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3341 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3342 | } |
| 3343 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3344 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3345 | DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3346 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3347 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 3348 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 3349 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 3350 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); |
| 3351 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); |
| 3352 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 3353 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 3354 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3355 | root->SetBounds(gfx::Size(100, 100)); |
| 3356 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 3357 | parent->SetBounds(gfx::Size(400, 400)); |
| 3358 | child1->SetPosition(gfx::PointF(4.f, 4.f)); |
| 3359 | child1->SetBounds(gfx::Size(800, 800)); |
| 3360 | child1->test_properties()->force_render_surface = true; |
| 3361 | child2->SetPosition(gfx::PointF(3.f, 3.f)); |
| 3362 | child2->SetBounds(gfx::Size(800, 800)); |
| 3363 | child2->test_properties()->force_render_surface = true; |
| 3364 | grand_child1->SetPosition(gfx::PointF(8.f, 8.f)); |
| 3365 | grand_child1->SetBounds(gfx::Size(1500, 1500)); |
| 3366 | grand_child2->SetPosition(gfx::PointF(7.f, 7.f)); |
| 3367 | grand_child2->SetBounds(gfx::Size(1500, 1500)); |
| 3368 | leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); |
| 3369 | leaf_node1->SetBounds(gfx::Size(2000, 2000)); |
| 3370 | leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); |
| 3371 | leaf_node2->SetBounds(gfx::Size(2000, 2000)); |
| 3372 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3373 | root->SetDrawsContent(true); |
| 3374 | parent->SetDrawsContent(true); |
| 3375 | child1->SetDrawsContent(true); |
| 3376 | child2->SetDrawsContent(true); |
| 3377 | grand_child1->SetDrawsContent(true); |
| 3378 | grand_child2->SetDrawsContent(true); |
| 3379 | leaf_node1->SetDrawsContent(true); |
| 3380 | leaf_node2->SetDrawsContent(true); |
| 3381 | |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3382 | // Case 1: No layers clip. Visible rects are clipped by the viewport. |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3383 | // Each layer's drawable content rect is its bounds in target space; the only |
| 3384 | // thing that changes with surfaces disabled is that target space is always |
| 3385 | // screen space. |
ajuma | 35b24f6 | 2017-01-27 21:23:09 | [diff] [blame] | 3386 | child1->test_properties()->force_render_surface = true; |
| 3387 | child2->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3388 | ExecuteCalculateDrawProperties(root); |
| 3389 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3390 | EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3391 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3392 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3393 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3394 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3395 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3396 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3397 | |
| 3398 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3399 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3400 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3401 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3402 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3403 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3404 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3405 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3406 | |
| 3407 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3408 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3409 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3410 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3411 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3412 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3413 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3414 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3415 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3416 | |
| 3417 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3418 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3419 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3420 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3421 | EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), |
| 3422 | grand_child1->drawable_content_rect()); |
| 3423 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3424 | grand_child2->drawable_content_rect()); |
| 3425 | EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3426 | EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3427 | |
| 3428 | // Case 2: The parent clips. In this case, neither surface is unclipped, so |
| 3429 | // all visible layer rects are clipped by the intersection of all ancestor |
| 3430 | // clips, whether or not surfaces are disabled. However, drawable content |
| 3431 | // rects are clipped only until the next render surface is reached, so |
| 3432 | // descendants of parent have their drawable content rects clipped only when |
| 3433 | // surfaces are disabled. |
| 3434 | parent->SetMasksToBounds(true); |
| 3435 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3436 | ExecuteCalculateDrawProperties(root); |
| 3437 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3438 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3439 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3440 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3441 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3442 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3443 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3444 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3445 | |
| 3446 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3447 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3448 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3449 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3450 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3451 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3452 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3453 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3454 | |
| 3455 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3456 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3457 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3458 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3459 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3460 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3461 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3462 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3463 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3464 | |
| 3465 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3466 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3467 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect()); |
| 3468 | EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect()); |
| 3469 | EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect()); |
| 3470 | EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect()); |
| 3471 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect()); |
| 3472 | EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect()); |
| 3473 | |
| 3474 | parent->SetMasksToBounds(false); |
| 3475 | |
| 3476 | // Case 3: child1 and grand_child2 clip. In this case, descendants of these |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3477 | // layers have their visible rects clipped by them; Similarly, descendants of |
| 3478 | // these layers have their drawable content rects clipped by them. |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3479 | child1->SetMasksToBounds(true); |
| 3480 | grand_child2->SetMasksToBounds(true); |
| 3481 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3482 | ExecuteCalculateDrawProperties(root); |
| 3483 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3484 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3485 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3486 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3487 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3488 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3489 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3490 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3491 | |
| 3492 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3493 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3494 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3495 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3496 | EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect()); |
| 3497 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3498 | EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect()); |
| 3499 | EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3500 | |
| 3501 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3502 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3503 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3504 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3505 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3506 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3507 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3508 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3509 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3510 | |
| 3511 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3512 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3513 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3514 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3515 | EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect()); |
| 3516 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3517 | grand_child2->drawable_content_rect()); |
| 3518 | EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); |
| 3519 | EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3520 | } |
| 3521 | |
| 3522 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3523 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3524 | LayerImpl* root = root_layer_for_testing(); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3525 | LayerImpl* child1 = AddChild<LayerImpl>(root); |
| 3526 | LayerImpl* child2 = AddChild<LayerImpl>(root); |
| 3527 | LayerImpl* child3 = AddChild<LayerImpl>(root); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3528 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3529 | root->SetBounds(gfx::Size(100, 100)); |
| 3530 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3531 | child1->SetBounds(gfx::Size(50, 50)); |
| 3532 | child1->SetDrawsContent(true); |
| 3533 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3534 | child2->SetBounds(gfx::Size(50, 50)); |
| 3535 | child2->SetDrawsContent(true); |
| 3536 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3537 | child3->SetBounds(gfx::Size(50, 50)); |
| 3538 | child3->SetDrawsContent(true); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3539 | |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3540 | LayerImplList render_surface_layer_list_impl; |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3541 | // Now set the root render surface an empty clip. |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3542 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 3543 | root, gfx::Size(), &render_surface_layer_list_impl); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3544 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 3545 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3546 | ASSERT_TRUE(root->render_surface()); |
| 3547 | EXPECT_FALSE(root->is_clipped()); |
| 3548 | |
| 3549 | gfx::Rect empty; |
| 3550 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 3551 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 3552 | |
| 3553 | // Visible content rect calculation will check if the target surface is |
| 3554 | // clipped or not. An empty clip rect does not indicate the render surface |
| 3555 | // is unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3556 | EXPECT_EQ(empty, child1->visible_layer_rect()); |
| 3557 | EXPECT_EQ(empty, child2->visible_layer_rect()); |
| 3558 | EXPECT_EQ(empty, child3->visible_layer_rect()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3559 | } |
| 3560 | |
| 3561 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3562 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3563 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3564 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3565 | |
| 3566 | root->SetBounds(gfx::Size(100, 100)); |
| 3567 | child->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3568 | child->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3569 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3570 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3571 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3572 | 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] | 3573 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3574 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3575 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3576 | ExecuteCalculateDrawProperties(root); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3577 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3578 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3579 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3580 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3581 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 3582 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3583 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3584 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3585 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3586 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3587 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3588 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3589 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3590 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3591 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3592 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3593 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3594 | uninvertible_matrix.MakeIdentity(); |
| 3595 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3596 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3597 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3598 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3599 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3600 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3601 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3602 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3603 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3604 | } |
| 3605 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3606 | TEST_F(LayerTreeHostCommonTest, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3607 | VisibleContentRectForLayerWithUninvertibleDrawTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3608 | LayerImpl* root = root_layer_for_testing(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3609 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3610 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3611 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3612 | gfx::Transform perspective; |
| 3613 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3614 | |
| 3615 | gfx::Transform rotation; |
| 3616 | rotation.RotateAboutYAxis(45.0); |
| 3617 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3618 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3619 | child->test_properties()->transform = perspective; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3620 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 3621 | child->SetBounds(gfx::Size(100, 100)); |
| 3622 | child->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 3623 | child->test_properties()->sorting_context_id = 1; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3624 | child->test_properties()->should_flatten_transform = false; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3625 | grand_child->test_properties()->transform = rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3626 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 3627 | grand_child->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 3628 | child->test_properties()->sorting_context_id = 1; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3629 | grand_child->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 3630 | grand_child->test_properties()->sorting_context_id = 1; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3631 | ExecuteCalculateDrawProperties(root); |
| 3632 | |
| 3633 | // Though all layers have invertible transforms, matrix multiplication using |
| 3634 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3635 | EXPECT_FALSE(root->layer_tree_impl() |
| 3636 | ->property_trees() |
| 3637 | ->transform_tree.Node(grand_child->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3638 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3639 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3640 | // CalcDrawProps skips a subtree when a layer's screen space transform is |
| 3641 | // uninvertible |
| 3642 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3643 | } |
| 3644 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3645 | TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) { |
| 3646 | FakeImplTaskRunnerProvider task_runner_provider; |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3647 | TestTaskGraphRunner task_graph_runner; |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3648 | std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 3649 | FakeCompositorFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 3650 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3651 | |
| 3652 | std::unique_ptr<LayerImpl> root = |
| 3653 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3654 | std::unique_ptr<LayerImpl> child = |
| 3655 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3656 | std::unique_ptr<TextureLayerImpl> surface = |
| 3657 | TextureLayerImpl::Create(host_impl.active_tree(), 3); |
| 3658 | std::unique_ptr<TextureLayerImpl> surface_child = |
| 3659 | TextureLayerImpl::Create(host_impl.active_tree(), 4); |
| 3660 | std::unique_ptr<TextureLayerImpl> surface_sibling = |
| 3661 | TextureLayerImpl::Create(host_impl.active_tree(), 5); |
| 3662 | std::unique_ptr<TextureLayerImpl> surface_child_mask = |
| 3663 | TextureLayerImpl::Create(host_impl.active_tree(), 6); |
| 3664 | |
| 3665 | surface->SetDrawsContent(true); |
| 3666 | surface_child->SetDrawsContent(true); |
| 3667 | surface_sibling->SetDrawsContent(true); |
| 3668 | surface_child_mask->SetDrawsContent(true); |
| 3669 | surface->SetContentsOpaque(true); |
| 3670 | surface_child->SetContentsOpaque(true); |
| 3671 | surface_sibling->SetContentsOpaque(true); |
| 3672 | surface_child_mask->SetContentsOpaque(true); |
| 3673 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3674 | gfx::Transform translate; |
| 3675 | translate.Translate(20.f, 20.f); |
| 3676 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3677 | root->SetBounds(gfx::Size(1000, 1000)); |
| 3678 | child->SetBounds(gfx::Size(300, 300)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3679 | surface->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3680 | surface->SetBounds(gfx::Size(300, 300)); |
| 3681 | surface->test_properties()->force_render_surface = true; |
| 3682 | surface_child->SetBounds(gfx::Size(300, 300)); |
| 3683 | surface_child->test_properties()->force_render_surface = true; |
| 3684 | surface_sibling->SetBounds(gfx::Size(200, 200)); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3685 | |
| 3686 | LayerImpl* surface_ptr = surface.get(); |
| 3687 | LayerImpl* surface_child_ptr = surface_child.get(); |
| 3688 | LayerImpl* surface_child_mask_ptr = surface_child_mask.get(); |
| 3689 | |
| 3690 | host_impl.SetViewportSize(root->bounds()); |
| 3691 | |
| 3692 | surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask)); |
| 3693 | surface->test_properties()->AddChild(std::move(surface_child)); |
| 3694 | child->test_properties()->AddChild(std::move(surface)); |
| 3695 | child->test_properties()->AddChild(std::move(surface_sibling)); |
| 3696 | root->test_properties()->AddChild(std::move(child)); |
| 3697 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 3698 | host_impl.SetVisible(true); |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3699 | host_impl.InitializeRenderer(compositor_frame_sink.get()); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3700 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 3701 | bool update_lcd_text = false; |
| 3702 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3703 | |
| 3704 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 3705 | surface_ptr->render_surface()->draw_transform(), translate); |
| 3706 | // surface_sibling draws into the root render surface and occludes |
| 3707 | // surface_child's contents. |
| 3708 | Occlusion actual_occlusion = |
| 3709 | surface_child_ptr->render_surface()->occlusion_in_content_space(); |
| 3710 | Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()), |
| 3711 | SimpleEnclosedRegion(gfx::Rect(200, 200))); |
| 3712 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3713 | |
| 3714 | // Mask layer should have the same occlusion. |
| 3715 | actual_occlusion = |
| 3716 | surface_child_mask_ptr->draw_properties().occlusion_in_content_space; |
| 3717 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3718 | } |
| 3719 | |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3720 | TEST_F(LayerTreeHostCommonTest, TextureLayerSnapping) { |
| 3721 | FakeImplTaskRunnerProvider task_runner_provider; |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3722 | TestTaskGraphRunner task_graph_runner; |
| 3723 | std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 3724 | FakeCompositorFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 3725 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3726 | |
| 3727 | std::unique_ptr<LayerImpl> root = |
| 3728 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3729 | std::unique_ptr<TextureLayerImpl> child = |
| 3730 | TextureLayerImpl::Create(host_impl.active_tree(), 2); |
| 3731 | |
| 3732 | LayerImpl* child_ptr = child.get(); |
| 3733 | |
| 3734 | root->SetBounds(gfx::Size(100, 100)); |
| 3735 | child->SetBounds(gfx::Size(100, 100)); |
| 3736 | child->SetDrawsContent(true); |
| 3737 | gfx::Transform fractional_translate; |
| 3738 | fractional_translate.Translate(10.5f, 20.3f); |
| 3739 | child->test_properties()->transform = fractional_translate; |
| 3740 | |
| 3741 | host_impl.SetViewportSize(root->bounds()); |
| 3742 | |
| 3743 | root->test_properties()->AddChild(std::move(child)); |
| 3744 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 3745 | host_impl.SetVisible(true); |
| 3746 | host_impl.InitializeRenderer(compositor_frame_sink.get()); |
| 3747 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 3748 | bool update_lcd_text = false; |
| 3749 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3750 | |
| 3751 | EXPECT_NE(child_ptr->ScreenSpaceTransform(), fractional_translate); |
| 3752 | fractional_translate.RoundTranslationComponents(); |
| 3753 | EXPECT_TRANSFORMATION_MATRIX_EQ(child_ptr->ScreenSpaceTransform(), |
| 3754 | fractional_translate); |
| 3755 | gfx::RectF layer_bounds_in_screen_space = |
| 3756 | MathUtil::MapClippedRect(child_ptr->ScreenSpaceTransform(), |
| 3757 | gfx::RectF(gfx::SizeF(child_ptr->bounds()))); |
| 3758 | EXPECT_EQ(layer_bounds_in_screen_space, gfx::RectF(11.f, 20.f, 100.f, 100.f)); |
| 3759 | } |
| 3760 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3761 | TEST_F(LayerTreeHostCommonTest, |
| 3762 | OcclusionForLayerWithUninvertibleDrawTransform) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3763 | FakeImplTaskRunnerProvider task_runner_provider; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3764 | TestTaskGraphRunner task_graph_runner; |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3765 | std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 3766 | FakeCompositorFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 3767 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3768 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3769 | std::unique_ptr<LayerImpl> root = |
| 3770 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3771 | std::unique_ptr<LayerImpl> child = |
| 3772 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3773 | std::unique_ptr<LayerImpl> grand_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3774 | LayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3775 | std::unique_ptr<LayerImpl> occluding_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3776 | LayerImpl::Create(host_impl.active_tree(), 4); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3777 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3778 | gfx::Transform perspective; |
| 3779 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3780 | |
| 3781 | gfx::Transform rotation; |
| 3782 | rotation.RotateAboutYAxis(45.0); |
| 3783 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3784 | root->SetBounds(gfx::Size(1000, 1000)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3785 | child->test_properties()->transform = perspective; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3786 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 3787 | child->SetBounds(gfx::Size(300, 300)); |
| 3788 | child->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 3789 | child->test_properties()->sorting_context_id = 1; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3790 | grand_child->test_properties()->transform = rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3791 | grand_child->SetBounds(gfx::Size(200, 200)); |
| 3792 | grand_child->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 3793 | grand_child->test_properties()->sorting_context_id = 1; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3794 | occluding_child->SetBounds(gfx::Size(200, 200)); |
| 3795 | occluding_child->test_properties()->should_flatten_transform = false; |
| 3796 | |
| 3797 | child->SetDrawsContent(true); |
| 3798 | grand_child->SetDrawsContent(true); |
| 3799 | occluding_child->SetDrawsContent(true); |
| 3800 | occluding_child->SetContentsOpaque(true); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3801 | |
| 3802 | host_impl.SetViewportSize(root->bounds()); |
| 3803 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3804 | child->test_properties()->AddChild(std::move(grand_child)); |
| 3805 | root->test_properties()->AddChild(std::move(child)); |
| 3806 | root->test_properties()->AddChild(std::move(occluding_child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3807 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 3808 | host_impl.SetVisible(true); |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3809 | host_impl.InitializeRenderer(compositor_frame_sink.get()); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 3810 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3811 | bool update_lcd_text = false; |
| 3812 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3813 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3814 | LayerImpl* grand_child_ptr = host_impl.active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3815 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3816 | ->test_properties() |
| 3817 | ->children[0] |
| 3818 | ->test_properties() |
| 3819 | ->children[0]; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3820 | |
| 3821 | // Though all layers have invertible transforms, matrix multiplication using |
| 3822 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3823 | EXPECT_FALSE( |
| 3824 | host_impl.active_tree() |
| 3825 | ->property_trees() |
| 3826 | ->transform_tree.Node(grand_child_ptr->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3827 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3828 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3829 | // Since |grand_child| has an uninvertible screen space transform, it is |
| 3830 | // skipped so |
| 3831 | // that we are not computing its occlusion_in_content_space. |
| 3832 | gfx::Rect layer_bounds = gfx::Rect(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3833 | EXPECT_EQ( |
| 3834 | layer_bounds, |
| 3835 | grand_child_ptr->draw_properties() |
| 3836 | .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds)); |
| 3837 | } |
| 3838 | |
| 3839 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3840 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3841 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3842 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3843 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3844 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3845 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3846 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3847 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3848 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3849 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3850 | render_surface->test_properties()->force_render_surface = true; |
| 3851 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3852 | child1->SetBounds(gfx::Size(50, 50)); |
| 3853 | child1->SetDrawsContent(true); |
| 3854 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3855 | child2->SetBounds(gfx::Size(50, 50)); |
| 3856 | child2->SetDrawsContent(true); |
| 3857 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3858 | child3->SetBounds(gfx::Size(50, 50)); |
| 3859 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3860 | ExecuteCalculateDrawProperties(root); |
| 3861 | |
| 3862 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3863 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3864 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3865 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3866 | |
| 3867 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3868 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3869 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3870 | |
| 3871 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3872 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3873 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3874 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3875 | |
| 3876 | // All layers that draw content into the surface have their visible content |
| 3877 | // rect clipped by the surface clip rect. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3878 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3879 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3880 | EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3881 | |
| 3882 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3883 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3884 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3885 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3886 | } |
| 3887 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3888 | TEST_F(LayerTreeHostCommonTest, |
| 3889 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3890 | // Check that clipping does not propagate down surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3891 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3892 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3893 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 3894 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3895 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3896 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3897 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3898 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3899 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3900 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 3901 | render_surface1->test_properties()->force_render_surface = true; |
| 3902 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 3903 | render_surface2->test_properties()->force_render_surface = true; |
| 3904 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3905 | child1->SetBounds(gfx::Size(50, 50)); |
| 3906 | child1->SetDrawsContent(true); |
| 3907 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3908 | child2->SetBounds(gfx::Size(50, 50)); |
| 3909 | child2->SetDrawsContent(true); |
| 3910 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3911 | child3->SetBounds(gfx::Size(50, 50)); |
| 3912 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3913 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3914 | |
| 3915 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3916 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3917 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3918 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3919 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3920 | |
| 3921 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3922 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3923 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); |
| 3924 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3925 | |
| 3926 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3927 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3928 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3929 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3930 | |
| 3931 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3932 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3933 | // render_surface2 grows to enclose all drawable content of its subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3934 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3935 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3936 | |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3937 | // All layers that draw content into render_surface2 think they are unclipped |
| 3938 | // by the surface. So, only the viewport clip applies. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3939 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3940 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3941 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3942 | |
| 3943 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3944 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3945 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3946 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3947 | } |
| 3948 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3949 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3950 | VisibleRectsForClippedDescendantsOfUnclippedSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3951 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3952 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3953 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 3954 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 3955 | LayerImpl* render_surface2 = AddChild<LayerImpl>(child2); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3956 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3957 | root->SetBounds(gfx::Size(100, 100)); |
| 3958 | render_surface1->SetBounds(gfx::Size(100, 100)); |
| 3959 | render_surface1->test_properties()->force_render_surface = true; |
| 3960 | child1->SetBounds(gfx::Size(500, 500)); |
| 3961 | child1->SetDrawsContent(true); |
| 3962 | child2->SetBounds(gfx::Size(700, 700)); |
| 3963 | child2->SetDrawsContent(true); |
| 3964 | render_surface2->SetBounds(gfx::Size(1000, 1000)); |
| 3965 | render_surface2->test_properties()->force_render_surface = true; |
| 3966 | render_surface2->SetDrawsContent(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3967 | |
| 3968 | child1->SetMasksToBounds(true); |
| 3969 | child2->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3970 | ExecuteCalculateDrawProperties(root); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3971 | EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3972 | EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3973 | } |
| 3974 | |
| 3975 | TEST_F(LayerTreeHostCommonTest, |
| 3976 | VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3977 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3978 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3979 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3980 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3981 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3982 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3983 | root->SetBounds(gfx::Size(100, 100)); |
| 3984 | |
| 3985 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3986 | clip_parent->SetMasksToBounds(true); |
| 3987 | clip_parent->test_properties()->clip_children = |
| 3988 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3989 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3990 | |
| 3991 | render_surface1->SetBounds(gfx::Size(20, 20)); |
| 3992 | render_surface1->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3993 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3994 | render_surface1->test_properties()->force_render_surface = true; |
| 3995 | |
| 3996 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3997 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3998 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3999 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4000 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 4001 | render_surface2->SetDrawsContent(true); |
| 4002 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4003 | |
| 4004 | ExecuteCalculateDrawProperties(root); |
| 4005 | EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect()); |
| 4006 | EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect()); |
| 4007 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect()); |
| 4008 | } |
| 4009 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 4010 | TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4011 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 4012 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 4013 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 4014 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 4015 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 4016 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4017 | root->SetBounds(gfx::Size(100, 100)); |
| 4018 | |
| 4019 | clip_parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4020 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 4021 | clip_parent->test_properties()->clip_children = |
| 4022 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 4023 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 4024 | |
| 4025 | render_surface1->SetBounds(gfx::Size(20, 20)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 4026 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4027 | render_surface1->test_properties()->force_render_surface = true; |
| 4028 | |
| 4029 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 4030 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 4031 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 4032 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4033 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 4034 | render_surface2->SetDrawsContent(true); |
| 4035 | render_surface2->test_properties()->force_render_surface = true; |
| 4036 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 4037 | clip_parent->SetMasksToBounds(true); |
| 4038 | render_surface1->SetMasksToBounds(true); |
| 4039 | |
| 4040 | ExecuteCalculateDrawProperties(root); |
| 4041 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect()); |
| 4042 | } |
| 4043 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 4044 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) { |
| 4045 | // Test that only drawn layers contribute to render surface content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4046 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 4047 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 4048 | LayerImpl* test_layer = AddChild<LayerImpl>(surface); |
| 4049 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4050 | root->SetBounds(gfx::Size(200, 200)); |
| 4051 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 4052 | surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4053 | surface->test_properties()->force_render_surface = true; |
| 4054 | test_layer->SetBounds(gfx::Size(150, 150)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 4055 | |
| 4056 | ExecuteCalculateDrawProperties(root); |
| 4057 | EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect()); |
| 4058 | |
| 4059 | test_layer->SetDrawsContent(true); |
| 4060 | ExecuteCalculateDrawProperties(root); |
| 4061 | EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect()); |
| 4062 | } |
| 4063 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4064 | TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) { |
| 4065 | // Tests visible rects computation when we have unclipped_surface-> |
| 4066 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 4067 | // of surface_with_unclipped_descendants doesn't propagate to the |
| 4068 | // clipped_surface below it. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4069 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4070 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 4071 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 4072 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 4073 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 4074 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 4075 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4076 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4077 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4078 | unclipped_surface->SetBounds(gfx::Size(30, 30)); |
| 4079 | unclipped_surface->SetDrawsContent(true); |
| 4080 | unclipped_surface->test_properties()->force_render_surface = true; |
| 4081 | |
| 4082 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 4083 | clip_parent->test_properties()->clip_children = |
| 4084 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 4085 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 4086 | |
| 4087 | unclipped_desc_surface->SetBounds(gfx::Size(20, 20)); |
| 4088 | unclipped_desc_surface->SetDrawsContent(true); |
| 4089 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 4090 | |
| 4091 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 4092 | clip_child->test_properties()->clip_parent = clip_parent; |
| 4093 | |
| 4094 | clipped_surface->SetBounds(gfx::Size(60, 60)); |
| 4095 | clipped_surface->SetDrawsContent(true); |
| 4096 | clipped_surface->test_properties()->force_render_surface = true; |
| 4097 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4098 | clip_parent->SetMasksToBounds(true); |
| 4099 | |
| 4100 | ExecuteCalculateDrawProperties(root); |
| 4101 | EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect()); |
| 4102 | EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect()); |
| 4103 | EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect()); |
| 4104 | } |
| 4105 | |
| 4106 | TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) { |
| 4107 | // Tests visible rects computation when we have unclipped_surface-> |
| 4108 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 4109 | // of root propagate to the clipped_surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4110 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4111 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 4112 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 4113 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 4114 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 4115 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 4116 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4117 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4118 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4119 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
| 4120 | unclipped_surface->SetDrawsContent(true); |
| 4121 | unclipped_surface->test_properties()->force_render_surface = true; |
| 4122 | |
| 4123 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 4124 | clip_parent->test_properties()->clip_children = |
| 4125 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 4126 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 4127 | |
| 4128 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 4129 | unclipped_desc_surface->SetDrawsContent(true); |
| 4130 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 4131 | |
| 4132 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 4133 | clip_child->test_properties()->clip_parent = clip_parent; |
| 4134 | |
| 4135 | clipped_surface->SetBounds(gfx::Size(50, 50)); |
| 4136 | clipped_surface->SetDrawsContent(true); |
| 4137 | clipped_surface->test_properties()->force_render_surface = true; |
| 4138 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4139 | clip_parent->SetMasksToBounds(true); |
| 4140 | unclipped_desc_surface->SetMasksToBounds(true); |
| 4141 | |
| 4142 | ExecuteCalculateDrawProperties(root); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 4143 | EXPECT_EQ(gfx::Rect(10, 10), unclipped_surface->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 4144 | EXPECT_EQ(gfx::Rect(10, 10), unclipped_desc_surface->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4145 | EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect()); |
| 4146 | } |
| 4147 | |
| 4148 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4149 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4150 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 4151 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4152 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4153 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 4154 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4155 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4156 | gfx::Transform child_rotation; |
| 4157 | child_rotation.Rotate(45.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4158 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4159 | root->SetBounds(gfx::Size(100, 100)); |
| 4160 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 4161 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4162 | child1->test_properties()->transform = child_rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4163 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 4164 | child1->SetBounds(gfx::Size(50, 50)); |
| 4165 | child1->SetDrawsContent(true); |
| 4166 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4167 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4168 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4169 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4170 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4171 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4172 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4173 | |
| 4174 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4175 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4176 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4177 | |
| 4178 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 4179 | // regions of the subtree. |
| 4180 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 4181 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4182 | gfx::Rect(50 - diagonal_radius, |
| 4183 | 50 - diagonal_radius, |
| 4184 | diagonal_radius * 2, |
| 4185 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4186 | EXPECT_EQ(gfx::RectF(expected_surface_drawable_content), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4187 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4188 | |
| 4189 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4190 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4191 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4192 | } |
| 4193 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4194 | TEST_F(LayerTreeHostCommonTest, |
| 4195 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4196 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 4197 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4198 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4199 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 4200 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4201 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4202 | gfx::Transform child_rotation; |
| 4203 | child_rotation.Rotate(45.0); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4204 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4205 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4206 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4207 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 4208 | render_surface->test_properties()->force_render_surface = true; |
| 4209 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 4210 | child1->SetBounds(gfx::Size(50, 50)); |
| 4211 | child1->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4212 | child1->test_properties()->transform = child_rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4213 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4214 | ExecuteCalculateDrawProperties(root); |
| 4215 | |
| 4216 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4217 | |
| 4218 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 4219 | // rotated layer. |
| 4220 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4221 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 4222 | 50 - diagonal_radius, |
| 4223 | diagonal_radius * 2, |
| 4224 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4225 | gfx::RectF expected_surface_drawable_content( |
| 4226 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4227 | EXPECT_EQ(expected_surface_drawable_content, |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4228 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4229 | |
| 4230 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 4231 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 4232 | // up covering the full left half of child1. |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 4233 | EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4234 | |
| 4235 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4236 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4237 | } |
| 4238 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4239 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4240 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4241 | FakePictureLayerImpl* render_surface1 = |
| 4242 | AddChildToRoot<FakePictureLayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4243 | FakePictureLayerImpl* render_surface2 = |
| 4244 | AddChild<FakePictureLayerImpl>(render_surface1); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4245 | FakePictureLayerImpl* child1 = |
| 4246 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4247 | FakePictureLayerImpl* child2 = |
| 4248 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4249 | FakePictureLayerImpl* child3 = |
| 4250 | AddChild<FakePictureLayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4251 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4252 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4253 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4254 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 4255 | render_surface1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4256 | render_surface1->SetDrawsContent(true); |
| 4257 | render_surface1->test_properties()->force_render_surface = true; |
| 4258 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 4259 | render_surface2->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4260 | render_surface2->SetDrawsContent(true); |
| 4261 | render_surface2->test_properties()->force_render_surface = true; |
| 4262 | child1->SetBounds(gfx::Size(50, 50)); |
| 4263 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4264 | child1->SetDrawsContent(true); |
| 4265 | child2->SetBounds(gfx::Size(50, 50)); |
| 4266 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 4267 | child2->SetDrawsContent(true); |
| 4268 | child3->SetBounds(gfx::Size(50, 50)); |
| 4269 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 4270 | child3->SetDrawsContent(true); |
| 4271 | float device_scale_factor = 2.f; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4272 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4273 | |
| 4274 | ASSERT_TRUE(render_surface1->render_surface()); |
| 4275 | ASSERT_TRUE(render_surface2->render_surface()); |
| 4276 | |
| 4277 | // drawable_content_rects for all layers and surfaces are scaled by |
| 4278 | // device_scale_factor. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4279 | EXPECT_EQ(gfx::RectF(200.f, 200.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4280 | root->render_surface()->DrawableContentRect()); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4281 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4282 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4283 | |
| 4284 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 4285 | // is only implicitly clipped by render_surface1. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4286 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4287 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4288 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4289 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 4290 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 4291 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4292 | |
| 4293 | // The root layer does not actually draw content of its own. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4294 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4295 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4296 | // All layer visible content rects are not expressed in content space of each |
| 4297 | // layer, so they are not scaled by the device_scale_factor. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4298 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect()); |
| 4299 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect()); |
| 4300 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 4301 | EXPECT_EQ(gfx::Rect(0, 0, 15, 15), child2->visible_layer_rect()); |
| 4302 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4303 | } |
| 4304 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4305 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4306 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 4307 | // layers. Note that 3d transforms still apply in this case, but they are |
| 4308 | // "flattened" to each parent layer according to current W3C spec. |
| 4309 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4310 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4311 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4312 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4313 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4314 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4315 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4316 | AddChild<LayerImpl>(front_facing_surface); |
| 4317 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4318 | AddChild<LayerImpl>(front_facing_surface); |
| 4319 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4320 | AddChild<LayerImpl>(back_facing_surface); |
| 4321 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4322 | AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4323 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4324 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4325 | front_facing_child->test_properties()->double_sided = false; |
| 4326 | back_facing_child->test_properties()->double_sided = false; |
| 4327 | front_facing_surface->test_properties()->double_sided = false; |
| 4328 | back_facing_surface->test_properties()->double_sided = false; |
| 4329 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4330 | false; |
| 4331 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4332 | false; |
| 4333 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4334 | false; |
| 4335 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4336 | false; |
| 4337 | |
| 4338 | // Everything draws content. |
| 4339 | front_facing_child->SetDrawsContent(true); |
| 4340 | back_facing_child->SetDrawsContent(true); |
| 4341 | front_facing_surface->SetDrawsContent(true); |
| 4342 | back_facing_surface->SetDrawsContent(true); |
| 4343 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4344 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4345 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4346 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4347 | |
| 4348 | gfx::Transform backface_matrix; |
| 4349 | backface_matrix.Translate(50.0, 50.0); |
| 4350 | backface_matrix.RotateAboutYAxis(180.0); |
| 4351 | backface_matrix.Translate(-50.0, -50.0); |
| 4352 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4353 | root->SetBounds(gfx::Size(100, 100)); |
| 4354 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4355 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4356 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4357 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4358 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4359 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4360 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4361 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4362 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4363 | front_facing_surface->test_properties()->force_render_surface = true; |
| 4364 | back_facing_surface->test_properties()->force_render_surface = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4365 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4366 | back_facing_child->test_properties()->transform = backface_matrix; |
| 4367 | back_facing_surface->test_properties()->transform = backface_matrix; |
| 4368 | back_facing_child_of_front_facing_surface->test_properties()->transform = |
| 4369 | backface_matrix; |
| 4370 | back_facing_child_of_back_facing_surface->test_properties()->transform = |
| 4371 | backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4372 | |
| 4373 | // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms |
| 4374 | // spec, these layers should blindly use their own local transforms to |
| 4375 | // determine back-face culling. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4376 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4377 | |
| 4378 | // Verify which render surfaces were created. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4379 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4380 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4381 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
| 4382 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4383 | EXPECT_FALSE( |
| 4384 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4385 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4386 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4387 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4388 | |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame] | 4389 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4390 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4391 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4392 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4393 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4394 | } |
| 4395 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4396 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4397 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 4398 | // is used. |
| 4399 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4400 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4401 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4402 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4403 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4404 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4405 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4406 | AddChild<LayerImpl>(front_facing_surface); |
| 4407 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4408 | AddChild<LayerImpl>(front_facing_surface); |
| 4409 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4410 | AddChild<LayerImpl>(back_facing_surface); |
| 4411 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4412 | AddChild<LayerImpl>(back_facing_surface); |
| 4413 | // Opacity will not force creation of render surfaces in this case because of |
| 4414 | // the preserve-3d transform style. Instead, an example of when a surface |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4415 | // would be created with preserve-3d is when there is a mask layer. |
| 4416 | LayerImpl* dummy_mask_layer1 = AddMaskLayer<LayerImpl>(front_facing_surface); |
| 4417 | LayerImpl* dummy_mask_layer2 = AddMaskLayer<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4418 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4419 | // Nothing is double-sided |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4420 | front_facing_child->test_properties()->double_sided = false; |
| 4421 | back_facing_child->test_properties()->double_sided = false; |
| 4422 | front_facing_surface->test_properties()->double_sided = false; |
| 4423 | back_facing_surface->test_properties()->double_sided = false; |
| 4424 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4425 | false; |
| 4426 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4427 | false; |
| 4428 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4429 | false; |
| 4430 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4431 | false; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4432 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4433 | // Everything draws content. |
| 4434 | front_facing_child->SetDrawsContent(true); |
| 4435 | back_facing_child->SetDrawsContent(true); |
| 4436 | front_facing_surface->SetDrawsContent(true); |
| 4437 | back_facing_surface->SetDrawsContent(true); |
| 4438 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4439 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4440 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4441 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4442 | dummy_mask_layer1->SetDrawsContent(true); |
| 4443 | dummy_mask_layer2->SetDrawsContent(true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4444 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4445 | gfx::Transform backface_matrix; |
| 4446 | backface_matrix.Translate(50.0, 50.0); |
| 4447 | backface_matrix.RotateAboutYAxis(180.0); |
| 4448 | backface_matrix.Translate(-50.0, -50.0); |
| 4449 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4450 | root->SetBounds(gfx::Size(100, 100)); |
| 4451 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4452 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4453 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4454 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4455 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4456 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4457 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4458 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4459 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4460 | back_facing_child->test_properties()->transform = backface_matrix; |
| 4461 | back_facing_surface->test_properties()->transform = backface_matrix; |
| 4462 | back_facing_child_of_front_facing_surface->test_properties()->transform = |
| 4463 | backface_matrix; |
| 4464 | back_facing_child_of_back_facing_surface->test_properties()->transform = |
| 4465 | backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4466 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4467 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 4468 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 4469 | // rendering context should use the transform with respect to that context. |
| 4470 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 4471 | // and (b) the layer's transform style is preserve-3d. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4472 | front_facing_surface->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 4473 | front_facing_surface->test_properties()->sorting_context_id = 1; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4474 | back_facing_surface->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 4475 | back_facing_surface->test_properties()->sorting_context_id = 1; |
| 4476 | front_facing_child_of_front_facing_surface->test_properties() |
| 4477 | ->sorting_context_id = 1; |
| 4478 | back_facing_child_of_front_facing_surface->test_properties() |
| 4479 | ->sorting_context_id = 1; |
| 4480 | front_facing_child_of_back_facing_surface->test_properties() |
| 4481 | ->sorting_context_id = 1; |
| 4482 | back_facing_child_of_back_facing_surface->test_properties() |
| 4483 | ->sorting_context_id = 1; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4484 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4485 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4486 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4487 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4488 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4489 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4490 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4491 | // We expect that a has_render_surface was created but not used. |
| 4492 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4493 | EXPECT_FALSE( |
| 4494 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4495 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4496 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4497 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4498 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4499 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4500 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4501 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4502 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4503 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4504 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4505 | } |
| 4506 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4507 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4508 | // Verify that layers are appropriately culled when their back face is showing |
| 4509 | // and they are not double sided, while animations are going on. |
| 4510 | // |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4511 | // Even layers that are animating get culled if their back face is showing and |
| 4512 | // they are not double sided. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4513 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4514 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4515 | LayerImpl* animating_surface = AddChildToRoot<LayerImpl>(); |
| 4516 | LayerImpl* child_of_animating_surface = |
| 4517 | AddChild<LayerImpl>(animating_surface); |
| 4518 | LayerImpl* animating_child = AddChildToRoot<LayerImpl>(); |
| 4519 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4520 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4521 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4522 | child->test_properties()->double_sided = false; |
| 4523 | child2->test_properties()->double_sided = false; |
| 4524 | animating_surface->test_properties()->double_sided = false; |
| 4525 | child_of_animating_surface->test_properties()->double_sided = false; |
| 4526 | animating_child->test_properties()->double_sided = false; |
| 4527 | |
| 4528 | // Everything draws content. |
| 4529 | child->SetDrawsContent(true); |
| 4530 | child2->SetDrawsContent(true); |
| 4531 | animating_surface->SetDrawsContent(true); |
| 4532 | child_of_animating_surface->SetDrawsContent(true); |
| 4533 | animating_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4534 | |
| 4535 | gfx::Transform backface_matrix; |
| 4536 | backface_matrix.Translate(50.0, 50.0); |
| 4537 | backface_matrix.RotateAboutYAxis(180.0); |
| 4538 | backface_matrix.Translate(-50.0, -50.0); |
| 4539 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4540 | SetElementIdsForTesting(); |
| 4541 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4542 | // Animate the transform on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4543 | AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(), |
| 4544 | timeline_impl(), 10.0, 30, 0); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4545 | // This is just an animating layer, not a surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4546 | AddAnimatedTransformToElementWithPlayer(animating_child->element_id(), |
| 4547 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4548 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4549 | root->SetBounds(gfx::Size(100, 100)); |
| 4550 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4551 | child->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4552 | animating_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4553 | animating_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4554 | animating_surface->test_properties()->force_render_surface = true; |
| 4555 | child_of_animating_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4556 | child_of_animating_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4557 | animating_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4558 | animating_child->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4559 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4560 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4561 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4562 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4563 | EXPECT_FALSE(child->has_render_surface()); |
| 4564 | EXPECT_TRUE(animating_surface->has_render_surface()); |
| 4565 | EXPECT_FALSE(child_of_animating_surface->has_render_surface()); |
| 4566 | EXPECT_FALSE(animating_child->has_render_surface()); |
| 4567 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4568 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4569 | EXPECT_EQ(1u, update_layer_list_impl()->size()); |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4570 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4571 | // The back facing layers are culled from the layer list, and have an empty |
| 4572 | // visible rect. |
| 4573 | EXPECT_TRUE(UpdateLayerListImplContains(child2->id())); |
| 4574 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
| 4575 | EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty()); |
| 4576 | EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty()); |
| 4577 | EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4578 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4579 | EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4580 | } |
| 4581 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4582 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4583 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4584 | // Verify the behavior of back-face culling for a render surface that is |
| 4585 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4586 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4587 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4588 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4589 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4590 | LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface); |
| 4591 | LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4592 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4593 | // RenderSurfaces are not double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4594 | front_facing_surface->test_properties()->double_sided = false; |
| 4595 | back_facing_surface->test_properties()->double_sided = false; |
| 4596 | |
| 4597 | // Everything draws content. |
| 4598 | front_facing_surface->SetDrawsContent(true); |
| 4599 | back_facing_surface->SetDrawsContent(true); |
| 4600 | child1->SetDrawsContent(true); |
| 4601 | child2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4602 | |
| 4603 | gfx::Transform backface_matrix; |
| 4604 | backface_matrix.Translate(50.0, 50.0); |
| 4605 | backface_matrix.RotateAboutYAxis(180.0); |
| 4606 | backface_matrix.Translate(-50.0, -50.0); |
| 4607 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4608 | root->SetBounds(gfx::Size(100, 100)); |
| 4609 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4610 | front_facing_surface->test_properties()->force_render_surface = true; |
| 4611 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4612 | back_facing_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4613 | back_facing_surface->test_properties()->force_render_surface = true; |
| 4614 | child1->SetBounds(gfx::Size(100, 100)); |
| 4615 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4616 | |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 4617 | front_facing_surface->test_properties()->sorting_context_id = 1; |
| 4618 | back_facing_surface->test_properties()->sorting_context_id = 1; |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4619 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4620 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4621 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4622 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4623 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4624 | |
| 4625 | // We expect the render surface to have been created, but remain unused. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4626 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4627 | EXPECT_FALSE(child1->has_render_surface()); |
| 4628 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4629 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4630 | EXPECT_EQ(2u, update_layer_list_impl()->size()); |
| 4631 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4632 | EXPECT_TRUE(UpdateLayerListImplContains(child1->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4633 | } |
| 4634 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4635 | TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4636 | // Verify draw and screen space transforms of layers not in a surface. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4637 | LayerImpl* root = root_layer_for_testing(); |
| 4638 | root->SetBounds(gfx::Size(100, 100)); |
| 4639 | root->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4640 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4641 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4642 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4643 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4644 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4645 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4646 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4647 | child2->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4648 | child2->SetBounds(gfx::Size(5, 5)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4649 | child2->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4650 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4651 | float device_scale_factor = 2.5f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4652 | gfx::Size viewport_size(100, 100); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4653 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4654 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4655 | EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale()); |
| 4656 | EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale()); |
| 4657 | EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale()); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4658 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4659 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4660 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4661 | // Verify root transforms |
| 4662 | gfx::Transform expected_root_transform; |
| 4663 | expected_root_transform.Scale(device_scale_factor, device_scale_factor); |
| 4664 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4665 | root->ScreenSpaceTransform()); |
| 4666 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4667 | root->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4668 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4669 | // Verify results of transformed root rects |
| 4670 | gfx::RectF root_bounds(gfx::SizeF(root->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4671 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4672 | gfx::RectF root_draw_rect = |
| 4673 | MathUtil::MapClippedRect(root->DrawTransform(), root_bounds); |
| 4674 | gfx::RectF root_screen_space_rect = |
| 4675 | MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4676 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4677 | gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds())); |
| 4678 | expected_root_draw_rect.Scale(device_scale_factor); |
| 4679 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect); |
| 4680 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4681 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4682 | // Verify child and child2 transforms. They should match. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4683 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4684 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4685 | expected_child_transform.Translate(child->position().x(), |
| 4686 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4687 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4688 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4689 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4690 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4691 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4692 | child2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4693 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4694 | child2->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4695 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4696 | // Verify results of transformed child and child2 rects. They should |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4697 | // match. |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4698 | gfx::RectF child_bounds(gfx::SizeF(child->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4699 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4700 | gfx::RectF child_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4701 | MathUtil::MapClippedRect(child->DrawTransform(), child_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4702 | gfx::RectF child_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4703 | MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4704 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4705 | gfx::RectF child2_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4706 | MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4707 | gfx::RectF child2_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4708 | MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4709 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4710 | gfx::RectF expected_child_draw_rect(child->position(), |
| 4711 | gfx::SizeF(child->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4712 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4713 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4714 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4715 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect); |
| 4716 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4717 | } |
| 4718 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4719 | TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4720 | // Verify draw and screen space transforms of layers in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4721 | gfx::Transform perspective_matrix; |
| 4722 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4723 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4724 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4725 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4726 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4727 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4728 | root->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4729 | |
| 4730 | LayerImpl* page_scale = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4731 | page_scale->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4732 | |
| 4733 | LayerImpl* parent = AddChild<LayerImpl>(page_scale); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4734 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4735 | parent->SetDrawsContent(true); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4736 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4737 | LayerImpl* perspective_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4738 | perspective_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4739 | perspective_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4740 | perspective_surface->test_properties()->transform = |
| 4741 | perspective_matrix * scale_small_matrix; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4742 | perspective_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4743 | perspective_surface->test_properties()->force_render_surface = true; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4744 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4745 | LayerImpl* scale_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4746 | scale_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4747 | scale_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4748 | scale_surface->test_properties()->transform = scale_small_matrix; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4749 | scale_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4750 | scale_surface->test_properties()->force_render_surface = true; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4751 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4752 | float device_scale_factor = 2.5f; |
| 4753 | float page_scale_factor = 3.f; |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4754 | root->layer_tree_impl()->SetViewportLayersFromIds( |
| 4755 | Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, |
| 4756 | Layer::INVALID_ID); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4757 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4758 | root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4759 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4760 | root, nullptr, nullptr); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4761 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4762 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4763 | parent->GetIdealContentsScale()); |
| 4764 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4765 | perspective_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4766 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4767 | // the nearest render target. Here this includes the layer transform as well |
| 4768 | // as the device and page scale factors. |
| 4769 | gfx::Transform transform = scale_small_matrix; |
| 4770 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4771 | device_scale_factor * page_scale_factor); |
| 4772 | gfx::Vector2dF scales = |
| 4773 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4774 | float max_2d_scale = std::max(scales.x(), scales.y()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4775 | EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4776 | |
| 4777 | // The ideal scale will draw 1:1 with its render target space along |
| 4778 | // the larger-scale axis. |
| 4779 | gfx::Vector2dF target_space_transform_scales = |
| 4780 | MathUtil::ComputeTransform2dScaleComponents( |
| 4781 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4782 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4783 | std::max(target_space_transform_scales.x(), |
| 4784 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4785 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4786 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4787 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4788 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4789 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4790 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4791 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4792 | parent->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4793 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4794 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4795 | // with the screen, and then scaled during drawing. |
| 4796 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4797 | expected_perspective_surface_draw_transform.Translate( |
| 4798 | device_scale_factor * page_scale_factor * |
| 4799 | perspective_surface->position().x(), |
| 4800 | device_scale_factor * page_scale_factor * |
| 4801 | perspective_surface->position().y()); |
| 4802 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4803 | perspective_matrix); |
| 4804 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4805 | scale_small_matrix); |
| 4806 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4807 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4808 | device_scale_factor * page_scale_factor, |
| 4809 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4810 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4811 | expected_perspective_surface_draw_transform, |
| 4812 | perspective_surface->render_surface()->draw_transform()); |
| 4813 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4814 | expected_perspective_surface_layer_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4815 | perspective_surface->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4816 | } |
| 4817 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4818 | TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4819 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4820 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4821 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4822 | |
| 4823 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4824 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4825 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4826 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4827 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4828 | root->SetBounds(gfx::Size(100, 100)); |
| 4829 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4830 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4831 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4832 | parent->test_properties()->transform = parent_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4833 | parent->SetDrawsContent(true); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4834 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4835 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4836 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4837 | child_scale->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4838 | child_scale->test_properties()->transform = child_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4839 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4840 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4841 | float device_scale_factor = 2.5f; |
| 4842 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4843 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4844 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4845 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 4846 | root, nullptr, nullptr); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4847 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4848 | // The ideal scale is able to go below 1. |
| 4849 | float expected_ideal_scale = |
| 4850 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4851 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4852 | EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale()); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4853 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4854 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4855 | initial_parent_scale * initial_child_scale; |
| 4856 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4857 | EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4858 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4859 | } |
| 4860 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4861 | TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4862 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4863 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4864 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4865 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4866 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4867 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4868 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4869 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4870 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4871 | root->SetBounds(gfx::Size(100, 100)); |
| 4872 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4873 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4874 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4875 | parent->test_properties()->transform = parent_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4876 | parent->SetDrawsContent(true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4877 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4878 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4879 | child_scale->SetBounds(gfx::Size(10, 10)); |
| 4880 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4881 | child_scale->test_properties()->transform = child_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4882 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4883 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4884 | ExecuteCalculateDrawProperties(root); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4885 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4886 | EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4887 | // Animating layers compute ideal scale in the same way as when |
| 4888 | // they are static. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4889 | EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale, |
| 4890 | child_scale->GetIdealContentsScale()); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4891 | } |
| 4892 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4893 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4894 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4895 | parent->SetBounds(gfx::Size(30, 30)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4896 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4897 | parent->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 4898 | parent->test_properties()->sorting_context_id = 1; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4899 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4900 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4901 | child->SetBounds(gfx::Size(10, 10)); |
| 4902 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4903 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4904 | child->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4905 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4906 | // This layer should end up in the same surface as child, with the same draw |
| 4907 | // and screen space transforms. |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4908 | LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4909 | duplicate_child_non_owner->SetBounds(gfx::Size(10, 10)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4910 | duplicate_child_non_owner->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4911 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4912 | float device_scale_factor = 1.5f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4913 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4914 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4915 | // We should have two render surfaces. The root's render surface and child's |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4916 | // render surface (it needs one because of force_render_surface). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4917 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4918 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4919 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4920 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4921 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4922 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4923 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4924 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4925 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4926 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4927 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4928 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4929 | child->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4930 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4931 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4932 | expected_screen_space_transform.Scale(device_scale_factor, |
| 4933 | device_scale_factor); |
| 4934 | expected_screen_space_transform.Translate(child->position().x(), |
| 4935 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4936 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4937 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4938 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4939 | gfx::Transform expected_duplicate_child_draw_transform = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4940 | child->DrawTransform(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4941 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4942 | duplicate_child_non_owner->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4943 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4944 | child->ScreenSpaceTransform(), |
| 4945 | duplicate_child_non_owner->ScreenSpaceTransform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4946 | EXPECT_EQ(child->drawable_content_rect(), |
| 4947 | duplicate_child_non_owner->drawable_content_rect()); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4948 | EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4949 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4950 | gfx::Transform expected_render_surface_draw_transform; |
| 4951 | expected_render_surface_draw_transform.Translate( |
| 4952 | device_scale_factor * child->position().x(), |
| 4953 | device_scale_factor * child->position().y()); |
| 4954 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 4955 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4956 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4957 | gfx::Transform expected_surface_draw_transform; |
| 4958 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 4959 | device_scale_factor * 2.f); |
| 4960 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 4961 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4962 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4963 | gfx::Transform expected_surface_screen_space_transform; |
| 4964 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 4965 | device_scale_factor * 2.f); |
| 4966 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4967 | expected_surface_screen_space_transform, |
| 4968 | child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4969 | } |
| 4970 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4971 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4972 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4973 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4974 | parent->SetBounds(gfx::Size(33, 31)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4975 | parent->SetDrawsContent(true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4976 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4977 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4978 | child->SetBounds(gfx::Size(13, 11)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4979 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4980 | child->test_properties()->force_render_surface = true; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4981 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 4982 | float device_scale_factor = 1.7f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4983 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4984 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4985 | // We should have two render surfaces. The root's render surface and child's |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4986 | // render surface (it needs one because of force_render_surface). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4987 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4988 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4989 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4990 | child->render_surface()->draw_transform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4991 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4992 | child->render_surface()->draw_transform()); |
| 4993 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4994 | gfx::Transform(), child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4995 | } |
| 4996 | |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 4997 | TEST_F(LayerTreeHostCommonTest, LayerSearch) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4998 | scoped_refptr<Layer> root = Layer::Create(); |
| 4999 | scoped_refptr<Layer> child = Layer::Create(); |
| 5000 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5001 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5002 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5003 | child->AddChild(grand_child.get()); |
| 5004 | child->SetMaskLayer(mask_layer.get()); |
| 5005 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5006 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 5007 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5008 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5009 | int nonexistent_id = -1; |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 5010 | EXPECT_EQ(root.get(), host()->LayerById(root->id())); |
| 5011 | EXPECT_EQ(child.get(), host()->LayerById(child->id())); |
| 5012 | EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id())); |
| 5013 | EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id())); |
| 5014 | EXPECT_FALSE(host()->LayerById(nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5015 | } |
| 5016 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5017 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5018 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 5019 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 5020 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5021 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5022 | root->SetBounds(gfx::Size(100, 100)); |
| 5023 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5024 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5025 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 5026 | grand_child->SetDrawsContent(true); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 5027 | ExecuteCalculateDrawProperties(root); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 5028 | EXPECT_FALSE(child->has_render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5029 | } |
| 5030 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5031 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5032 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5033 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 5034 | FakeLayerTreeHostImpl host_impl(host()->GetSettings(), &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 5035 | &task_graph_runner); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5036 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5037 | std::unique_ptr<LayerImpl> root = |
| 5038 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5039 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5040 | root->SetDrawsContent(true); |
| 5041 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5042 | std::unique_ptr<LayerImpl> child = |
| 5043 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5044 | child->SetBounds(gfx::Size(50, 50)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5045 | child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5046 | child->test_properties()->opacity = 0.0f; |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5047 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 5048 | const int child_id = child->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5049 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 5050 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5051 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 5052 | host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5053 | |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5054 | // Add opacity animation. |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5055 | scoped_refptr<AnimationTimeline> timeline = |
| 5056 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 5057 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5058 | host_impl.pending_tree()->SetElementIdsForTesting(); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5059 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5060 | ElementId child_element_id = |
| 5061 | host_impl.pending_tree()->LayerById(child_id)->element_id(); |
| 5062 | |
| 5063 | AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0, |
| 5064 | 0.0f, 1.0f, false); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5065 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5066 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5067 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5068 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5069 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5070 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5071 | |
| 5072 | // We should have one render surface and two layers. The child |
| 5073 | // layer should be included even though it is transparent. |
| 5074 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5075 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5076 | |
| 5077 | // If the root itself is hidden, the child should not be drawn even if it has |
| 5078 | // an animating opacity. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5079 | root_layer->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5080 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5081 | LayerImplList render_surface_layer_list2; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5082 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5083 | root_layer, root_layer->bounds(), &render_surface_layer_list2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5084 | inputs2.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5085 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5086 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5087 | LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5088 | EffectTree& tree = |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5089 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5090 | EffectNode* node = tree.Node(child_ptr->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5091 | EXPECT_FALSE(node->is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5092 | |
| 5093 | // A layer should be drawn and it should contribute to drawn surface when |
| 5094 | // it has animating opacity even if it has opacity 0. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5095 | root_layer->test_properties()->opacity = 1.0f; |
| 5096 | child_ptr->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5097 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5098 | LayerImplList render_surface_layer_list3; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5099 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5100 | root_layer, root_layer->bounds(), &render_surface_layer_list3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5101 | inputs3.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5102 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5103 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5104 | child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
| 5105 | tree = root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5106 | node = tree.Node(child_ptr->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5107 | EXPECT_TRUE(node->is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5108 | EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index())); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5109 | |
| 5110 | // But if the opacity of the layer remains 0 after activation, it should not |
| 5111 | // be drawn. |
| 5112 | host_impl.ActivateSyncTree(); |
danakj | 0da42ca6 | 2016-07-01 19:42:33 | [diff] [blame] | 5113 | LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id()); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5114 | LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id()); |
| 5115 | |
| 5116 | EffectTree& active_effect_tree = |
| 5117 | host_impl.active_tree()->property_trees()->effect_tree; |
| 5118 | EXPECT_TRUE(active_effect_tree.needs_update()); |
| 5119 | |
| 5120 | ExecuteCalculateDrawProperties(active_root); |
| 5121 | |
| 5122 | node = active_effect_tree.Node(active_child->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5123 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5124 | EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface( |
| 5125 | active_child->effect_tree_index())); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5126 | } |
| 5127 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5128 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 5129 | class LCDTextTest : public LayerTreeHostCommonTestBase, |
| 5130 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5131 | public: |
| 5132 | LCDTextTest() |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5133 | : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()), |
| 5134 | host_impl_(LCDTextTestLayerTreeSettings(), |
| 5135 | &task_runner_provider_, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5136 | &task_graph_runner_) {} |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5137 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5138 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 5139 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5140 | protected: |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5141 | LayerTreeSettings LCDTextTestLayerTreeSettings() { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5142 | LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings(); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5143 | |
| 5144 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
| 5145 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
| 5146 | settings.can_use_lcd_text = can_use_lcd_text_; |
| 5147 | settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_; |
| 5148 | return settings; |
| 5149 | } |
| 5150 | |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 5151 | void SetUp() override { |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5152 | timeline_ = |
| 5153 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 5154 | host_impl_.animation_host()->AddAnimationTimeline(timeline_); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5155 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5156 | std::unique_ptr<LayerImpl> root_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5157 | LayerImpl::Create(host_impl_.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5158 | std::unique_ptr<LayerImpl> child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5159 | LayerImpl::Create(host_impl_.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5160 | std::unique_ptr<LayerImpl> grand_child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5161 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 5162 | |
| 5163 | // Stash raw pointers to look at later. |
| 5164 | root_ = root_ptr.get(); |
| 5165 | child_ = child_ptr.get(); |
| 5166 | grand_child_ = grand_child_ptr.get(); |
| 5167 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5168 | child_->test_properties()->AddChild(std::move(grand_child_ptr)); |
| 5169 | root_->test_properties()->AddChild(std::move(child_ptr)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5170 | host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5171 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5172 | host_impl_.active_tree()->SetElementIdsForTesting(); |
| 5173 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5174 | root_->SetContentsOpaque(true); |
| 5175 | child_->SetContentsOpaque(true); |
| 5176 | grand_child_->SetContentsOpaque(true); |
| 5177 | |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5178 | root_->SetDrawsContent(true); |
| 5179 | child_->SetDrawsContent(true); |
| 5180 | grand_child_->SetDrawsContent(true); |
| 5181 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5182 | root_->SetBounds(gfx::Size(1, 1)); |
| 5183 | child_->SetBounds(gfx::Size(1, 1)); |
| 5184 | grand_child_->SetBounds(gfx::Size(1, 1)); |
| 5185 | |
| 5186 | child_->test_properties()->force_render_surface = |
| 5187 | std::tr1::get<2>(GetParam()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5188 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5189 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5190 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5191 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5192 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5193 | FakeImplTaskRunnerProvider task_runner_provider_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5194 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5195 | FakeLayerTreeHostImpl host_impl_; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5196 | scoped_refptr<AnimationTimeline> timeline_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5197 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5198 | LayerImpl* root_ = nullptr; |
| 5199 | LayerImpl* child_ = nullptr; |
| 5200 | LayerImpl* grand_child_ = nullptr; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5201 | }; |
| 5202 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5203 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5204 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5205 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5206 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5207 | // Case 1: Identity transform. |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5208 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5209 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5210 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5211 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5212 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5213 | // Case 2: Integral translation. |
| 5214 | gfx::Transform integral_translation; |
| 5215 | integral_translation.Translate(1.0, 2.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5216 | child_->test_properties()->transform = integral_translation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5217 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5218 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5219 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5220 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5221 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5222 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5223 | // Case 3: Non-integral translation. |
| 5224 | gfx::Transform non_integral_translation; |
| 5225 | non_integral_translation.Translate(1.5, 2.5); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5226 | child_->test_properties()->transform = non_integral_translation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5227 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5228 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5229 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5230 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5231 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5232 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5233 | // Case 4: Rotation. |
| 5234 | gfx::Transform rotation; |
| 5235 | rotation.Rotate(10.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5236 | child_->test_properties()->transform = rotation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5237 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5238 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5239 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5240 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5241 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5242 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5243 | // Case 5: Scale. |
| 5244 | gfx::Transform scale; |
| 5245 | scale.Scale(2.0, 2.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5246 | child_->test_properties()->transform = scale; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5247 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5248 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5249 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5250 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5251 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5252 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5253 | // Case 6: Skew. |
| 5254 | gfx::Transform skew; |
nainar | 8ca8ee6 | 2015-09-03 01:04:10 | [diff] [blame] | 5255 | skew.Skew(10.0, 0.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5256 | child_->test_properties()->transform = skew; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5257 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5258 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5259 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5260 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5261 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5262 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5263 | // Case 7: Translucent. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5264 | child_->test_properties()->transform = gfx::Transform(); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5265 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5266 | child_->test_properties()->opacity = 0.5f; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5267 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5268 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5269 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5270 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5271 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5272 | // Case 8: Sanity check: restore transform and opacity. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5273 | child_->test_properties()->transform = gfx::Transform(); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5274 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5275 | child_->test_properties()->opacity = 1.f; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5276 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5277 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5278 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5279 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5280 | |
| 5281 | // Case 9: Non-opaque content. |
| 5282 | child_->SetContentsOpaque(false); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5283 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5284 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5285 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5286 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5287 | |
| 5288 | // Case 10: Sanity check: restore content opaqueness. |
| 5289 | child_->SetContentsOpaque(true); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5290 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5291 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5292 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5293 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5294 | } |
| 5295 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5296 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5297 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5298 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5299 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5300 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5301 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5302 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5303 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5304 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5305 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5306 | // Add opacity animation. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5307 | child_->test_properties()->opacity = 0.9f; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5308 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5309 | |
| 5310 | SetElementIdsForTesting(); |
| 5311 | |
| 5312 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5313 | 10.0, 0.9f, 0.1f, false); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5314 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5315 | // Text LCD should be adjusted while animation is active. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5316 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5317 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5318 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 5322 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5323 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5324 | |
| 5325 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5326 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5327 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5328 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5329 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5330 | SetElementIdsForTesting(); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5331 | |
| 5332 | // Mark contents non-opaque within the first animation frame. |
| 5333 | child_->SetContentsOpaque(false); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5334 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5335 | 10.0, 0.9f, 0.1f, false); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 5336 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5337 | // LCD text should be disabled for non-opaque layers even during animations. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5338 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5339 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5340 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5341 | } |
| 5342 | |
| 5343 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5344 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5345 | testing::Combine(testing::Bool(), |
| 5346 | testing::Bool(), |
| 5347 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5348 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5349 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5350 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5351 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 5352 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5353 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5354 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5355 | std::unique_ptr<LayerImpl> root = |
| 5356 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5357 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5358 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5359 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5360 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5361 | std::unique_ptr<LayerImpl> child = |
| 5362 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5363 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5364 | child->SetDrawsContent(true); |
| 5365 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5366 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5367 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5368 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5369 | grand_child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5370 | grand_child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5371 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5372 | child->test_properties()->AddChild(std::move(grand_child)); |
| 5373 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5374 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5375 | |
| 5376 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5377 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5378 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5379 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5380 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5381 | |
| 5382 | // We should have one render surface and two layers. The grand child has |
| 5383 | // hidden itself. |
| 5384 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5385 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5386 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
| 5387 | EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5388 | } |
| 5389 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5390 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5391 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5392 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 5393 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5394 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5395 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5396 | std::unique_ptr<LayerImpl> root = |
| 5397 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5398 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5399 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5400 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5401 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5402 | std::unique_ptr<LayerImpl> child = |
| 5403 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5404 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5405 | child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5406 | child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5407 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5408 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5409 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5410 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5411 | grand_child->SetDrawsContent(true); |
| 5412 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5413 | child->test_properties()->AddChild(std::move(grand_child)); |
| 5414 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5415 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5416 | |
| 5417 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5418 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5419 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5420 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5421 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5422 | |
| 5423 | // We should have one render surface and one layers. The child has |
| 5424 | // hidden itself and the grand child. |
| 5425 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5426 | ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size()); |
| 5427 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5428 | } |
| 5429 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5430 | void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5431 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5432 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5433 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5434 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 5435 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5436 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5437 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5438 | std::unique_ptr<LayerImpl> root = |
| 5439 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5440 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5441 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5442 | LayerImpl* root_layer = root.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5443 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5444 | std::unique_ptr<LayerImpl> copy_grand_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5445 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5446 | copy_grand_parent->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5447 | copy_grand_parent->SetDrawsContent(true); |
| 5448 | LayerImpl* copy_grand_parent_layer = copy_grand_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5449 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5450 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5451 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5452 | copy_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5453 | copy_parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5454 | copy_parent->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5455 | LayerImpl* copy_parent_layer = copy_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5456 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5457 | std::unique_ptr<LayerImpl> copy_request = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5458 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5459 | copy_request->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5460 | copy_request->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5461 | copy_request->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5462 | LayerImpl* copy_layer = copy_request.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5463 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5464 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5465 | LayerImpl::Create(host_impl.pending_tree(), 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5466 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5467 | copy_child->SetDrawsContent(true); |
| 5468 | LayerImpl* copy_child_layer = copy_child.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5469 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5470 | std::unique_ptr<LayerImpl> copy_grand_child = |
thakis | e53c527 | 2016-01-24 01:20:40 | [diff] [blame] | 5471 | LayerImpl::Create(host_impl.pending_tree(), 6); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5472 | copy_grand_child->SetBounds(gfx::Size(20, 20)); |
| 5473 | copy_grand_child->SetDrawsContent(true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5474 | LayerImpl* copy_grand_child_layer = copy_grand_child.get(); |
| 5475 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5476 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5477 | LayerImpl::Create(host_impl.pending_tree(), 7); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5478 | copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5479 | copy_grand_parent_sibling_before->SetDrawsContent(true); |
| 5480 | LayerImpl* copy_grand_parent_sibling_before_layer = |
| 5481 | copy_grand_parent_sibling_before.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5482 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5483 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5484 | LayerImpl::Create(host_impl.pending_tree(), 8); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5485 | copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5486 | copy_grand_parent_sibling_after->SetDrawsContent(true); |
| 5487 | LayerImpl* copy_grand_parent_sibling_after_layer = |
| 5488 | copy_grand_parent_sibling_after.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5489 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5490 | copy_child->test_properties()->AddChild(std::move(copy_grand_child)); |
| 5491 | copy_request->test_properties()->AddChild(std::move(copy_child)); |
| 5492 | copy_parent->test_properties()->AddChild(std::move(copy_request)); |
| 5493 | copy_grand_parent->test_properties()->AddChild(std::move(copy_parent)); |
| 5494 | root->test_properties()->AddChild( |
| 5495 | std::move(copy_grand_parent_sibling_before)); |
| 5496 | root->test_properties()->AddChild(std::move(copy_grand_parent)); |
| 5497 | root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5498 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5499 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5500 | // 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] | 5501 | // hidden subtree on copy_layer. Also hide the copy grand child and its |
| 5502 | // subtree. |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5503 | copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true; |
| 5504 | copy_grand_parent_sibling_before_layer->test_properties() |
| 5505 | ->hide_layer_and_subtree = true; |
| 5506 | copy_grand_parent_sibling_after_layer->test_properties() |
| 5507 | ->hide_layer_and_subtree = true; |
| 5508 | copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5509 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5510 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5511 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5512 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5513 | LayerImplList render_surface_layer_list; |
| 5514 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5515 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5516 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5517 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5518 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5519 | EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 5520 | EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5521 | EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5522 | EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5523 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5524 | // We should have four render surfaces, one for the root, one for the grand |
| 5525 | // parent since it has opacity and two drawing descendants, one for the parent |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5526 | // since it owns a surface, and one for the copy_layer. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5527 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5528 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5529 | EXPECT_EQ(copy_grand_parent_layer->id(), |
| 5530 | render_surface_layer_list.at(1)->id()); |
| 5531 | EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id()); |
| 5532 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5533 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5534 | // The root render surface should have 2 contributing layers. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5535 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5536 | EXPECT_EQ(root_layer->id(), |
| 5537 | root_layer->render_surface()->layer_list().at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5538 | EXPECT_EQ(copy_grand_parent_layer->id(), |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5539 | root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5540 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 5541 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5542 | // appear in its list, since it needs to be drawn for the copy request. |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5543 | ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5544 | EXPECT_EQ(copy_layer->id(), |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5545 | copy_parent_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5546 | |
| 5547 | // The copy_layer's render surface should have two contributing layers. |
| 5548 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 5549 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5550 | copy_layer->render_surface()->layer_list().at(0)->id()); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5551 | EXPECT_EQ(copy_child_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5552 | copy_layer->render_surface()->layer_list().at(1)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5553 | |
| 5554 | // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden, |
| 5555 | // but the copy_layer and copy_child should be drawn for the copy request. |
| 5556 | // copy grand child should not be drawn as its hidden even in the copy |
| 5557 | // request. |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 5558 | EffectTree& tree = |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5559 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5560 | EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5561 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5562 | node = tree.Node(copy_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5563 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5564 | node = tree.Node(copy_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5565 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5566 | node = tree.Node(copy_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5567 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5568 | node = tree.Node(copy_grand_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5569 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5570 | |
| 5571 | // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its |
| 5572 | // actually hidden. |
| 5573 | EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5574 | } |
| 5575 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5576 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5577 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5578 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 5579 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5580 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5581 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5582 | std::unique_ptr<LayerImpl> root = |
| 5583 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5584 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5585 | root->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5586 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5587 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5588 | LayerImpl::Create(host_impl.pending_tree(), 2); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5589 | copy_parent->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5590 | copy_parent->SetMasksToBounds(true); |
| 5591 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5592 | std::unique_ptr<LayerImpl> copy_layer = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5593 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5594 | copy_layer->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5595 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5596 | copy_layer->test_properties()->force_render_surface = true; |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5597 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5598 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5599 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5600 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5601 | copy_child->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5602 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5603 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5604 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5605 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5606 | copy_layer->test_properties()->AddChild(std::move(copy_child)); |
| 5607 | copy_parent->test_properties()->AddChild(std::move(copy_layer)); |
| 5608 | root->test_properties()->AddChild(std::move(copy_parent)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5609 | |
| 5610 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5611 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5612 | root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5613 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5614 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5615 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5616 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5617 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5618 | // We should have two render surface, as the others are clipped out. |
| 5619 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5620 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5621 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5622 | // The root render surface should only have 2 contributing layer, since the |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5623 | // other layers are empty/clipped away. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5624 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5625 | EXPECT_EQ(root_layer->id(), |
| 5626 | root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5627 | } |
| 5628 | |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5629 | TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5630 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5631 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5632 | root->SetDrawsContent(true); |
| 5633 | root->SetMasksToBounds(true); |
| 5634 | |
| 5635 | LayerImpl* copy_layer = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5636 | copy_layer->SetBounds(gfx::Size(100, 100)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5637 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5638 | copy_layer->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5639 | |
| 5640 | LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5641 | copy_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5642 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5643 | copy_child->SetDrawsContent(true); |
| 5644 | |
| 5645 | LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5646 | copy_clip->SetBounds(gfx::Size(55, 55)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5647 | copy_clip->SetMasksToBounds(true); |
| 5648 | |
| 5649 | LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5650 | copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5651 | copy_clipped_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5652 | copy_clipped_child->SetDrawsContent(true); |
| 5653 | |
| 5654 | LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5655 | copy_surface->SetPosition(gfx::PointF(45.f, 45.f)); |
| 5656 | copy_surface->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5657 | copy_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5658 | copy_surface->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5659 | |
| 5660 | copy_layer->test_properties()->copy_requests.push_back( |
| 5661 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5662 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5663 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5664 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5665 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5666 | |
| 5667 | EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect()); |
| 5668 | EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect()); |
| 5669 | EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect()); |
| 5670 | EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect()); |
| 5671 | |
| 5672 | // Case 2: When the non root copy request layer is clipped. |
| 5673 | copy_layer->SetBounds(gfx::Size(50, 50)); |
| 5674 | copy_layer->SetMasksToBounds(true); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5675 | copy_layer->test_properties()->copy_requests.push_back( |
| 5676 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5677 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5678 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5679 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5680 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5681 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5682 | |
| 5683 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5684 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5685 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5686 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | 296dd9f | 2016-07-05 14:59:51 | [diff] [blame] | 5687 | |
| 5688 | // Case 3: When there is device scale factor. |
| 5689 | float device_scale_factor = 2.f; |
| 5690 | copy_layer->test_properties()->copy_requests.push_back( |
| 5691 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5692 | |
| 5693 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
| 5694 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 5695 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
| 5696 | |
| 5697 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5698 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5699 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5700 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5701 | } |
| 5702 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5703 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 5704 | // Ensure that a transform between the layer and its render surface is not a |
| 5705 | // problem. Constructs the following layer tree. |
| 5706 | // |
| 5707 | // root (a render surface) |
| 5708 | // + render_surface |
| 5709 | // + clip_parent (scaled) |
| 5710 | // + intervening_clipping_layer |
| 5711 | // + clip_child |
| 5712 | // |
| 5713 | // The render surface should be resized correctly and the clip child should |
| 5714 | // inherit the right clip rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5715 | LayerImpl* root = root_layer_for_testing(); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5716 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 5717 | LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5718 | clip_parent->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5719 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5720 | intervening->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5721 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5722 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5723 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5724 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5725 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5726 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5727 | |
| 5728 | intervening->SetMasksToBounds(true); |
| 5729 | clip_parent->SetMasksToBounds(true); |
| 5730 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5731 | gfx::Transform scale_transform; |
| 5732 | scale_transform.Scale(2, 2); |
| 5733 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5734 | root->SetBounds(gfx::Size(50, 50)); |
| 5735 | render_surface->SetBounds(gfx::Size(10, 10)); |
| 5736 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5737 | clip_parent->test_properties()->transform = scale_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5738 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5739 | clip_parent->SetBounds(gfx::Size(10, 10)); |
| 5740 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5741 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5742 | clip_child->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5743 | clip_child->SetBounds(gfx::Size(10, 10)); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5744 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5745 | |
| 5746 | ASSERT_TRUE(root->render_surface()); |
| 5747 | ASSERT_TRUE(render_surface->render_surface()); |
| 5748 | |
| 5749 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 5750 | // by the intervening clip layer. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5751 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect()); |
| 5752 | ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect()); |
| 5753 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5754 | |
| 5755 | // Ensure that the render surface reports a content rect that has been grown |
| 5756 | // to accomodate for the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5757 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), |
| 5758 | render_surface->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5759 | |
| 5760 | // The above check implies the two below, but they nicely demonstrate that |
| 5761 | // we've grown, despite the intervening layer's clip. |
| 5762 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 5763 | render_surface->render_surface()->content_rect())); |
| 5764 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 5765 | render_surface->render_surface()->content_rect())); |
| 5766 | } |
| 5767 | |
| 5768 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 5769 | // Ensure that intervening render surfaces are not a problem in the basic |
| 5770 | // case. In the following tree, both render surfaces should be resized to |
| 5771 | // accomodate for the clip child, despite an intervening clip. |
| 5772 | // |
| 5773 | // root (a render surface) |
| 5774 | // + clip_parent (masks to bounds) |
| 5775 | // + render_surface1 (sets opacity) |
| 5776 | // + intervening (masks to bounds) |
| 5777 | // + render_surface2 (also sets opacity) |
| 5778 | // + clip_child |
| 5779 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5780 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5781 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5782 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5783 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5784 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5785 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5786 | render_surface1->SetDrawsContent(true); |
| 5787 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5788 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5789 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5790 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5791 | |
| 5792 | intervening->SetMasksToBounds(true); |
| 5793 | clip_parent->SetMasksToBounds(true); |
| 5794 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5795 | gfx::Transform translation_transform; |
| 5796 | translation_transform.Translate(2, 2); |
| 5797 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5798 | root->SetBounds(gfx::Size(50, 50)); |
| 5799 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5800 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5801 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5802 | render_surface1->test_properties()->force_render_surface = true; |
| 5803 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5804 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5805 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5806 | render_surface2->test_properties()->force_render_surface = true; |
| 5807 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5808 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5809 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5810 | |
| 5811 | EXPECT_TRUE(root->render_surface()); |
| 5812 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5813 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5814 | |
| 5815 | // Since the render surfaces could have expanded, they should not clip (their |
| 5816 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5817 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5818 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5819 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5820 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5821 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5822 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5823 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5824 | |
| 5825 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5826 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5827 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5828 | |
| 5829 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5830 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5831 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5832 | |
| 5833 | // The content rects of both render surfaces should both have expanded to |
| 5834 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5835 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5836 | render_surface1->render_surface()->content_rect()); |
| 5837 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), |
| 5838 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5839 | |
| 5840 | // The clip child should have inherited the clip parent's clip (projected to |
| 5841 | // the right space, of course), and should have the correctly sized visible |
| 5842 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5843 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect()); |
| 5844 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5845 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5846 | } |
| 5847 | |
| 5848 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 5849 | // Ensure that intervening render surfaces are not a problem, even if there |
| 5850 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 5851 | // of transform. |
| 5852 | // |
| 5853 | // root (a render surface) |
| 5854 | // + clip_parent (masks to bounds) |
| 5855 | // + render_surface1 (sets opacity) |
| 5856 | // + intervening (masks to bounds AND scrolls) |
| 5857 | // + render_surface2 (also sets opacity) |
| 5858 | // + clip_child |
| 5859 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5860 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5861 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5862 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5863 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5864 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5865 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5866 | render_surface1->SetDrawsContent(true); |
| 5867 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5868 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5869 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5870 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5871 | |
| 5872 | intervening->SetMasksToBounds(true); |
| 5873 | clip_parent->SetMasksToBounds(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5874 | intervening->SetScrollClipLayer(clip_parent->id()); |
| 5875 | intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5876 | |
| 5877 | gfx::Transform translation_transform; |
| 5878 | translation_transform.Translate(2, 2); |
| 5879 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5880 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5881 | clip_parent->test_properties()->transform = translation_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5882 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5883 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5884 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5885 | render_surface1->test_properties()->force_render_surface = true; |
| 5886 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5887 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5888 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5889 | render_surface2->test_properties()->force_render_surface = true; |
| 5890 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5891 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5892 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5893 | |
| 5894 | EXPECT_TRUE(root->render_surface()); |
| 5895 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5896 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5897 | |
| 5898 | // Since the render surfaces could have expanded, they should not clip (their |
| 5899 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5900 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5901 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5902 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5903 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5904 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5905 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5906 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5907 | |
| 5908 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5909 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5910 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5911 | |
| 5912 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5913 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5914 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5915 | |
| 5916 | // The content rects of both render surfaces should both have expanded to |
| 5917 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5918 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5919 | render_surface1->render_surface()->content_rect()); |
| 5920 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), |
| 5921 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5922 | |
| 5923 | // The clip child should have inherited the clip parent's clip (projected to |
| 5924 | // the right space, of course), and should have the correctly sized visible |
| 5925 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5926 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect()); |
| 5927 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5928 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5929 | } |
| 5930 | |
| 5931 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 5932 | // Ensures that descendants of the clip child inherit the correct clip. |
| 5933 | // |
| 5934 | // root (a render surface) |
| 5935 | // + clip_parent (masks to bounds) |
| 5936 | // + intervening (masks to bounds) |
| 5937 | // + clip_child |
| 5938 | // + child |
| 5939 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5940 | LayerImpl* root = root_layer_for_testing(); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5941 | LayerImpl* clip_parent = AddChild<LayerImpl>(root); |
| 5942 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
| 5943 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5944 | LayerImpl* child = AddChild<LayerImpl>(clip_child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5945 | clip_child->SetDrawsContent(true); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5946 | child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5947 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5948 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5949 | clip_parent->test_properties()->clip_children = |
| 5950 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5951 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5952 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5953 | root->SetBounds(gfx::Size(50, 50)); |
| 5954 | clip_parent->SetBounds(gfx::Size(40, 40)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5955 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5956 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5957 | intervening->SetMasksToBounds(true); |
| 5958 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 5959 | child->SetBounds(gfx::Size(60, 60)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5960 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5961 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5962 | |
| 5963 | EXPECT_TRUE(root->render_surface()); |
| 5964 | |
| 5965 | // Neither the clip child nor its descendant should have inherited the clip |
| 5966 | // from |intervening|. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5967 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5968 | EXPECT_TRUE(clip_child->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5969 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5970 | EXPECT_TRUE(child->is_clipped()); |
| 5971 | } |
| 5972 | |
| 5973 | TEST_F(LayerTreeHostCommonTest, |
| 5974 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 5975 | // Ensures that non-descendant clip children in the tree do not affect |
| 5976 | // render surfaces. |
| 5977 | // |
| 5978 | // root (a render surface) |
| 5979 | // + clip_parent (masks to bounds) |
| 5980 | // + render_surface1 |
| 5981 | // + clip_child |
| 5982 | // + render_surface2 |
| 5983 | // + non_clip_child |
| 5984 | // |
| 5985 | // In this example render_surface2 should be unaffected by clip_child. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5986 | LayerImpl* root = root_layer_for_testing(); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5987 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5988 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5989 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5990 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent); |
| 5991 | LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5992 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5993 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5994 | clip_parent->test_properties()->clip_children = |
| 5995 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5996 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5997 | |
| 5998 | clip_parent->SetMasksToBounds(true); |
| 5999 | render_surface1->SetMasksToBounds(true); |
| 6000 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6001 | render_surface1->SetDrawsContent(true); |
| 6002 | clip_child->SetDrawsContent(true); |
| 6003 | render_surface2->SetDrawsContent(true); |
| 6004 | non_clip_child->SetDrawsContent(true); |
| 6005 | |
| 6006 | root->SetBounds(gfx::Size(15, 15)); |
| 6007 | clip_parent->SetBounds(gfx::Size(10, 10)); |
| 6008 | render_surface1->SetPosition(gfx::PointF(5, 5)); |
| 6009 | render_surface1->SetBounds(gfx::Size(5, 5)); |
| 6010 | render_surface1->test_properties()->force_render_surface = true; |
| 6011 | render_surface2->SetBounds(gfx::Size(5, 5)); |
| 6012 | render_surface2->test_properties()->force_render_surface = true; |
| 6013 | clip_child->SetPosition(gfx::PointF(-1, 1)); |
| 6014 | clip_child->SetBounds(gfx::Size(10, 10)); |
| 6015 | non_clip_child->SetBounds(gfx::Size(5, 5)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6016 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6017 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6018 | |
| 6019 | EXPECT_TRUE(root->render_surface()); |
| 6020 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6021 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6022 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6023 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6024 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6025 | |
| 6026 | // The render surface should not clip (it has unclipped descendants), instead |
| 6027 | // it should rely on layer clipping. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6028 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 6029 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6030 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6031 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6032 | // That said, it should have grown to accomodate the unclipped descendant and |
| 6033 | // its own size. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6034 | EXPECT_EQ(gfx::Rect(-1, 0, 6, 5), |
| 6035 | render_surface1->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6036 | |
| 6037 | // This render surface should clip. It has no unclipped descendants. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6038 | EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 6039 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6040 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 6041 | EXPECT_FALSE(render_surface2->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6042 | |
| 6043 | // It also shouldn't have grown to accomodate the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6044 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), |
| 6045 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6046 | |
| 6047 | // Sanity check our num_unclipped_descendants values. |
ajuma | 0641ded | 2016-05-05 21:28:21 | [diff] [blame] | 6048 | EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants); |
| 6049 | EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6050 | } |
| 6051 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6052 | TEST_F(LayerTreeHostCommonTest, |
| 6053 | CreateRenderSurfaceWhenFlattenInsideRenderingContext) { |
| 6054 | // Verifies that Render Surfaces are created at the edge of rendering context. |
| 6055 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6056 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6057 | LayerImpl* child1 = AddChildToRoot<LayerImpl>(); |
| 6058 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 6059 | LayerImpl* child3 = AddChild<LayerImpl>(child2); |
| 6060 | root->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6061 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6062 | gfx::Size bounds(100, 100); |
| 6063 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6064 | root->SetBounds(bounds); |
| 6065 | child1->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6066 | child1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6067 | child1->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6068 | child1->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6069 | child2->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6070 | child2->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6071 | child2->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6072 | child3->SetBounds(bounds); |
| 6073 | child3->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6074 | child3->test_properties()->sorting_context_id = 1; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 6075 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6076 | |
| 6077 | // Verify which render surfaces were created. |
| 6078 | EXPECT_TRUE(root->has_render_surface()); |
| 6079 | EXPECT_FALSE(child1->has_render_surface()); |
| 6080 | EXPECT_TRUE(child2->has_render_surface()); |
| 6081 | EXPECT_FALSE(child3->has_render_surface()); |
| 6082 | } |
| 6083 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6084 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6085 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6086 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 6087 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6088 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6089 | std::unique_ptr<LayerImpl> root = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6090 | LayerImpl::Create(host_impl.active_tree(), 12345); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6091 | std::unique_ptr<LayerImpl> child1 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6092 | LayerImpl::Create(host_impl.active_tree(), 123456); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6093 | std::unique_ptr<LayerImpl> child2 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6094 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6095 | std::unique_ptr<LayerImpl> child3 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6096 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 6097 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6098 | gfx::Size bounds(100, 100); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6099 | |
| 6100 | root->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6101 | root->SetDrawsContent(true); |
| 6102 | |
| 6103 | // This layer structure normally forces render surface due to preserves3d |
| 6104 | // behavior. |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6105 | child1->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6106 | child1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6107 | child1->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6108 | child1->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6109 | child2->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6110 | child2->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6111 | child2->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6112 | child3->SetBounds(bounds); |
| 6113 | child3->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6114 | child3->test_properties()->sorting_context_id = 1; |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6115 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6116 | child2->test_properties()->AddChild(std::move(child3)); |
| 6117 | child1->test_properties()->AddChild(std::move(child2)); |
| 6118 | root->test_properties()->AddChild(std::move(child1)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6119 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6120 | root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6121 | |
| 6122 | { |
| 6123 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6124 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6125 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6126 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6127 | inputs.can_render_to_separate_surface = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6128 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6129 | |
| 6130 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6131 | |
| 6132 | int count_represents_target_render_surface = 0; |
| 6133 | int count_represents_contributing_render_surface = 0; |
| 6134 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6135 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6136 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6137 | it != end; ++it) { |
| 6138 | if (it.represents_target_render_surface()) |
| 6139 | count_represents_target_render_surface++; |
| 6140 | if (it.represents_contributing_render_surface()) |
| 6141 | count_represents_contributing_render_surface++; |
| 6142 | if (it.represents_itself()) |
| 6143 | count_represents_itself++; |
| 6144 | } |
| 6145 | |
| 6146 | // Two render surfaces. |
| 6147 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 6148 | // Second render surface contributes to root render surface. |
| 6149 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 6150 | // All 4 layers represent itself. |
| 6151 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | { |
| 6155 | LayerImplList render_surface_layer_list; |
| 6156 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6157 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6158 | inputs.can_render_to_separate_surface = false; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6159 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6160 | |
| 6161 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6162 | |
| 6163 | int count_represents_target_render_surface = 0; |
| 6164 | int count_represents_contributing_render_surface = 0; |
| 6165 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6166 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6167 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6168 | it != end; ++it) { |
| 6169 | if (it.represents_target_render_surface()) |
| 6170 | count_represents_target_render_surface++; |
| 6171 | if (it.represents_contributing_render_surface()) |
| 6172 | count_represents_contributing_render_surface++; |
| 6173 | if (it.represents_itself()) |
| 6174 | count_represents_itself++; |
| 6175 | } |
| 6176 | |
| 6177 | // Only root layer has a render surface. |
| 6178 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 6179 | // No layer contributes a render surface to root render surface. |
| 6180 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 6181 | // All 4 layers represent itself. |
| 6182 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6183 | } |
| 6184 | } |
| 6185 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6186 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6187 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6188 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame] | 6189 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6190 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6191 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame] | 6192 | |
| 6193 | LayerImpl* flattener = AddChild<LayerImpl>(back_facing); |
| 6194 | LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6195 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6196 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6197 | child1->SetDrawsContent(true); |
| 6198 | child2->SetDrawsContent(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6199 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6200 | root->SetBounds(gfx::Size(50, 50)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6201 | back_facing->SetBounds(gfx::Size(50, 50)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6202 | back_facing->test_properties()->should_flatten_transform = false; |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame] | 6203 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6204 | render_surface1->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6205 | render_surface1->test_properties()->should_flatten_transform = false; |
| 6206 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6207 | render_surface1->test_properties()->double_sided = false; |
trchen | 7520478 | 2016-11-03 01:05:42 | [diff] [blame] | 6208 | child1->SetBounds(gfx::Size(20, 20)); |
| 6209 | |
| 6210 | flattener->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6211 | render_surface2->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6212 | render_surface2->test_properties()->should_flatten_transform = false; |
| 6213 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6214 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6215 | child2->SetBounds(gfx::Size(20, 20)); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6216 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6217 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6218 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6219 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6220 | EXPECT_EQ(2u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6221 | ->at(0) |
| 6222 | ->render_surface() |
| 6223 | ->layer_list() |
| 6224 | .size()); |
| 6225 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
| 6226 | ->at(1) |
| 6227 | ->render_surface() |
| 6228 | ->layer_list() |
| 6229 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6230 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6231 | gfx::Transform rotation_transform; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6232 | rotation_transform.RotateAboutXAxis(180.0); |
| 6233 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6234 | back_facing->test_properties()->transform = rotation_transform; |
jaydasika | 5aa88b8 | 2015-11-10 01:48:03 | [diff] [blame] | 6235 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6236 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6237 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6238 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6239 | // render_surface1 is in the same 3d rendering context as back_facing and is |
| 6240 | // not double sided, so it should not be in RSLL. render_surface2 is also not |
| 6241 | // double-sided, but will still be in RSLL as it's in a different 3d rendering |
| 6242 | // context. |
| 6243 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
| 6244 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6245 | ->at(0) |
| 6246 | ->render_surface() |
| 6247 | ->layer_list() |
| 6248 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6249 | } |
| 6250 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6251 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6252 | LayerImpl* root = root_layer_for_testing(); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6253 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 6254 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6255 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6256 | root->SetBounds(gfx::Size(50, 50)); |
| 6257 | root->test_properties()->should_flatten_transform = false; |
| 6258 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6259 | child->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6260 | child->test_properties()->should_flatten_transform = false; |
| 6261 | grand_child->SetBounds(gfx::Size(20, 20)); |
| 6262 | grand_child->SetDrawsContent(true); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6263 | grand_child->SetUseParentBackfaceVisibility(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6264 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6265 | ExecuteCalculateDrawProperties(root); |
| 6266 | |
| 6267 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6268 | EXPECT_EQ(grand_child, render_surface_layer_list_impl() |
| 6269 | ->at(0) |
| 6270 | ->render_surface() |
| 6271 | ->layer_list()[0]); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6272 | |
| 6273 | // As all layers have identity transform, we shouldn't check for backface |
| 6274 | // visibility. |
| 6275 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6276 | EXPECT_FALSE(child->should_check_backface_visibility()); |
| 6277 | EXPECT_FALSE(grand_child->should_check_backface_visibility()); |
| 6278 | // As there are no 3d rendering contexts, all layers should use their local |
| 6279 | // transform for backface visibility. |
| 6280 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6281 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6282 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6283 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6284 | gfx::Transform rotation_transform; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6285 | rotation_transform.RotateAboutXAxis(180.0); |
| 6286 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6287 | child->test_properties()->transform = rotation_transform; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6288 | child->test_properties()->sorting_context_id = 1; |
| 6289 | grand_child->test_properties()->sorting_context_id = 1; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6290 | child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6291 | |
| 6292 | ExecuteCalculateDrawProperties(root); |
| 6293 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6294 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6295 | ->at(0) |
| 6296 | ->render_surface() |
| 6297 | ->layer_list() |
| 6298 | .size()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6299 | |
| 6300 | // We should check for backface visibilty of child as it has a rotation |
| 6301 | // transform. We should also check for grand_child as it uses the backface |
| 6302 | // visibility of its parent. |
| 6303 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6304 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6305 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6306 | // child uses its local transform for backface visibility as it is the root of |
| 6307 | // a 3d rendering context. grand_child is in a 3d rendering context and is not |
| 6308 | // the root, but it derives its backface visibility from its parent which uses |
| 6309 | // its local transform. |
| 6310 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6311 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6312 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6313 | |
| 6314 | grand_child->SetUseParentBackfaceVisibility(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6315 | grand_child->test_properties()->double_sided = false; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6316 | grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6317 | |
| 6318 | ExecuteCalculateDrawProperties(root); |
| 6319 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6320 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6321 | ->at(0) |
| 6322 | ->render_surface() |
| 6323 | ->layer_list() |
| 6324 | .size()); |
| 6325 | |
| 6326 | // We should check the backface visibility of child as it has a rotation |
| 6327 | // transform and for grand_child as it is in a 3d rendering context and not |
| 6328 | // the root of it. |
| 6329 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6330 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6331 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6332 | // grand_child is in an existing 3d rendering context, so it should not use |
| 6333 | // local transform for backface visibility. |
| 6334 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6335 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6336 | EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility()); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6337 | } |
| 6338 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6339 | TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6340 | LayerImpl* root = root_layer_for_testing(); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6341 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6342 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6343 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6344 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6345 | gfx::Transform rotate_about_y; |
| 6346 | rotate_about_y.RotateAboutYAxis(180.0); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6347 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6348 | root->SetBounds(gfx::Size(50, 50)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6349 | root->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6350 | root->test_properties()->sorting_context_id = 1; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6351 | back_facing->test_properties()->transform = rotate_about_y; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6352 | back_facing->SetBounds(gfx::Size(50, 50)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6353 | back_facing->test_properties()->should_flatten_transform = false; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6354 | back_facing->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6355 | render_surface1->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6356 | render_surface1->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6357 | render_surface1->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6358 | render_surface1->test_properties()->force_render_surface = true; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6359 | render_surface1->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6360 | render_surface2->SetBounds(gfx::Size(30, 30)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6361 | render_surface2->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6362 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6363 | render_surface2->test_properties()->force_render_surface = true; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6364 | render_surface2->test_properties()->sorting_context_id = 1; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6365 | ExecuteCalculateDrawProperties(root); |
| 6366 | |
| 6367 | const EffectTree& tree = |
| 6368 | root->layer_tree_impl()->property_trees()->effect_tree; |
| 6369 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6370 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6371 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6372 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6373 | |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 6374 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6375 | gfx::Transform(), back_facing->transform_tree_index(), |
| 6376 | root->layer_tree_impl()); |
| 6377 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6378 | rotate_about_y, render_surface2->transform_tree_index(), |
| 6379 | root->layer_tree_impl()); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6380 | ExecuteCalculateDrawProperties(root); |
| 6381 | EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6382 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6383 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6384 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6385 | |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 6386 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6387 | rotate_about_y, render_surface1->transform_tree_index(), |
| 6388 | root->layer_tree_impl()); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6389 | ExecuteCalculateDrawProperties(root); |
| 6390 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6391 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6392 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6393 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6394 | } |
| 6395 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6396 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 6397 | // Checks that the simple case (being clipped by a scroll parent that would |
| 6398 | // have been processed before you anyhow) results in the right clips. |
| 6399 | // |
| 6400 | // + root |
| 6401 | // + scroll_parent_border |
| 6402 | // | + scroll_parent_clip |
| 6403 | // | + scroll_parent |
| 6404 | // + scroll_child |
| 6405 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6406 | LayerImpl* root = root_layer_for_testing(); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6407 | LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>(); |
| 6408 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6409 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6410 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6411 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6412 | scroll_parent->SetDrawsContent(true); |
| 6413 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6414 | scroll_parent_clip->SetMasksToBounds(true); |
| 6415 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6416 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6417 | scroll_parent->test_properties()->scroll_children = |
| 6418 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6419 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6420 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6421 | root->SetBounds(gfx::Size(50, 50)); |
| 6422 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6423 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6424 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6425 | scroll_child->SetBounds(gfx::Size(50, 50)); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6426 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6427 | |
| 6428 | EXPECT_TRUE(root->render_surface()); |
| 6429 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6430 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6431 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6432 | } |
| 6433 | |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6434 | TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) { |
| 6435 | // Tests the computation of draw transform for the scroll child when its |
| 6436 | // target is different from its scroll parent's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6437 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6438 | LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); |
| 6439 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); |
| 6440 | LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target); |
| 6441 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); |
| 6442 | |
| 6443 | scroll_parent->SetDrawsContent(true); |
| 6444 | scroll_child->SetDrawsContent(true); |
| 6445 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6446 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6447 | scroll_parent->test_properties()->scroll_children = |
| 6448 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6449 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6450 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6451 | root->SetBounds(gfx::Size(50, 50)); |
| 6452 | scroll_child_target->SetBounds(gfx::Size(50, 50)); |
| 6453 | scroll_child_target->test_properties()->force_render_surface = true; |
| 6454 | scroll_child->SetBounds(gfx::Size(50, 50)); |
| 6455 | scroll_parent_target->SetPosition(gfx::PointF(10, 10)); |
| 6456 | scroll_parent_target->SetBounds(gfx::Size(50, 50)); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6457 | scroll_parent_target->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6458 | scroll_parent_target->test_properties()->force_render_surface = true; |
| 6459 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6460 | |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6461 | float device_scale_factor = 1.5f; |
| 6462 | LayerImplList render_surface_layer_list_impl; |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 6463 | gfx::Size device_viewport_size = |
| 6464 | gfx::Size(root->bounds().width() * device_scale_factor, |
| 6465 | root->bounds().height() * device_scale_factor); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6466 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 6467 | root, device_viewport_size, gfx::Transform(), |
| 6468 | &render_surface_layer_list_impl); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6469 | inputs.device_scale_factor = device_scale_factor; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6470 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6471 | |
weiliangc | 1da3fb89 | 2016-03-14 20:23:52 | [diff] [blame] | 6472 | EXPECT_EQ(scroll_child->effect_tree_index(), |
| 6473 | scroll_child_target->effect_tree_index()); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6474 | EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); |
| 6475 | EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); |
| 6476 | gfx::Transform scale; |
| 6477 | scale.Scale(1.5f, 1.5f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6478 | EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6479 | } |
| 6480 | |
jaydasika | 4de4c083 | 2016-11-29 16:19:16 | [diff] [blame] | 6481 | TEST_F(LayerTreeHostCommonTest, TargetBetweenScrollChildandScrollParentTarget) { |
| 6482 | LayerImpl* root = root_layer_for_testing(); |
| 6483 | LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); |
| 6484 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); |
| 6485 | LayerImpl* child_of_scroll_child = AddChild<LayerImpl>(scroll_child); |
| 6486 | LayerImpl* intervening_target = AddChild<LayerImpl>(scroll_child_target); |
| 6487 | LayerImpl* clip = AddChild<LayerImpl>(intervening_target); |
| 6488 | LayerImpl* scroll_parent_target = AddChild<LayerImpl>(clip); |
| 6489 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); |
| 6490 | |
| 6491 | scroll_parent->SetDrawsContent(true); |
| 6492 | child_of_scroll_child->SetDrawsContent(true); |
| 6493 | |
| 6494 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 6495 | scroll_parent->test_properties()->scroll_children = |
| 6496 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6497 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
| 6498 | |
| 6499 | root->SetBounds(gfx::Size(50, 50)); |
| 6500 | scroll_child_target->SetBounds(gfx::Size(50, 50)); |
| 6501 | scroll_child_target->SetMasksToBounds(true); |
| 6502 | scroll_child_target->test_properties()->force_render_surface = true; |
| 6503 | scroll_child->SetBounds(gfx::Size(50, 50)); |
| 6504 | child_of_scroll_child->SetBounds(gfx::Size(50, 50)); |
| 6505 | child_of_scroll_child->test_properties()->force_render_surface = true; |
| 6506 | intervening_target->SetBounds(gfx::Size(50, 50)); |
| 6507 | intervening_target->test_properties()->force_render_surface = true; |
| 6508 | clip->SetBounds(gfx::Size(50, 50)); |
| 6509 | clip->SetMasksToBounds(true); |
| 6510 | scroll_parent_target->SetBounds(gfx::Size(50, 50)); |
| 6511 | scroll_parent_target->SetMasksToBounds(true); |
| 6512 | scroll_parent_target->test_properties()->force_render_surface = true; |
| 6513 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6514 | |
| 6515 | ExecuteCalculateDrawProperties(root); |
| 6516 | PropertyTrees* property_trees = root->layer_tree_impl()->property_trees(); |
| 6517 | ClipNode* clip_node = |
| 6518 | property_trees->clip_tree.Node(child_of_scroll_child->clip_tree_index()); |
| 6519 | ClipNode* parent_clip_node = property_trees->clip_tree.parent(clip_node); |
| 6520 | DCHECK_GT(parent_clip_node->target_transform_id, |
| 6521 | property_trees->transform_tree.TargetId( |
| 6522 | child_of_scroll_child->transform_tree_index())); |
| 6523 | } |
| 6524 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6525 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6526 | LayerImpl* root = root_layer_for_testing(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6527 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6528 | LayerImpl* child = AddChild<LayerImpl>(parent); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6529 | |
| 6530 | root->SetBounds(gfx::Size(50, 50)); |
| 6531 | root->SetDrawsContent(true); |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6532 | root->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6533 | parent->SetBounds(gfx::Size(30, 30)); |
| 6534 | parent->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6535 | parent->test_properties()->force_render_surface = true; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6536 | parent->test_properties()->sorting_context_id = 1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6537 | child->SetBounds(gfx::Size(20, 20)); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6538 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6539 | child->test_properties()->force_render_surface = true; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 6540 | child->test_properties()->sorting_context_id = 1; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6541 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6542 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6543 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6544 | |
| 6545 | gfx::Transform singular_transform; |
| 6546 | singular_transform.Scale3d( |
| 6547 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 6548 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6549 | child->test_properties()->transform = singular_transform; |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6550 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6551 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6552 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6553 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6554 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6555 | |
| 6556 | // Ensure that the entire subtree under a layer with singular transform does |
| 6557 | // not get rendered. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6558 | parent->test_properties()->transform = singular_transform; |
| 6559 | child->test_properties()->transform = gfx::Transform(); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6560 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6561 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6562 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6563 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6564 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6565 | } |
| 6566 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6567 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 6568 | // Checks that clipping by a scroll parent that follows you in paint order |
| 6569 | // still results in correct clipping. |
| 6570 | // |
| 6571 | // + root |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6572 | // + scroll_parent_border |
| 6573 | // + scroll_parent_clip |
| 6574 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6575 | // + scroll_child |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6576 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6577 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6578 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6579 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6580 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6581 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6582 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6583 | scroll_parent->SetDrawsContent(true); |
| 6584 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6585 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6586 | root->SetBounds(gfx::Size(50, 50)); |
| 6587 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6588 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6589 | scroll_parent_clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6590 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6591 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6592 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6593 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6594 | scroll_parent->test_properties()->scroll_children = |
| 6595 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6596 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6597 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6598 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6599 | |
| 6600 | EXPECT_TRUE(root->render_surface()); |
| 6601 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6602 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6603 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6604 | } |
| 6605 | |
| 6606 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 6607 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 6608 | // you in paint order still results in correct clipping. |
| 6609 | // |
| 6610 | // + root |
| 6611 | // + scroll_child |
| 6612 | // + scroll_parent_border |
| 6613 | // | + scroll_parent_clip |
| 6614 | // | + scroll_parent |
| 6615 | // + scroll_grandparent_border |
| 6616 | // + scroll_grandparent_clip |
| 6617 | // + scroll_grandparent |
| 6618 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6619 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6620 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6621 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6622 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6623 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6624 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6625 | LayerImpl* scroll_grandparent_clip = |
| 6626 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6627 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6628 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6629 | scroll_parent->SetDrawsContent(true); |
| 6630 | scroll_grandparent->SetDrawsContent(true); |
| 6631 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6632 | |
| 6633 | scroll_parent_clip->SetMasksToBounds(true); |
| 6634 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6635 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6636 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6637 | scroll_parent->test_properties()->scroll_children = |
| 6638 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6639 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6640 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6641 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6642 | scroll_grandparent->test_properties()->scroll_children = |
| 6643 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6644 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 6645 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6646 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6647 | root->SetBounds(gfx::Size(50, 50)); |
| 6648 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 6649 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 6650 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 6651 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6652 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6653 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6654 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6655 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6656 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6657 | |
| 6658 | EXPECT_TRUE(root->render_surface()); |
| 6659 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6660 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6661 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6662 | |
| 6663 | // Despite the fact that we visited the above layers out of order to get the |
| 6664 | // correct clip, the layer lists should be unaffected. |
| 6665 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6666 | EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0)); |
| 6667 | EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1)); |
| 6668 | EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6669 | } |
| 6670 | |
| 6671 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 6672 | // 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] | 6673 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6674 | // + root |
| 6675 | // + scroll_child |
| 6676 | // + scroll_parent_border |
| 6677 | // + scroll_parent_clip |
| 6678 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6679 | // + render_surface2 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6680 | // + scroll_grandparent_border |
| 6681 | // + scroll_grandparent_clip |
| 6682 | // + scroll_grandparent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6683 | // + render_surface1 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6684 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6685 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6686 | root->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6687 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6688 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6689 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6690 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6691 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6692 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6693 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6694 | LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent); |
| 6695 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6696 | LayerImpl* scroll_grandparent_clip = |
| 6697 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6698 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
| 6699 | LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6700 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6701 | scroll_parent->SetDrawsContent(true); |
| 6702 | render_surface1->SetDrawsContent(true); |
| 6703 | scroll_grandparent->SetDrawsContent(true); |
| 6704 | render_surface2->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6705 | |
| 6706 | scroll_parent_clip->SetMasksToBounds(true); |
| 6707 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6708 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6709 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6710 | scroll_parent->test_properties()->scroll_children = |
| 6711 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6712 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6713 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6714 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6715 | scroll_grandparent->test_properties()->scroll_children = |
| 6716 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6717 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 6718 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6719 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6720 | root->SetBounds(gfx::Size(50, 50)); |
| 6721 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 6722 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 6723 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 6724 | render_surface1->SetBounds(gfx::Size(50, 50)); |
| 6725 | render_surface1->test_properties()->force_render_surface = true; |
| 6726 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6727 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6728 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6729 | render_surface2->SetBounds(gfx::Size(50, 50)); |
| 6730 | render_surface2->test_properties()->force_render_surface = true; |
| 6731 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6732 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6733 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6734 | |
| 6735 | EXPECT_TRUE(root->render_surface()); |
| 6736 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6737 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6738 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6739 | |
| 6740 | // Despite the fact that we had to process the layers out of order to get the |
| 6741 | // right clip, our render_surface_layer_list's order should be unaffected. |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6742 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6743 | EXPECT_EQ(root, render_surface_layer_list_impl()->at(0)); |
| 6744 | EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1)); |
| 6745 | EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2)); |
| 6746 | EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface()); |
| 6747 | EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface()); |
| 6748 | EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6749 | } |
| 6750 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6751 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 6752 | // Ensures that when we have a render surface between a fixed position layer |
| 6753 | // and its container, we compute the fixed position layer's draw transform |
| 6754 | // with respect to that intervening render surface, not with respect to its |
| 6755 | // container's render target. |
| 6756 | // |
| 6757 | // + root |
| 6758 | // + render_surface |
| 6759 | // + fixed |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6760 | // + child |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6761 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6762 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6763 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 6764 | LayerImpl* fixed = AddChild<LayerImpl>(render_surface); |
| 6765 | LayerImpl* child = AddChild<LayerImpl>(fixed); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6766 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6767 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6768 | root->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6769 | |
| 6770 | LayerPositionConstraint constraint; |
| 6771 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6772 | fixed->test_properties()->position_constraint = constraint; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6773 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6774 | root->SetBounds(gfx::Size(50, 50)); |
| 6775 | render_surface->SetPosition(gfx::PointF(7.f, 9.f)); |
| 6776 | render_surface->SetBounds(gfx::Size(50, 50)); |
| 6777 | render_surface->SetDrawsContent(true); |
| 6778 | fixed->SetPosition(gfx::PointF(10.f, 15.f)); |
| 6779 | fixed->SetBounds(gfx::Size(50, 50)); |
| 6780 | fixed->SetDrawsContent(true); |
| 6781 | child->SetPosition(gfx::PointF(1.f, 2.f)); |
| 6782 | child->SetBounds(gfx::Size(50, 50)); |
| 6783 | child->SetDrawsContent(true); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6784 | ExecuteCalculateDrawProperties(root); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6785 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6786 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6787 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6788 | EffectTree& effect_tree = |
| 6789 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6790 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6791 | gfx::Transform expected_fixed_draw_transform; |
| 6792 | expected_fixed_draw_transform.Translate(10.f, 15.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6793 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6794 | expected_fixed_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6795 | draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6796 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6797 | gfx::Transform expected_fixed_screen_space_transform; |
| 6798 | expected_fixed_screen_space_transform.Translate(17.f, 24.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6799 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6800 | expected_fixed_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6801 | draw_property_utils::ScreenSpaceTransform(fixed, transform_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6802 | |
| 6803 | gfx::Transform expected_child_draw_transform; |
| 6804 | expected_child_draw_transform.Translate(11.f, 17.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6805 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6806 | expected_child_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6807 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6808 | |
| 6809 | gfx::Transform expected_child_screen_space_transform; |
| 6810 | expected_child_screen_space_transform.Translate(18.f, 26.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6811 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6812 | expected_child_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6813 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6814 | } |
| 6815 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6816 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 6817 | // This test verifies that a scrolling layer that gets snapped to |
| 6818 | // integer coordinates doesn't move a fixed position child. |
| 6819 | // |
| 6820 | // + root |
| 6821 | // + container |
| 6822 | // + scroller |
| 6823 | // + fixed |
| 6824 | // |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6825 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6826 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 6827 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6828 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6829 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6830 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 6831 | LayerImpl* root = root_ptr.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6832 | std::unique_ptr<LayerImpl> container = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6833 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 6834 | LayerImpl* container_layer = container.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6835 | std::unique_ptr<LayerImpl> scroller = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6836 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 6837 | LayerImpl* scroll_layer = scroller.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6838 | std::unique_ptr<LayerImpl> fixed = |
| 6839 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6840 | LayerImpl* fixed_layer = fixed.get(); |
| 6841 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6842 | container->test_properties()->is_container_for_fixed_position_layers = true; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6843 | |
| 6844 | LayerPositionConstraint constraint; |
| 6845 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6846 | fixed->test_properties()->position_constraint = constraint; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6847 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6848 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6849 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6850 | gfx::Transform container_transform; |
| 6851 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 6852 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 6853 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6854 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6855 | container->test_properties()->transform = container_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6856 | container->SetBounds(gfx::Size(40, 40)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6857 | container->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6858 | scroller->SetBounds(gfx::Size(30, 30)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6859 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6860 | fixed->SetBounds(gfx::Size(50, 50)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6861 | fixed->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6862 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6863 | scroller->test_properties()->AddChild(std::move(fixed)); |
| 6864 | container->test_properties()->AddChild(std::move(scroller)); |
| 6865 | root->test_properties()->AddChild(std::move(container)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6866 | root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr)); |
| 6867 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6868 | |
| 6869 | // Rounded to integers already. |
| 6870 | { |
| 6871 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6872 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6873 | |
| 6874 | LayerImplList render_surface_layer_list; |
| 6875 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6876 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6877 | root->layer_tree_impl() |
| 6878 | ->property_trees() |
| 6879 | ->transform_tree.set_source_to_parent_updates_allowed(false); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6880 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6881 | |
| 6882 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6883 | container_layer->draw_properties().screen_space_transform, |
| 6884 | fixed_layer->draw_properties().screen_space_transform); |
| 6885 | EXPECT_VECTOR_EQ( |
| 6886 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6887 | container_offset); |
| 6888 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6889 | .screen_space_transform.To2dTranslation(), |
| 6890 | container_offset - scroll_delta); |
| 6891 | } |
| 6892 | |
| 6893 | // Scroll delta requiring rounding. |
| 6894 | { |
| 6895 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6896 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6897 | |
| 6898 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 6899 | |
| 6900 | LayerImplList render_surface_layer_list; |
| 6901 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6902 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6903 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6904 | |
| 6905 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6906 | container_layer->draw_properties().screen_space_transform, |
| 6907 | fixed_layer->draw_properties().screen_space_transform); |
| 6908 | EXPECT_VECTOR_EQ( |
| 6909 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6910 | container_offset); |
| 6911 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6912 | .screen_space_transform.To2dTranslation(), |
| 6913 | container_offset - rounded_scroll_delta); |
| 6914 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6915 | |
| 6916 | // Scale is applied earlier in the tree. |
| 6917 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6918 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6919 | gfx::Transform scaled_container_transform = container_transform; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6920 | scaled_container_transform.Scale3d(2.0, 2.0, 1.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6921 | container_layer->test_properties()->transform = scaled_container_transform; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6922 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6923 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6924 | |
| 6925 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6926 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6927 | |
| 6928 | LayerImplList render_surface_layer_list; |
| 6929 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6930 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6931 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6932 | |
| 6933 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6934 | container_layer->draw_properties().screen_space_transform, |
| 6935 | fixed_layer->draw_properties().screen_space_transform); |
| 6936 | EXPECT_VECTOR_EQ( |
| 6937 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6938 | container_offset); |
| 6939 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6940 | container_layer->test_properties()->transform = container_transform; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6941 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6942 | } |
| 6943 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 6944 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6945 | ScrollSnappingWithAnimatedScreenSpaceTransform) { |
| 6946 | // This test verifies that a scrolling layer whose screen space transform is |
| 6947 | // animating doesn't get snapped to integer coordinates. |
| 6948 | // |
| 6949 | // + root |
| 6950 | // + animated layer |
| 6951 | // + surface |
| 6952 | // + container |
| 6953 | // + scroller |
| 6954 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6955 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6956 | LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>(); |
| 6957 | LayerImpl* surface = AddChild<LayerImpl>(animated_layer); |
| 6958 | LayerImpl* container = AddChild<LayerImpl>(surface); |
| 6959 | LayerImpl* scroller = AddChild<LayerImpl>(container); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6960 | |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6961 | gfx::Transform start_scale; |
| 6962 | start_scale.Scale(1.5f, 1.5f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6963 | |
| 6964 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6965 | animated_layer->test_properties()->transform = start_scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6966 | animated_layer->SetBounds(gfx::Size(50, 50)); |
| 6967 | surface->SetBounds(gfx::Size(50, 50)); |
| 6968 | surface->test_properties()->force_render_surface = true; |
| 6969 | container->SetBounds(gfx::Size(50, 50)); |
| 6970 | scroller->SetBounds(gfx::Size(100, 100)); |
| 6971 | scroller->SetScrollClipLayer(container->id()); |
| 6972 | scroller->SetDrawsContent(true); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6973 | |
| 6974 | gfx::Transform end_scale; |
| 6975 | end_scale.Scale(2.f, 2.f); |
| 6976 | TransformOperations start_operations; |
| 6977 | start_operations.AppendMatrix(start_scale); |
| 6978 | TransformOperations end_operations; |
| 6979 | end_operations.AppendMatrix(end_scale); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 6980 | SetElementIdsForTesting(); |
| 6981 | |
| 6982 | AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(), |
| 6983 | timeline_impl(), 1.0, |
| 6984 | start_operations, end_operations); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6985 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6986 | SetScrollOffsetDelta(scroller, scroll_delta); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6987 | |
| 6988 | ExecuteCalculateDrawProperties(root); |
| 6989 | |
| 6990 | gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); |
| 6991 | EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 6992 | scroller->DrawTransform().To2dTranslation()); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6993 | } |
| 6994 | |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 6995 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) { |
| 6996 | // This test verifies that a scrolling child of a scrolling layer doesn't get |
| 6997 | // snapped to integer coordinates. |
| 6998 | // |
| 6999 | // + root |
| 7000 | // + container |
| 7001 | // + scroller |
| 7002 | // + scroll_child |
| 7003 | // |
| 7004 | scoped_refptr<Layer> root = Layer::Create(); |
| 7005 | scoped_refptr<Layer> container = Layer::Create(); |
| 7006 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7007 | scoped_refptr<Layer> scroll_child = Layer::Create(); |
| 7008 | root->AddChild(container); |
| 7009 | root->AddChild(scroll_child); |
| 7010 | container->AddChild(scroller); |
| 7011 | host()->SetRootLayer(root); |
| 7012 | |
| 7013 | scroller->SetScrollClipLayerId(container->id()); |
| 7014 | scroll_child->SetScrollParent(scroller.get()); |
| 7015 | |
| 7016 | gfx::Transform rotate; |
| 7017 | rotate.RotateAboutYAxis(30); |
| 7018 | root->SetBounds(gfx::Size(50, 50)); |
| 7019 | container->SetBounds(gfx::Size(50, 50)); |
| 7020 | scroller->SetBounds(gfx::Size(100, 100)); |
| 7021 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 7022 | scroll_child->SetBounds(gfx::Size(10, 10)); |
| 7023 | scroll_child->SetTransform(rotate); |
| 7024 | |
| 7025 | ExecuteCalculateDrawProperties(root.get()); |
| 7026 | |
| 7027 | host()->host_impl()->CreatePendingTree(); |
| 7028 | host()->CommitAndCreatePendingTree(); |
| 7029 | host()->host_impl()->ActivateSyncTree(); |
| 7030 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7031 | |
| 7032 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7033 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7034 | LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id()); |
| 7035 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 7036 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 7037 | |
| 7038 | ExecuteCalculateDrawProperties(root_impl); |
| 7039 | |
| 7040 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 7041 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 7042 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7043 | |
| 7044 | gfx::Transform expected_scroll_child_screen_space_transform; |
| 7045 | expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); |
| 7046 | expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); |
| 7047 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, |
| 7048 | scroll_child_impl->ScreenSpaceTransform()); |
| 7049 | } |
| 7050 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7051 | TEST_F(LayerTreeHostCommonTest, StickyPositionTop) { |
| 7052 | scoped_refptr<Layer> root = Layer::Create(); |
| 7053 | scoped_refptr<Layer> container = Layer::Create(); |
| 7054 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7055 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7056 | root->AddChild(container); |
| 7057 | container->AddChild(scroller); |
| 7058 | scroller->AddChild(sticky_pos); |
| 7059 | host()->SetRootLayer(root); |
| 7060 | scroller->SetScrollClipLayerId(container->id()); |
| 7061 | |
| 7062 | LayerStickyPositionConstraint sticky_position; |
| 7063 | sticky_position.is_sticky = true; |
| 7064 | sticky_position.is_anchored_top = true; |
| 7065 | sticky_position.top_offset = 10.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7066 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7067 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7068 | gfx::Rect(10, 20, 10, 10); |
| 7069 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7070 | gfx::Rect(0, 0, 50, 50); |
| 7071 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7072 | |
| 7073 | root->SetBounds(gfx::Size(100, 100)); |
| 7074 | container->SetBounds(gfx::Size(100, 100)); |
| 7075 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7076 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7077 | sticky_pos->SetPosition(gfx::PointF(10, 20)); |
| 7078 | |
| 7079 | ExecuteCalculateDrawProperties(root.get()); |
| 7080 | host()->host_impl()->CreatePendingTree(); |
| 7081 | host()->CommitAndCreatePendingTree(); |
| 7082 | host()->host_impl()->ActivateSyncTree(); |
| 7083 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7084 | |
| 7085 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7086 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7087 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7088 | |
| 7089 | ExecuteCalculateDrawProperties(root_impl); |
| 7090 | EXPECT_VECTOR2DF_EQ( |
| 7091 | gfx::Vector2dF(10.f, 20.f), |
| 7092 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7093 | |
| 7094 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7095 | // we haven't gotten to the initial sticky item location yet. |
| 7096 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 7097 | ExecuteCalculateDrawProperties(root_impl); |
| 7098 | EXPECT_VECTOR2DF_EQ( |
| 7099 | gfx::Vector2dF(5.f, 15.f), |
| 7100 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7101 | |
| 7102 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 7103 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 7104 | ExecuteCalculateDrawProperties(root_impl); |
| 7105 | EXPECT_VECTOR2DF_EQ( |
| 7106 | gfx::Vector2dF(-5.f, 10.f), |
| 7107 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7108 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f)); |
| 7109 | ExecuteCalculateDrawProperties(root_impl); |
| 7110 | EXPECT_VECTOR2DF_EQ( |
| 7111 | gfx::Vector2dF(-5.f, 10.f), |
| 7112 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7113 | |
| 7114 | // Scroll past the end of the sticky container (note: this element does not |
| 7115 | // have its own layer as it does not need to be composited). |
| 7116 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); |
| 7117 | ExecuteCalculateDrawProperties(root_impl); |
| 7118 | EXPECT_VECTOR2DF_EQ( |
| 7119 | gfx::Vector2dF(-5.f, -10.f), |
| 7120 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7121 | } |
| 7122 | |
flackr | d2ae03f | 2016-11-14 19:22:05 | [diff] [blame] | 7123 | TEST_F(LayerTreeHostCommonTest, StickyPositionTopScrollParent) { |
| 7124 | scoped_refptr<Layer> root = Layer::Create(); |
| 7125 | scoped_refptr<Layer> container = Layer::Create(); |
| 7126 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7127 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7128 | root->AddChild(container); |
| 7129 | container->AddChild(scroller); |
| 7130 | root->AddChild(sticky_pos); |
| 7131 | sticky_pos->SetScrollParent(scroller.get()); |
| 7132 | host()->SetRootLayer(root); |
| 7133 | scroller->SetScrollClipLayerId(container->id()); |
| 7134 | |
| 7135 | LayerStickyPositionConstraint sticky_position; |
| 7136 | sticky_position.is_sticky = true; |
| 7137 | sticky_position.is_anchored_top = true; |
| 7138 | sticky_position.top_offset = 10.0f; |
| 7139 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); |
| 7140 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7141 | gfx::Rect(10, 20, 10, 10); |
| 7142 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7143 | gfx::Rect(0, 0, 50, 50); |
| 7144 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7145 | |
| 7146 | root->SetBounds(gfx::Size(200, 200)); |
| 7147 | container->SetBounds(gfx::Size(100, 100)); |
| 7148 | container->SetPosition(gfx::PointF(50, 50)); |
| 7149 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7150 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7151 | sticky_pos->SetPosition(gfx::PointF(60, 70)); |
| 7152 | |
| 7153 | ExecuteCalculateDrawProperties(root.get()); |
| 7154 | host()->host_impl()->CreatePendingTree(); |
| 7155 | host()->CommitAndCreatePendingTree(); |
| 7156 | host()->host_impl()->ActivateSyncTree(); |
| 7157 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7158 | |
| 7159 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7160 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7161 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7162 | |
| 7163 | ExecuteCalculateDrawProperties(root_impl); |
| 7164 | EXPECT_VECTOR2DF_EQ( |
| 7165 | gfx::Vector2dF(60.f, 70.f), |
| 7166 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7167 | |
| 7168 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7169 | // we haven't gotten to the initial sticky item location yet. |
| 7170 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 7171 | ExecuteCalculateDrawProperties(root_impl); |
| 7172 | EXPECT_VECTOR2DF_EQ( |
| 7173 | gfx::Vector2dF(55.f, 65.f), |
| 7174 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7175 | |
| 7176 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 7177 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 7178 | ExecuteCalculateDrawProperties(root_impl); |
| 7179 | EXPECT_VECTOR2DF_EQ( |
| 7180 | gfx::Vector2dF(45.f, 60.f), |
| 7181 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7182 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f)); |
| 7183 | ExecuteCalculateDrawProperties(root_impl); |
| 7184 | EXPECT_VECTOR2DF_EQ( |
| 7185 | gfx::Vector2dF(45.f, 60.f), |
| 7186 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7187 | |
| 7188 | // Scroll past the end of the sticky container (note: this element does not |
| 7189 | // have its own layer as it does not need to be composited). |
| 7190 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); |
| 7191 | ExecuteCalculateDrawProperties(root_impl); |
| 7192 | EXPECT_VECTOR2DF_EQ( |
| 7193 | gfx::Vector2dF(45.f, 40.f), |
| 7194 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7195 | } |
| 7196 | |
flackr | dc5dfbe | 2016-10-24 21:43:38 | [diff] [blame] | 7197 | TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) { |
| 7198 | scoped_refptr<Layer> root = Layer::Create(); |
| 7199 | scoped_refptr<Layer> container = Layer::Create(); |
| 7200 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7201 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7202 | root->AddChild(container); |
| 7203 | container->AddChild(scroller); |
| 7204 | scroller->AddChild(sticky_pos); |
| 7205 | host()->SetRootLayer(root); |
| 7206 | scroller->SetScrollClipLayerId(container->id()); |
| 7207 | |
| 7208 | LayerStickyPositionConstraint sticky_position; |
| 7209 | sticky_position.is_sticky = true; |
| 7210 | sticky_position.is_anchored_bottom = true; |
| 7211 | sticky_position.bottom_offset = 10.0f; |
| 7212 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 200); |
| 7213 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7214 | gfx::Rect(0, 200, 10, 10); |
| 7215 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7216 | gfx::Rect(0, 0, 100, 500); |
| 7217 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7218 | |
| 7219 | root->SetBounds(gfx::Size(100, 100)); |
| 7220 | container->SetBounds(gfx::Size(100, 100)); |
| 7221 | scroller->SetBounds(gfx::Size(100, 1000)); |
| 7222 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7223 | sticky_pos->SetPosition(gfx::PointF(0, 200)); |
| 7224 | |
| 7225 | ExecuteCalculateDrawProperties(root.get()); |
| 7226 | host()->host_impl()->CreatePendingTree(); |
| 7227 | host()->CommitAndCreatePendingTree(); |
| 7228 | host()->host_impl()->ActivateSyncTree(); |
| 7229 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7230 | |
| 7231 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7232 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7233 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7234 | |
| 7235 | ExecuteCalculateDrawProperties(root_impl); |
| 7236 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.8f)); |
| 7237 | ExecuteCalculateDrawProperties(root_impl); |
| 7238 | EXPECT_VECTOR2DF_EQ( |
| 7239 | gfx::Vector2dF(0.f, 80.f), |
| 7240 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7241 | } |
| 7242 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7243 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) { |
| 7244 | scoped_refptr<Layer> root = Layer::Create(); |
| 7245 | scoped_refptr<Layer> container = Layer::Create(); |
| 7246 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7247 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7248 | root->AddChild(container); |
| 7249 | container->AddChild(scroller); |
| 7250 | scroller->AddChild(sticky_pos); |
| 7251 | host()->SetRootLayer(root); |
| 7252 | scroller->SetScrollClipLayerId(container->id()); |
| 7253 | |
| 7254 | LayerStickyPositionConstraint sticky_position; |
| 7255 | sticky_position.is_sticky = true; |
| 7256 | sticky_position.is_anchored_bottom = true; |
| 7257 | sticky_position.bottom_offset = 10.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7258 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7259 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7260 | gfx::Rect(0, 150, 10, 10); |
| 7261 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7262 | gfx::Rect(0, 100, 50, 50); |
| 7263 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7264 | |
| 7265 | root->SetBounds(gfx::Size(100, 100)); |
| 7266 | container->SetBounds(gfx::Size(100, 100)); |
| 7267 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7268 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7269 | sticky_pos->SetPosition(gfx::PointF(0, 150)); |
| 7270 | |
| 7271 | ExecuteCalculateDrawProperties(root.get()); |
| 7272 | host()->host_impl()->CreatePendingTree(); |
| 7273 | host()->CommitAndCreatePendingTree(); |
| 7274 | host()->host_impl()->ActivateSyncTree(); |
| 7275 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7276 | |
| 7277 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7278 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7279 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7280 | |
| 7281 | // Initially the sticky element is moved up to the top of the container. |
| 7282 | ExecuteCalculateDrawProperties(root_impl); |
| 7283 | EXPECT_VECTOR2DF_EQ( |
| 7284 | gfx::Vector2dF(0.f, 100.f), |
| 7285 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7286 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 7287 | ExecuteCalculateDrawProperties(root_impl); |
| 7288 | EXPECT_VECTOR2DF_EQ( |
| 7289 | gfx::Vector2dF(0.f, 95.f), |
| 7290 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7291 | |
| 7292 | // Once we get past the top of the container it moves to be aligned 10px |
| 7293 | // up from the the bottom of the scroller. |
| 7294 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7295 | ExecuteCalculateDrawProperties(root_impl); |
| 7296 | EXPECT_VECTOR2DF_EQ( |
| 7297 | gfx::Vector2dF(0.f, 80.f), |
| 7298 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7299 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7300 | ExecuteCalculateDrawProperties(root_impl); |
| 7301 | EXPECT_VECTOR2DF_EQ( |
| 7302 | gfx::Vector2dF(0.f, 80.f), |
| 7303 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7304 | |
| 7305 | // Once we scroll past its initial location, it sticks there. |
| 7306 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f)); |
| 7307 | ExecuteCalculateDrawProperties(root_impl); |
| 7308 | EXPECT_VECTOR2DF_EQ( |
| 7309 | gfx::Vector2dF(0.f, 0.f), |
| 7310 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7311 | } |
| 7312 | |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7313 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) { |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7314 | scoped_refptr<Layer> root = Layer::Create(); |
| 7315 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7316 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7317 | root->AddChild(scroller); |
| 7318 | scroller->AddChild(sticky_pos); |
| 7319 | host()->SetRootLayer(root); |
| 7320 | scroller->SetScrollClipLayerId(root->id()); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 7321 | host()->RegisterViewportLayers(nullptr, root, scroller, nullptr); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7322 | |
| 7323 | LayerStickyPositionConstraint sticky_position; |
| 7324 | sticky_position.is_sticky = true; |
| 7325 | sticky_position.is_anchored_bottom = true; |
| 7326 | sticky_position.bottom_offset = 10.0f; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7327 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7328 | sticky_position.scroll_container_relative_sticky_box_rect = |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7329 | gfx::Rect(0, 70, 10, 10); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7330 | sticky_position.scroll_container_relative_containing_block_rect = |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7331 | gfx::Rect(0, 60, 100, 100); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7332 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7333 | |
| 7334 | root->SetBounds(gfx::Size(100, 100)); |
| 7335 | scroller->SetBounds(gfx::Size(100, 1000)); |
| 7336 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7337 | sticky_pos->SetPosition(gfx::PointF(0, 70)); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7338 | |
| 7339 | ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7340 | scroller.get(), nullptr); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7341 | host()->CommitAndCreateLayerImplTree(); |
| 7342 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7343 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7344 | ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id()); |
| 7345 | |
| 7346 | LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
| 7347 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7348 | |
| 7349 | // Initially the sticky element is moved to the bottom of the container. |
| 7350 | EXPECT_VECTOR2DF_EQ( |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7351 | gfx::Vector2dF(0.f, 70.f), |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7352 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7353 | |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7354 | // We start to hide the toolbar, but not far enough that the sticky element |
| 7355 | // should be moved up yet. |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7356 | root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7357 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7358 | nullptr); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7359 | EXPECT_VECTOR2DF_EQ( |
| 7360 | gfx::Vector2dF(0.f, 70.f), |
| 7361 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7362 | |
| 7363 | // On hiding more of the toolbar the sticky element starts to stick. |
| 7364 | root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
| 7365 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7366 | nullptr); |
| 7367 | EXPECT_VECTOR2DF_EQ( |
| 7368 | gfx::Vector2dF(0.f, 60.f), |
| 7369 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7370 | |
| 7371 | // On hiding more the sticky element stops moving as it has reached its |
| 7372 | // limit. |
| 7373 | root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
| 7374 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7375 | nullptr); |
| 7376 | EXPECT_VECTOR2DF_EQ( |
| 7377 | gfx::Vector2dF(0.f, 60.f), |
| 7378 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7379 | } |
| 7380 | |
| 7381 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) { |
| 7382 | scoped_refptr<Layer> root = Layer::Create(); |
| 7383 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7384 | scoped_refptr<Layer> outer_clip = Layer::Create(); |
| 7385 | scoped_refptr<Layer> outer_viewport = Layer::Create(); |
| 7386 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7387 | root->AddChild(scroller); |
| 7388 | scroller->AddChild(outer_clip); |
| 7389 | outer_clip->AddChild(outer_viewport); |
| 7390 | outer_viewport->AddChild(sticky_pos); |
| 7391 | host()->SetRootLayer(root); |
| 7392 | scroller->SetScrollClipLayerId(root->id()); |
| 7393 | outer_viewport->SetScrollClipLayerId(outer_clip->id()); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 7394 | host()->RegisterViewportLayers(nullptr, root, scroller, outer_viewport); |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 7395 | |
| 7396 | LayerStickyPositionConstraint sticky_position; |
| 7397 | sticky_position.is_sticky = true; |
| 7398 | sticky_position.is_anchored_bottom = true; |
| 7399 | sticky_position.bottom_offset = 10.0f; |
| 7400 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); |
| 7401 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7402 | gfx::Rect(0, 70, 10, 10); |
| 7403 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7404 | gfx::Rect(0, 60, 100, 100); |
| 7405 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7406 | |
| 7407 | root->SetBounds(gfx::Size(100, 100)); |
| 7408 | scroller->SetBounds(gfx::Size(100, 1000)); |
| 7409 | outer_clip->SetBounds(gfx::Size(100, 100)); |
| 7410 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7411 | sticky_pos->SetPosition(gfx::PointF(0, 70)); |
| 7412 | |
| 7413 | ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), |
| 7414 | scroller.get(), outer_viewport.get()); |
| 7415 | host()->CommitAndCreateLayerImplTree(); |
| 7416 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7417 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7418 | ASSERT_EQ(outer_viewport->id(), |
| 7419 | layer_tree_impl->OuterViewportScrollLayer()->id()); |
| 7420 | |
| 7421 | LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
| 7422 | LayerImpl* outer_scroll = layer_tree_impl->OuterViewportScrollLayer(); |
| 7423 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7424 | LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id()); |
| 7425 | |
| 7426 | // Initially the sticky element is moved to the bottom of the container. |
| 7427 | EXPECT_VECTOR2DF_EQ( |
| 7428 | gfx::Vector2dF(0.f, 70.f), |
| 7429 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7430 | |
| 7431 | // We start to hide the toolbar, but not far enough that the sticky element |
| 7432 | // should be moved up yet. |
| 7433 | outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
| 7434 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7435 | outer_scroll); |
| 7436 | EXPECT_VECTOR2DF_EQ( |
| 7437 | gfx::Vector2dF(0.f, 70.f), |
| 7438 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7439 | |
| 7440 | // On hiding more of the toolbar the sticky element starts to stick. |
| 7441 | outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
| 7442 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7443 | outer_scroll); |
| 7444 | |
| 7445 | // On hiding more the sticky element stops moving as it has reached its |
| 7446 | // limit. |
| 7447 | EXPECT_VECTOR2DF_EQ( |
| 7448 | gfx::Vector2dF(0.f, 60.f), |
| 7449 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7450 | |
| 7451 | outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
| 7452 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
| 7453 | outer_scroll); |
| 7454 | |
| 7455 | EXPECT_VECTOR2DF_EQ( |
| 7456 | gfx::Vector2dF(0.f, 60.f), |
| 7457 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7458 | } |
| 7459 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7460 | TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { |
| 7461 | scoped_refptr<Layer> root = Layer::Create(); |
| 7462 | scoped_refptr<Layer> container = Layer::Create(); |
| 7463 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7464 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7465 | root->AddChild(container); |
| 7466 | container->AddChild(scroller); |
| 7467 | scroller->AddChild(sticky_pos); |
| 7468 | host()->SetRootLayer(root); |
| 7469 | scroller->SetScrollClipLayerId(container->id()); |
| 7470 | |
| 7471 | LayerStickyPositionConstraint sticky_position; |
| 7472 | sticky_position.is_sticky = true; |
| 7473 | sticky_position.is_anchored_left = true; |
| 7474 | sticky_position.is_anchored_right = true; |
| 7475 | sticky_position.left_offset = 10.f; |
| 7476 | sticky_position.right_offset = 10.f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7477 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(145, 0); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7478 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7479 | gfx::Rect(145, 0, 10, 10); |
| 7480 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7481 | gfx::Rect(100, 0, 100, 100); |
| 7482 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7483 | |
| 7484 | root->SetBounds(gfx::Size(100, 100)); |
| 7485 | container->SetBounds(gfx::Size(100, 100)); |
| 7486 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7487 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7488 | sticky_pos->SetPosition(gfx::PointF(145, 0)); |
| 7489 | |
| 7490 | ExecuteCalculateDrawProperties(root.get()); |
| 7491 | host()->host_impl()->CreatePendingTree(); |
| 7492 | host()->CommitAndCreatePendingTree(); |
| 7493 | host()->host_impl()->ActivateSyncTree(); |
| 7494 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7495 | |
| 7496 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7497 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7498 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7499 | |
| 7500 | // Initially the sticky element is moved the leftmost side of the container. |
| 7501 | ExecuteCalculateDrawProperties(root_impl); |
| 7502 | EXPECT_VECTOR2DF_EQ( |
| 7503 | gfx::Vector2dF(100.f, 0.f), |
| 7504 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7505 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f)); |
| 7506 | ExecuteCalculateDrawProperties(root_impl); |
| 7507 | EXPECT_VECTOR2DF_EQ( |
| 7508 | gfx::Vector2dF(95.f, 0.f), |
| 7509 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7510 | |
| 7511 | // Once we get past the left side of the container it moves to be aligned 10px |
| 7512 | // up from the the right of the scroller. |
| 7513 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f)); |
| 7514 | ExecuteCalculateDrawProperties(root_impl); |
| 7515 | EXPECT_VECTOR2DF_EQ( |
| 7516 | gfx::Vector2dF(80.f, 0.f), |
| 7517 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7518 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f)); |
| 7519 | ExecuteCalculateDrawProperties(root_impl); |
| 7520 | EXPECT_VECTOR2DF_EQ( |
| 7521 | gfx::Vector2dF(80.f, 0.f), |
| 7522 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7523 | |
| 7524 | // When we get to the sticky element's original position we stop sticking |
| 7525 | // to the right. |
| 7526 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f)); |
| 7527 | ExecuteCalculateDrawProperties(root_impl); |
| 7528 | EXPECT_VECTOR2DF_EQ( |
| 7529 | gfx::Vector2dF(50.f, 0.f), |
| 7530 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7531 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f)); |
| 7532 | ExecuteCalculateDrawProperties(root_impl); |
| 7533 | EXPECT_VECTOR2DF_EQ( |
| 7534 | gfx::Vector2dF(40.f, 0.f), |
| 7535 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7536 | |
| 7537 | // The element starts sticking to the left once we scroll far enough. |
| 7538 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f)); |
| 7539 | ExecuteCalculateDrawProperties(root_impl); |
| 7540 | EXPECT_VECTOR2DF_EQ( |
| 7541 | gfx::Vector2dF(10.f, 0.f), |
| 7542 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7543 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f)); |
| 7544 | ExecuteCalculateDrawProperties(root_impl); |
| 7545 | EXPECT_VECTOR2DF_EQ( |
| 7546 | gfx::Vector2dF(10.f, 0.f), |
| 7547 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7548 | |
| 7549 | // Finally it stops sticking when it hits the right side of the container. |
| 7550 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f)); |
| 7551 | ExecuteCalculateDrawProperties(root_impl); |
| 7552 | EXPECT_VECTOR2DF_EQ( |
| 7553 | gfx::Vector2dF(0.f, 0.f), |
| 7554 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7555 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f)); |
| 7556 | ExecuteCalculateDrawProperties(root_impl); |
| 7557 | EXPECT_VECTOR2DF_EQ( |
| 7558 | gfx::Vector2dF(-5.f, 0.f), |
| 7559 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7560 | } |
| 7561 | |
| 7562 | // This test ensures that the compositor sticky position code correctly accounts |
| 7563 | // for the element having been given a position from the main thread sticky |
| 7564 | // position code. |
| 7565 | TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) { |
| 7566 | scoped_refptr<Layer> root = Layer::Create(); |
| 7567 | scoped_refptr<Layer> container = Layer::Create(); |
| 7568 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7569 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7570 | root->AddChild(container); |
| 7571 | container->AddChild(scroller); |
| 7572 | scroller->AddChild(sticky_pos); |
| 7573 | host()->SetRootLayer(root); |
| 7574 | scroller->SetScrollClipLayerId(container->id()); |
| 7575 | |
| 7576 | LayerStickyPositionConstraint sticky_position; |
| 7577 | sticky_position.is_sticky = true; |
| 7578 | sticky_position.is_anchored_top = true; |
| 7579 | sticky_position.top_offset = 10.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7580 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7581 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7582 | gfx::Rect(10, 20, 10, 10); |
| 7583 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7584 | gfx::Rect(0, 0, 50, 50); |
| 7585 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7586 | |
| 7587 | root->SetBounds(gfx::Size(100, 100)); |
| 7588 | container->SetBounds(gfx::Size(100, 100)); |
| 7589 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7590 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7591 | sticky_pos->SetPosition(gfx::PointF(10, 20)); |
| 7592 | |
| 7593 | ExecuteCalculateDrawProperties(root.get()); |
| 7594 | host()->host_impl()->CreatePendingTree(); |
| 7595 | host()->CommitAndCreatePendingTree(); |
| 7596 | host()->host_impl()->ActivateSyncTree(); |
| 7597 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7598 | |
| 7599 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7600 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7601 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7602 | |
| 7603 | ExecuteCalculateDrawProperties(root_impl); |
| 7604 | EXPECT_VECTOR2DF_EQ( |
| 7605 | gfx::Vector2dF(10.f, 20.f), |
| 7606 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7607 | |
| 7608 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7609 | // we haven't gotten to the initial sticky item location yet. |
| 7610 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 7611 | ExecuteCalculateDrawProperties(root_impl); |
| 7612 | EXPECT_VECTOR2DF_EQ( |
| 7613 | gfx::Vector2dF(5.f, 15.f), |
| 7614 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7615 | |
| 7616 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 7617 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 7618 | ExecuteCalculateDrawProperties(root_impl); |
| 7619 | EXPECT_VECTOR2DF_EQ( |
| 7620 | gfx::Vector2dF(-5.f, 10.f), |
| 7621 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7622 | |
| 7623 | // Now the main thread commits the new position of the sticky element. |
| 7624 | scroller->SetScrollOffset(gfx::ScrollOffset(15, 15)); |
| 7625 | sticky_pos->SetPosition(gfx::PointF(10, 25)); |
| 7626 | ExecuteCalculateDrawProperties(root.get()); |
| 7627 | host()->host_impl()->CreatePendingTree(); |
| 7628 | host()->CommitAndCreatePendingTree(); |
| 7629 | host()->host_impl()->ActivateSyncTree(); |
| 7630 | layer_tree_impl = host()->host_impl()->active_tree(); |
| 7631 | root_impl = layer_tree_impl->LayerById(root->id()); |
| 7632 | scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7633 | sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7634 | |
| 7635 | // The element should still be where it was before. We reset the delta to |
| 7636 | // (0, 0) because we have synced a scroll offset of (15, 15) from the main |
| 7637 | // thread. |
| 7638 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); |
| 7639 | ExecuteCalculateDrawProperties(root_impl); |
| 7640 | EXPECT_VECTOR2DF_EQ( |
| 7641 | gfx::Vector2dF(-5.f, 10.f), |
| 7642 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7643 | |
| 7644 | // And if we scroll a little further it remains there. |
| 7645 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); |
| 7646 | ExecuteCalculateDrawProperties(root_impl); |
| 7647 | EXPECT_VECTOR2DF_EQ( |
| 7648 | gfx::Vector2dF(-5.f, 10.f), |
| 7649 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7650 | } |
| 7651 | |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7652 | // This tests the main thread updates with a composited sticky container. In |
| 7653 | // this case the position received from main is relative to the container but |
| 7654 | // the constraint rects are relative to the ancestor scroller. |
| 7655 | TEST_F(LayerTreeHostCommonTest, StickyPositionCompositedContainer) { |
| 7656 | scoped_refptr<Layer> root = Layer::Create(); |
| 7657 | scoped_refptr<Layer> container = Layer::Create(); |
| 7658 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7659 | scoped_refptr<Layer> sticky_container = Layer::Create(); |
| 7660 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7661 | root->AddChild(container); |
| 7662 | container->AddChild(scroller); |
| 7663 | scroller->AddChild(sticky_container); |
| 7664 | sticky_container->AddChild(sticky_pos); |
| 7665 | host()->SetRootLayer(root); |
| 7666 | scroller->SetScrollClipLayerId(container->id()); |
| 7667 | |
| 7668 | LayerStickyPositionConstraint sticky_position; |
| 7669 | sticky_position.is_sticky = true; |
| 7670 | sticky_position.is_anchored_top = true; |
| 7671 | sticky_position.top_offset = 10.0f; |
| 7672 | // The sticky position layer is only offset by (0, 10) from its parent |
| 7673 | // layer, this position is used to determine the offset applied by the main |
| 7674 | // thread. |
| 7675 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 10); |
| 7676 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7677 | gfx::Rect(20, 30, 10, 10); |
| 7678 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7679 | gfx::Rect(20, 20, 30, 30); |
| 7680 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7681 | |
| 7682 | root->SetBounds(gfx::Size(100, 100)); |
| 7683 | container->SetBounds(gfx::Size(100, 100)); |
| 7684 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7685 | sticky_container->SetPosition(gfx::PointF(20, 20)); |
| 7686 | sticky_container->SetBounds(gfx::Size(30, 30)); |
| 7687 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7688 | sticky_pos->SetPosition(gfx::PointF(0, 10)); |
| 7689 | |
| 7690 | ExecuteCalculateDrawProperties(root.get()); |
| 7691 | host()->host_impl()->CreatePendingTree(); |
| 7692 | host()->CommitAndCreatePendingTree(); |
| 7693 | host()->host_impl()->ActivateSyncTree(); |
| 7694 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7695 | |
| 7696 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7697 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7698 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7699 | |
| 7700 | ExecuteCalculateDrawProperties(root_impl); |
| 7701 | EXPECT_VECTOR2DF_EQ( |
| 7702 | gfx::Vector2dF(20.f, 30.f), |
| 7703 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7704 | |
| 7705 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7706 | // we haven't gotten to the initial sticky item location yet. |
| 7707 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 7708 | ExecuteCalculateDrawProperties(root_impl); |
| 7709 | EXPECT_VECTOR2DF_EQ( |
| 7710 | gfx::Vector2dF(20.f, 25.f), |
| 7711 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7712 | |
| 7713 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 7714 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7715 | ExecuteCalculateDrawProperties(root_impl); |
| 7716 | EXPECT_VECTOR2DF_EQ( |
| 7717 | gfx::Vector2dF(20.f, 10.f), |
| 7718 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7719 | |
| 7720 | // Now the main thread commits the new position of the sticky element. |
| 7721 | scroller->SetScrollOffset(gfx::ScrollOffset(0, 25)); |
| 7722 | sticky_pos->SetPosition(gfx::PointF(0, 15)); |
| 7723 | ExecuteCalculateDrawProperties(root.get()); |
| 7724 | host()->host_impl()->CreatePendingTree(); |
| 7725 | host()->CommitAndCreatePendingTree(); |
| 7726 | host()->host_impl()->ActivateSyncTree(); |
| 7727 | layer_tree_impl = host()->host_impl()->active_tree(); |
| 7728 | root_impl = layer_tree_impl->LayerById(root->id()); |
| 7729 | scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7730 | sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7731 | |
| 7732 | // The element should still be where it was before. We reset the delta to |
| 7733 | // (0, 0) because we have synced a scroll offset of (0, 25) from the main |
| 7734 | // thread. |
| 7735 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); |
| 7736 | ExecuteCalculateDrawProperties(root_impl); |
| 7737 | EXPECT_VECTOR2DF_EQ( |
| 7738 | gfx::Vector2dF(20.f, 10.f), |
| 7739 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7740 | |
| 7741 | // And if we scroll a little further it remains there. |
| 7742 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 7743 | ExecuteCalculateDrawProperties(root_impl); |
| 7744 | EXPECT_VECTOR2DF_EQ( |
| 7745 | gfx::Vector2dF(20.f, 10.f), |
| 7746 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7747 | |
| 7748 | // And hits the bottom of the container. |
| 7749 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); |
| 7750 | ExecuteCalculateDrawProperties(root_impl); |
| 7751 | EXPECT_VECTOR2DF_EQ( |
| 7752 | gfx::Vector2dF(20.f, 5.f), |
| 7753 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7754 | } |
| 7755 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7756 | // A transform on a sticky element should not affect its sticky position. |
| 7757 | TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) { |
| 7758 | scoped_refptr<Layer> root = Layer::Create(); |
| 7759 | scoped_refptr<Layer> container = Layer::Create(); |
| 7760 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7761 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7762 | root->AddChild(container); |
| 7763 | container->AddChild(scroller); |
| 7764 | scroller->AddChild(sticky_pos); |
| 7765 | host()->SetRootLayer(root); |
| 7766 | scroller->SetScrollClipLayerId(container->id()); |
| 7767 | gfx::Transform t; |
| 7768 | t.Scale(2, 2); |
| 7769 | sticky_pos->SetTransform(t); |
| 7770 | |
| 7771 | LayerStickyPositionConstraint sticky_position; |
| 7772 | sticky_position.is_sticky = true; |
| 7773 | sticky_position.is_anchored_top = true; |
| 7774 | sticky_position.top_offset = 0.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7775 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7776 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7777 | gfx::Rect(0, 20, 10, 10); |
| 7778 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7779 | gfx::Rect(0, 0, 50, 50); |
| 7780 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7781 | |
| 7782 | root->SetBounds(gfx::Size(100, 100)); |
| 7783 | container->SetBounds(gfx::Size(100, 100)); |
| 7784 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7785 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7786 | sticky_pos->SetPosition(gfx::PointF(0, 20)); |
| 7787 | |
| 7788 | ExecuteCalculateDrawProperties(root.get()); |
| 7789 | host()->host_impl()->CreatePendingTree(); |
| 7790 | host()->CommitAndCreatePendingTree(); |
| 7791 | host()->host_impl()->ActivateSyncTree(); |
| 7792 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7793 | |
| 7794 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7795 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7796 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7797 | |
| 7798 | ExecuteCalculateDrawProperties(root_impl); |
| 7799 | EXPECT_VECTOR2DF_EQ( |
| 7800 | gfx::Vector2dF(0.f, 20.f), |
| 7801 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7802 | |
| 7803 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7804 | // we haven't gotten to the initial sticky item location yet. |
| 7805 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f)); |
| 7806 | ExecuteCalculateDrawProperties(root_impl); |
| 7807 | EXPECT_VECTOR2DF_EQ( |
| 7808 | gfx::Vector2dF(0.f, 5.f), |
| 7809 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7810 | |
| 7811 | // Scroll past the sticking point, the box is positioned at the scroller |
| 7812 | // edge. |
| 7813 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7814 | ExecuteCalculateDrawProperties(root_impl); |
| 7815 | EXPECT_VECTOR2DF_EQ( |
| 7816 | gfx::Vector2dF(0.f, 0.f), |
| 7817 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7818 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7819 | ExecuteCalculateDrawProperties(root_impl); |
| 7820 | EXPECT_VECTOR2DF_EQ( |
| 7821 | gfx::Vector2dF(0.f, 0.f), |
| 7822 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7823 | |
| 7824 | // Scroll past the end of the sticky container. |
| 7825 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); |
| 7826 | ExecuteCalculateDrawProperties(root_impl); |
| 7827 | EXPECT_VECTOR2DF_EQ( |
| 7828 | gfx::Vector2dF(0.f, -10.f), |
| 7829 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7830 | } |
| 7831 | |
| 7832 | // Tests that a transform does not affect the sticking points. The sticky |
| 7833 | // element will however move relative to the viewport due to its transform. |
| 7834 | TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) { |
| 7835 | scoped_refptr<Layer> root = Layer::Create(); |
| 7836 | scoped_refptr<Layer> container = Layer::Create(); |
| 7837 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7838 | scoped_refptr<Layer> sticky_container = Layer::Create(); |
| 7839 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7840 | root->AddChild(container); |
| 7841 | container->AddChild(scroller); |
| 7842 | scroller->AddChild(sticky_container); |
| 7843 | sticky_container->AddChild(sticky_pos); |
| 7844 | host()->SetRootLayer(root); |
| 7845 | scroller->SetScrollClipLayerId(container->id()); |
| 7846 | gfx::Transform t; |
| 7847 | t.Scale(2, 2); |
| 7848 | sticky_container->SetTransform(t); |
| 7849 | |
| 7850 | LayerStickyPositionConstraint sticky_position; |
| 7851 | sticky_position.is_sticky = true; |
| 7852 | sticky_position.is_anchored_top = true; |
| 7853 | sticky_position.top_offset = 0.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7854 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7855 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7856 | gfx::Rect(0, 20, 10, 10); |
| 7857 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7858 | gfx::Rect(0, 0, 50, 50); |
| 7859 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7860 | |
| 7861 | root->SetBounds(gfx::Size(100, 100)); |
| 7862 | container->SetBounds(gfx::Size(100, 100)); |
| 7863 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7864 | sticky_container->SetBounds(gfx::Size(50, 50)); |
| 7865 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7866 | sticky_pos->SetPosition(gfx::PointF(0, 20)); |
| 7867 | |
| 7868 | ExecuteCalculateDrawProperties(root.get()); |
| 7869 | host()->host_impl()->CreatePendingTree(); |
| 7870 | host()->CommitAndCreatePendingTree(); |
| 7871 | host()->host_impl()->ActivateSyncTree(); |
| 7872 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7873 | |
| 7874 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7875 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7876 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7877 | |
| 7878 | ExecuteCalculateDrawProperties(root_impl); |
| 7879 | EXPECT_VECTOR2DF_EQ( |
| 7880 | gfx::Vector2dF(0.f, 40.f), |
| 7881 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7882 | |
| 7883 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7884 | // we haven't gotten to the initial sticky item location yet. |
| 7885 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f)); |
| 7886 | ExecuteCalculateDrawProperties(root_impl); |
| 7887 | EXPECT_VECTOR2DF_EQ( |
| 7888 | gfx::Vector2dF(0.f, 25.f), |
| 7889 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7890 | |
| 7891 | // Scroll past the sticking point, the box is positioned at the scroller |
| 7892 | // edge but is also scaled by its container so it begins to move down. |
| 7893 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7894 | ExecuteCalculateDrawProperties(root_impl); |
| 7895 | EXPECT_VECTOR2DF_EQ( |
| 7896 | gfx::Vector2dF(0.f, 25.f), |
| 7897 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7898 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7899 | ExecuteCalculateDrawProperties(root_impl); |
| 7900 | EXPECT_VECTOR2DF_EQ( |
| 7901 | gfx::Vector2dF(0.f, 30.f), |
| 7902 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7903 | |
| 7904 | // Scroll past the end of the sticky container. |
| 7905 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); |
| 7906 | ExecuteCalculateDrawProperties(root_impl); |
| 7907 | EXPECT_VECTOR2DF_EQ( |
| 7908 | gfx::Vector2dF(0.f, 30.f), |
| 7909 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7910 | } |
| 7911 | |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7912 | TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { |
| 7913 | scoped_refptr<Layer> root = Layer::Create(); |
| 7914 | scoped_refptr<Layer> container = Layer::Create(); |
| 7915 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7916 | scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 7917 | |
| 7918 | scroller->SetIsContainerForFixedPositionLayers(true); |
| 7919 | root->AddChild(container); |
| 7920 | container->AddChild(scroller); |
| 7921 | scroller->AddChild(fixed_pos); |
| 7922 | host()->SetRootLayer(root); |
| 7923 | |
| 7924 | LayerPositionConstraint fixed_position; |
| 7925 | fixed_position.set_is_fixed_position(true); |
| 7926 | scroller->SetScrollClipLayerId(container->id()); |
| 7927 | fixed_pos->SetPositionConstraint(fixed_position); |
| 7928 | |
| 7929 | root->SetBounds(gfx::Size(50, 50)); |
| 7930 | container->SetBounds(gfx::Size(50, 50)); |
| 7931 | scroller->SetBounds(gfx::Size(50, 50)); |
| 7932 | fixed_pos->SetBounds(gfx::Size(50, 50)); |
| 7933 | |
| 7934 | gfx::Transform rotate; |
| 7935 | rotate.RotateAboutXAxis(20); |
| 7936 | container->SetTransform(rotate); |
| 7937 | |
| 7938 | ExecuteCalculateDrawProperties(root.get()); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 7939 | TransformTree& tree = |
| 7940 | root->layer_tree_host()->property_trees()->transform_tree; |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7941 | gfx::Transform transform; |
| 7942 | tree.ComputeTranslation(fixed_pos->transform_tree_index(), |
| 7943 | container->transform_tree_index(), &transform); |
| 7944 | EXPECT_TRUE(transform.IsIdentity()); |
| 7945 | } |
| 7946 | |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 7947 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) { |
| 7948 | // This test verifies that a fixed pos child of a scrolling layer doesn't get |
| 7949 | // snapped to integer coordinates. |
| 7950 | // |
| 7951 | // + root |
| 7952 | // + container |
| 7953 | // + scroller |
| 7954 | // + fixed_pos |
| 7955 | // |
| 7956 | scoped_refptr<Layer> root = Layer::Create(); |
| 7957 | scoped_refptr<Layer> container = Layer::Create(); |
| 7958 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7959 | scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 7960 | |
| 7961 | scroller->SetIsContainerForFixedPositionLayers(true); |
| 7962 | |
| 7963 | root->AddChild(container); |
| 7964 | container->AddChild(scroller); |
| 7965 | scroller->AddChild(fixed_pos); |
| 7966 | host()->SetRootLayer(root); |
| 7967 | |
| 7968 | LayerPositionConstraint fixed_position; |
| 7969 | fixed_position.set_is_fixed_position(true); |
| 7970 | scroller->SetScrollClipLayerId(container->id()); |
| 7971 | fixed_pos->SetPositionConstraint(fixed_position); |
| 7972 | |
| 7973 | root->SetBounds(gfx::Size(50, 50)); |
| 7974 | container->SetBounds(gfx::Size(50, 50)); |
| 7975 | scroller->SetBounds(gfx::Size(100, 100)); |
| 7976 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 7977 | fixed_pos->SetBounds(gfx::Size(10, 10)); |
| 7978 | |
| 7979 | ExecuteCalculateDrawProperties(root.get()); |
| 7980 | |
| 7981 | host()->host_impl()->CreatePendingTree(); |
| 7982 | host()->CommitAndCreatePendingTree(); |
| 7983 | host()->host_impl()->ActivateSyncTree(); |
| 7984 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7985 | |
| 7986 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7987 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7988 | LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id()); |
| 7989 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 7990 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 7991 | |
| 7992 | ExecuteCalculateDrawProperties(root_impl); |
| 7993 | |
| 7994 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 7995 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 7996 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7997 | |
| 7998 | gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f, |
| 7999 | 10.3f); |
| 8000 | EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation, |
| 8001 | fixed_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 8002 | } |
| 8003 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8004 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 8005 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8006 | static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8007 | LayerTreeImpl* tree_impl, |
| 8008 | int id) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8009 | return base::WrapUnique( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8010 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 8011 | } |
| 8012 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 8013 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8014 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8015 | private: |
| 8016 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 8017 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8018 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8019 | SetDrawsContent(true); |
| 8020 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8021 | }; |
| 8022 | |
| 8023 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8024 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8025 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8026 | LayerTreeSettings settings = host()->GetSettings(); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 8027 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8028 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8029 | &task_graph_runner); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8030 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8031 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8032 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8033 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8034 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8035 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8036 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8037 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 8038 | |
| 8039 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 8040 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 8041 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8042 | AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get(); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8043 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8044 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 8045 | parent->SetBounds(gfx::Size(1, 2)); |
| 8046 | child->SetBounds(gfx::Size(1, 2)); |
| 8047 | grand_child->SetBounds(gfx::Size(1, 2)); |
| 8048 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8049 | child->test_properties()->AddChild(std::move(grand_child)); |
| 8050 | parent->test_properties()->AddChild(std::move(child)); |
| 8051 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8052 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8053 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8054 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8055 | |
| 8056 | // No layers have animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8057 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 8058 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 8059 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 8060 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8061 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8062 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 8063 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 8064 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 8065 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 8066 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8067 | TransformOperations translation; |
| 8068 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 8069 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8070 | scoped_refptr<AnimationTimeline> timeline; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8071 | timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8072 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8073 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8074 | host_impl.active_tree()->SetElementIdsForTesting(); |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 8075 | |
| 8076 | scoped_refptr<AnimationPlayer> grand_parent_player = |
| 8077 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 8078 | timeline->AttachPlayer(grand_parent_player); |
| 8079 | grand_parent_player->AttachElement(grand_parent_raw->element_id()); |
| 8080 | |
| 8081 | scoped_refptr<AnimationPlayer> parent_player = |
| 8082 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 8083 | timeline->AttachPlayer(parent_player); |
| 8084 | parent_player->AttachElement(parent_raw->element_id()); |
| 8085 | |
| 8086 | scoped_refptr<AnimationPlayer> child_player = |
| 8087 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 8088 | timeline->AttachPlayer(child_player); |
| 8089 | child_player->AttachElement(child_raw->element_id()); |
| 8090 | |
| 8091 | scoped_refptr<AnimationPlayer> grand_child_player = |
| 8092 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 8093 | timeline->AttachPlayer(grand_child_player); |
| 8094 | grand_child_player->AttachElement(grand_child_raw->element_id()); |
| 8095 | |
| 8096 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 8097 | translation); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8098 | |
| 8099 | // No layers have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8100 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 8101 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 8102 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 8103 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8104 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8105 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 8106 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 8107 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 8108 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 8109 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8110 | TransformOperations scale; |
| 8111 | scale.AppendScale(5.f, 4.f, 3.f); |
| 8112 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 8113 | AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(), |
| 8114 | scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 8115 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8116 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8117 | |
| 8118 | // Only |child| has a scale-affecting animation. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8119 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 8120 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 8121 | EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw)); |
| 8122 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8123 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8124 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 8125 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 8126 | EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw)); |
| 8127 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 8128 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 8129 | AddAnimatedTransformToPlayer(grand_parent_player.get(), 1.0, |
| 8130 | TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8131 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8132 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8133 | |
| 8134 | // |grand_parent| and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8135 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 8136 | EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8137 | // We don't support combining animated scales from two nodes; 0.f means |
| 8138 | // that the maximum scale could not be computed. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8139 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 8140 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8141 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8142 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 8143 | EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw)); |
| 8144 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 8145 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 8146 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 8147 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 8148 | scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 8149 | parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8150 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8151 | |
| 8152 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8153 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 8154 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 8155 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 8156 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8157 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8158 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 8159 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 8160 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 8161 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 8162 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 8163 | grand_parent_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 8164 | parent_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 8165 | child_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8166 | |
| 8167 | TransformOperations perspective; |
| 8168 | perspective.AppendPerspective(10.f); |
| 8169 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 8170 | AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(), |
| 8171 | perspective); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 8172 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8173 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8174 | |
| 8175 | // |child| has a scale-affecting animation but computing the maximum of this |
| 8176 | // animation is not supported. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8177 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 8178 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 8179 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 8180 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8181 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8182 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 8183 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 8184 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 8185 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 8186 | |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 8187 | child_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 8188 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8189 | gfx::Transform scale_matrix; |
| 8190 | scale_matrix.Scale(1.f, 2.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8191 | grand_parent_raw->test_properties()->transform = scale_matrix; |
| 8192 | parent_raw->test_properties()->transform = scale_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8193 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8194 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 8195 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 8196 | scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8197 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8198 | |
| 8199 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 8200 | // animation with maximum scale 5.f. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8201 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 8202 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 8203 | EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw)); |
| 8204 | EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8205 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8206 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 8207 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 8208 | EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw)); |
| 8209 | EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 8210 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8211 | gfx::Transform perspective_matrix; |
| 8212 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8213 | child_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8214 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8215 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8216 | |
| 8217 | // |child| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8218 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 8219 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 8220 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 8221 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8222 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8223 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 8224 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 8225 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 8226 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 8227 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8228 | parent_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8229 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8230 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8231 | |
| 8232 | // |parent| and |child| have transforms that are neither translations nor |
| 8233 | // scales. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8234 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 8235 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 8236 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 8237 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8238 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8239 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 8240 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 8241 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 8242 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 8243 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8244 | parent_raw->test_properties()->transform = gfx::Transform(); |
| 8245 | child_raw->test_properties()->transform = gfx::Transform(); |
| 8246 | grand_parent_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8247 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8248 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8249 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8250 | |
| 8251 | // |grand_parent| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8252 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 8253 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 8254 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 8255 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 8256 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8257 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 8258 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 8259 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 8260 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8261 | } |
| 8262 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 8263 | static void GatherDrawnLayers(const LayerImplList* rsll, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8264 | std::set<LayerImpl*>* drawn_layers) { |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 8265 | for (LayerIterator it = LayerIterator::Begin(rsll), |
| 8266 | end = LayerIterator::End(rsll); |
| 8267 | it != end; ++it) { |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8268 | LayerImpl* layer = *it; |
| 8269 | if (it.represents_itself()) |
| 8270 | drawn_layers->insert(layer); |
| 8271 | |
| 8272 | if (!it.represents_contributing_render_surface()) |
| 8273 | continue; |
| 8274 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8275 | if (layer->render_surface()->MaskLayer()) |
| 8276 | drawn_layers->insert(layer->render_surface()->MaskLayer()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8277 | } |
| 8278 | } |
| 8279 | |
| 8280 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8281 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8282 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8283 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8284 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8285 | std::unique_ptr<LayerImpl> grand_parent = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8286 | LayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8287 | std::unique_ptr<LayerImpl> parent = |
| 8288 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 8289 | std::unique_ptr<LayerImpl> child = |
| 8290 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 8291 | std::unique_ptr<LayerImpl> grand_child1 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8292 | LayerImpl::Create(host_impl.active_tree(), 7); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8293 | std::unique_ptr<LayerImpl> grand_child2 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8294 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 8295 | |
| 8296 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 8297 | LayerImpl* parent_raw = parent.get(); |
| 8298 | LayerImpl* child_raw = child.get(); |
| 8299 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 8300 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 8301 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8302 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 8303 | parent->SetBounds(gfx::Size(1, 2)); |
| 8304 | child->SetBounds(gfx::Size(1, 2)); |
| 8305 | grand_child1->SetBounds(gfx::Size(1, 2)); |
| 8306 | grand_child2->SetBounds(gfx::Size(1, 2)); |
| 8307 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8308 | child->test_properties()->AddChild(std::move(grand_child1)); |
| 8309 | child->test_properties()->AddChild(std::move(grand_child2)); |
| 8310 | parent->test_properties()->AddChild(std::move(child)); |
| 8311 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8312 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8313 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8314 | // Start with nothing being drawn. |
| 8315 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8316 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8317 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8318 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8319 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 8320 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8321 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8322 | |
| 8323 | std::set<LayerImpl*> expected; |
| 8324 | std::set<LayerImpl*> actual; |
| 8325 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8326 | EXPECT_EQ(expected, actual); |
| 8327 | |
| 8328 | // If we force render surface, but none of the layers are in the layer list, |
| 8329 | // then this layer should not appear in RSLL. |
ajuma | 35b24f6 | 2017-01-27 21:23:09 | [diff] [blame] | 8330 | grand_child1_raw->test_properties()->force_render_surface = true; |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 8331 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8332 | |
| 8333 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8334 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8335 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8336 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8337 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 8338 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8339 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8340 | |
| 8341 | expected.clear(); |
| 8342 | actual.clear(); |
| 8343 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8344 | EXPECT_EQ(expected, actual); |
| 8345 | |
| 8346 | // However, if we say that this layer also draws content, it will appear in |
| 8347 | // RSLL. |
| 8348 | grand_child1_raw->SetDrawsContent(true); |
| 8349 | |
| 8350 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8351 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8352 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8353 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8354 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 8355 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8356 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8357 | |
| 8358 | expected.clear(); |
| 8359 | expected.insert(grand_child1_raw); |
| 8360 | |
| 8361 | actual.clear(); |
| 8362 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8363 | EXPECT_EQ(expected, actual); |
| 8364 | |
| 8365 | // Now child is forced to have a render surface, and one if its children draws |
| 8366 | // content. |
| 8367 | grand_child1_raw->SetDrawsContent(false); |
ajuma | 35b24f6 | 2017-01-27 21:23:09 | [diff] [blame] | 8368 | grand_child1_raw->test_properties()->force_render_surface = false; |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 8369 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
ajuma | 35b24f6 | 2017-01-27 21:23:09 | [diff] [blame] | 8370 | child_raw->test_properties()->force_render_surface = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8371 | grand_child2_raw->SetDrawsContent(true); |
| 8372 | |
| 8373 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8374 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8375 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8376 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8377 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 8378 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8379 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8380 | |
| 8381 | expected.clear(); |
| 8382 | expected.insert(grand_child2_raw); |
| 8383 | |
| 8384 | actual.clear(); |
| 8385 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8386 | EXPECT_EQ(expected, actual); |
| 8387 | |
| 8388 | // Add a mask layer to child. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8389 | child_raw->test_properties()->SetMaskLayer( |
| 8390 | LayerImpl::Create(host_impl.active_tree(), 6)); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 8391 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8392 | |
| 8393 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8394 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8395 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8396 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8397 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8398 | EXPECT_TRUE(child_raw->test_properties() |
| 8399 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8400 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8401 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8402 | |
| 8403 | expected.clear(); |
| 8404 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8405 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8406 | |
| 8407 | expected.clear(); |
| 8408 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8409 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8410 | |
| 8411 | actual.clear(); |
| 8412 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8413 | EXPECT_EQ(expected, actual); |
| 8414 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8415 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8416 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8417 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8418 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8419 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8420 | EXPECT_TRUE(child_raw->test_properties() |
| 8421 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8422 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8423 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8424 | |
| 8425 | expected.clear(); |
| 8426 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8427 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8428 | |
| 8429 | actual.clear(); |
| 8430 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8431 | EXPECT_EQ(expected, actual); |
| 8432 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8433 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8434 | |
| 8435 | // With nothing drawing, we should have no layers. |
| 8436 | grand_child2_raw->SetDrawsContent(false); |
| 8437 | |
| 8438 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8439 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8440 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8441 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8442 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8443 | EXPECT_FALSE(child_raw->test_properties() |
| 8444 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8445 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8446 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8447 | |
| 8448 | expected.clear(); |
| 8449 | actual.clear(); |
| 8450 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8451 | EXPECT_EQ(expected, actual); |
| 8452 | |
| 8453 | // Child itself draws means that we should have the child and the mask in the |
| 8454 | // list. |
| 8455 | child_raw->SetDrawsContent(true); |
| 8456 | |
| 8457 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8458 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8459 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8460 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8461 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8462 | EXPECT_TRUE(child_raw->test_properties() |
| 8463 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8464 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8465 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8466 | |
| 8467 | expected.clear(); |
| 8468 | expected.insert(child_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8469 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8470 | actual.clear(); |
| 8471 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8472 | EXPECT_EQ(expected, actual); |
| 8473 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8474 | child_raw->test_properties()->SetMaskLayer(nullptr); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 8475 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8476 | |
| 8477 | // Now everyone's a member! |
| 8478 | grand_parent_raw->SetDrawsContent(true); |
| 8479 | parent_raw->SetDrawsContent(true); |
| 8480 | child_raw->SetDrawsContent(true); |
| 8481 | grand_child1_raw->SetDrawsContent(true); |
| 8482 | grand_child2_raw->SetDrawsContent(true); |
| 8483 | |
| 8484 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8485 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8486 | EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8487 | EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8488 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 8489 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8490 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8491 | |
| 8492 | expected.clear(); |
| 8493 | expected.insert(grand_parent_raw); |
| 8494 | expected.insert(parent_raw); |
| 8495 | expected.insert(child_raw); |
| 8496 | expected.insert(grand_child1_raw); |
| 8497 | expected.insert(grand_child2_raw); |
| 8498 | |
| 8499 | actual.clear(); |
| 8500 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8501 | EXPECT_EQ(expected, actual); |
| 8502 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8503 | |
| 8504 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8505 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8506 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8507 | LayerTreeSettings settings = host()->GetSettings(); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8508 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8509 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8510 | &task_graph_runner); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8511 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8512 | std::unique_ptr<LayerImpl> root = |
| 8513 | LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8514 | LayerImpl* root_layer = root.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8515 | std::unique_ptr<LayerImpl> child1 = |
| 8516 | LayerImpl::Create(host_impl.active_tree(), 2); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8517 | LayerImpl* child1_layer = child1.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8518 | std::unique_ptr<LayerImpl> child2 = |
| 8519 | LayerImpl::Create(host_impl.active_tree(), 3); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8520 | LayerImpl* child2_layer = child2.get(); |
| 8521 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8522 | gfx::Transform scale_transform_child1, scale_transform_child2; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8523 | scale_transform_child1.Scale(2, 3); |
| 8524 | scale_transform_child2.Scale(4, 5); |
| 8525 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8526 | root->SetBounds(gfx::Size(1, 1)); |
| 8527 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8528 | child1_layer->test_properties()->transform = scale_transform_child1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8529 | child1_layer->SetBounds(gfx::Size(1, 1)); |
| 8530 | child1_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8531 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8532 | child1_layer->test_properties()->SetMaskLayer( |
| 8533 | LayerImpl::Create(host_impl.active_tree(), 4)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8534 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8535 | root->test_properties()->AddChild(std::move(child1)); |
| 8536 | root->test_properties()->AddChild(std::move(child2)); |
| 8537 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8538 | host_impl.active_tree()->SetElementIdsForTesting(); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8539 | |
| 8540 | ExecuteCalculateDrawProperties(root_layer); |
| 8541 | |
| 8542 | TransformOperations scale; |
| 8543 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8544 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8545 | scoped_refptr<AnimationTimeline> timeline = |
| 8546 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8547 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8548 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8549 | child2_layer->test_properties()->transform = scale_transform_child2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8550 | child2_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 8551 | child2_layer->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8552 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 8553 | 1.0, TransformOperations(), scale); |
| 8554 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8555 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8556 | ExecuteCalculateDrawProperties(root_layer); |
| 8557 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8558 | EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale()); |
| 8559 | EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8560 | EXPECT_FLOAT_EQ( |
| 8561 | 3.f, |
| 8562 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8563 | EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8564 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8565 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8566 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8567 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8568 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8569 | // Changing page-scale would affect ideal_contents_scale and |
| 8570 | // maximum_animation_contents_scale. |
| 8571 | |
| 8572 | float page_scale_factor = 3.f; |
| 8573 | float device_scale_factor = 1.0f; |
| 8574 | std::vector<LayerImpl*> render_surface_layer_list; |
| 8575 | gfx::Size device_viewport_size = |
| 8576 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 8577 | root_layer->bounds().height() * device_scale_factor); |
| 8578 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8579 | root_layer, device_viewport_size, &render_surface_layer_list); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8580 | |
| 8581 | inputs.page_scale_factor = page_scale_factor; |
| 8582 | inputs.can_adjust_raster_scales = true; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 8583 | inputs.page_scale_layer = root_layer; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8584 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8585 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8586 | EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale()); |
| 8587 | EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8588 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8589 | 9.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8590 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8591 | EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8592 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8593 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8594 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8595 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8596 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8597 | // Changing device-scale would affect ideal_contents_scale and |
| 8598 | // maximum_animation_contents_scale. |
| 8599 | |
| 8600 | device_scale_factor = 4.0f; |
| 8601 | inputs.device_scale_factor = device_scale_factor; |
| 8602 | inputs.can_adjust_raster_scales = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8603 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8604 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8605 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8606 | EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale()); |
| 8607 | EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8608 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8609 | 36.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8610 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8611 | EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8612 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8613 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8614 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8615 | EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer)); |
| 8616 | } |
| 8617 | |
| 8618 | TEST_F(LayerTreeHostCommonTest, AnimationScales) { |
| 8619 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8620 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8621 | LayerTreeSettings settings = host()->GetSettings(); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8622 | settings.layer_transforms_should_scale_layer_contents = true; |
| 8623 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8624 | &task_graph_runner); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8625 | |
| 8626 | std::unique_ptr<LayerImpl> root = |
| 8627 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8628 | LayerImpl* root_layer = root.get(); |
| 8629 | std::unique_ptr<LayerImpl> child1 = |
| 8630 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8631 | LayerImpl* child1_layer = child1.get(); |
| 8632 | std::unique_ptr<LayerImpl> child2 = |
| 8633 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 8634 | LayerImpl* child2_layer = child2.get(); |
| 8635 | |
| 8636 | root->test_properties()->AddChild(std::move(child1)); |
| 8637 | child1_layer->test_properties()->AddChild(std::move(child2)); |
| 8638 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8639 | |
| 8640 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 8641 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8642 | gfx::Transform scale_transform_child1, scale_transform_child2; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8643 | scale_transform_child1.Scale(2, 3); |
| 8644 | scale_transform_child2.Scale(4, 5); |
| 8645 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8646 | root_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8647 | child1_layer->test_properties()->transform = scale_transform_child1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8648 | child1_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8649 | child2_layer->test_properties()->transform = scale_transform_child2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8650 | child2_layer->SetBounds(gfx::Size(1, 1)); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8651 | |
| 8652 | TransformOperations scale; |
| 8653 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8654 | |
| 8655 | scoped_refptr<AnimationTimeline> timeline = |
| 8656 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8657 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 8658 | |
| 8659 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 8660 | 1.0, TransformOperations(), scale); |
| 8661 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8662 | // Correctly computes animation scale when rebuilding property trees. |
| 8663 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8664 | ExecuteCalculateDrawProperties(root_layer); |
| 8665 | |
| 8666 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8667 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8668 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
| 8669 | |
| 8670 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 8671 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer)); |
| 8672 | EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer)); |
| 8673 | |
| 8674 | // Correctly updates animation scale when layer property changes. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8675 | child1_layer->test_properties()->transform = gfx::Transform(); |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 8676 | root_layer->layer_tree_impl() |
| 8677 | ->property_trees() |
| 8678 | ->transform_tree.OnTransformAnimated(gfx::Transform(), |
| 8679 | child1_layer->transform_tree_index(), |
| 8680 | root_layer->layer_tree_impl()); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8681 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false; |
| 8682 | ExecuteCalculateDrawProperties(root_layer); |
| 8683 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
| 8684 | EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer)); |
| 8685 | |
| 8686 | // Do not update animation scale if already updated. |
| 8687 | host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting( |
| 8688 | child2_layer->transform_tree_index(), 100.f, 100.f); |
| 8689 | EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer)); |
| 8690 | EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer)); |
| 8691 | } |
| 8692 | |
| 8693 | TEST_F(LayerTreeHostCommonTest, |
| 8694 | AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) { |
| 8695 | // Returns empty scale if layer_transforms_should_scale_layer_contents is |
| 8696 | // false. |
| 8697 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8698 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8699 | LayerTreeSettings settings = host()->GetSettings(); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8700 | settings.layer_transforms_should_scale_layer_contents = false; |
| 8701 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8702 | &task_graph_runner); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8703 | |
| 8704 | std::unique_ptr<LayerImpl> root = |
| 8705 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8706 | LayerImpl* root_layer = root.get(); |
| 8707 | std::unique_ptr<LayerImpl> child = |
| 8708 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8709 | LayerImpl* child_layer = child.get(); |
| 8710 | |
| 8711 | root->test_properties()->AddChild(std::move(child)); |
| 8712 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8713 | |
| 8714 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 8715 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8716 | gfx::Transform scale_transform_child; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8717 | scale_transform_child.Scale(4, 5); |
| 8718 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8719 | root_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8720 | child_layer->test_properties()->transform = scale_transform_child; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8721 | child_layer->SetBounds(gfx::Size(1, 1)); |
| 8722 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8723 | TransformOperations scale; |
| 8724 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8725 | |
| 8726 | scoped_refptr<AnimationTimeline> timeline = |
| 8727 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8728 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 8729 | |
| 8730 | AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline, |
| 8731 | 1.0, TransformOperations(), scale); |
| 8732 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8733 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8734 | ExecuteCalculateDrawProperties(root_layer); |
| 8735 | |
| 8736 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8737 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer)); |
| 8738 | |
| 8739 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 8740 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8741 | } |
| 8742 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8743 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8744 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8745 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 8746 | LayerImpl* content = AddChild<LayerImpl>(clip); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8747 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8748 | root->SetBounds(gfx::Size(768 / 2, 3000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8749 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8750 | clip->SetBounds(gfx::Size(768 / 2, 10000)); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8751 | clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8752 | content->SetBounds(gfx::Size(768 / 2, 10000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8753 | content->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8754 | content->test_properties()->force_render_surface = true; |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8755 | |
| 8756 | gfx::Size device_viewport_size(768, 582); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8757 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8758 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8759 | root, device_viewport_size, gfx::Transform(), |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8760 | &render_surface_layer_list_impl); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8761 | inputs.device_scale_factor = 2.f; |
| 8762 | inputs.page_scale_factor = 1.f; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 8763 | inputs.page_scale_layer = nullptr; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8764 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8765 | |
| 8766 | // Layers in the root render surface have their visible content rect clipped |
| 8767 | // by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8768 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8769 | |
| 8770 | // Layers drawing to a child render surface should still have their visible |
| 8771 | // content rect clipped by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8772 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8773 | } |
| 8774 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8775 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8776 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8777 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 8778 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8779 | |
| 8780 | // Set two layers: the root layer clips it's child, |
| 8781 | // the child draws its content. |
| 8782 | |
| 8783 | gfx::Size root_size = gfx::Size(300, 500); |
| 8784 | |
| 8785 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8786 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8787 | |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 8788 | // Device viewport accomidated the root and the browser controls. |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8789 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8790 | |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 8791 | host_impl.SetViewportSize(device_viewport_size); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8792 | host_impl.active_tree()->SetRootLayerForTesting( |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8793 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8794 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8795 | LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8796 | root->SetBounds(root_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8797 | root->SetMasksToBounds(true); |
| 8798 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8799 | root->test_properties()->AddChild( |
| 8800 | LayerImpl::Create(host_impl.active_tree(), 2)); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8801 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 8802 | LayerImpl* sublayer = root->test_properties()->children[0]; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8803 | sublayer->SetBounds(sublayer_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8804 | sublayer->SetDrawsContent(true); |
| 8805 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8806 | host_impl.active_tree()->BuildPropertyTreesForTesting(); |
| 8807 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8808 | LayerImplList layer_impl_list; |
| 8809 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8810 | root, device_viewport_size, &layer_impl_list); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8811 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8812 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8813 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8814 | |
| 8815 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8816 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8817 | |
| 8818 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8819 | root_size.height() + 50); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8820 | EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8821 | } |
| 8822 | |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8823 | TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8824 | scoped_refptr<Layer> root = Layer::Create(); |
| 8825 | scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create(); |
| 8826 | scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); |
| 8827 | scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create(); |
| 8828 | scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8829 | |
| 8830 | root->AddChild(inner_viewport_container_layer); |
| 8831 | inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer); |
| 8832 | inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); |
| 8833 | outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); |
| 8834 | |
| 8835 | inner_viewport_scroll_layer->SetScrollClipLayerId( |
| 8836 | inner_viewport_container_layer->id()); |
| 8837 | outer_viewport_scroll_layer->SetScrollClipLayerId( |
| 8838 | outer_viewport_container_layer->id()); |
| 8839 | |
| 8840 | inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8841 | outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8842 | |
| 8843 | host()->SetRootLayer(root); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 8844 | host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer, |
| 8845 | outer_viewport_scroll_layer); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8846 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8847 | scoped_refptr<Layer> fixed_to_inner = Layer::Create(); |
| 8848 | scoped_refptr<Layer> fixed_to_outer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8849 | |
| 8850 | inner_viewport_scroll_layer->AddChild(fixed_to_inner); |
| 8851 | outer_viewport_scroll_layer->AddChild(fixed_to_outer); |
| 8852 | |
| 8853 | LayerPositionConstraint fixed_to_right; |
| 8854 | fixed_to_right.set_is_fixed_position(true); |
| 8855 | fixed_to_right.set_is_fixed_to_right_edge(true); |
| 8856 | |
| 8857 | fixed_to_inner->SetPositionConstraint(fixed_to_right); |
| 8858 | fixed_to_outer->SetPositionConstraint(fixed_to_right); |
| 8859 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8860 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8861 | |
| 8862 | TransformTree& transform_tree = host()->property_trees()->transform_tree; |
| 8863 | EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8864 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8865 | |
| 8866 | LayerPositionConstraint fixed_to_left; |
| 8867 | fixed_to_left.set_is_fixed_position(true); |
| 8868 | fixed_to_inner->SetPositionConstraint(fixed_to_left); |
| 8869 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8870 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8871 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8872 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8873 | |
| 8874 | fixed_to_outer->SetPositionConstraint(fixed_to_left); |
| 8875 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8876 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8877 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8878 | EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8879 | } |
| 8880 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8881 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8882 | host_impl()->CreatePendingTree(); |
| 8883 | std::unique_ptr<LayerImpl> pending_root = |
| 8884 | LayerImpl::Create(host_impl()->pending_tree(), 1); |
| 8885 | LayerImpl* root = pending_root.get(); |
| 8886 | host_impl()->pending_tree()->SetRootLayerForTesting(std::move(pending_root)); |
| 8887 | std::unique_ptr<LayerImpl> animated_ptr = |
| 8888 | LayerImpl::Create(host_impl()->pending_tree(), 2); |
| 8889 | LayerImpl* animated = animated_ptr.get(); |
| 8890 | root->test_properties()->AddChild(std::move(animated_ptr)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8891 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8892 | animated->SetDrawsContent(true); |
| 8893 | host_impl()->pending_tree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8894 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8895 | root->SetBounds(gfx::Size(100, 100)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8896 | root->SetMasksToBounds(true); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8897 | root->test_properties()->force_render_surface = true; |
| 8898 | animated->test_properties()->opacity = 0.f; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8899 | animated->SetBounds(gfx::Size(20, 20)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8900 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8901 | AddOpacityTransitionToElementWithPlayer( |
| 8902 | animated->element_id(), timeline_impl(), 10.0, 0.f, 1.f, false); |
| 8903 | animated->test_properties()->opacity_can_animate = true; |
| 8904 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8905 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8906 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8907 | EXPECT_FALSE(animated->visible_layer_rect().IsEmpty()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8908 | } |
| 8909 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8910 | TEST_F(LayerTreeHostCommonTest, |
| 8911 | VisibleContentRectForAnimatedLayerWithSingularTransform) { |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8912 | LayerImpl* root = root_layer_for_testing(); |
| 8913 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 8914 | LayerImpl* animated = AddChild<LayerImpl>(clip); |
| 8915 | LayerImpl* surface = AddChild<LayerImpl>(animated); |
| 8916 | LayerImpl* descendant_of_animation = AddChild<LayerImpl>(surface); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8917 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8918 | SetElementIdsForTesting(); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8919 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8920 | animated->SetDrawsContent(true); |
| 8921 | surface->SetDrawsContent(true); |
| 8922 | descendant_of_animation->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8923 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8924 | gfx::Transform uninvertible_matrix; |
| 8925 | uninvertible_matrix.Scale3d(6.f, 6.f, 0.f); |
| 8926 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8927 | root->SetBounds(gfx::Size(100, 100)); |
| 8928 | clip->SetBounds(gfx::Size(10, 10)); |
| 8929 | clip->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8930 | animated->test_properties()->transform = uninvertible_matrix; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8931 | animated->SetBounds(gfx::Size(120, 120)); |
| 8932 | surface->SetBounds(gfx::Size(100, 100)); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8933 | surface->test_properties()->force_render_surface = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8934 | descendant_of_animation->SetBounds(gfx::Size(200, 200)); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8935 | |
| 8936 | TransformOperations start_transform_operations; |
| 8937 | start_transform_operations.AppendMatrix(uninvertible_matrix); |
| 8938 | TransformOperations end_transform_operations; |
| 8939 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8940 | AddAnimatedTransformToElementWithPlayer( |
| 8941 | animated->element_id(), timeline_impl(), 10.0, start_transform_operations, |
| 8942 | end_transform_operations); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8943 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8944 | |
| 8945 | // The animated layer has a singular transform and maps to a non-empty rect in |
| 8946 | // clipped target space, so is treated as fully visible. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8947 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8948 | |
| 8949 | // The singular transform on |animated| is flattened when inherited by |
| 8950 | // |surface|, and this happens to make it invertible. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8951 | EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect()); |
| 8952 | EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8953 | |
| 8954 | gfx::Transform zero_matrix; |
| 8955 | zero_matrix.Scale3d(0.f, 0.f, 0.f); |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 8956 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 8957 | zero_matrix, animated->transform_tree_index(), root->layer_tree_impl()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8958 | // While computing visible rects by combining clips in screen space, we set |
| 8959 | // the entire layer as visible if the screen space transform is singular. This |
| 8960 | // is not always true when we combine clips in target space because if the |
| 8961 | // intersection of combined_clip in taret space with layer_rect projected to |
| 8962 | // target space is empty, we set it to an empty rect. |
| 8963 | bool skip_verify_visible_rect_calculations = true; |
| 8964 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
| 8965 | root, skip_verify_visible_rect_calculations); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8966 | |
| 8967 | // The animated layer maps to the empty rect in clipped target space, so is |
| 8968 | // treated as having an empty visible rect. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8969 | EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8970 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8971 | // The animated layer will be treated as fully visible when we combine clips |
| 8972 | // in screen space. |
| 8973 | gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic( |
| 8974 | root->layer_tree_impl()->property_trees(), animated); |
| 8975 | EXPECT_EQ(gfx::Rect(120, 120), visible_rect); |
| 8976 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8977 | // This time, flattening does not make |animated|'s transform invertible. This |
| 8978 | // means the clip cannot be projected into |surface|'s space, so we treat |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8979 | // |surface| and layers that draw into it as having empty visible rect. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8980 | EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect()); |
| 8981 | EXPECT_EQ(gfx::Rect(), descendant_of_animation->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8982 | } |
| 8983 | |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8984 | // Verify that having animated opacity but current opacity 1 still creates |
| 8985 | // a render surface. |
| 8986 | TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) { |
| 8987 | LayerImpl* root = root_layer_for_testing(); |
| 8988 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8989 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8990 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8991 | root->SetBounds(gfx::Size(50, 50)); |
| 8992 | child->SetBounds(gfx::Size(50, 50)); |
| 8993 | child->SetDrawsContent(true); |
| 8994 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8995 | grandchild->SetDrawsContent(true); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8996 | |
| 8997 | SetElementIdsForTesting(); |
| 8998 | AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8999 | 10.0, 1.f, 0.2f, false); |
| 9000 | ExecuteCalculateDrawProperties(root); |
| 9001 | |
| 9002 | EXPECT_EQ(1.f, child->Opacity()); |
| 9003 | EXPECT_TRUE(root->has_render_surface()); |
| 9004 | EXPECT_TRUE(child->has_render_surface()); |
| 9005 | EXPECT_FALSE(grandchild->has_render_surface()); |
| 9006 | } |
| 9007 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 9008 | // Verify that having an animated filter (but no current filter, as these |
| 9009 | // are mutually exclusive) correctly creates a render surface. |
| 9010 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9011 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 9012 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 9013 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 9014 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9015 | root->SetBounds(gfx::Size(50, 50)); |
| 9016 | child->SetBounds(gfx::Size(50, 50)); |
| 9017 | grandchild->SetBounds(gfx::Size(50, 50)); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 9018 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9019 | SetElementIdsForTesting(); |
| 9020 | AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(), |
| 9021 | 10.0, 0.1f, 0.2f); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 9022 | ExecuteCalculateDrawProperties(root); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 9023 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 9024 | EXPECT_TRUE(root->has_render_surface()); |
| 9025 | EXPECT_TRUE(child->has_render_surface()); |
| 9026 | EXPECT_FALSE(grandchild->has_render_surface()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 9027 | |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 9028 | EXPECT_TRUE(root->render_surface()->Filters().IsEmpty()); |
| 9029 | EXPECT_TRUE(child->render_surface()->Filters().IsEmpty()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 9030 | |
| 9031 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 9032 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 9033 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 9034 | } |
| 9035 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9036 | // Verify that having a filter animation with a delayed start time creates a |
| 9037 | // render surface. |
| 9038 | TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9039 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 9040 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 9041 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9042 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9043 | root->SetBounds(gfx::Size(50, 50)); |
| 9044 | child->SetBounds(gfx::Size(50, 50)); |
| 9045 | grandchild->SetBounds(gfx::Size(50, 50)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9046 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9047 | SetElementIdsForTesting(); |
| 9048 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9049 | std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9050 | KeyframedFilterAnimationCurve::Create()); |
| 9051 | FilterOperations start_filters; |
| 9052 | start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f)); |
| 9053 | FilterOperations end_filters; |
| 9054 | end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f)); |
| 9055 | curve->AddKeyframe( |
| 9056 | FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 9057 | curve->AddKeyframe(FilterKeyframe::Create( |
| 9058 | base::TimeDelta::FromMilliseconds(100), end_filters, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9059 | std::unique_ptr<Animation> animation = |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 9060 | Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 9061 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9062 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9063 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9064 | AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(), |
| 9065 | std::move(animation)); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 9066 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9067 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 9068 | EXPECT_TRUE(root->has_render_surface()); |
| 9069 | EXPECT_TRUE(child->has_render_surface()); |
| 9070 | EXPECT_FALSE(grandchild->has_render_surface()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9071 | |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 9072 | EXPECT_TRUE(root->render_surface()->Filters().IsEmpty()); |
| 9073 | EXPECT_TRUE(child->render_surface()->Filters().IsEmpty()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9074 | |
| 9075 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 9076 | EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation()); |
| 9077 | EXPECT_FALSE(child->FilterIsAnimating()); |
| 9078 | EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation()); |
| 9079 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 9080 | EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation()); |
| 9081 | } |
| 9082 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 9083 | // Ensures that the property tree code accounts for offsets between fixed |
| 9084 | // position layers and their respective containers. |
| 9085 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9086 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9087 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 9088 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 9089 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9090 | root->SetBounds(gfx::Size(50, 50)); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 9091 | root->SetMasksToBounds(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 9092 | root->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9093 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 9094 | child->SetBounds(gfx::Size(50, 50)); |
| 9095 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 9096 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 9097 | grandchild->SetDrawsContent(true); |
| 9098 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 9099 | LayerPositionConstraint constraint; |
| 9100 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 9101 | grandchild->test_properties()->position_constraint = constraint; |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 9102 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9103 | ExecuteCalculateDrawProperties(root); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 9104 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9105 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 9106 | } |
| 9107 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 9108 | // Ensures that the property tree code accounts for offsets between fixed |
| 9109 | // position containers and their transform tree parents, when a fixed position |
| 9110 | // layer's container is its layer tree parent, but this parent doesn't have its |
| 9111 | // own transform tree node. |
| 9112 | TEST_F(LayerTreeHostCommonTest, |
| 9113 | PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9114 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9115 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 9116 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 9117 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9118 | root->SetBounds(gfx::Size(50, 50)); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 9119 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9120 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 9121 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 9122 | child->SetBounds(gfx::Size(50, 50)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 9123 | child->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9124 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 9125 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 9126 | grandchild->SetDrawsContent(true); |
| 9127 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 9128 | LayerPositionConstraint constraint; |
| 9129 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 9130 | grandchild->test_properties()->position_constraint = constraint; |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 9131 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9132 | ExecuteCalculateDrawProperties(root); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 9133 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9134 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 9135 | } |
| 9136 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9137 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9138 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9139 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 9140 | LayerImpl* fixed = AddChild<LayerImpl>(frame_clip); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9141 | gfx::Transform translate_z; |
| 9142 | translate_z.Translate3d(0, 0, 10); |
| 9143 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9144 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 9145 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9146 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9147 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 9148 | frame_clip->SetBounds(gfx::Size(100, 100)); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9149 | frame_clip->SetMasksToBounds(true); |
| 9150 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9151 | fixed->SetBounds(gfx::Size(1000, 1000)); |
| 9152 | fixed->SetDrawsContent(true); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9153 | |
| 9154 | LayerPositionConstraint constraint; |
| 9155 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 9156 | fixed->test_properties()->position_constraint = constraint; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9157 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9158 | ExecuteCalculateDrawProperties(root); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9159 | |
| 9160 | gfx::Rect expected(0, 0, 100, 100); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9161 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9162 | } |
| 9163 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 9164 | TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9165 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9166 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 9167 | LayerImpl* scroller = AddChild<LayerImpl>(frame_clip); |
| 9168 | LayerImpl* fixed = AddChild<LayerImpl>(scroller); |
| 9169 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9170 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9171 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9172 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 9173 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 9174 | frame_clip->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9175 | frame_clip->SetMasksToBounds(true); |
| 9176 | frame_clip->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9177 | scroller->SetBounds(gfx::Size(1000, 1000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9178 | scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100)); |
| 9179 | scroller->SetScrollClipLayer(frame_clip->id()); |
| 9180 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9181 | fixed->SetPosition(gfx::PointF(100, 100)); |
| 9182 | fixed->SetBounds(gfx::Size(50, 50)); |
| 9183 | fixed->SetMasksToBounds(true); |
| 9184 | fixed->SetDrawsContent(true); |
| 9185 | fixed->test_properties()->force_render_surface = true; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 9186 | |
| 9187 | LayerPositionConstraint constraint; |
| 9188 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 9189 | fixed->test_properties()->position_constraint = constraint; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 9190 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9191 | ExecuteCalculateDrawProperties(root); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 9192 | |
| 9193 | gfx::Rect expected(0, 0, 50, 50); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9194 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 9195 | } |
| 9196 | |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 9197 | TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) { |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 9198 | gfx::Transform translate; |
| 9199 | gfx::Transform rotate; |
| 9200 | |
| 9201 | translate.Translate(10, 10); |
| 9202 | rotate.Rotate(45); |
| 9203 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9204 | scoped_refptr<Layer> root = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9205 | root->SetBounds(gfx::Size(800, 800)); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 9206 | root->SetIsContainerForFixedPositionLayers(true); |
| 9207 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9208 | host()->SetRootLayer(root); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 9209 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9210 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9211 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 9212 | |
| 9213 | root->SetTransform(translate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9214 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 9215 | |
| 9216 | root->SetTransform(rotate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9217 | EXPECT_TRUE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 9218 | } |
| 9219 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9220 | TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9221 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9222 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9223 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9224 | gfx::Transform scale_matrix; |
| 9225 | scale_matrix.Scale(2.f, 2.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9226 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9227 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9228 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9229 | child->test_properties()->transform = scale_matrix; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9230 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9231 | child->SetDrawsContent(true); |
| 9232 | |
| 9233 | ExecuteCalculateDrawProperties(root); |
| 9234 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9235 | |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 9236 | child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9237 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9238 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9239 | ExecuteCalculateDrawProperties(root); |
| 9240 | EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9241 | } |
| 9242 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9243 | TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9244 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9245 | LayerImpl* scroll_parent = AddChild<LayerImpl>(root); |
| 9246 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9247 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9248 | gfx::Transform scale; |
| 9249 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9250 | |
| 9251 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9252 | scroll_child->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9253 | scroll_child->SetBounds(gfx::Size(40, 40)); |
| 9254 | scroll_child->SetDrawsContent(true); |
| 9255 | scroll_parent->SetBounds(gfx::Size(30, 30)); |
| 9256 | scroll_parent->SetDrawsContent(true); |
| 9257 | |
| 9258 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 9259 | scroll_parent->test_properties()->scroll_children = |
| 9260 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9261 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9262 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9263 | ExecuteCalculateDrawProperties(root); |
| 9264 | EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9265 | |
| 9266 | scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9267 | scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
| 9268 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9269 | ExecuteCalculateDrawProperties(root); |
| 9270 | EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9271 | } |
| 9272 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9273 | static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9274 | |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9275 | TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) { |
| 9276 | // If the layer has a node in effect_tree, the return value of |
| 9277 | // num_copy_requests_in_target_subtree() must be equal to the actual number |
| 9278 | // of copy requests in the sub-layer_tree; Otherwise, the number is expected |
| 9279 | // to be the value of its nearest ancestor that owns an effect node and |
| 9280 | // greater than or equal to the actual number of copy requests in the |
| 9281 | // sub-layer_tree. |
| 9282 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9283 | scoped_refptr<Layer> root = Layer::Create(); |
| 9284 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 9285 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 9286 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 9287 | scoped_refptr<Layer> greatgrandchild = Layer::Create(); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9288 | |
| 9289 | root->AddChild(child1); |
| 9290 | root->AddChild(child2); |
| 9291 | child1->AddChild(grandchild); |
| 9292 | grandchild->AddChild(greatgrandchild); |
| 9293 | host()->SetRootLayer(root); |
| 9294 | |
| 9295 | child1->RequestCopyOfOutput( |
| 9296 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 9297 | greatgrandchild->RequestCopyOfOutput( |
| 9298 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 9299 | child2->SetOpacity(0.f); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9300 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9301 | |
| 9302 | EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2); |
| 9303 | EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2); |
| 9304 | EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0); |
| 9305 | EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2); |
| 9306 | EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1); |
| 9307 | } |
| 9308 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9309 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9310 | scoped_refptr<Layer> root = Layer::Create(); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 9311 | FakeContentLayerClient client; |
| 9312 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9313 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9314 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9315 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9316 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 9317 | scoped_refptr<FakePictureLayer> greatgrandchild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9318 | FakePictureLayer::Create(&client)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9319 | |
| 9320 | root->SetBounds(gfx::Size(100, 100)); |
| 9321 | child->SetBounds(gfx::Size(10, 10)); |
| 9322 | grandchild->SetBounds(gfx::Size(10, 10)); |
| 9323 | greatgrandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9324 | |
| 9325 | root->AddChild(child); |
| 9326 | child->AddChild(grandchild); |
| 9327 | grandchild->AddChild(greatgrandchild); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9328 | host()->SetRootLayer(root); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 9329 | host()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9330 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9331 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9332 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9333 | const LayerList* update_list = GetUpdateLayerList(); |
| 9334 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9335 | |
| 9336 | // Now we will reset the visible rect from property trees for the grandchild, |
| 9337 | // and we will configure |child| in several ways that should force the subtree |
| 9338 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 9339 | // remain empty. |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9340 | gfx::Transform singular; |
| 9341 | singular.matrix().set(0, 0, 0); |
| 9342 | |
| 9343 | child->SetTransform(singular); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9344 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9345 | update_list = GetUpdateLayerList(); |
| 9346 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9347 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9348 | |
| 9349 | child->SetHideLayerAndSubtree(true); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9350 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9351 | update_list = GetUpdateLayerList(); |
| 9352 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9353 | child->SetHideLayerAndSubtree(false); |
| 9354 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9355 | gfx::Transform zero_z_scale; |
| 9356 | zero_z_scale.Scale3d(1, 1, 0); |
| 9357 | child->SetTransform(zero_z_scale); |
| 9358 | |
| 9359 | // Add a transform animation with a start delay. Now, even though |child| has |
| 9360 | // a singular transform, the subtree should still get processed. |
| 9361 | int animation_id = 0; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9362 | std::unique_ptr<Animation> animation = Animation::Create( |
| 9363 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 9364 | animation_id, 1, TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 9365 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9366 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9367 | AddAnimationToElementWithPlayer(child->element_id(), timeline(), |
| 9368 | std::move(animation)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9369 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9370 | update_list = GetUpdateLayerList(); |
| 9371 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9372 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9373 | RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(), |
| 9374 | animation_id); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9375 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9376 | child->SetOpacity(0.f); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9377 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9378 | update_list = GetUpdateLayerList(); |
| 9379 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9380 | |
| 9381 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 9382 | // |greatgrandchild| in several ways that should force the subtree to be |
| 9383 | // processed anyhow. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9384 | grandchild->RequestCopyOfOutput( |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9385 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9386 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9387 | update_list = GetUpdateLayerList(); |
| 9388 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9389 | |
| 9390 | // Add an opacity animation with a start delay. |
| 9391 | animation_id = 1; |
| 9392 | animation = Animation::Create( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9393 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 9394 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 9395 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9396 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9397 | AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(), |
| 9398 | std::move(animation)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9399 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 9400 | update_list = GetUpdateLayerList(); |
| 9401 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9402 | } |
| 9403 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9404 | TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 9405 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 9406 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 9407 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9408 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9409 | std::unique_ptr<LayerImpl> root = |
| 9410 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 9411 | std::unique_ptr<LayerImpl> child = |
| 9412 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 9413 | std::unique_ptr<LayerImpl> grandchild = |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9414 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 9415 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9416 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 9417 | FakePictureLayerImpl::Create(host_impl.active_tree(), 4)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9418 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9419 | root->SetBounds(gfx::Size(100, 100)); |
| 9420 | child->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9421 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9422 | grandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9423 | grandchild->SetDrawsContent(true); |
| 9424 | greatgrandchild->SetDrawsContent(true); |
| 9425 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 9426 | LayerImpl* root_ptr = root.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9427 | LayerImpl* child_ptr = child.get(); |
| 9428 | LayerImpl* grandchild_ptr = grandchild.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9429 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9430 | child->test_properties()->AddChild(std::move(grandchild)); |
| 9431 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9432 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9433 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9434 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 9435 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9436 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9437 | // ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9438 | // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9439 | |
| 9440 | // Now we will reset the visible rect from property trees for the grandchild, |
| 9441 | // and we will configure |child| in several ways that should force the subtree |
| 9442 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 9443 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9444 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9445 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9446 | gfx::Transform singular; |
| 9447 | singular.matrix().set(0, 0, 0); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9448 | // This line is used to make the results of skipping and not skipping layers |
| 9449 | // different. |
| 9450 | singular.matrix().set(0, 1, 1); |
| 9451 | |
| 9452 | gfx::Transform rotate; |
| 9453 | rotate.Rotate(90); |
| 9454 | |
| 9455 | gfx::Transform rotate_back_and_translate; |
| 9456 | rotate_back_and_translate.RotateAboutYAxis(180); |
| 9457 | rotate_back_and_translate.Translate(-10, 0); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9458 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9459 | child_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9460 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9461 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9462 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9463 | child_ptr->test_properties()->transform = gfx::Transform(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9464 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9465 | child_ptr->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9466 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9467 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9468 | child_ptr->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9469 | |
jaydasika | b5bc1a2 | 2016-08-24 02:59:05 | [diff] [blame] | 9470 | child_ptr->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 9471 | 0.f, child_ptr->effect_tree_index(), child_ptr->layer_tree_impl()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9472 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9473 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9474 | child_ptr->test_properties()->opacity = 1.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9475 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9476 | root_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9477 | // Force transform tree to have a node for child, so that ancestor's |
| 9478 | // invertible transform can be tested. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9479 | child_ptr->test_properties()->transform = rotate; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9480 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9481 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9482 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9483 | root_ptr->test_properties()->transform = gfx::Transform(); |
| 9484 | child_ptr->test_properties()->transform = gfx::Transform(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9485 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9486 | root_ptr->test_properties()->opacity = 0.f; |
| 9487 | child_ptr->test_properties()->opacity = 0.7f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9488 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9489 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9490 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9491 | root_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9492 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9493 | child_ptr->test_properties()->opacity = 0.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9494 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 9495 | // |greatgrandchild| in several ways that should force the subtree to be |
| 9496 | // processed anyhow. |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 9497 | grandchild_ptr->test_properties()->copy_requests.push_back( |
| 9498 | CopyOutputRequest::CreateEmptyRequest()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 9499 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9500 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9501 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 9502 | |
| 9503 | host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests(); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9504 | child_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9505 | |
| 9506 | // A double sided render surface with backface visible should not be skipped |
| 9507 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
ajuma | 35b24f6 | 2017-01-27 21:23:09 | [diff] [blame] | 9508 | child_ptr->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9509 | child_ptr->test_properties()->double_sided = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9510 | child_ptr->test_properties()->transform = rotate_back_and_translate; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9511 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9512 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9513 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9514 | child_ptr->test_properties()->transform = gfx::Transform(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9515 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9516 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9517 | KeyframedTransformAnimationCurve::Create()); |
| 9518 | TransformOperations start; |
| 9519 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 9520 | gfx::Transform transform; |
| 9521 | transform.Scale3d(1.0, 2.0, 3.0); |
| 9522 | TransformOperations operation; |
| 9523 | operation.AppendMatrix(transform); |
| 9524 | curve->AddKeyframe( |
| 9525 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 9526 | curve->AddKeyframe(TransformKeyframe::Create( |
| 9527 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9528 | std::unique_ptr<Animation> transform_animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9529 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 9530 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9531 | host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(), |
| 9532 | player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 9533 | player->AddAnimation(std::move(transform_animation)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9534 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9535 | child_ptr->SetScrollClipLayer(root_ptr->id()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9536 | root_ptr->test_properties()->transform = singular; |
| 9537 | child_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9538 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9539 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9540 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9541 | |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9542 | host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(), |
| 9543 | player.get()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9544 | } |
| 9545 | |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9546 | TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9547 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9548 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 9549 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 9550 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9551 | SetElementIdsForTesting(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9552 | |
| 9553 | gfx::Transform singular; |
| 9554 | singular.matrix().set(0, 0, 0); |
| 9555 | singular.matrix().set(0, 1, 1); |
| 9556 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9557 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9558 | child->test_properties()->transform = singular; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9559 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9560 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9561 | grand_child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9562 | grand_child->SetDrawsContent(true); |
| 9563 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 9564 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9565 | KeyframedTransformAnimationCurve::Create()); |
| 9566 | TransformOperations start; |
| 9567 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 9568 | gfx::Transform transform; |
| 9569 | transform.Scale3d(1.0, 2.0, 3.0); |
| 9570 | TransformOperations operation; |
| 9571 | operation.AppendMatrix(transform); |
| 9572 | curve->AddKeyframe( |
| 9573 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 9574 | curve->AddKeyframe(TransformKeyframe::Create( |
| 9575 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 9576 | std::unique_ptr<Animation> transform_animation( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9577 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 9578 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9579 | host_impl()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9580 | grand_child->element_id(), player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 9581 | player->AddAnimation(std::move(transform_animation)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9582 | |
| 9583 | ExecuteCalculateDrawProperties(root); |
| 9584 | EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect()); |
| 9585 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
| 9586 | |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9587 | host_impl()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9588 | grand_child->element_id(), player.get()); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9589 | } |
| 9590 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9591 | TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { |
| 9592 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9593 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame] | 9594 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9595 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9596 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9597 | std::unique_ptr<LayerImpl> root = |
| 9598 | LayerImpl::Create(host_impl.pending_tree(), 1); |
| 9599 | std::unique_ptr<LayerImpl> child = |
| 9600 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 9601 | std::unique_ptr<LayerImpl> grandchild = |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9602 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 9603 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9604 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9605 | FakePictureLayerImpl::Create(host_impl.pending_tree(), 4)); |
| 9606 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9607 | root->SetBounds(gfx::Size(100, 100)); |
| 9608 | child->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9609 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9610 | grandchild->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9611 | grandchild->SetDrawsContent(true); |
| 9612 | greatgrandchild->SetDrawsContent(true); |
| 9613 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9614 | LayerImpl* root_ptr = root.get(); |
| 9615 | LayerImpl* grandchild_ptr = grandchild.get(); |
| 9616 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9617 | child->test_properties()->AddChild(std::move(grandchild)); |
| 9618 | root->test_properties()->AddChild(std::move(child)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9619 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9620 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9621 | host_impl.pending_tree()->SetElementIdsForTesting(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9622 | |
| 9623 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9624 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9625 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9626 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9627 | std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9628 | KeyframedFloatAnimationCurve::Create()); |
loyso | 1e4e7ee | 2016-06-03 03:04:49 | [diff] [blame] | 9629 | std::unique_ptr<TimingFunction> func = |
| 9630 | CubicBezierTimingFunction::CreatePreset( |
| 9631 | CubicBezierTimingFunction::EaseType::EASE); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9632 | curve->AddKeyframe( |
| 9633 | FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func))); |
| 9634 | curve->AddKeyframe( |
| 9635 | FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9636 | std::unique_ptr<Animation> animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9637 | Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY)); |
| 9638 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9639 | host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(), |
| 9640 | player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 9641 | player->AddAnimation(std::move(animation)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9642 | root_ptr->test_properties()->opacity = 0.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9643 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9644 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9645 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9646 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9647 | |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 9648 | host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(), |
| 9649 | player.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9650 | } |
| 9651 | |
| 9652 | TEST_F(LayerTreeHostCommonTest, SkippingLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9653 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9654 | LayerImpl* child = AddChild<LayerImpl>(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9655 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9656 | root->SetBounds(gfx::Size(100, 100)); |
| 9657 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9658 | child->SetDrawsContent(true); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9659 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9660 | ExecuteCalculateDrawProperties(root); |
| 9661 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9662 | child->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9663 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9664 | child->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9665 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9666 | ExecuteCalculateDrawProperties(root); |
| 9667 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9668 | child->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9669 | |
| 9670 | child->SetBounds(gfx::Size()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9671 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9672 | ExecuteCalculateDrawProperties(root); |
| 9673 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9674 | child->SetBounds(gfx::Size(10, 10)); |
| 9675 | |
| 9676 | gfx::Transform rotate; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9677 | child->test_properties()->double_sided = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9678 | rotate.RotateAboutXAxis(180.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9679 | child->test_properties()->transform = rotate; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9680 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9681 | ExecuteCalculateDrawProperties(root); |
| 9682 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9683 | child->test_properties()->double_sided = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9684 | child->test_properties()->transform = gfx::Transform(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9685 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9686 | child->test_properties()->opacity = 0.f; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9687 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9688 | ExecuteCalculateDrawProperties(root); |
| 9689 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9690 | } |
| 9691 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9692 | TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) { |
| 9693 | // Ensure that the treewalk in LayerTreeHostCommom:: |
| 9694 | // PreCalculateMetaInformation happens when its required. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9695 | scoped_refptr<Layer> root = Layer::Create(); |
| 9696 | scoped_refptr<Layer> parent = Layer::Create(); |
| 9697 | scoped_refptr<Layer> child = Layer::Create(); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9698 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9699 | root->SetBounds(gfx::Size(100, 100)); |
| 9700 | parent->SetBounds(gfx::Size(100, 100)); |
| 9701 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9702 | child->SetClipParent(root.get()); |
| 9703 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9704 | root->AddChild(parent); |
| 9705 | parent->AddChild(child); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9706 | host()->SetRootLayer(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9707 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9708 | child->RequestCopyOfOutput( |
| 9709 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9710 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9711 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9712 | EXPECT_EQ(parent->num_unclipped_descendants(), 1u); |
| 9713 | |
| 9714 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9715 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9716 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9717 | } |
| 9718 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9719 | TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) { |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9720 | scoped_refptr<Layer> root = Layer::Create(); |
| 9721 | root->SetBounds(gfx::Size(800, 800)); |
| 9722 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9723 | gfx::Transform translate_z; |
| 9724 | translate_z.Translate3d(0, 0, 10); |
| 9725 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9726 | scoped_refptr<Layer> child = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9727 | child->SetTransform(translate_z); |
| 9728 | child->SetBounds(gfx::Size(100, 100)); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9729 | |
| 9730 | root->AddChild(child); |
| 9731 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9732 | host()->SetRootLayer(root); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9733 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9734 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9735 | EXPECT_NE(-1, child->transform_tree_index()); |
| 9736 | |
| 9737 | child->RemoveFromParent(); |
| 9738 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9739 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9740 | EXPECT_EQ(-1, child->transform_tree_index()); |
| 9741 | } |
| 9742 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9743 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { |
| 9744 | // Ensure that a Clip Node is added when a render surface applies clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9745 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9746 | LayerImpl* significant_transform = AddChildToRoot<LayerImpl>(); |
| 9747 | LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform); |
| 9748 | LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree); |
| 9749 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9750 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9751 | // This transform should be a significant one so that a transform node is |
| 9752 | // formed for it. |
| 9753 | gfx::Transform transform1; |
| 9754 | transform1.RotateAboutYAxis(45); |
| 9755 | transform1.RotateAboutXAxis(30); |
| 9756 | // This transform should be a 3d transform as we want the render surface |
| 9757 | // to flatten the transform |
| 9758 | gfx::Transform transform2; |
| 9759 | transform2.Translate3d(10, 10, 10); |
| 9760 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9761 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9762 | significant_transform->test_properties()->transform = transform1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9763 | significant_transform->SetBounds(gfx::Size(30, 30)); |
| 9764 | layer_clips_subtree->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9765 | layer_clips_subtree->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9766 | layer_clips_subtree->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9767 | render_surface->test_properties()->transform = transform2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9768 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9769 | render_surface->test_properties()->force_render_surface = true; |
| 9770 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9771 | test_layer->SetDrawsContent(true); |
| 9772 | |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9773 | float device_scale_factor = 1.f; |
| 9774 | float page_scale_factor = 1.f; |
| 9775 | LayerImpl* page_scale_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 9776 | LayerImpl* inner_viewport_scroll_layer = nullptr; |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 9777 | LayerImpl* outer_viewport_scroll_layer = nullptr; |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9778 | // Visible rects computed by combining clips in target space and root space |
| 9779 | // don't match because of rotation transforms. So, we skip |
| 9780 | // verify_visible_rect_calculations. |
| 9781 | bool skip_verify_visible_rect_calculations = true; |
| 9782 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 9783 | page_scale_layer, inner_viewport_scroll_layer, |
flackr | a283bed | 2016-10-31 14:49:42 | [diff] [blame] | 9784 | outer_viewport_scroll_layer, |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9785 | skip_verify_visible_rect_calculations); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9786 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9787 | TransformTree& transform_tree = |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9788 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9789 | TransformNode* transform_node = |
| 9790 | transform_tree.Node(significant_transform->transform_tree_index()); |
wkorman | a4c2d868 | 2017-01-05 01:16:37 | [diff] [blame] | 9791 | EXPECT_EQ(transform_node->owning_layer_id, significant_transform->id()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9792 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9793 | EXPECT_TRUE(root->has_render_surface()); |
| 9794 | EXPECT_FALSE(significant_transform->has_render_surface()); |
| 9795 | EXPECT_TRUE(layer_clips_subtree->has_render_surface()); |
| 9796 | EXPECT_TRUE(render_surface->has_render_surface()); |
| 9797 | EXPECT_FALSE(test_layer->has_render_surface()); |
| 9798 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9799 | ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9800 | ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); |
ajuma | 259f1e7 | 2016-10-24 16:25:38 | [diff] [blame] | 9801 | EXPECT_EQ(clip_node->clip_type, ClipNode::ClipType::NONE); |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 9802 | EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect()); |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9803 | |
| 9804 | // Also test the visible rects computed by combining clips in root space. |
| 9805 | gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic( |
| 9806 | root->layer_tree_impl()->property_trees(), test_layer); |
| 9807 | EXPECT_EQ(gfx::Rect(30, 20), visible_rect); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9808 | } |
| 9809 | |
| 9810 | TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 9811 | // Ensure that when parent clip node's transform is an ancestor of current |
| 9812 | // clip node's target, clip is 'projected' from parent space to current |
| 9813 | // target space and visible rects are calculated correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9814 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9815 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9816 | LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 9817 | LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| 9818 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9819 | gfx::Transform transform; |
| 9820 | transform.RotateAboutYAxis(45); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9821 | |
| 9822 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9823 | clip_layer->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9824 | clip_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9825 | clip_layer->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9826 | target_layer->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9827 | target_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9828 | target_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9829 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9830 | test_layer->SetDrawsContent(true); |
| 9831 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9832 | ExecuteCalculateDrawProperties(root); |
| 9833 | |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9834 | EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9835 | } |
| 9836 | |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9837 | TEST_F(LayerTreeHostCommonTest, |
| 9838 | RenderSurfaceWithUnclippedDescendantsClipsSubtree) { |
| 9839 | // Ensure clip rect is calculated correctly when render surface has unclipped |
| 9840 | // descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9841 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9842 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9843 | LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); |
| 9844 | LayerImpl* render_surface = |
| 9845 | AddChild<LayerImpl>(between_clip_parent_and_child); |
| 9846 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9847 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9848 | gfx::Transform translate; |
| 9849 | translate.Translate(2.0, 2.0); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9850 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9851 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9852 | clip_parent->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9853 | clip_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9854 | clip_parent->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9855 | between_clip_parent_and_child->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9856 | between_clip_parent_and_child->SetBounds(gfx::Size(30, 30)); |
| 9857 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9858 | render_surface->test_properties()->force_render_surface = true; |
| 9859 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9860 | test_layer->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9861 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9862 | render_surface->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9863 | clip_parent->test_properties()->clip_children = |
| 9864 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9865 | clip_parent->test_properties()->clip_children->insert(render_surface); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9866 | |
| 9867 | ExecuteCalculateDrawProperties(root); |
| 9868 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9869 | EXPECT_TRUE(test_layer->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 9870 | EXPECT_FALSE(test_layer->render_target()->is_clipped()); |
weiliangc | 0b41eaf | 2016-03-14 21:35:56 | [diff] [blame] | 9871 | EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect()); |
| 9872 | EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9873 | } |
| 9874 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9875 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9876 | RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) { |
| 9877 | // Ensure that the visible layer rect of a descendant of a surface with |
| 9878 | // unclipped descendants is computed correctly, when the surface doesn't apply |
| 9879 | // a clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9880 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9881 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9882 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9883 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9884 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 9885 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9886 | root->SetBounds(gfx::Size(30, 10)); |
| 9887 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 9888 | render_surface->SetBounds(gfx::Size(10, 15)); |
| 9889 | render_surface->test_properties()->force_render_surface = true; |
| 9890 | clip_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9891 | clip_child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9892 | child->SetBounds(gfx::Size(40, 40)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9893 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9894 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9895 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9896 | clip_parent->test_properties()->clip_children = |
| 9897 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9898 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9899 | |
| 9900 | ExecuteCalculateDrawProperties(root); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 9901 | EXPECT_EQ(gfx::Rect(30, 10), child->visible_layer_rect()); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9902 | } |
| 9903 | |
| 9904 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9905 | RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9906 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9907 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9908 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9909 | LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface); |
| 9910 | LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1); |
| 9911 | LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child); |
| 9912 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9913 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9914 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9915 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 9916 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9917 | render_surface->SetMasksToBounds(true); |
| 9918 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9919 | render_surface->test_properties()->force_render_surface = true; |
| 9920 | test_layer1->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9921 | test_layer1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9922 | clip_child->SetBounds(gfx::Size(50, 50)); |
| 9923 | clip_child->SetDrawsContent(true); |
| 9924 | test_layer2->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9925 | test_layer2->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9926 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9927 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9928 | clip_parent->test_properties()->clip_children = |
| 9929 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9930 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9931 | |
| 9932 | ExecuteCalculateDrawProperties(root); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9933 | EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect()); |
| 9934 | EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect()); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9935 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
| 9936 | EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect()); |
| 9937 | } |
| 9938 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9939 | TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9940 | LayerImpl* root = root_layer_for_testing(); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9941 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9942 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9943 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9944 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9945 | root->SetBounds(gfx::Size(50, 50)); |
| 9946 | clip_parent->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9947 | clip_parent->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9948 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9949 | render_surface->test_properties()->force_render_surface = true; |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9950 | render_surface->SetMasksToBounds(true); |
| 9951 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9952 | clip_child->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9953 | clip_child->SetDrawsContent(true); |
| 9954 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9955 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9956 | clip_parent->test_properties()->clip_children = |
| 9957 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9958 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9959 | |
| 9960 | ExecuteCalculateDrawProperties(root); |
| 9961 | |
| 9962 | // The clip child should inherit its clip parent's clipping state, not its |
| 9963 | // tree parent's clipping state. |
| 9964 | EXPECT_FALSE(clip_parent->is_clipped()); |
| 9965 | EXPECT_TRUE(render_surface->is_clipped()); |
| 9966 | EXPECT_FALSE(clip_child->is_clipped()); |
| 9967 | } |
| 9968 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9969 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) { |
| 9970 | // Tests the value of render surface content rect when we have multiple types |
| 9971 | // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and |
| 9972 | // clipped surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9973 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9974 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 9975 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 9976 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9977 | LayerImpl* unclipped_desc_surface2 = |
| 9978 | AddChild<LayerImpl>(unclipped_desc_surface); |
| 9979 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2); |
| 9980 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 9981 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9982 | root->SetBounds(gfx::Size(80, 80)); |
| 9983 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9984 | unclipped_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9985 | unclipped_surface->SetDrawsContent(true); |
| 9986 | unclipped_surface->test_properties()->force_render_surface = true; |
| 9987 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 9988 | clip_parent->SetMasksToBounds(true); |
| 9989 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9990 | unclipped_desc_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9991 | unclipped_desc_surface->SetDrawsContent(true); |
| 9992 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9993 | unclipped_desc_surface2->SetBounds(gfx::Size(60, 60)); |
| 9994 | unclipped_desc_surface2->SetDrawsContent(true); |
| 9995 | unclipped_desc_surface2->test_properties()->force_render_surface = true; |
| 9996 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9997 | clipped_surface->SetBounds(gfx::Size(70, 70)); |
| 9998 | clipped_surface->SetDrawsContent(true); |
| 9999 | clipped_surface->test_properties()->force_render_surface = true; |
| 10000 | |
| 10001 | clip_child->test_properties()->clip_parent = clip_parent; |
| 10002 | clip_parent->test_properties()->clip_children = |
| 10003 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 10004 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 10005 | |
| 10006 | ExecuteCalculateDrawProperties(root); |
| 10007 | EXPECT_EQ(gfx::Rect(50, 50), |
| 10008 | unclipped_surface->render_surface()->content_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 10009 | EXPECT_EQ(gfx::Rect(50, 50), |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 10010 | unclipped_desc_surface->render_surface()->content_rect()); |
| 10011 | EXPECT_EQ(gfx::Rect(50, 50), |
| 10012 | unclipped_desc_surface2->render_surface()->content_rect()); |
| 10013 | EXPECT_EQ(gfx::Rect(50, 50), |
| 10014 | clipped_surface->render_surface()->content_rect()); |
| 10015 | } |
| 10016 | |
| 10017 | TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) { |
| 10018 | // Tests the value of render surface content rect when we have a layer that |
| 10019 | // clips between the clip parent's target and clip child's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10020 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 10021 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 10022 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 10023 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 10024 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 10025 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 10026 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 10027 | gfx::Transform translate; |
| 10028 | translate.Translate(10, 10); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10029 | |
jaydasika | 778cb27 | 2016-08-15 19:00:54 | [diff] [blame] | 10030 | gfx::Transform rotate; |
| 10031 | rotate.RotateAboutXAxis(10); |
| 10032 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10033 | root->SetBounds(gfx::Size(100, 100)); |
| 10034 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 10035 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10036 | surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 10037 | surface->test_properties()->transform = rotate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10038 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 10039 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10040 | clip_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 10041 | unclipped_desc_surface->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10042 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 10043 | unclipped_desc_surface->SetDrawsContent(true); |
| 10044 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 10045 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 10046 | clip_child->SetDrawsContent(true); |
| 10047 | |
| 10048 | clip_child->test_properties()->clip_parent = clip_parent; |
| 10049 | clip_parent->test_properties()->clip_children = |
| 10050 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 10051 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 10052 | |
| 10053 | ExecuteCalculateDrawProperties(root); |
| 10054 | |
| 10055 | EXPECT_EQ(gfx::Rect(10, 10), |
| 10056 | unclipped_desc_surface->render_surface()->content_rect()); |
| 10057 | } |
| 10058 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 10059 | TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10060 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 10061 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 10062 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 10063 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 10064 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 10065 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 10066 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 10067 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 10068 | gfx::Transform scale; |
| 10069 | scale.Scale(2, 2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10070 | |
| 10071 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 10072 | surface->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10073 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 10074 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10075 | surface->test_properties()->force_render_surface = true; |
| 10076 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 10077 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10078 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 10079 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 10080 | unclipped_desc_surface->SetDrawsContent(true); |
| 10081 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 10082 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 10083 | clip_child->SetDrawsContent(true); |
| 10084 | |
| 10085 | clip_child->test_properties()->clip_parent = clip_parent; |
| 10086 | clip_parent->test_properties()->clip_children = |
| 10087 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 10088 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 10089 | |
| 10090 | ExecuteCalculateDrawProperties(root); |
| 10091 | |
| 10092 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 10093 | } |
| 10094 | |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 10095 | TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10096 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 10097 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 10098 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 10099 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 10100 | gfx::Transform translation; |
| 10101 | translation.Translate(10, 10); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 10102 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10103 | root->SetBounds(gfx::Size(30, 30)); |
| 10104 | render_surface->SetBounds(gfx::Size(30, 30)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 10105 | render_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10106 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 10107 | test_layer->test_properties()->transform = translation; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10108 | test_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 10109 | test_layer->SetDrawsContent(true); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 10110 | test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10111 | test_layer->test_properties()->opacity = 0.f; |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 10112 | |
| 10113 | ExecuteCalculateDrawProperties(root); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 10114 | EXPECT_TRANSFORMATION_MATRIX_EQ(translation, |
| 10115 | test_layer->ScreenSpaceTransform()); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 10116 | } |
| 10117 | |
jaydasika | b874eddc | 2016-11-02 22:34:28 | [diff] [blame] | 10118 | TEST_F(LayerTreeHostCommonTest, ClipParentDrawsIntoScaledRootSurface) { |
| 10119 | LayerImpl* root = root_layer_for_testing(); |
| 10120 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 10121 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 10122 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 10123 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 10124 | |
| 10125 | root->SetBounds(gfx::Size(100, 100)); |
| 10126 | clip_layer->SetBounds(gfx::Size(20, 20)); |
| 10127 | clip_layer->SetMasksToBounds(true); |
| 10128 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 10129 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 10130 | unclipped_desc_surface->SetDrawsContent(true); |
| 10131 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 10132 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 10133 | clip_child->SetDrawsContent(true); |
| 10134 | |
| 10135 | clip_child->test_properties()->clip_parent = clip_parent; |
| 10136 | clip_parent->test_properties()->clip_children = |
| 10137 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 10138 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 10139 | |
| 10140 | float device_scale_factor = 1.f; |
| 10141 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 10142 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->clip_rect()); |
| 10143 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 10144 | |
| 10145 | device_scale_factor = 2.f; |
| 10146 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 10147 | EXPECT_EQ(gfx::Rect(40, 40), clip_child->clip_rect()); |
| 10148 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 10149 | } |
| 10150 | |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 10151 | TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10152 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 10153 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 10154 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 10155 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 10156 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10157 | root->SetBounds(gfx::Size(30, 30)); |
| 10158 | clip_parent->SetBounds(gfx::Size(40, 40)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 10159 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10160 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 10161 | render_surface->SetMasksToBounds(true); |
| 10162 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10163 | render_surface->test_properties()->force_render_surface = true; |
| 10164 | clip_child->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 10165 | clip_child->SetDrawsContent(true); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 10166 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10167 | clip_child->test_properties()->clip_parent = clip_parent; |
| 10168 | clip_parent->test_properties()->clip_children = |
| 10169 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 10170 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 10171 | |
| 10172 | ExecuteCalculateDrawProperties(root); |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 10173 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 10174 | } |
| 10175 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 10176 | TEST_F(LayerTreeHostCommonTest, |
| 10177 | LayerClipRectLargerThanClippingRenderSurfaceRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10178 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 10179 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 10180 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10181 | |
| 10182 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 10183 | root->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 10184 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10185 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 10186 | render_surface->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 10187 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10188 | render_surface->test_properties()->force_render_surface = true; |
| 10189 | test_layer->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 10190 | test_layer->SetMasksToBounds(true); |
| 10191 | test_layer->SetDrawsContent(true); |
| 10192 | ExecuteCalculateDrawProperties(root); |
| 10193 | |
| 10194 | EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect()); |
| 10195 | EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect()); |
| 10196 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect()); |
| 10197 | } |
| 10198 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 10199 | TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) { |
| 10200 | // Tests that subtree is hidden is updated. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10201 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 10202 | LayerImpl* hidden = AddChild<LayerImpl>(root); |
| 10203 | LayerImpl* test = AddChild<LayerImpl>(hidden); |
| 10204 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10205 | root->SetBounds(gfx::Size(30, 30)); |
| 10206 | hidden->SetBounds(gfx::Size(30, 30)); |
| 10207 | hidden->test_properties()->force_render_surface = true; |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 10208 | hidden->test_properties()->hide_layer_and_subtree = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10209 | test->SetBounds(gfx::Size(30, 30)); |
| 10210 | test->test_properties()->force_render_surface = true; |
| 10211 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 10212 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 10213 | EXPECT_TRUE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 10214 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 10215 | hidden->test_properties()->hide_layer_and_subtree = false; |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 10216 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 10217 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 10218 | EXPECT_FALSE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 10219 | } |
| 10220 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 10221 | TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10222 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 10223 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 10224 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 10225 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
| 10226 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10227 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 10228 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10229 | render_surface1->SetPosition(gfx::PointF(10, 10)); |
| 10230 | render_surface1->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 10231 | render_surface1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10232 | render_surface1->test_properties()->force_render_surface = true; |
| 10233 | render_surface2->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 10234 | render_surface2->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10235 | render_surface2->test_properties()->force_render_surface = true; |
| 10236 | clip_child->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 10237 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10238 | clip_child->test_properties()->clip_parent = root; |
| 10239 | root->test_properties()->clip_children = |
| 10240 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 10241 | root->test_properties()->clip_children->insert(clip_child); |
| 10242 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 10243 | ExecuteCalculateDrawProperties(root); |
| 10244 | |
| 10245 | EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); |
jaydasika | daf0af0 | 2016-01-06 15:33:37 | [diff] [blame] | 10246 | // A clip node is created for every render surface and for layers that have |
| 10247 | // local clip. So, here it should be craeted for every layer. |
| 10248 | EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 10249 | } |
| 10250 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 10251 | TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) { |
| 10252 | // Tests that a mask layer's draw properties are computed correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10253 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 10254 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 10255 | child->test_properties()->SetMaskLayer( |
| 10256 | LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 10257 | LayerImpl* mask = child->test_properties()->mask_layer; |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 10258 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 10259 | gfx::Transform transform; |
| 10260 | transform.Translate(10, 10); |
| 10261 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10262 | root->SetBounds(gfx::Size(40, 40)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 10263 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 10264 | child->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10265 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 10266 | child->SetDrawsContent(false); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10267 | mask->SetBounds(gfx::Size(20, 20)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 10268 | ExecuteCalculateDrawProperties(root); |
| 10269 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 10270 | // The render surface created for the mask has no contributing content, so the |
| 10271 | // mask isn't a drawn RSLL member. This means it has an empty visible rect, |
| 10272 | // but its screen space transform can still be computed correctly on-demand. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 10273 | EXPECT_FALSE(mask->is_drawn_render_surface_layer_list_member()); |
| 10274 | EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect()); |
| 10275 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 10276 | |
| 10277 | // Make the child's render surface have contributing content. |
| 10278 | child->SetDrawsContent(true); |
| 10279 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 10280 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 10281 | EXPECT_TRUE(mask->is_drawn_render_surface_layer_list_member()); |
| 10282 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
| 10283 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 10284 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 10285 | transform.Translate(10, 10); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 10286 | child->test_properties()->transform = transform; |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 10287 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 10288 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 10289 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
| 10290 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 10291 | } |
| 10292 | |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10293 | TEST_F(LayerTreeHostCommonTest, |
| 10294 | SublayerScaleWithTransformNodeBetweenTwoTargets) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10295 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10296 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 10297 | LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1); |
| 10298 | LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets); |
| 10299 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10300 | |
| 10301 | gfx::Transform scale; |
| 10302 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10303 | |
| 10304 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 10305 | render_surface1->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10306 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 10307 | render_surface1->test_properties()->force_render_surface = true; |
| 10308 | between_targets->SetBounds(gfx::Size(30, 30)); |
| 10309 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 10310 | render_surface2->test_properties()->force_render_surface = true; |
| 10311 | test_layer->SetBounds(gfx::Size(30, 30)); |
| 10312 | test_layer->SetDrawsContent(true); |
| 10313 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 10314 | // We want layer between the two targets to create a clip node and effect |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10315 | // node but it shouldn't create a render surface. |
| 10316 | between_targets->SetMasksToBounds(true); |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 10317 | between_targets->test_properties()->opacity = 0.5f; |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10318 | |
| 10319 | ExecuteCalculateDrawProperties(root); |
| 10320 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 10321 | EffectTree& tree = root->layer_tree_impl()->property_trees()->effect_tree; |
| 10322 | EffectNode* node = tree.Node(render_surface1->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 10323 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10324 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 10325 | node = tree.Node(between_targets->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 10326 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10327 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 10328 | node = tree.Node(render_surface2->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 10329 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 10330 | |
| 10331 | EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect()); |
| 10332 | } |
| 10333 | |
jaydasika | 3c5633d | 2016-08-25 00:39:22 | [diff] [blame] | 10334 | TEST_F(LayerTreeHostCommonTest, NoisyTransform) { |
| 10335 | LayerImpl* root = root_layer_for_testing(); |
| 10336 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 10337 | LayerImpl* scroll_child = AddChild<LayerImpl>(render_surface); |
| 10338 | LayerImpl* scroll_clip = AddChild<LayerImpl>(render_surface); |
| 10339 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_clip); |
| 10340 | |
| 10341 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 10342 | scroll_parent->test_properties()->scroll_children = |
| 10343 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 10344 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
| 10345 | scroll_parent->SetScrollClipLayer(scroll_clip->id()); |
| 10346 | |
| 10347 | scroll_parent->SetDrawsContent(true); |
| 10348 | scroll_child->SetDrawsContent(true); |
| 10349 | render_surface->test_properties()->force_render_surface = true; |
| 10350 | |
| 10351 | // A noisy transform that's invertible. |
| 10352 | gfx::Transform transform; |
| 10353 | transform.matrix().setDouble(0, 0, 6.12323e-17); |
| 10354 | transform.matrix().setDouble(0, 2, 1); |
| 10355 | transform.matrix().setDouble(2, 2, 6.12323e-17); |
| 10356 | transform.matrix().setDouble(2, 0, -1); |
| 10357 | |
| 10358 | scroll_child->test_properties()->transform = transform; |
| 10359 | render_surface->test_properties()->transform = transform; |
| 10360 | |
| 10361 | root->SetBounds(gfx::Size(30, 30)); |
| 10362 | scroll_child->SetBounds(gfx::Size(30, 30)); |
| 10363 | scroll_parent->SetBounds(gfx::Size(30, 30)); |
| 10364 | ExecuteCalculateDrawProperties(root); |
| 10365 | |
| 10366 | gfx::Transform expected; |
| 10367 | expected.matrix().setDouble(0, 0, 3.749395e-33); |
| 10368 | expected.matrix().setDouble(0, 2, 6.12323e-17); |
| 10369 | expected.matrix().setDouble(2, 0, -1); |
| 10370 | expected.matrix().setDouble(2, 2, 6.12323e-17); |
| 10371 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
| 10372 | scroll_child->ScreenSpaceTransform()); |
| 10373 | } |
| 10374 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10375 | TEST_F(LayerTreeHostCommonTest, LargeTransformTest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10376 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10377 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 10378 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10379 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 10380 | child->SetDrawsContent(true); |
| 10381 | child->SetMasksToBounds(true); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10382 | |
| 10383 | gfx::Transform large_transform; |
| 10384 | large_transform.Scale(99999999999999999999.f, 99999999999999999999.f); |
| 10385 | large_transform.Scale(9999999999999999999.f, 9999999999999999999.f); |
| 10386 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0))); |
| 10387 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1))); |
| 10388 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10389 | root->SetBounds(gfx::Size(30, 30)); |
| 10390 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 10391 | render_surface1->test_properties()->force_render_surface = true; |
| 10392 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 10393 | // TODO(sunxd): we make child have no render surface, because if the |
| 10394 | // child has one, the large transform applied to child will result in NaNs in |
| 10395 | // the draw_transform of the render_surface, thus make draw property updates |
| 10396 | // skip the child layer. We need further investigation into this to know |
| 10397 | // what exactly happens here. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 10398 | child->test_properties()->transform = large_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10399 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10400 | |
| 10401 | ExecuteCalculateDrawProperties(root); |
| 10402 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10403 | EXPECT_EQ(gfx::RectF(), |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 10404 | render_surface1->render_surface()->DrawableContentRect()); |
| 10405 | |
| 10406 | bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) || |
| 10407 | std::isnan(child->DrawTransform().matrix().get(0, 0)); |
| 10408 | EXPECT_TRUE(is_inf_or_nan); |
| 10409 | |
| 10410 | is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) || |
| 10411 | std::isnan(child->DrawTransform().matrix().get(1, 1)); |
| 10412 | EXPECT_TRUE(is_inf_or_nan); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10413 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 10414 | // The root layer should be in the RenderSurfaceLayerListImpl. |
| 10415 | const auto* rsll = render_surface_layer_list_impl(); |
| 10416 | EXPECT_NE(std::find(rsll->begin(), rsll->end(), root), rsll->end()); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 10417 | } |
| 10418 | |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10419 | TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) { |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10420 | scoped_refptr<Layer> root = Layer::Create(); |
| 10421 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 10422 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 10423 | root->AddChild(child); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10424 | host()->SetRootLayer(root); |
| 10425 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10426 | root->SetBounds(gfx::Size(100, 100)); |
| 10427 | child->SetBounds(gfx::Size(20, 20)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10428 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10429 | |
| 10430 | // Changing the opacity from 1 to non-1 value should trigger rebuild of |
| 10431 | // property trees as a new effect node will be created. |
| 10432 | child->SetOpacity(0.5f); |
| 10433 | PropertyTrees* property_trees = host()->property_trees(); |
| 10434 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 10435 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10436 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
wkorman | c2d1f65 | 2017-01-11 22:45:32 | [diff] [blame] | 10437 | EXPECT_NE(property_trees->layer_id_to_effect_node_index.find(child->id()), |
| 10438 | property_trees->layer_id_to_effect_node_index.end()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10439 | |
| 10440 | // child already has an effect node. Changing its opacity shouldn't trigger |
| 10441 | // a property trees rebuild. |
| 10442 | child->SetOpacity(0.8f); |
| 10443 | property_trees = host()->property_trees(); |
| 10444 | EXPECT_FALSE(property_trees->needs_rebuild); |
| 10445 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10446 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
wkorman | c2d1f65 | 2017-01-11 22:45:32 | [diff] [blame] | 10447 | EXPECT_NE(property_trees->layer_id_to_effect_node_index.find(child->id()), |
| 10448 | property_trees->layer_id_to_effect_node_index.end()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10449 | |
| 10450 | // Changing the opacity from non-1 value to 1 should trigger a rebuild of |
| 10451 | // property trees as the effect node may no longer be needed. |
| 10452 | child->SetOpacity(1.f); |
| 10453 | property_trees = host()->property_trees(); |
| 10454 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 10455 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10456 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
wkorman | c2d1f65 | 2017-01-11 22:45:32 | [diff] [blame] | 10457 | EXPECT_EQ(property_trees->layer_id_to_effect_node_index.find(child->id()), |
| 10458 | property_trees->layer_id_to_effect_node_index.end()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10459 | } |
| 10460 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10461 | TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) { |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10462 | scoped_refptr<Layer> root = Layer::Create(); |
| 10463 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 10464 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 10465 | root->AddChild(animated); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10466 | host()->SetRootLayer(root); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 10467 | host()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10468 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10469 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10470 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10471 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10472 | animated->SetOpacity(0.f); |
| 10473 | |
| 10474 | scoped_refptr<AnimationPlayer> player = |
| 10475 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 10476 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10477 | |
| 10478 | player->AttachElement(animated->element_id()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10479 | |
| 10480 | int animation_id = 0; |
| 10481 | std::unique_ptr<Animation> animation = Animation::Create( |
| 10482 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 10483 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 10484 | animation->set_fill_mode(Animation::FillMode::NONE); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10485 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 10486 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10487 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 10488 | std::move(animation)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10489 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10490 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10491 | |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 10492 | EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree; |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10493 | EffectNode* node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10494 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 10495 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10496 | |
| 10497 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
khushalsagar | 6156779 | 2016-09-17 00:13:58 | [diff] [blame] | 10498 | host()->AnimateLayers( |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10499 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 10500 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10501 | EXPECT_TRUE(node->is_currently_animating_opacity); |
| 10502 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10503 | |
| 10504 | player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/); |
| 10505 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10506 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 10507 | EXPECT_FALSE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10508 | } |
| 10509 | |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10510 | TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) { |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10511 | scoped_refptr<Layer> root = Layer::Create(); |
| 10512 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 10513 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 10514 | root->AddChild(animated); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10515 | host()->SetRootLayer(root); |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 10516 | host()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10517 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10518 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10519 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10520 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10521 | |
| 10522 | scoped_refptr<AnimationPlayer> player = |
| 10523 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 10524 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10525 | player->AttachElement(animated->element_id()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10526 | |
| 10527 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 10528 | KeyframedTransformAnimationCurve::Create()); |
| 10529 | TransformOperations start; |
| 10530 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 10531 | gfx::Transform transform; |
| 10532 | transform.Scale3d(1.0, 2.0, 3.0); |
| 10533 | TransformOperations operation; |
| 10534 | operation.AppendMatrix(transform); |
| 10535 | curve->AddKeyframe( |
| 10536 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 10537 | curve->AddKeyframe(TransformKeyframe::Create( |
| 10538 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
| 10539 | std::unique_ptr<Animation> animation( |
| 10540 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 10541 | animation->set_fill_mode(Animation::FillMode::NONE); |
| 10542 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 10543 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10544 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 10545 | std::move(animation)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10546 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10547 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10548 | |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 10549 | TransformTree& tree = |
| 10550 | root->layer_tree_host()->property_trees()->transform_tree; |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10551 | TransformNode* node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10552 | EXPECT_FALSE(node->is_currently_animating); |
| 10553 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10554 | |
| 10555 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
khushalsagar | 6156779 | 2016-09-17 00:13:58 | [diff] [blame] | 10556 | host()->AnimateLayers( |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10557 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 10558 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10559 | EXPECT_TRUE(node->is_currently_animating); |
| 10560 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10561 | |
| 10562 | player->AbortAnimations(TargetProperty::TRANSFORM, |
| 10563 | false /*needs_completion*/); |
| 10564 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10565 | EXPECT_FALSE(node->is_currently_animating); |
| 10566 | EXPECT_FALSE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10567 | } |
| 10568 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10569 | TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 10570 | // Test the behavior of scroll tree builder |
| 10571 | // Topology: |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10572 | // +root1(1)[inner_viewport_container_layer] |
| 10573 | // +-page_scale_layer |
| 10574 | // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling & |
| 10575 | // scrollable, inner_viewport_scroll_layer] |
| 10576 | // +------child6(6)[kScrollbarScrolling] |
| 10577 | // +--------grand_child10(10)[kScrollbarScrolling] |
| 10578 | // +----parent3(3) |
| 10579 | // +------child7(7)[scrollable] |
| 10580 | // +------child8(8)[scroll_parent=7] |
| 10581 | // +--------grand_child11(11)[scrollable] |
| 10582 | // +----parent4(4) |
| 10583 | // +------child9(9) |
| 10584 | // +--------grand_child12(12) |
| 10585 | // +----parent5(5)[contains_non_fast_scrollable_region] |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10586 | // |
| 10587 | // Expected scroll tree topology: |
| 10588 | // +property_tree_root---owner:-1 |
| 10589 | // +--root---owner:1, id:1 |
| 10590 | // +----node---owner:2, id:2 |
| 10591 | // +------node---owner:6, id:3 |
| 10592 | // +----node---owner:7, id:4 |
| 10593 | // +------node---owner:11, id:5 |
| 10594 | // +----node---owner:5, id:6 |
| 10595 | // |
| 10596 | // Extra check: |
| 10597 | // scroll_tree_index() of: |
| 10598 | // grand_child10:3 |
| 10599 | // parent3:1 |
| 10600 | // child8:4 |
| 10601 | // parent4:1 |
| 10602 | // child9:1 |
| 10603 | // grand_child12:1 |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 10604 | scoped_refptr<Layer> root1 = Layer::Create(); |
| 10605 | scoped_refptr<Layer> page_scale_layer = Layer::Create(); |
| 10606 | scoped_refptr<Layer> parent2 = Layer::Create(); |
| 10607 | scoped_refptr<Layer> parent3 = Layer::Create(); |
| 10608 | scoped_refptr<Layer> parent4 = Layer::Create(); |
| 10609 | scoped_refptr<Layer> parent5 = Layer::Create(); |
| 10610 | scoped_refptr<Layer> child6 = Layer::Create(); |
| 10611 | scoped_refptr<Layer> child7 = Layer::Create(); |
| 10612 | scoped_refptr<Layer> child8 = Layer::Create(); |
| 10613 | scoped_refptr<Layer> child9 = Layer::Create(); |
| 10614 | scoped_refptr<Layer> grand_child10 = Layer::Create(); |
| 10615 | scoped_refptr<Layer> grand_child11 = Layer::Create(); |
| 10616 | scoped_refptr<Layer> grand_child12 = Layer::Create(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10617 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10618 | root1->AddChild(page_scale_layer); |
| 10619 | page_scale_layer->AddChild(parent2); |
| 10620 | page_scale_layer->AddChild(parent3); |
| 10621 | page_scale_layer->AddChild(parent4); |
| 10622 | page_scale_layer->AddChild(parent5); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10623 | parent2->AddChild(child6); |
| 10624 | parent3->AddChild(child7); |
| 10625 | parent3->AddChild(child8); |
| 10626 | parent4->AddChild(child9); |
| 10627 | child6->AddChild(grand_child10); |
| 10628 | child8->AddChild(grand_child11); |
| 10629 | child9->AddChild(grand_child12); |
| 10630 | host()->SetRootLayer(root1); |
| 10631 | |
| 10632 | parent2->AddMainThreadScrollingReasons( |
| 10633 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10634 | parent2->AddMainThreadScrollingReasons( |
| 10635 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10636 | parent2->SetScrollClipLayerId(root1->id()); |
| 10637 | child6->AddMainThreadScrollingReasons( |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10638 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10639 | grand_child10->AddMainThreadScrollingReasons( |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10640 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10641 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10642 | child7->SetScrollClipLayerId(parent3->id()); |
| 10643 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10644 | child8->SetScrollParent(child7.get()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10645 | grand_child11->SetScrollClipLayerId(parent3->id()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10646 | |
| 10647 | parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10648 | parent5->SetBounds(gfx::Size(10, 10)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10649 | |
khushalsagar | b69ba945 | 2017-01-27 22:20:07 | [diff] [blame] | 10650 | host()->RegisterViewportLayers(nullptr, page_scale_layer, parent2, nullptr); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10651 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10652 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10653 | const int kRootPropertyTreeNodeId = 0; |
| 10654 | |
| 10655 | // Property tree root |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10656 | ScrollTree& scroll_tree = host()->property_trees()->scroll_tree; |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 10657 | PropertyTrees property_trees; |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10658 | property_trees.is_main_thread = true; |
| 10659 | property_trees.is_active = false; |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10660 | ScrollTree& expected_scroll_tree = property_trees.scroll_tree; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10661 | ScrollNode* property_tree_root = expected_scroll_tree.Node(0); |
| 10662 | property_tree_root->id = kRootPropertyTreeNodeId; |
ajuma | f884cfb | 2017-01-16 22:27:52 | [diff] [blame] | 10663 | property_tree_root->parent_id = ScrollTree::kInvalidNodeId; |
| 10664 | property_tree_root->owning_layer_id = Layer::INVALID_ID; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10665 | property_tree_root->scrollable = false; |
| 10666 | property_tree_root->main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10667 | MainThreadScrollingReason::kNotScrollingOnMain; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10668 | property_tree_root->contains_non_fast_scrollable_region = false; |
| 10669 | property_tree_root->transform_id = kRootPropertyTreeNodeId; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10670 | |
| 10671 | // The node owned by root1 |
| 10672 | ScrollNode scroll_root1; |
| 10673 | scroll_root1.id = 1; |
wkorman | a4c2d868 | 2017-01-05 01:16:37 | [diff] [blame] | 10674 | scroll_root1.owning_layer_id = root1->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10675 | scroll_root1.user_scrollable_horizontal = true; |
| 10676 | scroll_root1.user_scrollable_vertical = true; |
| 10677 | scroll_root1.transform_id = root1->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10678 | expected_scroll_tree.Insert(scroll_root1, 0); |
| 10679 | |
| 10680 | // The node owned by parent2 |
| 10681 | ScrollNode scroll_parent2; |
| 10682 | scroll_parent2.id = 2; |
wkorman | a4c2d868 | 2017-01-05 01:16:37 | [diff] [blame] | 10683 | scroll_parent2.owning_layer_id = parent2->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10684 | scroll_parent2.scrollable = true; |
| 10685 | scroll_parent2.main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10686 | parent2->main_thread_scrolling_reasons(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10687 | scroll_parent2.scroll_clip_layer_bounds = root1->bounds(); |
| 10688 | scroll_parent2.bounds = parent2->bounds(); |
| 10689 | scroll_parent2.max_scroll_offset_affected_by_page_scale = true; |
pdr | abe1552 | 2017-02-24 19:15:56 | [diff] [blame^] | 10690 | scroll_parent2.scrolls_inner_viewport = true; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10691 | scroll_parent2.user_scrollable_horizontal = true; |
| 10692 | scroll_parent2.user_scrollable_vertical = true; |
| 10693 | scroll_parent2.transform_id = parent2->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10694 | expected_scroll_tree.Insert(scroll_parent2, 1); |
| 10695 | |
| 10696 | // The node owned by child6 |
| 10697 | ScrollNode scroll_child6; |
| 10698 | scroll_child6.id = 3; |
wkorman | a4c2d868 | 2017-01-05 01:16:37 | [diff] [blame] | 10699 | scroll_child6.owning_layer_id = child6->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10700 | scroll_child6.main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10701 | child6->main_thread_scrolling_reasons(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10702 | scroll_child6.should_flatten = true; |
| 10703 | scroll_child6.user_scrollable_horizontal = true; |
| 10704 | scroll_child6.user_scrollable_vertical = true; |
| 10705 | scroll_child6.transform_id = child6->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10706 | expected_scroll_tree.Insert(scroll_child6, 2); |
| 10707 | |
| 10708 | // The node owned by child7, child7 also owns a transform node |
| 10709 | ScrollNode scroll_child7; |
| 10710 | scroll_child7.id = 4; |
wkorman | a4c2d868 | 2017-01-05 01:16:37 | [diff] [blame] | 10711 | scroll_child7.owning_layer_id = child7->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10712 | scroll_child7.scrollable = true; |
| 10713 | scroll_child7.scroll_clip_layer_bounds = parent3->bounds(); |
| 10714 | scroll_child7.bounds = child7->bounds(); |
| 10715 | scroll_child7.user_scrollable_horizontal = true; |
| 10716 | scroll_child7.user_scrollable_vertical = true; |
| 10717 | scroll_child7.transform_id = child7->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10718 | expected_scroll_tree.Insert(scroll_child7, 1); |
| 10719 | |
| 10720 | // The node owned by grand_child11, grand_child11 also owns a transform node |
| 10721 | ScrollNode scroll_grand_child11; |
| 10722 | scroll_grand_child11.id = 5; |
wkorman | a4c2d868 | 2017-01-05 01:16:37 | [diff] [blame] | 10723 | scroll_grand_child11.owning_layer_id = grand_child11->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10724 | scroll_grand_child11.scrollable = true; |
| 10725 | scroll_grand_child11.user_scrollable_horizontal = true; |
| 10726 | scroll_grand_child11.user_scrollable_vertical = true; |
| 10727 | scroll_grand_child11.transform_id = grand_child11->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10728 | expected_scroll_tree.Insert(scroll_grand_child11, 4); |
| 10729 | |
| 10730 | // The node owned by parent5 |
| 10731 | ScrollNode scroll_parent5; |
| 10732 | scroll_parent5.id = 8; |
wkorman | a4c2d868 | 2017-01-05 01:16:37 | [diff] [blame] | 10733 | scroll_parent5.owning_layer_id = parent5->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10734 | scroll_parent5.contains_non_fast_scrollable_region = true; |
| 10735 | scroll_parent5.bounds = gfx::Size(10, 10); |
| 10736 | scroll_parent5.should_flatten = true; |
| 10737 | scroll_parent5.user_scrollable_horizontal = true; |
| 10738 | scroll_parent5.user_scrollable_vertical = true; |
| 10739 | scroll_parent5.transform_id = parent5->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10740 | expected_scroll_tree.Insert(scroll_parent5, 1); |
| 10741 | |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10742 | expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0)); |
| 10743 | expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0)); |
| 10744 | expected_scroll_tree.SetScrollOffset(grand_child11->id(), |
| 10745 | gfx::ScrollOffset(0, 0)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10746 | expected_scroll_tree.set_needs_update(false); |
| 10747 | |
| 10748 | EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 10749 | |
| 10750 | // Check other layers' scroll_tree_index |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10751 | EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10752 | EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10753 | EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10754 | EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10755 | EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10756 | EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10757 | EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10758 | } |
| 10759 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 10760 | } // namespace |
| 10761 | } // namespace cc |