ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
danakj | 6496cba | 2014-10-16 01:31:08 | [diff] [blame] | 9 | #include <algorithm> |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 11 | #include <set> |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 13 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 14 | #include "base/memory/ptr_util.h" |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 15 | #include "cc/animation/animation_host.h" |
| 16 | #include "cc/animation/animation_id_provider.h" |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 17 | #include "cc/animation/animation_player.h" |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 18 | #include "cc/animation/keyframed_animation_curve.h" |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 19 | #include "cc/animation/transform_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 20 | #include "cc/base/math_util.h" |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 21 | #include "cc/input/main_thread_scrolling_reason.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 22 | #include "cc/layers/content_layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 23 | #include "cc/layers/layer.h" |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 24 | #include "cc/layers/layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 25 | #include "cc/layers/layer_impl.h" |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 26 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 27 | #include "cc/layers/render_surface_impl.h" |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 28 | #include "cc/layers/texture_layer_impl.h" |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 29 | #include "cc/output/copy_output_request.h" |
| 30 | #include "cc/output/copy_output_result.h" |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 31 | #include "cc/proto/begin_main_frame_and_commit_state.pb.h" |
| 32 | #include "cc/proto/gfx_conversions.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 33 | #include "cc/test/animation_test_common.h" |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 34 | #include "cc/test/fake_compositor_frame_sink.h" |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 35 | #include "cc/test/fake_content_layer_client.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 36 | #include "cc/test/fake_impl_task_runner_provider.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 37 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 38 | #include "cc/test/fake_layer_tree_host_impl.h" |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 39 | #include "cc/test/fake_picture_layer.h" |
| 40 | #include "cc/test/fake_picture_layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 41 | #include "cc/test/geometry_test_utils.h" |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 42 | #include "cc/test/layer_test_common.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 43 | #include "cc/test/test_task_graph_runner.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 44 | #include "cc/trees/clip_node.h" |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 45 | #include "cc/trees/draw_property_utils.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 46 | #include "cc/trees/effect_node.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 47 | #include "cc/trees/layer_tree_impl.h" |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 48 | #include "cc/trees/property_tree_builder.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 49 | #include "cc/trees/scroll_node.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 50 | #include "cc/trees/single_thread_proxy.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 51 | #include "cc/trees/task_runner_provider.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 52 | #include "cc/trees/transform_node.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 53 | #include "testing/gtest/include/gtest/gtest.h" |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 54 | #include "third_party/skia/include/effects/SkOffsetImageFilter.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 55 | #include "ui/gfx/geometry/quad_f.h" |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 56 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 57 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 58 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 59 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 60 | namespace { |
| 61 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 62 | class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings { |
| 63 | public: |
| 64 | VerifyTreeCalcsLayerTreeSettings() { |
jaydasika | 853306a | 2016-07-29 19:28:34 | [diff] [blame] | 65 | verify_clip_tree_calculations = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 66 | } |
| 67 | }; |
| 68 | |
| 69 | class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { |
| 70 | public: |
| 71 | LayerTreeHostCommonTestBase() |
| 72 | : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {} |
| 73 | explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings) |
| 74 | : LayerTestCommon::LayerImplTest(settings) {} |
| 75 | |
| 76 | static void SetScrollOffsetDelta(LayerImpl* layer_impl, |
| 77 | const gfx::Vector2dF& delta) { |
| 78 | if (layer_impl->layer_tree_impl() |
| 79 | ->property_trees() |
| 80 | ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(), |
| 81 | delta)) |
vollick | c969691 | 2016-09-16 16:02:47 | [diff] [blame] | 82 | layer_impl->layer_tree_impl()->DidUpdateScrollOffset(layer_impl->id()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static float GetMaximumAnimationScale(LayerImpl* layer_impl) { |
| 86 | return layer_impl->layer_tree_impl() |
| 87 | ->property_trees() |
| 88 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 89 | layer_impl->layer_tree_impl()) |
| 90 | .maximum_animation_scale; |
| 91 | } |
| 92 | |
| 93 | static float GetStartingAnimationScale(LayerImpl* layer_impl) { |
| 94 | return layer_impl->layer_tree_impl() |
| 95 | ->property_trees() |
| 96 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 97 | layer_impl->layer_tree_impl()) |
| 98 | .starting_animation_scale; |
| 99 | } |
| 100 | |
| 101 | void ExecuteCalculateDrawProperties(Layer* root_layer, |
| 102 | float device_scale_factor, |
| 103 | float page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 104 | Layer* page_scale_layer, |
| 105 | Layer* inner_viewport_scroll_layer) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 106 | PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 107 | |
| 108 | EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 109 | gfx::Size device_viewport_size = |
| 110 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 111 | root_layer->bounds().height() * device_scale_factor); |
| 112 | |
| 113 | // We are probably not testing what is intended if the root_layer bounds are |
| 114 | // empty. |
| 115 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 116 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 117 | root_layer, device_viewport_size); |
| 118 | inputs.device_scale_factor = device_scale_factor; |
| 119 | inputs.page_scale_factor = page_scale_factor; |
| 120 | inputs.page_scale_layer = page_scale_layer; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 121 | inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 122 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 123 | } |
| 124 | |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 125 | void ExecuteCalculateDrawProperties( |
| 126 | LayerImpl* root_layer, |
| 127 | float device_scale_factor, |
| 128 | float page_scale_factor, |
| 129 | LayerImpl* page_scale_layer, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 130 | LayerImpl* inner_viewport_scroll_layer, |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 131 | bool skip_verify_visible_rect_calculations = false) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 132 | if (device_scale_factor != |
| 133 | root_layer->layer_tree_impl()->device_scale_factor()) |
| 134 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 135 | |
| 136 | root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); |
| 137 | |
| 138 | EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 139 | |
| 140 | gfx::Size device_viewport_size = |
| 141 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 142 | root_layer->bounds().height() * device_scale_factor); |
| 143 | |
| 144 | render_surface_layer_list_impl_.reset(new LayerImplList); |
| 145 | |
| 146 | // We are probably not testing what is intended if the root_layer bounds are |
| 147 | // empty. |
| 148 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 149 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 150 | root_layer, device_viewport_size, |
| 151 | render_surface_layer_list_impl_.get()); |
| 152 | inputs.device_scale_factor = device_scale_factor; |
| 153 | inputs.page_scale_factor = page_scale_factor; |
| 154 | inputs.page_scale_layer = page_scale_layer; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 155 | inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 156 | inputs.can_adjust_raster_scales = true; |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 157 | if (skip_verify_visible_rect_calculations) |
| 158 | inputs.verify_visible_rect_calculations = false; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 159 | |
| 160 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 161 | } |
| 162 | |
| 163 | template <class LayerType> |
| 164 | void ExecuteCalculateDrawProperties(LayerType* root_layer) { |
| 165 | LayerType* page_scale_application_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 166 | LayerType* inner_viewport_scroll_layer = nullptr; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 167 | ExecuteCalculateDrawProperties(root_layer, 1.f, 1.f, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 168 | page_scale_application_layer, |
| 169 | inner_viewport_scroll_layer); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | template <class LayerType> |
| 173 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 174 | float device_scale_factor) { |
| 175 | LayerType* page_scale_application_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 176 | LayerType* inner_viewport_scroll_layer = nullptr; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 177 | ExecuteCalculateDrawProperties(root_layer, device_scale_factor, 1.f, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 178 | page_scale_application_layer, |
| 179 | inner_viewport_scroll_layer); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 180 | } |
| 181 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 182 | const LayerList* GetUpdateLayerList() { return &update_layer_list_; } |
| 183 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 184 | void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) { |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 185 | DCHECK(root_layer->GetLayerTree()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 186 | PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 187 | |
| 188 | bool can_render_to_separate_surface = true; |
| 189 | |
| 190 | const Layer* page_scale_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 191 | root_layer->GetLayerTree()->page_scale_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 192 | Layer* inner_viewport_scroll_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 193 | root_layer->GetLayerTree()->inner_viewport_scroll_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 194 | Layer* outer_viewport_scroll_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 195 | root_layer->GetLayerTree()->outer_viewport_scroll_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 196 | const Layer* overscroll_elasticity_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 197 | root_layer->GetLayerTree()->overscroll_elasticity_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 198 | gfx::Vector2dF elastic_overscroll = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 199 | root_layer->GetLayerTree()->elastic_overscroll(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 200 | float page_scale_factor = 1.f; |
| 201 | float device_scale_factor = 1.f; |
| 202 | gfx::Size device_viewport_size = |
| 203 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 204 | root_layer->bounds().height() * device_scale_factor); |
| 205 | PropertyTrees* property_trees = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 206 | root_layer->GetLayerTree()->property_trees(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 207 | update_layer_list_.clear(); |
| 208 | PropertyTreeBuilder::BuildPropertyTrees( |
| 209 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 210 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 211 | elastic_overscroll, page_scale_factor, device_scale_factor, |
| 212 | gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
| 213 | draw_property_utils::UpdatePropertyTrees(property_trees, |
| 214 | can_render_to_separate_surface); |
| 215 | draw_property_utils::FindLayersThatNeedUpdates( |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 216 | root_layer->GetLayerTree(), property_trees, &update_layer_list_); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 217 | } |
| 218 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 219 | void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
| 220 | LayerImpl* root_layer, |
| 221 | bool skip_verify_visible_rect_calculations = false) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 222 | DCHECK(root_layer->layer_tree_impl()); |
| 223 | PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer); |
| 224 | |
| 225 | bool can_render_to_separate_surface = true; |
| 226 | |
| 227 | LayerImpl* page_scale_layer = nullptr; |
| 228 | LayerImpl* inner_viewport_scroll_layer = |
| 229 | root_layer->layer_tree_impl()->InnerViewportScrollLayer(); |
| 230 | LayerImpl* outer_viewport_scroll_layer = |
| 231 | root_layer->layer_tree_impl()->OuterViewportScrollLayer(); |
| 232 | LayerImpl* overscroll_elasticity_layer = |
| 233 | root_layer->layer_tree_impl()->OverscrollElasticityLayer(); |
| 234 | gfx::Vector2dF elastic_overscroll = |
| 235 | root_layer->layer_tree_impl()->elastic_overscroll()->Current( |
| 236 | root_layer->layer_tree_impl()->IsActiveTree()); |
| 237 | float page_scale_factor = 1.f; |
| 238 | float device_scale_factor = 1.f; |
| 239 | gfx::Size device_viewport_size = |
| 240 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 241 | root_layer->bounds().height() * device_scale_factor); |
| 242 | update_layer_list_impl_.reset(new LayerImplList); |
| 243 | root_layer->layer_tree_impl()->BuildLayerListForTesting(); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 244 | PropertyTrees* property_trees = |
| 245 | root_layer->layer_tree_impl()->property_trees(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 246 | draw_property_utils::BuildPropertyTreesAndComputeVisibleRects( |
| 247 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 248 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 249 | elastic_overscroll, page_scale_factor, device_scale_factor, |
| 250 | gfx::Rect(device_viewport_size), gfx::Transform(), |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 251 | can_render_to_separate_surface, property_trees, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 252 | update_layer_list_impl_.get()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 253 | draw_property_utils::VerifyClipTreeCalculations(*update_layer_list_impl_, |
| 254 | property_trees); |
| 255 | if (!skip_verify_visible_rect_calculations) |
| 256 | draw_property_utils::VerifyVisibleRectsCalculations( |
| 257 | *update_layer_list_impl_, property_trees); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces( |
| 261 | LayerImpl* root_layer) { |
| 262 | gfx::Size device_viewport_size = |
| 263 | gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); |
| 264 | render_surface_layer_list_impl_.reset(new LayerImplList); |
| 265 | |
| 266 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 267 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 268 | root_layer, device_viewport_size, |
| 269 | render_surface_layer_list_impl_.get()); |
| 270 | inputs.can_adjust_raster_scales = true; |
| 271 | inputs.can_render_to_separate_surface = false; |
| 272 | |
| 273 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 274 | } |
| 275 | |
| 276 | bool UpdateLayerListImplContains(int id) const { |
| 277 | for (auto* layer : *update_layer_list_impl_) { |
| 278 | if (layer->id() == id) |
| 279 | return true; |
| 280 | } |
| 281 | return false; |
| 282 | } |
| 283 | |
| 284 | bool UpdateLayerListContains(int id) const { |
| 285 | for (const auto& layer : update_layer_list_) { |
| 286 | if (layer->id() == id) |
| 287 | return true; |
| 288 | } |
| 289 | return false; |
| 290 | } |
| 291 | |
| 292 | const LayerImplList* render_surface_layer_list_impl() const { |
| 293 | return render_surface_layer_list_impl_.get(); |
| 294 | } |
| 295 | const LayerImplList* update_layer_list_impl() const { |
| 296 | return update_layer_list_impl_.get(); |
| 297 | } |
| 298 | const LayerList& update_layer_list() const { return update_layer_list_; } |
| 299 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 300 | bool VerifyLayerInList(scoped_refptr<Layer> layer, |
| 301 | const LayerList* layer_list) { |
| 302 | return std::find(layer_list->begin(), layer_list->end(), layer) != |
| 303 | layer_list->end(); |
| 304 | } |
| 305 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 306 | private: |
| 307 | std::unique_ptr<std::vector<LayerImpl*>> render_surface_layer_list_impl_; |
| 308 | LayerList update_layer_list_; |
| 309 | std::unique_ptr<LayerImplList> update_layer_list_impl_; |
| 310 | }; |
| 311 | |
| 312 | class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase, |
| 313 | public testing::Test {}; |
| 314 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 315 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 316 | public: |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 317 | LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 318 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 319 | bool DrawsContent() const override { return true; } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 320 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 321 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 322 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 323 | }; |
| 324 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 325 | class LayerTreeSettingsScaleContent : public VerifyTreeCalcsLayerTreeSettings { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 326 | public: |
| 327 | LayerTreeSettingsScaleContent() { |
| 328 | layer_transforms_should_scale_layer_contents = true; |
| 329 | } |
| 330 | }; |
| 331 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 332 | class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTestBase, |
| 333 | public testing::Test { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 334 | public: |
| 335 | LayerTreeHostCommonScalingTest() |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 336 | : LayerTreeHostCommonTestBase(LayerTreeSettingsScaleContent()) {} |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 337 | }; |
| 338 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 339 | class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest { |
| 340 | public: |
| 341 | LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {} |
| 342 | |
| 343 | LayerImpl* TestVisibleRectAndDrawableContentRect( |
| 344 | const gfx::Rect& target_rect, |
| 345 | const gfx::Transform& layer_transform, |
| 346 | const gfx::Rect& layer_rect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 347 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 348 | LayerImpl* target = AddChild<LayerImpl>(root); |
| 349 | LayerImpl* drawing_layer = AddChild<LayerImpl>(target); |
| 350 | |
| 351 | root->SetDrawsContent(true); |
| 352 | target->SetDrawsContent(true); |
| 353 | target->SetMasksToBounds(true); |
| 354 | drawing_layer->SetDrawsContent(true); |
| 355 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 356 | root->SetBounds(gfx::Size(500, 500)); |
| 357 | root->test_properties()->force_render_surface = true; |
| 358 | target->SetPosition(gfx::PointF(target_rect.origin())); |
| 359 | target->SetBounds(target_rect.size()); |
| 360 | target->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 361 | drawing_layer->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 362 | drawing_layer->SetPosition(gfx::PointF(layer_rect.origin())); |
| 363 | drawing_layer->SetBounds(layer_rect.size()); |
| 364 | drawing_layer->test_properties()->should_flatten_transform = false; |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 365 | |
| 366 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 367 | ExecuteCalculateDrawProperties(root); |
| 368 | |
| 369 | return drawing_layer; |
| 370 | } |
| 371 | }; |
| 372 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 373 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 374 | // Sanity check: For layers positioned at zero, with zero size, |
| 375 | // and with identity transforms, then the draw transform, |
| 376 | // screen space transform, and the hierarchy passed on to children |
| 377 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 378 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 379 | LayerImpl* parent = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 380 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 381 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 382 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 383 | parent->SetBounds(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 384 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 385 | ExecuteCalculateDrawProperties(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 386 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 387 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 388 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 389 | child->ScreenSpaceTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 390 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 391 | grand_child->DrawTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 392 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 393 | grand_child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 394 | } |
| 395 | |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 396 | TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) { |
| 397 | // Tests that effect tree node gets a valid transform id when a layer |
| 398 | // has opacity but doesn't create a render surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 399 | LayerImpl* parent = root_layer_for_testing(); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 400 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 401 | child->SetDrawsContent(true); |
| 402 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 403 | parent->SetBounds(gfx::Size(100, 100)); |
| 404 | child->SetPosition(gfx::PointF(10, 10)); |
| 405 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 406 | child->test_properties()->opacity = 0.f; |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 407 | ExecuteCalculateDrawProperties(parent); |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 408 | EffectTree& effect_tree = |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 409 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 410 | EffectNode* node = effect_tree.Node(child->effect_tree_index()); |
| 411 | const int transform_tree_size = parent->layer_tree_impl() |
| 412 | ->property_trees() |
| 413 | ->transform_tree.next_available_id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 414 | EXPECT_LT(node->transform_id, transform_tree_size); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 415 | } |
| 416 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 417 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 418 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 419 | LayerImpl* layer = AddChild<LayerImpl>(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 420 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 421 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 422 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 423 | EffectTree& effect_tree = |
| 424 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 425 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 426 | root->SetBounds(gfx::Size(1, 2)); |
| 427 | |
| 428 | // 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] | 429 | // transform or the screenspace transform. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 430 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 431 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 432 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 433 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 434 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 435 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 436 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 437 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 438 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 439 | // Case 2: The anchor point by itself (without a layer transform) should have |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 440 | // no effect on the transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 441 | layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 442 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 443 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 444 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 445 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 446 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 447 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 448 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 449 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 450 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 451 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 452 | // Case 3: A change in actual position affects both the draw transform and |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 453 | // screen space transform. |
| 454 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 455 | position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 456 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 457 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 458 | ExecuteCalculateDrawProperties(root); |
| 459 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 460 | position_transform, |
| 461 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 462 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 463 | position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 464 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 465 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 466 | // Case 4: In the correct sequence of transforms, the layer transform should |
| 467 | // pre-multiply the translation-to-center. This is easily tested by using a |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 468 | // scale transform, because scale and translation are not commutative. |
| 469 | gfx::Transform layer_transform; |
| 470 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 471 | layer->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 472 | layer->test_properties()->transform_origin = gfx::Point3F(); |
| 473 | layer->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 474 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 475 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 476 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 477 | layer_transform, |
| 478 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 479 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 480 | layer_transform, |
| 481 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 482 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 483 | // Case 5: The layer transform should occur with respect to the anchor point. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 484 | gfx::Transform translation_to_anchor; |
| 485 | translation_to_anchor.Translate(5.0, 0.0); |
| 486 | gfx::Transform expected_result = |
| 487 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 488 | layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 489 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 490 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 491 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 492 | expected_result, |
| 493 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 494 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 495 | expected_result, |
| 496 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 497 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 498 | // Case 6: Verify that position pre-multiplies the layer transform. The |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 499 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 500 | // it is still worth testing to detect accidental regressions. |
| 501 | expected_result = position_transform * translation_to_anchor * |
| 502 | layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 503 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 504 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 505 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 506 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 507 | expected_result, |
| 508 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 509 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 510 | expected_result, |
| 511 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 512 | } |
| 513 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 514 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 515 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 516 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 517 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 518 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 519 | -kScrollOffset.y()); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 520 | float page_scale = 0.888f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 521 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 522 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 523 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 524 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 525 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 526 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 527 | std::unique_ptr<LayerImpl> sublayer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 528 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 529 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 530 | sublayer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 531 | sublayer->SetBounds(gfx::Size(500, 500)); |
[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> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 534 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 535 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 536 | scroll_layer->SetBounds(gfx::Size(10, 20)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 537 | std::unique_ptr<LayerImpl> clip_layer_scoped_ptr( |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 538 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 539 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 540 | |
| 541 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 542 | clip_layer->SetBounds( |
| 543 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 544 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 545 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 546 | SetScrollOffsetDelta(scroll_layer, kScrollDelta); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 547 | gfx::Transform impl_transform; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 548 | scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 549 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 550 | clip_layer->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr)); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 551 | scroll_layer_raw_ptr->layer_tree_impl() |
| 552 | ->property_trees() |
| 553 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(), |
| 554 | kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 555 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 556 | std::unique_ptr<LayerImpl> root( |
| 557 | LayerImpl::Create(host_impl.active_tree(), 3)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 558 | root->SetBounds(gfx::Size(3, 4)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 559 | root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 560 | root->SetHasRenderSurface(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 561 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 562 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 563 | |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 564 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 565 | scroll_layer->test_properties()->parent, |
| 566 | nullptr); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 567 | gfx::Transform expected_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 568 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 569 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 570 | page_scale * kDeviceScale), |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 571 | MathUtil::Round(sub_layer_screen_position.y() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 572 | page_scale * kDeviceScale)); |
| 573 | expected_transform.Scale(page_scale * kDeviceScale, |
| 574 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 575 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 576 | sublayer->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 577 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 578 | sublayer->ScreenSpaceTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 579 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 580 | gfx::Transform arbitrary_translate; |
| 581 | const float kTranslateX = 10.6f; |
| 582 | const float kTranslateY = 20.6f; |
| 583 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 584 | scroll_layer->test_properties()->transform = arbitrary_translate; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 585 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 586 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 587 | scroll_layer->test_properties()->parent, |
| 588 | nullptr); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 589 | expected_transform.MakeIdentity(); |
| 590 | expected_transform.Translate( |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 591 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 592 | sub_layer_screen_position.x() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 593 | kDeviceScale), |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 594 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 595 | sub_layer_screen_position.y() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 596 | kDeviceScale)); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 597 | expected_transform.Scale(page_scale * kDeviceScale, |
| 598 | page_scale * kDeviceScale); |
| 599 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 600 | sublayer->DrawTransform()); |
| 601 | |
| 602 | // Test that page scale is updated even when we don't rebuild property trees. |
| 603 | page_scale = 1.888f; |
| 604 | root_layer->layer_tree_impl()->SetViewportLayersFromIds( |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 605 | Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(), |
| 606 | Layer::INVALID_ID, Layer::INVALID_ID); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 607 | root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 608 | EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 609 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 610 | scroll_layer->test_properties()->parent, |
| 611 | nullptr); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 612 | |
| 613 | expected_transform.MakeIdentity(); |
| 614 | expected_transform.Translate( |
| 615 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 616 | sub_layer_screen_position.x() * page_scale * |
| 617 | kDeviceScale), |
| 618 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 619 | sub_layer_screen_position.y() * page_scale * |
| 620 | kDeviceScale)); |
| 621 | expected_transform.Scale(page_scale * kDeviceScale, |
| 622 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 623 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 624 | sublayer->DrawTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 625 | } |
| 626 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 627 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 628 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 629 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 630 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 631 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 632 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 633 | // One-time setup of root layer |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 634 | root->SetBounds(gfx::Size(1, 2)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 635 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 636 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 637 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 638 | EffectTree& effect_tree = |
| 639 | host_impl()->active_tree()->property_trees()->effect_tree; |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 640 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 641 | // Case 1: parent's anchor point should not affect child or grand_child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 642 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 643 | parent->SetBounds(gfx::Size(10, 12)); |
| 644 | child->SetBounds(gfx::Size(16, 18)); |
| 645 | grand_child->SetBounds(gfx::Size(76, 78)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 646 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 647 | |
| 648 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 649 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 650 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 651 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 652 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 653 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 654 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 655 | gfx::Transform(), draw_property_utils::DrawTransform( |
| 656 | grand_child, transform_tree, effect_tree)); |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 657 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 658 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 659 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 660 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 661 | // Case 2: parent's position affects child and grand_child. |
| 662 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 663 | parent_position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 664 | parent->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 665 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 666 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 667 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 668 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 669 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 670 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 671 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 672 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 673 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 674 | parent_position_transform, draw_property_utils::DrawTransform( |
| 675 | grand_child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 676 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 677 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 678 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 679 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 680 | // Case 3: parent's local transform affects child and grandchild |
| 681 | gfx::Transform parent_layer_transform; |
| 682 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 683 | gfx::Transform parent_translation_to_anchor; |
| 684 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 685 | gfx::Transform parent_composite_transform = |
| 686 | parent_translation_to_anchor * parent_layer_transform * |
| 687 | Inverse(parent_translation_to_anchor); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 688 | parent->test_properties()->transform = parent_layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 689 | parent->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 690 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 691 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 692 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 693 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 694 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 695 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 696 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 697 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 698 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 699 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 700 | draw_property_utils::DrawTransform(grand_child, transform_tree, |
| 701 | effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 702 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 703 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 704 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 705 | } |
| 706 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 707 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 708 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 709 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 710 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 711 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 712 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 713 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 714 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 715 | gfx::Transform parent_translation_to_anchor; |
| 716 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 717 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 718 | gfx::Transform parent_composite_transform = |
| 719 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 720 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 721 | gfx::Vector2dF parent_composite_scale = |
| 722 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 723 | 1.f); |
| 724 | gfx::Transform surface_sublayer_transform; |
| 725 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 726 | parent_composite_scale.y()); |
| 727 | gfx::Transform surface_sublayer_composite_transform = |
| 728 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 729 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 730 | root->SetBounds(gfx::Size(1, 2)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 731 | parent->test_properties()->transform = parent_layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 732 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f); |
| 733 | parent->SetBounds(gfx::Size(100, 120)); |
| 734 | child->SetBounds(gfx::Size(16, 18)); |
| 735 | child->test_properties()->force_render_surface = true; |
| 736 | grand_child->SetBounds(gfx::Size(8, 10)); |
| 737 | grand_child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 738 | ExecuteCalculateDrawProperties(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 739 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 740 | // Render surface should have been created now. |
| 741 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 742 | ASSERT_EQ(child->render_surface(), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 743 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 744 | // The child layer's draw transform should refer to its new render surface. |
| 745 | // The screen-space transform, however, should still refer to the root. |
| 746 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 747 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 748 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 749 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 750 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 751 | // Because the grand_child is the only drawable content, the child's render |
| 752 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 753 | // surface's subtree is drawn must be removed from the composite transform. |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 754 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, |
| 755 | child->render_target()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 756 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 757 | // The screen space is the same as the target since the child surface draws |
| 758 | // into the root. |
| 759 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 760 | surface_sublayer_composite_transform, |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 761 | child->render_target()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 762 | } |
| 763 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 764 | TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 765 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 766 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 767 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 768 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 769 | |
| 770 | gfx::Transform parent_transform; |
| 771 | parent_transform.Translate(10.0, 10.0); |
| 772 | |
| 773 | gfx::Transform child_transform; |
| 774 | child_transform.Rotate(45.0); |
| 775 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 776 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 777 | parent->test_properties()->transform = parent_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 778 | parent->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 779 | child->test_properties()->transform = child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 780 | child->SetBounds(gfx::Size(10, 10)); |
| 781 | child->test_properties()->force_render_surface = true; |
| 782 | grand_child->SetPosition(gfx::PointF(2.f, 2.f)); |
| 783 | grand_child->SetBounds(gfx::Size(20, 20)); |
| 784 | grand_child->SetDrawsContent(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 785 | |
| 786 | gfx::Transform expected_grand_child_screen_space_transform; |
| 787 | expected_grand_child_screen_space_transform.Translate(10.0, 10.0); |
| 788 | expected_grand_child_screen_space_transform.Rotate(45.0); |
| 789 | expected_grand_child_screen_space_transform.Translate(2.0, 2.0); |
| 790 | |
| 791 | // First compute draw properties with separate surfaces enabled. |
| 792 | ExecuteCalculateDrawProperties(root); |
| 793 | |
| 794 | // The grand child's draw transform should be its offset wrt the child. |
| 795 | gfx::Transform expected_grand_child_draw_transform; |
| 796 | expected_grand_child_draw_transform.Translate(2.0, 2.0); |
| 797 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 798 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 799 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 800 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 801 | |
| 802 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 803 | |
| 804 | // With separate surfaces disabled, the grand child's draw transform should be |
| 805 | // the same as its screen space transform. |
| 806 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 807 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 808 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 809 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 810 | } |
| 811 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 812 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 813 | // This test creates a more complex tree and verifies it all at once. This |
| 814 | // covers the following cases: |
| 815 | // - layers that are described w.r.t. a render surface: should have draw |
| 816 | // transforms described w.r.t. that surface |
| 817 | // - A render surface described w.r.t. an ancestor render surface: should |
| 818 | // have a draw transform described w.r.t. that ancestor surface |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 819 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 820 | // a render surface that is described w.r.t. an ancestor render surface. |
| 821 | // - verifying that each layer has a reference to the correct render surface |
| 822 | // and render target values. |
| 823 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 824 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 825 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 826 | parent->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 827 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 828 | render_surface1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 829 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 830 | render_surface2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 831 | LayerImpl* child_of_root = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 832 | child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 833 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 834 | child_of_rs1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 835 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 836 | child_of_rs2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 837 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 838 | grand_child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 839 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 840 | grand_child_of_rs1->SetDrawsContent(true); |
| 841 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 842 | grand_child_of_rs2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 843 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 844 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 845 | // to have a new render surface. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 846 | render_surface1->test_properties()->opacity = 0.5f; |
| 847 | render_surface2->test_properties()->opacity = 0.33f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 848 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 849 | // 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] | 850 | // (10,10). Matrix "A" is the composite layer transform used in all layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 851 | gfx::Transform translation_to_anchor; |
| 852 | translation_to_anchor.Translate(2.5, 0.0); |
| 853 | gfx::Transform layer_transform; |
| 854 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 855 | |
| 856 | gfx::Transform A = |
| 857 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 858 | |
| 859 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 860 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 861 | gfx::Transform surface1_sublayer_transform; |
| 862 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 863 | surface1_parent_transform_scale.y()); |
| 864 | |
| 865 | // SS1 = transform given to the subtree of render_surface1 |
| 866 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 867 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 868 | // the owning layer |
| 869 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 870 | |
| 871 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 872 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 873 | gfx::Transform surface2_sublayer_transform; |
| 874 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 875 | surface2_parent_transform_scale.y()); |
| 876 | |
| 877 | // SS2 = transform given to the subtree of render_surface2 |
| 878 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 879 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 880 | // the owning layer |
| 881 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 882 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 883 | root->SetBounds(gfx::Size(1, 2)); |
| 884 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 885 | parent->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 886 | parent->SetBounds(gfx::Size(10, 10)); |
| 887 | render_surface1->test_properties()->transform_origin = |
| 888 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 889 | render_surface1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 890 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 891 | render_surface1->test_properties()->force_render_surface = true; |
| 892 | render_surface2->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_surface2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 895 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 896 | render_surface2->test_properties()->force_render_surface = true; |
| 897 | child_of_root->test_properties()->transform_origin = |
| 898 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 899 | child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 900 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 901 | child_of_rs1->test_properties()->transform_origin = |
| 902 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 903 | child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 904 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 905 | child_of_rs2->test_properties()->transform_origin = |
| 906 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 907 | child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 908 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 909 | grand_child_of_root->test_properties()->transform_origin = |
| 910 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 911 | grand_child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 912 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 913 | grand_child_of_rs1->test_properties()->transform_origin = |
| 914 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 915 | grand_child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 916 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 917 | grand_child_of_rs2->test_properties()->transform_origin = |
| 918 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 919 | grand_child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 920 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 921 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 922 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 923 | |
| 924 | // Only layers that are associated with render surfaces should have an actual |
| 925 | // RenderSurface() value. |
| 926 | ASSERT_TRUE(root->render_surface()); |
| 927 | ASSERT_FALSE(child_of_root->render_surface()); |
| 928 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 929 | |
| 930 | ASSERT_TRUE(render_surface1->render_surface()); |
| 931 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 932 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 933 | |
| 934 | ASSERT_TRUE(render_surface2->render_surface()); |
| 935 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 936 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 937 | |
| 938 | // Verify all render target accessors |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 939 | EXPECT_EQ(root->render_surface(), parent->render_target()); |
| 940 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 941 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 942 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 943 | EXPECT_EQ(render_surface1->render_surface(), |
| 944 | render_surface1->render_target()); |
| 945 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 946 | EXPECT_EQ(render_surface1->render_surface(), |
| 947 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 948 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 949 | EXPECT_EQ(render_surface2->render_surface(), |
| 950 | render_surface2->render_target()); |
| 951 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 952 | EXPECT_EQ(render_surface2->render_surface(), |
| 953 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 954 | |
| 955 | // Verify layer draw transforms note that draw transforms are described with |
| 956 | // respect to the nearest ancestor render surface but screen space transforms |
| 957 | // are described with respect to the root. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 958 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform()); |
| 959 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 960 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 961 | grand_child_of_root->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 962 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 963 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform()); |
| 964 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 965 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 966 | grand_child_of_rs1->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(SS2, render_surface2->DrawTransform()); |
| 969 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 970 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 971 | grand_child_of_rs2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 972 | |
| 973 | // Verify layer screen-space transforms |
| 974 | // |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 975 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform()); |
| 976 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform()); |
| 977 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
| 978 | grand_child_of_root->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 979 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 980 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 981 | render_surface1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 982 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 983 | child_of_rs1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 984 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 985 | grand_child_of_rs1->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 986 | |
[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 | render_surface2->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 | child_of_rs2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 991 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 992 | grand_child_of_rs2->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 993 | |
| 994 | // Verify render surface transforms. |
| 995 | // |
| 996 | // Draw transform of render surface 1 is described with respect to root. |
| 997 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 998 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 999 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1000 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1001 | // Draw transform of render surface 2 is described with respect to render |
| 1002 | // surface 1. |
| 1003 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1004 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1005 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1006 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1007 | render_surface2->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1008 | |
| 1009 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 1010 | // is expected that we correctly set up transforms so that the y-component of |
| 1011 | // the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1012 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1013 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1014 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1015 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1016 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1017 | |
[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 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 1020 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1021 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1022 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1023 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1024 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1025 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 1026 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1027 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1028 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1029 | } |
| 1030 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1031 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1032 | // For layers that flatten their subtree, there should be an orthographic |
| 1033 | // projection (for x and y values) in the middle of the transform sequence. |
| 1034 | // Note that the way the code is currently implemented, it is not expected to |
| 1035 | // use a canonical orthographic projection. |
| 1036 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1037 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1038 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1039 | child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1040 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1041 | grand_child->SetDrawsContent(true); |
| 1042 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 1043 | great_grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1044 | |
| 1045 | gfx::Transform rotation_about_y_axis; |
| 1046 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1047 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1048 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1049 | child->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1050 | child->SetBounds(gfx::Size(10, 10)); |
| 1051 | child->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1052 | grand_child->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1053 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1054 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1055 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1056 | // No layers in this test should preserve 3d. |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1057 | ASSERT_TRUE(root->test_properties()->should_flatten_transform); |
| 1058 | ASSERT_TRUE(child->test_properties()->should_flatten_transform); |
| 1059 | ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform); |
| 1060 | ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1061 | |
| 1062 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1063 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1064 | gfx::Transform expected_grand_child_draw_transform = |
| 1065 | rotation_about_y_axis; // draws onto child's render surface |
| 1066 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1067 | flattened_rotation_about_y.FlattenTo2d(); |
| 1068 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1069 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1070 | gfx::Transform expected_great_grand_child_draw_transform = |
| 1071 | flattened_rotation_about_y; |
| 1072 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 1073 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1074 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1075 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1076 | |
| 1077 | // The child's draw transform should have been taken by its surface. |
| 1078 | ASSERT_TRUE(child->render_surface()); |
| 1079 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1080 | child->render_surface()->draw_transform()); |
| 1081 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1082 | expected_child_screen_space_transform, |
| 1083 | child->render_surface()->screen_space_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1084 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1085 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1086 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1087 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1088 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1089 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1090 | grand_child->ScreenSpaceTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1091 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1092 | great_grand_child->DrawTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1093 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1094 | expected_great_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1095 | great_grand_child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1096 | } |
| 1097 | |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1098 | TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1099 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1100 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1101 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1102 | |
| 1103 | gfx::Transform child_transform; |
| 1104 | child_transform.Translate(50.0, 50.0); |
| 1105 | child_transform.RotateAboutZAxis(30.0); |
| 1106 | |
| 1107 | gfx::Transform grand_child_transform; |
| 1108 | grand_child_transform.RotateAboutYAxis(90.0); |
| 1109 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1110 | root->SetBounds(gfx::Size(200, 200)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1111 | child->test_properties()->transform = child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1112 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1113 | grand_child->test_properties()->transform = grand_child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1114 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1115 | grand_child->test_properties()->should_flatten_transform = false; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1116 | grand_child->SetDrawsContent(true); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1117 | float device_scale_factor = 1.f; |
| 1118 | float page_scale_factor = 1.f; |
| 1119 | LayerImpl* page_scale_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 1120 | LayerImpl* inner_viewport_scroll_layer = nullptr; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1121 | // Visible rects computed by combining clips in target space and root space |
| 1122 | // don't match because of rotation transforms. So, we skip |
| 1123 | // verify_visible_rect_calculations. |
| 1124 | bool skip_verify_visible_rect_calculations = true; |
| 1125 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 1126 | page_scale_layer, inner_viewport_scroll_layer, |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1127 | skip_verify_visible_rect_calculations); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1128 | |
| 1129 | // Mapping grand_child's bounds to target space produces a non-empty rect |
| 1130 | // that is fully contained within the target's bounds, so grand_child should |
| 1131 | // be considered fully visible. |
| 1132 | EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1133 | grand_child->visible_layer_rect()); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1134 | } |
| 1135 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1136 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1137 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1138 | // skipping a necessary translation. Without that translation, the coordinate |
| 1139 | // space of the layer's draw transform is incorrect. |
| 1140 | // |
| 1141 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1142 | // but if that layer becomes a render surface, then its draw transform is |
| 1143 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1144 | // incorrectly as a result. |
| 1145 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1146 | LayerImpl* root = root_layer_for_testing(); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1147 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1148 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1149 | grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1150 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1151 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1152 | // The child height is zero, but has non-zero width that should be accounted |
| 1153 | // for while computing draw transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1154 | child->SetBounds(gfx::Size(10, 0)); |
| 1155 | child->test_properties()->force_render_surface = true; |
| 1156 | grand_child->SetBounds(gfx::Size(10, 10)); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1157 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1158 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1159 | ASSERT_TRUE(child->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1160 | // This is the real test, the rest are sanity checks. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1161 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1162 | child->render_surface()->draw_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1163 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1164 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1165 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1166 | } |
| 1167 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1168 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1169 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1170 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 1171 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 1172 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1173 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1174 | gfx::Transform translate; |
| 1175 | translate.Translate3d(5, 5, 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1176 | |
| 1177 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1178 | render_surface->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1179 | render_surface->SetBounds(gfx::Size(100, 100)); |
| 1180 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1181 | child->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1182 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1183 | grand_child->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1184 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1185 | grand_child->SetDrawsContent(true); |
| 1186 | |
| 1187 | // render_surface will have a sublayer scale because of device scale factor. |
| 1188 | float device_scale_factor = 2.0f; |
| 1189 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1190 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1191 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1192 | inputs.device_scale_factor = device_scale_factor; |
| 1193 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1194 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1195 | |
| 1196 | // Between grand_child and render_surface, we translate by (10, 10) and scale |
| 1197 | // by a factor of 2. |
| 1198 | gfx::Vector2dF expected_translation(20.0f, 20.0f); |
| 1199 | EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(), |
| 1200 | expected_translation); |
| 1201 | } |
| 1202 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1203 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1204 | // Transformations applied at the root of the tree should be forwarded |
| 1205 | // to child layers instead of applied to the root RenderSurface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1206 | LayerImpl* root = root_layer_for_testing(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1207 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1208 | |
| 1209 | root->SetDrawsContent(true); |
| 1210 | root->SetBounds(gfx::Size(20, 20)); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1211 | child->SetDrawsContent(true); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1212 | child->SetScrollClipLayer(root->id()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1213 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1214 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1215 | gfx::Transform translate; |
| 1216 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1217 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1218 | LayerImplList render_surface_layer_list_impl; |
| 1219 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1220 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1221 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1222 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1223 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1224 | translate, root->draw_properties().target_space_transform); |
| 1225 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1226 | translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1227 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1228 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1229 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1230 | |
| 1231 | gfx::Transform scale; |
| 1232 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1233 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1234 | LayerImplList render_surface_layer_list_impl; |
| 1235 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1236 | root, root->bounds(), scale, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1237 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1238 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1239 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1240 | scale, root->draw_properties().target_space_transform); |
| 1241 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1242 | scale, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1243 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1244 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1245 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1246 | |
| 1247 | gfx::Transform rotate; |
| 1248 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1249 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1250 | LayerImplList render_surface_layer_list_impl; |
| 1251 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1252 | root, root->bounds(), rotate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1253 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1254 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1255 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1256 | rotate, root->draw_properties().target_space_transform); |
| 1257 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1258 | rotate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1259 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1260 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1261 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1262 | |
| 1263 | gfx::Transform composite; |
| 1264 | composite.ConcatTransform(translate); |
| 1265 | composite.ConcatTransform(scale); |
| 1266 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1267 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1268 | LayerImplList render_surface_layer_list_impl; |
| 1269 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1270 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1271 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1272 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1273 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1274 | composite, root->draw_properties().target_space_transform); |
| 1275 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1276 | composite, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1277 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1278 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1279 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1280 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1281 | // Verify it composes correctly with device scale. |
| 1282 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1283 | |
| 1284 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1285 | LayerImplList render_surface_layer_list_impl; |
| 1286 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1287 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1288 | inputs.device_scale_factor = device_scale_factor; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1289 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1290 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1291 | gfx::Transform device_scaled_translate = translate; |
jaydasika | 18ea272 | 2016-10-27 23:47:10 | [diff] [blame] | 1292 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1293 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1294 | device_scaled_translate, |
| 1295 | root->draw_properties().target_space_transform); |
| 1296 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1297 | device_scaled_translate, |
| 1298 | child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1299 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1300 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1301 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1302 | |
| 1303 | // Verify it composes correctly with page scale. |
| 1304 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1305 | |
| 1306 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1307 | LayerImplList render_surface_layer_list_impl; |
| 1308 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1309 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1310 | inputs.page_scale_factor = page_scale_factor; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1311 | inputs.page_scale_layer = root; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1312 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1313 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1314 | gfx::Transform page_scaled_translate = translate; |
jaydasika | 18ea272 | 2016-10-27 23:47:10 | [diff] [blame] | 1315 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1316 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1317 | page_scaled_translate, root->draw_properties().target_space_transform); |
| 1318 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1319 | page_scaled_translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1320 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1321 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1322 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1323 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1324 | // Verify that it composes correctly with transforms directly on root layer. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1325 | root->test_properties()->transform = composite; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1326 | |
| 1327 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1328 | LayerImplList render_surface_layer_list_impl; |
| 1329 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1330 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [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 compositeSquared = composite; |
| 1334 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1335 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1336 | compositeSquared, root->draw_properties().target_space_transform); |
| 1337 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1338 | compositeSquared, 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()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1341 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1342 | } |
| 1343 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1344 | TEST_F(LayerTreeHostCommonTest, |
| 1345 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1346 | LayerImpl* root = root_layer_for_testing(); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1347 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1348 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1349 | |
| 1350 | root->SetBounds(gfx::Size(10, 10)); |
| 1351 | root->SetMasksToBounds(true); |
| 1352 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1353 | render_surface1->test_properties()->force_render_surface = true; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1354 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1355 | child->SetPosition(gfx::PointF(30.f, 30.f)); |
| 1356 | child->SetBounds(gfx::Size(10, 10)); |
| 1357 | ExecuteCalculateDrawProperties(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1358 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1359 | // 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] | 1360 | // the intermediate render surface should not be listed here, even if it was |
| 1361 | // forced to be created. Render surfaces without children or visible content |
| 1362 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1363 | // of size 0). |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1364 | ASSERT_TRUE(root->render_surface()); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1365 | EXPECT_EQ(1U, render_surface_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1366 | } |
| 1367 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1368 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1369 | LayerImpl* root = root_layer_for_testing(); |
| 1370 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1371 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1372 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1373 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1374 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1375 | render_surface1->test_properties()->opacity = 0.f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1376 | child->SetBounds(gfx::Size(10, 10)); |
| 1377 | child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1378 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1379 | LayerImplList render_surface_layer_list; |
| 1380 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1381 | root, root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1382 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1383 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1384 | |
| 1385 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1386 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1387 | // have been extended by the children. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1388 | ASSERT_TRUE(root->render_surface()); |
| 1389 | EXPECT_EQ(0U, root->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1390 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1391 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 1392 | EXPECT_EQ(gfx::Rect(), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1393 | } |
| 1394 | |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1395 | TEST_F(LayerTreeHostCommonTest, |
| 1396 | RenderSurfaceListForTransparentChildWithBackgroundFilter) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1397 | LayerImpl* root = root_layer_for_testing(); |
| 1398 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1399 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1400 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1401 | root->SetBounds(gfx::Size(10, 10)); |
| 1402 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1403 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1404 | render_surface1->test_properties()->opacity = 0.f; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 1405 | render_surface1->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1406 | FilterOperations filters; |
| 1407 | filters.Append(FilterOperation::CreateBlurFilter(1.5f)); |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 1408 | render_surface1->test_properties()->background_filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1409 | child->SetBounds(gfx::Size(10, 10)); |
| 1410 | child->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1411 | |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1412 | { |
| 1413 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1414 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1415 | root, root->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1416 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1417 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1418 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1419 | } |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1420 | // The layer is fully transparent, but has a background filter, so it |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1421 | // shouldn't be skipped and should be drawn. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1422 | ASSERT_TRUE(root->render_surface()); |
| 1423 | EXPECT_EQ(1U, root->render_surface()->layer_list().size()); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1424 | EXPECT_EQ(gfx::RectF(0, 0, 10, 10), |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1425 | root->render_surface()->DrawableContentRect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1426 | EffectTree& effect_tree = |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1427 | root->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1428 | EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1429 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1430 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1431 | // When root is transparent, the layer should not be drawn. |
jaydasika | 898b2f1 | 2016-08-20 04:22:09 | [diff] [blame] | 1432 | effect_tree.OnOpacityAnimated(0.f, root->effect_tree_index(), |
| 1433 | root->layer_tree_impl()); |
| 1434 | effect_tree.OnOpacityAnimated(1.f, render_surface1->effect_tree_index(), |
| 1435 | root->layer_tree_impl()); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1436 | render_surface1->set_visible_layer_rect(gfx::Rect()); |
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 | } |
| 1444 | |
| 1445 | node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1446 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1447 | EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect()); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1448 | } |
| 1449 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1450 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1451 | LayerImpl* root = root_layer_for_testing(); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1452 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1453 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1454 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1455 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1456 | gfx::Transform scale_matrix; |
| 1457 | scale_matrix.Scale(2.0f, 2.0f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1458 | |
| 1459 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1460 | parent->test_properties()->transform = scale_matrix; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1461 | FilterOperations filters; |
| 1462 | filters.Append(FilterOperation::CreateBlurFilter(10.0f)); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1463 | parent->test_properties()->filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1464 | parent->test_properties()->force_render_surface = true; |
| 1465 | child1->SetBounds(gfx::Size(25, 25)); |
| 1466 | child1->SetDrawsContent(true); |
| 1467 | child1->test_properties()->force_render_surface = true; |
| 1468 | child2->SetPosition(gfx::PointF(25, 25)); |
| 1469 | child2->SetBounds(gfx::Size(25, 25)); |
| 1470 | child2->SetDrawsContent(true); |
| 1471 | child2->test_properties()->force_render_surface = true; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1472 | |
| 1473 | LayerImplList render_surface_layer_list; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1474 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1475 | root, root->bounds(), &render_surface_layer_list); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1476 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1477 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1478 | |
| 1479 | ASSERT_TRUE(parent->render_surface()); |
| 1480 | EXPECT_EQ(2U, parent->render_surface()->layer_list().size()); |
| 1481 | EXPECT_EQ(4U, render_surface_layer_list.size()); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1482 | |
| 1483 | // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the |
| 1484 | // blur (-30,-30 110x110), and then scaled by the scale matrix |
| 1485 | // (-60,-60 220x220). |
| 1486 | EXPECT_EQ(gfx::RectF(-60, -60, 220, 220), |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1487 | parent->render_surface()->DrawableContentRect()); |
| 1488 | } |
| 1489 | |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1490 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1491 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1492 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1493 | |
| 1494 | root->SetBounds(gfx::Size(100, 100)); |
| 1495 | child->SetBounds(gfx::Size(25, 25)); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1496 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1497 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1498 | FilterOperations filters; |
| 1499 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1500 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1501 | child->test_properties()->filters = filters; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1502 | ExecuteCalculateDrawProperties(root); |
| 1503 | |
| 1504 | // The render surface's size should be unaffected by the offset image filter; |
| 1505 | // it need only have a drawable content rect large enough to contain the |
| 1506 | // contents (at the new offset). |
| 1507 | ASSERT_TRUE(child->render_surface()); |
| 1508 | EXPECT_EQ(gfx::RectF(50, 50, 25, 25), |
| 1509 | child->render_surface()->DrawableContentRect()); |
| 1510 | } |
| 1511 | |
| 1512 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) { |
| 1513 | const float device_scale_factor = 2.0f; |
| 1514 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1515 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1516 | LayerImpl* child = AddChild<LayerImpl>(root); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1517 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1518 | root->SetBounds(gfx::Size(100, 100)); |
| 1519 | child->SetBounds(gfx::Size(25, 25)); |
| 1520 | child->SetDrawsContent(true); |
| 1521 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1522 | |
| 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 | |
| 1528 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 1529 | |
| 1530 | // The render surface's size should be unaffected by the offset image filter; |
| 1531 | // it need only have a drawable content rect large enough to contain the |
| 1532 | // contents (at the new offset). All coordinates should be scaled by 2, |
| 1533 | // corresponding to the device scale factor. |
| 1534 | ASSERT_TRUE(child->render_surface()); |
| 1535 | EXPECT_EQ(gfx::RectF(100, 100, 50, 50), |
| 1536 | child->render_surface()->DrawableContentRect()); |
| 1537 | } |
| 1538 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1539 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1540 | LayerImpl* root = root_layer_for_testing(); |
| 1541 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1542 | |
| 1543 | root->SetBounds(gfx::Size(10, 10)); |
| 1544 | child->SetBounds(gfx::Size(10, 10)); |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1545 | child->SetDrawsContent(true); |
ajuma | 4c14b25 | 2016-07-26 20:10:59 | [diff] [blame] | 1546 | child->test_properties()->blend_mode = SkXfermode::kMultiply_Mode; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1547 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1548 | child->test_properties()->force_render_surface = true; |
| 1549 | ExecuteCalculateDrawProperties(root); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1550 | |
| 1551 | // Since the child layer has a blend mode other than normal, it should get |
| 1552 | // its own render surface. Also, layer's draw_properties should contain the |
| 1553 | // default blend mode, since the render surface becomes responsible for |
| 1554 | // applying the blend mode. |
| 1555 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1556 | EXPECT_EQ(1.0f, child->draw_opacity()); |
| 1557 | EXPECT_EQ(0.5f, child->render_surface()->draw_opacity()); |
jaydasika | 92239dc | 2015-08-15 02:59:26 | [diff] [blame] | 1558 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode()); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1559 | } |
| 1560 | |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1561 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1562 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1563 | LayerImpl* surface1 = AddChildToRoot<LayerImpl>(); |
| 1564 | LayerImpl* not_surface = AddChild<LayerImpl>(surface1); |
| 1565 | LayerImpl* surface2 = AddChild<LayerImpl>(not_surface); |
| 1566 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1567 | root->SetBounds(gfx::Size(10, 10)); |
| 1568 | surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1569 | surface1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1570 | surface1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1571 | surface1->test_properties()->force_render_surface = true; |
| 1572 | not_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1573 | not_surface->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1574 | surface2->SetBounds(gfx::Size(10, 10)); |
| 1575 | surface2->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1576 | surface2->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1577 | surface2->test_properties()->force_render_surface = true; |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1578 | ExecuteCalculateDrawProperties(root); |
| 1579 | |
| 1580 | ASSERT_TRUE(surface1->render_surface()); |
| 1581 | ASSERT_FALSE(not_surface->render_surface()); |
| 1582 | ASSERT_TRUE(surface2->render_surface()); |
| 1583 | EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); |
| 1584 | // surface2's draw opacity should include the opacity of not-surface and |
| 1585 | // itself, but not the opacity of surface1. |
| 1586 | EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); |
| 1587 | } |
| 1588 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1589 | TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) { |
| 1590 | // Tests that when separate surfaces are disabled, a layer's draw opacity is |
| 1591 | // the product of all ancestor layer opacties and the layer's own opacity. |
| 1592 | // (Rendering will still be incorrect in situations where we really do need |
| 1593 | // surfaces to apply opacity, such as when we have overlapping layers with an |
| 1594 | // ancestor whose opacity is <1.) |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1595 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1596 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1597 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1598 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1599 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1600 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1601 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1602 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1603 | root->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1604 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1605 | parent->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1606 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1607 | child1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1608 | child1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1609 | child1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1610 | child1->test_properties()->force_render_surface = true; |
| 1611 | child2->SetBounds(gfx::Size(100, 100)); |
| 1612 | child2->SetDrawsContent(true); |
| 1613 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 1614 | grand_child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1615 | grand_child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1616 | grand_child->test_properties()->force_render_surface = true; |
| 1617 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
| 1618 | leaf_node1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1619 | leaf_node1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1620 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
| 1621 | leaf_node2->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1622 | leaf_node2->test_properties()->opacity = 0.5f; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1623 | |
| 1624 | // With surfaces enabled, each layer's draw opacity is the product of layer |
| 1625 | // opacities on the path from the layer to its render target, not including |
| 1626 | // the opacity of the layer that owns the target surface (since that opacity |
| 1627 | // is applied by the surface). |
| 1628 | ExecuteCalculateDrawProperties(root); |
| 1629 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1630 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1631 | EXPECT_EQ(1.f, child1->draw_opacity()); |
| 1632 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1633 | EXPECT_EQ(1.f, grand_child->draw_opacity()); |
| 1634 | EXPECT_EQ(0.5f, leaf_node1->draw_opacity()); |
| 1635 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1636 | |
| 1637 | // With surfaces disabled, each layer's draw opacity is the product of layer |
| 1638 | // opacities on the path from the layer to the root. |
| 1639 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1640 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1641 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1642 | EXPECT_EQ(0.5f, child1->draw_opacity()); |
| 1643 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1644 | EXPECT_EQ(0.25f, grand_child->draw_opacity()); |
| 1645 | EXPECT_EQ(0.125f, leaf_node1->draw_opacity()); |
| 1646 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1647 | } |
| 1648 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1649 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1650 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1651 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1652 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1653 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1654 | root->SetBounds(gfx::Size(10, 10)); |
| 1655 | render_surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1656 | render_surface1->test_properties()->force_render_surface = true; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1657 | child->SetBounds(gfx::Size(10, 10)); |
| 1658 | child->SetDrawsContent(true); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1659 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1660 | { |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1661 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1662 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1663 | // The root layer always creates a render surface |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1664 | EXPECT_TRUE(root->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1665 | EXPECT_TRUE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1666 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1667 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1668 | { |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1669 | render_surface1->test_properties()->force_render_surface = false; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1670 | render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1671 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1672 | EXPECT_TRUE(root->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1673 | EXPECT_FALSE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1674 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1675 | } |
| 1676 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1677 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1678 | // Render surfaces act as a flattening point for their subtree, so should |
| 1679 | // always flatten the target-to-screen space transform seen by descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1680 | LayerImpl* root = root_layer_for_testing(); |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1681 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1682 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1683 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1684 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1685 | gfx::Transform rotation_about_y_axis; |
| 1686 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1687 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1688 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1689 | parent->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1690 | parent->SetBounds(gfx::Size(10, 10)); |
| 1691 | parent->test_properties()->force_render_surface = true; |
| 1692 | child->SetBounds(gfx::Size(10, 10)); |
| 1693 | child->SetDrawsContent(true); |
| 1694 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1695 | grand_child->SetDrawsContent(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1696 | grand_child->test_properties()->should_flatten_transform = false; |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1697 | ExecuteCalculateDrawProperties(root); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1698 | |
| 1699 | EXPECT_TRUE(parent->render_surface()); |
| 1700 | EXPECT_FALSE(child->render_surface()); |
| 1701 | EXPECT_FALSE(grand_child->render_surface()); |
| 1702 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1703 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1704 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1705 | grand_child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1706 | |
| 1707 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1708 | // have been flattened at their render target. In particular, the fact that |
| 1709 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1710 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1711 | flattened_rotation_about_y.FlattenTo2d(); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1712 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1713 | child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1714 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1715 | grand_child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1716 | } |
| 1717 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1718 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1719 | // The entire subtree of layers that are outside the clip rect should be |
| 1720 | // culled away, and should not affect the render_surface_layer_list. |
| 1721 | // |
| 1722 | // The test tree is set up as follows: |
| 1723 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1724 | // that have something to draw. |
| 1725 | // - parent is a large container layer. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1726 | // - child has MasksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1727 | // - grand_child is positioned outside of the child's bounds |
| 1728 | // - great_grand_child is also kept outside child's bounds. |
| 1729 | // |
| 1730 | // In this configuration, grand_child and great_grand_child are completely |
| 1731 | // outside the clip rect, and they should never get scheduled on the list of |
| 1732 | // render surfaces. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1733 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1734 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1735 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1736 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1737 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1738 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1739 | // leaf_node1 ensures that root and child are kept on the |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1740 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1741 | // should be clipped. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1742 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(child); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1743 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1744 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1745 | root->SetBounds(gfx::Size(500, 500)); |
| 1746 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1747 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1748 | child->test_properties()->force_render_surface = true; |
| 1749 | grand_child->SetPosition(gfx::PointF(45.f, 45.f)); |
| 1750 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1751 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
| 1752 | leaf_node1->SetBounds(gfx::Size(500, 500)); |
| 1753 | leaf_node1->SetDrawsContent(true); |
| 1754 | leaf_node1->SetBounds(gfx::Size(20, 20)); |
| 1755 | leaf_node2->SetDrawsContent(true); |
| 1756 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1757 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1758 | ASSERT_EQ(2U, render_surface_layer_list_impl()->size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1759 | EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id()); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1760 | EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1761 | } |
| 1762 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1763 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1764 | // 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] | 1765 | // of the surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1766 | |
| 1767 | // The test tree is set up as follows: |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1768 | // - root is a container layer that masksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1769 | // - 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] | 1770 | // the root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1771 | // - grand_child is a render surface, and the only visible content in child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1772 | // It is positioned outside of the clip rect from root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1773 | |
| 1774 | // In this configuration, grand_child should be outside the clipped |
| 1775 | // content rect of the child, making grand_child not appear in the |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1776 | // render_surface_layer_list. |
| 1777 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1778 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1779 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1780 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1781 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1782 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1783 | root->SetMasksToBounds(true); |
| 1784 | root->SetBounds(gfx::Size(100, 100)); |
| 1785 | child->SetBounds(gfx::Size(20, 20)); |
| 1786 | child->test_properties()->force_render_surface = true; |
| 1787 | grand_child->SetPosition(gfx::PointF(200.f, 200.f)); |
| 1788 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1789 | grand_child->test_properties()->force_render_surface = true; |
| 1790 | leaf_node->SetBounds(gfx::Size(10, 10)); |
| 1791 | leaf_node->SetDrawsContent(true); |
| 1792 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1793 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1794 | // We should cull child and grand_child from the |
| 1795 | // render_surface_layer_list. |
| 1796 | ASSERT_EQ(1U, render_surface_layer_list_impl()->size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1797 | EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1798 | } |
| 1799 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1800 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) { |
| 1801 | // Tests that LayerImpl's IsClipped() property is set to true when: |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1802 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1803 | // - the layer is clipped by an ancestor that contributes to the same |
| 1804 | // render target, |
| 1805 | // - a surface is clipped by an ancestor that contributes to the same |
| 1806 | // render target. |
| 1807 | // |
| 1808 | // In particular, for a layer that owns a render surface: |
| 1809 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1810 | // pass that clipped status to the layer itself. |
| 1811 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1812 | // and propagates the clip to the subtree. |
| 1813 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1814 | LayerImpl* root = root_layer_for_testing(); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1815 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1816 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1817 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1818 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1819 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1820 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1821 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1822 | root->SetBounds(gfx::Size(100, 100)); |
| 1823 | parent->SetBounds(gfx::Size(100, 100)); |
| 1824 | parent->SetDrawsContent(true); |
| 1825 | child1->SetBounds(gfx::Size(100, 100)); |
| 1826 | child1->SetDrawsContent(true); |
| 1827 | child2->SetBounds(gfx::Size(100, 100)); |
| 1828 | child2->SetDrawsContent(true); |
| 1829 | child2->test_properties()->force_render_surface = true; |
| 1830 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 1831 | grand_child->SetDrawsContent(true); |
| 1832 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
| 1833 | leaf_node1->SetDrawsContent(true); |
| 1834 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
| 1835 | leaf_node2->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1836 | |
| 1837 | // Case 1: nothing is clipped except the root render surface. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1838 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1839 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1840 | ASSERT_TRUE(root->render_surface()); |
| 1841 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1842 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1843 | EXPECT_FALSE(root->is_clipped()); |
| 1844 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1845 | EXPECT_FALSE(parent->is_clipped()); |
| 1846 | EXPECT_FALSE(child1->is_clipped()); |
| 1847 | EXPECT_FALSE(child2->is_clipped()); |
| 1848 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1849 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1850 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1851 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1852 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1853 | // Case 2: parent MasksToBounds, so the parent, child1, and child2's |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1854 | // surface are clipped. But layers that contribute to child2's surface are |
| 1855 | // not clipped explicitly because child2's surface already accounts for |
| 1856 | // that clip. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1857 | parent->SetMasksToBounds(true); |
| 1858 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1859 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1860 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1861 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1862 | ASSERT_TRUE(root->render_surface()); |
| 1863 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1864 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1865 | EXPECT_FALSE(root->is_clipped()); |
| 1866 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1867 | EXPECT_TRUE(parent->is_clipped()); |
| 1868 | EXPECT_TRUE(child1->is_clipped()); |
| 1869 | EXPECT_FALSE(child2->is_clipped()); |
| 1870 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1871 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1872 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1873 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1874 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1875 | parent->SetMasksToBounds(false); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1876 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1877 | // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1878 | // child2's render surface is not clipped. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1879 | child2->SetMasksToBounds(true); |
| 1880 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1881 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1882 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1883 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1884 | ASSERT_TRUE(root->render_surface()); |
| 1885 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1886 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1887 | EXPECT_FALSE(root->is_clipped()); |
| 1888 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1889 | EXPECT_FALSE(parent->is_clipped()); |
| 1890 | EXPECT_FALSE(child1->is_clipped()); |
| 1891 | EXPECT_TRUE(child2->is_clipped()); |
| 1892 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1893 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1894 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1895 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1896 | } |
| 1897 | |
| 1898 | TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) { |
| 1899 | // Tests that when as long as layer is clipped, it's clip rect is set to |
| 1900 | // correct value. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1901 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1902 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1903 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1904 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1905 | root->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1906 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1907 | parent->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1908 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1909 | child->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1910 | child->SetDrawsContent(true); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1911 | child->SetMasksToBounds(true); |
| 1912 | |
| 1913 | ExecuteCalculateDrawProperties(root); |
| 1914 | |
| 1915 | EXPECT_FALSE(root->is_clipped()); |
| 1916 | EXPECT_FALSE(parent->is_clipped()); |
| 1917 | EXPECT_TRUE(child->is_clipped()); |
| 1918 | EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect()); |
| 1919 | |
| 1920 | parent->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1921 | child->SetPosition(gfx::PointF(100.f, 100.f)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1922 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1923 | |
| 1924 | ExecuteCalculateDrawProperties(root); |
| 1925 | |
| 1926 | EXPECT_FALSE(root->is_clipped()); |
| 1927 | EXPECT_TRUE(parent->is_clipped()); |
| 1928 | EXPECT_TRUE(child->is_clipped()); |
| 1929 | EXPECT_EQ(gfx::Rect(), child->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1930 | } |
| 1931 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1932 | TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { |
| 1933 | // Tests that when separate surfaces are disabled, is_clipped is true exactly |
| 1934 | // when a layer or its ancestor has a clip; in particular, if a layer |
| 1935 | // is_clipped, so is its entire subtree (since there are no render surfaces |
| 1936 | // that can reset is_clipped). |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1937 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1938 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1939 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1940 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1941 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1942 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1943 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1944 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1945 | root->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1946 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1947 | parent->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1948 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1949 | child1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1950 | child1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1951 | child1->test_properties()->force_render_surface = true; |
| 1952 | child2->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1953 | child2->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1954 | grand_child->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1955 | grand_child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1956 | grand_child->test_properties()->force_render_surface = true; |
| 1957 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1958 | leaf_node1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1959 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1960 | leaf_node2->SetDrawsContent(true); |
| 1961 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1962 | // Case 1: Nothing is clipped. In this case, is_clipped is always false, with |
| 1963 | // or without surfaces. |
| 1964 | ExecuteCalculateDrawProperties(root); |
| 1965 | EXPECT_FALSE(root->is_clipped()); |
| 1966 | EXPECT_FALSE(parent->is_clipped()); |
| 1967 | EXPECT_FALSE(child1->is_clipped()); |
| 1968 | EXPECT_FALSE(child2->is_clipped()); |
| 1969 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1970 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1971 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1972 | |
| 1973 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1974 | EXPECT_FALSE(root->is_clipped()); |
| 1975 | EXPECT_FALSE(parent->is_clipped()); |
| 1976 | EXPECT_FALSE(child1->is_clipped()); |
| 1977 | EXPECT_FALSE(child2->is_clipped()); |
| 1978 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1979 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1980 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1981 | |
| 1982 | // Case 2: The root is clipped. With surfaces, this only persists until the |
| 1983 | // next render surface. Without surfaces, the entire tree is clipped. |
| 1984 | root->SetMasksToBounds(true); |
| 1985 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1986 | ExecuteCalculateDrawProperties(root); |
| 1987 | EXPECT_TRUE(root->is_clipped()); |
| 1988 | EXPECT_TRUE(parent->is_clipped()); |
| 1989 | EXPECT_FALSE(child1->is_clipped()); |
| 1990 | EXPECT_TRUE(child2->is_clipped()); |
| 1991 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1992 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1993 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1994 | |
| 1995 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1996 | EXPECT_TRUE(root->is_clipped()); |
| 1997 | EXPECT_TRUE(parent->is_clipped()); |
| 1998 | EXPECT_TRUE(child1->is_clipped()); |
| 1999 | EXPECT_TRUE(child2->is_clipped()); |
| 2000 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2001 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2002 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2003 | |
| 2004 | root->SetMasksToBounds(false); |
| 2005 | |
| 2006 | // Case 3: The parent is clipped. Again, with surfaces, this only persists |
| 2007 | // until the next render surface. Without surfaces, parent's entire subtree is |
| 2008 | // clipped. |
| 2009 | parent->SetMasksToBounds(true); |
| 2010 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2011 | ExecuteCalculateDrawProperties(root); |
| 2012 | EXPECT_FALSE(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_FALSE(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 | parent->SetMasksToBounds(false); |
| 2030 | |
| 2031 | // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it |
| 2032 | // has no non-surface children. Without surfaces, child1's entire subtree is |
| 2033 | // clipped. |
| 2034 | child1->SetMasksToBounds(true); |
| 2035 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2036 | ExecuteCalculateDrawProperties(root); |
| 2037 | EXPECT_FALSE(root->is_clipped()); |
| 2038 | EXPECT_FALSE(parent->is_clipped()); |
| 2039 | EXPECT_TRUE(child1->is_clipped()); |
| 2040 | EXPECT_FALSE(child2->is_clipped()); |
| 2041 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2042 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2043 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2044 | |
| 2045 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2046 | EXPECT_FALSE(root->is_clipped()); |
| 2047 | EXPECT_FALSE(parent->is_clipped()); |
| 2048 | EXPECT_TRUE(child1->is_clipped()); |
| 2049 | EXPECT_FALSE(child2->is_clipped()); |
| 2050 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2051 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2052 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2053 | |
| 2054 | child1->SetMasksToBounds(false); |
| 2055 | |
| 2056 | // Case 5: Only the leaf nodes are clipped. The behavior with and without |
| 2057 | // surfaces is the same. |
| 2058 | leaf_node1->SetMasksToBounds(true); |
| 2059 | leaf_node2->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_FALSE(child1->is_clipped()); |
| 2065 | EXPECT_FALSE(child2->is_clipped()); |
| 2066 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2067 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2068 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2069 | |
| 2070 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2071 | EXPECT_FALSE(root->is_clipped()); |
| 2072 | EXPECT_FALSE(parent->is_clipped()); |
| 2073 | EXPECT_FALSE(child1->is_clipped()); |
| 2074 | EXPECT_FALSE(child2->is_clipped()); |
| 2075 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2076 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2077 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2078 | } |
| 2079 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 2080 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2081 | // Verify that layers get the appropriate DrawableContentRect when their |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2082 | // parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2083 | // |
| 2084 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 2085 | // be the layer rect expressed in target space. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2086 | // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2087 | // will be the intersection of layer bounds and the mask region. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2088 | // grand_child3 - partially clipped and MasksToBounds; the |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2089 | // DrawableContentRect will still be the intersection of layer bounds and |
| 2090 | // the mask region. |
| 2091 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 2092 | // be empty. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2093 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2094 | LayerImpl* parent = root_layer_for_testing(); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2095 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2096 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2097 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2098 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2099 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2100 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2101 | parent->SetBounds(gfx::Size(500, 500)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2102 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2103 | child->SetBounds(gfx::Size(20, 20)); |
| 2104 | child->test_properties()->force_render_surface = true; |
| 2105 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2106 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 2107 | grand_child1->SetDrawsContent(true); |
| 2108 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2109 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 2110 | grand_child2->SetDrawsContent(true); |
| 2111 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2112 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2113 | grand_child3->SetBounds(gfx::Size(10, 10)); |
| 2114 | grand_child3->SetDrawsContent(true); |
| 2115 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 2116 | grand_child4->SetBounds(gfx::Size(10, 10)); |
| 2117 | grand_child4->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2118 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2119 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2120 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2121 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2122 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2123 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2124 | } |
| 2125 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2126 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2127 | // Verify that render surfaces (and their layers) get the appropriate |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2128 | // clip rects when their parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2129 | // |
| 2130 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2131 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2132 | // They may still have a clip rect of their own layer bounds, however, if |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2133 | // MasksToBounds was true. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2134 | LayerImpl* parent = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2135 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2136 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2137 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2138 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2139 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2140 | // The leaf nodes ensure that these grand_children become render surfaces for |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2141 | // this test. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2142 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2143 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2144 | LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2145 | LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2146 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2147 | parent->SetBounds(gfx::Size(500, 500)); |
| 2148 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2149 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2150 | child->test_properties()->force_render_surface = true; |
| 2151 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2152 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 2153 | grand_child1->test_properties()->force_render_surface = true; |
| 2154 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2155 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 2156 | grand_child2->test_properties()->force_render_surface = true; |
| 2157 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2158 | grand_child3->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2159 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2160 | grand_child3->test_properties()->force_render_surface = true; |
| 2161 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 2162 | grand_child4->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2163 | grand_child4->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2164 | grand_child4->test_properties()->force_render_surface = true; |
| 2165 | leaf_node1->SetBounds(gfx::Size(10, 10)); |
| 2166 | leaf_node1->SetDrawsContent(true); |
| 2167 | leaf_node2->SetBounds(gfx::Size(10, 10)); |
| 2168 | leaf_node2->SetDrawsContent(true); |
| 2169 | leaf_node3->SetBounds(gfx::Size(10, 10)); |
| 2170 | leaf_node3->SetDrawsContent(true); |
| 2171 | leaf_node4->SetBounds(gfx::Size(10, 10)); |
| 2172 | leaf_node4->SetDrawsContent(true); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2173 | ExecuteCalculateDrawProperties(parent); |
| 2174 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2175 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2176 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2177 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2178 | |
| 2179 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2180 | // MasksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2181 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2182 | grand_child1->render_surface()->clip_rect()); |
| 2183 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2184 | grand_child2->render_surface()->clip_rect()); |
| 2185 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2186 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2187 | } |
| 2188 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2189 | TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { |
| 2190 | // Tests that when separate surfaces are disabled, a layer's clip_rect is the |
| 2191 | // intersection of all ancestor clips in screen space; in particular, if a |
| 2192 | // layer masks to bounds, it contributes to the clip_rect of all layers in its |
| 2193 | // subtree (since there are no render surfaces that can reset the clip_rect). |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2194 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2195 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2196 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 2197 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 2198 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 2199 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 2200 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 2201 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2202 | root->SetBounds(gfx::Size(100, 100)); |
| 2203 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2204 | parent->SetBounds(gfx::Size(400, 400)); |
| 2205 | child1->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2206 | child1->SetBounds(gfx::Size(800, 800)); |
| 2207 | child2->SetPosition(gfx::PointF(3.f, 3.f)); |
| 2208 | child2->SetBounds(gfx::Size(800, 800)); |
| 2209 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2210 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2211 | leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2212 | leaf_node1->SetBounds(gfx::Size(2000, 2000)); |
| 2213 | leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); |
| 2214 | leaf_node2->SetBounds(gfx::Size(2000, 2000)); |
| 2215 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2216 | root->SetDrawsContent(true); |
| 2217 | parent->SetDrawsContent(true); |
| 2218 | child1->SetDrawsContent(true); |
| 2219 | child2->SetDrawsContent(true); |
| 2220 | grand_child->SetDrawsContent(true); |
| 2221 | leaf_node1->SetDrawsContent(true); |
| 2222 | leaf_node2->SetDrawsContent(true); |
| 2223 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2224 | root->test_properties()->force_render_surface = true; |
| 2225 | child1->test_properties()->force_render_surface = true; |
| 2226 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2227 | |
| 2228 | // Case 1: Nothing is clipped. In this case, each layer's clip rect is its |
| 2229 | // bounds in target space. The only thing that changes when surfaces are |
| 2230 | // disabled is that target space is always screen space. |
| 2231 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2232 | EXPECT_TRUE(root->has_render_surface()); |
| 2233 | EXPECT_FALSE(parent->has_render_surface()); |
| 2234 | EXPECT_TRUE(child1->has_render_surface()); |
| 2235 | EXPECT_FALSE(child2->has_render_surface()); |
| 2236 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2237 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2238 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2239 | EXPECT_FALSE(root->is_clipped()); |
| 2240 | EXPECT_FALSE(parent->is_clipped()); |
| 2241 | EXPECT_FALSE(child1->is_clipped()); |
| 2242 | EXPECT_FALSE(child2->is_clipped()); |
| 2243 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2244 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2245 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2246 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2247 | EXPECT_FALSE(child1->render_surface()->is_clipped()); |
| 2248 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2249 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2250 | |
| 2251 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2252 | EXPECT_FALSE(root->is_clipped()); |
| 2253 | EXPECT_FALSE(parent->is_clipped()); |
| 2254 | EXPECT_FALSE(child1->is_clipped()); |
| 2255 | EXPECT_FALSE(child2->is_clipped()); |
| 2256 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2257 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2258 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2259 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2260 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2261 | |
| 2262 | // Case 2: The root is clipped. In this case, layers that draw into the root |
| 2263 | // render surface are clipped by the root's bounds. |
| 2264 | root->SetMasksToBounds(true); |
| 2265 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2266 | root->test_properties()->force_render_surface = true; |
| 2267 | child1->test_properties()->force_render_surface = true; |
| 2268 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2269 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2270 | EXPECT_TRUE(root->has_render_surface()); |
| 2271 | EXPECT_FALSE(parent->has_render_surface()); |
| 2272 | EXPECT_TRUE(child1->has_render_surface()); |
| 2273 | EXPECT_FALSE(child2->has_render_surface()); |
| 2274 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2275 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2276 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2277 | EXPECT_TRUE(root->is_clipped()); |
| 2278 | EXPECT_TRUE(parent->is_clipped()); |
| 2279 | EXPECT_FALSE(child1->is_clipped()); |
| 2280 | EXPECT_TRUE(child1->render_surface()->is_clipped()); |
| 2281 | EXPECT_TRUE(child2->is_clipped()); |
| 2282 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2283 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2284 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2285 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2286 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2287 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2288 | EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2289 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2290 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2291 | |
| 2292 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2293 | EXPECT_TRUE(root->is_clipped()); |
| 2294 | EXPECT_TRUE(parent->is_clipped()); |
| 2295 | EXPECT_TRUE(child1->is_clipped()); |
| 2296 | EXPECT_TRUE(child2->is_clipped()); |
| 2297 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2298 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2299 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2300 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2301 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
| 2302 | EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect()); |
| 2303 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
| 2304 | EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect()); |
| 2305 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect()); |
| 2306 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2307 | |
| 2308 | root->SetMasksToBounds(false); |
| 2309 | |
| 2310 | // Case 3: The parent and child1 are clipped. When surfaces are enabled, the |
| 2311 | // parent clip rect only contributes to the subtree rooted at child2, since |
| 2312 | // the subtree rooted at child1 renders into a separate surface. Similarly, |
| 2313 | // child1's clip rect doesn't contribute to its descendants, since its only |
| 2314 | // child is a render surface. However, without surfaces, these clip rects |
| 2315 | // contribute to all descendants. |
| 2316 | parent->SetMasksToBounds(true); |
| 2317 | child1->SetMasksToBounds(true); |
| 2318 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2319 | root->test_properties()->force_render_surface = true; |
| 2320 | child1->test_properties()->force_render_surface = true; |
| 2321 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2322 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2323 | EXPECT_TRUE(root->has_render_surface()); |
| 2324 | EXPECT_FALSE(parent->has_render_surface()); |
| 2325 | EXPECT_TRUE(child1->has_render_surface()); |
| 2326 | EXPECT_FALSE(child2->has_render_surface()); |
| 2327 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2328 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2329 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2330 | EXPECT_FALSE(root->is_clipped()); |
| 2331 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2332 | EXPECT_TRUE(parent->is_clipped()); |
| 2333 | EXPECT_TRUE(child1->is_clipped()); |
| 2334 | EXPECT_TRUE(child2->is_clipped()); |
| 2335 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2336 | EXPECT_TRUE(grand_child->render_surface()->is_clipped()); |
| 2337 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2338 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2339 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2340 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2341 | EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); |
| 2342 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2343 | EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2344 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2345 | |
| 2346 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2347 | EXPECT_FALSE(root->is_clipped()); |
| 2348 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2349 | EXPECT_TRUE(parent->is_clipped()); |
| 2350 | EXPECT_TRUE(child1->is_clipped()); |
| 2351 | EXPECT_TRUE(child2->is_clipped()); |
| 2352 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2353 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2354 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2355 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2356 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2357 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect()); |
| 2358 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
| 2359 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect()); |
| 2360 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect()); |
| 2361 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2362 | } |
| 2363 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2364 | TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2365 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2366 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2367 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2368 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2369 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2370 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2371 | root->SetBounds(gfx::Size(100, 100)); |
| 2372 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2373 | parent->SetBounds(gfx::Size(400, 400)); |
| 2374 | parent->SetMasksToBounds(true); |
| 2375 | child->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2376 | child->SetBounds(gfx::Size(800, 800)); |
| 2377 | child->SetMasksToBounds(true); |
| 2378 | child->test_properties()->force_render_surface = true; |
| 2379 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2380 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2381 | grand_child->test_properties()->force_render_surface = true; |
| 2382 | leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2383 | leaf_node->SetBounds(gfx::Size(2000, 2000)); |
| 2384 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2385 | root->SetDrawsContent(true); |
| 2386 | parent->SetDrawsContent(true); |
| 2387 | child->SetDrawsContent(true); |
| 2388 | grand_child->SetDrawsContent(true); |
| 2389 | leaf_node->SetDrawsContent(true); |
| 2390 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2391 | host_impl()->set_resourceless_software_draw_for_testing(); |
| 2392 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2393 | gfx::PointF test_point(90.f, 90.f); |
| 2394 | LayerImpl* result_layer = |
| 2395 | root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point); |
| 2396 | ASSERT_TRUE(result_layer); |
| 2397 | EXPECT_EQ(leaf_node, result_layer); |
| 2398 | } |
| 2399 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2400 | TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { |
| 2401 | // Tests that draw properties are computed correctly when we disable and then |
| 2402 | // re-enable separate surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2403 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2404 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2405 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2406 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2407 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2408 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2409 | root->SetBounds(gfx::Size(100, 100)); |
| 2410 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2411 | parent->SetBounds(gfx::Size(400, 400)); |
| 2412 | parent->SetMasksToBounds(true); |
| 2413 | child->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2414 | child->SetBounds(gfx::Size(800, 800)); |
| 2415 | child->SetMasksToBounds(true); |
| 2416 | child->test_properties()->force_render_surface = true; |
| 2417 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2418 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2419 | grand_child->test_properties()->force_render_surface = true; |
| 2420 | leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2421 | leaf_node->SetBounds(gfx::Size(2000, 2000)); |
| 2422 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2423 | root->SetDrawsContent(true); |
| 2424 | parent->SetDrawsContent(true); |
| 2425 | child->SetDrawsContent(true); |
| 2426 | grand_child->SetDrawsContent(true); |
| 2427 | leaf_node->SetDrawsContent(true); |
| 2428 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2429 | gfx::Transform expected_leaf_draw_transform_with_surfaces; |
| 2430 | expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); |
| 2431 | |
| 2432 | gfx::Transform expected_leaf_draw_transform_without_surfaces; |
| 2433 | expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); |
| 2434 | |
| 2435 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2436 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2437 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2438 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2439 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, |
| 2440 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2441 | |
| 2442 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2443 | EXPECT_TRUE(leaf_node->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2444 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); |
| 2445 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2446 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces, |
| 2447 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2448 | |
| 2449 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2450 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2451 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2452 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2453 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, |
| 2454 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2455 | } |
| 2456 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2457 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2458 | LayerImpl* root = root_layer_for_testing(); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2459 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 2460 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
| 2461 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 2462 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 2463 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
| 2464 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 2465 | LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
| 2466 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2467 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2468 | root->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2469 | render_surface1->SetDrawsContent(true); |
| 2470 | child_of_rs1->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2471 | grand_child_of_rs1->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2472 | render_surface2->SetDrawsContent(true); |
| 2473 | child_of_rs2->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2474 | grand_child_of_rs2->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2475 | child_of_root->SetDrawsContent(true); |
| 2476 | grand_child_of_root->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2477 | |
| 2478 | gfx::Transform layer_transform; |
| 2479 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2480 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2481 | root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2482 | root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2483 | root->SetBounds(gfx::Size(10, 10)); |
| 2484 | root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2485 | render_surface1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2486 | render_surface1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2487 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 2488 | render_surface1->test_properties()->transform_origin = |
| 2489 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2490 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2491 | render_surface2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2492 | render_surface2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2493 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 2494 | render_surface2->test_properties()->transform_origin = |
| 2495 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2496 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2497 | child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2498 | child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2499 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2500 | child_of_root->test_properties()->transform_origin = |
| 2501 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2502 | child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2503 | child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2504 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2505 | child_of_rs1->test_properties()->transform_origin = |
| 2506 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2507 | child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2508 | child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2509 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2510 | child_of_rs2->test_properties()->transform_origin = |
| 2511 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2512 | grand_child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2513 | grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2514 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2515 | grand_child_of_root->test_properties()->transform_origin = |
| 2516 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2517 | grand_child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2518 | grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2519 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2520 | grand_child_of_rs1->test_properties()->transform_origin = |
| 2521 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2522 | grand_child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2523 | grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2524 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2525 | grand_child_of_rs2->test_properties()->transform_origin = |
| 2526 | gfx::Point3F(0.25f, 0.f, 0.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2527 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2528 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2529 | SetElementIdsForTesting(); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 2530 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2531 | // Put an animated opacity on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2532 | AddOpacityTransitionToElementWithPlayer( |
| 2533 | render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2534 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2535 | // Also put an animated opacity on a layer without descendants. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2536 | AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(), |
| 2537 | timeline_impl(), 10.0, 1.f, 0.f, |
| 2538 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2539 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2540 | // Put a transform animation on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2541 | AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(), |
| 2542 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2543 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2544 | // Also put transform animations on grand_child_of_root, and |
| 2545 | // grand_child_of_rs2 |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2546 | AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(), |
| 2547 | timeline_impl(), 10.0, 30, 0); |
| 2548 | AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(), |
| 2549 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2550 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2551 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 2552 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2553 | |
| 2554 | // Only layers that are associated with render surfaces should have an actual |
| 2555 | // RenderSurface() value. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2556 | ASSERT_TRUE(root->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2557 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2558 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2559 | |
| 2560 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2561 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2562 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2563 | |
| 2564 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2565 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2566 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2567 | |
| 2568 | // Verify all render target accessors |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2569 | EXPECT_EQ(root->render_surface(), root->render_target()); |
| 2570 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 2571 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2572 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2573 | EXPECT_EQ(render_surface1->render_surface(), |
| 2574 | render_surface1->render_target()); |
| 2575 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 2576 | EXPECT_EQ(render_surface1->render_surface(), |
| 2577 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2578 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2579 | EXPECT_EQ(render_surface2->render_surface(), |
| 2580 | render_surface2->render_target()); |
| 2581 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 2582 | EXPECT_EQ(render_surface2->render_surface(), |
| 2583 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2584 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2585 | // Verify screen_space_transform_is_animating values |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2586 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2587 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2588 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2589 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2590 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2591 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2592 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2593 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2594 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2595 | |
| 2596 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2597 | // It is expected that we correctly set up transforms so that the y-component |
| 2598 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2599 | EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2600 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2601 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2602 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2603 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2604 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2605 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2606 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2607 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2608 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2609 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2610 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2611 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2612 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2613 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2614 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2615 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2616 | } |
| 2617 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2618 | TEST_F(LayerTreeHostCommonTest, LargeTransforms) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2619 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2620 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2621 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2622 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2623 | gfx::Transform large_transform; |
| 2624 | large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); |
| 2625 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2626 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2627 | child->test_properties()->transform = large_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2628 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2629 | grand_child->test_properties()->transform = large_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2630 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2631 | grand_child->SetDrawsContent(true); |
| 2632 | ExecuteCalculateDrawProperties(root); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2633 | |
| 2634 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
| 2635 | } |
| 2636 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2637 | TEST_F(LayerTreeHostCommonTest, |
| 2638 | ScreenSpaceTransformIsAnimatingWithDelayedAnimation) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2639 | LayerImpl* root = root_layer_for_testing(); |
| 2640 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2641 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2642 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 2643 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2644 | root->SetDrawsContent(true); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2645 | child->SetDrawsContent(true); |
| 2646 | grand_child->SetDrawsContent(true); |
| 2647 | great_grand_child->SetDrawsContent(true); |
| 2648 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2649 | root->SetBounds(gfx::Size(10, 10)); |
| 2650 | child->SetBounds(gfx::Size(10, 10)); |
| 2651 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2652 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2653 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2654 | SetElementIdsForTesting(); |
| 2655 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2656 | // Add a transform animation with a start delay to |grand_child|. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2657 | std::unique_ptr<Animation> animation = Animation::Create( |
| 2658 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1, |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 2659 | TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 2660 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2661 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2662 | AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(), |
| 2663 | std::move(animation)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2664 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2665 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2666 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2667 | EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 2668 | |
| 2669 | EXPECT_FALSE(grand_child->TransformIsAnimating()); |
| 2670 | EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation()); |
| 2671 | EXPECT_TRUE(grand_child->screen_space_transform_is_animating()); |
| 2672 | EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating()); |
| 2673 | } |
| 2674 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2675 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) { |
| 2676 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2677 | // correctly for identity transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2678 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2679 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2680 | gfx::Transform layer_to_surface_transform; |
| 2681 | |
| 2682 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2683 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2684 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2685 | gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30); |
| 2686 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2687 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2688 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2689 | EXPECT_EQ(expected_drawable_content_rect, |
| 2690 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2691 | |
| 2692 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2693 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2694 | expected_visible_layer_rect = gfx::Rect(); |
| 2695 | expected_drawable_content_rect = gfx::Rect(); |
| 2696 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2697 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2698 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2699 | EXPECT_EQ(expected_drawable_content_rect, |
| 2700 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2701 | |
| 2702 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2703 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2704 | expected_visible_layer_rect = gfx::Rect(20, 20); |
| 2705 | expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20); |
| 2706 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2707 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2708 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2709 | EXPECT_EQ(expected_drawable_content_rect, |
| 2710 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2711 | } |
| 2712 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2713 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) { |
| 2714 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2715 | // for rotations about z-axis (i.e. 2D rotations). |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2716 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2717 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2718 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2719 | gfx::Transform layer_to_surface_transform; |
| 2720 | |
| 2721 | // Case 1: Layer is contained within the surface. |
| 2722 | layer_to_surface_transform.MakeIdentity(); |
| 2723 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2724 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2725 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2726 | gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43); |
| 2727 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2728 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2729 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2730 | EXPECT_EQ(expected_drawable_content_rect, |
| 2731 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2732 | |
| 2733 | // Case 2: Layer is outside the surface rect. |
| 2734 | layer_to_surface_transform.MakeIdentity(); |
| 2735 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2736 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2737 | expected_visible_layer_rect = gfx::Rect(); |
| 2738 | expected_drawable_content_rect = gfx::Rect(); |
| 2739 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2740 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2741 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2742 | EXPECT_EQ(expected_drawable_content_rect, |
| 2743 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2744 | |
| 2745 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2746 | // the layer is oriented diagonally, with the left half outside of the render |
| 2747 | // surface. In this case, the g should still be the entire layer |
| 2748 | // (remember the g is computed in layer space); both the top-left |
| 2749 | // and bottom-right corners of the layer are still visible. |
| 2750 | layer_to_surface_transform.MakeIdentity(); |
| 2751 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2752 | expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2753 | expected_drawable_content_rect = gfx::Rect(22, 43); |
| 2754 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2755 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2756 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2757 | EXPECT_EQ(expected_drawable_content_rect, |
| 2758 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2759 | |
| 2760 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2761 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2762 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2763 | // surface overlaps the right side of the layer. The g should be |
| 2764 | // the layer's right half. |
| 2765 | layer_to_surface_transform.MakeIdentity(); |
| 2766 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2767 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2768 | // Right half of layer bounds. |
| 2769 | expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30); |
| 2770 | expected_drawable_content_rect = gfx::Rect(22, 22); |
| 2771 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2772 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2773 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2774 | EXPECT_EQ(expected_drawable_content_rect, |
| 2775 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2776 | } |
| 2777 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2778 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) { |
| 2779 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2780 | // for 3d transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2781 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2782 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2783 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2784 | gfx::Transform layer_to_surface_transform; |
| 2785 | |
| 2786 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2787 | // degrees, should be fully contained in the render surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2788 | // 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] | 2789 | layer_to_surface_transform.MakeIdentity(); |
| 2790 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2791 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2792 | gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100); |
| 2793 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2794 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2795 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2796 | EXPECT_EQ(expected_drawable_content_rect, |
| 2797 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2798 | |
| 2799 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2800 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2801 | // visible on the surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2802 | // 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] | 2803 | SkMScalar half_width_of_rotated_layer = |
| 2804 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2805 | layer_to_surface_transform.MakeIdentity(); |
| 2806 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2807 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2808 | // edge of the layer. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2809 | // Tight half of the layer. |
| 2810 | expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100); |
| 2811 | expected_drawable_content_rect = gfx::Rect(36, 100); |
| 2812 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2813 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2814 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2815 | EXPECT_EQ(expected_drawable_content_rect, |
| 2816 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2817 | } |
| 2818 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2819 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) { |
| 2820 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2821 | // when the layer has a perspective projection onto the target surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2822 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2823 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2824 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2825 | gfx::Transform layer_to_surface_transform; |
| 2826 | |
| 2827 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2828 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2829 | // its translated more than the perspective amount. |
| 2830 | layer_to_surface_transform.MakeIdentity(); |
| 2831 | |
| 2832 | // The following sequence of transforms applies the perspective about the |
| 2833 | // center of the surface. |
| 2834 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2835 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2836 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2837 | |
| 2838 | // This translate places the layer in front of the surface's projection plane. |
| 2839 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2840 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2841 | // Layer position is (-50, -50), visible rect in layer space is layer bounds |
| 2842 | // offset by layer position. |
| 2843 | gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150); |
| 2844 | gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38); |
| 2845 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2846 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2847 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2848 | EXPECT_EQ(expected_drawable_content_rect, |
| 2849 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2850 | |
| 2851 | // Case 2: same projection as before, except that the layer is also translated |
| 2852 | // to the side, so that only the right half of the layer should be visible. |
| 2853 | // |
| 2854 | // Explanation of expected result: The perspective ratio is (z distance |
| 2855 | // between layer and camera origin) / (z distance between projection plane and |
| 2856 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2857 | // move a layer by translating -25 units in projected surface units (so that |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2858 | // 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] | 2859 | // -25 == -100 in the layer's units. |
| 2860 | layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0); |
| 2861 | // Visible layer rect is moved by 100, and drawable content rect is in target |
| 2862 | // space and is moved by 25. |
| 2863 | expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150); |
| 2864 | expected_drawable_content_rect = gfx::Rect(13, 38); |
| 2865 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2866 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2867 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2868 | EXPECT_EQ(expected_drawable_content_rect, |
| 2869 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2870 | } |
| 2871 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2872 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2873 | DrawRectsFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2874 | // There is currently no explicit concept of an orthographic projection plane |
| 2875 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2876 | // are technically behind the surface in an orthographic world should not be |
| 2877 | // clipped when they are flattened to the surface. |
| 2878 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2879 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2880 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2881 | gfx::Transform layer_to_surface_transform; |
| 2882 | |
| 2883 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2884 | // at the center of the layer. |
| 2885 | layer_to_surface_transform.MakeIdentity(); |
| 2886 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2887 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2888 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2889 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2890 | // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface |
| 2891 | // space. |
| 2892 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2893 | gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100); |
| 2894 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2895 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2896 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2897 | EXPECT_EQ(expected_drawable_content_rect, |
| 2898 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2899 | } |
| 2900 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2901 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2902 | DrawRectsFor3dPerspectiveWhenClippedByW) { |
| 2903 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2904 | // when projecting a surface onto a layer, but the layer is partially behind |
| 2905 | // the camera (not just behind the projection plane). In this case, the |
| 2906 | // cartesian coordinates may seem to be valid, but actually they are not. The |
| 2907 | // visible rect needs to be properly clipped by the w = 0 plane in homogeneous |
| 2908 | // coordinates before converting to cartesian coordinates. The drawable |
| 2909 | // content rect would be entire surface rect because layer is rotated at the |
| 2910 | // camera position. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2911 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2912 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200); |
| 2913 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2914 | gfx::Transform layer_to_surface_transform; |
| 2915 | |
| 2916 | // The layer is positioned so that the right half of the layer should be in |
| 2917 | // front of the camera, while the other half is behind the surface's |
| 2918 | // projection plane. The following sequence of transforms applies the |
| 2919 | // perspective and rotation about the center of the layer. |
| 2920 | layer_to_surface_transform.MakeIdentity(); |
| 2921 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2922 | layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0); |
| 2923 | layer_to_surface_transform.RotateAboutYAxis(-45.0); |
| 2924 | layer_to_surface_transform.Translate(-10, -1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2925 | |
| 2926 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2927 | // transform, otherwise this code is not testing the intended scenario. |
| 2928 | bool clipped; |
| 2929 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2930 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2931 | &clipped); |
| 2932 | ASSERT_TRUE(clipped); |
| 2933 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2934 | gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1); |
| 2935 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 2936 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2937 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2938 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2939 | EXPECT_EQ(expected_drawable_content_rect, |
| 2940 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2941 | } |
| 2942 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2943 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2944 | // To determine visible rect in layer space, there needs to be an |
| 2945 | // un-projection from surface space to layer space. When the original |
| 2946 | // transform was a perspective projection that was clipped, it returns a rect |
| 2947 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2948 | // clipping again. |
| 2949 | |
| 2950 | // This sequence of transforms causes one corner of the layer to protrude |
| 2951 | // across the w = 0 plane, and should be clipped. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2952 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150); |
| 2953 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2954 | gfx::Transform layer_to_surface_transform; |
| 2955 | layer_to_surface_transform.MakeIdentity(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2956 | layer_to_surface_transform.Translate(10, 10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2957 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2958 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2959 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2960 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2961 | layer_to_surface_transform.Translate(-10, -10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2962 | |
| 2963 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2964 | // code is not testing the intended scenario. |
| 2965 | bool clipped; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2966 | gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
| 2967 | layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2968 | MathUtil::ProjectQuad( |
| 2969 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2970 | ASSERT_TRUE(clipped); |
| 2971 | |
| 2972 | // Only the corner of the layer is not visible on the surface because of being |
| 2973 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2974 | // rect is that the entire layer should still be considered visible. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2975 | gfx::Rect expected_visible_layer_rect = layer_content_rect; |
| 2976 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 2977 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2978 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2979 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2980 | EXPECT_EQ(expected_drawable_content_rect, |
| 2981 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2982 | } |
| 2983 | |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2984 | TEST_F(LayerTreeHostCommonTest, |
| 2985 | VisibleRectsForPositionedRootLayerClippedByViewport) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2986 | LayerImpl* root = root_layer_for_testing(); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2987 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2988 | root->SetPosition(gfx::PointF(60, 70)); |
| 2989 | root->SetBounds(gfx::Size(100, 100)); |
| 2990 | root->SetDrawsContent(true); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 2991 | ExecuteCalculateDrawProperties(root); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2992 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2993 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2994 | root->render_surface()->DrawableContentRect()); |
| 2995 | // In target space, not clipped. |
| 2996 | EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 2997 | // In layer space, clipped. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2998 | EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2999 | } |
| 3000 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3001 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3002 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3003 | LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3004 | LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3005 | LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3006 | |
| 3007 | root->SetBounds(gfx::Size(100, 100)); |
| 3008 | child1_layer->SetBounds(gfx::Size(50, 50)); |
| 3009 | child1_layer->SetDrawsContent(true); |
| 3010 | child2_layer->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3011 | child2_layer->SetBounds(gfx::Size(50, 50)); |
| 3012 | child2_layer->SetDrawsContent(true); |
| 3013 | child3_layer->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3014 | child3_layer->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3015 | child3_layer->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3016 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3017 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3018 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3019 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3020 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3021 | // Layers that do not draw content should have empty visible_layer_rects. |
| 3022 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3023 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3024 | // layer visible_layer_rects are clipped by their target surface. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3025 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); |
| 3026 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); |
| 3027 | EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3028 | |
| 3029 | // layer drawable_content_rects are not clipped. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3030 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect()); |
| 3031 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect()); |
| 3032 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3033 | } |
| 3034 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3035 | TEST_F(LayerTreeHostCommonTest, |
| 3036 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3037 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3038 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3039 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3040 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3041 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3042 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3043 | root->SetBounds(gfx::Size(100, 100)); |
| 3044 | child->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3045 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3046 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3047 | grand_child1->SetBounds(gfx::Size(50, 50)); |
| 3048 | grand_child1->SetDrawsContent(true); |
| 3049 | grand_child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3050 | grand_child2->SetBounds(gfx::Size(50, 50)); |
| 3051 | grand_child2->SetDrawsContent(true); |
| 3052 | grand_child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3053 | grand_child3->SetBounds(gfx::Size(50, 50)); |
| 3054 | grand_child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3055 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3056 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3057 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3058 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3059 | |
| 3060 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3061 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3062 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3063 | |
| 3064 | // All grandchild visible content rects should be clipped by child. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3065 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); |
| 3066 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); |
| 3067 | EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3068 | |
| 3069 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3070 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 3071 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3072 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 3073 | } |
| 3074 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3075 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3076 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3077 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 3078 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3079 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3080 | gfx::Transform child_scale_matrix; |
| 3081 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 3082 | gfx::Transform grand_child_scale_matrix; |
| 3083 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3084 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3085 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3086 | child->test_properties()->transform = child_scale_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3087 | child->SetBounds(gfx::Size(10, 10)); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3088 | child->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3089 | grand_child->test_properties()->transform = grand_child_scale_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3090 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3091 | grand_child->SetDrawsContent(true); |
| 3092 | ExecuteCalculateDrawProperties(root); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3093 | |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 3094 | // The visible rect is expanded to integer coordinates. |
| 3095 | EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3096 | } |
| 3097 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3098 | TEST_F(LayerTreeHostCommonTest, |
| 3099 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3100 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3101 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3102 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3103 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3104 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3105 | |
| 3106 | root->SetBounds(gfx::Size(100, 100)); |
| 3107 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3108 | render_surface->test_properties()->force_render_surface = true; |
| 3109 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3110 | child1->SetBounds(gfx::Size(50, 50)); |
| 3111 | child1->SetDrawsContent(true); |
| 3112 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3113 | child2->SetBounds(gfx::Size(50, 50)); |
| 3114 | child2->SetDrawsContent(true); |
| 3115 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3116 | child3->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3117 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3118 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3119 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3120 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3121 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3122 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3123 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3124 | |
| 3125 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3126 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3127 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3128 | |
| 3129 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 3130 | // regions of the subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3131 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3132 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3133 | |
| 3134 | // All layers that draw content into the unclipped surface are also unclipped. |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3135 | // Only the viewport clip should apply |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3136 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3137 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3138 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3139 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3140 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3141 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3142 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3143 | } |
| 3144 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3145 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3146 | DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3147 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3148 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 3149 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 3150 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 3151 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); |
| 3152 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); |
| 3153 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 3154 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 3155 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3156 | root->SetBounds(gfx::Size(100, 100)); |
| 3157 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 3158 | parent->SetBounds(gfx::Size(400, 400)); |
| 3159 | child1->SetPosition(gfx::PointF(4.f, 4.f)); |
| 3160 | child1->SetBounds(gfx::Size(800, 800)); |
| 3161 | child1->test_properties()->force_render_surface = true; |
| 3162 | child2->SetPosition(gfx::PointF(3.f, 3.f)); |
| 3163 | child2->SetBounds(gfx::Size(800, 800)); |
| 3164 | child2->test_properties()->force_render_surface = true; |
| 3165 | grand_child1->SetPosition(gfx::PointF(8.f, 8.f)); |
| 3166 | grand_child1->SetBounds(gfx::Size(1500, 1500)); |
| 3167 | grand_child2->SetPosition(gfx::PointF(7.f, 7.f)); |
| 3168 | grand_child2->SetBounds(gfx::Size(1500, 1500)); |
| 3169 | leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); |
| 3170 | leaf_node1->SetBounds(gfx::Size(2000, 2000)); |
| 3171 | leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); |
| 3172 | leaf_node2->SetBounds(gfx::Size(2000, 2000)); |
| 3173 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3174 | root->SetDrawsContent(true); |
| 3175 | parent->SetDrawsContent(true); |
| 3176 | child1->SetDrawsContent(true); |
| 3177 | child2->SetDrawsContent(true); |
| 3178 | grand_child1->SetDrawsContent(true); |
| 3179 | grand_child2->SetDrawsContent(true); |
| 3180 | leaf_node1->SetDrawsContent(true); |
| 3181 | leaf_node2->SetDrawsContent(true); |
| 3182 | |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3183 | // Case 1: No layers clip. Visible rects are clipped by the viewport. |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3184 | // Each layer's drawable content rect is its bounds in target space; the only |
| 3185 | // thing that changes with surfaces disabled is that target space is always |
| 3186 | // screen space. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3187 | root->SetHasRenderSurface(true); |
| 3188 | child1->SetHasRenderSurface(true); |
| 3189 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3190 | ExecuteCalculateDrawProperties(root); |
| 3191 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3192 | EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3193 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3194 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3195 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3196 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3197 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3198 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3199 | |
| 3200 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3201 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3202 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3203 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3204 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3205 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3206 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3207 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3208 | |
| 3209 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3210 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3211 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3212 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3213 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3214 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3215 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3216 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3217 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3218 | |
| 3219 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3220 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3221 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3222 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3223 | EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), |
| 3224 | grand_child1->drawable_content_rect()); |
| 3225 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3226 | grand_child2->drawable_content_rect()); |
| 3227 | EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3228 | EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3229 | |
| 3230 | // Case 2: The parent clips. In this case, neither surface is unclipped, so |
| 3231 | // all visible layer rects are clipped by the intersection of all ancestor |
| 3232 | // clips, whether or not surfaces are disabled. However, drawable content |
| 3233 | // rects are clipped only until the next render surface is reached, so |
| 3234 | // descendants of parent have their drawable content rects clipped only when |
| 3235 | // surfaces are disabled. |
| 3236 | parent->SetMasksToBounds(true); |
| 3237 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3238 | ExecuteCalculateDrawProperties(root); |
| 3239 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3240 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3241 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3242 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3243 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3244 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3245 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3246 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3247 | |
| 3248 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3249 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3250 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3251 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3252 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3253 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3254 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3255 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3256 | |
| 3257 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3258 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3259 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3260 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3261 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3262 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3263 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3264 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3265 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3266 | |
| 3267 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3268 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3269 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect()); |
| 3270 | EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect()); |
| 3271 | EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect()); |
| 3272 | EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect()); |
| 3273 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect()); |
| 3274 | EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect()); |
| 3275 | |
| 3276 | parent->SetMasksToBounds(false); |
| 3277 | |
| 3278 | // Case 3: child1 and grand_child2 clip. In this case, descendants of these |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3279 | // layers have their visible rects clipped by them; Similarly, descendants of |
| 3280 | // these layers have their drawable content rects clipped by them. |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3281 | child1->SetMasksToBounds(true); |
| 3282 | grand_child2->SetMasksToBounds(true); |
| 3283 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3284 | ExecuteCalculateDrawProperties(root); |
| 3285 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3286 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3287 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3288 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3289 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3290 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3291 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3292 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3293 | |
| 3294 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3295 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3296 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3297 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3298 | EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect()); |
| 3299 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3300 | EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect()); |
| 3301 | EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3302 | |
| 3303 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3304 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3305 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3306 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3307 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3308 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3309 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3310 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3311 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3312 | |
| 3313 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3314 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3315 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3316 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3317 | EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect()); |
| 3318 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3319 | grand_child2->drawable_content_rect()); |
| 3320 | EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); |
| 3321 | EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3322 | } |
| 3323 | |
| 3324 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3325 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3326 | LayerImpl* root = root_layer_for_testing(); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3327 | LayerImpl* child1 = AddChild<LayerImpl>(root); |
| 3328 | LayerImpl* child2 = AddChild<LayerImpl>(root); |
| 3329 | LayerImpl* child3 = AddChild<LayerImpl>(root); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3330 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3331 | root->SetBounds(gfx::Size(100, 100)); |
| 3332 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3333 | child1->SetBounds(gfx::Size(50, 50)); |
| 3334 | child1->SetDrawsContent(true); |
| 3335 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3336 | child2->SetBounds(gfx::Size(50, 50)); |
| 3337 | child2->SetDrawsContent(true); |
| 3338 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3339 | child3->SetBounds(gfx::Size(50, 50)); |
| 3340 | child3->SetDrawsContent(true); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3341 | |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3342 | LayerImplList render_surface_layer_list_impl; |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3343 | // Now set the root render surface an empty clip. |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3344 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 3345 | root, gfx::Size(), &render_surface_layer_list_impl); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3346 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 3347 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3348 | ASSERT_TRUE(root->render_surface()); |
| 3349 | EXPECT_FALSE(root->is_clipped()); |
| 3350 | |
| 3351 | gfx::Rect empty; |
| 3352 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 3353 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 3354 | |
| 3355 | // Visible content rect calculation will check if the target surface is |
| 3356 | // clipped or not. An empty clip rect does not indicate the render surface |
| 3357 | // is unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3358 | EXPECT_EQ(empty, child1->visible_layer_rect()); |
| 3359 | EXPECT_EQ(empty, child2->visible_layer_rect()); |
| 3360 | EXPECT_EQ(empty, child3->visible_layer_rect()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3364 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3365 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3366 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3367 | |
| 3368 | root->SetBounds(gfx::Size(100, 100)); |
| 3369 | child->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3370 | child->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3371 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3372 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3373 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3374 | 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] | 3375 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3376 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3377 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3378 | ExecuteCalculateDrawProperties(root); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3379 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3380 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3381 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3382 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3383 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 3384 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3385 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3386 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3387 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3388 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3389 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3390 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3391 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3392 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3393 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3394 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3395 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3396 | uninvertible_matrix.MakeIdentity(); |
| 3397 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3398 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3399 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3400 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3401 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3402 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3403 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3404 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3405 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3406 | } |
| 3407 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3408 | TEST_F(LayerTreeHostCommonTest, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3409 | VisibleContentRectForLayerWithUninvertibleDrawTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3410 | LayerImpl* root = root_layer_for_testing(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3411 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3412 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3413 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3414 | gfx::Transform perspective; |
| 3415 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3416 | |
| 3417 | gfx::Transform rotation; |
| 3418 | rotation.RotateAboutYAxis(45.0); |
| 3419 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3420 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3421 | child->test_properties()->transform = perspective; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3422 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 3423 | child->SetBounds(gfx::Size(100, 100)); |
| 3424 | child->SetDrawsContent(true); |
| 3425 | child->Set3dSortingContextId(1); |
| 3426 | child->test_properties()->should_flatten_transform = false; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3427 | grand_child->test_properties()->transform = rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3428 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 3429 | grand_child->SetDrawsContent(true); |
| 3430 | grand_child->Set3dSortingContextId(1); |
| 3431 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3432 | ExecuteCalculateDrawProperties(root); |
| 3433 | |
| 3434 | // Though all layers have invertible transforms, matrix multiplication using |
| 3435 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3436 | EXPECT_FALSE(root->layer_tree_impl() |
| 3437 | ->property_trees() |
| 3438 | ->transform_tree.Node(grand_child->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3439 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3440 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3441 | // CalcDrawProps skips a subtree when a layer's screen space transform is |
| 3442 | // uninvertible |
| 3443 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3444 | } |
| 3445 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3446 | TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) { |
| 3447 | FakeImplTaskRunnerProvider task_runner_provider; |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3448 | TestTaskGraphRunner task_graph_runner; |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3449 | std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 3450 | FakeCompositorFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 3451 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3452 | |
| 3453 | std::unique_ptr<LayerImpl> root = |
| 3454 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3455 | std::unique_ptr<LayerImpl> child = |
| 3456 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3457 | std::unique_ptr<TextureLayerImpl> surface = |
| 3458 | TextureLayerImpl::Create(host_impl.active_tree(), 3); |
| 3459 | std::unique_ptr<TextureLayerImpl> surface_child = |
| 3460 | TextureLayerImpl::Create(host_impl.active_tree(), 4); |
| 3461 | std::unique_ptr<TextureLayerImpl> surface_sibling = |
| 3462 | TextureLayerImpl::Create(host_impl.active_tree(), 5); |
| 3463 | std::unique_ptr<TextureLayerImpl> surface_child_mask = |
| 3464 | TextureLayerImpl::Create(host_impl.active_tree(), 6); |
| 3465 | |
| 3466 | surface->SetDrawsContent(true); |
| 3467 | surface_child->SetDrawsContent(true); |
| 3468 | surface_sibling->SetDrawsContent(true); |
| 3469 | surface_child_mask->SetDrawsContent(true); |
| 3470 | surface->SetContentsOpaque(true); |
| 3471 | surface_child->SetContentsOpaque(true); |
| 3472 | surface_sibling->SetContentsOpaque(true); |
| 3473 | surface_child_mask->SetContentsOpaque(true); |
| 3474 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3475 | gfx::Transform translate; |
| 3476 | translate.Translate(20.f, 20.f); |
| 3477 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3478 | root->SetBounds(gfx::Size(1000, 1000)); |
| 3479 | child->SetBounds(gfx::Size(300, 300)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3480 | surface->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3481 | surface->SetBounds(gfx::Size(300, 300)); |
| 3482 | surface->test_properties()->force_render_surface = true; |
| 3483 | surface_child->SetBounds(gfx::Size(300, 300)); |
| 3484 | surface_child->test_properties()->force_render_surface = true; |
| 3485 | surface_sibling->SetBounds(gfx::Size(200, 200)); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3486 | |
| 3487 | LayerImpl* surface_ptr = surface.get(); |
| 3488 | LayerImpl* surface_child_ptr = surface_child.get(); |
| 3489 | LayerImpl* surface_child_mask_ptr = surface_child_mask.get(); |
| 3490 | |
| 3491 | host_impl.SetViewportSize(root->bounds()); |
| 3492 | |
| 3493 | surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask)); |
| 3494 | surface->test_properties()->AddChild(std::move(surface_child)); |
| 3495 | child->test_properties()->AddChild(std::move(surface)); |
| 3496 | child->test_properties()->AddChild(std::move(surface_sibling)); |
| 3497 | root->test_properties()->AddChild(std::move(child)); |
| 3498 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 3499 | host_impl.SetVisible(true); |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3500 | host_impl.InitializeRenderer(compositor_frame_sink.get()); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3501 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 3502 | bool update_lcd_text = false; |
| 3503 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3504 | |
| 3505 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 3506 | surface_ptr->render_surface()->draw_transform(), translate); |
| 3507 | // surface_sibling draws into the root render surface and occludes |
| 3508 | // surface_child's contents. |
| 3509 | Occlusion actual_occlusion = |
| 3510 | surface_child_ptr->render_surface()->occlusion_in_content_space(); |
| 3511 | Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()), |
| 3512 | SimpleEnclosedRegion(gfx::Rect(200, 200))); |
| 3513 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3514 | |
| 3515 | // Mask layer should have the same occlusion. |
| 3516 | actual_occlusion = |
| 3517 | surface_child_mask_ptr->draw_properties().occlusion_in_content_space; |
| 3518 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3519 | } |
| 3520 | |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3521 | TEST_F(LayerTreeHostCommonTest, TextureLayerSnapping) { |
| 3522 | FakeImplTaskRunnerProvider task_runner_provider; |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3523 | TestTaskGraphRunner task_graph_runner; |
| 3524 | std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 3525 | FakeCompositorFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 3526 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 3527 | |
| 3528 | std::unique_ptr<LayerImpl> root = |
| 3529 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3530 | std::unique_ptr<TextureLayerImpl> child = |
| 3531 | TextureLayerImpl::Create(host_impl.active_tree(), 2); |
| 3532 | |
| 3533 | LayerImpl* child_ptr = child.get(); |
| 3534 | |
| 3535 | root->SetBounds(gfx::Size(100, 100)); |
| 3536 | child->SetBounds(gfx::Size(100, 100)); |
| 3537 | child->SetDrawsContent(true); |
| 3538 | gfx::Transform fractional_translate; |
| 3539 | fractional_translate.Translate(10.5f, 20.3f); |
| 3540 | child->test_properties()->transform = fractional_translate; |
| 3541 | |
| 3542 | host_impl.SetViewportSize(root->bounds()); |
| 3543 | |
| 3544 | root->test_properties()->AddChild(std::move(child)); |
| 3545 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 3546 | host_impl.SetVisible(true); |
| 3547 | host_impl.InitializeRenderer(compositor_frame_sink.get()); |
| 3548 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 3549 | bool update_lcd_text = false; |
| 3550 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3551 | |
| 3552 | EXPECT_NE(child_ptr->ScreenSpaceTransform(), fractional_translate); |
| 3553 | fractional_translate.RoundTranslationComponents(); |
| 3554 | EXPECT_TRANSFORMATION_MATRIX_EQ(child_ptr->ScreenSpaceTransform(), |
| 3555 | fractional_translate); |
| 3556 | gfx::RectF layer_bounds_in_screen_space = |
| 3557 | MathUtil::MapClippedRect(child_ptr->ScreenSpaceTransform(), |
| 3558 | gfx::RectF(gfx::SizeF(child_ptr->bounds()))); |
| 3559 | EXPECT_EQ(layer_bounds_in_screen_space, gfx::RectF(11.f, 20.f, 100.f, 100.f)); |
| 3560 | } |
| 3561 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3562 | TEST_F(LayerTreeHostCommonTest, |
| 3563 | OcclusionForLayerWithUninvertibleDrawTransform) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3564 | FakeImplTaskRunnerProvider task_runner_provider; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3565 | TestTaskGraphRunner task_graph_runner; |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3566 | std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 3567 | FakeCompositorFrameSink::Create3d(); |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 3568 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3569 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3570 | std::unique_ptr<LayerImpl> root = |
| 3571 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3572 | std::unique_ptr<LayerImpl> child = |
| 3573 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3574 | std::unique_ptr<LayerImpl> grand_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3575 | LayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3576 | std::unique_ptr<LayerImpl> occluding_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3577 | LayerImpl::Create(host_impl.active_tree(), 4); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3578 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3579 | gfx::Transform perspective; |
| 3580 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3581 | |
| 3582 | gfx::Transform rotation; |
| 3583 | rotation.RotateAboutYAxis(45.0); |
| 3584 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3585 | root->SetBounds(gfx::Size(1000, 1000)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3586 | child->test_properties()->transform = perspective; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3587 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 3588 | child->SetBounds(gfx::Size(300, 300)); |
| 3589 | child->test_properties()->should_flatten_transform = false; |
| 3590 | child->Set3dSortingContextId(1); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3591 | grand_child->test_properties()->transform = rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3592 | grand_child->SetBounds(gfx::Size(200, 200)); |
| 3593 | grand_child->test_properties()->should_flatten_transform = false; |
| 3594 | grand_child->Set3dSortingContextId(1); |
| 3595 | occluding_child->SetBounds(gfx::Size(200, 200)); |
| 3596 | occluding_child->test_properties()->should_flatten_transform = false; |
| 3597 | |
| 3598 | child->SetDrawsContent(true); |
| 3599 | grand_child->SetDrawsContent(true); |
| 3600 | occluding_child->SetDrawsContent(true); |
| 3601 | occluding_child->SetContentsOpaque(true); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3602 | |
| 3603 | host_impl.SetViewportSize(root->bounds()); |
| 3604 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3605 | child->test_properties()->AddChild(std::move(grand_child)); |
| 3606 | root->test_properties()->AddChild(std::move(child)); |
| 3607 | root->test_properties()->AddChild(std::move(occluding_child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3608 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 3609 | host_impl.SetVisible(true); |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3610 | host_impl.InitializeRenderer(compositor_frame_sink.get()); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 3611 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3612 | bool update_lcd_text = false; |
| 3613 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3614 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3615 | LayerImpl* grand_child_ptr = host_impl.active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3616 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3617 | ->test_properties() |
| 3618 | ->children[0] |
| 3619 | ->test_properties() |
| 3620 | ->children[0]; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3621 | |
| 3622 | // Though all layers have invertible transforms, matrix multiplication using |
| 3623 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3624 | EXPECT_FALSE( |
| 3625 | host_impl.active_tree() |
| 3626 | ->property_trees() |
| 3627 | ->transform_tree.Node(grand_child_ptr->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3628 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3629 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3630 | // Since |grand_child| has an uninvertible screen space transform, it is |
| 3631 | // skipped so |
| 3632 | // that we are not computing its occlusion_in_content_space. |
| 3633 | gfx::Rect layer_bounds = gfx::Rect(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3634 | EXPECT_EQ( |
| 3635 | layer_bounds, |
| 3636 | grand_child_ptr->draw_properties() |
| 3637 | .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds)); |
| 3638 | } |
| 3639 | |
| 3640 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3641 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3642 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3643 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3644 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3645 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3646 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3647 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3648 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3649 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3650 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3651 | render_surface->test_properties()->force_render_surface = true; |
| 3652 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3653 | child1->SetBounds(gfx::Size(50, 50)); |
| 3654 | child1->SetDrawsContent(true); |
| 3655 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3656 | child2->SetBounds(gfx::Size(50, 50)); |
| 3657 | child2->SetDrawsContent(true); |
| 3658 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3659 | child3->SetBounds(gfx::Size(50, 50)); |
| 3660 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3661 | ExecuteCalculateDrawProperties(root); |
| 3662 | |
| 3663 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3664 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3665 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3666 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3667 | |
| 3668 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3669 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3670 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3671 | |
| 3672 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3673 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3674 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3675 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3676 | |
| 3677 | // All layers that draw content into the surface have their visible content |
| 3678 | // rect clipped by the surface clip rect. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3679 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3680 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3681 | EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3682 | |
| 3683 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3684 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3685 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3686 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3687 | } |
| 3688 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3689 | TEST_F(LayerTreeHostCommonTest, |
| 3690 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3691 | // Check that clipping does not propagate down surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3692 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3693 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3694 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 3695 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3696 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3697 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3698 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3699 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3700 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3701 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 3702 | render_surface1->test_properties()->force_render_surface = true; |
| 3703 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 3704 | render_surface2->test_properties()->force_render_surface = true; |
| 3705 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3706 | child1->SetBounds(gfx::Size(50, 50)); |
| 3707 | child1->SetDrawsContent(true); |
| 3708 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3709 | child2->SetBounds(gfx::Size(50, 50)); |
| 3710 | child2->SetDrawsContent(true); |
| 3711 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3712 | child3->SetBounds(gfx::Size(50, 50)); |
| 3713 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3714 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3715 | |
| 3716 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3717 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3718 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3719 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3720 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3721 | |
| 3722 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3723 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3724 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); |
| 3725 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3726 | |
| 3727 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3728 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3729 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3730 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3731 | |
| 3732 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3733 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3734 | // render_surface2 grows to enclose all drawable content of its subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3735 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3736 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3737 | |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3738 | // All layers that draw content into render_surface2 think they are unclipped |
| 3739 | // by the surface. So, only the viewport clip applies. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3740 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3741 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3742 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3743 | |
| 3744 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3745 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3746 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3747 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3748 | } |
| 3749 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3750 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3751 | VisibleRectsForClippedDescendantsOfUnclippedSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3752 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3753 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3754 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 3755 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 3756 | LayerImpl* render_surface2 = AddChild<LayerImpl>(child2); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3757 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3758 | root->SetBounds(gfx::Size(100, 100)); |
| 3759 | render_surface1->SetBounds(gfx::Size(100, 100)); |
| 3760 | render_surface1->test_properties()->force_render_surface = true; |
| 3761 | child1->SetBounds(gfx::Size(500, 500)); |
| 3762 | child1->SetDrawsContent(true); |
| 3763 | child2->SetBounds(gfx::Size(700, 700)); |
| 3764 | child2->SetDrawsContent(true); |
| 3765 | render_surface2->SetBounds(gfx::Size(1000, 1000)); |
| 3766 | render_surface2->test_properties()->force_render_surface = true; |
| 3767 | render_surface2->SetDrawsContent(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3768 | |
| 3769 | child1->SetMasksToBounds(true); |
| 3770 | child2->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3771 | ExecuteCalculateDrawProperties(root); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3772 | EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3773 | EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3774 | } |
| 3775 | |
| 3776 | TEST_F(LayerTreeHostCommonTest, |
| 3777 | VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3778 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3779 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3780 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3781 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3782 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3783 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3784 | root->SetBounds(gfx::Size(100, 100)); |
| 3785 | |
| 3786 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3787 | clip_parent->SetMasksToBounds(true); |
| 3788 | clip_parent->test_properties()->clip_children = |
| 3789 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3790 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3791 | |
| 3792 | render_surface1->SetBounds(gfx::Size(20, 20)); |
| 3793 | render_surface1->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3794 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3795 | render_surface1->test_properties()->force_render_surface = true; |
| 3796 | |
| 3797 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3798 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3799 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3800 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3801 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 3802 | render_surface2->SetDrawsContent(true); |
| 3803 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3804 | |
| 3805 | ExecuteCalculateDrawProperties(root); |
| 3806 | EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect()); |
| 3807 | EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect()); |
| 3808 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect()); |
| 3809 | } |
| 3810 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3811 | TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3812 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3813 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3814 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3815 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3816 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3817 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3818 | root->SetBounds(gfx::Size(100, 100)); |
| 3819 | |
| 3820 | clip_parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 3821 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3822 | clip_parent->test_properties()->clip_children = |
| 3823 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3824 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3825 | |
| 3826 | render_surface1->SetBounds(gfx::Size(20, 20)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3827 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3828 | render_surface1->test_properties()->force_render_surface = true; |
| 3829 | |
| 3830 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3831 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3832 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3833 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3834 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 3835 | render_surface2->SetDrawsContent(true); |
| 3836 | render_surface2->test_properties()->force_render_surface = true; |
| 3837 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3838 | clip_parent->SetMasksToBounds(true); |
| 3839 | render_surface1->SetMasksToBounds(true); |
| 3840 | |
| 3841 | ExecuteCalculateDrawProperties(root); |
| 3842 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect()); |
| 3843 | } |
| 3844 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3845 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) { |
| 3846 | // Test that only drawn layers contribute to render surface content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3847 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3848 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 3849 | LayerImpl* test_layer = AddChild<LayerImpl>(surface); |
| 3850 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3851 | root->SetBounds(gfx::Size(200, 200)); |
| 3852 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3853 | surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3854 | surface->test_properties()->force_render_surface = true; |
| 3855 | test_layer->SetBounds(gfx::Size(150, 150)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3856 | |
| 3857 | ExecuteCalculateDrawProperties(root); |
| 3858 | EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect()); |
| 3859 | |
| 3860 | test_layer->SetDrawsContent(true); |
| 3861 | ExecuteCalculateDrawProperties(root); |
| 3862 | EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect()); |
| 3863 | } |
| 3864 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3865 | TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) { |
| 3866 | // Tests visible rects computation when we have unclipped_surface-> |
| 3867 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3868 | // of surface_with_unclipped_descendants doesn't propagate to the |
| 3869 | // clipped_surface below it. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3870 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3871 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3872 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3873 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3874 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3875 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3876 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3877 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3878 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3879 | unclipped_surface->SetBounds(gfx::Size(30, 30)); |
| 3880 | unclipped_surface->SetDrawsContent(true); |
| 3881 | unclipped_surface->test_properties()->force_render_surface = true; |
| 3882 | |
| 3883 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3884 | clip_parent->test_properties()->clip_children = |
| 3885 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3886 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3887 | |
| 3888 | unclipped_desc_surface->SetBounds(gfx::Size(20, 20)); |
| 3889 | unclipped_desc_surface->SetDrawsContent(true); |
| 3890 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 3891 | |
| 3892 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 3893 | clip_child->test_properties()->clip_parent = clip_parent; |
| 3894 | |
| 3895 | clipped_surface->SetBounds(gfx::Size(60, 60)); |
| 3896 | clipped_surface->SetDrawsContent(true); |
| 3897 | clipped_surface->test_properties()->force_render_surface = true; |
| 3898 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3899 | clip_parent->SetMasksToBounds(true); |
| 3900 | |
| 3901 | ExecuteCalculateDrawProperties(root); |
| 3902 | EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect()); |
| 3903 | EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect()); |
| 3904 | EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect()); |
| 3905 | } |
| 3906 | |
| 3907 | TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) { |
| 3908 | // Tests visible rects computation when we have unclipped_surface-> |
| 3909 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3910 | // of root propagate to the clipped_surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3911 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3912 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3913 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3914 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3915 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3916 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3917 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3918 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3919 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3920 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
| 3921 | unclipped_surface->SetDrawsContent(true); |
| 3922 | unclipped_surface->test_properties()->force_render_surface = true; |
| 3923 | |
| 3924 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3925 | clip_parent->test_properties()->clip_children = |
| 3926 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3927 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3928 | |
| 3929 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 3930 | unclipped_desc_surface->SetDrawsContent(true); |
| 3931 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 3932 | |
| 3933 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 3934 | clip_child->test_properties()->clip_parent = clip_parent; |
| 3935 | |
| 3936 | clipped_surface->SetBounds(gfx::Size(50, 50)); |
| 3937 | clipped_surface->SetDrawsContent(true); |
| 3938 | clipped_surface->test_properties()->force_render_surface = true; |
| 3939 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3940 | clip_parent->SetMasksToBounds(true); |
| 3941 | unclipped_desc_surface->SetMasksToBounds(true); |
| 3942 | |
| 3943 | ExecuteCalculateDrawProperties(root); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3944 | EXPECT_EQ(gfx::Rect(10, 10), unclipped_surface->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3945 | EXPECT_EQ(gfx::Rect(10, 10), unclipped_desc_surface->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3946 | EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect()); |
| 3947 | } |
| 3948 | |
| 3949 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3950 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3951 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3952 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3953 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3954 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3955 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3956 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3957 | gfx::Transform child_rotation; |
| 3958 | child_rotation.Rotate(45.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3959 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3960 | root->SetBounds(gfx::Size(100, 100)); |
| 3961 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3962 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3963 | child1->test_properties()->transform = child_rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3964 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 3965 | child1->SetBounds(gfx::Size(50, 50)); |
| 3966 | child1->SetDrawsContent(true); |
| 3967 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3968 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3969 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3970 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3971 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3972 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3973 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3974 | |
| 3975 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3976 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3977 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3978 | |
| 3979 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3980 | // regions of the subtree. |
| 3981 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3982 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3983 | gfx::Rect(50 - diagonal_radius, |
| 3984 | 50 - diagonal_radius, |
| 3985 | diagonal_radius * 2, |
| 3986 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3987 | EXPECT_EQ(gfx::RectF(expected_surface_drawable_content), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3988 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3989 | |
| 3990 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3991 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3992 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3993 | } |
| 3994 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3995 | TEST_F(LayerTreeHostCommonTest, |
| 3996 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3997 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3998 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3999 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4000 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 4001 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4002 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4003 | gfx::Transform child_rotation; |
| 4004 | child_rotation.Rotate(45.0); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4005 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4006 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4007 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4008 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 4009 | render_surface->test_properties()->force_render_surface = true; |
| 4010 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 4011 | child1->SetBounds(gfx::Size(50, 50)); |
| 4012 | child1->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4013 | child1->test_properties()->transform = child_rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4014 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4015 | ExecuteCalculateDrawProperties(root); |
| 4016 | |
| 4017 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4018 | |
| 4019 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 4020 | // rotated layer. |
| 4021 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4022 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 4023 | 50 - diagonal_radius, |
| 4024 | diagonal_radius * 2, |
| 4025 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4026 | gfx::RectF expected_surface_drawable_content( |
| 4027 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4028 | EXPECT_EQ(expected_surface_drawable_content, |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4029 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4030 | |
| 4031 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 4032 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 4033 | // up covering the full left half of child1. |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 4034 | EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4035 | |
| 4036 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4037 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4038 | } |
| 4039 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4040 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4041 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4042 | FakePictureLayerImpl* render_surface1 = |
| 4043 | AddChildToRoot<FakePictureLayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4044 | FakePictureLayerImpl* render_surface2 = |
| 4045 | AddChild<FakePictureLayerImpl>(render_surface1); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4046 | FakePictureLayerImpl* child1 = |
| 4047 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4048 | FakePictureLayerImpl* child2 = |
| 4049 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4050 | FakePictureLayerImpl* child3 = |
| 4051 | AddChild<FakePictureLayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4052 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4053 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4054 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4055 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 4056 | render_surface1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4057 | render_surface1->SetDrawsContent(true); |
| 4058 | render_surface1->test_properties()->force_render_surface = true; |
| 4059 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 4060 | render_surface2->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4061 | render_surface2->SetDrawsContent(true); |
| 4062 | render_surface2->test_properties()->force_render_surface = true; |
| 4063 | child1->SetBounds(gfx::Size(50, 50)); |
| 4064 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4065 | child1->SetDrawsContent(true); |
| 4066 | child2->SetBounds(gfx::Size(50, 50)); |
| 4067 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 4068 | child2->SetDrawsContent(true); |
| 4069 | child3->SetBounds(gfx::Size(50, 50)); |
| 4070 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 4071 | child3->SetDrawsContent(true); |
| 4072 | float device_scale_factor = 2.f; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4073 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4074 | |
| 4075 | ASSERT_TRUE(render_surface1->render_surface()); |
| 4076 | ASSERT_TRUE(render_surface2->render_surface()); |
| 4077 | |
| 4078 | // drawable_content_rects for all layers and surfaces are scaled by |
| 4079 | // device_scale_factor. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4080 | EXPECT_EQ(gfx::RectF(200.f, 200.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4081 | root->render_surface()->DrawableContentRect()); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4082 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4083 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4084 | |
| 4085 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 4086 | // is only implicitly clipped by render_surface1. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4087 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4088 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4089 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4090 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 4091 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 4092 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4093 | |
| 4094 | // The root layer does not actually draw content of its own. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4095 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4096 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4097 | // All layer visible content rects are not expressed in content space of each |
| 4098 | // layer, so they are not scaled by the device_scale_factor. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4099 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect()); |
| 4100 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect()); |
| 4101 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 4102 | EXPECT_EQ(gfx::Rect(0, 0, 15, 15), child2->visible_layer_rect()); |
| 4103 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4104 | } |
| 4105 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4106 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4107 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 4108 | // layers. Note that 3d transforms still apply in this case, but they are |
| 4109 | // "flattened" to each parent layer according to current W3C spec. |
| 4110 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4111 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4112 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4113 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4114 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4115 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4116 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4117 | AddChild<LayerImpl>(front_facing_surface); |
| 4118 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4119 | AddChild<LayerImpl>(front_facing_surface); |
| 4120 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4121 | AddChild<LayerImpl>(back_facing_surface); |
| 4122 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4123 | AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4124 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4125 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4126 | front_facing_child->test_properties()->double_sided = false; |
| 4127 | back_facing_child->test_properties()->double_sided = false; |
| 4128 | front_facing_surface->test_properties()->double_sided = false; |
| 4129 | back_facing_surface->test_properties()->double_sided = false; |
| 4130 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4131 | false; |
| 4132 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4133 | false; |
| 4134 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4135 | false; |
| 4136 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4137 | false; |
| 4138 | |
| 4139 | // Everything draws content. |
| 4140 | front_facing_child->SetDrawsContent(true); |
| 4141 | back_facing_child->SetDrawsContent(true); |
| 4142 | front_facing_surface->SetDrawsContent(true); |
| 4143 | back_facing_surface->SetDrawsContent(true); |
| 4144 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4145 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4146 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4147 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4148 | |
| 4149 | gfx::Transform backface_matrix; |
| 4150 | backface_matrix.Translate(50.0, 50.0); |
| 4151 | backface_matrix.RotateAboutYAxis(180.0); |
| 4152 | backface_matrix.Translate(-50.0, -50.0); |
| 4153 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4154 | root->SetBounds(gfx::Size(100, 100)); |
| 4155 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4156 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4157 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4158 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4159 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4160 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4161 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4162 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4163 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4164 | front_facing_surface->test_properties()->force_render_surface = true; |
| 4165 | back_facing_surface->test_properties()->force_render_surface = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4166 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4167 | back_facing_child->test_properties()->transform = backface_matrix; |
| 4168 | back_facing_surface->test_properties()->transform = backface_matrix; |
| 4169 | back_facing_child_of_front_facing_surface->test_properties()->transform = |
| 4170 | backface_matrix; |
| 4171 | back_facing_child_of_back_facing_surface->test_properties()->transform = |
| 4172 | backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4173 | |
| 4174 | // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms |
| 4175 | // spec, these layers should blindly use their own local transforms to |
| 4176 | // determine back-face culling. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4177 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4178 | |
| 4179 | // Verify which render surfaces were created. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4180 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4181 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4182 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
| 4183 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4184 | EXPECT_FALSE( |
| 4185 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4186 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4187 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4188 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4189 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4190 | EXPECT_EQ(4u, update_layer_list_impl()->size()); |
| 4191 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4192 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4193 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4194 | front_facing_child_of_front_facing_surface->id())); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4195 | EXPECT_TRUE(UpdateLayerListImplContains( |
| 4196 | front_facing_child_of_back_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4197 | } |
| 4198 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4199 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4200 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 4201 | // is used. |
| 4202 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4203 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4204 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4205 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4206 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4207 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4208 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4209 | AddChild<LayerImpl>(front_facing_surface); |
| 4210 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4211 | AddChild<LayerImpl>(front_facing_surface); |
| 4212 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4213 | AddChild<LayerImpl>(back_facing_surface); |
| 4214 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4215 | AddChild<LayerImpl>(back_facing_surface); |
| 4216 | // Opacity will not force creation of render surfaces in this case because of |
| 4217 | // the preserve-3d transform style. Instead, an example of when a surface |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4218 | // would be created with preserve-3d is when there is a mask layer. |
| 4219 | LayerImpl* dummy_mask_layer1 = AddMaskLayer<LayerImpl>(front_facing_surface); |
| 4220 | LayerImpl* dummy_mask_layer2 = AddMaskLayer<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4221 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4222 | // Nothing is double-sided |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4223 | front_facing_child->test_properties()->double_sided = false; |
| 4224 | back_facing_child->test_properties()->double_sided = false; |
| 4225 | front_facing_surface->test_properties()->double_sided = false; |
| 4226 | back_facing_surface->test_properties()->double_sided = false; |
| 4227 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4228 | false; |
| 4229 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4230 | false; |
| 4231 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4232 | false; |
| 4233 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4234 | false; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4235 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4236 | // Everything draws content. |
| 4237 | front_facing_child->SetDrawsContent(true); |
| 4238 | back_facing_child->SetDrawsContent(true); |
| 4239 | front_facing_surface->SetDrawsContent(true); |
| 4240 | back_facing_surface->SetDrawsContent(true); |
| 4241 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4242 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4243 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4244 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4245 | dummy_mask_layer1->SetDrawsContent(true); |
| 4246 | dummy_mask_layer2->SetDrawsContent(true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4247 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4248 | gfx::Transform backface_matrix; |
| 4249 | backface_matrix.Translate(50.0, 50.0); |
| 4250 | backface_matrix.RotateAboutYAxis(180.0); |
| 4251 | backface_matrix.Translate(-50.0, -50.0); |
| 4252 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4253 | root->SetBounds(gfx::Size(100, 100)); |
| 4254 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4255 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4256 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4257 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4258 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4259 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4260 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4261 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4262 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4263 | back_facing_child->test_properties()->transform = backface_matrix; |
| 4264 | back_facing_surface->test_properties()->transform = backface_matrix; |
| 4265 | back_facing_child_of_front_facing_surface->test_properties()->transform = |
| 4266 | backface_matrix; |
| 4267 | back_facing_child_of_back_facing_surface->test_properties()->transform = |
| 4268 | backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4269 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4270 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 4271 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 4272 | // rendering context should use the transform with respect to that context. |
| 4273 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 4274 | // and (b) the layer's transform style is preserve-3d. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4275 | front_facing_surface->test_properties()->should_flatten_transform = false; |
| 4276 | front_facing_surface->Set3dSortingContextId(1); |
| 4277 | back_facing_surface->test_properties()->should_flatten_transform = false; |
| 4278 | back_facing_surface->Set3dSortingContextId(1); |
| 4279 | front_facing_child_of_front_facing_surface->Set3dSortingContextId(1); |
| 4280 | back_facing_child_of_front_facing_surface->Set3dSortingContextId(1); |
| 4281 | front_facing_child_of_back_facing_surface->Set3dSortingContextId(1); |
| 4282 | back_facing_child_of_back_facing_surface->Set3dSortingContextId(1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4283 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4284 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4285 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4286 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4287 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4288 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4289 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4290 | // We expect that a has_render_surface was created but not used. |
| 4291 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4292 | EXPECT_FALSE( |
| 4293 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4294 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4295 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4296 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4297 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4298 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4299 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4300 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4301 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4302 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4303 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4304 | } |
| 4305 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4306 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4307 | // Verify that layers are appropriately culled when their back face is showing |
| 4308 | // and they are not double sided, while animations are going on. |
| 4309 | // |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4310 | // Even layers that are animating get culled if their back face is showing and |
| 4311 | // they are not double sided. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4312 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4313 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4314 | LayerImpl* animating_surface = AddChildToRoot<LayerImpl>(); |
| 4315 | LayerImpl* child_of_animating_surface = |
| 4316 | AddChild<LayerImpl>(animating_surface); |
| 4317 | LayerImpl* animating_child = AddChildToRoot<LayerImpl>(); |
| 4318 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4319 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4320 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4321 | child->test_properties()->double_sided = false; |
| 4322 | child2->test_properties()->double_sided = false; |
| 4323 | animating_surface->test_properties()->double_sided = false; |
| 4324 | child_of_animating_surface->test_properties()->double_sided = false; |
| 4325 | animating_child->test_properties()->double_sided = false; |
| 4326 | |
| 4327 | // Everything draws content. |
| 4328 | child->SetDrawsContent(true); |
| 4329 | child2->SetDrawsContent(true); |
| 4330 | animating_surface->SetDrawsContent(true); |
| 4331 | child_of_animating_surface->SetDrawsContent(true); |
| 4332 | animating_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4333 | |
| 4334 | gfx::Transform backface_matrix; |
| 4335 | backface_matrix.Translate(50.0, 50.0); |
| 4336 | backface_matrix.RotateAboutYAxis(180.0); |
| 4337 | backface_matrix.Translate(-50.0, -50.0); |
| 4338 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4339 | SetElementIdsForTesting(); |
| 4340 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4341 | // Animate the transform on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4342 | AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(), |
| 4343 | timeline_impl(), 10.0, 30, 0); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4344 | // This is just an animating layer, not a surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4345 | AddAnimatedTransformToElementWithPlayer(animating_child->element_id(), |
| 4346 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4347 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4348 | root->SetBounds(gfx::Size(100, 100)); |
| 4349 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4350 | child->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4351 | animating_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4352 | animating_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4353 | animating_surface->test_properties()->force_render_surface = true; |
| 4354 | child_of_animating_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4355 | child_of_animating_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4356 | animating_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4357 | animating_child->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4358 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4359 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4360 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4361 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4362 | EXPECT_FALSE(child->has_render_surface()); |
| 4363 | EXPECT_TRUE(animating_surface->has_render_surface()); |
| 4364 | EXPECT_FALSE(child_of_animating_surface->has_render_surface()); |
| 4365 | EXPECT_FALSE(animating_child->has_render_surface()); |
| 4366 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4367 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4368 | EXPECT_EQ(1u, update_layer_list_impl()->size()); |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4369 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4370 | // The back facing layers are culled from the layer list, and have an empty |
| 4371 | // visible rect. |
| 4372 | EXPECT_TRUE(UpdateLayerListImplContains(child2->id())); |
| 4373 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
| 4374 | EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty()); |
| 4375 | EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty()); |
| 4376 | EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4377 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4378 | EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4379 | } |
| 4380 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4381 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4382 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4383 | // Verify the behavior of back-face culling for a render surface that is |
| 4384 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4385 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4386 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4387 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4388 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4389 | LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface); |
| 4390 | LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4391 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4392 | // RenderSurfaces are not double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4393 | front_facing_surface->test_properties()->double_sided = false; |
| 4394 | back_facing_surface->test_properties()->double_sided = false; |
| 4395 | |
| 4396 | // Everything draws content. |
| 4397 | front_facing_surface->SetDrawsContent(true); |
| 4398 | back_facing_surface->SetDrawsContent(true); |
| 4399 | child1->SetDrawsContent(true); |
| 4400 | child2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4401 | |
| 4402 | gfx::Transform backface_matrix; |
| 4403 | backface_matrix.Translate(50.0, 50.0); |
| 4404 | backface_matrix.RotateAboutYAxis(180.0); |
| 4405 | backface_matrix.Translate(-50.0, -50.0); |
| 4406 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4407 | root->SetBounds(gfx::Size(100, 100)); |
| 4408 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4409 | front_facing_surface->test_properties()->force_render_surface = true; |
| 4410 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4411 | back_facing_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4412 | back_facing_surface->test_properties()->force_render_surface = true; |
| 4413 | child1->SetBounds(gfx::Size(100, 100)); |
| 4414 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4415 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4416 | front_facing_surface->Set3dSortingContextId(1); |
| 4417 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4418 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4419 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4420 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4421 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4422 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4423 | |
| 4424 | // We expect the render surface to have been created, but remain unused. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4425 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4426 | EXPECT_FALSE(child1->has_render_surface()); |
| 4427 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4428 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4429 | EXPECT_EQ(2u, update_layer_list_impl()->size()); |
| 4430 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4431 | EXPECT_TRUE(UpdateLayerListImplContains(child1->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4432 | } |
| 4433 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4434 | TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4435 | // Verify draw and screen space transforms of layers not in a surface. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4436 | LayerImpl* root = root_layer_for_testing(); |
| 4437 | root->SetBounds(gfx::Size(100, 100)); |
| 4438 | root->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4439 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4440 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4441 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4442 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4443 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4444 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4445 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4446 | child2->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4447 | child2->SetBounds(gfx::Size(5, 5)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4448 | child2->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4449 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4450 | float device_scale_factor = 2.5f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4451 | gfx::Size viewport_size(100, 100); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4452 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4453 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4454 | EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale()); |
| 4455 | EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale()); |
| 4456 | EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale()); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4457 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4458 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4459 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4460 | // Verify root transforms |
| 4461 | gfx::Transform expected_root_transform; |
| 4462 | expected_root_transform.Scale(device_scale_factor, device_scale_factor); |
| 4463 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4464 | root->ScreenSpaceTransform()); |
| 4465 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4466 | root->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4467 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4468 | // Verify results of transformed root rects |
| 4469 | gfx::RectF root_bounds(gfx::SizeF(root->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4470 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4471 | gfx::RectF root_draw_rect = |
| 4472 | MathUtil::MapClippedRect(root->DrawTransform(), root_bounds); |
| 4473 | gfx::RectF root_screen_space_rect = |
| 4474 | MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4475 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4476 | gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds())); |
| 4477 | expected_root_draw_rect.Scale(device_scale_factor); |
| 4478 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect); |
| 4479 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4480 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4481 | // Verify child and child2 transforms. They should match. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4482 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4483 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4484 | expected_child_transform.Translate(child->position().x(), |
| 4485 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4486 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4487 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4488 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4489 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4490 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4491 | child2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4492 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4493 | child2->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4494 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4495 | // Verify results of transformed child and child2 rects. They should |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4496 | // match. |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4497 | gfx::RectF child_bounds(gfx::SizeF(child->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4498 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4499 | gfx::RectF child_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4500 | MathUtil::MapClippedRect(child->DrawTransform(), child_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4501 | gfx::RectF child_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4502 | MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4503 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4504 | gfx::RectF child2_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4505 | MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4506 | gfx::RectF child2_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4507 | MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4508 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4509 | gfx::RectF expected_child_draw_rect(child->position(), |
| 4510 | gfx::SizeF(child->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4511 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4512 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4513 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4514 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect); |
| 4515 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4516 | } |
| 4517 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4518 | TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4519 | // Verify draw and screen space transforms of layers in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4520 | gfx::Transform perspective_matrix; |
| 4521 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4522 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4523 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4524 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4525 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4526 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4527 | root->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4528 | |
| 4529 | LayerImpl* page_scale = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4530 | page_scale->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4531 | |
| 4532 | LayerImpl* parent = AddChild<LayerImpl>(page_scale); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4533 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4534 | parent->SetDrawsContent(true); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4535 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4536 | LayerImpl* perspective_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4537 | perspective_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4538 | perspective_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4539 | perspective_surface->test_properties()->transform = |
| 4540 | perspective_matrix * scale_small_matrix; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4541 | perspective_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4542 | perspective_surface->test_properties()->force_render_surface = true; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4543 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4544 | LayerImpl* scale_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4545 | scale_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4546 | scale_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4547 | scale_surface->test_properties()->transform = scale_small_matrix; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4548 | scale_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4549 | scale_surface->test_properties()->force_render_surface = true; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4550 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4551 | float device_scale_factor = 2.5f; |
| 4552 | float page_scale_factor = 3.f; |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4553 | root->layer_tree_impl()->SetViewportLayersFromIds( |
| 4554 | Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, |
| 4555 | Layer::INVALID_ID); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4556 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4557 | root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4558 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 4559 | root, nullptr); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4560 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4561 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4562 | parent->GetIdealContentsScale()); |
| 4563 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4564 | perspective_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4565 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4566 | // the nearest render target. Here this includes the layer transform as well |
| 4567 | // as the device and page scale factors. |
| 4568 | gfx::Transform transform = scale_small_matrix; |
| 4569 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4570 | device_scale_factor * page_scale_factor); |
| 4571 | gfx::Vector2dF scales = |
| 4572 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4573 | float max_2d_scale = std::max(scales.x(), scales.y()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4574 | EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4575 | |
| 4576 | // The ideal scale will draw 1:1 with its render target space along |
| 4577 | // the larger-scale axis. |
| 4578 | gfx::Vector2dF target_space_transform_scales = |
| 4579 | MathUtil::ComputeTransform2dScaleComponents( |
| 4580 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4581 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4582 | std::max(target_space_transform_scales.x(), |
| 4583 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4584 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4585 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4586 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4587 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4588 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4589 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4590 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4591 | parent->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4592 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4593 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4594 | // with the screen, and then scaled during drawing. |
| 4595 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4596 | expected_perspective_surface_draw_transform.Translate( |
| 4597 | device_scale_factor * page_scale_factor * |
| 4598 | perspective_surface->position().x(), |
| 4599 | device_scale_factor * page_scale_factor * |
| 4600 | perspective_surface->position().y()); |
| 4601 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4602 | perspective_matrix); |
| 4603 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4604 | scale_small_matrix); |
| 4605 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4606 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4607 | device_scale_factor * page_scale_factor, |
| 4608 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4609 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4610 | expected_perspective_surface_draw_transform, |
| 4611 | perspective_surface->render_surface()->draw_transform()); |
| 4612 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4613 | expected_perspective_surface_layer_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4614 | perspective_surface->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4615 | } |
| 4616 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4617 | TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4618 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4619 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4620 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4621 | |
| 4622 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4623 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4624 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4625 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4626 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4627 | root->SetBounds(gfx::Size(100, 100)); |
| 4628 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4629 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4630 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4631 | parent->test_properties()->transform = parent_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4632 | parent->SetDrawsContent(true); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4633 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4634 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4635 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4636 | child_scale->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4637 | child_scale->test_properties()->transform = child_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4638 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4639 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4640 | float device_scale_factor = 2.5f; |
| 4641 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4642 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4643 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4644 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 4645 | root, nullptr); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4646 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4647 | // The ideal scale is able to go below 1. |
| 4648 | float expected_ideal_scale = |
| 4649 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4650 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4651 | EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale()); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4652 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4653 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4654 | initial_parent_scale * initial_child_scale; |
| 4655 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4656 | EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4657 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4658 | } |
| 4659 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4660 | TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4661 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4662 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4663 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4664 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4665 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4666 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4667 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4668 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4669 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4670 | root->SetBounds(gfx::Size(100, 100)); |
| 4671 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4672 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4673 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4674 | parent->test_properties()->transform = parent_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4675 | parent->SetDrawsContent(true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4676 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4677 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4678 | child_scale->SetBounds(gfx::Size(10, 10)); |
| 4679 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4680 | child_scale->test_properties()->transform = child_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4681 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4682 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4683 | ExecuteCalculateDrawProperties(root); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4684 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4685 | EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4686 | // Animating layers compute ideal scale in the same way as when |
| 4687 | // they are static. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4688 | EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale, |
| 4689 | child_scale->GetIdealContentsScale()); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4690 | } |
| 4691 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4692 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4693 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4694 | parent->SetBounds(gfx::Size(30, 30)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4695 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4696 | parent->Set3dSortingContextId(1); |
| 4697 | parent->test_properties()->should_flatten_transform = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4698 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4699 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4700 | child->SetBounds(gfx::Size(10, 10)); |
| 4701 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4702 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4703 | child->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4704 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4705 | // This layer should end up in the same surface as child, with the same draw |
| 4706 | // and screen space transforms. |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4707 | LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4708 | duplicate_child_non_owner->SetBounds(gfx::Size(10, 10)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4709 | duplicate_child_non_owner->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4710 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4711 | float device_scale_factor = 1.5f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4712 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4713 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4714 | // We should have two render surfaces. The root's render surface and child's |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4715 | // render surface (it needs one because of force_render_surface). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4716 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4717 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4718 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4719 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4720 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4721 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4722 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4723 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4724 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4725 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4726 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4727 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4728 | child->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4729 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4730 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4731 | expected_screen_space_transform.Scale(device_scale_factor, |
| 4732 | device_scale_factor); |
| 4733 | expected_screen_space_transform.Translate(child->position().x(), |
| 4734 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4735 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4736 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4737 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4738 | gfx::Transform expected_duplicate_child_draw_transform = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4739 | child->DrawTransform(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4740 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4741 | duplicate_child_non_owner->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4742 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4743 | child->ScreenSpaceTransform(), |
| 4744 | duplicate_child_non_owner->ScreenSpaceTransform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4745 | EXPECT_EQ(child->drawable_content_rect(), |
| 4746 | duplicate_child_non_owner->drawable_content_rect()); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4747 | EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4748 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4749 | gfx::Transform expected_render_surface_draw_transform; |
| 4750 | expected_render_surface_draw_transform.Translate( |
| 4751 | device_scale_factor * child->position().x(), |
| 4752 | device_scale_factor * child->position().y()); |
| 4753 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 4754 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4755 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4756 | gfx::Transform expected_surface_draw_transform; |
| 4757 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 4758 | device_scale_factor * 2.f); |
| 4759 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 4760 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4761 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4762 | gfx::Transform expected_surface_screen_space_transform; |
| 4763 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 4764 | device_scale_factor * 2.f); |
| 4765 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4766 | expected_surface_screen_space_transform, |
| 4767 | child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4768 | } |
| 4769 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4770 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4771 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4772 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4773 | parent->SetBounds(gfx::Size(33, 31)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4774 | parent->SetDrawsContent(true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4775 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4776 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4777 | child->SetBounds(gfx::Size(13, 11)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4778 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4779 | child->test_properties()->force_render_surface = true; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4780 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 4781 | float device_scale_factor = 1.7f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4782 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4783 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4784 | // We should have two render surfaces. The root's render surface and child's |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame] | 4785 | // render surface (it needs one because of force_render_surface). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4786 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4787 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4788 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4789 | child->render_surface()->draw_transform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4790 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4791 | child->render_surface()->draw_transform()); |
| 4792 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4793 | gfx::Transform(), child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4794 | } |
| 4795 | |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 4796 | TEST_F(LayerTreeHostCommonTest, LayerSearch) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4797 | scoped_refptr<Layer> root = Layer::Create(); |
| 4798 | scoped_refptr<Layer> child = Layer::Create(); |
| 4799 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 4800 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4801 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4802 | child->AddChild(grand_child.get()); |
| 4803 | child->SetMaskLayer(mask_layer.get()); |
| 4804 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4805 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4806 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4807 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4808 | int nonexistent_id = -1; |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 4809 | LayerTree* layer_tree = host()->GetLayerTree(); |
| 4810 | EXPECT_EQ(root.get(), layer_tree->LayerById(root->id())); |
| 4811 | EXPECT_EQ(child.get(), layer_tree->LayerById(child->id())); |
| 4812 | EXPECT_EQ(grand_child.get(), layer_tree->LayerById(grand_child->id())); |
| 4813 | EXPECT_EQ(mask_layer.get(), layer_tree->LayerById(mask_layer->id())); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 4814 | EXPECT_FALSE(layer_tree->LayerById(nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4815 | } |
| 4816 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4817 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4818 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4819 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 4820 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4821 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4822 | root->SetBounds(gfx::Size(100, 100)); |
| 4823 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4824 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4825 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 4826 | grand_child->SetDrawsContent(true); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4827 | ExecuteCalculateDrawProperties(root); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4828 | EXPECT_FALSE(child->has_render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4829 | } |
| 4830 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4831 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4832 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 4833 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 4834 | FakeLayerTreeHostImpl host_impl(host()->GetSettings(), &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 4835 | &task_graph_runner); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4836 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4837 | std::unique_ptr<LayerImpl> root = |
| 4838 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4839 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4840 | root->SetDrawsContent(true); |
| 4841 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4842 | std::unique_ptr<LayerImpl> child = |
| 4843 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4844 | child->SetBounds(gfx::Size(50, 50)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4845 | child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4846 | child->test_properties()->opacity = 0.0f; |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4847 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 4848 | const int child_id = child->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4849 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 4850 | root->SetHasRenderSurface(true); |
| 4851 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4852 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4853 | host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4854 | |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4855 | // Add opacity animation. |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4856 | scoped_refptr<AnimationTimeline> timeline = |
| 4857 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 4858 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4859 | host_impl.pending_tree()->SetElementIdsForTesting(); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4860 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4861 | ElementId child_element_id = |
| 4862 | host_impl.pending_tree()->LayerById(child_id)->element_id(); |
| 4863 | |
| 4864 | AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0, |
| 4865 | 0.0f, 1.0f, false); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4866 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4867 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4868 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4869 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4870 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4871 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4872 | |
| 4873 | // We should have one render surface and two layers. The child |
| 4874 | // layer should be included even though it is transparent. |
| 4875 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4876 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4877 | |
| 4878 | // If the root itself is hidden, the child should not be drawn even if it has |
| 4879 | // an animating opacity. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4880 | root_layer->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4881 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4882 | LayerImplList render_surface_layer_list2; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4883 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4884 | root_layer, root_layer->bounds(), &render_surface_layer_list2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4885 | inputs2.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4886 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4887 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4888 | LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4889 | EffectTree& tree = |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4890 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4891 | EffectNode* node = tree.Node(child_ptr->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4892 | EXPECT_FALSE(node->is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4893 | |
| 4894 | // A layer should be drawn and it should contribute to drawn surface when |
| 4895 | // it has animating opacity even if it has opacity 0. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4896 | root_layer->test_properties()->opacity = 1.0f; |
| 4897 | child_ptr->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4898 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4899 | LayerImplList render_surface_layer_list3; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4900 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4901 | root_layer, root_layer->bounds(), &render_surface_layer_list3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4902 | inputs3.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4903 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4904 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4905 | child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
| 4906 | tree = root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4907 | node = tree.Node(child_ptr->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4908 | EXPECT_TRUE(node->is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4909 | EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index())); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4910 | |
| 4911 | // But if the opacity of the layer remains 0 after activation, it should not |
| 4912 | // be drawn. |
| 4913 | host_impl.ActivateSyncTree(); |
danakj | 0da42ca6 | 2016-07-01 19:42:33 | [diff] [blame] | 4914 | LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id()); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4915 | LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id()); |
| 4916 | |
| 4917 | EffectTree& active_effect_tree = |
| 4918 | host_impl.active_tree()->property_trees()->effect_tree; |
| 4919 | EXPECT_TRUE(active_effect_tree.needs_update()); |
| 4920 | |
| 4921 | ExecuteCalculateDrawProperties(active_root); |
| 4922 | |
| 4923 | node = active_effect_tree.Node(active_child->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4924 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4925 | EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface( |
| 4926 | active_child->effect_tree_index())); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4927 | } |
| 4928 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4929 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4930 | class LCDTextTest : public LayerTreeHostCommonTestBase, |
| 4931 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4932 | public: |
| 4933 | LCDTextTest() |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4934 | : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()), |
| 4935 | host_impl_(LCDTextTestLayerTreeSettings(), |
| 4936 | &task_runner_provider_, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4937 | &task_graph_runner_) {} |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4938 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4939 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 4940 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4941 | protected: |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4942 | LayerTreeSettings LCDTextTestLayerTreeSettings() { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4943 | LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings(); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4944 | |
| 4945 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
| 4946 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
| 4947 | settings.can_use_lcd_text = can_use_lcd_text_; |
| 4948 | settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_; |
| 4949 | return settings; |
| 4950 | } |
| 4951 | |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 4952 | void SetUp() override { |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4953 | timeline_ = |
| 4954 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 4955 | host_impl_.animation_host()->AddAnimationTimeline(timeline_); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4956 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4957 | std::unique_ptr<LayerImpl> root_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4958 | LayerImpl::Create(host_impl_.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4959 | std::unique_ptr<LayerImpl> child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4960 | LayerImpl::Create(host_impl_.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4961 | std::unique_ptr<LayerImpl> grand_child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4962 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 4963 | |
| 4964 | // Stash raw pointers to look at later. |
| 4965 | root_ = root_ptr.get(); |
| 4966 | child_ = child_ptr.get(); |
| 4967 | grand_child_ = grand_child_ptr.get(); |
| 4968 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4969 | child_->test_properties()->AddChild(std::move(grand_child_ptr)); |
| 4970 | root_->test_properties()->AddChild(std::move(child_ptr)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4971 | host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4972 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4973 | host_impl_.active_tree()->SetElementIdsForTesting(); |
| 4974 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 4975 | root_->SetContentsOpaque(true); |
| 4976 | child_->SetContentsOpaque(true); |
| 4977 | grand_child_->SetContentsOpaque(true); |
| 4978 | |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4979 | root_->SetDrawsContent(true); |
| 4980 | child_->SetDrawsContent(true); |
| 4981 | grand_child_->SetDrawsContent(true); |
| 4982 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4983 | root_->SetBounds(gfx::Size(1, 1)); |
| 4984 | child_->SetBounds(gfx::Size(1, 1)); |
| 4985 | grand_child_->SetBounds(gfx::Size(1, 1)); |
| 4986 | |
| 4987 | child_->test_properties()->force_render_surface = |
| 4988 | std::tr1::get<2>(GetParam()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4989 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4990 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4991 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4992 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4993 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4994 | FakeImplTaskRunnerProvider task_runner_provider_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 4995 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4996 | FakeLayerTreeHostImpl host_impl_; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4997 | scoped_refptr<AnimationTimeline> timeline_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4998 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4999 | LayerImpl* root_ = nullptr; |
| 5000 | LayerImpl* child_ = nullptr; |
| 5001 | LayerImpl* grand_child_ = nullptr; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5002 | }; |
| 5003 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5004 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5005 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5006 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5007 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5008 | // Case 1: Identity transform. |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5009 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5010 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5011 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5012 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5013 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5014 | // Case 2: Integral translation. |
| 5015 | gfx::Transform integral_translation; |
| 5016 | integral_translation.Translate(1.0, 2.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5017 | child_->test_properties()->transform = integral_translation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5018 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5019 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5020 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5021 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5022 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5023 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5024 | // Case 3: Non-integral translation. |
| 5025 | gfx::Transform non_integral_translation; |
| 5026 | non_integral_translation.Translate(1.5, 2.5); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5027 | child_->test_properties()->transform = non_integral_translation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5028 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5029 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5030 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5031 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5032 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5033 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5034 | // Case 4: Rotation. |
| 5035 | gfx::Transform rotation; |
| 5036 | rotation.Rotate(10.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5037 | child_->test_properties()->transform = rotation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5038 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5039 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5040 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5041 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5042 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5043 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5044 | // Case 5: Scale. |
| 5045 | gfx::Transform scale; |
| 5046 | scale.Scale(2.0, 2.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5047 | child_->test_properties()->transform = scale; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5048 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5049 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5050 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5051 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5052 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5053 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5054 | // Case 6: Skew. |
| 5055 | gfx::Transform skew; |
nainar | 8ca8ee6 | 2015-09-03 01:04:10 | [diff] [blame] | 5056 | skew.Skew(10.0, 0.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5057 | child_->test_properties()->transform = skew; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5058 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5059 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5060 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5061 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5062 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5063 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5064 | // Case 7: Translucent. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5065 | child_->test_properties()->transform = gfx::Transform(); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5066 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5067 | child_->test_properties()->opacity = 0.5f; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5068 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5069 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5070 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5071 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5072 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5073 | // Case 8: Sanity check: restore transform and opacity. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5074 | child_->test_properties()->transform = gfx::Transform(); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5075 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5076 | child_->test_properties()->opacity = 1.f; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5077 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5078 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5079 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5080 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5081 | |
| 5082 | // Case 9: Non-opaque content. |
| 5083 | child_->SetContentsOpaque(false); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5084 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5085 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5086 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5087 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5088 | |
| 5089 | // Case 10: Sanity check: restore content opaqueness. |
| 5090 | child_->SetContentsOpaque(true); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5091 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5092 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5093 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5094 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5095 | } |
| 5096 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5097 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5098 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5099 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5100 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5101 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5102 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5103 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5104 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5105 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5106 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5107 | // Add opacity animation. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5108 | child_->test_properties()->opacity = 0.9f; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5109 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5110 | |
| 5111 | SetElementIdsForTesting(); |
| 5112 | |
| 5113 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5114 | 10.0, 0.9f, 0.1f, false); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5115 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5116 | // Text LCD should be adjusted while animation is active. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5117 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5118 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5119 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 5123 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5124 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5125 | |
| 5126 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5127 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5128 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5129 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5130 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5131 | SetElementIdsForTesting(); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5132 | |
| 5133 | // Mark contents non-opaque within the first animation frame. |
| 5134 | child_->SetContentsOpaque(false); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5135 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5136 | 10.0, 0.9f, 0.1f, false); |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 5137 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5138 | // LCD text should be disabled for non-opaque layers even during animations. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5139 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5140 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5141 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5142 | } |
| 5143 | |
| 5144 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5145 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5146 | testing::Combine(testing::Bool(), |
| 5147 | testing::Bool(), |
| 5148 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5149 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5150 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5151 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5152 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 5153 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5154 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5155 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5156 | std::unique_ptr<LayerImpl> root = |
| 5157 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5158 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5159 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5160 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5161 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5162 | std::unique_ptr<LayerImpl> child = |
| 5163 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5164 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5165 | child->SetDrawsContent(true); |
| 5166 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5167 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5168 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5169 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5170 | grand_child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5171 | grand_child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5172 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5173 | child->test_properties()->AddChild(std::move(grand_child)); |
| 5174 | root->test_properties()->AddChild(std::move(child)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5175 | root->SetHasRenderSurface(true); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5176 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5177 | |
| 5178 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5179 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5180 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5181 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5182 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5183 | |
| 5184 | // We should have one render surface and two layers. The grand child has |
| 5185 | // hidden itself. |
| 5186 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5187 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5188 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
| 5189 | EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5190 | } |
| 5191 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5192 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5193 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5194 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 5195 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5196 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5197 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5198 | std::unique_ptr<LayerImpl> root = |
| 5199 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5200 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5201 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5202 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5203 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5204 | std::unique_ptr<LayerImpl> child = |
| 5205 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5206 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5207 | child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5208 | child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5209 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5210 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5211 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5212 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5213 | grand_child->SetDrawsContent(true); |
| 5214 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5215 | child->test_properties()->AddChild(std::move(grand_child)); |
| 5216 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5217 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5218 | |
| 5219 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5220 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5221 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5222 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5223 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5224 | |
| 5225 | // We should have one render surface and one layers. The child has |
| 5226 | // hidden itself and the grand child. |
| 5227 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5228 | ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size()); |
| 5229 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5230 | } |
| 5231 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5232 | void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5233 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5234 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5235 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5236 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 5237 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5238 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5239 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5240 | std::unique_ptr<LayerImpl> root = |
| 5241 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5242 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5243 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5244 | LayerImpl* root_layer = root.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5245 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5246 | std::unique_ptr<LayerImpl> copy_grand_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5247 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5248 | copy_grand_parent->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5249 | copy_grand_parent->SetDrawsContent(true); |
| 5250 | LayerImpl* copy_grand_parent_layer = copy_grand_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5251 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5252 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5253 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5254 | copy_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5255 | copy_parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5256 | copy_parent->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5257 | LayerImpl* copy_parent_layer = copy_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5258 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5259 | std::unique_ptr<LayerImpl> copy_request = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5260 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5261 | copy_request->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5262 | copy_request->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5263 | copy_request->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5264 | LayerImpl* copy_layer = copy_request.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5265 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5266 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5267 | LayerImpl::Create(host_impl.pending_tree(), 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5268 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5269 | copy_child->SetDrawsContent(true); |
| 5270 | LayerImpl* copy_child_layer = copy_child.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5271 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5272 | std::unique_ptr<LayerImpl> copy_grand_child = |
thakis | e53c527 | 2016-01-24 01:20:40 | [diff] [blame] | 5273 | LayerImpl::Create(host_impl.pending_tree(), 6); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5274 | copy_grand_child->SetBounds(gfx::Size(20, 20)); |
| 5275 | copy_grand_child->SetDrawsContent(true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5276 | LayerImpl* copy_grand_child_layer = copy_grand_child.get(); |
| 5277 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5278 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5279 | LayerImpl::Create(host_impl.pending_tree(), 7); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5280 | copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5281 | copy_grand_parent_sibling_before->SetDrawsContent(true); |
| 5282 | LayerImpl* copy_grand_parent_sibling_before_layer = |
| 5283 | copy_grand_parent_sibling_before.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5284 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5285 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5286 | LayerImpl::Create(host_impl.pending_tree(), 8); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5287 | copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5288 | copy_grand_parent_sibling_after->SetDrawsContent(true); |
| 5289 | LayerImpl* copy_grand_parent_sibling_after_layer = |
| 5290 | copy_grand_parent_sibling_after.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5291 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5292 | copy_child->test_properties()->AddChild(std::move(copy_grand_child)); |
| 5293 | copy_request->test_properties()->AddChild(std::move(copy_child)); |
| 5294 | copy_parent->test_properties()->AddChild(std::move(copy_request)); |
| 5295 | copy_grand_parent->test_properties()->AddChild(std::move(copy_parent)); |
| 5296 | root->test_properties()->AddChild( |
| 5297 | std::move(copy_grand_parent_sibling_before)); |
| 5298 | root->test_properties()->AddChild(std::move(copy_grand_parent)); |
| 5299 | root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5300 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5301 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5302 | // 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] | 5303 | // hidden subtree on copy_layer. Also hide the copy grand child and its |
| 5304 | // subtree. |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5305 | copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true; |
| 5306 | copy_grand_parent_sibling_before_layer->test_properties() |
| 5307 | ->hide_layer_and_subtree = true; |
| 5308 | copy_grand_parent_sibling_after_layer->test_properties() |
| 5309 | ->hide_layer_and_subtree = true; |
| 5310 | copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5311 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5312 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5313 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5314 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5315 | LayerImplList render_surface_layer_list; |
| 5316 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5317 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5318 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5319 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5320 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5321 | EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 5322 | EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5323 | EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5324 | EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5325 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5326 | // We should have four render surfaces, one for the root, one for the grand |
| 5327 | // parent since it has opacity and two drawing descendants, one for the parent |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5328 | // since it owns a surface, and one for the copy_layer. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5329 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5330 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5331 | EXPECT_EQ(copy_grand_parent_layer->id(), |
| 5332 | render_surface_layer_list.at(1)->id()); |
| 5333 | EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id()); |
| 5334 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5335 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5336 | // The root render surface should have 2 contributing layers. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5337 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5338 | EXPECT_EQ(root_layer->id(), |
| 5339 | root_layer->render_surface()->layer_list().at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5340 | EXPECT_EQ(copy_grand_parent_layer->id(), |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5341 | root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5342 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 5343 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5344 | // appear in its list, since it needs to be drawn for the copy request. |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5345 | ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5346 | EXPECT_EQ(copy_layer->id(), |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5347 | copy_parent_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5348 | |
| 5349 | // The copy_layer's render surface should have two contributing layers. |
| 5350 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 5351 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5352 | copy_layer->render_surface()->layer_list().at(0)->id()); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5353 | EXPECT_EQ(copy_child_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5354 | copy_layer->render_surface()->layer_list().at(1)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5355 | |
| 5356 | // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden, |
| 5357 | // but the copy_layer and copy_child should be drawn for the copy request. |
| 5358 | // copy grand child should not be drawn as its hidden even in the copy |
| 5359 | // request. |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 5360 | EffectTree& tree = |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5361 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5362 | EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5363 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5364 | node = tree.Node(copy_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5365 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5366 | node = tree.Node(copy_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5367 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5368 | node = tree.Node(copy_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5369 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5370 | node = tree.Node(copy_grand_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5371 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5372 | |
| 5373 | // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its |
| 5374 | // actually hidden. |
| 5375 | EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5376 | } |
| 5377 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5378 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5379 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5380 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 5381 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5382 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5383 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5384 | std::unique_ptr<LayerImpl> root = |
| 5385 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5386 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5387 | root->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5388 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5389 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5390 | LayerImpl::Create(host_impl.pending_tree(), 2); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5391 | copy_parent->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5392 | copy_parent->SetMasksToBounds(true); |
| 5393 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5394 | std::unique_ptr<LayerImpl> copy_layer = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5395 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5396 | copy_layer->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5397 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5398 | copy_layer->test_properties()->force_render_surface = true; |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5399 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5400 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5401 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5402 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5403 | copy_child->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5404 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5405 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5406 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5407 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5408 | copy_layer->test_properties()->AddChild(std::move(copy_child)); |
| 5409 | copy_parent->test_properties()->AddChild(std::move(copy_layer)); |
| 5410 | root->test_properties()->AddChild(std::move(copy_parent)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5411 | |
| 5412 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5413 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5414 | root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5415 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5416 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5417 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5418 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5419 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5420 | // We should have two render surface, as the others are clipped out. |
| 5421 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5422 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5423 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5424 | // The root render surface should only have 2 contributing layer, since the |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5425 | // other layers are empty/clipped away. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5426 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5427 | EXPECT_EQ(root_layer->id(), |
| 5428 | root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5429 | } |
| 5430 | |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5431 | TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5432 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5433 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5434 | root->SetDrawsContent(true); |
| 5435 | root->SetMasksToBounds(true); |
| 5436 | |
| 5437 | LayerImpl* copy_layer = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5438 | copy_layer->SetBounds(gfx::Size(100, 100)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5439 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5440 | copy_layer->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5441 | |
| 5442 | LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5443 | copy_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5444 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5445 | copy_child->SetDrawsContent(true); |
| 5446 | |
| 5447 | LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5448 | copy_clip->SetBounds(gfx::Size(55, 55)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5449 | copy_clip->SetMasksToBounds(true); |
| 5450 | |
| 5451 | LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5452 | copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5453 | copy_clipped_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5454 | copy_clipped_child->SetDrawsContent(true); |
| 5455 | |
| 5456 | LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5457 | copy_surface->SetPosition(gfx::PointF(45.f, 45.f)); |
| 5458 | copy_surface->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5459 | copy_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5460 | copy_surface->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5461 | |
| 5462 | copy_layer->test_properties()->copy_requests.push_back( |
| 5463 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5464 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5465 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5466 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5467 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5468 | |
| 5469 | EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect()); |
| 5470 | EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect()); |
| 5471 | EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect()); |
| 5472 | EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect()); |
| 5473 | |
| 5474 | // Case 2: When the non root copy request layer is clipped. |
| 5475 | copy_layer->SetBounds(gfx::Size(50, 50)); |
| 5476 | copy_layer->SetMasksToBounds(true); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5477 | copy_layer->test_properties()->copy_requests.push_back( |
| 5478 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5479 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5480 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5481 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5482 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5483 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5484 | |
| 5485 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5486 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5487 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5488 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | 296dd9f | 2016-07-05 14:59:51 | [diff] [blame] | 5489 | |
| 5490 | // Case 3: When there is device scale factor. |
| 5491 | float device_scale_factor = 2.f; |
| 5492 | copy_layer->test_properties()->copy_requests.push_back( |
| 5493 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5494 | |
| 5495 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
| 5496 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 5497 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
| 5498 | |
| 5499 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5500 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5501 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5502 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5503 | } |
| 5504 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5505 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 5506 | // Ensure that a transform between the layer and its render surface is not a |
| 5507 | // problem. Constructs the following layer tree. |
| 5508 | // |
| 5509 | // root (a render surface) |
| 5510 | // + render_surface |
| 5511 | // + clip_parent (scaled) |
| 5512 | // + intervening_clipping_layer |
| 5513 | // + clip_child |
| 5514 | // |
| 5515 | // The render surface should be resized correctly and the clip child should |
| 5516 | // inherit the right clip rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5517 | LayerImpl* root = root_layer_for_testing(); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5518 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 5519 | LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5520 | clip_parent->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5521 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5522 | intervening->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5523 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5524 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5525 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5526 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5527 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5528 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5529 | |
| 5530 | intervening->SetMasksToBounds(true); |
| 5531 | clip_parent->SetMasksToBounds(true); |
| 5532 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5533 | gfx::Transform scale_transform; |
| 5534 | scale_transform.Scale(2, 2); |
| 5535 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5536 | root->SetBounds(gfx::Size(50, 50)); |
| 5537 | render_surface->SetBounds(gfx::Size(10, 10)); |
| 5538 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5539 | clip_parent->test_properties()->transform = scale_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5540 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5541 | clip_parent->SetBounds(gfx::Size(10, 10)); |
| 5542 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5543 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5544 | clip_child->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5545 | clip_child->SetBounds(gfx::Size(10, 10)); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5546 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5547 | |
| 5548 | ASSERT_TRUE(root->render_surface()); |
| 5549 | ASSERT_TRUE(render_surface->render_surface()); |
| 5550 | |
| 5551 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 5552 | // by the intervening clip layer. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5553 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect()); |
| 5554 | ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect()); |
| 5555 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5556 | |
| 5557 | // Ensure that the render surface reports a content rect that has been grown |
| 5558 | // to accomodate for the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5559 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), |
| 5560 | render_surface->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5561 | |
| 5562 | // The above check implies the two below, but they nicely demonstrate that |
| 5563 | // we've grown, despite the intervening layer's clip. |
| 5564 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 5565 | render_surface->render_surface()->content_rect())); |
| 5566 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 5567 | render_surface->render_surface()->content_rect())); |
| 5568 | } |
| 5569 | |
| 5570 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 5571 | // Ensure that intervening render surfaces are not a problem in the basic |
| 5572 | // case. In the following tree, both render surfaces should be resized to |
| 5573 | // accomodate for the clip child, despite an intervening clip. |
| 5574 | // |
| 5575 | // root (a render surface) |
| 5576 | // + clip_parent (masks to bounds) |
| 5577 | // + render_surface1 (sets opacity) |
| 5578 | // + intervening (masks to bounds) |
| 5579 | // + render_surface2 (also sets opacity) |
| 5580 | // + clip_child |
| 5581 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5582 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5583 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5584 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5585 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5586 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5587 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5588 | render_surface1->SetDrawsContent(true); |
| 5589 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5590 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5591 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5592 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5593 | |
| 5594 | intervening->SetMasksToBounds(true); |
| 5595 | clip_parent->SetMasksToBounds(true); |
| 5596 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5597 | gfx::Transform translation_transform; |
| 5598 | translation_transform.Translate(2, 2); |
| 5599 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5600 | root->SetBounds(gfx::Size(50, 50)); |
| 5601 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5602 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5603 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5604 | render_surface1->test_properties()->force_render_surface = true; |
| 5605 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5606 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5607 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5608 | render_surface2->test_properties()->force_render_surface = true; |
| 5609 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5610 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5611 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5612 | |
| 5613 | EXPECT_TRUE(root->render_surface()); |
| 5614 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5615 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5616 | |
| 5617 | // Since the render surfaces could have expanded, they should not clip (their |
| 5618 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5619 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5620 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5621 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5622 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5623 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5624 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5625 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5626 | |
| 5627 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5628 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5629 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5630 | |
| 5631 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5632 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5633 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5634 | |
| 5635 | // The content rects of both render surfaces should both have expanded to |
| 5636 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5637 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5638 | render_surface1->render_surface()->content_rect()); |
| 5639 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), |
| 5640 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5641 | |
| 5642 | // The clip child should have inherited the clip parent's clip (projected to |
| 5643 | // the right space, of course), and should have the correctly sized visible |
| 5644 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5645 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect()); |
| 5646 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5647 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5648 | } |
| 5649 | |
| 5650 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 5651 | // Ensure that intervening render surfaces are not a problem, even if there |
| 5652 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 5653 | // of transform. |
| 5654 | // |
| 5655 | // root (a render surface) |
| 5656 | // + clip_parent (masks to bounds) |
| 5657 | // + render_surface1 (sets opacity) |
| 5658 | // + intervening (masks to bounds AND scrolls) |
| 5659 | // + render_surface2 (also sets opacity) |
| 5660 | // + clip_child |
| 5661 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5662 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5663 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5664 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5665 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5666 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5667 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5668 | render_surface1->SetDrawsContent(true); |
| 5669 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5670 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5671 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5672 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5673 | |
| 5674 | intervening->SetMasksToBounds(true); |
| 5675 | clip_parent->SetMasksToBounds(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5676 | intervening->SetScrollClipLayer(clip_parent->id()); |
| 5677 | intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5678 | |
| 5679 | gfx::Transform translation_transform; |
| 5680 | translation_transform.Translate(2, 2); |
| 5681 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5682 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5683 | clip_parent->test_properties()->transform = translation_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5684 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5685 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5686 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5687 | render_surface1->test_properties()->force_render_surface = true; |
| 5688 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5689 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5690 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5691 | render_surface2->test_properties()->force_render_surface = true; |
| 5692 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5693 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5694 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5695 | |
| 5696 | EXPECT_TRUE(root->render_surface()); |
| 5697 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5698 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5699 | |
| 5700 | // Since the render surfaces could have expanded, they should not clip (their |
| 5701 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5702 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5703 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5704 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5705 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5706 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5707 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5708 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5709 | |
| 5710 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5711 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5712 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5713 | |
| 5714 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5715 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5716 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5717 | |
| 5718 | // The content rects of both render surfaces should both have expanded to |
| 5719 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5720 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5721 | render_surface1->render_surface()->content_rect()); |
| 5722 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), |
| 5723 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5724 | |
| 5725 | // The clip child should have inherited the clip parent's clip (projected to |
| 5726 | // the right space, of course), and should have the correctly sized visible |
| 5727 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5728 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect()); |
| 5729 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5730 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5731 | } |
| 5732 | |
| 5733 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 5734 | // Ensures that descendants of the clip child inherit the correct clip. |
| 5735 | // |
| 5736 | // root (a render surface) |
| 5737 | // + clip_parent (masks to bounds) |
| 5738 | // + intervening (masks to bounds) |
| 5739 | // + clip_child |
| 5740 | // + child |
| 5741 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5742 | LayerImpl* root = root_layer_for_testing(); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5743 | LayerImpl* clip_parent = AddChild<LayerImpl>(root); |
| 5744 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
| 5745 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5746 | LayerImpl* child = AddChild<LayerImpl>(clip_child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5747 | clip_child->SetDrawsContent(true); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5748 | child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5749 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5750 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5751 | clip_parent->test_properties()->clip_children = |
| 5752 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5753 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5754 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5755 | root->SetBounds(gfx::Size(50, 50)); |
| 5756 | clip_parent->SetBounds(gfx::Size(40, 40)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5757 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5758 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5759 | intervening->SetMasksToBounds(true); |
| 5760 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 5761 | child->SetBounds(gfx::Size(60, 60)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5762 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5763 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5764 | |
| 5765 | EXPECT_TRUE(root->render_surface()); |
| 5766 | |
| 5767 | // Neither the clip child nor its descendant should have inherited the clip |
| 5768 | // from |intervening|. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5769 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5770 | EXPECT_TRUE(clip_child->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5771 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5772 | EXPECT_TRUE(child->is_clipped()); |
| 5773 | } |
| 5774 | |
| 5775 | TEST_F(LayerTreeHostCommonTest, |
| 5776 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 5777 | // Ensures that non-descendant clip children in the tree do not affect |
| 5778 | // render surfaces. |
| 5779 | // |
| 5780 | // root (a render surface) |
| 5781 | // + clip_parent (masks to bounds) |
| 5782 | // + render_surface1 |
| 5783 | // + clip_child |
| 5784 | // + render_surface2 |
| 5785 | // + non_clip_child |
| 5786 | // |
| 5787 | // In this example render_surface2 should be unaffected by clip_child. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5788 | LayerImpl* root = root_layer_for_testing(); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5789 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5790 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5791 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5792 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent); |
| 5793 | LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5794 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5795 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5796 | clip_parent->test_properties()->clip_children = |
| 5797 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5798 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5799 | |
| 5800 | clip_parent->SetMasksToBounds(true); |
| 5801 | render_surface1->SetMasksToBounds(true); |
| 5802 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5803 | render_surface1->SetDrawsContent(true); |
| 5804 | clip_child->SetDrawsContent(true); |
| 5805 | render_surface2->SetDrawsContent(true); |
| 5806 | non_clip_child->SetDrawsContent(true); |
| 5807 | |
| 5808 | root->SetBounds(gfx::Size(15, 15)); |
| 5809 | clip_parent->SetBounds(gfx::Size(10, 10)); |
| 5810 | render_surface1->SetPosition(gfx::PointF(5, 5)); |
| 5811 | render_surface1->SetBounds(gfx::Size(5, 5)); |
| 5812 | render_surface1->test_properties()->force_render_surface = true; |
| 5813 | render_surface2->SetBounds(gfx::Size(5, 5)); |
| 5814 | render_surface2->test_properties()->force_render_surface = true; |
| 5815 | clip_child->SetPosition(gfx::PointF(-1, 1)); |
| 5816 | clip_child->SetBounds(gfx::Size(10, 10)); |
| 5817 | non_clip_child->SetBounds(gfx::Size(5, 5)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5818 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5819 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5820 | |
| 5821 | EXPECT_TRUE(root->render_surface()); |
| 5822 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5823 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5824 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5825 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5826 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5827 | |
| 5828 | // The render surface should not clip (it has unclipped descendants), instead |
| 5829 | // it should rely on layer clipping. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5830 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5831 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5832 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 5833 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5834 | // That said, it should have grown to accomodate the unclipped descendant and |
| 5835 | // its own size. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5836 | EXPECT_EQ(gfx::Rect(-1, 0, 6, 5), |
| 5837 | render_surface1->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5838 | |
| 5839 | // This render surface should clip. It has no unclipped descendants. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5840 | EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 5841 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5842 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 5843 | EXPECT_FALSE(render_surface2->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5844 | |
| 5845 | // It also shouldn't have grown to accomodate the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5846 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), |
| 5847 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5848 | |
| 5849 | // Sanity check our num_unclipped_descendants values. |
ajuma | 0641ded | 2016-05-05 21:28:21 | [diff] [blame] | 5850 | EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants); |
| 5851 | EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5852 | } |
| 5853 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5854 | TEST_F(LayerTreeHostCommonTest, |
| 5855 | CreateRenderSurfaceWhenFlattenInsideRenderingContext) { |
| 5856 | // Verifies that Render Surfaces are created at the edge of rendering context. |
| 5857 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5858 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5859 | LayerImpl* child1 = AddChildToRoot<LayerImpl>(); |
| 5860 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 5861 | LayerImpl* child3 = AddChild<LayerImpl>(child2); |
| 5862 | root->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5863 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5864 | gfx::Size bounds(100, 100); |
| 5865 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5866 | root->SetBounds(bounds); |
| 5867 | child1->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5868 | child1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5869 | child1->Set3dSortingContextId(1); |
| 5870 | child1->test_properties()->should_flatten_transform = false; |
| 5871 | child2->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5872 | child2->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5873 | child2->Set3dSortingContextId(1); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5874 | child3->SetBounds(bounds); |
| 5875 | child3->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5876 | child3->Set3dSortingContextId(1); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 5877 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5878 | |
| 5879 | // Verify which render surfaces were created. |
| 5880 | EXPECT_TRUE(root->has_render_surface()); |
| 5881 | EXPECT_FALSE(child1->has_render_surface()); |
| 5882 | EXPECT_TRUE(child2->has_render_surface()); |
| 5883 | EXPECT_FALSE(child3->has_render_surface()); |
| 5884 | } |
| 5885 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5886 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5887 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5888 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 5889 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5890 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5891 | std::unique_ptr<LayerImpl> root = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5892 | LayerImpl::Create(host_impl.active_tree(), 12345); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5893 | std::unique_ptr<LayerImpl> child1 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5894 | LayerImpl::Create(host_impl.active_tree(), 123456); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5895 | std::unique_ptr<LayerImpl> child2 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5896 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5897 | std::unique_ptr<LayerImpl> child3 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5898 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 5899 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5900 | gfx::Size bounds(100, 100); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5901 | |
| 5902 | root->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5903 | root->SetDrawsContent(true); |
| 5904 | |
| 5905 | // This layer structure normally forces render surface due to preserves3d |
| 5906 | // behavior. |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5907 | child1->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5908 | child1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5909 | child1->Set3dSortingContextId(1); |
| 5910 | child1->test_properties()->should_flatten_transform = false; |
| 5911 | child2->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5912 | child2->SetDrawsContent(true); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 5913 | child2->Set3dSortingContextId(1); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5914 | child3->SetBounds(bounds); |
| 5915 | child3->SetDrawsContent(true); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 5916 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5917 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5918 | child2->test_properties()->AddChild(std::move(child3)); |
| 5919 | child1->test_properties()->AddChild(std::move(child2)); |
| 5920 | root->test_properties()->AddChild(std::move(child1)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5921 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5922 | root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5923 | |
| 5924 | { |
| 5925 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5926 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5927 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5928 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5929 | inputs.can_render_to_separate_surface = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5930 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5931 | |
| 5932 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5933 | |
| 5934 | int count_represents_target_render_surface = 0; |
| 5935 | int count_represents_contributing_render_surface = 0; |
| 5936 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 5937 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 5938 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5939 | it != end; ++it) { |
| 5940 | if (it.represents_target_render_surface()) |
| 5941 | count_represents_target_render_surface++; |
| 5942 | if (it.represents_contributing_render_surface()) |
| 5943 | count_represents_contributing_render_surface++; |
| 5944 | if (it.represents_itself()) |
| 5945 | count_represents_itself++; |
| 5946 | } |
| 5947 | |
| 5948 | // Two render surfaces. |
| 5949 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 5950 | // Second render surface contributes to root render surface. |
| 5951 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 5952 | // All 4 layers represent itself. |
| 5953 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | { |
| 5957 | LayerImplList render_surface_layer_list; |
| 5958 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5959 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5960 | inputs.can_render_to_separate_surface = false; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5961 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5962 | |
| 5963 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5964 | |
| 5965 | int count_represents_target_render_surface = 0; |
| 5966 | int count_represents_contributing_render_surface = 0; |
| 5967 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 5968 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 5969 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5970 | it != end; ++it) { |
| 5971 | if (it.represents_target_render_surface()) |
| 5972 | count_represents_target_render_surface++; |
| 5973 | if (it.represents_contributing_render_surface()) |
| 5974 | count_represents_contributing_render_surface++; |
| 5975 | if (it.represents_itself()) |
| 5976 | count_represents_itself++; |
| 5977 | } |
| 5978 | |
| 5979 | // Only root layer has a render surface. |
| 5980 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 5981 | // No layer contributes a render surface to root render surface. |
| 5982 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 5983 | // All 4 layers represent itself. |
| 5984 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5985 | } |
| 5986 | } |
| 5987 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5988 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5989 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5990 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 5991 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 5992 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 5993 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 5994 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5995 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5996 | child1->SetDrawsContent(true); |
| 5997 | child2->SetDrawsContent(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5998 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5999 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6000 | root->Set3dSortingContextId(1); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6001 | root->test_properties()->should_flatten_transform = false; |
| 6002 | back_facing->SetBounds(gfx::Size(50, 50)); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6003 | back_facing->Set3dSortingContextId(1); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6004 | back_facing->test_properties()->should_flatten_transform = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6005 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 6006 | render_surface1->Set3dSortingContextId(1); |
| 6007 | render_surface1->test_properties()->should_flatten_transform = false; |
| 6008 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6009 | render_surface1->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6010 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 6011 | // Different context from the rest. |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6012 | render_surface2->Set3dSortingContextId(2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6013 | render_surface2->test_properties()->should_flatten_transform = false; |
| 6014 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6015 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6016 | child1->SetBounds(gfx::Size(20, 20)); |
| 6017 | child2->SetBounds(gfx::Size(20, 20)); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6018 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6019 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6020 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6021 | EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id()); |
| 6022 | EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id()); |
| 6023 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6024 | EXPECT_EQ(2u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6025 | ->at(0) |
| 6026 | ->render_surface() |
| 6027 | ->layer_list() |
| 6028 | .size()); |
| 6029 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
| 6030 | ->at(1) |
| 6031 | ->render_surface() |
| 6032 | ->layer_list() |
| 6033 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6034 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6035 | gfx::Transform rotation_transform; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6036 | rotation_transform.RotateAboutXAxis(180.0); |
| 6037 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6038 | back_facing->test_properties()->transform = rotation_transform; |
jaydasika | 5aa88b8 | 2015-11-10 01:48:03 | [diff] [blame] | 6039 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6040 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6041 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6042 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6043 | // render_surface1 is in the same 3d rendering context as back_facing and is |
| 6044 | // not double sided, so it should not be in RSLL. render_surface2 is also not |
| 6045 | // double-sided, but will still be in RSLL as it's in a different 3d rendering |
| 6046 | // context. |
| 6047 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
| 6048 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6049 | ->at(0) |
| 6050 | ->render_surface() |
| 6051 | ->layer_list() |
| 6052 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6053 | } |
| 6054 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6055 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6056 | LayerImpl* root = root_layer_for_testing(); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6057 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 6058 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6059 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6060 | root->SetBounds(gfx::Size(50, 50)); |
| 6061 | root->test_properties()->should_flatten_transform = false; |
| 6062 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6063 | child->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6064 | child->test_properties()->should_flatten_transform = false; |
| 6065 | grand_child->SetBounds(gfx::Size(20, 20)); |
| 6066 | grand_child->SetDrawsContent(true); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6067 | grand_child->SetUseParentBackfaceVisibility(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6068 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6069 | ExecuteCalculateDrawProperties(root); |
| 6070 | |
| 6071 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6072 | EXPECT_EQ(grand_child, render_surface_layer_list_impl() |
| 6073 | ->at(0) |
| 6074 | ->render_surface() |
| 6075 | ->layer_list()[0]); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6076 | |
| 6077 | // As all layers have identity transform, we shouldn't check for backface |
| 6078 | // visibility. |
| 6079 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6080 | EXPECT_FALSE(child->should_check_backface_visibility()); |
| 6081 | EXPECT_FALSE(grand_child->should_check_backface_visibility()); |
| 6082 | // As there are no 3d rendering contexts, all layers should use their local |
| 6083 | // transform for backface visibility. |
| 6084 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6085 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6086 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6087 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6088 | gfx::Transform rotation_transform; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6089 | rotation_transform.RotateAboutXAxis(180.0); |
| 6090 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6091 | child->test_properties()->transform = rotation_transform; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6092 | child->Set3dSortingContextId(1); |
| 6093 | grand_child->Set3dSortingContextId(1); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6094 | child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6095 | |
| 6096 | ExecuteCalculateDrawProperties(root); |
| 6097 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6098 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6099 | ->at(0) |
| 6100 | ->render_surface() |
| 6101 | ->layer_list() |
| 6102 | .size()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6103 | |
| 6104 | // We should check for backface visibilty of child as it has a rotation |
| 6105 | // transform. We should also check for grand_child as it uses the backface |
| 6106 | // visibility of its parent. |
| 6107 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6108 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6109 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6110 | // child uses its local transform for backface visibility as it is the root of |
| 6111 | // a 3d rendering context. grand_child is in a 3d rendering context and is not |
| 6112 | // the root, but it derives its backface visibility from its parent which uses |
| 6113 | // its local transform. |
| 6114 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6115 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6116 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6117 | |
| 6118 | grand_child->SetUseParentBackfaceVisibility(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6119 | grand_child->test_properties()->double_sided = false; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6120 | grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6121 | |
| 6122 | ExecuteCalculateDrawProperties(root); |
| 6123 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6124 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6125 | ->at(0) |
| 6126 | ->render_surface() |
| 6127 | ->layer_list() |
| 6128 | .size()); |
| 6129 | |
| 6130 | // We should check the backface visibility of child as it has a rotation |
| 6131 | // transform and for grand_child as it is in a 3d rendering context and not |
| 6132 | // the root of it. |
| 6133 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6134 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6135 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6136 | // grand_child is in an existing 3d rendering context, so it should not use |
| 6137 | // local transform for backface visibility. |
| 6138 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6139 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6140 | EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility()); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6141 | } |
| 6142 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6143 | TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6144 | LayerImpl* root = root_layer_for_testing(); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6145 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6146 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6147 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6148 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6149 | gfx::Transform rotate_about_y; |
| 6150 | rotate_about_y.RotateAboutYAxis(180.0); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6151 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6152 | root->SetBounds(gfx::Size(50, 50)); |
| 6153 | root->Set3dSortingContextId(1); |
| 6154 | root->test_properties()->should_flatten_transform = false; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6155 | back_facing->test_properties()->transform = rotate_about_y; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6156 | back_facing->SetBounds(gfx::Size(50, 50)); |
| 6157 | back_facing->Set3dSortingContextId(1); |
| 6158 | back_facing->test_properties()->should_flatten_transform = false; |
| 6159 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 6160 | render_surface1->Set3dSortingContextId(1); |
| 6161 | render_surface1->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6162 | render_surface1->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6163 | render_surface1->test_properties()->force_render_surface = true; |
| 6164 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 6165 | render_surface2->Set3dSortingContextId(1); |
| 6166 | render_surface2->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6167 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6168 | render_surface2->test_properties()->force_render_surface = true; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6169 | ExecuteCalculateDrawProperties(root); |
| 6170 | |
| 6171 | const EffectTree& tree = |
| 6172 | root->layer_tree_impl()->property_trees()->effect_tree; |
| 6173 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6174 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6175 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6176 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6177 | |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 6178 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6179 | gfx::Transform(), back_facing->transform_tree_index(), |
| 6180 | root->layer_tree_impl()); |
| 6181 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6182 | rotate_about_y, render_surface2->transform_tree_index(), |
| 6183 | root->layer_tree_impl()); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6184 | ExecuteCalculateDrawProperties(root); |
| 6185 | EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6186 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6187 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6188 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6189 | |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 6190 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6191 | rotate_about_y, render_surface1->transform_tree_index(), |
| 6192 | root->layer_tree_impl()); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6193 | ExecuteCalculateDrawProperties(root); |
| 6194 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6195 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6196 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6197 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6198 | } |
| 6199 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6200 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 6201 | // Checks that the simple case (being clipped by a scroll parent that would |
| 6202 | // have been processed before you anyhow) results in the right clips. |
| 6203 | // |
| 6204 | // + root |
| 6205 | // + scroll_parent_border |
| 6206 | // | + scroll_parent_clip |
| 6207 | // | + scroll_parent |
| 6208 | // + scroll_child |
| 6209 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6210 | LayerImpl* root = root_layer_for_testing(); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6211 | LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>(); |
| 6212 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6213 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6214 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6215 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6216 | scroll_parent->SetDrawsContent(true); |
| 6217 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6218 | scroll_parent_clip->SetMasksToBounds(true); |
| 6219 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6220 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6221 | scroll_parent->test_properties()->scroll_children = |
| 6222 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6223 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6224 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6225 | root->SetBounds(gfx::Size(50, 50)); |
| 6226 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6227 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6228 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6229 | scroll_child->SetBounds(gfx::Size(50, 50)); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6230 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6231 | |
| 6232 | EXPECT_TRUE(root->render_surface()); |
| 6233 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6234 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6235 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6236 | } |
| 6237 | |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6238 | TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) { |
| 6239 | // Tests the computation of draw transform for the scroll child when its |
| 6240 | // target is different from its scroll parent's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6241 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6242 | LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); |
| 6243 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); |
| 6244 | LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target); |
| 6245 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); |
| 6246 | |
| 6247 | scroll_parent->SetDrawsContent(true); |
| 6248 | scroll_child->SetDrawsContent(true); |
| 6249 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6250 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6251 | scroll_parent->test_properties()->scroll_children = |
| 6252 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6253 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6254 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6255 | root->SetBounds(gfx::Size(50, 50)); |
| 6256 | scroll_child_target->SetBounds(gfx::Size(50, 50)); |
| 6257 | scroll_child_target->test_properties()->force_render_surface = true; |
| 6258 | scroll_child->SetBounds(gfx::Size(50, 50)); |
| 6259 | scroll_parent_target->SetPosition(gfx::PointF(10, 10)); |
| 6260 | scroll_parent_target->SetBounds(gfx::Size(50, 50)); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6261 | scroll_parent_target->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6262 | scroll_parent_target->test_properties()->force_render_surface = true; |
| 6263 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6264 | |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6265 | float device_scale_factor = 1.5f; |
| 6266 | LayerImplList render_surface_layer_list_impl; |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 6267 | gfx::Size device_viewport_size = |
| 6268 | gfx::Size(root->bounds().width() * device_scale_factor, |
| 6269 | root->bounds().height() * device_scale_factor); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6270 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 6271 | root, device_viewport_size, gfx::Transform(), |
| 6272 | &render_surface_layer_list_impl); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6273 | inputs.device_scale_factor = device_scale_factor; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6274 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6275 | |
weiliangc | 1da3fb89 | 2016-03-14 20:23:52 | [diff] [blame] | 6276 | EXPECT_EQ(scroll_child->effect_tree_index(), |
| 6277 | scroll_child_target->effect_tree_index()); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6278 | EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); |
| 6279 | EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); |
| 6280 | gfx::Transform scale; |
| 6281 | scale.Scale(1.5f, 1.5f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6282 | EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6283 | } |
| 6284 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6285 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6286 | LayerImpl* root = root_layer_for_testing(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6287 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6288 | LayerImpl* child = AddChild<LayerImpl>(parent); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6289 | |
| 6290 | root->SetBounds(gfx::Size(50, 50)); |
| 6291 | root->SetDrawsContent(true); |
| 6292 | root->Set3dSortingContextId(1); |
| 6293 | parent->SetBounds(gfx::Size(30, 30)); |
| 6294 | parent->SetDrawsContent(true); |
| 6295 | parent->Set3dSortingContextId(1); |
| 6296 | parent->test_properties()->force_render_surface = true; |
| 6297 | child->SetBounds(gfx::Size(20, 20)); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6298 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6299 | child->Set3dSortingContextId(1); |
| 6300 | child->test_properties()->force_render_surface = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6301 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6302 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6303 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6304 | |
| 6305 | gfx::Transform singular_transform; |
| 6306 | singular_transform.Scale3d( |
| 6307 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 6308 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6309 | child->test_properties()->transform = singular_transform; |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6310 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6311 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6312 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6313 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6314 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6315 | |
| 6316 | // Ensure that the entire subtree under a layer with singular transform does |
| 6317 | // not get rendered. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6318 | parent->test_properties()->transform = singular_transform; |
| 6319 | child->test_properties()->transform = gfx::Transform(); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6320 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6321 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6322 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6323 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6324 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6325 | } |
| 6326 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6327 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 6328 | // Checks that clipping by a scroll parent that follows you in paint order |
| 6329 | // still results in correct clipping. |
| 6330 | // |
| 6331 | // + root |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6332 | // + scroll_parent_border |
| 6333 | // + scroll_parent_clip |
| 6334 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6335 | // + scroll_child |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6336 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6337 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6338 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6339 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6340 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6341 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6342 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6343 | scroll_parent->SetDrawsContent(true); |
| 6344 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6345 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6346 | root->SetBounds(gfx::Size(50, 50)); |
| 6347 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6348 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6349 | scroll_parent_clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6350 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6351 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6352 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6353 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6354 | scroll_parent->test_properties()->scroll_children = |
| 6355 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6356 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6357 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6358 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6359 | |
| 6360 | EXPECT_TRUE(root->render_surface()); |
| 6361 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6362 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6363 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6364 | } |
| 6365 | |
| 6366 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 6367 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 6368 | // you in paint order still results in correct clipping. |
| 6369 | // |
| 6370 | // + root |
| 6371 | // + scroll_child |
| 6372 | // + scroll_parent_border |
| 6373 | // | + scroll_parent_clip |
| 6374 | // | + scroll_parent |
| 6375 | // + scroll_grandparent_border |
| 6376 | // + scroll_grandparent_clip |
| 6377 | // + scroll_grandparent |
| 6378 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6379 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6380 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6381 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6382 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6383 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6384 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6385 | LayerImpl* scroll_grandparent_clip = |
| 6386 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6387 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6388 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6389 | scroll_parent->SetDrawsContent(true); |
| 6390 | scroll_grandparent->SetDrawsContent(true); |
| 6391 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6392 | |
| 6393 | scroll_parent_clip->SetMasksToBounds(true); |
| 6394 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6395 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6396 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6397 | scroll_parent->test_properties()->scroll_children = |
| 6398 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6399 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6400 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6401 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6402 | scroll_grandparent->test_properties()->scroll_children = |
| 6403 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6404 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 6405 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6406 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6407 | root->SetBounds(gfx::Size(50, 50)); |
| 6408 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 6409 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 6410 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 6411 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6412 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6413 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6414 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6415 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6416 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6417 | |
| 6418 | EXPECT_TRUE(root->render_surface()); |
| 6419 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6420 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6421 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6422 | |
| 6423 | // Despite the fact that we visited the above layers out of order to get the |
| 6424 | // correct clip, the layer lists should be unaffected. |
| 6425 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6426 | EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0)); |
| 6427 | EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1)); |
| 6428 | EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6429 | } |
| 6430 | |
| 6431 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 6432 | // 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] | 6433 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6434 | // + root |
| 6435 | // + scroll_child |
| 6436 | // + scroll_parent_border |
| 6437 | // + scroll_parent_clip |
| 6438 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6439 | // + render_surface2 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6440 | // + scroll_grandparent_border |
| 6441 | // + scroll_grandparent_clip |
| 6442 | // + scroll_grandparent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6443 | // + render_surface1 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6444 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6445 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6446 | root->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6447 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6448 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6449 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6450 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6451 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6452 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6453 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6454 | LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent); |
| 6455 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6456 | LayerImpl* scroll_grandparent_clip = |
| 6457 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6458 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
| 6459 | LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6460 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6461 | scroll_parent->SetDrawsContent(true); |
| 6462 | render_surface1->SetDrawsContent(true); |
| 6463 | scroll_grandparent->SetDrawsContent(true); |
| 6464 | render_surface2->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6465 | |
| 6466 | scroll_parent_clip->SetMasksToBounds(true); |
| 6467 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6468 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6469 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6470 | scroll_parent->test_properties()->scroll_children = |
| 6471 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6472 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6473 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6474 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6475 | scroll_grandparent->test_properties()->scroll_children = |
| 6476 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6477 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 6478 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6479 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6480 | root->SetBounds(gfx::Size(50, 50)); |
| 6481 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 6482 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 6483 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 6484 | render_surface1->SetBounds(gfx::Size(50, 50)); |
| 6485 | render_surface1->test_properties()->force_render_surface = true; |
| 6486 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6487 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6488 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6489 | render_surface2->SetBounds(gfx::Size(50, 50)); |
| 6490 | render_surface2->test_properties()->force_render_surface = true; |
| 6491 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6492 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6493 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6494 | |
| 6495 | EXPECT_TRUE(root->render_surface()); |
| 6496 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6497 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6498 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6499 | |
| 6500 | // Despite the fact that we had to process the layers out of order to get the |
| 6501 | // right clip, our render_surface_layer_list's order should be unaffected. |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6502 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6503 | EXPECT_EQ(root, render_surface_layer_list_impl()->at(0)); |
| 6504 | EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1)); |
| 6505 | EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2)); |
| 6506 | EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface()); |
| 6507 | EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface()); |
| 6508 | EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6509 | } |
| 6510 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6511 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 6512 | // Ensures that when we have a render surface between a fixed position layer |
| 6513 | // and its container, we compute the fixed position layer's draw transform |
| 6514 | // with respect to that intervening render surface, not with respect to its |
| 6515 | // container's render target. |
| 6516 | // |
| 6517 | // + root |
| 6518 | // + render_surface |
| 6519 | // + fixed |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6520 | // + child |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6521 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6522 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6523 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 6524 | LayerImpl* fixed = AddChild<LayerImpl>(render_surface); |
| 6525 | LayerImpl* child = AddChild<LayerImpl>(fixed); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6526 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6527 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6528 | root->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6529 | |
| 6530 | LayerPositionConstraint constraint; |
| 6531 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6532 | fixed->test_properties()->position_constraint = constraint; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6533 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6534 | root->SetBounds(gfx::Size(50, 50)); |
| 6535 | render_surface->SetPosition(gfx::PointF(7.f, 9.f)); |
| 6536 | render_surface->SetBounds(gfx::Size(50, 50)); |
| 6537 | render_surface->SetDrawsContent(true); |
| 6538 | fixed->SetPosition(gfx::PointF(10.f, 15.f)); |
| 6539 | fixed->SetBounds(gfx::Size(50, 50)); |
| 6540 | fixed->SetDrawsContent(true); |
| 6541 | child->SetPosition(gfx::PointF(1.f, 2.f)); |
| 6542 | child->SetBounds(gfx::Size(50, 50)); |
| 6543 | child->SetDrawsContent(true); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6544 | ExecuteCalculateDrawProperties(root); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6545 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6546 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6547 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6548 | EffectTree& effect_tree = |
| 6549 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6550 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6551 | gfx::Transform expected_fixed_draw_transform; |
| 6552 | expected_fixed_draw_transform.Translate(10.f, 15.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6553 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6554 | expected_fixed_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6555 | draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6556 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6557 | gfx::Transform expected_fixed_screen_space_transform; |
| 6558 | expected_fixed_screen_space_transform.Translate(17.f, 24.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6559 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6560 | expected_fixed_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6561 | draw_property_utils::ScreenSpaceTransform(fixed, transform_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6562 | |
| 6563 | gfx::Transform expected_child_draw_transform; |
| 6564 | expected_child_draw_transform.Translate(11.f, 17.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6565 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6566 | expected_child_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6567 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6568 | |
| 6569 | gfx::Transform expected_child_screen_space_transform; |
| 6570 | expected_child_screen_space_transform.Translate(18.f, 26.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6571 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6572 | expected_child_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6573 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6574 | } |
| 6575 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6576 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 6577 | // This test verifies that a scrolling layer that gets snapped to |
| 6578 | // integer coordinates doesn't move a fixed position child. |
| 6579 | // |
| 6580 | // + root |
| 6581 | // + container |
| 6582 | // + scroller |
| 6583 | // + fixed |
| 6584 | // |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6585 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6586 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 6587 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6588 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6589 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6590 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 6591 | LayerImpl* root = root_ptr.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6592 | std::unique_ptr<LayerImpl> container = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6593 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 6594 | LayerImpl* container_layer = container.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6595 | std::unique_ptr<LayerImpl> scroller = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6596 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 6597 | LayerImpl* scroll_layer = scroller.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6598 | std::unique_ptr<LayerImpl> fixed = |
| 6599 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6600 | LayerImpl* fixed_layer = fixed.get(); |
| 6601 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6602 | container->test_properties()->is_container_for_fixed_position_layers = true; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6603 | |
| 6604 | LayerPositionConstraint constraint; |
| 6605 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6606 | fixed->test_properties()->position_constraint = constraint; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6607 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6608 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6609 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6610 | gfx::Transform container_transform; |
| 6611 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 6612 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 6613 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6614 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6615 | container->test_properties()->transform = container_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6616 | container->SetBounds(gfx::Size(40, 40)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6617 | container->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6618 | scroller->SetBounds(gfx::Size(30, 30)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6619 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6620 | fixed->SetBounds(gfx::Size(50, 50)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6621 | fixed->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6622 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6623 | scroller->test_properties()->AddChild(std::move(fixed)); |
| 6624 | container->test_properties()->AddChild(std::move(scroller)); |
| 6625 | root->test_properties()->AddChild(std::move(container)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6626 | root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr)); |
| 6627 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6628 | |
| 6629 | // Rounded to integers already. |
| 6630 | { |
| 6631 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6632 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6633 | |
| 6634 | LayerImplList render_surface_layer_list; |
| 6635 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6636 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6637 | root->layer_tree_impl() |
| 6638 | ->property_trees() |
| 6639 | ->transform_tree.set_source_to_parent_updates_allowed(false); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6640 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6641 | |
| 6642 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6643 | container_layer->draw_properties().screen_space_transform, |
| 6644 | fixed_layer->draw_properties().screen_space_transform); |
| 6645 | EXPECT_VECTOR_EQ( |
| 6646 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6647 | container_offset); |
| 6648 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6649 | .screen_space_transform.To2dTranslation(), |
| 6650 | container_offset - scroll_delta); |
| 6651 | } |
| 6652 | |
| 6653 | // Scroll delta requiring rounding. |
| 6654 | { |
| 6655 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6656 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6657 | |
| 6658 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 6659 | |
| 6660 | LayerImplList render_surface_layer_list; |
| 6661 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6662 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6663 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6664 | |
| 6665 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6666 | container_layer->draw_properties().screen_space_transform, |
| 6667 | fixed_layer->draw_properties().screen_space_transform); |
| 6668 | EXPECT_VECTOR_EQ( |
| 6669 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6670 | container_offset); |
| 6671 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6672 | .screen_space_transform.To2dTranslation(), |
| 6673 | container_offset - rounded_scroll_delta); |
| 6674 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6675 | |
| 6676 | // Scale is applied earlier in the tree. |
| 6677 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6678 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6679 | gfx::Transform scaled_container_transform = container_transform; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6680 | scaled_container_transform.Scale3d(2.0, 2.0, 1.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6681 | container_layer->test_properties()->transform = scaled_container_transform; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6682 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6683 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6684 | |
| 6685 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6686 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6687 | |
| 6688 | LayerImplList render_surface_layer_list; |
| 6689 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6690 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6691 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6692 | |
| 6693 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6694 | container_layer->draw_properties().screen_space_transform, |
| 6695 | fixed_layer->draw_properties().screen_space_transform); |
| 6696 | EXPECT_VECTOR_EQ( |
| 6697 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6698 | container_offset); |
| 6699 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6700 | container_layer->test_properties()->transform = container_transform; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6701 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6702 | } |
| 6703 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 6704 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6705 | ScrollSnappingWithAnimatedScreenSpaceTransform) { |
| 6706 | // This test verifies that a scrolling layer whose screen space transform is |
| 6707 | // animating doesn't get snapped to integer coordinates. |
| 6708 | // |
| 6709 | // + root |
| 6710 | // + animated layer |
| 6711 | // + surface |
| 6712 | // + container |
| 6713 | // + scroller |
| 6714 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6715 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6716 | LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>(); |
| 6717 | LayerImpl* surface = AddChild<LayerImpl>(animated_layer); |
| 6718 | LayerImpl* container = AddChild<LayerImpl>(surface); |
| 6719 | LayerImpl* scroller = AddChild<LayerImpl>(container); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6720 | |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6721 | gfx::Transform start_scale; |
| 6722 | start_scale.Scale(1.5f, 1.5f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6723 | |
| 6724 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6725 | animated_layer->test_properties()->transform = start_scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6726 | animated_layer->SetBounds(gfx::Size(50, 50)); |
| 6727 | surface->SetBounds(gfx::Size(50, 50)); |
| 6728 | surface->test_properties()->force_render_surface = true; |
| 6729 | container->SetBounds(gfx::Size(50, 50)); |
| 6730 | scroller->SetBounds(gfx::Size(100, 100)); |
| 6731 | scroller->SetScrollClipLayer(container->id()); |
| 6732 | scroller->SetDrawsContent(true); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6733 | |
| 6734 | gfx::Transform end_scale; |
| 6735 | end_scale.Scale(2.f, 2.f); |
| 6736 | TransformOperations start_operations; |
| 6737 | start_operations.AppendMatrix(start_scale); |
| 6738 | TransformOperations end_operations; |
| 6739 | end_operations.AppendMatrix(end_scale); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 6740 | SetElementIdsForTesting(); |
| 6741 | |
| 6742 | AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(), |
| 6743 | timeline_impl(), 1.0, |
| 6744 | start_operations, end_operations); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6745 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6746 | SetScrollOffsetDelta(scroller, scroll_delta); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6747 | |
| 6748 | ExecuteCalculateDrawProperties(root); |
| 6749 | |
| 6750 | gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); |
| 6751 | EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 6752 | scroller->DrawTransform().To2dTranslation()); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6753 | } |
| 6754 | |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 6755 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) { |
| 6756 | // This test verifies that a scrolling child of a scrolling layer doesn't get |
| 6757 | // snapped to integer coordinates. |
| 6758 | // |
| 6759 | // + root |
| 6760 | // + container |
| 6761 | // + scroller |
| 6762 | // + scroll_child |
| 6763 | // |
| 6764 | scoped_refptr<Layer> root = Layer::Create(); |
| 6765 | scoped_refptr<Layer> container = Layer::Create(); |
| 6766 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6767 | scoped_refptr<Layer> scroll_child = Layer::Create(); |
| 6768 | root->AddChild(container); |
| 6769 | root->AddChild(scroll_child); |
| 6770 | container->AddChild(scroller); |
| 6771 | host()->SetRootLayer(root); |
| 6772 | |
| 6773 | scroller->SetScrollClipLayerId(container->id()); |
| 6774 | scroll_child->SetScrollParent(scroller.get()); |
| 6775 | |
| 6776 | gfx::Transform rotate; |
| 6777 | rotate.RotateAboutYAxis(30); |
| 6778 | root->SetBounds(gfx::Size(50, 50)); |
| 6779 | container->SetBounds(gfx::Size(50, 50)); |
| 6780 | scroller->SetBounds(gfx::Size(100, 100)); |
| 6781 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 6782 | scroll_child->SetBounds(gfx::Size(10, 10)); |
| 6783 | scroll_child->SetTransform(rotate); |
| 6784 | |
| 6785 | ExecuteCalculateDrawProperties(root.get()); |
| 6786 | |
| 6787 | host()->host_impl()->CreatePendingTree(); |
| 6788 | host()->CommitAndCreatePendingTree(); |
| 6789 | host()->host_impl()->ActivateSyncTree(); |
| 6790 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6791 | |
| 6792 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6793 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6794 | LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id()); |
| 6795 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 6796 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 6797 | |
| 6798 | ExecuteCalculateDrawProperties(root_impl); |
| 6799 | |
| 6800 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 6801 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 6802 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6803 | |
| 6804 | gfx::Transform expected_scroll_child_screen_space_transform; |
| 6805 | expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); |
| 6806 | expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); |
| 6807 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, |
| 6808 | scroll_child_impl->ScreenSpaceTransform()); |
| 6809 | } |
| 6810 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6811 | TEST_F(LayerTreeHostCommonTest, StickyPositionTop) { |
| 6812 | scoped_refptr<Layer> root = Layer::Create(); |
| 6813 | scoped_refptr<Layer> container = Layer::Create(); |
| 6814 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6815 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6816 | root->AddChild(container); |
| 6817 | container->AddChild(scroller); |
| 6818 | scroller->AddChild(sticky_pos); |
| 6819 | host()->SetRootLayer(root); |
| 6820 | scroller->SetScrollClipLayerId(container->id()); |
| 6821 | |
| 6822 | LayerStickyPositionConstraint sticky_position; |
| 6823 | sticky_position.is_sticky = true; |
| 6824 | sticky_position.is_anchored_top = true; |
| 6825 | sticky_position.top_offset = 10.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 6826 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6827 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6828 | gfx::Rect(10, 20, 10, 10); |
| 6829 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6830 | gfx::Rect(0, 0, 50, 50); |
| 6831 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6832 | |
| 6833 | root->SetBounds(gfx::Size(100, 100)); |
| 6834 | container->SetBounds(gfx::Size(100, 100)); |
| 6835 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 6836 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6837 | sticky_pos->SetPosition(gfx::PointF(10, 20)); |
| 6838 | |
| 6839 | ExecuteCalculateDrawProperties(root.get()); |
| 6840 | host()->host_impl()->CreatePendingTree(); |
| 6841 | host()->CommitAndCreatePendingTree(); |
| 6842 | host()->host_impl()->ActivateSyncTree(); |
| 6843 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6844 | |
| 6845 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6846 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6847 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6848 | |
| 6849 | ExecuteCalculateDrawProperties(root_impl); |
| 6850 | EXPECT_VECTOR2DF_EQ( |
| 6851 | gfx::Vector2dF(10.f, 20.f), |
| 6852 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6853 | |
| 6854 | // Scroll less than sticking point, sticky element should move with scroll as |
| 6855 | // we haven't gotten to the initial sticky item location yet. |
| 6856 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 6857 | ExecuteCalculateDrawProperties(root_impl); |
| 6858 | EXPECT_VECTOR2DF_EQ( |
| 6859 | gfx::Vector2dF(5.f, 15.f), |
| 6860 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6861 | |
| 6862 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 6863 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 6864 | ExecuteCalculateDrawProperties(root_impl); |
| 6865 | EXPECT_VECTOR2DF_EQ( |
| 6866 | gfx::Vector2dF(-5.f, 10.f), |
| 6867 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6868 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f)); |
| 6869 | ExecuteCalculateDrawProperties(root_impl); |
| 6870 | EXPECT_VECTOR2DF_EQ( |
| 6871 | gfx::Vector2dF(-5.f, 10.f), |
| 6872 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6873 | |
| 6874 | // Scroll past the end of the sticky container (note: this element does not |
| 6875 | // have its own layer as it does not need to be composited). |
| 6876 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); |
| 6877 | ExecuteCalculateDrawProperties(root_impl); |
| 6878 | EXPECT_VECTOR2DF_EQ( |
| 6879 | gfx::Vector2dF(-5.f, -10.f), |
| 6880 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6881 | } |
| 6882 | |
flackr | dc5dfbe | 2016-10-24 21:43:38 | [diff] [blame] | 6883 | TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) { |
| 6884 | scoped_refptr<Layer> root = Layer::Create(); |
| 6885 | scoped_refptr<Layer> container = Layer::Create(); |
| 6886 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6887 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6888 | root->AddChild(container); |
| 6889 | container->AddChild(scroller); |
| 6890 | scroller->AddChild(sticky_pos); |
| 6891 | host()->SetRootLayer(root); |
| 6892 | scroller->SetScrollClipLayerId(container->id()); |
| 6893 | |
| 6894 | LayerStickyPositionConstraint sticky_position; |
| 6895 | sticky_position.is_sticky = true; |
| 6896 | sticky_position.is_anchored_bottom = true; |
| 6897 | sticky_position.bottom_offset = 10.0f; |
| 6898 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 200); |
| 6899 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6900 | gfx::Rect(0, 200, 10, 10); |
| 6901 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6902 | gfx::Rect(0, 0, 100, 500); |
| 6903 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6904 | |
| 6905 | root->SetBounds(gfx::Size(100, 100)); |
| 6906 | container->SetBounds(gfx::Size(100, 100)); |
| 6907 | scroller->SetBounds(gfx::Size(100, 1000)); |
| 6908 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6909 | sticky_pos->SetPosition(gfx::PointF(0, 200)); |
| 6910 | |
| 6911 | ExecuteCalculateDrawProperties(root.get()); |
| 6912 | host()->host_impl()->CreatePendingTree(); |
| 6913 | host()->CommitAndCreatePendingTree(); |
| 6914 | host()->host_impl()->ActivateSyncTree(); |
| 6915 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6916 | |
| 6917 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6918 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6919 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6920 | |
| 6921 | ExecuteCalculateDrawProperties(root_impl); |
| 6922 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.8f)); |
| 6923 | ExecuteCalculateDrawProperties(root_impl); |
| 6924 | EXPECT_VECTOR2DF_EQ( |
| 6925 | gfx::Vector2dF(0.f, 80.f), |
| 6926 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6927 | } |
| 6928 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6929 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) { |
| 6930 | scoped_refptr<Layer> root = Layer::Create(); |
| 6931 | scoped_refptr<Layer> container = Layer::Create(); |
| 6932 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6933 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6934 | root->AddChild(container); |
| 6935 | container->AddChild(scroller); |
| 6936 | scroller->AddChild(sticky_pos); |
| 6937 | host()->SetRootLayer(root); |
| 6938 | scroller->SetScrollClipLayerId(container->id()); |
| 6939 | |
| 6940 | LayerStickyPositionConstraint sticky_position; |
| 6941 | sticky_position.is_sticky = true; |
| 6942 | sticky_position.is_anchored_bottom = true; |
| 6943 | sticky_position.bottom_offset = 10.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 6944 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6945 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6946 | gfx::Rect(0, 150, 10, 10); |
| 6947 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6948 | gfx::Rect(0, 100, 50, 50); |
| 6949 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6950 | |
| 6951 | root->SetBounds(gfx::Size(100, 100)); |
| 6952 | container->SetBounds(gfx::Size(100, 100)); |
| 6953 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 6954 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6955 | sticky_pos->SetPosition(gfx::PointF(0, 150)); |
| 6956 | |
| 6957 | ExecuteCalculateDrawProperties(root.get()); |
| 6958 | host()->host_impl()->CreatePendingTree(); |
| 6959 | host()->CommitAndCreatePendingTree(); |
| 6960 | host()->host_impl()->ActivateSyncTree(); |
| 6961 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6962 | |
| 6963 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6964 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6965 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6966 | |
| 6967 | // Initially the sticky element is moved up to the top of the container. |
| 6968 | ExecuteCalculateDrawProperties(root_impl); |
| 6969 | EXPECT_VECTOR2DF_EQ( |
| 6970 | gfx::Vector2dF(0.f, 100.f), |
| 6971 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6972 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 6973 | ExecuteCalculateDrawProperties(root_impl); |
| 6974 | EXPECT_VECTOR2DF_EQ( |
| 6975 | gfx::Vector2dF(0.f, 95.f), |
| 6976 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6977 | |
| 6978 | // Once we get past the top of the container it moves to be aligned 10px |
| 6979 | // up from the the bottom of the scroller. |
| 6980 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 6981 | ExecuteCalculateDrawProperties(root_impl); |
| 6982 | EXPECT_VECTOR2DF_EQ( |
| 6983 | gfx::Vector2dF(0.f, 80.f), |
| 6984 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6985 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 6986 | ExecuteCalculateDrawProperties(root_impl); |
| 6987 | EXPECT_VECTOR2DF_EQ( |
| 6988 | gfx::Vector2dF(0.f, 80.f), |
| 6989 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6990 | |
| 6991 | // Once we scroll past its initial location, it sticks there. |
| 6992 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f)); |
| 6993 | ExecuteCalculateDrawProperties(root_impl); |
| 6994 | EXPECT_VECTOR2DF_EQ( |
| 6995 | gfx::Vector2dF(0.f, 0.f), |
| 6996 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6997 | } |
| 6998 | |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 6999 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottomHideBrowserControls) { |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 7000 | scoped_refptr<Layer> root = Layer::Create(); |
| 7001 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7002 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7003 | root->AddChild(scroller); |
| 7004 | scroller->AddChild(sticky_pos); |
| 7005 | host()->SetRootLayer(root); |
| 7006 | scroller->SetScrollClipLayerId(root->id()); |
| 7007 | host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller, |
| 7008 | nullptr); |
| 7009 | |
| 7010 | LayerStickyPositionConstraint sticky_position; |
| 7011 | sticky_position.is_sticky = true; |
| 7012 | sticky_position.is_anchored_bottom = true; |
| 7013 | sticky_position.bottom_offset = 10.0f; |
| 7014 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150); |
| 7015 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7016 | gfx::Rect(0, 150, 10, 10); |
| 7017 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7018 | gfx::Rect(0, 0, 100, 1000); |
| 7019 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7020 | |
| 7021 | root->SetBounds(gfx::Size(100, 100)); |
| 7022 | scroller->SetBounds(gfx::Size(100, 1000)); |
| 7023 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7024 | sticky_pos->SetPosition(gfx::PointF(0, 150)); |
| 7025 | |
| 7026 | ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), |
| 7027 | scroller.get()); |
| 7028 | host()->CommitAndCreateLayerImplTree(); |
| 7029 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7030 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7031 | ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id()); |
| 7032 | |
| 7033 | LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
| 7034 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7035 | |
| 7036 | // Initially the sticky element is moved to the bottom of the container. |
| 7037 | EXPECT_VECTOR2DF_EQ( |
| 7038 | gfx::Vector2dF(0.f, 80.f), |
| 7039 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7040 | |
| 7041 | // When we show the toolbar we hide part of the scroll container, this should |
| 7042 | // move the sticky element up to remain at the bottom of the clipped |
| 7043 | // container. |
| 7044 | root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
| 7045 | ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll); |
| 7046 | EXPECT_VECTOR2DF_EQ( |
| 7047 | gfx::Vector2dF(0.f, 70.f), |
| 7048 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7049 | } |
| 7050 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7051 | TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { |
| 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_left = true; |
| 7065 | sticky_position.is_anchored_right = true; |
| 7066 | sticky_position.left_offset = 10.f; |
| 7067 | sticky_position.right_offset = 10.f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7068 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(145, 0); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7069 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7070 | gfx::Rect(145, 0, 10, 10); |
| 7071 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7072 | gfx::Rect(100, 0, 100, 100); |
| 7073 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7074 | |
| 7075 | root->SetBounds(gfx::Size(100, 100)); |
| 7076 | container->SetBounds(gfx::Size(100, 100)); |
| 7077 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7078 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7079 | sticky_pos->SetPosition(gfx::PointF(145, 0)); |
| 7080 | |
| 7081 | ExecuteCalculateDrawProperties(root.get()); |
| 7082 | host()->host_impl()->CreatePendingTree(); |
| 7083 | host()->CommitAndCreatePendingTree(); |
| 7084 | host()->host_impl()->ActivateSyncTree(); |
| 7085 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7086 | |
| 7087 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7088 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7089 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7090 | |
| 7091 | // Initially the sticky element is moved the leftmost side of the container. |
| 7092 | ExecuteCalculateDrawProperties(root_impl); |
| 7093 | EXPECT_VECTOR2DF_EQ( |
| 7094 | gfx::Vector2dF(100.f, 0.f), |
| 7095 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7096 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f)); |
| 7097 | ExecuteCalculateDrawProperties(root_impl); |
| 7098 | EXPECT_VECTOR2DF_EQ( |
| 7099 | gfx::Vector2dF(95.f, 0.f), |
| 7100 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7101 | |
| 7102 | // Once we get past the left side of the container it moves to be aligned 10px |
| 7103 | // up from the the right of the scroller. |
| 7104 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f)); |
| 7105 | ExecuteCalculateDrawProperties(root_impl); |
| 7106 | EXPECT_VECTOR2DF_EQ( |
| 7107 | gfx::Vector2dF(80.f, 0.f), |
| 7108 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7109 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f)); |
| 7110 | ExecuteCalculateDrawProperties(root_impl); |
| 7111 | EXPECT_VECTOR2DF_EQ( |
| 7112 | gfx::Vector2dF(80.f, 0.f), |
| 7113 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7114 | |
| 7115 | // When we get to the sticky element's original position we stop sticking |
| 7116 | // to the right. |
| 7117 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f)); |
| 7118 | ExecuteCalculateDrawProperties(root_impl); |
| 7119 | EXPECT_VECTOR2DF_EQ( |
| 7120 | gfx::Vector2dF(50.f, 0.f), |
| 7121 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7122 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f)); |
| 7123 | ExecuteCalculateDrawProperties(root_impl); |
| 7124 | EXPECT_VECTOR2DF_EQ( |
| 7125 | gfx::Vector2dF(40.f, 0.f), |
| 7126 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7127 | |
| 7128 | // The element starts sticking to the left once we scroll far enough. |
| 7129 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f)); |
| 7130 | ExecuteCalculateDrawProperties(root_impl); |
| 7131 | EXPECT_VECTOR2DF_EQ( |
| 7132 | gfx::Vector2dF(10.f, 0.f), |
| 7133 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7134 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f)); |
| 7135 | ExecuteCalculateDrawProperties(root_impl); |
| 7136 | EXPECT_VECTOR2DF_EQ( |
| 7137 | gfx::Vector2dF(10.f, 0.f), |
| 7138 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7139 | |
| 7140 | // Finally it stops sticking when it hits the right side of the container. |
| 7141 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f)); |
| 7142 | ExecuteCalculateDrawProperties(root_impl); |
| 7143 | EXPECT_VECTOR2DF_EQ( |
| 7144 | gfx::Vector2dF(0.f, 0.f), |
| 7145 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7146 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f)); |
| 7147 | ExecuteCalculateDrawProperties(root_impl); |
| 7148 | EXPECT_VECTOR2DF_EQ( |
| 7149 | gfx::Vector2dF(-5.f, 0.f), |
| 7150 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7151 | } |
| 7152 | |
| 7153 | // This test ensures that the compositor sticky position code correctly accounts |
| 7154 | // for the element having been given a position from the main thread sticky |
| 7155 | // position code. |
| 7156 | TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) { |
| 7157 | scoped_refptr<Layer> root = Layer::Create(); |
| 7158 | scoped_refptr<Layer> container = Layer::Create(); |
| 7159 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7160 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7161 | root->AddChild(container); |
| 7162 | container->AddChild(scroller); |
| 7163 | scroller->AddChild(sticky_pos); |
| 7164 | host()->SetRootLayer(root); |
| 7165 | scroller->SetScrollClipLayerId(container->id()); |
| 7166 | |
| 7167 | LayerStickyPositionConstraint sticky_position; |
| 7168 | sticky_position.is_sticky = true; |
| 7169 | sticky_position.is_anchored_top = true; |
| 7170 | sticky_position.top_offset = 10.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7171 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7172 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7173 | gfx::Rect(10, 20, 10, 10); |
| 7174 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7175 | gfx::Rect(0, 0, 50, 50); |
| 7176 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7177 | |
| 7178 | root->SetBounds(gfx::Size(100, 100)); |
| 7179 | container->SetBounds(gfx::Size(100, 100)); |
| 7180 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7181 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7182 | sticky_pos->SetPosition(gfx::PointF(10, 20)); |
| 7183 | |
| 7184 | ExecuteCalculateDrawProperties(root.get()); |
| 7185 | host()->host_impl()->CreatePendingTree(); |
| 7186 | host()->CommitAndCreatePendingTree(); |
| 7187 | host()->host_impl()->ActivateSyncTree(); |
| 7188 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7189 | |
| 7190 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7191 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7192 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7193 | |
| 7194 | ExecuteCalculateDrawProperties(root_impl); |
| 7195 | EXPECT_VECTOR2DF_EQ( |
| 7196 | gfx::Vector2dF(10.f, 20.f), |
| 7197 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7198 | |
| 7199 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7200 | // we haven't gotten to the initial sticky item location yet. |
| 7201 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 7202 | ExecuteCalculateDrawProperties(root_impl); |
| 7203 | EXPECT_VECTOR2DF_EQ( |
| 7204 | gfx::Vector2dF(5.f, 15.f), |
| 7205 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7206 | |
| 7207 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 7208 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 7209 | ExecuteCalculateDrawProperties(root_impl); |
| 7210 | EXPECT_VECTOR2DF_EQ( |
| 7211 | gfx::Vector2dF(-5.f, 10.f), |
| 7212 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7213 | |
| 7214 | // Now the main thread commits the new position of the sticky element. |
| 7215 | scroller->SetScrollOffset(gfx::ScrollOffset(15, 15)); |
| 7216 | sticky_pos->SetPosition(gfx::PointF(10, 25)); |
| 7217 | ExecuteCalculateDrawProperties(root.get()); |
| 7218 | host()->host_impl()->CreatePendingTree(); |
| 7219 | host()->CommitAndCreatePendingTree(); |
| 7220 | host()->host_impl()->ActivateSyncTree(); |
| 7221 | layer_tree_impl = host()->host_impl()->active_tree(); |
| 7222 | root_impl = layer_tree_impl->LayerById(root->id()); |
| 7223 | scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7224 | sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7225 | |
| 7226 | // The element should still be where it was before. We reset the delta to |
| 7227 | // (0, 0) because we have synced a scroll offset of (15, 15) from the main |
| 7228 | // thread. |
| 7229 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); |
| 7230 | ExecuteCalculateDrawProperties(root_impl); |
| 7231 | EXPECT_VECTOR2DF_EQ( |
| 7232 | gfx::Vector2dF(-5.f, 10.f), |
| 7233 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7234 | |
| 7235 | // And if we scroll a little further it remains there. |
| 7236 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); |
| 7237 | ExecuteCalculateDrawProperties(root_impl); |
| 7238 | EXPECT_VECTOR2DF_EQ( |
| 7239 | gfx::Vector2dF(-5.f, 10.f), |
| 7240 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7241 | } |
| 7242 | |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7243 | // This tests the main thread updates with a composited sticky container. In |
| 7244 | // this case the position received from main is relative to the container but |
| 7245 | // the constraint rects are relative to the ancestor scroller. |
| 7246 | TEST_F(LayerTreeHostCommonTest, StickyPositionCompositedContainer) { |
| 7247 | scoped_refptr<Layer> root = Layer::Create(); |
| 7248 | scoped_refptr<Layer> container = Layer::Create(); |
| 7249 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7250 | scoped_refptr<Layer> sticky_container = Layer::Create(); |
| 7251 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7252 | root->AddChild(container); |
| 7253 | container->AddChild(scroller); |
| 7254 | scroller->AddChild(sticky_container); |
| 7255 | sticky_container->AddChild(sticky_pos); |
| 7256 | host()->SetRootLayer(root); |
| 7257 | scroller->SetScrollClipLayerId(container->id()); |
| 7258 | |
| 7259 | LayerStickyPositionConstraint sticky_position; |
| 7260 | sticky_position.is_sticky = true; |
| 7261 | sticky_position.is_anchored_top = true; |
| 7262 | sticky_position.top_offset = 10.0f; |
| 7263 | // The sticky position layer is only offset by (0, 10) from its parent |
| 7264 | // layer, this position is used to determine the offset applied by the main |
| 7265 | // thread. |
| 7266 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 10); |
| 7267 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7268 | gfx::Rect(20, 30, 10, 10); |
| 7269 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7270 | gfx::Rect(20, 20, 30, 30); |
| 7271 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7272 | |
| 7273 | root->SetBounds(gfx::Size(100, 100)); |
| 7274 | container->SetBounds(gfx::Size(100, 100)); |
| 7275 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7276 | sticky_container->SetPosition(gfx::PointF(20, 20)); |
| 7277 | sticky_container->SetBounds(gfx::Size(30, 30)); |
| 7278 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7279 | sticky_pos->SetPosition(gfx::PointF(0, 10)); |
| 7280 | |
| 7281 | ExecuteCalculateDrawProperties(root.get()); |
| 7282 | host()->host_impl()->CreatePendingTree(); |
| 7283 | host()->CommitAndCreatePendingTree(); |
| 7284 | host()->host_impl()->ActivateSyncTree(); |
| 7285 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7286 | |
| 7287 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7288 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7289 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7290 | |
| 7291 | ExecuteCalculateDrawProperties(root_impl); |
| 7292 | EXPECT_VECTOR2DF_EQ( |
| 7293 | gfx::Vector2dF(20.f, 30.f), |
| 7294 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7295 | |
| 7296 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7297 | // we haven't gotten to the initial sticky item location yet. |
| 7298 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 7299 | ExecuteCalculateDrawProperties(root_impl); |
| 7300 | EXPECT_VECTOR2DF_EQ( |
| 7301 | gfx::Vector2dF(20.f, 25.f), |
| 7302 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7303 | |
| 7304 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 7305 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7306 | ExecuteCalculateDrawProperties(root_impl); |
| 7307 | EXPECT_VECTOR2DF_EQ( |
| 7308 | gfx::Vector2dF(20.f, 10.f), |
| 7309 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7310 | |
| 7311 | // Now the main thread commits the new position of the sticky element. |
| 7312 | scroller->SetScrollOffset(gfx::ScrollOffset(0, 25)); |
| 7313 | sticky_pos->SetPosition(gfx::PointF(0, 15)); |
| 7314 | ExecuteCalculateDrawProperties(root.get()); |
| 7315 | host()->host_impl()->CreatePendingTree(); |
| 7316 | host()->CommitAndCreatePendingTree(); |
| 7317 | host()->host_impl()->ActivateSyncTree(); |
| 7318 | layer_tree_impl = host()->host_impl()->active_tree(); |
| 7319 | root_impl = layer_tree_impl->LayerById(root->id()); |
| 7320 | scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7321 | sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7322 | |
| 7323 | // The element should still be where it was before. We reset the delta to |
| 7324 | // (0, 0) because we have synced a scroll offset of (0, 25) from the main |
| 7325 | // thread. |
| 7326 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); |
| 7327 | ExecuteCalculateDrawProperties(root_impl); |
| 7328 | EXPECT_VECTOR2DF_EQ( |
| 7329 | gfx::Vector2dF(20.f, 10.f), |
| 7330 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7331 | |
| 7332 | // And if we scroll a little further it remains there. |
| 7333 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 7334 | ExecuteCalculateDrawProperties(root_impl); |
| 7335 | EXPECT_VECTOR2DF_EQ( |
| 7336 | gfx::Vector2dF(20.f, 10.f), |
| 7337 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7338 | |
| 7339 | // And hits the bottom of the container. |
| 7340 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); |
| 7341 | ExecuteCalculateDrawProperties(root_impl); |
| 7342 | EXPECT_VECTOR2DF_EQ( |
| 7343 | gfx::Vector2dF(20.f, 5.f), |
| 7344 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7345 | } |
| 7346 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7347 | // A transform on a sticky element should not affect its sticky position. |
| 7348 | TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) { |
| 7349 | scoped_refptr<Layer> root = Layer::Create(); |
| 7350 | scoped_refptr<Layer> container = Layer::Create(); |
| 7351 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7352 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7353 | root->AddChild(container); |
| 7354 | container->AddChild(scroller); |
| 7355 | scroller->AddChild(sticky_pos); |
| 7356 | host()->SetRootLayer(root); |
| 7357 | scroller->SetScrollClipLayerId(container->id()); |
| 7358 | gfx::Transform t; |
| 7359 | t.Scale(2, 2); |
| 7360 | sticky_pos->SetTransform(t); |
| 7361 | |
| 7362 | LayerStickyPositionConstraint sticky_position; |
| 7363 | sticky_position.is_sticky = true; |
| 7364 | sticky_position.is_anchored_top = true; |
| 7365 | sticky_position.top_offset = 0.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7366 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7367 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7368 | gfx::Rect(0, 20, 10, 10); |
| 7369 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7370 | gfx::Rect(0, 0, 50, 50); |
| 7371 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7372 | |
| 7373 | root->SetBounds(gfx::Size(100, 100)); |
| 7374 | container->SetBounds(gfx::Size(100, 100)); |
| 7375 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7376 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7377 | sticky_pos->SetPosition(gfx::PointF(0, 20)); |
| 7378 | |
| 7379 | ExecuteCalculateDrawProperties(root.get()); |
| 7380 | host()->host_impl()->CreatePendingTree(); |
| 7381 | host()->CommitAndCreatePendingTree(); |
| 7382 | host()->host_impl()->ActivateSyncTree(); |
| 7383 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7384 | |
| 7385 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7386 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7387 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7388 | |
| 7389 | ExecuteCalculateDrawProperties(root_impl); |
| 7390 | EXPECT_VECTOR2DF_EQ( |
| 7391 | gfx::Vector2dF(0.f, 20.f), |
| 7392 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7393 | |
| 7394 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7395 | // we haven't gotten to the initial sticky item location yet. |
| 7396 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f)); |
| 7397 | ExecuteCalculateDrawProperties(root_impl); |
| 7398 | EXPECT_VECTOR2DF_EQ( |
| 7399 | gfx::Vector2dF(0.f, 5.f), |
| 7400 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7401 | |
| 7402 | // Scroll past the sticking point, the box is positioned at the scroller |
| 7403 | // edge. |
| 7404 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7405 | ExecuteCalculateDrawProperties(root_impl); |
| 7406 | EXPECT_VECTOR2DF_EQ( |
| 7407 | gfx::Vector2dF(0.f, 0.f), |
| 7408 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7409 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7410 | ExecuteCalculateDrawProperties(root_impl); |
| 7411 | EXPECT_VECTOR2DF_EQ( |
| 7412 | gfx::Vector2dF(0.f, 0.f), |
| 7413 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7414 | |
| 7415 | // Scroll past the end of the sticky container. |
| 7416 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); |
| 7417 | ExecuteCalculateDrawProperties(root_impl); |
| 7418 | EXPECT_VECTOR2DF_EQ( |
| 7419 | gfx::Vector2dF(0.f, -10.f), |
| 7420 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7421 | } |
| 7422 | |
| 7423 | // Tests that a transform does not affect the sticking points. The sticky |
| 7424 | // element will however move relative to the viewport due to its transform. |
| 7425 | TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) { |
| 7426 | scoped_refptr<Layer> root = Layer::Create(); |
| 7427 | scoped_refptr<Layer> container = Layer::Create(); |
| 7428 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7429 | scoped_refptr<Layer> sticky_container = Layer::Create(); |
| 7430 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7431 | root->AddChild(container); |
| 7432 | container->AddChild(scroller); |
| 7433 | scroller->AddChild(sticky_container); |
| 7434 | sticky_container->AddChild(sticky_pos); |
| 7435 | host()->SetRootLayer(root); |
| 7436 | scroller->SetScrollClipLayerId(container->id()); |
| 7437 | gfx::Transform t; |
| 7438 | t.Scale(2, 2); |
| 7439 | sticky_container->SetTransform(t); |
| 7440 | |
| 7441 | LayerStickyPositionConstraint sticky_position; |
| 7442 | sticky_position.is_sticky = true; |
| 7443 | sticky_position.is_anchored_top = true; |
| 7444 | sticky_position.top_offset = 0.0f; |
flackr | 68e1c29 | 2016-10-11 16:34:42 | [diff] [blame] | 7445 | sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 7446 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7447 | gfx::Rect(0, 20, 10, 10); |
| 7448 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7449 | gfx::Rect(0, 0, 50, 50); |
| 7450 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7451 | |
| 7452 | root->SetBounds(gfx::Size(100, 100)); |
| 7453 | container->SetBounds(gfx::Size(100, 100)); |
| 7454 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7455 | sticky_container->SetBounds(gfx::Size(50, 50)); |
| 7456 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7457 | sticky_pos->SetPosition(gfx::PointF(0, 20)); |
| 7458 | |
| 7459 | ExecuteCalculateDrawProperties(root.get()); |
| 7460 | host()->host_impl()->CreatePendingTree(); |
| 7461 | host()->CommitAndCreatePendingTree(); |
| 7462 | host()->host_impl()->ActivateSyncTree(); |
| 7463 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7464 | |
| 7465 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7466 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7467 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7468 | |
| 7469 | ExecuteCalculateDrawProperties(root_impl); |
| 7470 | EXPECT_VECTOR2DF_EQ( |
| 7471 | gfx::Vector2dF(0.f, 40.f), |
| 7472 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7473 | |
| 7474 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7475 | // we haven't gotten to the initial sticky item location yet. |
| 7476 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f)); |
| 7477 | ExecuteCalculateDrawProperties(root_impl); |
| 7478 | EXPECT_VECTOR2DF_EQ( |
| 7479 | gfx::Vector2dF(0.f, 25.f), |
| 7480 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7481 | |
| 7482 | // Scroll past the sticking point, the box is positioned at the scroller |
| 7483 | // edge but is also scaled by its container so it begins to move down. |
| 7484 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7485 | ExecuteCalculateDrawProperties(root_impl); |
| 7486 | EXPECT_VECTOR2DF_EQ( |
| 7487 | gfx::Vector2dF(0.f, 25.f), |
| 7488 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7489 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7490 | ExecuteCalculateDrawProperties(root_impl); |
| 7491 | EXPECT_VECTOR2DF_EQ( |
| 7492 | gfx::Vector2dF(0.f, 30.f), |
| 7493 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7494 | |
| 7495 | // Scroll past the end of the sticky container. |
| 7496 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); |
| 7497 | ExecuteCalculateDrawProperties(root_impl); |
| 7498 | EXPECT_VECTOR2DF_EQ( |
| 7499 | gfx::Vector2dF(0.f, 30.f), |
| 7500 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7501 | } |
| 7502 | |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7503 | TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { |
| 7504 | scoped_refptr<Layer> root = Layer::Create(); |
| 7505 | scoped_refptr<Layer> container = Layer::Create(); |
| 7506 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7507 | scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 7508 | |
| 7509 | scroller->SetIsContainerForFixedPositionLayers(true); |
| 7510 | root->AddChild(container); |
| 7511 | container->AddChild(scroller); |
| 7512 | scroller->AddChild(fixed_pos); |
| 7513 | host()->SetRootLayer(root); |
| 7514 | |
| 7515 | LayerPositionConstraint fixed_position; |
| 7516 | fixed_position.set_is_fixed_position(true); |
| 7517 | scroller->SetScrollClipLayerId(container->id()); |
| 7518 | fixed_pos->SetPositionConstraint(fixed_position); |
| 7519 | |
| 7520 | root->SetBounds(gfx::Size(50, 50)); |
| 7521 | container->SetBounds(gfx::Size(50, 50)); |
| 7522 | scroller->SetBounds(gfx::Size(50, 50)); |
| 7523 | fixed_pos->SetBounds(gfx::Size(50, 50)); |
| 7524 | |
| 7525 | gfx::Transform rotate; |
| 7526 | rotate.RotateAboutXAxis(20); |
| 7527 | container->SetTransform(rotate); |
| 7528 | |
| 7529 | ExecuteCalculateDrawProperties(root.get()); |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 7530 | TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree; |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7531 | gfx::Transform transform; |
| 7532 | tree.ComputeTranslation(fixed_pos->transform_tree_index(), |
| 7533 | container->transform_tree_index(), &transform); |
| 7534 | EXPECT_TRUE(transform.IsIdentity()); |
| 7535 | } |
| 7536 | |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 7537 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) { |
| 7538 | // This test verifies that a fixed pos child of a scrolling layer doesn't get |
| 7539 | // snapped to integer coordinates. |
| 7540 | // |
| 7541 | // + root |
| 7542 | // + container |
| 7543 | // + scroller |
| 7544 | // + fixed_pos |
| 7545 | // |
| 7546 | scoped_refptr<Layer> root = Layer::Create(); |
| 7547 | scoped_refptr<Layer> container = Layer::Create(); |
| 7548 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7549 | scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 7550 | |
| 7551 | scroller->SetIsContainerForFixedPositionLayers(true); |
| 7552 | |
| 7553 | root->AddChild(container); |
| 7554 | container->AddChild(scroller); |
| 7555 | scroller->AddChild(fixed_pos); |
| 7556 | host()->SetRootLayer(root); |
| 7557 | |
| 7558 | LayerPositionConstraint fixed_position; |
| 7559 | fixed_position.set_is_fixed_position(true); |
| 7560 | scroller->SetScrollClipLayerId(container->id()); |
| 7561 | fixed_pos->SetPositionConstraint(fixed_position); |
| 7562 | |
| 7563 | root->SetBounds(gfx::Size(50, 50)); |
| 7564 | container->SetBounds(gfx::Size(50, 50)); |
| 7565 | scroller->SetBounds(gfx::Size(100, 100)); |
| 7566 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 7567 | fixed_pos->SetBounds(gfx::Size(10, 10)); |
| 7568 | |
| 7569 | ExecuteCalculateDrawProperties(root.get()); |
| 7570 | |
| 7571 | host()->host_impl()->CreatePendingTree(); |
| 7572 | host()->CommitAndCreatePendingTree(); |
| 7573 | host()->host_impl()->ActivateSyncTree(); |
| 7574 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7575 | |
| 7576 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7577 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7578 | LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id()); |
| 7579 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 7580 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 7581 | |
| 7582 | ExecuteCalculateDrawProperties(root_impl); |
| 7583 | |
| 7584 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 7585 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 7586 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7587 | |
| 7588 | gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f, |
| 7589 | 10.3f); |
| 7590 | EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation, |
| 7591 | fixed_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7592 | } |
| 7593 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7594 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7595 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7596 | static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7597 | LayerTreeImpl* tree_impl, |
| 7598 | int id) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7599 | return base::WrapUnique( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7600 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7601 | } |
| 7602 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7603 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7604 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7605 | private: |
| 7606 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7607 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7608 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7609 | SetDrawsContent(true); |
| 7610 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7611 | }; |
| 7612 | |
| 7613 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7614 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7615 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 7616 | LayerTreeSettings settings = host()->GetSettings(); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7617 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7618 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 7619 | &task_graph_runner); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7620 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7621 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7622 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7623 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7624 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7625 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7626 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7627 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7628 | |
| 7629 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7630 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7631 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7632 | AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get(); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7633 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7634 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 7635 | parent->SetBounds(gfx::Size(1, 2)); |
| 7636 | child->SetBounds(gfx::Size(1, 2)); |
| 7637 | grand_child->SetBounds(gfx::Size(1, 2)); |
| 7638 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7639 | child->test_properties()->AddChild(std::move(grand_child)); |
| 7640 | parent->test_properties()->AddChild(std::move(child)); |
| 7641 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7642 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 7643 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7644 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7645 | |
| 7646 | // No layers have animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7647 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7648 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7649 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7650 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7651 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7652 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7653 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7654 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7655 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7656 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7657 | TransformOperations translation; |
| 7658 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7659 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7660 | scoped_refptr<AnimationTimeline> timeline; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7661 | timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7662 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7663 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7664 | host_impl.active_tree()->SetElementIdsForTesting(); |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7665 | |
| 7666 | scoped_refptr<AnimationPlayer> grand_parent_player = |
| 7667 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7668 | timeline->AttachPlayer(grand_parent_player); |
| 7669 | grand_parent_player->AttachElement(grand_parent_raw->element_id()); |
| 7670 | |
| 7671 | scoped_refptr<AnimationPlayer> parent_player = |
| 7672 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7673 | timeline->AttachPlayer(parent_player); |
| 7674 | parent_player->AttachElement(parent_raw->element_id()); |
| 7675 | |
| 7676 | scoped_refptr<AnimationPlayer> child_player = |
| 7677 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7678 | timeline->AttachPlayer(child_player); |
| 7679 | child_player->AttachElement(child_raw->element_id()); |
| 7680 | |
| 7681 | scoped_refptr<AnimationPlayer> grand_child_player = |
| 7682 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7683 | timeline->AttachPlayer(grand_child_player); |
| 7684 | grand_child_player->AttachElement(grand_child_raw->element_id()); |
| 7685 | |
| 7686 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7687 | translation); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7688 | |
| 7689 | // No layers have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7690 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7691 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7692 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7693 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7694 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7695 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7696 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7697 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7698 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7699 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7700 | TransformOperations scale; |
| 7701 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7702 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7703 | AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(), |
| 7704 | scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7705 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7706 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7707 | |
| 7708 | // Only |child| has a scale-affecting animation. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7709 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7710 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7711 | EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw)); |
| 7712 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7713 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7714 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7715 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7716 | EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw)); |
| 7717 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7718 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7719 | AddAnimatedTransformToPlayer(grand_parent_player.get(), 1.0, |
| 7720 | TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7721 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7722 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7723 | |
| 7724 | // |grand_parent| and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7725 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7726 | EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7727 | // We don't support combining animated scales from two nodes; 0.f means |
| 7728 | // that the maximum scale could not be computed. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7729 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7730 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7731 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7732 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7733 | EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw)); |
| 7734 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7735 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7736 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7737 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7738 | scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7739 | parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7740 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7741 | |
| 7742 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7743 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7744 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7745 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7746 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7747 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7748 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7749 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7750 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7751 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7752 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7753 | grand_parent_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 7754 | parent_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 7755 | child_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7756 | |
| 7757 | TransformOperations perspective; |
| 7758 | perspective.AppendPerspective(10.f); |
| 7759 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7760 | AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(), |
| 7761 | perspective); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7762 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7763 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7764 | |
| 7765 | // |child| has a scale-affecting animation but computing the maximum of this |
| 7766 | // animation is not supported. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7767 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7768 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7769 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7770 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7771 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7772 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7773 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7774 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7775 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7776 | |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 7777 | child_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 7778 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7779 | gfx::Transform scale_matrix; |
| 7780 | scale_matrix.Scale(1.f, 2.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7781 | grand_parent_raw->test_properties()->transform = scale_matrix; |
| 7782 | parent_raw->test_properties()->transform = scale_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7783 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7784 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7785 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7786 | scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7787 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7788 | |
| 7789 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 7790 | // animation with maximum scale 5.f. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7791 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7792 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 7793 | EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw)); |
| 7794 | EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7795 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7796 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7797 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 7798 | EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw)); |
| 7799 | EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7800 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7801 | gfx::Transform perspective_matrix; |
| 7802 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7803 | child_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7804 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7805 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7806 | |
| 7807 | // |child| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7808 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7809 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 7810 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7811 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7812 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7813 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7814 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 7815 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7816 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7817 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7818 | parent_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7819 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7820 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7821 | |
| 7822 | // |parent| and |child| have transforms that are neither translations nor |
| 7823 | // scales. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7824 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7825 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7826 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7827 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7828 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7829 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7830 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7831 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7832 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7833 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7834 | parent_raw->test_properties()->transform = gfx::Transform(); |
| 7835 | child_raw->test_properties()->transform = gfx::Transform(); |
| 7836 | grand_parent_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7837 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7838 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7839 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7840 | |
| 7841 | // |grand_parent| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7842 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7843 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7844 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7845 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7846 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7847 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7848 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7849 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7850 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7851 | } |
| 7852 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 7853 | static void GatherDrawnLayers(const LayerImplList* rsll, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7854 | std::set<LayerImpl*>* drawn_layers) { |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 7855 | for (LayerIterator it = LayerIterator::Begin(rsll), |
| 7856 | end = LayerIterator::End(rsll); |
| 7857 | it != end; ++it) { |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7858 | LayerImpl* layer = *it; |
| 7859 | if (it.represents_itself()) |
| 7860 | drawn_layers->insert(layer); |
| 7861 | |
| 7862 | if (!it.represents_contributing_render_surface()) |
| 7863 | continue; |
| 7864 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7865 | if (layer->render_surface()->MaskLayer()) |
| 7866 | drawn_layers->insert(layer->render_surface()->MaskLayer()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7867 | } |
| 7868 | } |
| 7869 | |
| 7870 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7871 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7872 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 7873 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7874 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7875 | std::unique_ptr<LayerImpl> grand_parent = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7876 | LayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7877 | std::unique_ptr<LayerImpl> parent = |
| 7878 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7879 | std::unique_ptr<LayerImpl> child = |
| 7880 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7881 | std::unique_ptr<LayerImpl> grand_child1 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7882 | LayerImpl::Create(host_impl.active_tree(), 7); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7883 | std::unique_ptr<LayerImpl> grand_child2 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7884 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 7885 | |
| 7886 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 7887 | LayerImpl* parent_raw = parent.get(); |
| 7888 | LayerImpl* child_raw = child.get(); |
| 7889 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 7890 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 7891 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7892 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 7893 | parent->SetBounds(gfx::Size(1, 2)); |
| 7894 | child->SetBounds(gfx::Size(1, 2)); |
| 7895 | grand_child1->SetBounds(gfx::Size(1, 2)); |
| 7896 | grand_child2->SetBounds(gfx::Size(1, 2)); |
| 7897 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7898 | child->test_properties()->AddChild(std::move(grand_child1)); |
| 7899 | child->test_properties()->AddChild(std::move(grand_child2)); |
| 7900 | parent->test_properties()->AddChild(std::move(child)); |
| 7901 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7902 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7903 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7904 | // Start with nothing being drawn. |
| 7905 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7906 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7907 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7908 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7909 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7910 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7911 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7912 | |
| 7913 | std::set<LayerImpl*> expected; |
| 7914 | std::set<LayerImpl*> actual; |
| 7915 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7916 | EXPECT_EQ(expected, actual); |
| 7917 | |
| 7918 | // If we force render surface, but none of the layers are in the layer list, |
| 7919 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7920 | grand_child1_raw->SetHasRenderSurface(true); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7921 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7922 | |
| 7923 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7924 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7925 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7926 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7927 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7928 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7929 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7930 | |
| 7931 | expected.clear(); |
| 7932 | actual.clear(); |
| 7933 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7934 | EXPECT_EQ(expected, actual); |
| 7935 | |
| 7936 | // However, if we say that this layer also draws content, it will appear in |
| 7937 | // RSLL. |
| 7938 | grand_child1_raw->SetDrawsContent(true); |
| 7939 | |
| 7940 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7941 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7942 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7943 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7944 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7945 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7946 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7947 | |
| 7948 | expected.clear(); |
| 7949 | expected.insert(grand_child1_raw); |
| 7950 | |
| 7951 | actual.clear(); |
| 7952 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7953 | EXPECT_EQ(expected, actual); |
| 7954 | |
| 7955 | // Now child is forced to have a render surface, and one if its children draws |
| 7956 | // content. |
| 7957 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7958 | grand_child1_raw->SetHasRenderSurface(false); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7959 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7960 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7961 | grand_child2_raw->SetDrawsContent(true); |
| 7962 | |
| 7963 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7964 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7965 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7966 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7967 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7968 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7969 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7970 | |
| 7971 | expected.clear(); |
| 7972 | expected.insert(grand_child2_raw); |
| 7973 | |
| 7974 | actual.clear(); |
| 7975 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7976 | EXPECT_EQ(expected, actual); |
| 7977 | |
| 7978 | // Add a mask layer to child. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7979 | child_raw->test_properties()->SetMaskLayer( |
| 7980 | LayerImpl::Create(host_impl.active_tree(), 6)); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7981 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7982 | |
| 7983 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7984 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7985 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7986 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7987 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7988 | EXPECT_TRUE(child_raw->test_properties() |
| 7989 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7990 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7991 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7992 | |
| 7993 | expected.clear(); |
| 7994 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7995 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7996 | |
| 7997 | expected.clear(); |
| 7998 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7999 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8000 | |
| 8001 | actual.clear(); |
| 8002 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8003 | EXPECT_EQ(expected, actual); |
| 8004 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8005 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8006 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8007 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8008 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8009 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8010 | EXPECT_TRUE(child_raw->test_properties() |
| 8011 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8012 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8013 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8014 | |
| 8015 | expected.clear(); |
| 8016 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8017 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8018 | |
| 8019 | actual.clear(); |
| 8020 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8021 | EXPECT_EQ(expected, actual); |
| 8022 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8023 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8024 | |
| 8025 | // With nothing drawing, we should have no layers. |
| 8026 | grand_child2_raw->SetDrawsContent(false); |
| 8027 | |
| 8028 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8029 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8030 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8031 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8032 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8033 | EXPECT_FALSE(child_raw->test_properties() |
| 8034 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8035 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8036 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8037 | |
| 8038 | expected.clear(); |
| 8039 | actual.clear(); |
| 8040 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8041 | EXPECT_EQ(expected, actual); |
| 8042 | |
| 8043 | // Child itself draws means that we should have the child and the mask in the |
| 8044 | // list. |
| 8045 | child_raw->SetDrawsContent(true); |
| 8046 | |
| 8047 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8048 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8049 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8050 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8051 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8052 | EXPECT_TRUE(child_raw->test_properties() |
| 8053 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8054 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8055 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8056 | |
| 8057 | expected.clear(); |
| 8058 | expected.insert(child_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8059 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8060 | actual.clear(); |
| 8061 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8062 | EXPECT_EQ(expected, actual); |
| 8063 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8064 | child_raw->test_properties()->SetMaskLayer(nullptr); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 8065 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8066 | |
| 8067 | // Now everyone's a member! |
| 8068 | grand_parent_raw->SetDrawsContent(true); |
| 8069 | parent_raw->SetDrawsContent(true); |
| 8070 | child_raw->SetDrawsContent(true); |
| 8071 | grand_child1_raw->SetDrawsContent(true); |
| 8072 | grand_child2_raw->SetDrawsContent(true); |
| 8073 | |
| 8074 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8075 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8076 | EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8077 | EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 8078 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 8079 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 8080 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8081 | |
| 8082 | expected.clear(); |
| 8083 | expected.insert(grand_parent_raw); |
| 8084 | expected.insert(parent_raw); |
| 8085 | expected.insert(child_raw); |
| 8086 | expected.insert(grand_child1_raw); |
| 8087 | expected.insert(grand_child2_raw); |
| 8088 | |
| 8089 | actual.clear(); |
| 8090 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8091 | EXPECT_EQ(expected, actual); |
| 8092 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8093 | |
| 8094 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8095 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8096 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8097 | LayerTreeSettings settings = host()->GetSettings(); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8098 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8099 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 8100 | &task_graph_runner); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8101 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8102 | std::unique_ptr<LayerImpl> root = |
| 8103 | LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8104 | LayerImpl* root_layer = root.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8105 | std::unique_ptr<LayerImpl> child1 = |
| 8106 | LayerImpl::Create(host_impl.active_tree(), 2); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8107 | LayerImpl* child1_layer = child1.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8108 | std::unique_ptr<LayerImpl> child2 = |
| 8109 | LayerImpl::Create(host_impl.active_tree(), 3); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8110 | LayerImpl* child2_layer = child2.get(); |
| 8111 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8112 | gfx::Transform scale_transform_child1, scale_transform_child2; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8113 | scale_transform_child1.Scale(2, 3); |
| 8114 | scale_transform_child2.Scale(4, 5); |
| 8115 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8116 | root->SetBounds(gfx::Size(1, 1)); |
| 8117 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8118 | child1_layer->test_properties()->transform = scale_transform_child1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8119 | child1_layer->SetBounds(gfx::Size(1, 1)); |
| 8120 | child1_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8121 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8122 | child1_layer->test_properties()->SetMaskLayer( |
| 8123 | LayerImpl::Create(host_impl.active_tree(), 4)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8124 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8125 | root->test_properties()->AddChild(std::move(child1)); |
| 8126 | root->test_properties()->AddChild(std::move(child2)); |
| 8127 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8128 | host_impl.active_tree()->SetElementIdsForTesting(); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8129 | |
| 8130 | ExecuteCalculateDrawProperties(root_layer); |
| 8131 | |
| 8132 | TransformOperations scale; |
| 8133 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8134 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8135 | scoped_refptr<AnimationTimeline> timeline = |
| 8136 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8137 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8138 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8139 | child2_layer->test_properties()->transform = scale_transform_child2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8140 | child2_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 8141 | child2_layer->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8142 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 8143 | 1.0, TransformOperations(), scale); |
| 8144 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8145 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8146 | ExecuteCalculateDrawProperties(root_layer); |
| 8147 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8148 | EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale()); |
| 8149 | EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8150 | EXPECT_FLOAT_EQ( |
| 8151 | 3.f, |
| 8152 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8153 | EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8154 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8155 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8156 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8157 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8158 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8159 | // Changing page-scale would affect ideal_contents_scale and |
| 8160 | // maximum_animation_contents_scale. |
| 8161 | |
| 8162 | float page_scale_factor = 3.f; |
| 8163 | float device_scale_factor = 1.0f; |
| 8164 | std::vector<LayerImpl*> render_surface_layer_list; |
| 8165 | gfx::Size device_viewport_size = |
| 8166 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 8167 | root_layer->bounds().height() * device_scale_factor); |
| 8168 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8169 | root_layer, device_viewport_size, &render_surface_layer_list); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8170 | |
| 8171 | inputs.page_scale_factor = page_scale_factor; |
| 8172 | inputs.can_adjust_raster_scales = true; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 8173 | inputs.page_scale_layer = root_layer; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8174 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8175 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8176 | EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale()); |
| 8177 | EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8178 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8179 | 9.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8180 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8181 | EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8182 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8183 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8184 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8185 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8186 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8187 | // Changing device-scale would affect ideal_contents_scale and |
| 8188 | // maximum_animation_contents_scale. |
| 8189 | |
| 8190 | device_scale_factor = 4.0f; |
| 8191 | inputs.device_scale_factor = device_scale_factor; |
| 8192 | inputs.can_adjust_raster_scales = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8193 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8194 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8195 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8196 | EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale()); |
| 8197 | EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8198 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8199 | 36.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 8200 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8201 | EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8202 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8203 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8204 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8205 | EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer)); |
| 8206 | } |
| 8207 | |
| 8208 | TEST_F(LayerTreeHostCommonTest, AnimationScales) { |
| 8209 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8210 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8211 | LayerTreeSettings settings = host()->GetSettings(); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8212 | settings.layer_transforms_should_scale_layer_contents = true; |
| 8213 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 8214 | &task_graph_runner); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8215 | |
| 8216 | std::unique_ptr<LayerImpl> root = |
| 8217 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8218 | LayerImpl* root_layer = root.get(); |
| 8219 | std::unique_ptr<LayerImpl> child1 = |
| 8220 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8221 | LayerImpl* child1_layer = child1.get(); |
| 8222 | std::unique_ptr<LayerImpl> child2 = |
| 8223 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 8224 | LayerImpl* child2_layer = child2.get(); |
| 8225 | |
| 8226 | root->test_properties()->AddChild(std::move(child1)); |
| 8227 | child1_layer->test_properties()->AddChild(std::move(child2)); |
| 8228 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8229 | |
| 8230 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 8231 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8232 | gfx::Transform scale_transform_child1, scale_transform_child2; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8233 | scale_transform_child1.Scale(2, 3); |
| 8234 | scale_transform_child2.Scale(4, 5); |
| 8235 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8236 | root_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8237 | child1_layer->test_properties()->transform = scale_transform_child1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8238 | child1_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8239 | child2_layer->test_properties()->transform = scale_transform_child2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8240 | child2_layer->SetBounds(gfx::Size(1, 1)); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8241 | |
| 8242 | TransformOperations scale; |
| 8243 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8244 | |
| 8245 | scoped_refptr<AnimationTimeline> timeline = |
| 8246 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8247 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 8248 | |
| 8249 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 8250 | 1.0, TransformOperations(), scale); |
| 8251 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8252 | // Correctly computes animation scale when rebuilding property trees. |
| 8253 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8254 | ExecuteCalculateDrawProperties(root_layer); |
| 8255 | |
| 8256 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8257 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8258 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
| 8259 | |
| 8260 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 8261 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer)); |
| 8262 | EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer)); |
| 8263 | |
| 8264 | // Correctly updates animation scale when layer property changes. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8265 | child1_layer->test_properties()->transform = gfx::Transform(); |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 8266 | root_layer->layer_tree_impl() |
| 8267 | ->property_trees() |
| 8268 | ->transform_tree.OnTransformAnimated(gfx::Transform(), |
| 8269 | child1_layer->transform_tree_index(), |
| 8270 | root_layer->layer_tree_impl()); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8271 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false; |
| 8272 | ExecuteCalculateDrawProperties(root_layer); |
| 8273 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
| 8274 | EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer)); |
| 8275 | |
| 8276 | // Do not update animation scale if already updated. |
| 8277 | host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting( |
| 8278 | child2_layer->transform_tree_index(), 100.f, 100.f); |
| 8279 | EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer)); |
| 8280 | EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer)); |
| 8281 | } |
| 8282 | |
| 8283 | TEST_F(LayerTreeHostCommonTest, |
| 8284 | AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) { |
| 8285 | // Returns empty scale if layer_transforms_should_scale_layer_contents is |
| 8286 | // false. |
| 8287 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8288 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8289 | LayerTreeSettings settings = host()->GetSettings(); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8290 | settings.layer_transforms_should_scale_layer_contents = false; |
| 8291 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 8292 | &task_graph_runner); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8293 | |
| 8294 | std::unique_ptr<LayerImpl> root = |
| 8295 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8296 | LayerImpl* root_layer = root.get(); |
| 8297 | std::unique_ptr<LayerImpl> child = |
| 8298 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8299 | LayerImpl* child_layer = child.get(); |
| 8300 | |
| 8301 | root->test_properties()->AddChild(std::move(child)); |
| 8302 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8303 | |
| 8304 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 8305 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8306 | gfx::Transform scale_transform_child; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8307 | scale_transform_child.Scale(4, 5); |
| 8308 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8309 | root_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8310 | child_layer->test_properties()->transform = scale_transform_child; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8311 | child_layer->SetBounds(gfx::Size(1, 1)); |
| 8312 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8313 | TransformOperations scale; |
| 8314 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8315 | |
| 8316 | scoped_refptr<AnimationTimeline> timeline = |
| 8317 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8318 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 8319 | |
| 8320 | AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline, |
| 8321 | 1.0, TransformOperations(), scale); |
| 8322 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8323 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8324 | ExecuteCalculateDrawProperties(root_layer); |
| 8325 | |
| 8326 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8327 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer)); |
| 8328 | |
| 8329 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 8330 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8331 | } |
| 8332 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8333 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8334 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8335 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 8336 | LayerImpl* content = AddChild<LayerImpl>(clip); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8337 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8338 | root->SetBounds(gfx::Size(768 / 2, 3000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8339 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8340 | clip->SetBounds(gfx::Size(768 / 2, 10000)); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8341 | clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8342 | content->SetBounds(gfx::Size(768 / 2, 10000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8343 | content->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8344 | content->test_properties()->force_render_surface = true; |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8345 | |
| 8346 | gfx::Size device_viewport_size(768, 582); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8347 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8348 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8349 | root, device_viewport_size, gfx::Transform(), |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8350 | &render_surface_layer_list_impl); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8351 | inputs.device_scale_factor = 2.f; |
| 8352 | inputs.page_scale_factor = 1.f; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 8353 | inputs.page_scale_layer = nullptr; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8354 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8355 | |
| 8356 | // Layers in the root render surface have their visible content rect clipped |
| 8357 | // by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8358 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8359 | |
| 8360 | // Layers drawing to a child render surface should still have their visible |
| 8361 | // content rect clipped by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8362 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8363 | } |
| 8364 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8365 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8366 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8367 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 8368 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8369 | |
| 8370 | // Set two layers: the root layer clips it's child, |
| 8371 | // the child draws its content. |
| 8372 | |
| 8373 | gfx::Size root_size = gfx::Size(300, 500); |
| 8374 | |
| 8375 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8376 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8377 | |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 8378 | // Device viewport accomidated the root and the browser controls. |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8379 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8380 | |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 8381 | host_impl.SetViewportSize(device_viewport_size); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8382 | host_impl.active_tree()->SetRootLayerForTesting( |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8383 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8384 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8385 | LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8386 | root->SetBounds(root_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8387 | root->SetMasksToBounds(true); |
| 8388 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8389 | root->test_properties()->AddChild( |
| 8390 | LayerImpl::Create(host_impl.active_tree(), 2)); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8391 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 8392 | LayerImpl* sublayer = root->test_properties()->children[0]; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8393 | sublayer->SetBounds(sublayer_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8394 | sublayer->SetDrawsContent(true); |
| 8395 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8396 | host_impl.active_tree()->BuildPropertyTreesForTesting(); |
| 8397 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8398 | LayerImplList layer_impl_list; |
| 8399 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8400 | root, device_viewport_size, &layer_impl_list); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8401 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8402 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8403 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8404 | |
| 8405 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8406 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8407 | |
| 8408 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8409 | root_size.height() + 50); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8410 | EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8411 | } |
| 8412 | |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8413 | TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8414 | scoped_refptr<Layer> root = Layer::Create(); |
| 8415 | scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create(); |
| 8416 | scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); |
| 8417 | scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create(); |
| 8418 | scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8419 | |
| 8420 | root->AddChild(inner_viewport_container_layer); |
| 8421 | inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer); |
| 8422 | inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); |
| 8423 | outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); |
| 8424 | |
| 8425 | inner_viewport_scroll_layer->SetScrollClipLayerId( |
| 8426 | inner_viewport_container_layer->id()); |
| 8427 | outer_viewport_scroll_layer->SetScrollClipLayerId( |
| 8428 | outer_viewport_container_layer->id()); |
| 8429 | |
| 8430 | inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8431 | outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8432 | |
| 8433 | host()->SetRootLayer(root); |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 8434 | host()->GetLayerTree()->RegisterViewportLayers( |
| 8435 | nullptr, root, inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8436 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8437 | scoped_refptr<Layer> fixed_to_inner = Layer::Create(); |
| 8438 | scoped_refptr<Layer> fixed_to_outer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8439 | |
| 8440 | inner_viewport_scroll_layer->AddChild(fixed_to_inner); |
| 8441 | outer_viewport_scroll_layer->AddChild(fixed_to_outer); |
| 8442 | |
| 8443 | LayerPositionConstraint fixed_to_right; |
| 8444 | fixed_to_right.set_is_fixed_position(true); |
| 8445 | fixed_to_right.set_is_fixed_to_right_edge(true); |
| 8446 | |
| 8447 | fixed_to_inner->SetPositionConstraint(fixed_to_right); |
| 8448 | fixed_to_outer->SetPositionConstraint(fixed_to_right); |
| 8449 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8450 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8451 | |
| 8452 | TransformTree& transform_tree = host()->property_trees()->transform_tree; |
| 8453 | EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8454 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8455 | |
| 8456 | LayerPositionConstraint fixed_to_left; |
| 8457 | fixed_to_left.set_is_fixed_position(true); |
| 8458 | fixed_to_inner->SetPositionConstraint(fixed_to_left); |
| 8459 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8460 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8461 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8462 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8463 | |
| 8464 | fixed_to_outer->SetPositionConstraint(fixed_to_left); |
| 8465 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8466 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8467 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8468 | EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8469 | } |
| 8470 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8471 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8472 | host_impl()->CreatePendingTree(); |
| 8473 | std::unique_ptr<LayerImpl> pending_root = |
| 8474 | LayerImpl::Create(host_impl()->pending_tree(), 1); |
| 8475 | LayerImpl* root = pending_root.get(); |
| 8476 | host_impl()->pending_tree()->SetRootLayerForTesting(std::move(pending_root)); |
| 8477 | std::unique_ptr<LayerImpl> animated_ptr = |
| 8478 | LayerImpl::Create(host_impl()->pending_tree(), 2); |
| 8479 | LayerImpl* animated = animated_ptr.get(); |
| 8480 | root->test_properties()->AddChild(std::move(animated_ptr)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8481 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8482 | animated->SetDrawsContent(true); |
| 8483 | host_impl()->pending_tree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8484 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8485 | root->SetBounds(gfx::Size(100, 100)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8486 | root->SetMasksToBounds(true); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8487 | root->test_properties()->force_render_surface = true; |
| 8488 | animated->test_properties()->opacity = 0.f; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8489 | animated->SetBounds(gfx::Size(20, 20)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8490 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8491 | AddOpacityTransitionToElementWithPlayer( |
| 8492 | animated->element_id(), timeline_impl(), 10.0, 0.f, 1.f, false); |
| 8493 | animated->test_properties()->opacity_can_animate = true; |
| 8494 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8495 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8496 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8497 | EXPECT_FALSE(animated->visible_layer_rect().IsEmpty()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8498 | } |
| 8499 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8500 | TEST_F(LayerTreeHostCommonTest, |
| 8501 | VisibleContentRectForAnimatedLayerWithSingularTransform) { |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8502 | LayerImpl* root = root_layer_for_testing(); |
| 8503 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 8504 | LayerImpl* animated = AddChild<LayerImpl>(clip); |
| 8505 | LayerImpl* surface = AddChild<LayerImpl>(animated); |
| 8506 | LayerImpl* descendant_of_animation = AddChild<LayerImpl>(surface); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8507 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8508 | SetElementIdsForTesting(); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8509 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8510 | animated->SetDrawsContent(true); |
| 8511 | surface->SetDrawsContent(true); |
| 8512 | descendant_of_animation->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8513 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8514 | gfx::Transform uninvertible_matrix; |
| 8515 | uninvertible_matrix.Scale3d(6.f, 6.f, 0.f); |
| 8516 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8517 | root->SetBounds(gfx::Size(100, 100)); |
| 8518 | clip->SetBounds(gfx::Size(10, 10)); |
| 8519 | clip->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8520 | animated->test_properties()->transform = uninvertible_matrix; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8521 | animated->SetBounds(gfx::Size(120, 120)); |
| 8522 | surface->SetBounds(gfx::Size(100, 100)); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8523 | surface->test_properties()->force_render_surface = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8524 | descendant_of_animation->SetBounds(gfx::Size(200, 200)); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8525 | |
| 8526 | TransformOperations start_transform_operations; |
| 8527 | start_transform_operations.AppendMatrix(uninvertible_matrix); |
| 8528 | TransformOperations end_transform_operations; |
| 8529 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8530 | AddAnimatedTransformToElementWithPlayer( |
| 8531 | animated->element_id(), timeline_impl(), 10.0, start_transform_operations, |
| 8532 | end_transform_operations); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8533 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8534 | |
| 8535 | // The animated layer has a singular transform and maps to a non-empty rect in |
| 8536 | // clipped target space, so is treated as fully visible. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8537 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8538 | |
| 8539 | // The singular transform on |animated| is flattened when inherited by |
| 8540 | // |surface|, and this happens to make it invertible. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8541 | EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect()); |
| 8542 | EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8543 | |
| 8544 | gfx::Transform zero_matrix; |
| 8545 | zero_matrix.Scale3d(0.f, 0.f, 0.f); |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 8546 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 8547 | zero_matrix, animated->transform_tree_index(), root->layer_tree_impl()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8548 | // While computing visible rects by combining clips in screen space, we set |
| 8549 | // the entire layer as visible if the screen space transform is singular. This |
| 8550 | // is not always true when we combine clips in target space because if the |
| 8551 | // intersection of combined_clip in taret space with layer_rect projected to |
| 8552 | // target space is empty, we set it to an empty rect. |
| 8553 | bool skip_verify_visible_rect_calculations = true; |
| 8554 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
| 8555 | root, skip_verify_visible_rect_calculations); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8556 | |
| 8557 | // The animated layer maps to the empty rect in clipped target space, so is |
| 8558 | // treated as having an empty visible rect. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8559 | EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8560 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8561 | // The animated layer will be treated as fully visible when we combine clips |
| 8562 | // in screen space. |
| 8563 | gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic( |
| 8564 | root->layer_tree_impl()->property_trees(), animated); |
| 8565 | EXPECT_EQ(gfx::Rect(120, 120), visible_rect); |
| 8566 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8567 | // This time, flattening does not make |animated|'s transform invertible. This |
| 8568 | // means the clip cannot be projected into |surface|'s space, so we treat |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8569 | // |surface| and layers that draw into it as having empty visible rect. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8570 | EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect()); |
| 8571 | EXPECT_EQ(gfx::Rect(), descendant_of_animation->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8572 | } |
| 8573 | |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8574 | // Verify that having animated opacity but current opacity 1 still creates |
| 8575 | // a render surface. |
| 8576 | TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) { |
| 8577 | LayerImpl* root = root_layer_for_testing(); |
| 8578 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8579 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8580 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8581 | root->SetBounds(gfx::Size(50, 50)); |
| 8582 | child->SetBounds(gfx::Size(50, 50)); |
| 8583 | child->SetDrawsContent(true); |
| 8584 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8585 | grandchild->SetDrawsContent(true); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8586 | |
| 8587 | SetElementIdsForTesting(); |
| 8588 | AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8589 | 10.0, 1.f, 0.2f, false); |
| 8590 | ExecuteCalculateDrawProperties(root); |
| 8591 | |
| 8592 | EXPECT_EQ(1.f, child->Opacity()); |
| 8593 | EXPECT_TRUE(root->has_render_surface()); |
| 8594 | EXPECT_TRUE(child->has_render_surface()); |
| 8595 | EXPECT_FALSE(grandchild->has_render_surface()); |
| 8596 | } |
| 8597 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8598 | // Verify that having an animated filter (but no current filter, as these |
| 8599 | // are mutually exclusive) correctly creates a render surface. |
| 8600 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8601 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8602 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8603 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8604 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8605 | root->SetBounds(gfx::Size(50, 50)); |
| 8606 | child->SetBounds(gfx::Size(50, 50)); |
| 8607 | grandchild->SetBounds(gfx::Size(50, 50)); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8608 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8609 | SetElementIdsForTesting(); |
| 8610 | AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8611 | 10.0, 0.1f, 0.2f); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8612 | ExecuteCalculateDrawProperties(root); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8613 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8614 | EXPECT_TRUE(root->has_render_surface()); |
| 8615 | EXPECT_TRUE(child->has_render_surface()); |
| 8616 | EXPECT_FALSE(grandchild->has_render_surface()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8617 | |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 8618 | EXPECT_TRUE(root->render_surface()->Filters().IsEmpty()); |
| 8619 | EXPECT_TRUE(child->render_surface()->Filters().IsEmpty()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8620 | |
| 8621 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8622 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 8623 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8624 | } |
| 8625 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8626 | // Verify that having a filter animation with a delayed start time creates a |
| 8627 | // render surface. |
| 8628 | TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8629 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8630 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8631 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8632 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8633 | root->SetBounds(gfx::Size(50, 50)); |
| 8634 | child->SetBounds(gfx::Size(50, 50)); |
| 8635 | grandchild->SetBounds(gfx::Size(50, 50)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8636 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8637 | SetElementIdsForTesting(); |
| 8638 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8639 | std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8640 | KeyframedFilterAnimationCurve::Create()); |
| 8641 | FilterOperations start_filters; |
| 8642 | start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f)); |
| 8643 | FilterOperations end_filters; |
| 8644 | end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f)); |
| 8645 | curve->AddKeyframe( |
| 8646 | FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 8647 | curve->AddKeyframe(FilterKeyframe::Create( |
| 8648 | base::TimeDelta::FromMilliseconds(100), end_filters, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8649 | std::unique_ptr<Animation> animation = |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8650 | Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8651 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8652 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8653 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8654 | AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8655 | std::move(animation)); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8656 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8657 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8658 | EXPECT_TRUE(root->has_render_surface()); |
| 8659 | EXPECT_TRUE(child->has_render_surface()); |
| 8660 | EXPECT_FALSE(grandchild->has_render_surface()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8661 | |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 8662 | EXPECT_TRUE(root->render_surface()->Filters().IsEmpty()); |
| 8663 | EXPECT_TRUE(child->render_surface()->Filters().IsEmpty()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8664 | |
| 8665 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8666 | EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation()); |
| 8667 | EXPECT_FALSE(child->FilterIsAnimating()); |
| 8668 | EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation()); |
| 8669 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8670 | EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation()); |
| 8671 | } |
| 8672 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8673 | // Ensures that the property tree code accounts for offsets between fixed |
| 8674 | // position layers and their respective containers. |
| 8675 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8676 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8677 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8678 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8679 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8680 | root->SetBounds(gfx::Size(50, 50)); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8681 | root->SetMasksToBounds(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8682 | root->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8683 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 8684 | child->SetBounds(gfx::Size(50, 50)); |
| 8685 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 8686 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8687 | grandchild->SetDrawsContent(true); |
| 8688 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8689 | LayerPositionConstraint constraint; |
| 8690 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8691 | grandchild->test_properties()->position_constraint = constraint; |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8692 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8693 | ExecuteCalculateDrawProperties(root); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8694 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8695 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8696 | } |
| 8697 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8698 | // Ensures that the property tree code accounts for offsets between fixed |
| 8699 | // position containers and their transform tree parents, when a fixed position |
| 8700 | // layer's container is its layer tree parent, but this parent doesn't have its |
| 8701 | // own transform tree node. |
| 8702 | TEST_F(LayerTreeHostCommonTest, |
| 8703 | PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8704 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8705 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8706 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8707 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8708 | root->SetBounds(gfx::Size(50, 50)); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8709 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8710 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 8711 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 8712 | child->SetBounds(gfx::Size(50, 50)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8713 | child->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8714 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 8715 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8716 | grandchild->SetDrawsContent(true); |
| 8717 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8718 | LayerPositionConstraint constraint; |
| 8719 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8720 | grandchild->test_properties()->position_constraint = constraint; |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8721 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8722 | ExecuteCalculateDrawProperties(root); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8723 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8724 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8725 | } |
| 8726 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8727 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8728 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8729 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8730 | LayerImpl* fixed = AddChild<LayerImpl>(frame_clip); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8731 | gfx::Transform translate_z; |
| 8732 | translate_z.Translate3d(0, 0, 10); |
| 8733 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8734 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8735 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8736 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8737 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 8738 | frame_clip->SetBounds(gfx::Size(100, 100)); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8739 | frame_clip->SetMasksToBounds(true); |
| 8740 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8741 | fixed->SetBounds(gfx::Size(1000, 1000)); |
| 8742 | fixed->SetDrawsContent(true); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8743 | |
| 8744 | LayerPositionConstraint constraint; |
| 8745 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8746 | fixed->test_properties()->position_constraint = constraint; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8747 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8748 | ExecuteCalculateDrawProperties(root); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8749 | |
| 8750 | gfx::Rect expected(0, 0, 100, 100); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8751 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8752 | } |
| 8753 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8754 | TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8755 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8756 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8757 | LayerImpl* scroller = AddChild<LayerImpl>(frame_clip); |
| 8758 | LayerImpl* fixed = AddChild<LayerImpl>(scroller); |
| 8759 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8760 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8761 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8762 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 8763 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 8764 | frame_clip->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8765 | frame_clip->SetMasksToBounds(true); |
| 8766 | frame_clip->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8767 | scroller->SetBounds(gfx::Size(1000, 1000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8768 | scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100)); |
| 8769 | scroller->SetScrollClipLayer(frame_clip->id()); |
| 8770 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8771 | fixed->SetPosition(gfx::PointF(100, 100)); |
| 8772 | fixed->SetBounds(gfx::Size(50, 50)); |
| 8773 | fixed->SetMasksToBounds(true); |
| 8774 | fixed->SetDrawsContent(true); |
| 8775 | fixed->test_properties()->force_render_surface = true; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8776 | |
| 8777 | LayerPositionConstraint constraint; |
| 8778 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8779 | fixed->test_properties()->position_constraint = constraint; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8780 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8781 | ExecuteCalculateDrawProperties(root); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8782 | |
| 8783 | gfx::Rect expected(0, 0, 50, 50); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8784 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8785 | } |
| 8786 | |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8787 | TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) { |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8788 | gfx::Transform translate; |
| 8789 | gfx::Transform rotate; |
| 8790 | |
| 8791 | translate.Translate(10, 10); |
| 8792 | rotate.Rotate(45); |
| 8793 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8794 | scoped_refptr<Layer> root = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8795 | root->SetBounds(gfx::Size(800, 800)); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8796 | root->SetIsContainerForFixedPositionLayers(true); |
| 8797 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8798 | host()->SetRootLayer(root); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8799 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8800 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8801 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8802 | |
| 8803 | root->SetTransform(translate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8804 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8805 | |
| 8806 | root->SetTransform(rotate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8807 | EXPECT_TRUE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8808 | } |
| 8809 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8810 | TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8811 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8812 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8813 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8814 | gfx::Transform scale_matrix; |
| 8815 | scale_matrix.Scale(2.f, 2.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8816 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8817 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8818 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8819 | child->test_properties()->transform = scale_matrix; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8820 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8821 | child->SetDrawsContent(true); |
| 8822 | |
| 8823 | ExecuteCalculateDrawProperties(root); |
| 8824 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8825 | |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 8826 | child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8827 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8828 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8829 | ExecuteCalculateDrawProperties(root); |
| 8830 | EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8831 | } |
| 8832 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8833 | TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8834 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8835 | LayerImpl* scroll_parent = AddChild<LayerImpl>(root); |
| 8836 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8837 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8838 | gfx::Transform scale; |
| 8839 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8840 | |
| 8841 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8842 | scroll_child->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8843 | scroll_child->SetBounds(gfx::Size(40, 40)); |
| 8844 | scroll_child->SetDrawsContent(true); |
| 8845 | scroll_parent->SetBounds(gfx::Size(30, 30)); |
| 8846 | scroll_parent->SetDrawsContent(true); |
| 8847 | |
| 8848 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 8849 | scroll_parent->test_properties()->scroll_children = |
| 8850 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 8851 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8852 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8853 | ExecuteCalculateDrawProperties(root); |
| 8854 | EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8855 | |
| 8856 | scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8857 | scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
| 8858 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8859 | ExecuteCalculateDrawProperties(root); |
| 8860 | EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8861 | } |
| 8862 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8863 | static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8864 | |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8865 | TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) { |
| 8866 | // If the layer has a node in effect_tree, the return value of |
| 8867 | // num_copy_requests_in_target_subtree() must be equal to the actual number |
| 8868 | // of copy requests in the sub-layer_tree; Otherwise, the number is expected |
| 8869 | // to be the value of its nearest ancestor that owns an effect node and |
| 8870 | // greater than or equal to the actual number of copy requests in the |
| 8871 | // sub-layer_tree. |
| 8872 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8873 | scoped_refptr<Layer> root = Layer::Create(); |
| 8874 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 8875 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 8876 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 8877 | scoped_refptr<Layer> greatgrandchild = Layer::Create(); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8878 | |
| 8879 | root->AddChild(child1); |
| 8880 | root->AddChild(child2); |
| 8881 | child1->AddChild(grandchild); |
| 8882 | grandchild->AddChild(greatgrandchild); |
| 8883 | host()->SetRootLayer(root); |
| 8884 | |
| 8885 | child1->RequestCopyOfOutput( |
| 8886 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8887 | greatgrandchild->RequestCopyOfOutput( |
| 8888 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8889 | child2->SetOpacity(0.f); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8890 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8891 | |
| 8892 | EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2); |
| 8893 | EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2); |
| 8894 | EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0); |
| 8895 | EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2); |
| 8896 | EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1); |
| 8897 | } |
| 8898 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8899 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8900 | scoped_refptr<Layer> root = Layer::Create(); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 8901 | FakeContentLayerClient client; |
| 8902 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8903 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8904 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8905 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8906 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8907 | scoped_refptr<FakePictureLayer> greatgrandchild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8908 | FakePictureLayer::Create(&client)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8909 | |
| 8910 | root->SetBounds(gfx::Size(100, 100)); |
| 8911 | child->SetBounds(gfx::Size(10, 10)); |
| 8912 | grandchild->SetBounds(gfx::Size(10, 10)); |
| 8913 | greatgrandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8914 | |
| 8915 | root->AddChild(child); |
| 8916 | child->AddChild(grandchild); |
| 8917 | grandchild->AddChild(greatgrandchild); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8918 | host()->SetRootLayer(root); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 8919 | host()->GetLayerTree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8920 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8921 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8922 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8923 | const LayerList* update_list = GetUpdateLayerList(); |
| 8924 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8925 | |
| 8926 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8927 | // and we will configure |child| in several ways that should force the subtree |
| 8928 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8929 | // remain empty. |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8930 | gfx::Transform singular; |
| 8931 | singular.matrix().set(0, 0, 0); |
| 8932 | |
| 8933 | child->SetTransform(singular); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8934 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8935 | update_list = GetUpdateLayerList(); |
| 8936 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8937 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8938 | |
| 8939 | child->SetHideLayerAndSubtree(true); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8940 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8941 | update_list = GetUpdateLayerList(); |
| 8942 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8943 | child->SetHideLayerAndSubtree(false); |
| 8944 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8945 | gfx::Transform zero_z_scale; |
| 8946 | zero_z_scale.Scale3d(1, 1, 0); |
| 8947 | child->SetTransform(zero_z_scale); |
| 8948 | |
| 8949 | // Add a transform animation with a start delay. Now, even though |child| has |
| 8950 | // a singular transform, the subtree should still get processed. |
| 8951 | int animation_id = 0; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8952 | std::unique_ptr<Animation> animation = Animation::Create( |
| 8953 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8954 | animation_id, 1, TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8955 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8956 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8957 | AddAnimationToElementWithPlayer(child->element_id(), timeline(), |
| 8958 | std::move(animation)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8959 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8960 | update_list = GetUpdateLayerList(); |
| 8961 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8962 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8963 | RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(), |
| 8964 | animation_id); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8965 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8966 | child->SetOpacity(0.f); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8967 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8968 | update_list = GetUpdateLayerList(); |
| 8969 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8970 | |
| 8971 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8972 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8973 | // processed anyhow. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 8974 | grandchild->RequestCopyOfOutput( |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8975 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8976 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8977 | update_list = GetUpdateLayerList(); |
| 8978 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8979 | |
| 8980 | // Add an opacity animation with a start delay. |
| 8981 | animation_id = 1; |
| 8982 | animation = Animation::Create( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8983 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8984 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8985 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8986 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8987 | AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(), |
| 8988 | std::move(animation)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8989 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8990 | update_list = GetUpdateLayerList(); |
| 8991 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8992 | } |
| 8993 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8994 | TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8995 | FakeImplTaskRunnerProvider task_runner_provider; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8996 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 8997 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8998 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8999 | std::unique_ptr<LayerImpl> root = |
| 9000 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 9001 | std::unique_ptr<LayerImpl> child = |
| 9002 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 9003 | std::unique_ptr<LayerImpl> grandchild = |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9004 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 9005 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9006 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 9007 | FakePictureLayerImpl::Create(host_impl.active_tree(), 4)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9008 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9009 | root->SetBounds(gfx::Size(100, 100)); |
| 9010 | child->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9011 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9012 | grandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9013 | grandchild->SetDrawsContent(true); |
| 9014 | greatgrandchild->SetDrawsContent(true); |
| 9015 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 9016 | LayerImpl* root_ptr = root.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9017 | LayerImpl* child_ptr = child.get(); |
| 9018 | LayerImpl* grandchild_ptr = grandchild.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9019 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9020 | child->test_properties()->AddChild(std::move(grandchild)); |
| 9021 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9022 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9023 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9024 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 9025 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9026 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9027 | // ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9028 | // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9029 | |
| 9030 | // Now we will reset the visible rect from property trees for the grandchild, |
| 9031 | // and we will configure |child| in several ways that should force the subtree |
| 9032 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 9033 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9034 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9035 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9036 | gfx::Transform singular; |
| 9037 | singular.matrix().set(0, 0, 0); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9038 | // This line is used to make the results of skipping and not skipping layers |
| 9039 | // different. |
| 9040 | singular.matrix().set(0, 1, 1); |
| 9041 | |
| 9042 | gfx::Transform rotate; |
| 9043 | rotate.Rotate(90); |
| 9044 | |
| 9045 | gfx::Transform rotate_back_and_translate; |
| 9046 | rotate_back_and_translate.RotateAboutYAxis(180); |
| 9047 | rotate_back_and_translate.Translate(-10, 0); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9048 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9049 | child_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9050 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9051 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9052 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9053 | child_ptr->test_properties()->transform = gfx::Transform(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9054 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9055 | child_ptr->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9056 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9057 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9058 | child_ptr->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9059 | |
jaydasika | b5bc1a2 | 2016-08-24 02:59:05 | [diff] [blame] | 9060 | child_ptr->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 9061 | 0.f, child_ptr->effect_tree_index(), child_ptr->layer_tree_impl()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9062 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9063 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9064 | child_ptr->test_properties()->opacity = 1.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9065 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9066 | root_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9067 | // Force transform tree to have a node for child, so that ancestor's |
| 9068 | // invertible transform can be tested. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9069 | child_ptr->test_properties()->transform = rotate; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9070 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9071 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9072 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9073 | root_ptr->test_properties()->transform = gfx::Transform(); |
| 9074 | child_ptr->test_properties()->transform = gfx::Transform(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9075 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9076 | root_ptr->test_properties()->opacity = 0.f; |
| 9077 | child_ptr->test_properties()->opacity = 0.7f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9078 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9079 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9080 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9081 | root_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9082 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9083 | child_ptr->test_properties()->opacity = 0.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9084 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 9085 | // |greatgrandchild| in several ways that should force the subtree to be |
| 9086 | // processed anyhow. |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 9087 | grandchild_ptr->test_properties()->copy_requests.push_back( |
| 9088 | CopyOutputRequest::CreateEmptyRequest()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 9089 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9090 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9091 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 9092 | |
| 9093 | host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests(); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9094 | child_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9095 | |
| 9096 | // A double sided render surface with backface visible should not be skipped |
| 9097 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9098 | child_ptr->SetHasRenderSurface(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9099 | child_ptr->test_properties()->double_sided = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9100 | child_ptr->test_properties()->transform = rotate_back_and_translate; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9101 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9102 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9103 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9104 | child_ptr->test_properties()->transform = gfx::Transform(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9105 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9106 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9107 | KeyframedTransformAnimationCurve::Create()); |
| 9108 | TransformOperations start; |
| 9109 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 9110 | gfx::Transform transform; |
| 9111 | transform.Scale3d(1.0, 2.0, 3.0); |
| 9112 | TransformOperations operation; |
| 9113 | operation.AppendMatrix(transform); |
| 9114 | curve->AddKeyframe( |
| 9115 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 9116 | curve->AddKeyframe(TransformKeyframe::Create( |
| 9117 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9118 | std::unique_ptr<Animation> transform_animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9119 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 9120 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 9121 | host_impl.active_tree()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9122 | root_ptr->element_id(), player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 9123 | player->AddAnimation(std::move(transform_animation)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9124 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9125 | child_ptr->SetScrollClipLayer(root_ptr->id()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9126 | root_ptr->test_properties()->transform = singular; |
| 9127 | child_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9128 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9129 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9130 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9131 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 9132 | host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9133 | root_ptr->element_id(), player.get()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9134 | } |
| 9135 | |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9136 | TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9137 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9138 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 9139 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 9140 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9141 | SetElementIdsForTesting(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9142 | |
| 9143 | gfx::Transform singular; |
| 9144 | singular.matrix().set(0, 0, 0); |
| 9145 | singular.matrix().set(0, 1, 1); |
| 9146 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9147 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9148 | child->test_properties()->transform = singular; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9149 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9150 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9151 | grand_child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9152 | grand_child->SetDrawsContent(true); |
| 9153 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 9154 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9155 | KeyframedTransformAnimationCurve::Create()); |
| 9156 | TransformOperations start; |
| 9157 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 9158 | gfx::Transform transform; |
| 9159 | transform.Scale3d(1.0, 2.0, 3.0); |
| 9160 | TransformOperations operation; |
| 9161 | operation.AppendMatrix(transform); |
| 9162 | curve->AddKeyframe( |
| 9163 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 9164 | curve->AddKeyframe(TransformKeyframe::Create( |
| 9165 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 9166 | std::unique_ptr<Animation> transform_animation( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9167 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 9168 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 9169 | host_impl()->active_tree()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9170 | grand_child->element_id(), player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 9171 | player->AddAnimation(std::move(transform_animation)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9172 | |
| 9173 | ExecuteCalculateDrawProperties(root); |
| 9174 | EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect()); |
| 9175 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
| 9176 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 9177 | host_impl()->active_tree()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9178 | grand_child->element_id(), player.get()); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 9179 | } |
| 9180 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9181 | TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { |
| 9182 | FakeImplTaskRunnerProvider task_runner_provider; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9183 | TestTaskGraphRunner task_graph_runner; |
piman | c44437a2 | 2016-10-29 00:09:22 | [diff] [blame^] | 9184 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9185 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9186 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9187 | std::unique_ptr<LayerImpl> root = |
| 9188 | LayerImpl::Create(host_impl.pending_tree(), 1); |
| 9189 | std::unique_ptr<LayerImpl> child = |
| 9190 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 9191 | std::unique_ptr<LayerImpl> grandchild = |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9192 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 9193 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9194 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9195 | FakePictureLayerImpl::Create(host_impl.pending_tree(), 4)); |
| 9196 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9197 | root->SetBounds(gfx::Size(100, 100)); |
| 9198 | child->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9199 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9200 | grandchild->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9201 | grandchild->SetDrawsContent(true); |
| 9202 | greatgrandchild->SetDrawsContent(true); |
| 9203 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9204 | LayerImpl* root_ptr = root.get(); |
| 9205 | LayerImpl* grandchild_ptr = grandchild.get(); |
| 9206 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9207 | child->test_properties()->AddChild(std::move(grandchild)); |
| 9208 | root->test_properties()->AddChild(std::move(child)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9209 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9210 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9211 | host_impl.pending_tree()->SetElementIdsForTesting(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9212 | |
| 9213 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9214 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9215 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9216 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9217 | std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9218 | KeyframedFloatAnimationCurve::Create()); |
loyso | 1e4e7ee | 2016-06-03 03:04:49 | [diff] [blame] | 9219 | std::unique_ptr<TimingFunction> func = |
| 9220 | CubicBezierTimingFunction::CreatePreset( |
| 9221 | CubicBezierTimingFunction::EaseType::EASE); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9222 | curve->AddKeyframe( |
| 9223 | FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func))); |
| 9224 | curve->AddKeyframe( |
| 9225 | FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9226 | std::unique_ptr<Animation> animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9227 | Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY)); |
| 9228 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 9229 | host_impl.active_tree()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9230 | root_ptr->element_id(), player.get()); |
loyso | bb50779 | 2016-10-04 05:31:02 | [diff] [blame] | 9231 | player->AddAnimation(std::move(animation)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9232 | root_ptr->test_properties()->opacity = 0.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9233 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9234 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9235 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9236 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9237 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 9238 | host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9239 | root_ptr->element_id(), player.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9240 | } |
| 9241 | |
| 9242 | TEST_F(LayerTreeHostCommonTest, SkippingLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9243 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9244 | LayerImpl* child = AddChild<LayerImpl>(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9245 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9246 | root->SetBounds(gfx::Size(100, 100)); |
| 9247 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9248 | child->SetDrawsContent(true); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9249 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9250 | ExecuteCalculateDrawProperties(root); |
| 9251 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9252 | child->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9253 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9254 | child->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9255 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9256 | ExecuteCalculateDrawProperties(root); |
| 9257 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9258 | child->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9259 | |
| 9260 | child->SetBounds(gfx::Size()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9261 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9262 | ExecuteCalculateDrawProperties(root); |
| 9263 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9264 | child->SetBounds(gfx::Size(10, 10)); |
| 9265 | |
| 9266 | gfx::Transform rotate; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9267 | child->test_properties()->double_sided = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9268 | rotate.RotateAboutXAxis(180.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9269 | child->test_properties()->transform = rotate; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9270 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9271 | ExecuteCalculateDrawProperties(root); |
| 9272 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9273 | child->test_properties()->double_sided = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9274 | child->test_properties()->transform = gfx::Transform(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9275 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9276 | child->test_properties()->opacity = 0.f; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9277 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9278 | ExecuteCalculateDrawProperties(root); |
| 9279 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9280 | } |
| 9281 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9282 | TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) { |
| 9283 | // Ensure that the treewalk in LayerTreeHostCommom:: |
| 9284 | // PreCalculateMetaInformation happens when its required. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9285 | scoped_refptr<Layer> root = Layer::Create(); |
| 9286 | scoped_refptr<Layer> parent = Layer::Create(); |
| 9287 | scoped_refptr<Layer> child = Layer::Create(); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9288 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9289 | root->SetBounds(gfx::Size(100, 100)); |
| 9290 | parent->SetBounds(gfx::Size(100, 100)); |
| 9291 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9292 | child->SetClipParent(root.get()); |
| 9293 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9294 | root->AddChild(parent); |
| 9295 | parent->AddChild(child); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9296 | host()->SetRootLayer(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9297 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9298 | child->RequestCopyOfOutput( |
| 9299 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9300 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9301 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9302 | EXPECT_EQ(parent->num_unclipped_descendants(), 1u); |
| 9303 | |
| 9304 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9305 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9306 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9307 | } |
| 9308 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9309 | TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) { |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9310 | scoped_refptr<Layer> root = Layer::Create(); |
| 9311 | root->SetBounds(gfx::Size(800, 800)); |
| 9312 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9313 | gfx::Transform translate_z; |
| 9314 | translate_z.Translate3d(0, 0, 10); |
| 9315 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9316 | scoped_refptr<Layer> child = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9317 | child->SetTransform(translate_z); |
| 9318 | child->SetBounds(gfx::Size(100, 100)); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9319 | |
| 9320 | root->AddChild(child); |
| 9321 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9322 | host()->SetRootLayer(root); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9323 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9324 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9325 | EXPECT_NE(-1, child->transform_tree_index()); |
| 9326 | |
| 9327 | child->RemoveFromParent(); |
| 9328 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9329 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9330 | EXPECT_EQ(-1, child->transform_tree_index()); |
| 9331 | } |
| 9332 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9333 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { |
| 9334 | // Ensure that a Clip Node is added when a render surface applies clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9335 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9336 | LayerImpl* significant_transform = AddChildToRoot<LayerImpl>(); |
| 9337 | LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform); |
| 9338 | LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree); |
| 9339 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9340 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9341 | // This transform should be a significant one so that a transform node is |
| 9342 | // formed for it. |
| 9343 | gfx::Transform transform1; |
| 9344 | transform1.RotateAboutYAxis(45); |
| 9345 | transform1.RotateAboutXAxis(30); |
| 9346 | // This transform should be a 3d transform as we want the render surface |
| 9347 | // to flatten the transform |
| 9348 | gfx::Transform transform2; |
| 9349 | transform2.Translate3d(10, 10, 10); |
| 9350 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9351 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9352 | significant_transform->test_properties()->transform = transform1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9353 | significant_transform->SetBounds(gfx::Size(30, 30)); |
| 9354 | layer_clips_subtree->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9355 | layer_clips_subtree->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9356 | layer_clips_subtree->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9357 | render_surface->test_properties()->transform = transform2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9358 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9359 | render_surface->test_properties()->force_render_surface = true; |
| 9360 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9361 | test_layer->SetDrawsContent(true); |
| 9362 | |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9363 | float device_scale_factor = 1.f; |
| 9364 | float page_scale_factor = 1.f; |
| 9365 | LayerImpl* page_scale_layer = nullptr; |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 9366 | LayerImpl* inner_viewport_scroll_layer = nullptr; |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9367 | // Visible rects computed by combining clips in target space and root space |
| 9368 | // don't match because of rotation transforms. So, we skip |
| 9369 | // verify_visible_rect_calculations. |
| 9370 | bool skip_verify_visible_rect_calculations = true; |
| 9371 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
flackr | e310f29 | 2016-10-12 21:09:28 | [diff] [blame] | 9372 | page_scale_layer, inner_viewport_scroll_layer, |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9373 | skip_verify_visible_rect_calculations); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9374 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9375 | TransformTree& transform_tree = |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9376 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9377 | TransformNode* transform_node = |
| 9378 | transform_tree.Node(significant_transform->transform_tree_index()); |
| 9379 | EXPECT_EQ(transform_node->owner_id, significant_transform->id()); |
| 9380 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9381 | EXPECT_TRUE(root->has_render_surface()); |
| 9382 | EXPECT_FALSE(significant_transform->has_render_surface()); |
| 9383 | EXPECT_TRUE(layer_clips_subtree->has_render_surface()); |
| 9384 | EXPECT_TRUE(render_surface->has_render_surface()); |
| 9385 | EXPECT_FALSE(test_layer->has_render_surface()); |
| 9386 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9387 | ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9388 | ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); |
ajuma | 259f1e7 | 2016-10-24 16:25:38 | [diff] [blame] | 9389 | EXPECT_EQ(clip_node->clip_type, ClipNode::ClipType::NONE); |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 9390 | EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect()); |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9391 | |
| 9392 | // Also test the visible rects computed by combining clips in root space. |
| 9393 | gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic( |
| 9394 | root->layer_tree_impl()->property_trees(), test_layer); |
| 9395 | EXPECT_EQ(gfx::Rect(30, 20), visible_rect); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9396 | } |
| 9397 | |
| 9398 | TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 9399 | // Ensure that when parent clip node's transform is an ancestor of current |
| 9400 | // clip node's target, clip is 'projected' from parent space to current |
| 9401 | // target space and visible rects are calculated correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9402 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9403 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9404 | LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 9405 | LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| 9406 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9407 | gfx::Transform transform; |
| 9408 | transform.RotateAboutYAxis(45); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9409 | |
| 9410 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9411 | clip_layer->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9412 | clip_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9413 | clip_layer->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9414 | target_layer->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9415 | target_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9416 | target_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9417 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9418 | test_layer->SetDrawsContent(true); |
| 9419 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9420 | ExecuteCalculateDrawProperties(root); |
| 9421 | |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9422 | EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9423 | } |
| 9424 | |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9425 | TEST_F(LayerTreeHostCommonTest, |
| 9426 | RenderSurfaceWithUnclippedDescendantsClipsSubtree) { |
| 9427 | // Ensure clip rect is calculated correctly when render surface has unclipped |
| 9428 | // descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9429 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9430 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9431 | LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); |
| 9432 | LayerImpl* render_surface = |
| 9433 | AddChild<LayerImpl>(between_clip_parent_and_child); |
| 9434 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9435 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9436 | gfx::Transform translate; |
| 9437 | translate.Translate(2.0, 2.0); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9438 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9439 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9440 | clip_parent->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9441 | clip_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9442 | clip_parent->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9443 | between_clip_parent_and_child->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9444 | between_clip_parent_and_child->SetBounds(gfx::Size(30, 30)); |
| 9445 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9446 | render_surface->test_properties()->force_render_surface = true; |
| 9447 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9448 | test_layer->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9449 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9450 | render_surface->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9451 | clip_parent->test_properties()->clip_children = |
| 9452 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9453 | clip_parent->test_properties()->clip_children->insert(render_surface); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9454 | |
| 9455 | ExecuteCalculateDrawProperties(root); |
| 9456 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9457 | EXPECT_TRUE(test_layer->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 9458 | EXPECT_FALSE(test_layer->render_target()->is_clipped()); |
weiliangc | 0b41eaf | 2016-03-14 21:35:56 | [diff] [blame] | 9459 | EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect()); |
| 9460 | EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9461 | } |
| 9462 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9463 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9464 | RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) { |
| 9465 | // Ensure that the visible layer rect of a descendant of a surface with |
| 9466 | // unclipped descendants is computed correctly, when the surface doesn't apply |
| 9467 | // a clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9468 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9469 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9470 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9471 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9472 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 9473 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9474 | root->SetBounds(gfx::Size(30, 10)); |
| 9475 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 9476 | render_surface->SetBounds(gfx::Size(10, 15)); |
| 9477 | render_surface->test_properties()->force_render_surface = true; |
| 9478 | clip_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9479 | clip_child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9480 | child->SetBounds(gfx::Size(40, 40)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9481 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9482 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9483 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9484 | clip_parent->test_properties()->clip_children = |
| 9485 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9486 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9487 | |
| 9488 | ExecuteCalculateDrawProperties(root); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 9489 | EXPECT_EQ(gfx::Rect(30, 10), child->visible_layer_rect()); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9490 | } |
| 9491 | |
| 9492 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9493 | RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9494 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9495 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9496 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9497 | LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface); |
| 9498 | LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1); |
| 9499 | LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child); |
| 9500 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9501 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9502 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9503 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 9504 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9505 | render_surface->SetMasksToBounds(true); |
| 9506 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9507 | render_surface->test_properties()->force_render_surface = true; |
| 9508 | test_layer1->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9509 | test_layer1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9510 | clip_child->SetBounds(gfx::Size(50, 50)); |
| 9511 | clip_child->SetDrawsContent(true); |
| 9512 | test_layer2->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9513 | test_layer2->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9514 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9515 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9516 | clip_parent->test_properties()->clip_children = |
| 9517 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9518 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9519 | |
| 9520 | ExecuteCalculateDrawProperties(root); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9521 | EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect()); |
| 9522 | EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect()); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9523 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
| 9524 | EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect()); |
| 9525 | } |
| 9526 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9527 | TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9528 | LayerImpl* root = root_layer_for_testing(); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9529 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9530 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9531 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9532 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9533 | root->SetBounds(gfx::Size(50, 50)); |
| 9534 | clip_parent->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9535 | clip_parent->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9536 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9537 | render_surface->test_properties()->force_render_surface = true; |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9538 | render_surface->SetMasksToBounds(true); |
| 9539 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9540 | clip_child->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9541 | clip_child->SetDrawsContent(true); |
| 9542 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9543 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9544 | clip_parent->test_properties()->clip_children = |
| 9545 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9546 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9547 | |
| 9548 | ExecuteCalculateDrawProperties(root); |
| 9549 | |
| 9550 | // The clip child should inherit its clip parent's clipping state, not its |
| 9551 | // tree parent's clipping state. |
| 9552 | EXPECT_FALSE(clip_parent->is_clipped()); |
| 9553 | EXPECT_TRUE(render_surface->is_clipped()); |
| 9554 | EXPECT_FALSE(clip_child->is_clipped()); |
| 9555 | } |
| 9556 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9557 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) { |
| 9558 | // Tests the value of render surface content rect when we have multiple types |
| 9559 | // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and |
| 9560 | // clipped surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9561 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9562 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 9563 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 9564 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9565 | LayerImpl* unclipped_desc_surface2 = |
| 9566 | AddChild<LayerImpl>(unclipped_desc_surface); |
| 9567 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2); |
| 9568 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 9569 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9570 | root->SetBounds(gfx::Size(80, 80)); |
| 9571 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9572 | unclipped_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9573 | unclipped_surface->SetDrawsContent(true); |
| 9574 | unclipped_surface->test_properties()->force_render_surface = true; |
| 9575 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 9576 | clip_parent->SetMasksToBounds(true); |
| 9577 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9578 | unclipped_desc_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9579 | unclipped_desc_surface->SetDrawsContent(true); |
| 9580 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9581 | unclipped_desc_surface2->SetBounds(gfx::Size(60, 60)); |
| 9582 | unclipped_desc_surface2->SetDrawsContent(true); |
| 9583 | unclipped_desc_surface2->test_properties()->force_render_surface = true; |
| 9584 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9585 | clipped_surface->SetBounds(gfx::Size(70, 70)); |
| 9586 | clipped_surface->SetDrawsContent(true); |
| 9587 | clipped_surface->test_properties()->force_render_surface = true; |
| 9588 | |
| 9589 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9590 | clip_parent->test_properties()->clip_children = |
| 9591 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9592 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9593 | |
| 9594 | ExecuteCalculateDrawProperties(root); |
| 9595 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9596 | unclipped_surface->render_surface()->content_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9597 | EXPECT_EQ(gfx::Rect(50, 50), |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9598 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9599 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9600 | unclipped_desc_surface2->render_surface()->content_rect()); |
| 9601 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9602 | clipped_surface->render_surface()->content_rect()); |
| 9603 | } |
| 9604 | |
| 9605 | TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) { |
| 9606 | // Tests the value of render surface content rect when we have a layer that |
| 9607 | // clips between the clip parent's target and clip child's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9608 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9609 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9610 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9611 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9612 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9613 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9614 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9615 | gfx::Transform translate; |
| 9616 | translate.Translate(10, 10); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9617 | |
jaydasika | 778cb27 | 2016-08-15 19:00:54 | [diff] [blame] | 9618 | gfx::Transform rotate; |
| 9619 | rotate.RotateAboutXAxis(10); |
| 9620 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9621 | root->SetBounds(gfx::Size(100, 100)); |
| 9622 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9623 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9624 | surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9625 | surface->test_properties()->transform = rotate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9626 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9627 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9628 | clip_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9629 | unclipped_desc_surface->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9630 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 9631 | unclipped_desc_surface->SetDrawsContent(true); |
| 9632 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9633 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9634 | clip_child->SetDrawsContent(true); |
| 9635 | |
| 9636 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9637 | clip_parent->test_properties()->clip_children = |
| 9638 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9639 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9640 | |
| 9641 | ExecuteCalculateDrawProperties(root); |
| 9642 | |
| 9643 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9644 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9645 | } |
| 9646 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9647 | TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9648 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9649 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9650 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9651 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9652 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9653 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9654 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9655 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9656 | gfx::Transform scale; |
| 9657 | scale.Scale(2, 2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9658 | |
| 9659 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9660 | surface->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9661 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9662 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9663 | surface->test_properties()->force_render_surface = true; |
| 9664 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9665 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9666 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 9667 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 9668 | unclipped_desc_surface->SetDrawsContent(true); |
| 9669 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9670 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9671 | clip_child->SetDrawsContent(true); |
| 9672 | |
| 9673 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9674 | clip_parent->test_properties()->clip_children = |
| 9675 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9676 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9677 | |
| 9678 | ExecuteCalculateDrawProperties(root); |
| 9679 | |
| 9680 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 9681 | } |
| 9682 | |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9683 | TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9684 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9685 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9686 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9687 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9688 | gfx::Transform translation; |
| 9689 | translation.Translate(10, 10); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9690 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9691 | root->SetBounds(gfx::Size(30, 30)); |
| 9692 | render_surface->SetBounds(gfx::Size(30, 30)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9693 | render_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9694 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9695 | test_layer->test_properties()->transform = translation; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9696 | test_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9697 | test_layer->SetDrawsContent(true); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9698 | test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9699 | test_layer->test_properties()->opacity = 0.f; |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9700 | |
| 9701 | ExecuteCalculateDrawProperties(root); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 9702 | EXPECT_TRANSFORMATION_MATRIX_EQ(translation, |
| 9703 | test_layer->ScreenSpaceTransform()); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9704 | } |
| 9705 | |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9706 | TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9707 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9708 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9709 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9710 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9711 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9712 | root->SetBounds(gfx::Size(30, 30)); |
| 9713 | clip_parent->SetBounds(gfx::Size(40, 40)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9714 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9715 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9716 | render_surface->SetMasksToBounds(true); |
| 9717 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9718 | render_surface->test_properties()->force_render_surface = true; |
| 9719 | clip_child->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9720 | clip_child->SetDrawsContent(true); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9721 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9722 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9723 | clip_parent->test_properties()->clip_children = |
| 9724 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9725 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9726 | |
| 9727 | ExecuteCalculateDrawProperties(root); |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 9728 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9729 | } |
| 9730 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9731 | TEST_F(LayerTreeHostCommonTest, |
| 9732 | LayerClipRectLargerThanClippingRenderSurfaceRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9733 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9734 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9735 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9736 | |
| 9737 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9738 | root->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9739 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9740 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9741 | render_surface->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9742 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9743 | render_surface->test_properties()->force_render_surface = true; |
| 9744 | test_layer->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9745 | test_layer->SetMasksToBounds(true); |
| 9746 | test_layer->SetDrawsContent(true); |
| 9747 | ExecuteCalculateDrawProperties(root); |
| 9748 | |
| 9749 | EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect()); |
| 9750 | EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect()); |
| 9751 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect()); |
| 9752 | } |
| 9753 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9754 | TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) { |
| 9755 | // Tests that subtree is hidden is updated. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9756 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9757 | LayerImpl* hidden = AddChild<LayerImpl>(root); |
| 9758 | LayerImpl* test = AddChild<LayerImpl>(hidden); |
| 9759 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9760 | root->SetBounds(gfx::Size(30, 30)); |
| 9761 | hidden->SetBounds(gfx::Size(30, 30)); |
| 9762 | hidden->test_properties()->force_render_surface = true; |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9763 | hidden->test_properties()->hide_layer_and_subtree = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9764 | test->SetBounds(gfx::Size(30, 30)); |
| 9765 | test->test_properties()->force_render_surface = true; |
| 9766 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9767 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9768 | EXPECT_TRUE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9769 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9770 | hidden->test_properties()->hide_layer_and_subtree = false; |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9771 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9772 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9773 | EXPECT_FALSE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9774 | } |
| 9775 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9776 | TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9777 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9778 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9779 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 9780 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
| 9781 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9782 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9783 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9784 | render_surface1->SetPosition(gfx::PointF(10, 10)); |
| 9785 | render_surface1->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9786 | render_surface1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9787 | render_surface1->test_properties()->force_render_surface = true; |
| 9788 | render_surface2->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9789 | render_surface2->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9790 | render_surface2->test_properties()->force_render_surface = true; |
| 9791 | clip_child->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9792 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9793 | clip_child->test_properties()->clip_parent = root; |
| 9794 | root->test_properties()->clip_children = |
| 9795 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9796 | root->test_properties()->clip_children->insert(clip_child); |
| 9797 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9798 | ExecuteCalculateDrawProperties(root); |
| 9799 | |
| 9800 | EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); |
jaydasika | daf0af0 | 2016-01-06 15:33:37 | [diff] [blame] | 9801 | // A clip node is created for every render surface and for layers that have |
| 9802 | // local clip. So, here it should be craeted for every layer. |
| 9803 | EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9804 | } |
| 9805 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9806 | TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) { |
| 9807 | // Tests that a mask layer's draw properties are computed correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9808 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9809 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9810 | child->test_properties()->SetMaskLayer( |
| 9811 | LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 9812 | LayerImpl* mask = child->test_properties()->mask_layer; |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9813 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9814 | gfx::Transform transform; |
| 9815 | transform.Translate(10, 10); |
| 9816 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9817 | root->SetBounds(gfx::Size(40, 40)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9818 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9819 | child->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9820 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9821 | child->SetDrawsContent(false); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9822 | mask->SetBounds(gfx::Size(20, 20)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9823 | ExecuteCalculateDrawProperties(root); |
| 9824 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9825 | // The render surface created for the mask has no contributing content, so the |
| 9826 | // mask isn't a drawn RSLL member. This means it has an empty visible rect, |
| 9827 | // but its screen space transform can still be computed correctly on-demand. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9828 | EXPECT_FALSE(mask->is_drawn_render_surface_layer_list_member()); |
| 9829 | EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect()); |
| 9830 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9831 | |
| 9832 | // Make the child's render surface have contributing content. |
| 9833 | child->SetDrawsContent(true); |
| 9834 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9835 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9836 | EXPECT_TRUE(mask->is_drawn_render_surface_layer_list_member()); |
| 9837 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
| 9838 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9839 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9840 | transform.Translate(10, 10); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9841 | child->test_properties()->transform = transform; |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9842 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9843 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9844 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
| 9845 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9846 | } |
| 9847 | |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9848 | TEST_F(LayerTreeHostCommonTest, |
| 9849 | SublayerScaleWithTransformNodeBetweenTwoTargets) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9850 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9851 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9852 | LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1); |
| 9853 | LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets); |
| 9854 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9855 | |
| 9856 | gfx::Transform scale; |
| 9857 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9858 | |
| 9859 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9860 | render_surface1->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9861 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 9862 | render_surface1->test_properties()->force_render_surface = true; |
| 9863 | between_targets->SetBounds(gfx::Size(30, 30)); |
| 9864 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 9865 | render_surface2->test_properties()->force_render_surface = true; |
| 9866 | test_layer->SetBounds(gfx::Size(30, 30)); |
| 9867 | test_layer->SetDrawsContent(true); |
| 9868 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 9869 | // We want layer between the two targets to create a clip node and effect |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9870 | // node but it shouldn't create a render surface. |
| 9871 | between_targets->SetMasksToBounds(true); |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 9872 | between_targets->test_properties()->opacity = 0.5f; |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9873 | |
| 9874 | ExecuteCalculateDrawProperties(root); |
| 9875 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 9876 | EffectTree& tree = root->layer_tree_impl()->property_trees()->effect_tree; |
| 9877 | EffectNode* node = tree.Node(render_surface1->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9878 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9879 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 9880 | node = tree.Node(between_targets->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9881 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9882 | |
jaydasika | b433552b | 2016-10-26 18:49:44 | [diff] [blame] | 9883 | node = tree.Node(render_surface2->effect_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9884 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9885 | |
| 9886 | EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect()); |
| 9887 | } |
| 9888 | |
jaydasika | 3c5633d | 2016-08-25 00:39:22 | [diff] [blame] | 9889 | TEST_F(LayerTreeHostCommonTest, NoisyTransform) { |
| 9890 | LayerImpl* root = root_layer_for_testing(); |
| 9891 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9892 | LayerImpl* scroll_child = AddChild<LayerImpl>(render_surface); |
| 9893 | LayerImpl* scroll_clip = AddChild<LayerImpl>(render_surface); |
| 9894 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_clip); |
| 9895 | |
| 9896 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 9897 | scroll_parent->test_properties()->scroll_children = |
| 9898 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9899 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
| 9900 | scroll_parent->SetScrollClipLayer(scroll_clip->id()); |
| 9901 | |
| 9902 | scroll_parent->SetDrawsContent(true); |
| 9903 | scroll_child->SetDrawsContent(true); |
| 9904 | render_surface->test_properties()->force_render_surface = true; |
| 9905 | |
| 9906 | // A noisy transform that's invertible. |
| 9907 | gfx::Transform transform; |
| 9908 | transform.matrix().setDouble(0, 0, 6.12323e-17); |
| 9909 | transform.matrix().setDouble(0, 2, 1); |
| 9910 | transform.matrix().setDouble(2, 2, 6.12323e-17); |
| 9911 | transform.matrix().setDouble(2, 0, -1); |
| 9912 | |
| 9913 | scroll_child->test_properties()->transform = transform; |
| 9914 | render_surface->test_properties()->transform = transform; |
| 9915 | |
| 9916 | root->SetBounds(gfx::Size(30, 30)); |
| 9917 | scroll_child->SetBounds(gfx::Size(30, 30)); |
| 9918 | scroll_parent->SetBounds(gfx::Size(30, 30)); |
| 9919 | ExecuteCalculateDrawProperties(root); |
| 9920 | |
| 9921 | gfx::Transform expected; |
| 9922 | expected.matrix().setDouble(0, 0, 3.749395e-33); |
| 9923 | expected.matrix().setDouble(0, 2, 6.12323e-17); |
| 9924 | expected.matrix().setDouble(2, 0, -1); |
| 9925 | expected.matrix().setDouble(2, 2, 6.12323e-17); |
| 9926 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
| 9927 | scroll_child->ScreenSpaceTransform()); |
| 9928 | } |
| 9929 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9930 | TEST_F(LayerTreeHostCommonTest, LargeTransformTest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9931 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9932 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9933 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9934 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9935 | child->SetDrawsContent(true); |
| 9936 | child->SetMasksToBounds(true); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9937 | |
| 9938 | gfx::Transform large_transform; |
| 9939 | large_transform.Scale(99999999999999999999.f, 99999999999999999999.f); |
| 9940 | large_transform.Scale(9999999999999999999.f, 9999999999999999999.f); |
| 9941 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0))); |
| 9942 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1))); |
| 9943 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9944 | root->SetBounds(gfx::Size(30, 30)); |
| 9945 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 9946 | render_surface1->test_properties()->force_render_surface = true; |
| 9947 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9948 | // TODO(sunxd): we make child have no render surface, because if the |
| 9949 | // child has one, the large transform applied to child will result in NaNs in |
| 9950 | // the draw_transform of the render_surface, thus make draw property updates |
| 9951 | // skip the child layer. We need further investigation into this to know |
| 9952 | // what exactly happens here. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9953 | child->test_properties()->transform = large_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9954 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9955 | |
| 9956 | ExecuteCalculateDrawProperties(root); |
| 9957 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9958 | EXPECT_EQ(gfx::RectF(), |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9959 | render_surface1->render_surface()->DrawableContentRect()); |
| 9960 | |
| 9961 | bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) || |
| 9962 | std::isnan(child->DrawTransform().matrix().get(0, 0)); |
| 9963 | EXPECT_TRUE(is_inf_or_nan); |
| 9964 | |
| 9965 | is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) || |
| 9966 | std::isnan(child->DrawTransform().matrix().get(1, 1)); |
| 9967 | EXPECT_TRUE(is_inf_or_nan); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9968 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 9969 | // The root layer should be in the RenderSurfaceLayerListImpl. |
| 9970 | const auto* rsll = render_surface_layer_list_impl(); |
| 9971 | EXPECT_NE(std::find(rsll->begin(), rsll->end(), root), rsll->end()); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9972 | } |
| 9973 | |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9974 | TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) { |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9975 | scoped_refptr<Layer> root = Layer::Create(); |
| 9976 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 9977 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9978 | root->AddChild(child); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9979 | host()->SetRootLayer(root); |
| 9980 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9981 | root->SetBounds(gfx::Size(100, 100)); |
| 9982 | child->SetBounds(gfx::Size(20, 20)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9983 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9984 | |
| 9985 | // Changing the opacity from 1 to non-1 value should trigger rebuild of |
| 9986 | // property trees as a new effect node will be created. |
| 9987 | child->SetOpacity(0.5f); |
| 9988 | PropertyTrees* property_trees = host()->property_trees(); |
| 9989 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 9990 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9991 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9992 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 9993 | property_trees->effect_id_to_index_map.end()); |
| 9994 | |
| 9995 | // child already has an effect node. Changing its opacity shouldn't trigger |
| 9996 | // a property trees rebuild. |
| 9997 | child->SetOpacity(0.8f); |
| 9998 | property_trees = host()->property_trees(); |
| 9999 | EXPECT_FALSE(property_trees->needs_rebuild); |
| 10000 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10001 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10002 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 10003 | property_trees->effect_id_to_index_map.end()); |
| 10004 | |
| 10005 | // Changing the opacity from non-1 value to 1 should trigger a rebuild of |
| 10006 | // property trees as the effect node may no longer be needed. |
| 10007 | child->SetOpacity(1.f); |
| 10008 | property_trees = host()->property_trees(); |
| 10009 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 10010 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10011 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 10012 | EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()), |
| 10013 | property_trees->effect_id_to_index_map.end()); |
| 10014 | } |
| 10015 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10016 | TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) { |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10017 | scoped_refptr<Layer> root = Layer::Create(); |
| 10018 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 10019 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 10020 | root->AddChild(animated); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10021 | host()->SetRootLayer(root); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 10022 | host()->GetLayerTree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10023 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10024 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10025 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10026 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10027 | animated->SetOpacity(0.f); |
| 10028 | |
| 10029 | scoped_refptr<AnimationPlayer> player = |
| 10030 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 10031 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10032 | |
| 10033 | player->AttachElement(animated->element_id()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10034 | |
| 10035 | int animation_id = 0; |
| 10036 | std::unique_ptr<Animation> animation = Animation::Create( |
| 10037 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 10038 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 10039 | animation->set_fill_mode(Animation::FillMode::NONE); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10040 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 10041 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10042 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 10043 | std::move(animation)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10044 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10045 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10046 | |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 10047 | EffectTree& tree = root->GetLayerTree()->property_trees()->effect_tree; |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10048 | EffectNode* node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10049 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 10050 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10051 | |
| 10052 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
khushalsagar | 6156779 | 2016-09-17 00:13:58 | [diff] [blame] | 10053 | host()->AnimateLayers( |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10054 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 10055 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10056 | EXPECT_TRUE(node->is_currently_animating_opacity); |
| 10057 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10058 | |
| 10059 | player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/); |
| 10060 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10061 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 10062 | EXPECT_FALSE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 10063 | } |
| 10064 | |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10065 | TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) { |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10066 | scoped_refptr<Layer> root = Layer::Create(); |
| 10067 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 10068 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 10069 | root->AddChild(animated); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10070 | host()->SetRootLayer(root); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 10071 | host()->GetLayerTree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10072 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10073 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10074 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 10075 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10076 | |
| 10077 | scoped_refptr<AnimationPlayer> player = |
| 10078 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 10079 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10080 | player->AttachElement(animated->element_id()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10081 | |
| 10082 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 10083 | KeyframedTransformAnimationCurve::Create()); |
| 10084 | TransformOperations start; |
| 10085 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 10086 | gfx::Transform transform; |
| 10087 | transform.Scale3d(1.0, 2.0, 3.0); |
| 10088 | TransformOperations operation; |
| 10089 | operation.AppendMatrix(transform); |
| 10090 | curve->AddKeyframe( |
| 10091 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 10092 | curve->AddKeyframe(TransformKeyframe::Create( |
| 10093 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
| 10094 | std::unique_ptr<Animation> animation( |
| 10095 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 10096 | animation->set_fill_mode(Animation::FillMode::NONE); |
| 10097 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 10098 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10099 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 10100 | std::move(animation)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10101 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10102 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10103 | |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 10104 | TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree; |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10105 | TransformNode* node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10106 | EXPECT_FALSE(node->is_currently_animating); |
| 10107 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10108 | |
| 10109 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
khushalsagar | 6156779 | 2016-09-17 00:13:58 | [diff] [blame] | 10110 | host()->AnimateLayers( |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10111 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 10112 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10113 | EXPECT_TRUE(node->is_currently_animating); |
| 10114 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10115 | |
| 10116 | player->AbortAnimations(TargetProperty::TRANSFORM, |
| 10117 | false /*needs_completion*/); |
| 10118 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10119 | EXPECT_FALSE(node->is_currently_animating); |
| 10120 | EXPECT_FALSE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 10121 | } |
| 10122 | |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 10123 | TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) { |
| 10124 | LayerTreeHostCommon::ScrollUpdateInfo scroll; |
| 10125 | scroll.layer_id = 2; |
| 10126 | scroll.scroll_delta = gfx::Vector2d(5, 10); |
| 10127 | |
| 10128 | proto::ScrollUpdateInfo proto; |
| 10129 | scroll.ToProtobuf(&proto); |
| 10130 | LayerTreeHostCommon::ScrollUpdateInfo new_scroll; |
| 10131 | new_scroll.FromProtobuf(proto); |
| 10132 | |
| 10133 | EXPECT_EQ(scroll, new_scroll); |
| 10134 | } |
| 10135 | |
| 10136 | TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) { |
| 10137 | ScrollAndScaleSet scroll_and_scale_set; |
| 10138 | |
| 10139 | LayerTreeHostCommon::ScrollUpdateInfo scroll1; |
| 10140 | scroll1.layer_id = 1; |
| 10141 | scroll1.scroll_delta = gfx::Vector2d(5, 10); |
| 10142 | LayerTreeHostCommon::ScrollUpdateInfo scroll2; |
| 10143 | scroll2.layer_id = 2; |
| 10144 | scroll2.scroll_delta = gfx::Vector2d(1, 5); |
| 10145 | scroll_and_scale_set.scrolls.push_back(scroll1); |
| 10146 | scroll_and_scale_set.scrolls.push_back(scroll2); |
| 10147 | |
| 10148 | scroll_and_scale_set.page_scale_delta = 0.3f; |
| 10149 | scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f); |
| 10150 | scroll_and_scale_set.top_controls_delta = 0.9f; |
| 10151 | |
| 10152 | proto::ScrollAndScaleSet proto; |
| 10153 | scroll_and_scale_set.ToProtobuf(&proto); |
| 10154 | ScrollAndScaleSet new_scroll_and_scale_set; |
| 10155 | new_scroll_and_scale_set.FromProtobuf(proto); |
| 10156 | |
| 10157 | EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); |
| 10158 | } |
| 10159 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10160 | TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 10161 | // Test the behavior of scroll tree builder |
| 10162 | // Topology: |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10163 | // +root1(1)[inner_viewport_container_layer] |
| 10164 | // +-page_scale_layer |
| 10165 | // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling & |
| 10166 | // scrollable, inner_viewport_scroll_layer] |
| 10167 | // +------child6(6)[kScrollbarScrolling] |
| 10168 | // +--------grand_child10(10)[kScrollbarScrolling] |
| 10169 | // +----parent3(3) |
| 10170 | // +------child7(7)[scrollable] |
| 10171 | // +------child8(8)[scroll_parent=7] |
| 10172 | // +--------grand_child11(11)[scrollable] |
| 10173 | // +----parent4(4) |
| 10174 | // +------child9(9) |
| 10175 | // +--------grand_child12(12) |
| 10176 | // +----parent5(5)[contains_non_fast_scrollable_region] |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10177 | // |
| 10178 | // Expected scroll tree topology: |
| 10179 | // +property_tree_root---owner:-1 |
| 10180 | // +--root---owner:1, id:1 |
| 10181 | // +----node---owner:2, id:2 |
| 10182 | // +------node---owner:6, id:3 |
| 10183 | // +----node---owner:7, id:4 |
| 10184 | // +------node---owner:11, id:5 |
| 10185 | // +----node---owner:5, id:6 |
| 10186 | // |
| 10187 | // Extra check: |
| 10188 | // scroll_tree_index() of: |
| 10189 | // grand_child10:3 |
| 10190 | // parent3:1 |
| 10191 | // child8:4 |
| 10192 | // parent4:1 |
| 10193 | // child9:1 |
| 10194 | // grand_child12:1 |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 10195 | scoped_refptr<Layer> root1 = Layer::Create(); |
| 10196 | scoped_refptr<Layer> page_scale_layer = Layer::Create(); |
| 10197 | scoped_refptr<Layer> parent2 = Layer::Create(); |
| 10198 | scoped_refptr<Layer> parent3 = Layer::Create(); |
| 10199 | scoped_refptr<Layer> parent4 = Layer::Create(); |
| 10200 | scoped_refptr<Layer> parent5 = Layer::Create(); |
| 10201 | scoped_refptr<Layer> child6 = Layer::Create(); |
| 10202 | scoped_refptr<Layer> child7 = Layer::Create(); |
| 10203 | scoped_refptr<Layer> child8 = Layer::Create(); |
| 10204 | scoped_refptr<Layer> child9 = Layer::Create(); |
| 10205 | scoped_refptr<Layer> grand_child10 = Layer::Create(); |
| 10206 | scoped_refptr<Layer> grand_child11 = Layer::Create(); |
| 10207 | scoped_refptr<Layer> grand_child12 = Layer::Create(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10208 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10209 | root1->AddChild(page_scale_layer); |
| 10210 | page_scale_layer->AddChild(parent2); |
| 10211 | page_scale_layer->AddChild(parent3); |
| 10212 | page_scale_layer->AddChild(parent4); |
| 10213 | page_scale_layer->AddChild(parent5); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10214 | parent2->AddChild(child6); |
| 10215 | parent3->AddChild(child7); |
| 10216 | parent3->AddChild(child8); |
| 10217 | parent4->AddChild(child9); |
| 10218 | child6->AddChild(grand_child10); |
| 10219 | child8->AddChild(grand_child11); |
| 10220 | child9->AddChild(grand_child12); |
| 10221 | host()->SetRootLayer(root1); |
| 10222 | |
| 10223 | parent2->AddMainThreadScrollingReasons( |
| 10224 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10225 | parent2->AddMainThreadScrollingReasons( |
| 10226 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10227 | parent2->SetScrollClipLayerId(root1->id()); |
| 10228 | child6->AddMainThreadScrollingReasons( |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10229 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10230 | grand_child10->AddMainThreadScrollingReasons( |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10231 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10232 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10233 | child7->SetScrollClipLayerId(parent3->id()); |
| 10234 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10235 | child8->SetScrollParent(child7.get()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10236 | grand_child11->SetScrollClipLayerId(parent3->id()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10237 | |
| 10238 | parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10239 | parent5->SetBounds(gfx::Size(10, 10)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10240 | |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 10241 | host()->GetLayerTree()->RegisterViewportLayers(nullptr, page_scale_layer, |
| 10242 | parent2, nullptr); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10243 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10244 | |
| 10245 | const int kInvalidPropertyTreeNodeId = -1; |
| 10246 | const int kRootPropertyTreeNodeId = 0; |
| 10247 | |
| 10248 | // Property tree root |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10249 | ScrollTree& scroll_tree = host()->property_trees()->scroll_tree; |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 10250 | PropertyTrees property_trees; |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10251 | property_trees.is_main_thread = true; |
| 10252 | property_trees.is_active = false; |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10253 | ScrollTree& expected_scroll_tree = property_trees.scroll_tree; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10254 | ScrollNode* property_tree_root = expected_scroll_tree.Node(0); |
| 10255 | property_tree_root->id = kRootPropertyTreeNodeId; |
| 10256 | property_tree_root->parent_id = kInvalidPropertyTreeNodeId; |
| 10257 | property_tree_root->owner_id = kInvalidPropertyTreeNodeId; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10258 | property_tree_root->scrollable = false; |
| 10259 | property_tree_root->main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10260 | MainThreadScrollingReason::kNotScrollingOnMain; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10261 | property_tree_root->contains_non_fast_scrollable_region = false; |
| 10262 | property_tree_root->transform_id = kRootPropertyTreeNodeId; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10263 | |
| 10264 | // The node owned by root1 |
| 10265 | ScrollNode scroll_root1; |
| 10266 | scroll_root1.id = 1; |
| 10267 | scroll_root1.owner_id = root1->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10268 | scroll_root1.user_scrollable_horizontal = true; |
| 10269 | scroll_root1.user_scrollable_vertical = true; |
| 10270 | scroll_root1.transform_id = root1->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10271 | expected_scroll_tree.Insert(scroll_root1, 0); |
| 10272 | |
| 10273 | // The node owned by parent2 |
| 10274 | ScrollNode scroll_parent2; |
| 10275 | scroll_parent2.id = 2; |
| 10276 | scroll_parent2.owner_id = parent2->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10277 | scroll_parent2.scrollable = true; |
| 10278 | scroll_parent2.main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10279 | parent2->main_thread_scrolling_reasons(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10280 | scroll_parent2.scroll_clip_layer_bounds = root1->bounds(); |
| 10281 | scroll_parent2.bounds = parent2->bounds(); |
| 10282 | scroll_parent2.max_scroll_offset_affected_by_page_scale = true; |
| 10283 | scroll_parent2.is_inner_viewport_scroll_layer = true; |
| 10284 | scroll_parent2.user_scrollable_horizontal = true; |
| 10285 | scroll_parent2.user_scrollable_vertical = true; |
| 10286 | scroll_parent2.transform_id = parent2->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10287 | expected_scroll_tree.Insert(scroll_parent2, 1); |
| 10288 | |
| 10289 | // The node owned by child6 |
| 10290 | ScrollNode scroll_child6; |
| 10291 | scroll_child6.id = 3; |
| 10292 | scroll_child6.owner_id = child6->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10293 | scroll_child6.main_thread_scrolling_reasons = |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 10294 | child6->main_thread_scrolling_reasons(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10295 | scroll_child6.should_flatten = true; |
| 10296 | scroll_child6.user_scrollable_horizontal = true; |
| 10297 | scroll_child6.user_scrollable_vertical = true; |
| 10298 | scroll_child6.transform_id = child6->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10299 | expected_scroll_tree.Insert(scroll_child6, 2); |
| 10300 | |
| 10301 | // The node owned by child7, child7 also owns a transform node |
| 10302 | ScrollNode scroll_child7; |
| 10303 | scroll_child7.id = 4; |
| 10304 | scroll_child7.owner_id = child7->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10305 | scroll_child7.scrollable = true; |
| 10306 | scroll_child7.scroll_clip_layer_bounds = parent3->bounds(); |
| 10307 | scroll_child7.bounds = child7->bounds(); |
| 10308 | scroll_child7.user_scrollable_horizontal = true; |
| 10309 | scroll_child7.user_scrollable_vertical = true; |
| 10310 | scroll_child7.transform_id = child7->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10311 | expected_scroll_tree.Insert(scroll_child7, 1); |
| 10312 | |
| 10313 | // The node owned by grand_child11, grand_child11 also owns a transform node |
| 10314 | ScrollNode scroll_grand_child11; |
| 10315 | scroll_grand_child11.id = 5; |
| 10316 | scroll_grand_child11.owner_id = grand_child11->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10317 | scroll_grand_child11.scrollable = true; |
| 10318 | scroll_grand_child11.user_scrollable_horizontal = true; |
| 10319 | scroll_grand_child11.user_scrollable_vertical = true; |
| 10320 | scroll_grand_child11.transform_id = grand_child11->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10321 | expected_scroll_tree.Insert(scroll_grand_child11, 4); |
| 10322 | |
| 10323 | // The node owned by parent5 |
| 10324 | ScrollNode scroll_parent5; |
| 10325 | scroll_parent5.id = 8; |
| 10326 | scroll_parent5.owner_id = parent5->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10327 | scroll_parent5.contains_non_fast_scrollable_region = true; |
| 10328 | scroll_parent5.bounds = gfx::Size(10, 10); |
| 10329 | scroll_parent5.should_flatten = true; |
| 10330 | scroll_parent5.user_scrollable_horizontal = true; |
| 10331 | scroll_parent5.user_scrollable_vertical = true; |
| 10332 | scroll_parent5.transform_id = parent5->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10333 | expected_scroll_tree.Insert(scroll_parent5, 1); |
| 10334 | |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10335 | expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0)); |
| 10336 | expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0)); |
| 10337 | expected_scroll_tree.SetScrollOffset(grand_child11->id(), |
| 10338 | gfx::ScrollOffset(0, 0)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10339 | expected_scroll_tree.set_needs_update(false); |
| 10340 | |
| 10341 | EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 10342 | |
| 10343 | // Check other layers' scroll_tree_index |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10344 | EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10345 | EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10346 | EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10347 | EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10348 | EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10349 | EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10350 | EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10351 | } |
| 10352 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 10353 | } // namespace |
| 10354 | } // namespace cc |