ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
danakj | 6496cba | 2014-10-16 01:31:08 | [diff] [blame] | 9 | #include <algorithm> |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 11 | #include <set> |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 13 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 14 | #include "base/memory/ptr_util.h" |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 15 | #include "cc/animation/animation_host.h" |
| 16 | #include "cc/animation/animation_id_provider.h" |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 17 | #include "cc/animation/animation_player.h" |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 18 | #include "cc/animation/keyframed_animation_curve.h" |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 19 | #include "cc/animation/transform_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 20 | #include "cc/base/math_util.h" |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 21 | #include "cc/input/main_thread_scrolling_reason.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 22 | #include "cc/layers/content_layer_client.h" |
[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() { |
| 65 | verify_transform_tree_calculations = true; |
jaydasika | 853306a | 2016-07-29 19:28:34 | [diff] [blame] | 66 | verify_clip_tree_calculations = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 67 | } |
| 68 | }; |
| 69 | |
| 70 | class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { |
| 71 | public: |
| 72 | LayerTreeHostCommonTestBase() |
| 73 | : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {} |
| 74 | explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings) |
| 75 | : LayerTestCommon::LayerImplTest(settings) {} |
| 76 | |
| 77 | static void SetScrollOffsetDelta(LayerImpl* layer_impl, |
| 78 | const gfx::Vector2dF& delta) { |
| 79 | if (layer_impl->layer_tree_impl() |
| 80 | ->property_trees() |
| 81 | ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(), |
| 82 | delta)) |
vollick | c969691 | 2016-09-16 16:02:47 | [diff] [blame] | 83 | layer_impl->layer_tree_impl()->DidUpdateScrollOffset(layer_impl->id()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static float GetMaximumAnimationScale(LayerImpl* layer_impl) { |
| 87 | return layer_impl->layer_tree_impl() |
| 88 | ->property_trees() |
| 89 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 90 | layer_impl->layer_tree_impl()) |
| 91 | .maximum_animation_scale; |
| 92 | } |
| 93 | |
| 94 | static float GetStartingAnimationScale(LayerImpl* layer_impl) { |
| 95 | return layer_impl->layer_tree_impl() |
| 96 | ->property_trees() |
| 97 | ->GetAnimationScales(layer_impl->transform_tree_index(), |
| 98 | layer_impl->layer_tree_impl()) |
| 99 | .starting_animation_scale; |
| 100 | } |
| 101 | |
| 102 | void ExecuteCalculateDrawProperties(Layer* root_layer, |
| 103 | float device_scale_factor, |
| 104 | float page_scale_factor, |
| 105 | Layer* page_scale_layer) { |
| 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; |
| 121 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 122 | } |
| 123 | |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 124 | void ExecuteCalculateDrawProperties( |
| 125 | LayerImpl* root_layer, |
| 126 | float device_scale_factor, |
| 127 | float page_scale_factor, |
| 128 | LayerImpl* page_scale_layer, |
| 129 | bool skip_verify_visible_rect_calculations = false) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 130 | if (device_scale_factor != |
| 131 | root_layer->layer_tree_impl()->device_scale_factor()) |
| 132 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 133 | |
| 134 | root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); |
| 135 | |
| 136 | EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); |
| 137 | |
| 138 | gfx::Size device_viewport_size = |
| 139 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 140 | root_layer->bounds().height() * device_scale_factor); |
| 141 | |
| 142 | render_surface_layer_list_impl_.reset(new LayerImplList); |
| 143 | |
| 144 | // We are probably not testing what is intended if the root_layer bounds are |
| 145 | // empty. |
| 146 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 147 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 148 | root_layer, device_viewport_size, |
| 149 | render_surface_layer_list_impl_.get()); |
| 150 | inputs.device_scale_factor = device_scale_factor; |
| 151 | inputs.page_scale_factor = page_scale_factor; |
| 152 | inputs.page_scale_layer = page_scale_layer; |
| 153 | inputs.can_adjust_raster_scales = true; |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 154 | if (skip_verify_visible_rect_calculations) |
| 155 | inputs.verify_visible_rect_calculations = false; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 156 | |
| 157 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 158 | } |
| 159 | |
| 160 | template <class LayerType> |
| 161 | void ExecuteCalculateDrawProperties(LayerType* root_layer) { |
| 162 | LayerType* page_scale_application_layer = nullptr; |
| 163 | ExecuteCalculateDrawProperties(root_layer, 1.f, 1.f, |
| 164 | page_scale_application_layer); |
| 165 | } |
| 166 | |
| 167 | template <class LayerType> |
| 168 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 169 | float device_scale_factor) { |
| 170 | LayerType* page_scale_application_layer = nullptr; |
| 171 | ExecuteCalculateDrawProperties(root_layer, device_scale_factor, 1.f, |
| 172 | page_scale_application_layer); |
| 173 | } |
| 174 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 175 | const LayerList* GetUpdateLayerList() { return &update_layer_list_; } |
| 176 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 177 | void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) { |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 178 | DCHECK(root_layer->GetLayerTree()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 179 | PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 180 | |
| 181 | bool can_render_to_separate_surface = true; |
| 182 | |
| 183 | const Layer* page_scale_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 184 | root_layer->GetLayerTree()->page_scale_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 185 | Layer* inner_viewport_scroll_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 186 | root_layer->GetLayerTree()->inner_viewport_scroll_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 187 | Layer* outer_viewport_scroll_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 188 | root_layer->GetLayerTree()->outer_viewport_scroll_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 189 | const Layer* overscroll_elasticity_layer = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 190 | root_layer->GetLayerTree()->overscroll_elasticity_layer(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 191 | gfx::Vector2dF elastic_overscroll = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 192 | root_layer->GetLayerTree()->elastic_overscroll(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 193 | float page_scale_factor = 1.f; |
| 194 | float device_scale_factor = 1.f; |
| 195 | gfx::Size device_viewport_size = |
| 196 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 197 | root_layer->bounds().height() * device_scale_factor); |
| 198 | PropertyTrees* property_trees = |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 199 | root_layer->GetLayerTree()->property_trees(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 200 | update_layer_list_.clear(); |
| 201 | PropertyTreeBuilder::BuildPropertyTrees( |
| 202 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 203 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 204 | elastic_overscroll, page_scale_factor, device_scale_factor, |
| 205 | gfx::Rect(device_viewport_size), gfx::Transform(), property_trees); |
| 206 | draw_property_utils::UpdatePropertyTrees(property_trees, |
| 207 | can_render_to_separate_surface); |
| 208 | draw_property_utils::FindLayersThatNeedUpdates( |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 209 | root_layer->GetLayerTree(), property_trees->transform_tree, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 210 | property_trees->effect_tree, &update_layer_list_); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 211 | } |
| 212 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 213 | void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
| 214 | LayerImpl* root_layer, |
| 215 | bool skip_verify_visible_rect_calculations = false) { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 216 | DCHECK(root_layer->layer_tree_impl()); |
| 217 | PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer); |
| 218 | |
| 219 | bool can_render_to_separate_surface = true; |
| 220 | |
| 221 | LayerImpl* page_scale_layer = nullptr; |
| 222 | LayerImpl* inner_viewport_scroll_layer = |
| 223 | root_layer->layer_tree_impl()->InnerViewportScrollLayer(); |
| 224 | LayerImpl* outer_viewport_scroll_layer = |
| 225 | root_layer->layer_tree_impl()->OuterViewportScrollLayer(); |
| 226 | LayerImpl* overscroll_elasticity_layer = |
| 227 | root_layer->layer_tree_impl()->OverscrollElasticityLayer(); |
| 228 | gfx::Vector2dF elastic_overscroll = |
| 229 | root_layer->layer_tree_impl()->elastic_overscroll()->Current( |
| 230 | root_layer->layer_tree_impl()->IsActiveTree()); |
| 231 | float page_scale_factor = 1.f; |
| 232 | float device_scale_factor = 1.f; |
| 233 | gfx::Size device_viewport_size = |
| 234 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 235 | root_layer->bounds().height() * device_scale_factor); |
| 236 | update_layer_list_impl_.reset(new LayerImplList); |
| 237 | root_layer->layer_tree_impl()->BuildLayerListForTesting(); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 238 | PropertyTrees* property_trees = |
| 239 | root_layer->layer_tree_impl()->property_trees(); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 240 | draw_property_utils::BuildPropertyTreesAndComputeVisibleRects( |
| 241 | root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 242 | outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 243 | elastic_overscroll, page_scale_factor, device_scale_factor, |
| 244 | gfx::Rect(device_viewport_size), gfx::Transform(), |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 245 | can_render_to_separate_surface, property_trees, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 246 | update_layer_list_impl_.get()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 247 | draw_property_utils::VerifyClipTreeCalculations(*update_layer_list_impl_, |
| 248 | property_trees); |
| 249 | if (!skip_verify_visible_rect_calculations) |
| 250 | draw_property_utils::VerifyVisibleRectsCalculations( |
| 251 | *update_layer_list_impl_, property_trees); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces( |
| 255 | LayerImpl* root_layer) { |
| 256 | gfx::Size device_viewport_size = |
| 257 | gfx::Size(root_layer->bounds().width(), root_layer->bounds().height()); |
| 258 | render_surface_layer_list_impl_.reset(new LayerImplList); |
| 259 | |
| 260 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 261 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 262 | root_layer, device_viewport_size, |
| 263 | render_surface_layer_list_impl_.get()); |
| 264 | inputs.can_adjust_raster_scales = true; |
| 265 | inputs.can_render_to_separate_surface = false; |
| 266 | |
| 267 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 268 | } |
| 269 | |
| 270 | bool UpdateLayerListImplContains(int id) const { |
| 271 | for (auto* layer : *update_layer_list_impl_) { |
| 272 | if (layer->id() == id) |
| 273 | return true; |
| 274 | } |
| 275 | return false; |
| 276 | } |
| 277 | |
| 278 | bool UpdateLayerListContains(int id) const { |
| 279 | for (const auto& layer : update_layer_list_) { |
| 280 | if (layer->id() == id) |
| 281 | return true; |
| 282 | } |
| 283 | return false; |
| 284 | } |
| 285 | |
| 286 | const LayerImplList* render_surface_layer_list_impl() const { |
| 287 | return render_surface_layer_list_impl_.get(); |
| 288 | } |
| 289 | const LayerImplList* update_layer_list_impl() const { |
| 290 | return update_layer_list_impl_.get(); |
| 291 | } |
| 292 | const LayerList& update_layer_list() const { return update_layer_list_; } |
| 293 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 294 | bool VerifyLayerInList(scoped_refptr<Layer> layer, |
| 295 | const LayerList* layer_list) { |
| 296 | return std::find(layer_list->begin(), layer_list->end(), layer) != |
| 297 | layer_list->end(); |
| 298 | } |
| 299 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 300 | private: |
| 301 | std::unique_ptr<std::vector<LayerImpl*>> render_surface_layer_list_impl_; |
| 302 | LayerList update_layer_list_; |
| 303 | std::unique_ptr<LayerImplList> update_layer_list_impl_; |
| 304 | }; |
| 305 | |
| 306 | class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase, |
| 307 | public testing::Test {}; |
| 308 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 309 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 310 | public: |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 311 | LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 312 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 313 | bool DrawsContent() const override { return true; } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 314 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 315 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 316 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 317 | }; |
| 318 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 319 | class LayerTreeSettingsScaleContent : public VerifyTreeCalcsLayerTreeSettings { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 320 | public: |
| 321 | LayerTreeSettingsScaleContent() { |
| 322 | layer_transforms_should_scale_layer_contents = true; |
| 323 | } |
| 324 | }; |
| 325 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 326 | class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTestBase, |
| 327 | public testing::Test { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 328 | public: |
| 329 | LayerTreeHostCommonScalingTest() |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 330 | : LayerTreeHostCommonTestBase(LayerTreeSettingsScaleContent()) {} |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 331 | }; |
| 332 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 333 | class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest { |
| 334 | public: |
| 335 | LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {} |
| 336 | |
| 337 | LayerImpl* TestVisibleRectAndDrawableContentRect( |
| 338 | const gfx::Rect& target_rect, |
| 339 | const gfx::Transform& layer_transform, |
| 340 | const gfx::Rect& layer_rect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 341 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 342 | LayerImpl* target = AddChild<LayerImpl>(root); |
| 343 | LayerImpl* drawing_layer = AddChild<LayerImpl>(target); |
| 344 | |
| 345 | root->SetDrawsContent(true); |
| 346 | target->SetDrawsContent(true); |
| 347 | target->SetMasksToBounds(true); |
| 348 | drawing_layer->SetDrawsContent(true); |
| 349 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 350 | root->SetBounds(gfx::Size(500, 500)); |
| 351 | root->test_properties()->force_render_surface = true; |
| 352 | target->SetPosition(gfx::PointF(target_rect.origin())); |
| 353 | target->SetBounds(target_rect.size()); |
| 354 | target->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 355 | drawing_layer->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 356 | drawing_layer->SetPosition(gfx::PointF(layer_rect.origin())); |
| 357 | drawing_layer->SetBounds(layer_rect.size()); |
| 358 | drawing_layer->test_properties()->should_flatten_transform = false; |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 359 | |
| 360 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 361 | ExecuteCalculateDrawProperties(root); |
| 362 | |
| 363 | return drawing_layer; |
| 364 | } |
| 365 | }; |
| 366 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 367 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 368 | // Sanity check: For layers positioned at zero, with zero size, |
| 369 | // and with identity transforms, then the draw transform, |
| 370 | // screen space transform, and the hierarchy passed on to children |
| 371 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 372 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 373 | LayerImpl* parent = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 374 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 375 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 376 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 377 | parent->SetBounds(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 378 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 379 | ExecuteCalculateDrawProperties(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 380 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 381 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 382 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 383 | child->ScreenSpaceTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 384 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 385 | grand_child->DrawTransform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 386 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 387 | grand_child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 388 | } |
| 389 | |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 390 | TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) { |
| 391 | // Tests that effect tree node gets a valid transform id when a layer |
| 392 | // has opacity but doesn't create a render surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 393 | LayerImpl* parent = root_layer_for_testing(); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 394 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 395 | child->SetDrawsContent(true); |
| 396 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 397 | parent->SetBounds(gfx::Size(100, 100)); |
| 398 | child->SetPosition(gfx::PointF(10, 10)); |
| 399 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 400 | child->test_properties()->opacity = 0.f; |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 401 | ExecuteCalculateDrawProperties(parent); |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 402 | EffectTree& effect_tree = |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 403 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 404 | EffectNode* node = effect_tree.Node(child->effect_tree_index()); |
| 405 | const int transform_tree_size = parent->layer_tree_impl() |
| 406 | ->property_trees() |
| 407 | ->transform_tree.next_available_id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 408 | EXPECT_LT(node->transform_id, transform_tree_size); |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 409 | } |
| 410 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 411 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 412 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 413 | LayerImpl* layer = AddChild<LayerImpl>(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 414 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 415 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 416 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 417 | EffectTree& effect_tree = |
| 418 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 419 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 420 | root->SetBounds(gfx::Size(1, 2)); |
| 421 | |
| 422 | // 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] | 423 | // transform or the screenspace transform. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 424 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 425 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 426 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 427 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 428 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 429 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 430 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 431 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 432 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 433 | // Case 2: The anchor point by itself (without a layer transform) should have |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 434 | // no effect on the transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 435 | layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 436 | layer->SetBounds(gfx::Size(10, 12)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 437 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 438 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 439 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 440 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 441 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 442 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 443 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 444 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 445 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 446 | // Case 3: A change in actual position affects both the draw transform and |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 447 | // screen space transform. |
| 448 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 449 | position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 450 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 451 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 452 | ExecuteCalculateDrawProperties(root); |
| 453 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 454 | position_transform, |
| 455 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 456 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 457 | position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 458 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 459 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 460 | // Case 4: In the correct sequence of transforms, the layer transform should |
| 461 | // pre-multiply the translation-to-center. This is easily tested by using a |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 462 | // scale transform, because scale and translation are not commutative. |
| 463 | gfx::Transform layer_transform; |
| 464 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 465 | layer->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 466 | layer->test_properties()->transform_origin = gfx::Point3F(); |
| 467 | layer->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 468 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 469 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 470 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 471 | layer_transform, |
| 472 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 473 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 474 | layer_transform, |
| 475 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 476 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 477 | // Case 5: The layer transform should occur with respect to the anchor point. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 478 | gfx::Transform translation_to_anchor; |
| 479 | translation_to_anchor.Translate(5.0, 0.0); |
| 480 | gfx::Transform expected_result = |
| 481 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 482 | layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 483 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 484 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 485 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 486 | expected_result, |
| 487 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 488 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 489 | expected_result, |
| 490 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 491 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 492 | // Case 6: Verify that position pre-multiplies the layer transform. The |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 493 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 494 | // it is still worth testing to detect accidental regressions. |
| 495 | expected_result = position_transform * translation_to_anchor * |
| 496 | layer_transform * Inverse(translation_to_anchor); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 497 | layer->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 498 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 499 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 500 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 501 | expected_result, |
| 502 | draw_property_utils::DrawTransform(layer, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 503 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 504 | expected_result, |
| 505 | draw_property_utils::ScreenSpaceTransform(layer, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 506 | } |
| 507 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 508 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 509 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 510 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 511 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 512 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 513 | -kScrollOffset.y()); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 514 | float page_scale = 0.888f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 515 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 516 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 517 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 518 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 519 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 520 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 521 | &task_graph_runner); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 522 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 523 | std::unique_ptr<LayerImpl> sublayer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 524 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 525 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 526 | sublayer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 527 | sublayer->SetBounds(gfx::Size(500, 500)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 528 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 529 | std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 530 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 531 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 532 | scroll_layer->SetBounds(gfx::Size(10, 20)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 533 | std::unique_ptr<LayerImpl> clip_layer_scoped_ptr( |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 534 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 535 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 536 | |
| 537 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 538 | clip_layer->SetBounds( |
| 539 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 540 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 541 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 542 | SetScrollOffsetDelta(scroll_layer, kScrollDelta); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 543 | gfx::Transform impl_transform; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 544 | scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 545 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 546 | clip_layer->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr)); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 547 | scroll_layer_raw_ptr->layer_tree_impl() |
| 548 | ->property_trees() |
| 549 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(), |
| 550 | kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 551 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 552 | std::unique_ptr<LayerImpl> root( |
| 553 | LayerImpl::Create(host_impl.active_tree(), 3)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 554 | root->SetBounds(gfx::Size(3, 4)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 555 | root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 556 | root->SetHasRenderSurface(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 557 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 558 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 559 | |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 560 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 561 | scroll_layer->test_properties()->parent); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 562 | gfx::Transform expected_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 563 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 564 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 565 | page_scale * kDeviceScale), |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 566 | MathUtil::Round(sub_layer_screen_position.y() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 567 | page_scale * kDeviceScale)); |
| 568 | expected_transform.Scale(page_scale * kDeviceScale, |
| 569 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 570 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 571 | sublayer->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 572 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 573 | sublayer->ScreenSpaceTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 574 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 575 | gfx::Transform arbitrary_translate; |
| 576 | const float kTranslateX = 10.6f; |
| 577 | const float kTranslateY = 20.6f; |
| 578 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 579 | scroll_layer->test_properties()->transform = arbitrary_translate; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 580 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 581 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 582 | scroll_layer->test_properties()->parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 583 | expected_transform.MakeIdentity(); |
| 584 | expected_transform.Translate( |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 585 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 586 | sub_layer_screen_position.x() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 587 | kDeviceScale), |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 588 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 589 | sub_layer_screen_position.y() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 590 | kDeviceScale)); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 591 | expected_transform.Scale(page_scale * kDeviceScale, |
| 592 | page_scale * kDeviceScale); |
| 593 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 594 | sublayer->DrawTransform()); |
| 595 | |
| 596 | // Test that page scale is updated even when we don't rebuild property trees. |
| 597 | page_scale = 1.888f; |
| 598 | root_layer->layer_tree_impl()->SetViewportLayersFromIds( |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 599 | Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(), |
| 600 | Layer::INVALID_ID, Layer::INVALID_ID); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 601 | root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 602 | EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 603 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 604 | scroll_layer->test_properties()->parent); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 605 | |
| 606 | expected_transform.MakeIdentity(); |
| 607 | expected_transform.Translate( |
| 608 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 609 | sub_layer_screen_position.x() * page_scale * |
| 610 | kDeviceScale), |
| 611 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 612 | sub_layer_screen_position.y() * page_scale * |
| 613 | kDeviceScale)); |
| 614 | expected_transform.Scale(page_scale * kDeviceScale, |
| 615 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 616 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 617 | sublayer->DrawTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 618 | } |
| 619 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 620 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 621 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 622 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 623 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 624 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 625 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 626 | // One-time setup of root layer |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 627 | root->SetBounds(gfx::Size(1, 2)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 628 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 629 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 630 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 631 | EffectTree& effect_tree = |
| 632 | host_impl()->active_tree()->property_trees()->effect_tree; |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 633 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 634 | // Case 1: parent's anchor point should not affect child or grand_child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 635 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f); |
| 636 | parent->SetBounds(gfx::Size(10, 12)); |
| 637 | child->SetBounds(gfx::Size(16, 18)); |
| 638 | grand_child->SetBounds(gfx::Size(76, 78)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 639 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 640 | |
| 641 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 642 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 643 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 644 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 645 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 646 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 647 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 648 | gfx::Transform(), draw_property_utils::DrawTransform( |
| 649 | grand_child, transform_tree, effect_tree)); |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 650 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 651 | gfx::Transform(), |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 652 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 653 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 654 | // Case 2: parent's position affects child and grand_child. |
| 655 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 656 | parent_position_transform.Translate(0.f, 1.2f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 657 | parent->SetPosition(gfx::PointF(0.f, 1.2f)); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 658 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 659 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 660 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 661 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 662 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 663 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 664 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 665 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
| 666 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 667 | parent_position_transform, draw_property_utils::DrawTransform( |
| 668 | grand_child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 669 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 670 | parent_position_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 671 | draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 672 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 673 | // Case 3: parent's local transform affects child and grandchild |
| 674 | gfx::Transform parent_layer_transform; |
| 675 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 676 | gfx::Transform parent_translation_to_anchor; |
| 677 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 678 | gfx::Transform parent_composite_transform = |
| 679 | parent_translation_to_anchor * parent_layer_transform * |
| 680 | Inverse(parent_translation_to_anchor); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 681 | parent->test_properties()->transform = parent_layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 682 | parent->SetPosition(gfx::PointF()); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 683 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 684 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 685 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 686 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 687 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 688 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 689 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 690 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 691 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 692 | parent_composite_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 693 | draw_property_utils::DrawTransform(grand_child, transform_tree, |
| 694 | 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(grand_child, transform_tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 698 | } |
| 699 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 700 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 701 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 702 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 703 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 704 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 705 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 706 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 707 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 708 | gfx::Transform parent_translation_to_anchor; |
| 709 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 710 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 711 | gfx::Transform parent_composite_transform = |
| 712 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 713 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 714 | gfx::Vector2dF parent_composite_scale = |
| 715 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 716 | 1.f); |
| 717 | gfx::Transform surface_sublayer_transform; |
| 718 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 719 | parent_composite_scale.y()); |
| 720 | gfx::Transform surface_sublayer_composite_transform = |
| 721 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 722 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 723 | root->SetBounds(gfx::Size(1, 2)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 724 | parent->test_properties()->transform = parent_layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 725 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f); |
| 726 | parent->SetBounds(gfx::Size(100, 120)); |
| 727 | child->SetBounds(gfx::Size(16, 18)); |
| 728 | child->test_properties()->force_render_surface = true; |
| 729 | grand_child->SetBounds(gfx::Size(8, 10)); |
| 730 | grand_child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 731 | ExecuteCalculateDrawProperties(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 732 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 733 | // Render surface should have been created now. |
| 734 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 735 | ASSERT_EQ(child->render_surface(), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 736 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 737 | // The child layer's draw transform should refer to its new render surface. |
| 738 | // The screen-space transform, however, should still refer to the root. |
| 739 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 740 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 741 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 742 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 743 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 744 | // Because the grand_child is the only drawable content, the child's render |
| 745 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 746 | // surface's subtree is drawn must be removed from the composite transform. |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 747 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, |
| 748 | child->render_target()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 749 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 750 | // The screen space is the same as the target since the child surface draws |
| 751 | // into the root. |
| 752 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 753 | surface_sublayer_composite_transform, |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 754 | child->render_target()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 755 | } |
| 756 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 757 | TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 758 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 759 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 760 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 761 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 762 | |
| 763 | gfx::Transform parent_transform; |
| 764 | parent_transform.Translate(10.0, 10.0); |
| 765 | |
| 766 | gfx::Transform child_transform; |
| 767 | child_transform.Rotate(45.0); |
| 768 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 769 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 770 | parent->test_properties()->transform = parent_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 771 | parent->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 772 | child->test_properties()->transform = child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 773 | child->SetBounds(gfx::Size(10, 10)); |
| 774 | child->test_properties()->force_render_surface = true; |
| 775 | grand_child->SetPosition(gfx::PointF(2.f, 2.f)); |
| 776 | grand_child->SetBounds(gfx::Size(20, 20)); |
| 777 | grand_child->SetDrawsContent(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 778 | |
| 779 | gfx::Transform expected_grand_child_screen_space_transform; |
| 780 | expected_grand_child_screen_space_transform.Translate(10.0, 10.0); |
| 781 | expected_grand_child_screen_space_transform.Rotate(45.0); |
| 782 | expected_grand_child_screen_space_transform.Translate(2.0, 2.0); |
| 783 | |
| 784 | // First compute draw properties with separate surfaces enabled. |
| 785 | ExecuteCalculateDrawProperties(root); |
| 786 | |
| 787 | // The grand child's draw transform should be its offset wrt the child. |
| 788 | gfx::Transform expected_grand_child_draw_transform; |
| 789 | expected_grand_child_draw_transform.Translate(2.0, 2.0); |
| 790 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 791 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 792 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 793 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 794 | |
| 795 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 796 | |
| 797 | // With separate surfaces disabled, the grand child's draw transform should be |
| 798 | // the same as its screen space transform. |
| 799 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 800 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 801 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 802 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 803 | } |
| 804 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 805 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 806 | // This test creates a more complex tree and verifies it all at once. This |
| 807 | // covers the following cases: |
| 808 | // - layers that are described w.r.t. a render surface: should have draw |
| 809 | // transforms described w.r.t. that surface |
| 810 | // - A render surface described w.r.t. an ancestor render surface: should |
| 811 | // have a draw transform described w.r.t. that ancestor surface |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 812 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 813 | // a render surface that is described w.r.t. an ancestor render surface. |
| 814 | // - verifying that each layer has a reference to the correct render surface |
| 815 | // and render target values. |
| 816 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 817 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 818 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 819 | parent->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 820 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 821 | render_surface1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 822 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 823 | render_surface2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 824 | LayerImpl* child_of_root = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 825 | child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 826 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 827 | child_of_rs1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 828 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 829 | child_of_rs2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 830 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 831 | grand_child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 832 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 833 | grand_child_of_rs1->SetDrawsContent(true); |
| 834 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 835 | grand_child_of_rs2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 836 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 837 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 838 | // to have a new render surface. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 839 | render_surface1->test_properties()->opacity = 0.5f; |
| 840 | render_surface2->test_properties()->opacity = 0.33f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 841 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 842 | // 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^] | 843 | // (10,10). Matrix "A" is the composite layer transform used in all layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 844 | gfx::Transform translation_to_anchor; |
| 845 | translation_to_anchor.Translate(2.5, 0.0); |
| 846 | gfx::Transform layer_transform; |
| 847 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 848 | |
| 849 | gfx::Transform A = |
| 850 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 851 | |
| 852 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 853 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 854 | gfx::Transform surface1_sublayer_transform; |
| 855 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 856 | surface1_parent_transform_scale.y()); |
| 857 | |
| 858 | // SS1 = transform given to the subtree of render_surface1 |
| 859 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 860 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 861 | // the owning layer |
| 862 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 863 | |
| 864 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 865 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 866 | gfx::Transform surface2_sublayer_transform; |
| 867 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 868 | surface2_parent_transform_scale.y()); |
| 869 | |
| 870 | // SS2 = transform given to the subtree of render_surface2 |
| 871 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 872 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 873 | // the owning layer |
| 874 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 875 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 876 | root->SetBounds(gfx::Size(1, 2)); |
| 877 | parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 878 | parent->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 879 | parent->SetBounds(gfx::Size(10, 10)); |
| 880 | render_surface1->test_properties()->transform_origin = |
| 881 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 882 | render_surface1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 883 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 884 | render_surface1->test_properties()->force_render_surface = true; |
| 885 | render_surface2->test_properties()->transform_origin = |
| 886 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 887 | render_surface2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 888 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 889 | render_surface2->test_properties()->force_render_surface = true; |
| 890 | child_of_root->test_properties()->transform_origin = |
| 891 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 892 | child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 893 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 894 | child_of_rs1->test_properties()->transform_origin = |
| 895 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 896 | child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 897 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 898 | child_of_rs2->test_properties()->transform_origin = |
| 899 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 900 | child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 901 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 902 | grand_child_of_root->test_properties()->transform_origin = |
| 903 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 904 | grand_child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 905 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 906 | grand_child_of_rs1->test_properties()->transform_origin = |
| 907 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 908 | grand_child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 909 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 910 | grand_child_of_rs2->test_properties()->transform_origin = |
| 911 | gfx::Point3F(2.5f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 912 | grand_child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 913 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 914 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 915 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 916 | |
| 917 | // Only layers that are associated with render surfaces should have an actual |
| 918 | // RenderSurface() value. |
| 919 | ASSERT_TRUE(root->render_surface()); |
| 920 | ASSERT_FALSE(child_of_root->render_surface()); |
| 921 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 922 | |
| 923 | ASSERT_TRUE(render_surface1->render_surface()); |
| 924 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 925 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 926 | |
| 927 | ASSERT_TRUE(render_surface2->render_surface()); |
| 928 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 929 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 930 | |
| 931 | // Verify all render target accessors |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 932 | EXPECT_EQ(root->render_surface(), parent->render_target()); |
| 933 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 934 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 935 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 936 | EXPECT_EQ(render_surface1->render_surface(), |
| 937 | render_surface1->render_target()); |
| 938 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 939 | EXPECT_EQ(render_surface1->render_surface(), |
| 940 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 941 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 942 | EXPECT_EQ(render_surface2->render_surface(), |
| 943 | render_surface2->render_target()); |
| 944 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 945 | EXPECT_EQ(render_surface2->render_surface(), |
| 946 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 947 | |
| 948 | // Verify layer draw transforms note that draw transforms are described with |
| 949 | // respect to the nearest ancestor render surface but screen space transforms |
| 950 | // are described with respect to the root. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 951 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform()); |
| 952 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 953 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 954 | grand_child_of_root->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 955 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 956 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform()); |
| 957 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 958 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 959 | grand_child_of_rs1->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 960 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 961 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform()); |
| 962 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 963 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 964 | grand_child_of_rs2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 965 | |
| 966 | // Verify layer screen-space transforms |
| 967 | // |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 968 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform()); |
| 969 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform()); |
| 970 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
| 971 | grand_child_of_root->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 972 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 973 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 974 | render_surface1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 975 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 976 | child_of_rs1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 977 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 978 | grand_child_of_rs1->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 * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 981 | render_surface2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 982 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 983 | child_of_rs2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 984 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 985 | grand_child_of_rs2->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 986 | |
| 987 | // Verify render surface transforms. |
| 988 | // |
| 989 | // Draw transform of render surface 1 is described with respect to root. |
| 990 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 991 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 992 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 993 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 994 | // Draw transform of render surface 2 is described with respect to render |
| 995 | // surface 1. |
| 996 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 997 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 998 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 999 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1000 | render_surface2->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1001 | |
| 1002 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 1003 | // is expected that we correctly set up transforms so that the y-component of |
| 1004 | // the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1005 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1006 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1007 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1008 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1009 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1010 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1011 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1012 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 1013 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1014 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1015 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1016 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1017 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1018 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 1019 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1020 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1021 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1022 | } |
| 1023 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1024 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1025 | // For layers that flatten their subtree, there should be an orthographic |
| 1026 | // projection (for x and y values) in the middle of the transform sequence. |
| 1027 | // Note that the way the code is currently implemented, it is not expected to |
| 1028 | // use a canonical orthographic projection. |
| 1029 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1030 | LayerImpl* root = root_layer_for_testing(); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1031 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1032 | child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1033 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1034 | grand_child->SetDrawsContent(true); |
| 1035 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 1036 | great_grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1037 | |
| 1038 | gfx::Transform rotation_about_y_axis; |
| 1039 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1040 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1041 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1042 | child->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1043 | child->SetBounds(gfx::Size(10, 10)); |
| 1044 | child->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1045 | grand_child->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1046 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1047 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1048 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1049 | // No layers in this test should preserve 3d. |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1050 | ASSERT_TRUE(root->test_properties()->should_flatten_transform); |
| 1051 | ASSERT_TRUE(child->test_properties()->should_flatten_transform); |
| 1052 | ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform); |
| 1053 | ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1054 | |
| 1055 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1056 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1057 | gfx::Transform expected_grand_child_draw_transform = |
| 1058 | rotation_about_y_axis; // draws onto child's render surface |
| 1059 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1060 | flattened_rotation_about_y.FlattenTo2d(); |
| 1061 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1062 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1063 | gfx::Transform expected_great_grand_child_draw_transform = |
| 1064 | flattened_rotation_about_y; |
| 1065 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 1066 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1067 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 1068 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1069 | |
| 1070 | // The child's draw transform should have been taken by its surface. |
| 1071 | ASSERT_TRUE(child->render_surface()); |
| 1072 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1073 | child->render_surface()->draw_transform()); |
| 1074 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1075 | expected_child_screen_space_transform, |
| 1076 | child->render_surface()->screen_space_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1077 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1078 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1079 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1080 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1081 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1082 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1083 | grand_child->ScreenSpaceTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1084 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1085 | great_grand_child->DrawTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1086 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1087 | expected_great_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1088 | great_grand_child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1089 | } |
| 1090 | |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1091 | TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1092 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1093 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1094 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1095 | |
| 1096 | gfx::Transform child_transform; |
| 1097 | child_transform.Translate(50.0, 50.0); |
| 1098 | child_transform.RotateAboutZAxis(30.0); |
| 1099 | |
| 1100 | gfx::Transform grand_child_transform; |
| 1101 | grand_child_transform.RotateAboutYAxis(90.0); |
| 1102 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1103 | root->SetBounds(gfx::Size(200, 200)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1104 | child->test_properties()->transform = child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1105 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1106 | grand_child->test_properties()->transform = grand_child_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1107 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1108 | grand_child->test_properties()->should_flatten_transform = false; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1109 | grand_child->SetDrawsContent(true); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1110 | float device_scale_factor = 1.f; |
| 1111 | float page_scale_factor = 1.f; |
| 1112 | LayerImpl* page_scale_layer = nullptr; |
| 1113 | // Visible rects computed by combining clips in target space and root space |
| 1114 | // don't match because of rotation transforms. So, we skip |
| 1115 | // verify_visible_rect_calculations. |
| 1116 | bool skip_verify_visible_rect_calculations = true; |
| 1117 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 1118 | page_scale_layer, |
| 1119 | skip_verify_visible_rect_calculations); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1120 | |
| 1121 | // Mapping grand_child's bounds to target space produces a non-empty rect |
| 1122 | // that is fully contained within the target's bounds, so grand_child should |
| 1123 | // be considered fully visible. |
| 1124 | EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1125 | grand_child->visible_layer_rect()); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1126 | } |
| 1127 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1128 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1129 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1130 | // skipping a necessary translation. Without that translation, the coordinate |
| 1131 | // space of the layer's draw transform is incorrect. |
| 1132 | // |
| 1133 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1134 | // but if that layer becomes a render surface, then its draw transform is |
| 1135 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1136 | // incorrectly as a result. |
| 1137 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1138 | LayerImpl* root = root_layer_for_testing(); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1139 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1140 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1141 | grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1142 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1143 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1144 | // The child height is zero, but has non-zero width that should be accounted |
| 1145 | // for while computing draw transforms. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1146 | child->SetBounds(gfx::Size(10, 0)); |
| 1147 | child->test_properties()->force_render_surface = true; |
| 1148 | grand_child->SetBounds(gfx::Size(10, 10)); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1149 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1150 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1151 | ASSERT_TRUE(child->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1152 | // This is the real test, the rest are sanity checks. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1153 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1154 | child->render_surface()->draw_transform()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1155 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1156 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1157 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1158 | } |
| 1159 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1160 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1161 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1162 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 1163 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 1164 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1165 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1166 | gfx::Transform translate; |
| 1167 | translate.Translate3d(5, 5, 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1168 | |
| 1169 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1170 | render_surface->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1171 | render_surface->SetBounds(gfx::Size(100, 100)); |
| 1172 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1173 | child->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1174 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1175 | grand_child->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1176 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1177 | grand_child->SetDrawsContent(true); |
| 1178 | |
| 1179 | // render_surface will have a sublayer scale because of device scale factor. |
| 1180 | float device_scale_factor = 2.0f; |
| 1181 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1182 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1183 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1184 | inputs.device_scale_factor = device_scale_factor; |
| 1185 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1186 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1187 | |
| 1188 | // Between grand_child and render_surface, we translate by (10, 10) and scale |
| 1189 | // by a factor of 2. |
| 1190 | gfx::Vector2dF expected_translation(20.0f, 20.0f); |
| 1191 | EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(), |
| 1192 | expected_translation); |
| 1193 | } |
| 1194 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1195 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1196 | // Transformations applied at the root of the tree should be forwarded |
| 1197 | // to child layers instead of applied to the root RenderSurface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1198 | LayerImpl* root = root_layer_for_testing(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1199 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1200 | |
| 1201 | root->SetDrawsContent(true); |
| 1202 | root->SetBounds(gfx::Size(20, 20)); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1203 | child->SetDrawsContent(true); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1204 | child->SetScrollClipLayer(root->id()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1205 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1206 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1207 | gfx::Transform translate; |
| 1208 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1209 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1210 | LayerImplList render_surface_layer_list_impl; |
| 1211 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1212 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1213 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1214 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1215 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1216 | translate, root->draw_properties().target_space_transform); |
| 1217 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1218 | translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1219 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1220 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1221 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1222 | |
| 1223 | gfx::Transform scale; |
| 1224 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1225 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1226 | LayerImplList render_surface_layer_list_impl; |
| 1227 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1228 | root, root->bounds(), scale, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1229 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1230 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1231 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1232 | scale, root->draw_properties().target_space_transform); |
| 1233 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1234 | scale, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1235 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1236 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1237 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1238 | |
| 1239 | gfx::Transform rotate; |
| 1240 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1241 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1242 | LayerImplList render_surface_layer_list_impl; |
| 1243 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1244 | root, root->bounds(), rotate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1245 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1246 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1247 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1248 | rotate, root->draw_properties().target_space_transform); |
| 1249 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1250 | rotate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1251 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1252 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1253 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1254 | |
| 1255 | gfx::Transform composite; |
| 1256 | composite.ConcatTransform(translate); |
| 1257 | composite.ConcatTransform(scale); |
| 1258 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1259 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1260 | LayerImplList render_surface_layer_list_impl; |
| 1261 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1262 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1263 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1264 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1265 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1266 | composite, root->draw_properties().target_space_transform); |
| 1267 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1268 | composite, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1269 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1270 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1271 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1272 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1273 | // Verify it composes correctly with device scale. |
| 1274 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1275 | |
| 1276 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1277 | LayerImplList render_surface_layer_list_impl; |
| 1278 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1279 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1280 | inputs.device_scale_factor = device_scale_factor; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1281 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1282 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1283 | gfx::Transform device_scaled_translate = translate; |
| 1284 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1285 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1286 | device_scaled_translate, |
| 1287 | root->draw_properties().target_space_transform); |
| 1288 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1289 | device_scaled_translate, |
| 1290 | child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1291 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1292 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1293 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1294 | |
| 1295 | // Verify it composes correctly with page scale. |
| 1296 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1297 | |
| 1298 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1299 | LayerImplList render_surface_layer_list_impl; |
| 1300 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1301 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1302 | inputs.page_scale_factor = page_scale_factor; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1303 | inputs.page_scale_layer = root; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1304 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1305 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1306 | gfx::Transform page_scaled_translate = translate; |
| 1307 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1308 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1309 | page_scaled_translate, root->draw_properties().target_space_transform); |
| 1310 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1311 | page_scaled_translate, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1312 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1313 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1314 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1315 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1316 | // Verify that it composes correctly with transforms directly on root layer. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1317 | root->test_properties()->transform = composite; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1318 | |
| 1319 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1320 | LayerImplList render_surface_layer_list_impl; |
| 1321 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1322 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1323 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1324 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1325 | gfx::Transform compositeSquared = composite; |
| 1326 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1327 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1328 | compositeSquared, root->draw_properties().target_space_transform); |
| 1329 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1330 | compositeSquared, child->draw_properties().target_space_transform); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 1331 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 1332 | root->render_surface()->draw_transform()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1333 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1334 | } |
| 1335 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1336 | TEST_F(LayerTreeHostCommonTest, |
| 1337 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1338 | LayerImpl* root = root_layer_for_testing(); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1339 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1340 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1341 | |
| 1342 | root->SetBounds(gfx::Size(10, 10)); |
| 1343 | root->SetMasksToBounds(true); |
| 1344 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1345 | render_surface1->test_properties()->force_render_surface = true; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1346 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1347 | child->SetPosition(gfx::PointF(30.f, 30.f)); |
| 1348 | child->SetBounds(gfx::Size(10, 10)); |
| 1349 | ExecuteCalculateDrawProperties(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1350 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1351 | // 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] | 1352 | // the intermediate render surface should not be listed here, even if it was |
| 1353 | // forced to be created. Render surfaces without children or visible content |
| 1354 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1355 | // of size 0). |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1356 | ASSERT_TRUE(root->render_surface()); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1357 | EXPECT_EQ(1U, render_surface_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1358 | } |
| 1359 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1360 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1361 | LayerImpl* root = root_layer_for_testing(); |
| 1362 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1363 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1364 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1365 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1366 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1367 | render_surface1->test_properties()->opacity = 0.f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1368 | child->SetBounds(gfx::Size(10, 10)); |
| 1369 | child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1370 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1371 | LayerImplList render_surface_layer_list; |
| 1372 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1373 | root, root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1374 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1375 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1376 | |
| 1377 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1378 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1379 | // have been extended by the children. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1380 | ASSERT_TRUE(root->render_surface()); |
| 1381 | EXPECT_EQ(0U, root->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1382 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1383 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 1384 | EXPECT_EQ(gfx::Rect(), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1385 | } |
| 1386 | |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1387 | TEST_F(LayerTreeHostCommonTest, |
| 1388 | RenderSurfaceListForTransparentChildWithBackgroundFilter) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1389 | LayerImpl* root = root_layer_for_testing(); |
| 1390 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1391 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1392 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1393 | root->SetBounds(gfx::Size(10, 10)); |
| 1394 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 1395 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1396 | render_surface1->test_properties()->opacity = 0.f; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 1397 | render_surface1->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1398 | FilterOperations filters; |
| 1399 | filters.Append(FilterOperation::CreateBlurFilter(1.5f)); |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 1400 | render_surface1->test_properties()->background_filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1401 | child->SetBounds(gfx::Size(10, 10)); |
| 1402 | child->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1403 | |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1404 | { |
| 1405 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1406 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1407 | root, root->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1408 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1409 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1410 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1411 | } |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1412 | // The layer is fully transparent, but has a background filter, so it |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1413 | // shouldn't be skipped and should be drawn. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1414 | ASSERT_TRUE(root->render_surface()); |
| 1415 | EXPECT_EQ(1U, root->render_surface()->layer_list().size()); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1416 | EXPECT_EQ(gfx::RectF(0, 0, 10, 10), |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1417 | root->render_surface()->DrawableContentRect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1418 | EffectTree& effect_tree = |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1419 | root->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1420 | EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1421 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1422 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1423 | // When root is transparent, the layer should not be drawn. |
jaydasika | 898b2f1 | 2016-08-20 04:22:09 | [diff] [blame] | 1424 | effect_tree.OnOpacityAnimated(0.f, root->effect_tree_index(), |
| 1425 | root->layer_tree_impl()); |
| 1426 | effect_tree.OnOpacityAnimated(1.f, render_surface1->effect_tree_index(), |
| 1427 | root->layer_tree_impl()); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1428 | render_surface1->set_visible_layer_rect(gfx::Rect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1429 | { |
| 1430 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1431 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1432 | root, root->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1433 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1434 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | node = effect_tree.Node(render_surface1->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 1438 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1439 | EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect()); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1440 | } |
| 1441 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1442 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1443 | LayerImpl* root = root_layer_for_testing(); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1444 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1445 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1446 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1447 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1448 | gfx::Transform scale_matrix; |
| 1449 | scale_matrix.Scale(2.0f, 2.0f); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1450 | |
| 1451 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1452 | parent->test_properties()->transform = scale_matrix; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1453 | FilterOperations filters; |
| 1454 | filters.Append(FilterOperation::CreateBlurFilter(10.0f)); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1455 | parent->test_properties()->filters = filters; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1456 | parent->test_properties()->force_render_surface = true; |
| 1457 | child1->SetBounds(gfx::Size(25, 25)); |
| 1458 | child1->SetDrawsContent(true); |
| 1459 | child1->test_properties()->force_render_surface = true; |
| 1460 | child2->SetPosition(gfx::PointF(25, 25)); |
| 1461 | child2->SetBounds(gfx::Size(25, 25)); |
| 1462 | child2->SetDrawsContent(true); |
| 1463 | child2->test_properties()->force_render_surface = true; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1464 | |
| 1465 | LayerImplList render_surface_layer_list; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1466 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1467 | root, root->bounds(), &render_surface_layer_list); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1468 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1469 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1470 | |
| 1471 | ASSERT_TRUE(parent->render_surface()); |
| 1472 | EXPECT_EQ(2U, parent->render_surface()->layer_list().size()); |
| 1473 | EXPECT_EQ(4U, render_surface_layer_list.size()); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1474 | |
| 1475 | // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the |
| 1476 | // blur (-30,-30 110x110), and then scaled by the scale matrix |
| 1477 | // (-60,-60 220x220). |
| 1478 | EXPECT_EQ(gfx::RectF(-60, -60, 220, 220), |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1479 | parent->render_surface()->DrawableContentRect()); |
| 1480 | } |
| 1481 | |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1482 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1483 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1484 | LayerImpl* child = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1485 | |
| 1486 | root->SetBounds(gfx::Size(100, 100)); |
| 1487 | child->SetBounds(gfx::Size(25, 25)); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1488 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1489 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1490 | FilterOperations filters; |
| 1491 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1492 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1493 | child->test_properties()->filters = filters; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1494 | ExecuteCalculateDrawProperties(root); |
| 1495 | |
| 1496 | // The render surface's size should be unaffected by the offset image filter; |
| 1497 | // it need only have a drawable content rect large enough to contain the |
| 1498 | // contents (at the new offset). |
| 1499 | ASSERT_TRUE(child->render_surface()); |
| 1500 | EXPECT_EQ(gfx::RectF(50, 50, 25, 25), |
| 1501 | child->render_surface()->DrawableContentRect()); |
| 1502 | } |
| 1503 | |
| 1504 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) { |
| 1505 | const float device_scale_factor = 2.0f; |
| 1506 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1507 | LayerImpl* root = root_layer_for_testing(); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1508 | LayerImpl* child = AddChild<LayerImpl>(root); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1509 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1510 | root->SetBounds(gfx::Size(100, 100)); |
| 1511 | child->SetBounds(gfx::Size(25, 25)); |
| 1512 | child->SetDrawsContent(true); |
| 1513 | child->test_properties()->force_render_surface = true; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1514 | |
| 1515 | FilterOperations filters; |
| 1516 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1517 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 1518 | child->test_properties()->filters = filters; |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1519 | |
| 1520 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 1521 | |
| 1522 | // The render surface's size should be unaffected by the offset image filter; |
| 1523 | // it need only have a drawable content rect large enough to contain the |
| 1524 | // contents (at the new offset). All coordinates should be scaled by 2, |
| 1525 | // corresponding to the device scale factor. |
| 1526 | ASSERT_TRUE(child->render_surface()); |
| 1527 | EXPECT_EQ(gfx::RectF(100, 100, 50, 50), |
| 1528 | child->render_surface()->DrawableContentRect()); |
| 1529 | } |
| 1530 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1531 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1532 | LayerImpl* root = root_layer_for_testing(); |
| 1533 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1534 | |
| 1535 | root->SetBounds(gfx::Size(10, 10)); |
| 1536 | child->SetBounds(gfx::Size(10, 10)); |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1537 | child->SetDrawsContent(true); |
ajuma | 4c14b25 | 2016-07-26 20:10:59 | [diff] [blame] | 1538 | child->test_properties()->blend_mode = SkXfermode::kMultiply_Mode; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1539 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1540 | child->test_properties()->force_render_surface = true; |
| 1541 | ExecuteCalculateDrawProperties(root); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1542 | |
| 1543 | // Since the child layer has a blend mode other than normal, it should get |
| 1544 | // its own render surface. Also, layer's draw_properties should contain the |
| 1545 | // default blend mode, since the render surface becomes responsible for |
| 1546 | // applying the blend mode. |
| 1547 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1548 | EXPECT_EQ(1.0f, child->draw_opacity()); |
| 1549 | EXPECT_EQ(0.5f, child->render_surface()->draw_opacity()); |
jaydasika | 92239dc | 2015-08-15 02:59:26 | [diff] [blame] | 1550 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode()); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1551 | } |
| 1552 | |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1553 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1554 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1555 | LayerImpl* surface1 = AddChildToRoot<LayerImpl>(); |
| 1556 | LayerImpl* not_surface = AddChild<LayerImpl>(surface1); |
| 1557 | LayerImpl* surface2 = AddChild<LayerImpl>(not_surface); |
| 1558 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1559 | root->SetBounds(gfx::Size(10, 10)); |
| 1560 | surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1561 | surface1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1562 | surface1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1563 | surface1->test_properties()->force_render_surface = true; |
| 1564 | not_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1565 | not_surface->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1566 | surface2->SetBounds(gfx::Size(10, 10)); |
| 1567 | surface2->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1568 | surface2->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1569 | surface2->test_properties()->force_render_surface = true; |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1570 | ExecuteCalculateDrawProperties(root); |
| 1571 | |
| 1572 | ASSERT_TRUE(surface1->render_surface()); |
| 1573 | ASSERT_FALSE(not_surface->render_surface()); |
| 1574 | ASSERT_TRUE(surface2->render_surface()); |
| 1575 | EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); |
| 1576 | // surface2's draw opacity should include the opacity of not-surface and |
| 1577 | // itself, but not the opacity of surface1. |
| 1578 | EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); |
| 1579 | } |
| 1580 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1581 | TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) { |
| 1582 | // Tests that when separate surfaces are disabled, a layer's draw opacity is |
| 1583 | // the product of all ancestor layer opacties and the layer's own opacity. |
| 1584 | // (Rendering will still be incorrect in situations where we really do need |
| 1585 | // surfaces to apply opacity, such as when we have overlapping layers with an |
| 1586 | // ancestor whose opacity is <1.) |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1587 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1588 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1589 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1590 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1591 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1592 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1593 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1594 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1595 | root->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1596 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1597 | parent->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1598 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1599 | child1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1600 | child1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1601 | child1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1602 | child1->test_properties()->force_render_surface = true; |
| 1603 | child2->SetBounds(gfx::Size(100, 100)); |
| 1604 | child2->SetDrawsContent(true); |
| 1605 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 1606 | grand_child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1607 | grand_child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1608 | grand_child->test_properties()->force_render_surface = true; |
| 1609 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
| 1610 | leaf_node1->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1611 | leaf_node1->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1612 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
| 1613 | leaf_node2->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1614 | leaf_node2->test_properties()->opacity = 0.5f; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1615 | |
| 1616 | // With surfaces enabled, each layer's draw opacity is the product of layer |
| 1617 | // opacities on the path from the layer to its render target, not including |
| 1618 | // the opacity of the layer that owns the target surface (since that opacity |
| 1619 | // is applied by the surface). |
| 1620 | ExecuteCalculateDrawProperties(root); |
| 1621 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1622 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1623 | EXPECT_EQ(1.f, child1->draw_opacity()); |
| 1624 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1625 | EXPECT_EQ(1.f, grand_child->draw_opacity()); |
| 1626 | EXPECT_EQ(0.5f, leaf_node1->draw_opacity()); |
| 1627 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1628 | |
| 1629 | // With surfaces disabled, each layer's draw opacity is the product of layer |
| 1630 | // opacities on the path from the layer to the root. |
| 1631 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1632 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1633 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1634 | EXPECT_EQ(0.5f, child1->draw_opacity()); |
| 1635 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1636 | EXPECT_EQ(0.25f, grand_child->draw_opacity()); |
| 1637 | EXPECT_EQ(0.125f, leaf_node1->draw_opacity()); |
| 1638 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1639 | } |
| 1640 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1641 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1642 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1643 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1644 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1645 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1646 | root->SetBounds(gfx::Size(10, 10)); |
| 1647 | render_surface1->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1648 | render_surface1->test_properties()->force_render_surface = true; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1649 | child->SetBounds(gfx::Size(10, 10)); |
| 1650 | child->SetDrawsContent(true); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1651 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1652 | { |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1653 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1654 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1655 | // The root layer always creates a render surface |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1656 | EXPECT_TRUE(root->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1657 | EXPECT_TRUE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1658 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1659 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1660 | { |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1661 | render_surface1->test_properties()->force_render_surface = false; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1662 | render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 1663 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
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_FALSE(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 | } |
| 1668 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1669 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1670 | // Render surfaces act as a flattening point for their subtree, so should |
| 1671 | // always flatten the target-to-screen space transform seen by descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1672 | LayerImpl* root = root_layer_for_testing(); |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1673 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1674 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1675 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1676 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1677 | gfx::Transform rotation_about_y_axis; |
| 1678 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1679 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1680 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 1681 | parent->test_properties()->transform = rotation_about_y_axis; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1682 | parent->SetBounds(gfx::Size(10, 10)); |
| 1683 | parent->test_properties()->force_render_surface = true; |
| 1684 | child->SetBounds(gfx::Size(10, 10)); |
| 1685 | child->SetDrawsContent(true); |
| 1686 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1687 | grand_child->SetDrawsContent(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1688 | grand_child->test_properties()->should_flatten_transform = false; |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1689 | ExecuteCalculateDrawProperties(root); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1690 | |
| 1691 | EXPECT_TRUE(parent->render_surface()); |
| 1692 | EXPECT_FALSE(child->render_surface()); |
| 1693 | EXPECT_FALSE(grand_child->render_surface()); |
| 1694 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1695 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform()); |
| 1696 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1697 | grand_child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1698 | |
| 1699 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1700 | // have been flattened at their render target. In particular, the fact that |
| 1701 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1702 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1703 | flattened_rotation_about_y.FlattenTo2d(); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1704 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1705 | child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1706 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1707 | grand_child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1708 | } |
| 1709 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1710 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1711 | // The entire subtree of layers that are outside the clip rect should be |
| 1712 | // culled away, and should not affect the render_surface_layer_list. |
| 1713 | // |
| 1714 | // The test tree is set up as follows: |
| 1715 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1716 | // that have something to draw. |
| 1717 | // - parent is a large container layer. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1718 | // - child has MasksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1719 | // - grand_child is positioned outside of the child's bounds |
| 1720 | // - great_grand_child is also kept outside child's bounds. |
| 1721 | // |
| 1722 | // In this configuration, grand_child and great_grand_child are completely |
| 1723 | // outside the clip rect, and they should never get scheduled on the list of |
| 1724 | // render surfaces. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1725 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1726 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1727 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1728 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1729 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1730 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1731 | // leaf_node1 ensures that root and child are kept on the |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1732 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1733 | // should be clipped. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1734 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(child); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1735 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1736 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1737 | root->SetBounds(gfx::Size(500, 500)); |
| 1738 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1739 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1740 | child->test_properties()->force_render_surface = true; |
| 1741 | grand_child->SetPosition(gfx::PointF(45.f, 45.f)); |
| 1742 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1743 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
| 1744 | leaf_node1->SetBounds(gfx::Size(500, 500)); |
| 1745 | leaf_node1->SetDrawsContent(true); |
| 1746 | leaf_node1->SetBounds(gfx::Size(20, 20)); |
| 1747 | leaf_node2->SetDrawsContent(true); |
| 1748 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1749 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1750 | ASSERT_EQ(2U, render_surface_layer_list_impl()->size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1751 | EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id()); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1752 | EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1753 | } |
| 1754 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1755 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1756 | // 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] | 1757 | // of the surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1758 | |
| 1759 | // The test tree is set up as follows: |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1760 | // - root is a container layer that masksToBounds=true to cause clipping. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1761 | // - 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] | 1762 | // the root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1763 | // - grand_child is a render surface, and the only visible content in child. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1764 | // It is positioned outside of the clip rect from root. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1765 | |
| 1766 | // In this configuration, grand_child should be outside the clipped |
| 1767 | // content rect of the child, making grand_child not appear in the |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1768 | // render_surface_layer_list. |
| 1769 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1770 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1771 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1772 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1773 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1774 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1775 | root->SetMasksToBounds(true); |
| 1776 | root->SetBounds(gfx::Size(100, 100)); |
| 1777 | child->SetBounds(gfx::Size(20, 20)); |
| 1778 | child->test_properties()->force_render_surface = true; |
| 1779 | grand_child->SetPosition(gfx::PointF(200.f, 200.f)); |
| 1780 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 1781 | grand_child->test_properties()->force_render_surface = true; |
| 1782 | leaf_node->SetBounds(gfx::Size(10, 10)); |
| 1783 | leaf_node->SetDrawsContent(true); |
| 1784 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1785 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1786 | // We should cull child and grand_child from the |
| 1787 | // render_surface_layer_list. |
| 1788 | ASSERT_EQ(1U, render_surface_layer_list_impl()->size()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1789 | EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1790 | } |
| 1791 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1792 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) { |
| 1793 | // Tests that LayerImpl's IsClipped() property is set to true when: |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1794 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1795 | // - the layer is clipped by an ancestor that contributes to the same |
| 1796 | // render target, |
| 1797 | // - a surface is clipped by an ancestor that contributes to the same |
| 1798 | // render target. |
| 1799 | // |
| 1800 | // In particular, for a layer that owns a render surface: |
| 1801 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1802 | // pass that clipped status to the layer itself. |
| 1803 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1804 | // and propagates the clip to the subtree. |
| 1805 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1806 | LayerImpl* root = root_layer_for_testing(); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1807 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1808 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1809 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1810 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1811 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1812 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1813 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1814 | root->SetBounds(gfx::Size(100, 100)); |
| 1815 | parent->SetBounds(gfx::Size(100, 100)); |
| 1816 | parent->SetDrawsContent(true); |
| 1817 | child1->SetBounds(gfx::Size(100, 100)); |
| 1818 | child1->SetDrawsContent(true); |
| 1819 | child2->SetBounds(gfx::Size(100, 100)); |
| 1820 | child2->SetDrawsContent(true); |
| 1821 | child2->test_properties()->force_render_surface = true; |
| 1822 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 1823 | grand_child->SetDrawsContent(true); |
| 1824 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
| 1825 | leaf_node1->SetDrawsContent(true); |
| 1826 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
| 1827 | leaf_node2->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1828 | |
| 1829 | // Case 1: nothing is clipped except the root render surface. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1830 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1831 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1832 | ASSERT_TRUE(root->render_surface()); |
| 1833 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1834 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1835 | EXPECT_FALSE(root->is_clipped()); |
| 1836 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1837 | EXPECT_FALSE(parent->is_clipped()); |
| 1838 | EXPECT_FALSE(child1->is_clipped()); |
| 1839 | EXPECT_FALSE(child2->is_clipped()); |
| 1840 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1841 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1842 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1843 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1844 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1845 | // Case 2: parent MasksToBounds, so the parent, child1, and child2's |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1846 | // surface are clipped. But layers that contribute to child2's surface are |
| 1847 | // not clipped explicitly because child2's surface already accounts for |
| 1848 | // that clip. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1849 | parent->SetMasksToBounds(true); |
| 1850 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1851 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1852 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1853 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1854 | ASSERT_TRUE(root->render_surface()); |
| 1855 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1856 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1857 | EXPECT_FALSE(root->is_clipped()); |
| 1858 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1859 | EXPECT_TRUE(parent->is_clipped()); |
| 1860 | EXPECT_TRUE(child1->is_clipped()); |
| 1861 | EXPECT_FALSE(child2->is_clipped()); |
| 1862 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1863 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1864 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1865 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1866 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1867 | parent->SetMasksToBounds(false); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1868 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1869 | // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1870 | // child2's render surface is not clipped. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1871 | child2->SetMasksToBounds(true); |
| 1872 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1873 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1874 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1875 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1876 | ASSERT_TRUE(root->render_surface()); |
| 1877 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1878 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1879 | EXPECT_FALSE(root->is_clipped()); |
| 1880 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1881 | EXPECT_FALSE(parent->is_clipped()); |
| 1882 | EXPECT_FALSE(child1->is_clipped()); |
| 1883 | EXPECT_TRUE(child2->is_clipped()); |
| 1884 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1885 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1886 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1887 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1888 | } |
| 1889 | |
| 1890 | TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) { |
| 1891 | // Tests that when as long as layer is clipped, it's clip rect is set to |
| 1892 | // correct value. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1893 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1894 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1895 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1896 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1897 | root->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1898 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1899 | parent->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1900 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1901 | child->SetBounds(gfx::Size(100, 100)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1902 | child->SetDrawsContent(true); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1903 | child->SetMasksToBounds(true); |
| 1904 | |
| 1905 | ExecuteCalculateDrawProperties(root); |
| 1906 | |
| 1907 | EXPECT_FALSE(root->is_clipped()); |
| 1908 | EXPECT_FALSE(parent->is_clipped()); |
| 1909 | EXPECT_TRUE(child->is_clipped()); |
| 1910 | EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect()); |
| 1911 | |
| 1912 | parent->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1913 | child->SetPosition(gfx::PointF(100.f, 100.f)); |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1914 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1915 | |
| 1916 | ExecuteCalculateDrawProperties(root); |
| 1917 | |
| 1918 | EXPECT_FALSE(root->is_clipped()); |
| 1919 | EXPECT_TRUE(parent->is_clipped()); |
| 1920 | EXPECT_TRUE(child->is_clipped()); |
| 1921 | EXPECT_EQ(gfx::Rect(), child->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1922 | } |
| 1923 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1924 | TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { |
| 1925 | // Tests that when separate surfaces are disabled, is_clipped is true exactly |
| 1926 | // when a layer or its ancestor has a clip; in particular, if a layer |
| 1927 | // is_clipped, so is its entire subtree (since there are no render surfaces |
| 1928 | // that can reset is_clipped). |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1929 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1930 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1931 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1932 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1933 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1934 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1935 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1936 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1937 | root->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1938 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1939 | parent->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1940 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1941 | child1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1942 | child1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1943 | child1->test_properties()->force_render_surface = true; |
| 1944 | child2->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1945 | child2->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1946 | grand_child->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1947 | grand_child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1948 | grand_child->test_properties()->force_render_surface = true; |
| 1949 | leaf_node1->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1950 | leaf_node1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 1951 | leaf_node2->SetBounds(gfx::Size(100, 100)); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1952 | leaf_node2->SetDrawsContent(true); |
| 1953 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1954 | // Case 1: Nothing is clipped. In this case, is_clipped is always false, with |
| 1955 | // or without surfaces. |
| 1956 | ExecuteCalculateDrawProperties(root); |
| 1957 | EXPECT_FALSE(root->is_clipped()); |
| 1958 | EXPECT_FALSE(parent->is_clipped()); |
| 1959 | EXPECT_FALSE(child1->is_clipped()); |
| 1960 | EXPECT_FALSE(child2->is_clipped()); |
| 1961 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1962 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1963 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1964 | |
| 1965 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1966 | EXPECT_FALSE(root->is_clipped()); |
| 1967 | EXPECT_FALSE(parent->is_clipped()); |
| 1968 | EXPECT_FALSE(child1->is_clipped()); |
| 1969 | EXPECT_FALSE(child2->is_clipped()); |
| 1970 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1971 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1972 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1973 | |
| 1974 | // Case 2: The root is clipped. With surfaces, this only persists until the |
| 1975 | // next render surface. Without surfaces, the entire tree is clipped. |
| 1976 | root->SetMasksToBounds(true); |
| 1977 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1978 | ExecuteCalculateDrawProperties(root); |
| 1979 | EXPECT_TRUE(root->is_clipped()); |
| 1980 | EXPECT_TRUE(parent->is_clipped()); |
| 1981 | EXPECT_FALSE(child1->is_clipped()); |
| 1982 | EXPECT_TRUE(child2->is_clipped()); |
| 1983 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1984 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1985 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1986 | |
| 1987 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1988 | EXPECT_TRUE(root->is_clipped()); |
| 1989 | EXPECT_TRUE(parent->is_clipped()); |
| 1990 | EXPECT_TRUE(child1->is_clipped()); |
| 1991 | EXPECT_TRUE(child2->is_clipped()); |
| 1992 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1993 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1994 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1995 | |
| 1996 | root->SetMasksToBounds(false); |
| 1997 | |
| 1998 | // Case 3: The parent is clipped. Again, with surfaces, this only persists |
| 1999 | // until the next render surface. Without surfaces, parent's entire subtree is |
| 2000 | // clipped. |
| 2001 | parent->SetMasksToBounds(true); |
| 2002 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2003 | ExecuteCalculateDrawProperties(root); |
| 2004 | EXPECT_FALSE(root->is_clipped()); |
| 2005 | EXPECT_TRUE(parent->is_clipped()); |
| 2006 | EXPECT_FALSE(child1->is_clipped()); |
| 2007 | EXPECT_TRUE(child2->is_clipped()); |
| 2008 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2009 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2010 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2011 | |
| 2012 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2013 | EXPECT_FALSE(root->is_clipped()); |
| 2014 | EXPECT_TRUE(parent->is_clipped()); |
| 2015 | EXPECT_TRUE(child1->is_clipped()); |
| 2016 | EXPECT_TRUE(child2->is_clipped()); |
| 2017 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2018 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2019 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2020 | |
| 2021 | parent->SetMasksToBounds(false); |
| 2022 | |
| 2023 | // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it |
| 2024 | // has no non-surface children. Without surfaces, child1's entire subtree is |
| 2025 | // clipped. |
| 2026 | child1->SetMasksToBounds(true); |
| 2027 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2028 | ExecuteCalculateDrawProperties(root); |
| 2029 | EXPECT_FALSE(root->is_clipped()); |
| 2030 | EXPECT_FALSE(parent->is_clipped()); |
| 2031 | EXPECT_TRUE(child1->is_clipped()); |
| 2032 | EXPECT_FALSE(child2->is_clipped()); |
| 2033 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2034 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2035 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2036 | |
| 2037 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2038 | EXPECT_FALSE(root->is_clipped()); |
| 2039 | EXPECT_FALSE(parent->is_clipped()); |
| 2040 | EXPECT_TRUE(child1->is_clipped()); |
| 2041 | EXPECT_FALSE(child2->is_clipped()); |
| 2042 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2043 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2044 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2045 | |
| 2046 | child1->SetMasksToBounds(false); |
| 2047 | |
| 2048 | // Case 5: Only the leaf nodes are clipped. The behavior with and without |
| 2049 | // surfaces is the same. |
| 2050 | leaf_node1->SetMasksToBounds(true); |
| 2051 | leaf_node2->SetMasksToBounds(true); |
| 2052 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 2053 | ExecuteCalculateDrawProperties(root); |
| 2054 | EXPECT_FALSE(root->is_clipped()); |
| 2055 | EXPECT_FALSE(parent->is_clipped()); |
| 2056 | EXPECT_FALSE(child1->is_clipped()); |
| 2057 | EXPECT_FALSE(child2->is_clipped()); |
| 2058 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2059 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2060 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2061 | |
| 2062 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2063 | EXPECT_FALSE(root->is_clipped()); |
| 2064 | EXPECT_FALSE(parent->is_clipped()); |
| 2065 | EXPECT_FALSE(child1->is_clipped()); |
| 2066 | EXPECT_FALSE(child2->is_clipped()); |
| 2067 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2068 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2069 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2070 | } |
| 2071 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 2072 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2073 | // Verify that layers get the appropriate DrawableContentRect when their |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2074 | // parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2075 | // |
| 2076 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 2077 | // be the layer rect expressed in target space. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2078 | // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2079 | // will be the intersection of layer bounds and the mask region. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2080 | // grand_child3 - partially clipped and MasksToBounds; the |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2081 | // DrawableContentRect will still be the intersection of layer bounds and |
| 2082 | // the mask region. |
| 2083 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 2084 | // be empty. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2085 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2086 | LayerImpl* parent = root_layer_for_testing(); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2087 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2088 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2089 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2090 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2091 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2092 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2093 | parent->SetBounds(gfx::Size(500, 500)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2094 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2095 | child->SetBounds(gfx::Size(20, 20)); |
| 2096 | child->test_properties()->force_render_surface = true; |
| 2097 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2098 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 2099 | grand_child1->SetDrawsContent(true); |
| 2100 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2101 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 2102 | grand_child2->SetDrawsContent(true); |
| 2103 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2104 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2105 | grand_child3->SetBounds(gfx::Size(10, 10)); |
| 2106 | grand_child3->SetDrawsContent(true); |
| 2107 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 2108 | grand_child4->SetBounds(gfx::Size(10, 10)); |
| 2109 | grand_child4->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2110 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2111 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2112 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2113 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2114 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2115 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2116 | } |
| 2117 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2118 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2119 | // Verify that render surfaces (and their layers) get the appropriate |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2120 | // clip rects when their parent MasksToBounds is true. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2121 | // |
| 2122 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2123 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2124 | // They may still have a clip rect of their own layer bounds, however, if |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2125 | // MasksToBounds was true. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2126 | LayerImpl* parent = root_layer_for_testing(); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2127 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2128 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2129 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2130 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2131 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2132 | // The leaf nodes ensure that these grand_children become render surfaces for |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2133 | // this test. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2134 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2135 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2136 | LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2137 | LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2138 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2139 | parent->SetBounds(gfx::Size(500, 500)); |
| 2140 | child->SetBounds(gfx::Size(20, 20)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2141 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2142 | child->test_properties()->force_render_surface = true; |
| 2143 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 2144 | grand_child1->SetBounds(gfx::Size(10, 10)); |
| 2145 | grand_child1->test_properties()->force_render_surface = true; |
| 2146 | grand_child2->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2147 | grand_child2->SetBounds(gfx::Size(10, 10)); |
| 2148 | grand_child2->test_properties()->force_render_surface = true; |
| 2149 | grand_child3->SetPosition(gfx::PointF(15.f, 15.f)); |
| 2150 | grand_child3->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2151 | grand_child3->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2152 | grand_child3->test_properties()->force_render_surface = true; |
| 2153 | grand_child4->SetPosition(gfx::PointF(45.f, 45.f)); |
| 2154 | grand_child4->SetBounds(gfx::Size(10, 10)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2155 | grand_child4->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2156 | grand_child4->test_properties()->force_render_surface = true; |
| 2157 | leaf_node1->SetBounds(gfx::Size(10, 10)); |
| 2158 | leaf_node1->SetDrawsContent(true); |
| 2159 | leaf_node2->SetBounds(gfx::Size(10, 10)); |
| 2160 | leaf_node2->SetDrawsContent(true); |
| 2161 | leaf_node3->SetBounds(gfx::Size(10, 10)); |
| 2162 | leaf_node3->SetDrawsContent(true); |
| 2163 | leaf_node4->SetBounds(gfx::Size(10, 10)); |
| 2164 | leaf_node4->SetDrawsContent(true); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2165 | ExecuteCalculateDrawProperties(parent); |
| 2166 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2167 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2168 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2169 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2170 | |
| 2171 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2172 | // MasksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2173 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2174 | grand_child1->render_surface()->clip_rect()); |
| 2175 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2176 | grand_child2->render_surface()->clip_rect()); |
| 2177 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2178 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2179 | } |
| 2180 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2181 | TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { |
| 2182 | // Tests that when separate surfaces are disabled, a layer's clip_rect is the |
| 2183 | // intersection of all ancestor clips in screen space; in particular, if a |
| 2184 | // layer masks to bounds, it contributes to the clip_rect of all layers in its |
| 2185 | // subtree (since there are no render surfaces that can reset the clip_rect). |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2186 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2187 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2188 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 2189 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 2190 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 2191 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 2192 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 2193 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2194 | root->SetBounds(gfx::Size(100, 100)); |
| 2195 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2196 | parent->SetBounds(gfx::Size(400, 400)); |
| 2197 | child1->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2198 | child1->SetBounds(gfx::Size(800, 800)); |
| 2199 | child2->SetPosition(gfx::PointF(3.f, 3.f)); |
| 2200 | child2->SetBounds(gfx::Size(800, 800)); |
| 2201 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2202 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2203 | leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2204 | leaf_node1->SetBounds(gfx::Size(2000, 2000)); |
| 2205 | leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); |
| 2206 | leaf_node2->SetBounds(gfx::Size(2000, 2000)); |
| 2207 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2208 | root->SetDrawsContent(true); |
| 2209 | parent->SetDrawsContent(true); |
| 2210 | child1->SetDrawsContent(true); |
| 2211 | child2->SetDrawsContent(true); |
| 2212 | grand_child->SetDrawsContent(true); |
| 2213 | leaf_node1->SetDrawsContent(true); |
| 2214 | leaf_node2->SetDrawsContent(true); |
| 2215 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2216 | root->test_properties()->force_render_surface = true; |
| 2217 | child1->test_properties()->force_render_surface = true; |
| 2218 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2219 | |
| 2220 | // Case 1: Nothing is clipped. In this case, each layer's clip rect is its |
| 2221 | // bounds in target space. The only thing that changes when surfaces are |
| 2222 | // disabled is that target space is always screen space. |
| 2223 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2224 | EXPECT_TRUE(root->has_render_surface()); |
| 2225 | EXPECT_FALSE(parent->has_render_surface()); |
| 2226 | EXPECT_TRUE(child1->has_render_surface()); |
| 2227 | EXPECT_FALSE(child2->has_render_surface()); |
| 2228 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2229 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2230 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2231 | EXPECT_FALSE(root->is_clipped()); |
| 2232 | EXPECT_FALSE(parent->is_clipped()); |
| 2233 | EXPECT_FALSE(child1->is_clipped()); |
| 2234 | EXPECT_FALSE(child2->is_clipped()); |
| 2235 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2236 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2237 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2238 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2239 | EXPECT_FALSE(child1->render_surface()->is_clipped()); |
| 2240 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2241 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2242 | |
| 2243 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2244 | EXPECT_FALSE(root->is_clipped()); |
| 2245 | EXPECT_FALSE(parent->is_clipped()); |
| 2246 | EXPECT_FALSE(child1->is_clipped()); |
| 2247 | EXPECT_FALSE(child2->is_clipped()); |
| 2248 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2249 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2250 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2251 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2252 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2253 | |
| 2254 | // Case 2: The root is clipped. In this case, layers that draw into the root |
| 2255 | // render surface are clipped by the root's bounds. |
| 2256 | root->SetMasksToBounds(true); |
| 2257 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2258 | root->test_properties()->force_render_surface = true; |
| 2259 | child1->test_properties()->force_render_surface = true; |
| 2260 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2261 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2262 | EXPECT_TRUE(root->has_render_surface()); |
| 2263 | EXPECT_FALSE(parent->has_render_surface()); |
| 2264 | EXPECT_TRUE(child1->has_render_surface()); |
| 2265 | EXPECT_FALSE(child2->has_render_surface()); |
| 2266 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2267 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2268 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2269 | EXPECT_TRUE(root->is_clipped()); |
| 2270 | EXPECT_TRUE(parent->is_clipped()); |
| 2271 | EXPECT_FALSE(child1->is_clipped()); |
| 2272 | EXPECT_TRUE(child1->render_surface()->is_clipped()); |
| 2273 | EXPECT_TRUE(child2->is_clipped()); |
| 2274 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2275 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2276 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2277 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2278 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2279 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2280 | EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2281 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2282 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2283 | |
| 2284 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2285 | EXPECT_TRUE(root->is_clipped()); |
| 2286 | EXPECT_TRUE(parent->is_clipped()); |
| 2287 | EXPECT_TRUE(child1->is_clipped()); |
| 2288 | EXPECT_TRUE(child2->is_clipped()); |
| 2289 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2290 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2291 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2292 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2293 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
| 2294 | EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect()); |
| 2295 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
| 2296 | EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect()); |
| 2297 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect()); |
| 2298 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2299 | |
| 2300 | root->SetMasksToBounds(false); |
| 2301 | |
| 2302 | // Case 3: The parent and child1 are clipped. When surfaces are enabled, the |
| 2303 | // parent clip rect only contributes to the subtree rooted at child2, since |
| 2304 | // the subtree rooted at child1 renders into a separate surface. Similarly, |
| 2305 | // child1's clip rect doesn't contribute to its descendants, since its only |
| 2306 | // child is a render surface. However, without surfaces, these clip rects |
| 2307 | // contribute to all descendants. |
| 2308 | parent->SetMasksToBounds(true); |
| 2309 | child1->SetMasksToBounds(true); |
| 2310 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2311 | root->test_properties()->force_render_surface = true; |
| 2312 | child1->test_properties()->force_render_surface = true; |
| 2313 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2314 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2315 | EXPECT_TRUE(root->has_render_surface()); |
| 2316 | EXPECT_FALSE(parent->has_render_surface()); |
| 2317 | EXPECT_TRUE(child1->has_render_surface()); |
| 2318 | EXPECT_FALSE(child2->has_render_surface()); |
| 2319 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2320 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2321 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2322 | EXPECT_FALSE(root->is_clipped()); |
| 2323 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2324 | EXPECT_TRUE(parent->is_clipped()); |
| 2325 | EXPECT_TRUE(child1->is_clipped()); |
| 2326 | EXPECT_TRUE(child2->is_clipped()); |
| 2327 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2328 | EXPECT_TRUE(grand_child->render_surface()->is_clipped()); |
| 2329 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2330 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2331 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2332 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2333 | EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); |
| 2334 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2335 | EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2336 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2337 | |
| 2338 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2339 | EXPECT_FALSE(root->is_clipped()); |
| 2340 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2341 | EXPECT_TRUE(parent->is_clipped()); |
| 2342 | EXPECT_TRUE(child1->is_clipped()); |
| 2343 | EXPECT_TRUE(child2->is_clipped()); |
| 2344 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2345 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2346 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2347 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2348 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2349 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect()); |
| 2350 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
| 2351 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect()); |
| 2352 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect()); |
| 2353 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2354 | } |
| 2355 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2356 | TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2357 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2358 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2359 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2360 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2361 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2362 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2363 | root->SetBounds(gfx::Size(100, 100)); |
| 2364 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2365 | parent->SetBounds(gfx::Size(400, 400)); |
| 2366 | parent->SetMasksToBounds(true); |
| 2367 | child->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2368 | child->SetBounds(gfx::Size(800, 800)); |
| 2369 | child->SetMasksToBounds(true); |
| 2370 | child->test_properties()->force_render_surface = true; |
| 2371 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2372 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2373 | grand_child->test_properties()->force_render_surface = true; |
| 2374 | leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2375 | leaf_node->SetBounds(gfx::Size(2000, 2000)); |
| 2376 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2377 | root->SetDrawsContent(true); |
| 2378 | parent->SetDrawsContent(true); |
| 2379 | child->SetDrawsContent(true); |
| 2380 | grand_child->SetDrawsContent(true); |
| 2381 | leaf_node->SetDrawsContent(true); |
| 2382 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2383 | host_impl()->set_resourceless_software_draw_for_testing(); |
| 2384 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2385 | gfx::PointF test_point(90.f, 90.f); |
| 2386 | LayerImpl* result_layer = |
| 2387 | root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point); |
| 2388 | ASSERT_TRUE(result_layer); |
| 2389 | EXPECT_EQ(leaf_node, result_layer); |
| 2390 | } |
| 2391 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2392 | TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { |
| 2393 | // Tests that draw properties are computed correctly when we disable and then |
| 2394 | // re-enable separate surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2395 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2396 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2397 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2398 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2399 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2400 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2401 | root->SetBounds(gfx::Size(100, 100)); |
| 2402 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 2403 | parent->SetBounds(gfx::Size(400, 400)); |
| 2404 | parent->SetMasksToBounds(true); |
| 2405 | child->SetPosition(gfx::PointF(4.f, 4.f)); |
| 2406 | child->SetBounds(gfx::Size(800, 800)); |
| 2407 | child->SetMasksToBounds(true); |
| 2408 | child->test_properties()->force_render_surface = true; |
| 2409 | grand_child->SetPosition(gfx::PointF(8.f, 8.f)); |
| 2410 | grand_child->SetBounds(gfx::Size(1500, 1500)); |
| 2411 | grand_child->test_properties()->force_render_surface = true; |
| 2412 | leaf_node->SetPosition(gfx::PointF(16.f, 16.f)); |
| 2413 | leaf_node->SetBounds(gfx::Size(2000, 2000)); |
| 2414 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2415 | root->SetDrawsContent(true); |
| 2416 | parent->SetDrawsContent(true); |
| 2417 | child->SetDrawsContent(true); |
| 2418 | grand_child->SetDrawsContent(true); |
| 2419 | leaf_node->SetDrawsContent(true); |
| 2420 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2421 | gfx::Transform expected_leaf_draw_transform_with_surfaces; |
| 2422 | expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); |
| 2423 | |
| 2424 | gfx::Transform expected_leaf_draw_transform_without_surfaces; |
| 2425 | expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); |
| 2426 | |
| 2427 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2428 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2429 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2430 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2431 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, |
| 2432 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2433 | |
| 2434 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2435 | EXPECT_TRUE(leaf_node->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2436 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); |
| 2437 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2438 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces, |
| 2439 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2440 | |
| 2441 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2442 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2443 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2444 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 2445 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces, |
| 2446 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2447 | } |
| 2448 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2449 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2450 | LayerImpl* root = root_layer_for_testing(); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2451 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 2452 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
| 2453 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 2454 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 2455 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
| 2456 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 2457 | LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
| 2458 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2459 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2460 | root->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2461 | render_surface1->SetDrawsContent(true); |
| 2462 | child_of_rs1->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2463 | grand_child_of_rs1->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2464 | render_surface2->SetDrawsContent(true); |
| 2465 | child_of_rs2->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2466 | grand_child_of_rs2->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2467 | child_of_root->SetDrawsContent(true); |
| 2468 | grand_child_of_root->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2469 | |
| 2470 | gfx::Transform layer_transform; |
| 2471 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2472 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2473 | root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2474 | root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2475 | root->SetBounds(gfx::Size(10, 10)); |
| 2476 | root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2477 | render_surface1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2478 | render_surface1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2479 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 2480 | render_surface1->test_properties()->transform_origin = |
| 2481 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2482 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2483 | render_surface2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2484 | render_surface2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2485 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 2486 | render_surface2->test_properties()->transform_origin = |
| 2487 | gfx::Point3F(0.25f, 0.f, 0.f); |
| 2488 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2489 | child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2490 | child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2491 | child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2492 | child_of_root->test_properties()->transform_origin = |
| 2493 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2494 | child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2495 | child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2496 | child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2497 | child_of_rs1->test_properties()->transform_origin = |
| 2498 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2499 | child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2500 | child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2501 | child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2502 | child_of_rs2->test_properties()->transform_origin = |
| 2503 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2504 | grand_child_of_root->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2505 | grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2506 | grand_child_of_root->SetBounds(gfx::Size(10, 10)); |
| 2507 | grand_child_of_root->test_properties()->transform_origin = |
| 2508 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2509 | grand_child_of_rs1->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2510 | grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2511 | grand_child_of_rs1->SetBounds(gfx::Size(10, 10)); |
| 2512 | grand_child_of_rs1->test_properties()->transform_origin = |
| 2513 | gfx::Point3F(0.25f, 0.f, 0.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2514 | grand_child_of_rs2->test_properties()->transform = layer_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2515 | grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f)); |
| 2516 | grand_child_of_rs2->SetBounds(gfx::Size(10, 10)); |
| 2517 | grand_child_of_rs2->test_properties()->transform_origin = |
| 2518 | gfx::Point3F(0.25f, 0.f, 0.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2519 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2520 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2521 | SetElementIdsForTesting(); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 2522 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2523 | // Put an animated opacity on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2524 | AddOpacityTransitionToElementWithPlayer( |
| 2525 | render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2526 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2527 | // Also put an animated opacity on a layer without descendants. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2528 | AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(), |
| 2529 | timeline_impl(), 10.0, 1.f, 0.f, |
| 2530 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2531 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2532 | // Put a transform animation on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2533 | AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(), |
| 2534 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2535 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2536 | // Also put transform animations on grand_child_of_root, and |
| 2537 | // grand_child_of_rs2 |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2538 | AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(), |
| 2539 | timeline_impl(), 10.0, 30, 0); |
| 2540 | AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(), |
| 2541 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2542 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2543 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 2544 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2545 | |
| 2546 | // Only layers that are associated with render surfaces should have an actual |
| 2547 | // RenderSurface() value. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2548 | ASSERT_TRUE(root->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2549 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2550 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2551 | |
| 2552 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2553 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2554 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2555 | |
| 2556 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2557 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2558 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2559 | |
| 2560 | // Verify all render target accessors |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2561 | EXPECT_EQ(root->render_surface(), root->render_target()); |
| 2562 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 2563 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2564 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2565 | EXPECT_EQ(render_surface1->render_surface(), |
| 2566 | render_surface1->render_target()); |
| 2567 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 2568 | EXPECT_EQ(render_surface1->render_surface(), |
| 2569 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2570 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2571 | EXPECT_EQ(render_surface2->render_surface(), |
| 2572 | render_surface2->render_target()); |
| 2573 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 2574 | EXPECT_EQ(render_surface2->render_surface(), |
| 2575 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2576 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2577 | // Verify screen_space_transform_is_animating values |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2578 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2579 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2580 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2581 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2582 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2583 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2584 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2585 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2586 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2587 | |
| 2588 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2589 | // It is expected that we correctly set up transforms so that the y-component |
| 2590 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2591 | EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2592 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2593 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2594 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2595 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2596 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2597 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2598 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2599 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2600 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2601 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2602 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2603 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2604 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2605 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2606 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2607 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2608 | } |
| 2609 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2610 | TEST_F(LayerTreeHostCommonTest, LargeTransforms) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2611 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2612 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2613 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2614 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2615 | gfx::Transform large_transform; |
| 2616 | large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); |
| 2617 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2618 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2619 | child->test_properties()->transform = large_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2620 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 2621 | grand_child->test_properties()->transform = large_transform; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2622 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2623 | grand_child->SetDrawsContent(true); |
| 2624 | ExecuteCalculateDrawProperties(root); |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2625 | |
| 2626 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
| 2627 | } |
| 2628 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2629 | TEST_F(LayerTreeHostCommonTest, |
| 2630 | ScreenSpaceTransformIsAnimatingWithDelayedAnimation) { |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2631 | LayerImpl* root = root_layer_for_testing(); |
| 2632 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2633 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2634 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 2635 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2636 | root->SetDrawsContent(true); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2637 | child->SetDrawsContent(true); |
| 2638 | grand_child->SetDrawsContent(true); |
| 2639 | great_grand_child->SetDrawsContent(true); |
| 2640 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2641 | root->SetBounds(gfx::Size(10, 10)); |
| 2642 | child->SetBounds(gfx::Size(10, 10)); |
| 2643 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 2644 | great_grand_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2645 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2646 | SetElementIdsForTesting(); |
| 2647 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2648 | // Add a transform animation with a start delay to |grand_child|. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2649 | std::unique_ptr<Animation> animation = Animation::Create( |
| 2650 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1, |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 2651 | TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 2652 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2653 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 2654 | AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(), |
| 2655 | std::move(animation)); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2656 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2657 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2658 | EXPECT_FALSE(root->screen_space_transform_is_animating()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2659 | EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 2660 | |
| 2661 | EXPECT_FALSE(grand_child->TransformIsAnimating()); |
| 2662 | EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation()); |
| 2663 | EXPECT_TRUE(grand_child->screen_space_transform_is_animating()); |
| 2664 | EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating()); |
| 2665 | } |
| 2666 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2667 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) { |
| 2668 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2669 | // correctly for identity transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2670 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2671 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2672 | gfx::Transform layer_to_surface_transform; |
| 2673 | |
| 2674 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2675 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2676 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2677 | gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30); |
| 2678 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2679 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2680 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2681 | EXPECT_EQ(expected_drawable_content_rect, |
| 2682 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2683 | |
| 2684 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2685 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2686 | expected_visible_layer_rect = gfx::Rect(); |
| 2687 | expected_drawable_content_rect = gfx::Rect(); |
| 2688 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2689 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2690 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2691 | EXPECT_EQ(expected_drawable_content_rect, |
| 2692 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2693 | |
| 2694 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2695 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2696 | expected_visible_layer_rect = gfx::Rect(20, 20); |
| 2697 | expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20); |
| 2698 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2699 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2700 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2701 | EXPECT_EQ(expected_drawable_content_rect, |
| 2702 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2703 | } |
| 2704 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2705 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) { |
| 2706 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2707 | // for rotations about z-axis (i.e. 2D rotations). |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2708 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2709 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2710 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2711 | gfx::Transform layer_to_surface_transform; |
| 2712 | |
| 2713 | // Case 1: Layer is contained within the surface. |
| 2714 | layer_to_surface_transform.MakeIdentity(); |
| 2715 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2716 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2717 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2718 | gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43); |
| 2719 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2720 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2721 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2722 | EXPECT_EQ(expected_drawable_content_rect, |
| 2723 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2724 | |
| 2725 | // Case 2: Layer is outside the surface rect. |
| 2726 | layer_to_surface_transform.MakeIdentity(); |
| 2727 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2728 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2729 | expected_visible_layer_rect = gfx::Rect(); |
| 2730 | expected_drawable_content_rect = gfx::Rect(); |
| 2731 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2732 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2733 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2734 | EXPECT_EQ(expected_drawable_content_rect, |
| 2735 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2736 | |
| 2737 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2738 | // the layer is oriented diagonally, with the left half outside of the render |
| 2739 | // surface. In this case, the g should still be the entire layer |
| 2740 | // (remember the g is computed in layer space); both the top-left |
| 2741 | // and bottom-right corners of the layer are still visible. |
| 2742 | layer_to_surface_transform.MakeIdentity(); |
| 2743 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2744 | expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2745 | expected_drawable_content_rect = gfx::Rect(22, 43); |
| 2746 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2747 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2748 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2749 | EXPECT_EQ(expected_drawable_content_rect, |
| 2750 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2751 | |
| 2752 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2753 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2754 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2755 | // surface overlaps the right side of the layer. The g should be |
| 2756 | // the layer's right half. |
| 2757 | layer_to_surface_transform.MakeIdentity(); |
| 2758 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2759 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2760 | // Right half of layer bounds. |
| 2761 | expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30); |
| 2762 | expected_drawable_content_rect = gfx::Rect(22, 22); |
| 2763 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2764 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2765 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2766 | EXPECT_EQ(expected_drawable_content_rect, |
| 2767 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2768 | } |
| 2769 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2770 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) { |
| 2771 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2772 | // for 3d transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2773 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2774 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2775 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2776 | gfx::Transform layer_to_surface_transform; |
| 2777 | |
| 2778 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2779 | // degrees, should be fully contained in the render surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2780 | // 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] | 2781 | layer_to_surface_transform.MakeIdentity(); |
| 2782 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2783 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2784 | gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100); |
| 2785 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2786 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2787 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2788 | EXPECT_EQ(expected_drawable_content_rect, |
| 2789 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2790 | |
| 2791 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2792 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2793 | // visible on the surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2794 | // 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] | 2795 | SkMScalar half_width_of_rotated_layer = |
| 2796 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2797 | layer_to_surface_transform.MakeIdentity(); |
| 2798 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2799 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2800 | // edge of the layer. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2801 | // Tight half of the layer. |
| 2802 | expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100); |
| 2803 | expected_drawable_content_rect = gfx::Rect(36, 100); |
| 2804 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2805 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2806 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2807 | EXPECT_EQ(expected_drawable_content_rect, |
| 2808 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2809 | } |
| 2810 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2811 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) { |
| 2812 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2813 | // when the layer has a perspective projection onto the target surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2814 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2815 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2816 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2817 | gfx::Transform layer_to_surface_transform; |
| 2818 | |
| 2819 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2820 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2821 | // its translated more than the perspective amount. |
| 2822 | layer_to_surface_transform.MakeIdentity(); |
| 2823 | |
| 2824 | // The following sequence of transforms applies the perspective about the |
| 2825 | // center of the surface. |
| 2826 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2827 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2828 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2829 | |
| 2830 | // This translate places the layer in front of the surface's projection plane. |
| 2831 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2832 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2833 | // Layer position is (-50, -50), visible rect in layer space is layer bounds |
| 2834 | // offset by layer position. |
| 2835 | gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150); |
| 2836 | gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38); |
| 2837 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2838 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2839 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2840 | EXPECT_EQ(expected_drawable_content_rect, |
| 2841 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2842 | |
| 2843 | // Case 2: same projection as before, except that the layer is also translated |
| 2844 | // to the side, so that only the right half of the layer should be visible. |
| 2845 | // |
| 2846 | // Explanation of expected result: The perspective ratio is (z distance |
| 2847 | // between layer and camera origin) / (z distance between projection plane and |
| 2848 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2849 | // move a layer by translating -25 units in projected surface units (so that |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2850 | // 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] | 2851 | // -25 == -100 in the layer's units. |
| 2852 | layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0); |
| 2853 | // Visible layer rect is moved by 100, and drawable content rect is in target |
| 2854 | // space and is moved by 25. |
| 2855 | expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150); |
| 2856 | expected_drawable_content_rect = gfx::Rect(13, 38); |
| 2857 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2858 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2859 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2860 | EXPECT_EQ(expected_drawable_content_rect, |
| 2861 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2862 | } |
| 2863 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2864 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2865 | DrawRectsFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2866 | // There is currently no explicit concept of an orthographic projection plane |
| 2867 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2868 | // are technically behind the surface in an orthographic world should not be |
| 2869 | // clipped when they are flattened to the surface. |
| 2870 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2871 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2872 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2873 | gfx::Transform layer_to_surface_transform; |
| 2874 | |
| 2875 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2876 | // at the center of the layer. |
| 2877 | layer_to_surface_transform.MakeIdentity(); |
| 2878 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2879 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2880 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2881 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2882 | // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface |
| 2883 | // space. |
| 2884 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2885 | gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100); |
| 2886 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2887 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2888 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2889 | EXPECT_EQ(expected_drawable_content_rect, |
| 2890 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2891 | } |
| 2892 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2893 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2894 | DrawRectsFor3dPerspectiveWhenClippedByW) { |
| 2895 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2896 | // when projecting a surface onto a layer, but the layer is partially behind |
| 2897 | // the camera (not just behind the projection plane). In this case, the |
| 2898 | // cartesian coordinates may seem to be valid, but actually they are not. The |
| 2899 | // visible rect needs to be properly clipped by the w = 0 plane in homogeneous |
| 2900 | // coordinates before converting to cartesian coordinates. The drawable |
| 2901 | // content rect would be entire surface rect because layer is rotated at the |
| 2902 | // camera position. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2903 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2904 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200); |
| 2905 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2906 | gfx::Transform layer_to_surface_transform; |
| 2907 | |
| 2908 | // The layer is positioned so that the right half of the layer should be in |
| 2909 | // front of the camera, while the other half is behind the surface's |
| 2910 | // projection plane. The following sequence of transforms applies the |
| 2911 | // perspective and rotation about the center of the layer. |
| 2912 | layer_to_surface_transform.MakeIdentity(); |
| 2913 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2914 | layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0); |
| 2915 | layer_to_surface_transform.RotateAboutYAxis(-45.0); |
| 2916 | layer_to_surface_transform.Translate(-10, -1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2917 | |
| 2918 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2919 | // transform, otherwise this code is not testing the intended scenario. |
| 2920 | bool clipped; |
| 2921 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2922 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2923 | &clipped); |
| 2924 | ASSERT_TRUE(clipped); |
| 2925 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2926 | gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1); |
| 2927 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 2928 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2929 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2930 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2931 | EXPECT_EQ(expected_drawable_content_rect, |
| 2932 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2933 | } |
| 2934 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2935 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2936 | // To determine visible rect in layer space, there needs to be an |
| 2937 | // un-projection from surface space to layer space. When the original |
| 2938 | // transform was a perspective projection that was clipped, it returns a rect |
| 2939 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2940 | // clipping again. |
| 2941 | |
| 2942 | // This sequence of transforms causes one corner of the layer to protrude |
| 2943 | // across the w = 0 plane, and should be clipped. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2944 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150); |
| 2945 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2946 | gfx::Transform layer_to_surface_transform; |
| 2947 | layer_to_surface_transform.MakeIdentity(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2948 | layer_to_surface_transform.Translate(10, 10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2949 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2950 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2951 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2952 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2953 | layer_to_surface_transform.Translate(-10, -10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2954 | |
| 2955 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2956 | // code is not testing the intended scenario. |
| 2957 | bool clipped; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2958 | gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
| 2959 | layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2960 | MathUtil::ProjectQuad( |
| 2961 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2962 | ASSERT_TRUE(clipped); |
| 2963 | |
| 2964 | // Only the corner of the layer is not visible on the surface because of being |
| 2965 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2966 | // rect is that the entire layer should still be considered visible. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2967 | gfx::Rect expected_visible_layer_rect = layer_content_rect; |
| 2968 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 2969 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2970 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2971 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2972 | EXPECT_EQ(expected_drawable_content_rect, |
| 2973 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2974 | } |
| 2975 | |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2976 | TEST_F(LayerTreeHostCommonTest, |
| 2977 | VisibleRectsForPositionedRootLayerClippedByViewport) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2978 | LayerImpl* root = root_layer_for_testing(); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2979 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2980 | root->SetPosition(gfx::PointF(60, 70)); |
| 2981 | root->SetBounds(gfx::Size(100, 100)); |
| 2982 | root->SetDrawsContent(true); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 2983 | ExecuteCalculateDrawProperties(root); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2984 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2985 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2986 | root->render_surface()->DrawableContentRect()); |
| 2987 | // In target space, not clipped. |
| 2988 | EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 2989 | // In layer space, clipped. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2990 | EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2991 | } |
| 2992 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2993 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 2994 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2995 | LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2996 | LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2997 | LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 2998 | |
| 2999 | root->SetBounds(gfx::Size(100, 100)); |
| 3000 | child1_layer->SetBounds(gfx::Size(50, 50)); |
| 3001 | child1_layer->SetDrawsContent(true); |
| 3002 | child2_layer->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3003 | child2_layer->SetBounds(gfx::Size(50, 50)); |
| 3004 | child2_layer->SetDrawsContent(true); |
| 3005 | child3_layer->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3006 | child3_layer->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3007 | child3_layer->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3008 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3009 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3010 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3011 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3012 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3013 | // Layers that do not draw content should have empty visible_layer_rects. |
| 3014 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3015 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3016 | // layer visible_layer_rects are clipped by their target surface. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3017 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); |
| 3018 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); |
| 3019 | EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3020 | |
| 3021 | // layer drawable_content_rects are not clipped. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3022 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect()); |
| 3023 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect()); |
| 3024 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3025 | } |
| 3026 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3027 | TEST_F(LayerTreeHostCommonTest, |
| 3028 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3029 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3030 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3031 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3032 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3033 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3034 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3035 | root->SetBounds(gfx::Size(100, 100)); |
| 3036 | child->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3037 | child->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3038 | grand_child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3039 | grand_child1->SetBounds(gfx::Size(50, 50)); |
| 3040 | grand_child1->SetDrawsContent(true); |
| 3041 | grand_child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3042 | grand_child2->SetBounds(gfx::Size(50, 50)); |
| 3043 | grand_child2->SetDrawsContent(true); |
| 3044 | grand_child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3045 | grand_child3->SetBounds(gfx::Size(50, 50)); |
| 3046 | grand_child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3047 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3048 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3049 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3050 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3051 | |
| 3052 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3053 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3054 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3055 | |
| 3056 | // All grandchild visible content rects should be clipped by child. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3057 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); |
| 3058 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); |
| 3059 | EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3060 | |
| 3061 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3062 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 3063 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3064 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 3065 | } |
| 3066 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3067 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3068 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3069 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 3070 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3071 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3072 | gfx::Transform child_scale_matrix; |
| 3073 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 3074 | gfx::Transform grand_child_scale_matrix; |
| 3075 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3076 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3077 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3078 | child->test_properties()->transform = child_scale_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3079 | child->SetBounds(gfx::Size(10, 10)); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3080 | child->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3081 | grand_child->test_properties()->transform = grand_child_scale_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3082 | grand_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3083 | grand_child->SetDrawsContent(true); |
| 3084 | ExecuteCalculateDrawProperties(root); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3085 | |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 3086 | // The visible rect is expanded to integer coordinates. |
| 3087 | EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3088 | } |
| 3089 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3090 | TEST_F(LayerTreeHostCommonTest, |
| 3091 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3092 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3093 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3094 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3095 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3096 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3097 | |
| 3098 | root->SetBounds(gfx::Size(100, 100)); |
| 3099 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3100 | render_surface->test_properties()->force_render_surface = true; |
| 3101 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3102 | child1->SetBounds(gfx::Size(50, 50)); |
| 3103 | child1->SetDrawsContent(true); |
| 3104 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3105 | child2->SetBounds(gfx::Size(50, 50)); |
| 3106 | child2->SetDrawsContent(true); |
| 3107 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3108 | child3->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3109 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3110 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3111 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3112 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3113 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3114 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3115 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3116 | |
| 3117 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3118 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3119 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3120 | |
| 3121 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 3122 | // regions of the subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3123 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3124 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3125 | |
| 3126 | // All layers that draw content into the unclipped surface are also unclipped. |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3127 | // Only the viewport clip should apply |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3128 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3129 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3130 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3131 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3132 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3133 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3134 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3135 | } |
| 3136 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3137 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3138 | DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3139 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3140 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 3141 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 3142 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 3143 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); |
| 3144 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); |
| 3145 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 3146 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 3147 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3148 | root->SetBounds(gfx::Size(100, 100)); |
| 3149 | parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 3150 | parent->SetBounds(gfx::Size(400, 400)); |
| 3151 | child1->SetPosition(gfx::PointF(4.f, 4.f)); |
| 3152 | child1->SetBounds(gfx::Size(800, 800)); |
| 3153 | child1->test_properties()->force_render_surface = true; |
| 3154 | child2->SetPosition(gfx::PointF(3.f, 3.f)); |
| 3155 | child2->SetBounds(gfx::Size(800, 800)); |
| 3156 | child2->test_properties()->force_render_surface = true; |
| 3157 | grand_child1->SetPosition(gfx::PointF(8.f, 8.f)); |
| 3158 | grand_child1->SetBounds(gfx::Size(1500, 1500)); |
| 3159 | grand_child2->SetPosition(gfx::PointF(7.f, 7.f)); |
| 3160 | grand_child2->SetBounds(gfx::Size(1500, 1500)); |
| 3161 | leaf_node1->SetPosition(gfx::PointF(16.f, 16.f)); |
| 3162 | leaf_node1->SetBounds(gfx::Size(2000, 2000)); |
| 3163 | leaf_node2->SetPosition(gfx::PointF(9.f, 9.f)); |
| 3164 | leaf_node2->SetBounds(gfx::Size(2000, 2000)); |
| 3165 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3166 | root->SetDrawsContent(true); |
| 3167 | parent->SetDrawsContent(true); |
| 3168 | child1->SetDrawsContent(true); |
| 3169 | child2->SetDrawsContent(true); |
| 3170 | grand_child1->SetDrawsContent(true); |
| 3171 | grand_child2->SetDrawsContent(true); |
| 3172 | leaf_node1->SetDrawsContent(true); |
| 3173 | leaf_node2->SetDrawsContent(true); |
| 3174 | |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3175 | // Case 1: No layers clip. Visible rects are clipped by the viewport. |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3176 | // Each layer's drawable content rect is its bounds in target space; the only |
| 3177 | // thing that changes with surfaces disabled is that target space is always |
| 3178 | // screen space. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3179 | root->SetHasRenderSurface(true); |
| 3180 | child1->SetHasRenderSurface(true); |
| 3181 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3182 | ExecuteCalculateDrawProperties(root); |
| 3183 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3184 | EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3185 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3186 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3187 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3188 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3189 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3190 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3191 | |
| 3192 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3193 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3194 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3195 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3196 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3197 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3198 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3199 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3200 | |
| 3201 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3202 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3203 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3204 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3205 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3206 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3207 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3208 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3209 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3210 | |
| 3211 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3212 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3213 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3214 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3215 | EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), |
| 3216 | grand_child1->drawable_content_rect()); |
| 3217 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3218 | grand_child2->drawable_content_rect()); |
| 3219 | EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3220 | EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3221 | |
| 3222 | // Case 2: The parent clips. In this case, neither surface is unclipped, so |
| 3223 | // all visible layer rects are clipped by the intersection of all ancestor |
| 3224 | // clips, whether or not surfaces are disabled. However, drawable content |
| 3225 | // rects are clipped only until the next render surface is reached, so |
| 3226 | // descendants of parent have their drawable content rects clipped only when |
| 3227 | // surfaces are disabled. |
| 3228 | parent->SetMasksToBounds(true); |
| 3229 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3230 | ExecuteCalculateDrawProperties(root); |
| 3231 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3232 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3233 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3234 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3235 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3236 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3237 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3238 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3239 | |
| 3240 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3241 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3242 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3243 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3244 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3245 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3246 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3247 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3248 | |
| 3249 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3250 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3251 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3252 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3253 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3254 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3255 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3256 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3257 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3258 | |
| 3259 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3260 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3261 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect()); |
| 3262 | EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect()); |
| 3263 | EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect()); |
| 3264 | EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect()); |
| 3265 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect()); |
| 3266 | EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect()); |
| 3267 | |
| 3268 | parent->SetMasksToBounds(false); |
| 3269 | |
| 3270 | // Case 3: child1 and grand_child2 clip. In this case, descendants of these |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3271 | // layers have their visible rects clipped by them; Similarly, descendants of |
| 3272 | // these layers have their drawable content rects clipped by them. |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3273 | child1->SetMasksToBounds(true); |
| 3274 | grand_child2->SetMasksToBounds(true); |
| 3275 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 3276 | ExecuteCalculateDrawProperties(root); |
| 3277 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3278 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3279 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3280 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3281 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3282 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3283 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3284 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3285 | |
| 3286 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3287 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3288 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3289 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3290 | EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect()); |
| 3291 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3292 | EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect()); |
| 3293 | EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3294 | |
| 3295 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3296 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3297 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3298 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3299 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3300 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3301 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3302 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3303 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3304 | |
| 3305 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3306 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3307 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3308 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3309 | EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect()); |
| 3310 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3311 | grand_child2->drawable_content_rect()); |
| 3312 | EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); |
| 3313 | EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3314 | } |
| 3315 | |
| 3316 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3317 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3318 | LayerImpl* root = root_layer_for_testing(); |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3319 | LayerImpl* child1 = AddChild<LayerImpl>(root); |
| 3320 | LayerImpl* child2 = AddChild<LayerImpl>(root); |
| 3321 | LayerImpl* child3 = AddChild<LayerImpl>(root); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3322 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3323 | root->SetBounds(gfx::Size(100, 100)); |
| 3324 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3325 | child1->SetBounds(gfx::Size(50, 50)); |
| 3326 | child1->SetDrawsContent(true); |
| 3327 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3328 | child2->SetBounds(gfx::Size(50, 50)); |
| 3329 | child2->SetDrawsContent(true); |
| 3330 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3331 | child3->SetBounds(gfx::Size(50, 50)); |
| 3332 | child3->SetDrawsContent(true); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3333 | |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3334 | LayerImplList render_surface_layer_list_impl; |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3335 | // Now set the root render surface an empty clip. |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3336 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 3337 | root, gfx::Size(), &render_surface_layer_list_impl); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3338 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 3339 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3340 | ASSERT_TRUE(root->render_surface()); |
| 3341 | EXPECT_FALSE(root->is_clipped()); |
| 3342 | |
| 3343 | gfx::Rect empty; |
| 3344 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 3345 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 3346 | |
| 3347 | // Visible content rect calculation will check if the target surface is |
| 3348 | // clipped or not. An empty clip rect does not indicate the render surface |
| 3349 | // is unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3350 | EXPECT_EQ(empty, child1->visible_layer_rect()); |
| 3351 | EXPECT_EQ(empty, child2->visible_layer_rect()); |
| 3352 | EXPECT_EQ(empty, child3->visible_layer_rect()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3353 | } |
| 3354 | |
| 3355 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3356 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3357 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3358 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3359 | |
| 3360 | root->SetBounds(gfx::Size(100, 100)); |
| 3361 | child->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3362 | child->SetBounds(gfx::Size(50, 50)); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3363 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3364 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3365 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3366 | 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] | 3367 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3368 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3369 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3370 | ExecuteCalculateDrawProperties(root); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3371 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3372 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3373 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3374 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3375 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 3376 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3377 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3378 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3379 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3380 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3381 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3382 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3383 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3384 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3385 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3386 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3387 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3388 | uninvertible_matrix.MakeIdentity(); |
| 3389 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3390 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3391 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3392 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3393 | child->test_properties()->transform = uninvertible_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3394 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3395 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3396 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3397 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3398 | } |
| 3399 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3400 | TEST_F(LayerTreeHostCommonTest, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3401 | VisibleContentRectForLayerWithUninvertibleDrawTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3402 | LayerImpl* root = root_layer_for_testing(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3403 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3404 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3405 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3406 | gfx::Transform perspective; |
| 3407 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3408 | |
| 3409 | gfx::Transform rotation; |
| 3410 | rotation.RotateAboutYAxis(45.0); |
| 3411 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3412 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3413 | child->test_properties()->transform = perspective; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3414 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 3415 | child->SetBounds(gfx::Size(100, 100)); |
| 3416 | child->SetDrawsContent(true); |
| 3417 | child->Set3dSortingContextId(1); |
| 3418 | child->test_properties()->should_flatten_transform = false; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3419 | grand_child->test_properties()->transform = rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3420 | grand_child->SetBounds(gfx::Size(100, 100)); |
| 3421 | grand_child->SetDrawsContent(true); |
| 3422 | grand_child->Set3dSortingContextId(1); |
| 3423 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3424 | ExecuteCalculateDrawProperties(root); |
| 3425 | |
| 3426 | // Though all layers have invertible transforms, matrix multiplication using |
| 3427 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3428 | EXPECT_FALSE(root->layer_tree_impl() |
| 3429 | ->property_trees() |
| 3430 | ->transform_tree.Node(grand_child->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3431 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3432 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3433 | // CalcDrawProps skips a subtree when a layer's screen space transform is |
| 3434 | // uninvertible |
| 3435 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3436 | } |
| 3437 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3438 | TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) { |
| 3439 | FakeImplTaskRunnerProvider task_runner_provider; |
| 3440 | TestSharedBitmapManager shared_bitmap_manager; |
| 3441 | TestTaskGraphRunner task_graph_runner; |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3442 | std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 3443 | FakeCompositorFrameSink::Create3d(); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3444 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 3445 | &task_graph_runner); |
| 3446 | |
| 3447 | std::unique_ptr<LayerImpl> root = |
| 3448 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3449 | std::unique_ptr<LayerImpl> child = |
| 3450 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3451 | std::unique_ptr<TextureLayerImpl> surface = |
| 3452 | TextureLayerImpl::Create(host_impl.active_tree(), 3); |
| 3453 | std::unique_ptr<TextureLayerImpl> surface_child = |
| 3454 | TextureLayerImpl::Create(host_impl.active_tree(), 4); |
| 3455 | std::unique_ptr<TextureLayerImpl> surface_sibling = |
| 3456 | TextureLayerImpl::Create(host_impl.active_tree(), 5); |
| 3457 | std::unique_ptr<TextureLayerImpl> surface_child_mask = |
| 3458 | TextureLayerImpl::Create(host_impl.active_tree(), 6); |
| 3459 | |
| 3460 | surface->SetDrawsContent(true); |
| 3461 | surface_child->SetDrawsContent(true); |
| 3462 | surface_sibling->SetDrawsContent(true); |
| 3463 | surface_child_mask->SetDrawsContent(true); |
| 3464 | surface->SetContentsOpaque(true); |
| 3465 | surface_child->SetContentsOpaque(true); |
| 3466 | surface_sibling->SetContentsOpaque(true); |
| 3467 | surface_child_mask->SetContentsOpaque(true); |
| 3468 | |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3469 | gfx::Transform translate; |
| 3470 | translate.Translate(20.f, 20.f); |
| 3471 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3472 | root->SetBounds(gfx::Size(1000, 1000)); |
| 3473 | child->SetBounds(gfx::Size(300, 300)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3474 | surface->test_properties()->transform = translate; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3475 | surface->SetBounds(gfx::Size(300, 300)); |
| 3476 | surface->test_properties()->force_render_surface = true; |
| 3477 | surface_child->SetBounds(gfx::Size(300, 300)); |
| 3478 | surface_child->test_properties()->force_render_surface = true; |
| 3479 | surface_sibling->SetBounds(gfx::Size(200, 200)); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3480 | |
| 3481 | LayerImpl* surface_ptr = surface.get(); |
| 3482 | LayerImpl* surface_child_ptr = surface_child.get(); |
| 3483 | LayerImpl* surface_child_mask_ptr = surface_child_mask.get(); |
| 3484 | |
| 3485 | host_impl.SetViewportSize(root->bounds()); |
| 3486 | |
| 3487 | surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask)); |
| 3488 | surface->test_properties()->AddChild(std::move(surface_child)); |
| 3489 | child->test_properties()->AddChild(std::move(surface)); |
| 3490 | child->test_properties()->AddChild(std::move(surface_sibling)); |
| 3491 | root->test_properties()->AddChild(std::move(child)); |
| 3492 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 3493 | host_impl.SetVisible(true); |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3494 | host_impl.InitializeRenderer(compositor_frame_sink.get()); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3495 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 3496 | bool update_lcd_text = false; |
| 3497 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3498 | |
| 3499 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 3500 | surface_ptr->render_surface()->draw_transform(), translate); |
| 3501 | // surface_sibling draws into the root render surface and occludes |
| 3502 | // surface_child's contents. |
| 3503 | Occlusion actual_occlusion = |
| 3504 | surface_child_ptr->render_surface()->occlusion_in_content_space(); |
| 3505 | Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()), |
| 3506 | SimpleEnclosedRegion(gfx::Rect(200, 200))); |
| 3507 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3508 | |
| 3509 | // Mask layer should have the same occlusion. |
| 3510 | actual_occlusion = |
| 3511 | surface_child_mask_ptr->draw_properties().occlusion_in_content_space; |
| 3512 | EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); |
| 3513 | } |
| 3514 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3515 | TEST_F(LayerTreeHostCommonTest, |
| 3516 | OcclusionForLayerWithUninvertibleDrawTransform) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3517 | FakeImplTaskRunnerProvider task_runner_provider; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3518 | TestSharedBitmapManager shared_bitmap_manager; |
| 3519 | TestTaskGraphRunner task_graph_runner; |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3520 | std::unique_ptr<CompositorFrameSink> compositor_frame_sink = |
| 3521 | FakeCompositorFrameSink::Create3d(); |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3522 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3523 | &task_graph_runner); |
jaydasika | 69c77aa | 2016-07-14 22:48:48 | [diff] [blame] | 3524 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3525 | std::unique_ptr<LayerImpl> root = |
| 3526 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3527 | std::unique_ptr<LayerImpl> child = |
| 3528 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3529 | std::unique_ptr<LayerImpl> grand_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3530 | LayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3531 | std::unique_ptr<LayerImpl> occluding_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3532 | LayerImpl::Create(host_impl.active_tree(), 4); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3533 | |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3534 | gfx::Transform perspective; |
| 3535 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3536 | |
| 3537 | gfx::Transform rotation; |
| 3538 | rotation.RotateAboutYAxis(45.0); |
| 3539 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3540 | root->SetBounds(gfx::Size(1000, 1000)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3541 | child->test_properties()->transform = perspective; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3542 | child->SetPosition(gfx::PointF(10.f, 10.f)); |
| 3543 | child->SetBounds(gfx::Size(300, 300)); |
| 3544 | child->test_properties()->should_flatten_transform = false; |
| 3545 | child->Set3dSortingContextId(1); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3546 | grand_child->test_properties()->transform = rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3547 | grand_child->SetBounds(gfx::Size(200, 200)); |
| 3548 | grand_child->test_properties()->should_flatten_transform = false; |
| 3549 | grand_child->Set3dSortingContextId(1); |
| 3550 | occluding_child->SetBounds(gfx::Size(200, 200)); |
| 3551 | occluding_child->test_properties()->should_flatten_transform = false; |
| 3552 | |
| 3553 | child->SetDrawsContent(true); |
| 3554 | grand_child->SetDrawsContent(true); |
| 3555 | occluding_child->SetDrawsContent(true); |
| 3556 | occluding_child->SetContentsOpaque(true); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3557 | |
| 3558 | host_impl.SetViewportSize(root->bounds()); |
| 3559 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3560 | child->test_properties()->AddChild(std::move(grand_child)); |
| 3561 | root->test_properties()->AddChild(std::move(child)); |
| 3562 | root->test_properties()->AddChild(std::move(occluding_child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3563 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 3564 | host_impl.SetVisible(true); |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 3565 | host_impl.InitializeRenderer(compositor_frame_sink.get()); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 3566 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3567 | bool update_lcd_text = false; |
| 3568 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3569 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3570 | LayerImpl* grand_child_ptr = host_impl.active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3571 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3572 | ->test_properties() |
| 3573 | ->children[0] |
| 3574 | ->test_properties() |
| 3575 | ->children[0]; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3576 | |
| 3577 | // Though all layers have invertible transforms, matrix multiplication using |
| 3578 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3579 | EXPECT_FALSE( |
| 3580 | host_impl.active_tree() |
| 3581 | ->property_trees() |
| 3582 | ->transform_tree.Node(grand_child_ptr->transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3583 | ->ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3584 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3585 | // Since |grand_child| has an uninvertible screen space transform, it is |
| 3586 | // skipped so |
| 3587 | // that we are not computing its occlusion_in_content_space. |
| 3588 | gfx::Rect layer_bounds = gfx::Rect(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3589 | EXPECT_EQ( |
| 3590 | layer_bounds, |
| 3591 | grand_child_ptr->draw_properties() |
| 3592 | .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds)); |
| 3593 | } |
| 3594 | |
| 3595 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3596 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3597 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3598 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3599 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3600 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3601 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3602 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3603 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3604 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3605 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3606 | render_surface->test_properties()->force_render_surface = true; |
| 3607 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3608 | child1->SetBounds(gfx::Size(50, 50)); |
| 3609 | child1->SetDrawsContent(true); |
| 3610 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3611 | child2->SetBounds(gfx::Size(50, 50)); |
| 3612 | child2->SetDrawsContent(true); |
| 3613 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3614 | child3->SetBounds(gfx::Size(50, 50)); |
| 3615 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3616 | ExecuteCalculateDrawProperties(root); |
| 3617 | |
| 3618 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3619 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3620 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3621 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3622 | |
| 3623 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3624 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3625 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3626 | |
| 3627 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3628 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3629 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3630 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3631 | |
| 3632 | // All layers that draw content into the surface have their visible content |
| 3633 | // rect clipped by the surface clip rect. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3634 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3635 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3636 | EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3637 | |
| 3638 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3639 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3640 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3641 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3642 | } |
| 3643 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3644 | TEST_F(LayerTreeHostCommonTest, |
| 3645 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3646 | // Check that clipping does not propagate down surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3647 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3648 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3649 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 3650 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3651 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3652 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3653 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3654 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3655 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3656 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 3657 | render_surface1->test_properties()->force_render_surface = true; |
| 3658 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 3659 | render_surface2->test_properties()->force_render_surface = true; |
| 3660 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 3661 | child1->SetBounds(gfx::Size(50, 50)); |
| 3662 | child1->SetDrawsContent(true); |
| 3663 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 3664 | child2->SetBounds(gfx::Size(50, 50)); |
| 3665 | child2->SetDrawsContent(true); |
| 3666 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 3667 | child3->SetBounds(gfx::Size(50, 50)); |
| 3668 | child3->SetDrawsContent(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3669 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3670 | |
| 3671 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3672 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3673 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3674 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3675 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3676 | |
| 3677 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3678 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3679 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); |
| 3680 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3681 | |
| 3682 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3683 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3684 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3685 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3686 | |
| 3687 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3688 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3689 | // render_surface2 grows to enclose all drawable content of its subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3690 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3691 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3692 | |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3693 | // All layers that draw content into render_surface2 think they are unclipped |
| 3694 | // by the surface. So, only the viewport clip applies. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3695 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3696 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3697 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3698 | |
| 3699 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3700 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3701 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3702 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3703 | } |
| 3704 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3705 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3706 | VisibleRectsForClippedDescendantsOfUnclippedSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3707 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3708 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3709 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 3710 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 3711 | LayerImpl* render_surface2 = AddChild<LayerImpl>(child2); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3712 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3713 | root->SetBounds(gfx::Size(100, 100)); |
| 3714 | render_surface1->SetBounds(gfx::Size(100, 100)); |
| 3715 | render_surface1->test_properties()->force_render_surface = true; |
| 3716 | child1->SetBounds(gfx::Size(500, 500)); |
| 3717 | child1->SetDrawsContent(true); |
| 3718 | child2->SetBounds(gfx::Size(700, 700)); |
| 3719 | child2->SetDrawsContent(true); |
| 3720 | render_surface2->SetBounds(gfx::Size(1000, 1000)); |
| 3721 | render_surface2->test_properties()->force_render_surface = true; |
| 3722 | render_surface2->SetDrawsContent(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3723 | |
| 3724 | child1->SetMasksToBounds(true); |
| 3725 | child2->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3726 | ExecuteCalculateDrawProperties(root); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3727 | EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3728 | EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3729 | } |
| 3730 | |
| 3731 | TEST_F(LayerTreeHostCommonTest, |
| 3732 | VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3733 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3734 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3735 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3736 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3737 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3738 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3739 | root->SetBounds(gfx::Size(100, 100)); |
| 3740 | |
| 3741 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3742 | clip_parent->SetMasksToBounds(true); |
| 3743 | clip_parent->test_properties()->clip_children = |
| 3744 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3745 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3746 | |
| 3747 | render_surface1->SetBounds(gfx::Size(20, 20)); |
| 3748 | render_surface1->SetMasksToBounds(true); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3749 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3750 | render_surface1->test_properties()->force_render_surface = true; |
| 3751 | |
| 3752 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3753 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3754 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3755 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3756 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 3757 | render_surface2->SetDrawsContent(true); |
| 3758 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3759 | |
| 3760 | ExecuteCalculateDrawProperties(root); |
| 3761 | EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect()); |
| 3762 | EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect()); |
| 3763 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect()); |
| 3764 | } |
| 3765 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3766 | TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3767 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3768 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3769 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3770 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3771 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3772 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3773 | root->SetBounds(gfx::Size(100, 100)); |
| 3774 | |
| 3775 | clip_parent->SetPosition(gfx::PointF(2.f, 2.f)); |
| 3776 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3777 | clip_parent->test_properties()->clip_children = |
| 3778 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3779 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3780 | |
| 3781 | render_surface1->SetBounds(gfx::Size(20, 20)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3782 | render_surface1->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3783 | render_surface1->test_properties()->force_render_surface = true; |
| 3784 | |
| 3785 | clip_child->SetBounds(gfx::Size(60, 60)); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3786 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3787 | clip_child->test_properties()->clip_parent = clip_parent; |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3788 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3789 | render_surface2->SetBounds(gfx::Size(60, 60)); |
| 3790 | render_surface2->SetDrawsContent(true); |
| 3791 | render_surface2->test_properties()->force_render_surface = true; |
| 3792 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3793 | clip_parent->SetMasksToBounds(true); |
| 3794 | render_surface1->SetMasksToBounds(true); |
| 3795 | |
| 3796 | ExecuteCalculateDrawProperties(root); |
| 3797 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect()); |
| 3798 | } |
| 3799 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3800 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) { |
| 3801 | // Test that only drawn layers contribute to render surface content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3802 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3803 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 3804 | LayerImpl* test_layer = AddChild<LayerImpl>(surface); |
| 3805 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3806 | root->SetBounds(gfx::Size(200, 200)); |
| 3807 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3808 | surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3809 | surface->test_properties()->force_render_surface = true; |
| 3810 | test_layer->SetBounds(gfx::Size(150, 150)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3811 | |
| 3812 | ExecuteCalculateDrawProperties(root); |
| 3813 | EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect()); |
| 3814 | |
| 3815 | test_layer->SetDrawsContent(true); |
| 3816 | ExecuteCalculateDrawProperties(root); |
| 3817 | EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect()); |
| 3818 | } |
| 3819 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3820 | TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) { |
| 3821 | // Tests visible rects computation when we have unclipped_surface-> |
| 3822 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3823 | // of surface_with_unclipped_descendants doesn't propagate to the |
| 3824 | // clipped_surface below it. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3825 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3826 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3827 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3828 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3829 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3830 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3831 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3832 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3833 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3834 | unclipped_surface->SetBounds(gfx::Size(30, 30)); |
| 3835 | unclipped_surface->SetDrawsContent(true); |
| 3836 | unclipped_surface->test_properties()->force_render_surface = true; |
| 3837 | |
| 3838 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3839 | clip_parent->test_properties()->clip_children = |
| 3840 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3841 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3842 | |
| 3843 | unclipped_desc_surface->SetBounds(gfx::Size(20, 20)); |
| 3844 | unclipped_desc_surface->SetDrawsContent(true); |
| 3845 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 3846 | |
| 3847 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 3848 | clip_child->test_properties()->clip_parent = clip_parent; |
| 3849 | |
| 3850 | clipped_surface->SetBounds(gfx::Size(60, 60)); |
| 3851 | clipped_surface->SetDrawsContent(true); |
| 3852 | clipped_surface->test_properties()->force_render_surface = true; |
| 3853 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3854 | clip_parent->SetMasksToBounds(true); |
| 3855 | |
| 3856 | ExecuteCalculateDrawProperties(root); |
| 3857 | EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect()); |
| 3858 | EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect()); |
| 3859 | EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect()); |
| 3860 | } |
| 3861 | |
| 3862 | TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) { |
| 3863 | // Tests visible rects computation when we have unclipped_surface-> |
| 3864 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3865 | // of root propagate to the clipped_surface. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3866 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3867 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3868 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3869 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3870 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3871 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3872 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3873 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3874 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3875 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
| 3876 | unclipped_surface->SetDrawsContent(true); |
| 3877 | unclipped_surface->test_properties()->force_render_surface = true; |
| 3878 | |
| 3879 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 3880 | clip_parent->test_properties()->clip_children = |
| 3881 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 3882 | clip_parent->test_properties()->clip_children->insert(clip_child); |
| 3883 | |
| 3884 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 3885 | unclipped_desc_surface->SetDrawsContent(true); |
| 3886 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 3887 | |
| 3888 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 3889 | clip_child->test_properties()->clip_parent = clip_parent; |
| 3890 | |
| 3891 | clipped_surface->SetBounds(gfx::Size(50, 50)); |
| 3892 | clipped_surface->SetDrawsContent(true); |
| 3893 | clipped_surface->test_properties()->force_render_surface = true; |
| 3894 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3895 | clip_parent->SetMasksToBounds(true); |
| 3896 | unclipped_desc_surface->SetMasksToBounds(true); |
| 3897 | |
| 3898 | ExecuteCalculateDrawProperties(root); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 3899 | EXPECT_EQ(gfx::Rect(10, 10), unclipped_surface->visible_layer_rect()); |
jaydasika | 526eae0a | 2016-09-02 01:47:59 | [diff] [blame] | 3900 | EXPECT_EQ(gfx::Rect(10, 10), unclipped_desc_surface->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3901 | EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect()); |
| 3902 | } |
| 3903 | |
| 3904 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3905 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3906 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3907 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3908 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3909 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3910 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3911 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3912 | gfx::Transform child_rotation; |
| 3913 | child_rotation.Rotate(45.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3914 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3915 | root->SetBounds(gfx::Size(100, 100)); |
| 3916 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3917 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3918 | child1->test_properties()->transform = child_rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3919 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 3920 | child1->SetBounds(gfx::Size(50, 50)); |
| 3921 | child1->SetDrawsContent(true); |
| 3922 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3923 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3924 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3925 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3926 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3927 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3928 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3929 | |
| 3930 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3931 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3932 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3933 | |
| 3934 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3935 | // regions of the subtree. |
| 3936 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3937 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3938 | gfx::Rect(50 - diagonal_radius, |
| 3939 | 50 - diagonal_radius, |
| 3940 | diagonal_radius * 2, |
| 3941 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3942 | EXPECT_EQ(gfx::RectF(expected_surface_drawable_content), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3943 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3944 | |
| 3945 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3946 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3947 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3948 | } |
| 3949 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3950 | TEST_F(LayerTreeHostCommonTest, |
| 3951 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3952 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3953 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3954 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3955 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3956 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3957 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3958 | gfx::Transform child_rotation; |
| 3959 | child_rotation.Rotate(45.0); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3960 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3961 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3962 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3963 | render_surface->SetBounds(gfx::Size(3, 4)); |
| 3964 | render_surface->test_properties()->force_render_surface = true; |
| 3965 | child1->SetPosition(gfx::PointF(25.f, 25.f)); |
| 3966 | child1->SetBounds(gfx::Size(50, 50)); |
| 3967 | child1->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 3968 | child1->test_properties()->transform = child_rotation; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 3969 | child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3970 | ExecuteCalculateDrawProperties(root); |
| 3971 | |
| 3972 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3973 | |
| 3974 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3975 | // rotated layer. |
| 3976 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3977 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3978 | 50 - diagonal_radius, |
| 3979 | diagonal_radius * 2, |
| 3980 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3981 | gfx::RectF expected_surface_drawable_content( |
| 3982 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3983 | EXPECT_EQ(expected_surface_drawable_content, |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3984 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3985 | |
| 3986 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3987 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3988 | // up covering the full left half of child1. |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 3989 | EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3990 | |
| 3991 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3992 | EXPECT_EQ(unclipped_surface_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, DrawableAndVisibleContentRectsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3996 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3997 | FakePictureLayerImpl* render_surface1 = |
| 3998 | AddChildToRoot<FakePictureLayerImpl>(); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3999 | FakePictureLayerImpl* render_surface2 = |
| 4000 | AddChild<FakePictureLayerImpl>(render_surface1); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4001 | FakePictureLayerImpl* child1 = |
| 4002 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4003 | FakePictureLayerImpl* child2 = |
| 4004 | AddChild<FakePictureLayerImpl>(render_surface2); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4005 | FakePictureLayerImpl* child3 = |
| 4006 | AddChild<FakePictureLayerImpl>(render_surface2); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4007 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4008 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4009 | root->SetMasksToBounds(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4010 | render_surface1->SetBounds(gfx::Size(3, 4)); |
| 4011 | render_surface1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4012 | render_surface1->SetDrawsContent(true); |
| 4013 | render_surface1->test_properties()->force_render_surface = true; |
| 4014 | render_surface2->SetBounds(gfx::Size(7, 13)); |
| 4015 | render_surface2->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4016 | render_surface2->SetDrawsContent(true); |
| 4017 | render_surface2->test_properties()->force_render_surface = true; |
| 4018 | child1->SetBounds(gfx::Size(50, 50)); |
| 4019 | child1->SetPosition(gfx::PointF(5.f, 5.f)); |
| 4020 | child1->SetDrawsContent(true); |
| 4021 | child2->SetBounds(gfx::Size(50, 50)); |
| 4022 | child2->SetPosition(gfx::PointF(75.f, 75.f)); |
| 4023 | child2->SetDrawsContent(true); |
| 4024 | child3->SetBounds(gfx::Size(50, 50)); |
| 4025 | child3->SetPosition(gfx::PointF(125.f, 125.f)); |
| 4026 | child3->SetDrawsContent(true); |
| 4027 | float device_scale_factor = 2.f; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4028 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4029 | |
| 4030 | ASSERT_TRUE(render_surface1->render_surface()); |
| 4031 | ASSERT_TRUE(render_surface2->render_surface()); |
| 4032 | |
| 4033 | // drawable_content_rects for all layers and surfaces are scaled by |
| 4034 | // device_scale_factor. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4035 | EXPECT_EQ(gfx::RectF(200.f, 200.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4036 | root->render_surface()->DrawableContentRect()); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4037 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4038 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4039 | |
| 4040 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 4041 | // is only implicitly clipped by render_surface1. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4042 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4043 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4044 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4045 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 4046 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 4047 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4048 | |
| 4049 | // The root layer does not actually draw content of its own. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4050 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4051 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4052 | // All layer visible content rects are not expressed in content space of each |
| 4053 | // layer, so they are not scaled by the device_scale_factor. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4054 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect()); |
| 4055 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect()); |
| 4056 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 4057 | EXPECT_EQ(gfx::Rect(0, 0, 15, 15), child2->visible_layer_rect()); |
| 4058 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4059 | } |
| 4060 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4061 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4062 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 4063 | // layers. Note that 3d transforms still apply in this case, but they are |
| 4064 | // "flattened" to each parent layer according to current W3C spec. |
| 4065 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4066 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4067 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4068 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4069 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4070 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4071 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4072 | AddChild<LayerImpl>(front_facing_surface); |
| 4073 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4074 | AddChild<LayerImpl>(front_facing_surface); |
| 4075 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4076 | AddChild<LayerImpl>(back_facing_surface); |
| 4077 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4078 | AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4079 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4080 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4081 | front_facing_child->test_properties()->double_sided = false; |
| 4082 | back_facing_child->test_properties()->double_sided = false; |
| 4083 | front_facing_surface->test_properties()->double_sided = false; |
| 4084 | back_facing_surface->test_properties()->double_sided = false; |
| 4085 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4086 | false; |
| 4087 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4088 | false; |
| 4089 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4090 | false; |
| 4091 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4092 | false; |
| 4093 | |
| 4094 | // Everything draws content. |
| 4095 | front_facing_child->SetDrawsContent(true); |
| 4096 | back_facing_child->SetDrawsContent(true); |
| 4097 | front_facing_surface->SetDrawsContent(true); |
| 4098 | back_facing_surface->SetDrawsContent(true); |
| 4099 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4100 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4101 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4102 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4103 | |
| 4104 | gfx::Transform backface_matrix; |
| 4105 | backface_matrix.Translate(50.0, 50.0); |
| 4106 | backface_matrix.RotateAboutYAxis(180.0); |
| 4107 | backface_matrix.Translate(-50.0, -50.0); |
| 4108 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4109 | root->SetBounds(gfx::Size(100, 100)); |
| 4110 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4111 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4112 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4113 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4114 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4115 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4116 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4117 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4118 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4119 | front_facing_surface->test_properties()->force_render_surface = true; |
| 4120 | back_facing_surface->test_properties()->force_render_surface = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4121 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4122 | back_facing_child->test_properties()->transform = backface_matrix; |
| 4123 | back_facing_surface->test_properties()->transform = backface_matrix; |
| 4124 | back_facing_child_of_front_facing_surface->test_properties()->transform = |
| 4125 | backface_matrix; |
| 4126 | back_facing_child_of_back_facing_surface->test_properties()->transform = |
| 4127 | backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4128 | |
| 4129 | // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms |
| 4130 | // spec, these layers should blindly use their own local transforms to |
| 4131 | // determine back-face culling. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4132 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4133 | |
| 4134 | // Verify which render surfaces were created. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4135 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4136 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4137 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
| 4138 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4139 | EXPECT_FALSE( |
| 4140 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4141 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4142 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4143 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4144 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4145 | EXPECT_EQ(4u, update_layer_list_impl()->size()); |
| 4146 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4147 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4148 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4149 | front_facing_child_of_front_facing_surface->id())); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4150 | EXPECT_TRUE(UpdateLayerListImplContains( |
| 4151 | front_facing_child_of_back_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4152 | } |
| 4153 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4154 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4155 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 4156 | // is used. |
| 4157 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4158 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4159 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4160 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4161 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4162 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4163 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4164 | AddChild<LayerImpl>(front_facing_surface); |
| 4165 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4166 | AddChild<LayerImpl>(front_facing_surface); |
| 4167 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4168 | AddChild<LayerImpl>(back_facing_surface); |
| 4169 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4170 | AddChild<LayerImpl>(back_facing_surface); |
| 4171 | // Opacity will not force creation of render surfaces in this case because of |
| 4172 | // the preserve-3d transform style. Instead, an example of when a surface |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame^] | 4173 | // would be created with preserve-3d is when there is a mask layer. |
| 4174 | LayerImpl* dummy_mask_layer1 = AddMaskLayer<LayerImpl>(front_facing_surface); |
| 4175 | LayerImpl* dummy_mask_layer2 = AddMaskLayer<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4176 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4177 | // Nothing is double-sided |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4178 | front_facing_child->test_properties()->double_sided = false; |
| 4179 | back_facing_child->test_properties()->double_sided = false; |
| 4180 | front_facing_surface->test_properties()->double_sided = false; |
| 4181 | back_facing_surface->test_properties()->double_sided = false; |
| 4182 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4183 | false; |
| 4184 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4185 | false; |
| 4186 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4187 | false; |
| 4188 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4189 | false; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4190 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4191 | // Everything draws content. |
| 4192 | front_facing_child->SetDrawsContent(true); |
| 4193 | back_facing_child->SetDrawsContent(true); |
| 4194 | front_facing_surface->SetDrawsContent(true); |
| 4195 | back_facing_surface->SetDrawsContent(true); |
| 4196 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4197 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4198 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4199 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame^] | 4200 | dummy_mask_layer1->SetDrawsContent(true); |
| 4201 | dummy_mask_layer2->SetDrawsContent(true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4202 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4203 | gfx::Transform backface_matrix; |
| 4204 | backface_matrix.Translate(50.0, 50.0); |
| 4205 | backface_matrix.RotateAboutYAxis(180.0); |
| 4206 | backface_matrix.Translate(-50.0, -50.0); |
| 4207 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4208 | root->SetBounds(gfx::Size(100, 100)); |
| 4209 | front_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4210 | back_facing_child->SetBounds(gfx::Size(100, 100)); |
| 4211 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4212 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4213 | front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4214 | back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4215 | front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4216 | back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4217 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4218 | back_facing_child->test_properties()->transform = backface_matrix; |
| 4219 | back_facing_surface->test_properties()->transform = backface_matrix; |
| 4220 | back_facing_child_of_front_facing_surface->test_properties()->transform = |
| 4221 | backface_matrix; |
| 4222 | back_facing_child_of_back_facing_surface->test_properties()->transform = |
| 4223 | backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4224 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4225 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 4226 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 4227 | // rendering context should use the transform with respect to that context. |
| 4228 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 4229 | // and (b) the layer's transform style is preserve-3d. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4230 | front_facing_surface->test_properties()->should_flatten_transform = false; |
| 4231 | front_facing_surface->Set3dSortingContextId(1); |
| 4232 | back_facing_surface->test_properties()->should_flatten_transform = false; |
| 4233 | back_facing_surface->Set3dSortingContextId(1); |
| 4234 | front_facing_child_of_front_facing_surface->Set3dSortingContextId(1); |
| 4235 | back_facing_child_of_front_facing_surface->Set3dSortingContextId(1); |
| 4236 | front_facing_child_of_back_facing_surface->Set3dSortingContextId(1); |
| 4237 | back_facing_child_of_back_facing_surface->Set3dSortingContextId(1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4238 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4239 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4240 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4241 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4242 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4243 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4244 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4245 | // We expect that a has_render_surface was created but not used. |
| 4246 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4247 | EXPECT_FALSE( |
| 4248 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4249 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4250 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4251 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4252 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4253 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4254 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4255 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4256 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4257 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4258 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4259 | } |
| 4260 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4261 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4262 | // Verify that layers are appropriately culled when their back face is showing |
| 4263 | // and they are not double sided, while animations are going on. |
| 4264 | // |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4265 | // Even layers that are animating get culled if their back face is showing and |
| 4266 | // they are not double sided. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4267 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4268 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4269 | LayerImpl* animating_surface = AddChildToRoot<LayerImpl>(); |
| 4270 | LayerImpl* child_of_animating_surface = |
| 4271 | AddChild<LayerImpl>(animating_surface); |
| 4272 | LayerImpl* animating_child = AddChildToRoot<LayerImpl>(); |
| 4273 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4274 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4275 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4276 | child->test_properties()->double_sided = false; |
| 4277 | child2->test_properties()->double_sided = false; |
| 4278 | animating_surface->test_properties()->double_sided = false; |
| 4279 | child_of_animating_surface->test_properties()->double_sided = false; |
| 4280 | animating_child->test_properties()->double_sided = false; |
| 4281 | |
| 4282 | // Everything draws content. |
| 4283 | child->SetDrawsContent(true); |
| 4284 | child2->SetDrawsContent(true); |
| 4285 | animating_surface->SetDrawsContent(true); |
| 4286 | child_of_animating_surface->SetDrawsContent(true); |
| 4287 | animating_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4288 | |
| 4289 | gfx::Transform backface_matrix; |
| 4290 | backface_matrix.Translate(50.0, 50.0); |
| 4291 | backface_matrix.RotateAboutYAxis(180.0); |
| 4292 | backface_matrix.Translate(-50.0, -50.0); |
| 4293 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4294 | SetElementIdsForTesting(); |
| 4295 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4296 | // Animate the transform on the render surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4297 | AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(), |
| 4298 | timeline_impl(), 10.0, 30, 0); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4299 | // This is just an animating layer, not a surface. |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4300 | AddAnimatedTransformToElementWithPlayer(animating_child->element_id(), |
| 4301 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4302 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4303 | root->SetBounds(gfx::Size(100, 100)); |
| 4304 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4305 | child->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4306 | animating_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4307 | animating_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4308 | animating_surface->test_properties()->force_render_surface = true; |
| 4309 | child_of_animating_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4310 | child_of_animating_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4311 | animating_child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4312 | animating_child->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4313 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4314 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4315 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4316 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4317 | EXPECT_FALSE(child->has_render_surface()); |
| 4318 | EXPECT_TRUE(animating_surface->has_render_surface()); |
| 4319 | EXPECT_FALSE(child_of_animating_surface->has_render_surface()); |
| 4320 | EXPECT_FALSE(animating_child->has_render_surface()); |
| 4321 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4322 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4323 | EXPECT_EQ(1u, update_layer_list_impl()->size()); |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4324 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4325 | // The back facing layers are culled from the layer list, and have an empty |
| 4326 | // visible rect. |
| 4327 | EXPECT_TRUE(UpdateLayerListImplContains(child2->id())); |
| 4328 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
| 4329 | EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty()); |
| 4330 | EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty()); |
| 4331 | EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4332 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4333 | EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4334 | } |
| 4335 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4336 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4337 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4338 | // Verify the behavior of back-face culling for a render surface that is |
| 4339 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4340 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4341 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4342 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4343 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4344 | LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface); |
| 4345 | LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4346 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4347 | // RenderSurfaces are not double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4348 | front_facing_surface->test_properties()->double_sided = false; |
| 4349 | back_facing_surface->test_properties()->double_sided = false; |
| 4350 | |
| 4351 | // Everything draws content. |
| 4352 | front_facing_surface->SetDrawsContent(true); |
| 4353 | back_facing_surface->SetDrawsContent(true); |
| 4354 | child1->SetDrawsContent(true); |
| 4355 | child2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4356 | |
| 4357 | gfx::Transform backface_matrix; |
| 4358 | backface_matrix.Translate(50.0, 50.0); |
| 4359 | backface_matrix.RotateAboutYAxis(180.0); |
| 4360 | backface_matrix.Translate(-50.0, -50.0); |
| 4361 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4362 | root->SetBounds(gfx::Size(100, 100)); |
| 4363 | front_facing_surface->SetBounds(gfx::Size(100, 100)); |
| 4364 | front_facing_surface->test_properties()->force_render_surface = true; |
| 4365 | back_facing_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4366 | back_facing_surface->test_properties()->transform = backface_matrix; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4367 | back_facing_surface->test_properties()->force_render_surface = true; |
| 4368 | child1->SetBounds(gfx::Size(100, 100)); |
| 4369 | child2->SetBounds(gfx::Size(100, 100)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4370 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4371 | front_facing_surface->Set3dSortingContextId(1); |
| 4372 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4373 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 4374 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4375 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4376 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4377 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4378 | |
| 4379 | // We expect the render surface to have been created, but remain unused. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4380 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4381 | EXPECT_FALSE(child1->has_render_surface()); |
| 4382 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4383 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4384 | EXPECT_EQ(2u, update_layer_list_impl()->size()); |
| 4385 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4386 | EXPECT_TRUE(UpdateLayerListImplContains(child1->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4387 | } |
| 4388 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4389 | TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4390 | // Verify draw and screen space transforms of layers not in a surface. |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4391 | LayerImpl* root = root_layer_for_testing(); |
| 4392 | root->SetBounds(gfx::Size(100, 100)); |
| 4393 | root->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4394 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4395 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4396 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4397 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4398 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4399 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4400 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4401 | child2->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4402 | child2->SetBounds(gfx::Size(5, 5)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4403 | child2->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4404 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4405 | float device_scale_factor = 2.5f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4406 | gfx::Size viewport_size(100, 100); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4407 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4408 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4409 | EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale()); |
| 4410 | EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale()); |
| 4411 | EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale()); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4412 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4413 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4414 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4415 | // Verify root transforms |
| 4416 | gfx::Transform expected_root_transform; |
| 4417 | expected_root_transform.Scale(device_scale_factor, device_scale_factor); |
| 4418 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4419 | root->ScreenSpaceTransform()); |
| 4420 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform, |
| 4421 | root->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4422 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4423 | // Verify results of transformed root rects |
| 4424 | gfx::RectF root_bounds(gfx::SizeF(root->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4425 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4426 | gfx::RectF root_draw_rect = |
| 4427 | MathUtil::MapClippedRect(root->DrawTransform(), root_bounds); |
| 4428 | gfx::RectF root_screen_space_rect = |
| 4429 | MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4430 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4431 | gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds())); |
| 4432 | expected_root_draw_rect.Scale(device_scale_factor); |
| 4433 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect); |
| 4434 | EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4435 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4436 | // Verify child and child2 transforms. They should match. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4437 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4438 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4439 | expected_child_transform.Translate(child->position().x(), |
| 4440 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4441 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4442 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4443 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4444 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4445 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4446 | child2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4447 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4448 | child2->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4449 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4450 | // Verify results of transformed child and child2 rects. They should |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4451 | // match. |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4452 | gfx::RectF child_bounds(gfx::SizeF(child->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4453 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4454 | gfx::RectF child_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4455 | MathUtil::MapClippedRect(child->DrawTransform(), child_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4456 | gfx::RectF child_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4457 | MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4458 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4459 | gfx::RectF child2_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4460 | MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4461 | gfx::RectF child2_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4462 | MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4463 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4464 | gfx::RectF expected_child_draw_rect(child->position(), |
| 4465 | gfx::SizeF(child->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4466 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4467 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4468 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4469 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect); |
| 4470 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4471 | } |
| 4472 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4473 | TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4474 | // Verify draw and screen space transforms of layers in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4475 | gfx::Transform perspective_matrix; |
| 4476 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4477 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4478 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4479 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4480 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4481 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4482 | root->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4483 | |
| 4484 | LayerImpl* page_scale = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4485 | page_scale->SetBounds(gfx::Size(100, 100)); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4486 | |
| 4487 | LayerImpl* parent = AddChild<LayerImpl>(page_scale); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4488 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4489 | parent->SetDrawsContent(true); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4490 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4491 | LayerImpl* perspective_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4492 | perspective_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4493 | perspective_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4494 | perspective_surface->test_properties()->transform = |
| 4495 | perspective_matrix * scale_small_matrix; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4496 | perspective_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4497 | perspective_surface->test_properties()->force_render_surface = true; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4498 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4499 | LayerImpl* scale_surface = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4500 | scale_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4501 | scale_surface->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4502 | scale_surface->test_properties()->transform = scale_small_matrix; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4503 | scale_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4504 | scale_surface->test_properties()->force_render_surface = true; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4505 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4506 | float device_scale_factor = 2.5f; |
| 4507 | float page_scale_factor = 3.f; |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4508 | root->layer_tree_impl()->SetViewportLayersFromIds( |
| 4509 | Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, |
| 4510 | Layer::INVALID_ID); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4511 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4512 | root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4513 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4514 | root); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4515 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4516 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4517 | parent->GetIdealContentsScale()); |
| 4518 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4519 | perspective_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4520 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4521 | // the nearest render target. Here this includes the layer transform as well |
| 4522 | // as the device and page scale factors. |
| 4523 | gfx::Transform transform = scale_small_matrix; |
| 4524 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4525 | device_scale_factor * page_scale_factor); |
| 4526 | gfx::Vector2dF scales = |
| 4527 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4528 | float max_2d_scale = std::max(scales.x(), scales.y()); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4529 | EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4530 | |
| 4531 | // The ideal scale will draw 1:1 with its render target space along |
| 4532 | // the larger-scale axis. |
| 4533 | gfx::Vector2dF target_space_transform_scales = |
| 4534 | MathUtil::ComputeTransform2dScaleComponents( |
| 4535 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4536 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4537 | std::max(target_space_transform_scales.x(), |
| 4538 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4539 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4540 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4541 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4542 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4543 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4544 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4545 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4546 | parent->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4547 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4548 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4549 | // with the screen, and then scaled during drawing. |
| 4550 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4551 | expected_perspective_surface_draw_transform.Translate( |
| 4552 | device_scale_factor * page_scale_factor * |
| 4553 | perspective_surface->position().x(), |
| 4554 | device_scale_factor * page_scale_factor * |
| 4555 | perspective_surface->position().y()); |
| 4556 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4557 | perspective_matrix); |
| 4558 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4559 | scale_small_matrix); |
| 4560 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4561 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4562 | device_scale_factor * page_scale_factor, |
| 4563 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4564 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4565 | expected_perspective_surface_draw_transform, |
| 4566 | perspective_surface->render_surface()->draw_transform()); |
| 4567 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4568 | expected_perspective_surface_layer_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4569 | perspective_surface->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4570 | } |
| 4571 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4572 | TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4573 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4574 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4575 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4576 | |
| 4577 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4578 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4579 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4580 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4581 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4582 | root->SetBounds(gfx::Size(100, 100)); |
| 4583 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4584 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4585 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4586 | parent->test_properties()->transform = parent_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4587 | parent->SetDrawsContent(true); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4588 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4589 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4590 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4591 | child_scale->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4592 | child_scale->test_properties()->transform = child_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4593 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4594 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4595 | float device_scale_factor = 2.5f; |
| 4596 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4597 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4598 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4599 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4600 | root); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4601 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4602 | // The ideal scale is able to go below 1. |
| 4603 | float expected_ideal_scale = |
| 4604 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4605 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4606 | EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale()); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4607 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4608 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4609 | initial_parent_scale * initial_child_scale; |
| 4610 | EXPECT_LT(expected_ideal_scale, 1.f); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4611 | EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4612 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4613 | } |
| 4614 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4615 | TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4616 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4617 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4618 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4619 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4620 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4621 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4622 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4623 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4624 | LayerImpl* root = root_layer_for_testing(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4625 | root->SetBounds(gfx::Size(100, 100)); |
| 4626 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4627 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4628 | parent->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4629 | parent->test_properties()->transform = parent_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4630 | parent->SetDrawsContent(true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4631 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4632 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4633 | child_scale->SetBounds(gfx::Size(10, 10)); |
| 4634 | child_scale->SetPosition(gfx::PointF(2.f, 2.f)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4635 | child_scale->test_properties()->transform = child_scale_matrix; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4636 | child_scale->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4637 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4638 | ExecuteCalculateDrawProperties(root); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4639 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4640 | EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale()); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4641 | // Animating layers compute ideal scale in the same way as when |
| 4642 | // they are static. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4643 | EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale, |
| 4644 | child_scale->GetIdealContentsScale()); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4645 | } |
| 4646 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4647 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4648 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4649 | parent->SetBounds(gfx::Size(30, 30)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4650 | parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4651 | parent->Set3dSortingContextId(1); |
| 4652 | parent->test_properties()->should_flatten_transform = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4653 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4654 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4655 | child->SetBounds(gfx::Size(10, 10)); |
| 4656 | child->SetPosition(gfx::PointF(2.f, 2.f)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4657 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4658 | child->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4659 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4660 | // This layer should end up in the same surface as child, with the same draw |
| 4661 | // and screen space transforms. |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4662 | LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4663 | duplicate_child_non_owner->SetBounds(gfx::Size(10, 10)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4664 | duplicate_child_non_owner->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4665 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4666 | float device_scale_factor = 1.5f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4667 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4668 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4669 | // We should have two render surfaces. The root's render surface and child's |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame^] | 4670 | // render surface (it needs one because of force_render_surface). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4671 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4672 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4673 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4674 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4675 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4676 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4677 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4678 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4679 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4680 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4681 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4682 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4683 | child->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4684 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4685 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4686 | expected_screen_space_transform.Scale(device_scale_factor, |
| 4687 | device_scale_factor); |
| 4688 | expected_screen_space_transform.Translate(child->position().x(), |
| 4689 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4690 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4691 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4692 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4693 | gfx::Transform expected_duplicate_child_draw_transform = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4694 | child->DrawTransform(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4695 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4696 | duplicate_child_non_owner->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4697 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4698 | child->ScreenSpaceTransform(), |
| 4699 | duplicate_child_non_owner->ScreenSpaceTransform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4700 | EXPECT_EQ(child->drawable_content_rect(), |
| 4701 | duplicate_child_non_owner->drawable_content_rect()); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4702 | EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4703 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4704 | gfx::Transform expected_render_surface_draw_transform; |
| 4705 | expected_render_surface_draw_transform.Translate( |
| 4706 | device_scale_factor * child->position().x(), |
| 4707 | device_scale_factor * child->position().y()); |
| 4708 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 4709 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4710 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4711 | gfx::Transform expected_surface_draw_transform; |
| 4712 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 4713 | device_scale_factor * 2.f); |
| 4714 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 4715 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4716 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4717 | gfx::Transform expected_surface_screen_space_transform; |
| 4718 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 4719 | device_scale_factor * 2.f); |
| 4720 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4721 | expected_surface_screen_space_transform, |
| 4722 | child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4723 | } |
| 4724 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4725 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4726 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4727 | LayerImpl* parent = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4728 | parent->SetBounds(gfx::Size(33, 31)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4729 | parent->SetDrawsContent(true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4730 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4731 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4732 | child->SetBounds(gfx::Size(13, 11)); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4733 | child->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4734 | child->test_properties()->force_render_surface = true; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4735 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 4736 | float device_scale_factor = 1.7f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4737 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4738 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4739 | // We should have two render surfaces. The root's render surface and child's |
wangxianzhu | 932d7f1 | 2016-09-30 05:47:00 | [diff] [blame^] | 4740 | // render surface (it needs one because of force_render_surface). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4741 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4742 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4743 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4744 | child->render_surface()->draw_transform()); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4745 | EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4746 | child->render_surface()->draw_transform()); |
| 4747 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 4748 | gfx::Transform(), child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4749 | } |
| 4750 | |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 4751 | TEST_F(LayerTreeHostCommonTest, LayerSearch) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4752 | scoped_refptr<Layer> root = Layer::Create(); |
| 4753 | scoped_refptr<Layer> child = Layer::Create(); |
| 4754 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 4755 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4756 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4757 | child->AddChild(grand_child.get()); |
| 4758 | child->SetMaskLayer(mask_layer.get()); |
| 4759 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4760 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4761 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4762 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4763 | int nonexistent_id = -1; |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 4764 | LayerTree* layer_tree = host()->GetLayerTree(); |
| 4765 | EXPECT_EQ(root.get(), layer_tree->LayerById(root->id())); |
| 4766 | EXPECT_EQ(child.get(), layer_tree->LayerById(child->id())); |
| 4767 | EXPECT_EQ(grand_child.get(), layer_tree->LayerById(grand_child->id())); |
| 4768 | EXPECT_EQ(mask_layer.get(), layer_tree->LayerById(mask_layer->id())); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 4769 | EXPECT_FALSE(layer_tree->LayerById(nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4770 | } |
| 4771 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4772 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4773 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4774 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 4775 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4776 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4777 | root->SetBounds(gfx::Size(100, 100)); |
| 4778 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4779 | child->test_properties()->opacity = 0.5f; |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4780 | grand_child->SetBounds(gfx::Size(10, 10)); |
| 4781 | grand_child->SetDrawsContent(true); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4782 | ExecuteCalculateDrawProperties(root); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4783 | EXPECT_FALSE(child->has_render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4784 | } |
| 4785 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4786 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4787 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4788 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 4789 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 4790 | FakeLayerTreeHostImpl host_impl(host()->GetSettings(), &task_runner_provider, |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4791 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4792 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4793 | std::unique_ptr<LayerImpl> root = |
| 4794 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4795 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4796 | root->SetDrawsContent(true); |
| 4797 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4798 | std::unique_ptr<LayerImpl> child = |
| 4799 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4800 | child->SetBounds(gfx::Size(50, 50)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4801 | child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4802 | child->test_properties()->opacity = 0.0f; |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4803 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 4804 | const int child_id = child->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4805 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 4806 | root->SetHasRenderSurface(true); |
| 4807 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4808 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4809 | host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4810 | |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4811 | // Add opacity animation. |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4812 | scoped_refptr<AnimationTimeline> timeline = |
| 4813 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 4814 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4815 | host_impl.pending_tree()->SetElementIdsForTesting(); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4816 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4817 | ElementId child_element_id = |
| 4818 | host_impl.pending_tree()->LayerById(child_id)->element_id(); |
| 4819 | |
| 4820 | AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0, |
| 4821 | 0.0f, 1.0f, false); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4822 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 4823 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4824 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4825 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4826 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4827 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4828 | |
| 4829 | // We should have one render surface and two layers. The child |
| 4830 | // layer should be included even though it is transparent. |
| 4831 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4832 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4833 | |
| 4834 | // If the root itself is hidden, the child should not be drawn even if it has |
| 4835 | // an animating opacity. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4836 | root_layer->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4837 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4838 | LayerImplList render_surface_layer_list2; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4839 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4840 | root_layer, root_layer->bounds(), &render_surface_layer_list2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4841 | inputs2.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4842 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4843 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4844 | LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4845 | EffectTree& tree = |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4846 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 4847 | EffectNode* node = tree.Node(child_ptr->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4848 | EXPECT_FALSE(node->is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4849 | |
| 4850 | // A layer should be drawn and it should contribute to drawn surface when |
| 4851 | // it has animating opacity even if it has opacity 0. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4852 | root_layer->test_properties()->opacity = 1.0f; |
| 4853 | child_ptr->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4854 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4855 | LayerImplList render_surface_layer_list3; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4856 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 4857 | root_layer, root_layer->bounds(), &render_surface_layer_list3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4858 | inputs3.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 4859 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4860 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 4861 | child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
| 4862 | tree = root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4863 | node = tree.Node(child_ptr->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4864 | EXPECT_TRUE(node->is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 4865 | EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index())); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4866 | |
| 4867 | // But if the opacity of the layer remains 0 after activation, it should not |
| 4868 | // be drawn. |
| 4869 | host_impl.ActivateSyncTree(); |
danakj | 0da42ca6 | 2016-07-01 19:42:33 | [diff] [blame] | 4870 | LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id()); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4871 | LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id()); |
| 4872 | |
| 4873 | EffectTree& active_effect_tree = |
| 4874 | host_impl.active_tree()->property_trees()->effect_tree; |
| 4875 | EXPECT_TRUE(active_effect_tree.needs_update()); |
| 4876 | |
| 4877 | ExecuteCalculateDrawProperties(active_root); |
| 4878 | |
| 4879 | node = active_effect_tree.Node(active_child->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 4880 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 4881 | EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface( |
| 4882 | active_child->effect_tree_index())); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 4883 | } |
| 4884 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4885 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4886 | class LCDTextTest : public LayerTreeHostCommonTestBase, |
| 4887 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4888 | public: |
| 4889 | LCDTextTest() |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4890 | : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()), |
| 4891 | host_impl_(LCDTextTestLayerTreeSettings(), |
| 4892 | &task_runner_provider_, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4893 | &shared_bitmap_manager_, |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4894 | &task_graph_runner_) {} |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4895 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4896 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 4897 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4898 | protected: |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4899 | LayerTreeSettings LCDTextTestLayerTreeSettings() { |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4900 | LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings(); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4901 | |
| 4902 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
| 4903 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
| 4904 | settings.can_use_lcd_text = can_use_lcd_text_; |
| 4905 | settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_; |
| 4906 | return settings; |
| 4907 | } |
| 4908 | |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 4909 | void SetUp() override { |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4910 | timeline_ = |
| 4911 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 4912 | host_impl_.animation_host()->AddAnimationTimeline(timeline_); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4913 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4914 | std::unique_ptr<LayerImpl> root_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4915 | LayerImpl::Create(host_impl_.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4916 | std::unique_ptr<LayerImpl> child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4917 | LayerImpl::Create(host_impl_.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4918 | std::unique_ptr<LayerImpl> grand_child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4919 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 4920 | |
| 4921 | // Stash raw pointers to look at later. |
| 4922 | root_ = root_ptr.get(); |
| 4923 | child_ = child_ptr.get(); |
| 4924 | grand_child_ = grand_child_ptr.get(); |
| 4925 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4926 | child_->test_properties()->AddChild(std::move(grand_child_ptr)); |
| 4927 | root_->test_properties()->AddChild(std::move(child_ptr)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4928 | host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4929 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 4930 | host_impl_.active_tree()->SetElementIdsForTesting(); |
| 4931 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 4932 | root_->SetContentsOpaque(true); |
| 4933 | child_->SetContentsOpaque(true); |
| 4934 | grand_child_->SetContentsOpaque(true); |
| 4935 | |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4936 | root_->SetDrawsContent(true); |
| 4937 | child_->SetDrawsContent(true); |
| 4938 | grand_child_->SetDrawsContent(true); |
| 4939 | |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 4940 | root_->SetBounds(gfx::Size(1, 1)); |
| 4941 | child_->SetBounds(gfx::Size(1, 1)); |
| 4942 | grand_child_->SetBounds(gfx::Size(1, 1)); |
| 4943 | |
| 4944 | child_->test_properties()->force_render_surface = |
| 4945 | std::tr1::get<2>(GetParam()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4946 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4947 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4948 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4949 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4950 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4951 | FakeImplTaskRunnerProvider task_runner_provider_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4952 | TestSharedBitmapManager shared_bitmap_manager_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 4953 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4954 | FakeLayerTreeHostImpl host_impl_; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4955 | scoped_refptr<AnimationTimeline> timeline_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 4956 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4957 | LayerImpl* root_ = nullptr; |
| 4958 | LayerImpl* child_ = nullptr; |
| 4959 | LayerImpl* grand_child_ = nullptr; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4960 | }; |
| 4961 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4962 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 4963 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 4964 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 4965 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4966 | // Case 1: Identity transform. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4967 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4968 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4969 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 4970 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4971 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4972 | // Case 2: Integral translation. |
| 4973 | gfx::Transform integral_translation; |
| 4974 | integral_translation.Translate(1.0, 2.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4975 | child_->test_properties()->transform = integral_translation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4976 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4977 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4978 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4979 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 4980 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4981 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4982 | // Case 3: Non-integral translation. |
| 4983 | gfx::Transform non_integral_translation; |
| 4984 | non_integral_translation.Translate(1.5, 2.5); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4985 | child_->test_properties()->transform = non_integral_translation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4986 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4987 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4988 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4989 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 4990 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 4991 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4992 | // Case 4: Rotation. |
| 4993 | gfx::Transform rotation; |
| 4994 | rotation.Rotate(10.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4995 | child_->test_properties()->transform = rotation; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 4996 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 4997 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 4998 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 4999 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5000 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5001 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5002 | // Case 5: Scale. |
| 5003 | gfx::Transform scale; |
| 5004 | scale.Scale(2.0, 2.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5005 | child_->test_properties()->transform = scale; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5006 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5007 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5008 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5009 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5010 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5011 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5012 | // Case 6: Skew. |
| 5013 | gfx::Transform skew; |
nainar | 8ca8ee6 | 2015-09-03 01:04:10 | [diff] [blame] | 5014 | skew.Skew(10.0, 0.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5015 | child_->test_properties()->transform = skew; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5016 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5017 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5018 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5019 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5020 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5021 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5022 | // Case 7: Translucent. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5023 | child_->test_properties()->transform = gfx::Transform(); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5024 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5025 | child_->test_properties()->opacity = 0.5f; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5026 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5027 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5028 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5029 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5030 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5031 | // Case 8: Sanity check: restore transform and opacity. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5032 | child_->test_properties()->transform = gfx::Transform(); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5033 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5034 | child_->test_properties()->opacity = 1.f; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5035 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5036 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5037 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5038 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5039 | |
| 5040 | // Case 9: Non-opaque content. |
| 5041 | child_->SetContentsOpaque(false); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5042 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5043 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5044 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5045 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5046 | |
| 5047 | // Case 10: Sanity check: restore content opaqueness. |
| 5048 | child_->SetContentsOpaque(true); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5049 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5050 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5051 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5052 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5053 | } |
| 5054 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5055 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5056 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5057 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5058 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5059 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5060 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5061 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5062 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5063 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5064 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5065 | // Add opacity animation. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5066 | child_->test_properties()->opacity = 0.9f; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5067 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5068 | |
| 5069 | SetElementIdsForTesting(); |
| 5070 | |
| 5071 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5072 | 10.0, 0.9f, 0.1f, false); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5073 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5074 | // Text LCD should be adjusted while animation is active. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5075 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5076 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5077 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5078 | } |
| 5079 | |
| 5080 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 5081 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5082 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5083 | |
| 5084 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5085 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5086 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5087 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5088 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5089 | SetElementIdsForTesting(); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5090 | |
| 5091 | // Mark contents non-opaque within the first animation frame. |
| 5092 | child_->SetContentsOpaque(false); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 5093 | AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), |
| 5094 | 10.0, 0.9f, 0.1f, false); |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 5095 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5096 | // LCD text should be disabled for non-opaque layers even during animations. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5097 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5098 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5099 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5100 | } |
| 5101 | |
| 5102 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5103 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5104 | testing::Combine(testing::Bool(), |
| 5105 | testing::Bool(), |
| 5106 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5107 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5108 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5109 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5110 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5111 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5112 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5113 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5114 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5115 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5116 | std::unique_ptr<LayerImpl> root = |
| 5117 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5118 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5119 | root->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5120 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5121 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5122 | std::unique_ptr<LayerImpl> child = |
| 5123 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5124 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5125 | child->SetDrawsContent(true); |
| 5126 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5127 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5128 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5129 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5130 | grand_child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5131 | grand_child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5132 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5133 | child->test_properties()->AddChild(std::move(grand_child)); |
| 5134 | root->test_properties()->AddChild(std::move(child)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5135 | root->SetHasRenderSurface(true); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5136 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5137 | |
| 5138 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5139 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5140 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5141 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5142 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5143 | |
| 5144 | // We should have one render surface and two layers. The grand child has |
| 5145 | // hidden itself. |
| 5146 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5147 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5148 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
| 5149 | EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5150 | } |
| 5151 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5152 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5153 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5154 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5155 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5156 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5157 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5158 | host_impl.CreatePendingTree(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5159 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5160 | std::unique_ptr<LayerImpl> root = |
| 5161 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5162 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5163 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5164 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5165 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5166 | std::unique_ptr<LayerImpl> child = |
| 5167 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5168 | child->SetBounds(gfx::Size(40, 40)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5169 | child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5170 | child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5171 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5172 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5173 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5174 | grand_child->SetBounds(gfx::Size(30, 30)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5175 | grand_child->SetDrawsContent(true); |
| 5176 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5177 | child->test_properties()->AddChild(std::move(grand_child)); |
| 5178 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5179 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5180 | |
| 5181 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5182 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5183 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5184 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5185 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5186 | |
| 5187 | // We should have one render surface and one layers. The child has |
| 5188 | // hidden itself and the grand child. |
| 5189 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5190 | ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size()); |
| 5191 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5192 | } |
| 5193 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5194 | void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5195 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5196 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5197 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5198 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5199 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5200 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5201 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5202 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5203 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5204 | std::unique_ptr<LayerImpl> root = |
| 5205 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5206 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5207 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5208 | LayerImpl* root_layer = root.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5209 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5210 | std::unique_ptr<LayerImpl> copy_grand_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5211 | LayerImpl::Create(host_impl.pending_tree(), 2); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5212 | copy_grand_parent->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5213 | copy_grand_parent->SetDrawsContent(true); |
| 5214 | LayerImpl* copy_grand_parent_layer = copy_grand_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5215 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5216 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5217 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5218 | copy_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5219 | copy_parent->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5220 | copy_parent->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5221 | LayerImpl* copy_parent_layer = copy_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5222 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5223 | std::unique_ptr<LayerImpl> copy_request = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5224 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5225 | copy_request->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5226 | copy_request->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5227 | copy_request->test_properties()->force_render_surface = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5228 | LayerImpl* copy_layer = copy_request.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5229 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5230 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5231 | LayerImpl::Create(host_impl.pending_tree(), 5); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5232 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5233 | copy_child->SetDrawsContent(true); |
| 5234 | LayerImpl* copy_child_layer = copy_child.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5235 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5236 | std::unique_ptr<LayerImpl> copy_grand_child = |
thakis | e53c527 | 2016-01-24 01:20:40 | [diff] [blame] | 5237 | LayerImpl::Create(host_impl.pending_tree(), 6); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5238 | copy_grand_child->SetBounds(gfx::Size(20, 20)); |
| 5239 | copy_grand_child->SetDrawsContent(true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5240 | LayerImpl* copy_grand_child_layer = copy_grand_child.get(); |
| 5241 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5242 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5243 | LayerImpl::Create(host_impl.pending_tree(), 7); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5244 | copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5245 | copy_grand_parent_sibling_before->SetDrawsContent(true); |
| 5246 | LayerImpl* copy_grand_parent_sibling_before_layer = |
| 5247 | copy_grand_parent_sibling_before.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5248 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5249 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5250 | LayerImpl::Create(host_impl.pending_tree(), 8); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5251 | copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5252 | copy_grand_parent_sibling_after->SetDrawsContent(true); |
| 5253 | LayerImpl* copy_grand_parent_sibling_after_layer = |
| 5254 | copy_grand_parent_sibling_after.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5255 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5256 | copy_child->test_properties()->AddChild(std::move(copy_grand_child)); |
| 5257 | copy_request->test_properties()->AddChild(std::move(copy_child)); |
| 5258 | copy_parent->test_properties()->AddChild(std::move(copy_request)); |
| 5259 | copy_grand_parent->test_properties()->AddChild(std::move(copy_parent)); |
| 5260 | root->test_properties()->AddChild( |
| 5261 | std::move(copy_grand_parent_sibling_before)); |
| 5262 | root->test_properties()->AddChild(std::move(copy_grand_parent)); |
| 5263 | root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5264 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5265 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5266 | // 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] | 5267 | // hidden subtree on copy_layer. Also hide the copy grand child and its |
| 5268 | // subtree. |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5269 | copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true; |
| 5270 | copy_grand_parent_sibling_before_layer->test_properties() |
| 5271 | ->hide_layer_and_subtree = true; |
| 5272 | copy_grand_parent_sibling_after_layer->test_properties() |
| 5273 | ->hide_layer_and_subtree = true; |
| 5274 | copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5275 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5276 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5277 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5278 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5279 | LayerImplList render_surface_layer_list; |
| 5280 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5281 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5282 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5283 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5284 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5285 | EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 5286 | EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5287 | EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5288 | EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5289 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5290 | // We should have four render surfaces, one for the root, one for the grand |
| 5291 | // parent since it has opacity and two drawing descendants, one for the parent |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5292 | // since it owns a surface, and one for the copy_layer. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5293 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5294 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5295 | EXPECT_EQ(copy_grand_parent_layer->id(), |
| 5296 | render_surface_layer_list.at(1)->id()); |
| 5297 | EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id()); |
| 5298 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5299 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5300 | // The root render surface should have 2 contributing layers. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5301 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5302 | EXPECT_EQ(root_layer->id(), |
| 5303 | root_layer->render_surface()->layer_list().at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5304 | EXPECT_EQ(copy_grand_parent_layer->id(), |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5305 | root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5306 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 5307 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5308 | // appear in its list, since it needs to be drawn for the copy request. |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5309 | ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5310 | EXPECT_EQ(copy_layer->id(), |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5311 | copy_parent_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5312 | |
| 5313 | // The copy_layer's render surface should have two contributing layers. |
| 5314 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 5315 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5316 | copy_layer->render_surface()->layer_list().at(0)->id()); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5317 | EXPECT_EQ(copy_child_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5318 | copy_layer->render_surface()->layer_list().at(1)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5319 | |
| 5320 | // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden, |
| 5321 | // but the copy_layer and copy_child should be drawn for the copy request. |
| 5322 | // copy grand child should not be drawn as its hidden even in the copy |
| 5323 | // request. |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 5324 | EffectTree& tree = |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5325 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5326 | EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5327 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5328 | node = tree.Node(copy_parent_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5329 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5330 | node = tree.Node(copy_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5331 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5332 | node = tree.Node(copy_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5333 | EXPECT_TRUE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5334 | node = tree.Node(copy_grand_child_layer->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 5335 | EXPECT_FALSE(node->is_drawn); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5336 | |
| 5337 | // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its |
| 5338 | // actually hidden. |
| 5339 | EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5340 | } |
| 5341 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5342 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5343 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5344 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5345 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5346 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5347 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5348 | host_impl.CreatePendingTree(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5349 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5350 | std::unique_ptr<LayerImpl> root = |
| 5351 | LayerImpl::Create(host_impl.pending_tree(), 1); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5352 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5353 | root->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5354 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5355 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5356 | LayerImpl::Create(host_impl.pending_tree(), 2); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5357 | copy_parent->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5358 | copy_parent->SetMasksToBounds(true); |
| 5359 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5360 | std::unique_ptr<LayerImpl> copy_layer = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5361 | LayerImpl::Create(host_impl.pending_tree(), 3); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5362 | copy_layer->SetBounds(gfx::Size(30, 30)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5363 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5364 | copy_layer->test_properties()->force_render_surface = true; |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5365 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5366 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5367 | LayerImpl::Create(host_impl.pending_tree(), 4); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5368 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5369 | copy_child->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5370 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5371 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5372 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5373 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5374 | copy_layer->test_properties()->AddChild(std::move(copy_child)); |
| 5375 | copy_parent->test_properties()->AddChild(std::move(copy_layer)); |
| 5376 | root->test_properties()->AddChild(std::move(copy_parent)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5377 | |
| 5378 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5379 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5380 | root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5381 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5382 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5383 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5384 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5385 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5386 | // We should have two render surface, as the others are clipped out. |
| 5387 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5388 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5389 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5390 | // The root render surface should only have 2 contributing layer, since the |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5391 | // other layers are empty/clipped away. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5392 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5393 | EXPECT_EQ(root_layer->id(), |
| 5394 | root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5395 | } |
| 5396 | |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5397 | TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5398 | LayerImpl* root = root_layer_for_testing(); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5399 | root->SetBounds(gfx::Size(50, 50)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5400 | root->SetDrawsContent(true); |
| 5401 | root->SetMasksToBounds(true); |
| 5402 | |
| 5403 | LayerImpl* copy_layer = AddChild<LayerImpl>(root); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5404 | copy_layer->SetBounds(gfx::Size(100, 100)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5405 | copy_layer->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5406 | copy_layer->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5407 | |
| 5408 | LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5409 | copy_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5410 | copy_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5411 | copy_child->SetDrawsContent(true); |
| 5412 | |
| 5413 | LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5414 | copy_clip->SetBounds(gfx::Size(55, 55)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5415 | copy_clip->SetMasksToBounds(true); |
| 5416 | |
| 5417 | LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5418 | copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f)); |
| 5419 | copy_clipped_child->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5420 | copy_clipped_child->SetDrawsContent(true); |
| 5421 | |
| 5422 | LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5423 | copy_surface->SetPosition(gfx::PointF(45.f, 45.f)); |
| 5424 | copy_surface->SetBounds(gfx::Size(20, 20)); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5425 | copy_surface->SetDrawsContent(true); |
danakj | e4fa7b7 | 2016-07-25 22:00:06 | [diff] [blame] | 5426 | copy_surface->test_properties()->force_render_surface = true; |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5427 | |
| 5428 | copy_layer->test_properties()->copy_requests.push_back( |
| 5429 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5430 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5431 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5432 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5433 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5434 | |
| 5435 | EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect()); |
| 5436 | EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect()); |
| 5437 | EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect()); |
| 5438 | EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect()); |
| 5439 | |
| 5440 | // Case 2: When the non root copy request layer is clipped. |
| 5441 | copy_layer->SetBounds(gfx::Size(50, 50)); |
| 5442 | copy_layer->SetMasksToBounds(true); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5443 | copy_layer->test_properties()->copy_requests.push_back( |
| 5444 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5445 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5446 | |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5447 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5448 | ExecuteCalculateDrawProperties(root); |
weiliangc | e22ce84 | 2016-07-04 23:31:53 | [diff] [blame] | 5449 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5450 | |
| 5451 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5452 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5453 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5454 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | 296dd9f | 2016-07-05 14:59:51 | [diff] [blame] | 5455 | |
| 5456 | // Case 3: When there is device scale factor. |
| 5457 | float device_scale_factor = 2.f; |
| 5458 | copy_layer->test_properties()->copy_requests.push_back( |
| 5459 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5460 | |
| 5461 | DCHECK(!copy_layer->test_properties()->copy_requests.empty()); |
| 5462 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 5463 | DCHECK(copy_layer->test_properties()->copy_requests.empty()); |
| 5464 | |
| 5465 | EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect()); |
| 5466 | EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect()); |
| 5467 | EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect()); |
| 5468 | EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect()); |
weiliangc | de7e0c3 | 2016-06-15 15:02:41 | [diff] [blame] | 5469 | } |
| 5470 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5471 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 5472 | // Ensure that a transform between the layer and its render surface is not a |
| 5473 | // problem. Constructs the following layer tree. |
| 5474 | // |
| 5475 | // root (a render surface) |
| 5476 | // + render_surface |
| 5477 | // + clip_parent (scaled) |
| 5478 | // + intervening_clipping_layer |
| 5479 | // + clip_child |
| 5480 | // |
| 5481 | // The render surface should be resized correctly and the clip child should |
| 5482 | // inherit the right clip rect. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5483 | LayerImpl* root = root_layer_for_testing(); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5484 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 5485 | LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5486 | clip_parent->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5487 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5488 | intervening->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5489 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5490 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5491 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5492 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5493 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5494 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5495 | |
| 5496 | intervening->SetMasksToBounds(true); |
| 5497 | clip_parent->SetMasksToBounds(true); |
| 5498 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5499 | gfx::Transform scale_transform; |
| 5500 | scale_transform.Scale(2, 2); |
| 5501 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5502 | root->SetBounds(gfx::Size(50, 50)); |
| 5503 | render_surface->SetBounds(gfx::Size(10, 10)); |
| 5504 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5505 | clip_parent->test_properties()->transform = scale_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5506 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5507 | clip_parent->SetBounds(gfx::Size(10, 10)); |
| 5508 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5509 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5510 | clip_child->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5511 | clip_child->SetBounds(gfx::Size(10, 10)); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5512 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5513 | |
| 5514 | ASSERT_TRUE(root->render_surface()); |
| 5515 | ASSERT_TRUE(render_surface->render_surface()); |
| 5516 | |
| 5517 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 5518 | // by the intervening clip layer. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5519 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect()); |
| 5520 | ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect()); |
| 5521 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5522 | |
| 5523 | // Ensure that the render surface reports a content rect that has been grown |
| 5524 | // to accomodate for the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5525 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), |
| 5526 | render_surface->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5527 | |
| 5528 | // The above check implies the two below, but they nicely demonstrate that |
| 5529 | // we've grown, despite the intervening layer's clip. |
| 5530 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 5531 | render_surface->render_surface()->content_rect())); |
| 5532 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 5533 | render_surface->render_surface()->content_rect())); |
| 5534 | } |
| 5535 | |
| 5536 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 5537 | // Ensure that intervening render surfaces are not a problem in the basic |
| 5538 | // case. In the following tree, both render surfaces should be resized to |
| 5539 | // accomodate for the clip child, despite an intervening clip. |
| 5540 | // |
| 5541 | // root (a render surface) |
| 5542 | // + clip_parent (masks to bounds) |
| 5543 | // + render_surface1 (sets opacity) |
| 5544 | // + intervening (masks to bounds) |
| 5545 | // + render_surface2 (also sets opacity) |
| 5546 | // + clip_child |
| 5547 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5548 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5549 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5550 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5551 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5552 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5553 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5554 | render_surface1->SetDrawsContent(true); |
| 5555 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5556 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5557 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5558 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5559 | |
| 5560 | intervening->SetMasksToBounds(true); |
| 5561 | clip_parent->SetMasksToBounds(true); |
| 5562 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5563 | gfx::Transform translation_transform; |
| 5564 | translation_transform.Translate(2, 2); |
| 5565 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5566 | root->SetBounds(gfx::Size(50, 50)); |
| 5567 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5568 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5569 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5570 | render_surface1->test_properties()->force_render_surface = true; |
| 5571 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5572 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5573 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5574 | render_surface2->test_properties()->force_render_surface = true; |
| 5575 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5576 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5577 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5578 | |
| 5579 | EXPECT_TRUE(root->render_surface()); |
| 5580 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5581 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5582 | |
| 5583 | // Since the render surfaces could have expanded, they should not clip (their |
| 5584 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5585 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5586 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5587 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5588 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5589 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5590 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5591 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5592 | |
| 5593 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5594 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5595 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5596 | |
| 5597 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5598 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5599 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5600 | |
| 5601 | // The content rects of both render surfaces should both have expanded to |
| 5602 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5603 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5604 | render_surface1->render_surface()->content_rect()); |
| 5605 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), |
| 5606 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5607 | |
| 5608 | // The clip child should have inherited the clip parent's clip (projected to |
| 5609 | // the right space, of course), and should have the correctly sized visible |
| 5610 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5611 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect()); |
| 5612 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5613 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5614 | } |
| 5615 | |
| 5616 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 5617 | // Ensure that intervening render surfaces are not a problem, even if there |
| 5618 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 5619 | // of transform. |
| 5620 | // |
| 5621 | // root (a render surface) |
| 5622 | // + clip_parent (masks to bounds) |
| 5623 | // + render_surface1 (sets opacity) |
| 5624 | // + intervening (masks to bounds AND scrolls) |
| 5625 | // + render_surface2 (also sets opacity) |
| 5626 | // + clip_child |
| 5627 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5628 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5629 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5630 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5631 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5632 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5633 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5634 | render_surface1->SetDrawsContent(true); |
| 5635 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5636 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5637 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5638 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5639 | |
| 5640 | intervening->SetMasksToBounds(true); |
| 5641 | clip_parent->SetMasksToBounds(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5642 | intervening->SetScrollClipLayer(clip_parent->id()); |
| 5643 | intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5644 | |
| 5645 | gfx::Transform translation_transform; |
| 5646 | translation_transform.Translate(2, 2); |
| 5647 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5648 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5649 | clip_parent->test_properties()->transform = translation_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5650 | clip_parent->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5651 | clip_parent->SetBounds(gfx::Size(40, 40)); |
| 5652 | render_surface1->SetBounds(gfx::Size(10, 10)); |
| 5653 | render_surface1->test_properties()->force_render_surface = true; |
| 5654 | intervening->SetPosition(gfx::PointF(1.f, 1.f)); |
| 5655 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5656 | render_surface2->SetBounds(gfx::Size(10, 10)); |
| 5657 | render_surface2->test_properties()->force_render_surface = true; |
| 5658 | clip_child->SetPosition(gfx::PointF(-10.f, -10.f)); |
| 5659 | clip_child->SetBounds(gfx::Size(60, 60)); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5660 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5661 | |
| 5662 | EXPECT_TRUE(root->render_surface()); |
| 5663 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5664 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5665 | |
| 5666 | // Since the render surfaces could have expanded, they should not clip (their |
| 5667 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5668 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5669 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5670 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5671 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5672 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5673 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5674 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5675 | |
| 5676 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5677 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5678 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5679 | |
| 5680 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5681 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5682 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5683 | |
| 5684 | // The content rects of both render surfaces should both have expanded to |
| 5685 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5686 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5687 | render_surface1->render_surface()->content_rect()); |
| 5688 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), |
| 5689 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5690 | |
| 5691 | // The clip child should have inherited the clip parent's clip (projected to |
| 5692 | // the right space, of course), and should have the correctly sized visible |
| 5693 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5694 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect()); |
| 5695 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5696 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5697 | } |
| 5698 | |
| 5699 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 5700 | // Ensures that descendants of the clip child inherit the correct clip. |
| 5701 | // |
| 5702 | // root (a render surface) |
| 5703 | // + clip_parent (masks to bounds) |
| 5704 | // + intervening (masks to bounds) |
| 5705 | // + clip_child |
| 5706 | // + child |
| 5707 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5708 | LayerImpl* root = root_layer_for_testing(); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5709 | LayerImpl* clip_parent = AddChild<LayerImpl>(root); |
| 5710 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
| 5711 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5712 | LayerImpl* child = AddChild<LayerImpl>(clip_child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5713 | clip_child->SetDrawsContent(true); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5714 | child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5715 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5716 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5717 | clip_parent->test_properties()->clip_children = |
| 5718 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5719 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5720 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5721 | root->SetBounds(gfx::Size(50, 50)); |
| 5722 | clip_parent->SetBounds(gfx::Size(40, 40)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5723 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5724 | intervening->SetBounds(gfx::Size(5, 5)); |
| 5725 | intervening->SetMasksToBounds(true); |
| 5726 | clip_child->SetBounds(gfx::Size(60, 60)); |
| 5727 | child->SetBounds(gfx::Size(60, 60)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5728 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5729 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5730 | |
| 5731 | EXPECT_TRUE(root->render_surface()); |
| 5732 | |
| 5733 | // Neither the clip child nor its descendant should have inherited the clip |
| 5734 | // from |intervening|. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5735 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5736 | EXPECT_TRUE(clip_child->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5737 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5738 | EXPECT_TRUE(child->is_clipped()); |
| 5739 | } |
| 5740 | |
| 5741 | TEST_F(LayerTreeHostCommonTest, |
| 5742 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 5743 | // Ensures that non-descendant clip children in the tree do not affect |
| 5744 | // render surfaces. |
| 5745 | // |
| 5746 | // root (a render surface) |
| 5747 | // + clip_parent (masks to bounds) |
| 5748 | // + render_surface1 |
| 5749 | // + clip_child |
| 5750 | // + render_surface2 |
| 5751 | // + non_clip_child |
| 5752 | // |
| 5753 | // In this example render_surface2 should be unaffected by clip_child. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5754 | LayerImpl* root = root_layer_for_testing(); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5755 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5756 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5757 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5758 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent); |
| 5759 | LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5760 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5761 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5762 | clip_parent->test_properties()->clip_children = |
| 5763 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 5764 | clip_parent->test_properties()->clip_children->insert(clip_child); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5765 | |
| 5766 | clip_parent->SetMasksToBounds(true); |
| 5767 | render_surface1->SetMasksToBounds(true); |
| 5768 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5769 | render_surface1->SetDrawsContent(true); |
| 5770 | clip_child->SetDrawsContent(true); |
| 5771 | render_surface2->SetDrawsContent(true); |
| 5772 | non_clip_child->SetDrawsContent(true); |
| 5773 | |
| 5774 | root->SetBounds(gfx::Size(15, 15)); |
| 5775 | clip_parent->SetBounds(gfx::Size(10, 10)); |
| 5776 | render_surface1->SetPosition(gfx::PointF(5, 5)); |
| 5777 | render_surface1->SetBounds(gfx::Size(5, 5)); |
| 5778 | render_surface1->test_properties()->force_render_surface = true; |
| 5779 | render_surface2->SetBounds(gfx::Size(5, 5)); |
| 5780 | render_surface2->test_properties()->force_render_surface = true; |
| 5781 | clip_child->SetPosition(gfx::PointF(-1, 1)); |
| 5782 | clip_child->SetBounds(gfx::Size(10, 10)); |
| 5783 | non_clip_child->SetBounds(gfx::Size(5, 5)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5784 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 5785 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5786 | |
| 5787 | EXPECT_TRUE(root->render_surface()); |
| 5788 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5789 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5790 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5791 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5792 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5793 | |
| 5794 | // The render surface should not clip (it has unclipped descendants), instead |
| 5795 | // it should rely on layer clipping. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5796 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5797 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5798 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 5799 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5800 | // That said, it should have grown to accomodate the unclipped descendant and |
| 5801 | // its own size. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5802 | EXPECT_EQ(gfx::Rect(-1, 0, 6, 5), |
| 5803 | render_surface1->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5804 | |
| 5805 | // This render surface should clip. It has no unclipped descendants. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5806 | EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 5807 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5808 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 5809 | EXPECT_FALSE(render_surface2->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5810 | |
| 5811 | // It also shouldn't have grown to accomodate the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5812 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), |
| 5813 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5814 | |
| 5815 | // Sanity check our num_unclipped_descendants values. |
ajuma | 0641ded | 2016-05-05 21:28:21 | [diff] [blame] | 5816 | EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants); |
| 5817 | EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5818 | } |
| 5819 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5820 | TEST_F(LayerTreeHostCommonTest, |
| 5821 | CreateRenderSurfaceWhenFlattenInsideRenderingContext) { |
| 5822 | // Verifies that Render Surfaces are created at the edge of rendering context. |
| 5823 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5824 | LayerImpl* root = root_layer_for_testing(); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5825 | LayerImpl* child1 = AddChildToRoot<LayerImpl>(); |
| 5826 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 5827 | LayerImpl* child3 = AddChild<LayerImpl>(child2); |
| 5828 | root->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5829 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5830 | gfx::Size bounds(100, 100); |
| 5831 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5832 | root->SetBounds(bounds); |
| 5833 | child1->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5834 | child1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5835 | child1->Set3dSortingContextId(1); |
| 5836 | child1->test_properties()->should_flatten_transform = false; |
| 5837 | child2->SetBounds(bounds); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5838 | child2->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5839 | child2->Set3dSortingContextId(1); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5840 | child3->SetBounds(bounds); |
| 5841 | child3->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5842 | child3->Set3dSortingContextId(1); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 5843 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 5844 | |
| 5845 | // Verify which render surfaces were created. |
| 5846 | EXPECT_TRUE(root->has_render_surface()); |
| 5847 | EXPECT_FALSE(child1->has_render_surface()); |
| 5848 | EXPECT_TRUE(child2->has_render_surface()); |
| 5849 | EXPECT_FALSE(child3->has_render_surface()); |
| 5850 | } |
| 5851 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5852 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5853 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5854 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5855 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5856 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5857 | &task_graph_runner); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 5858 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5859 | std::unique_ptr<LayerImpl> root = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5860 | LayerImpl::Create(host_impl.active_tree(), 12345); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5861 | std::unique_ptr<LayerImpl> child1 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5862 | LayerImpl::Create(host_impl.active_tree(), 123456); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5863 | std::unique_ptr<LayerImpl> child2 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5864 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5865 | std::unique_ptr<LayerImpl> child3 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5866 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 5867 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5868 | gfx::Size bounds(100, 100); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5869 | |
| 5870 | root->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5871 | root->SetDrawsContent(true); |
| 5872 | |
| 5873 | // This layer structure normally forces render surface due to preserves3d |
| 5874 | // behavior. |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5875 | child1->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5876 | child1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5877 | child1->Set3dSortingContextId(1); |
| 5878 | child1->test_properties()->should_flatten_transform = false; |
| 5879 | child2->SetBounds(bounds); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5880 | child2->SetDrawsContent(true); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 5881 | child2->Set3dSortingContextId(1); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5882 | child3->SetBounds(bounds); |
| 5883 | child3->SetDrawsContent(true); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 5884 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5885 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5886 | child2->test_properties()->AddChild(std::move(child3)); |
| 5887 | child1->test_properties()->AddChild(std::move(child2)); |
| 5888 | root->test_properties()->AddChild(std::move(child1)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5889 | LayerImpl* root_layer = root.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5890 | root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root)); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5891 | |
| 5892 | { |
| 5893 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5894 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5895 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5896 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5897 | inputs.can_render_to_separate_surface = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5898 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5899 | |
| 5900 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5901 | |
| 5902 | int count_represents_target_render_surface = 0; |
| 5903 | int count_represents_contributing_render_surface = 0; |
| 5904 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 5905 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 5906 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5907 | it != end; ++it) { |
| 5908 | if (it.represents_target_render_surface()) |
| 5909 | count_represents_target_render_surface++; |
| 5910 | if (it.represents_contributing_render_surface()) |
| 5911 | count_represents_contributing_render_surface++; |
| 5912 | if (it.represents_itself()) |
| 5913 | count_represents_itself++; |
| 5914 | } |
| 5915 | |
| 5916 | // Two render surfaces. |
| 5917 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 5918 | // Second render surface contributes to root render surface. |
| 5919 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 5920 | // All 4 layers represent itself. |
| 5921 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5922 | } |
| 5923 | |
| 5924 | { |
| 5925 | LayerImplList render_surface_layer_list; |
| 5926 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5927 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5928 | inputs.can_render_to_separate_surface = false; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5929 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5930 | |
| 5931 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5932 | |
| 5933 | int count_represents_target_render_surface = 0; |
| 5934 | int count_represents_contributing_render_surface = 0; |
| 5935 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 5936 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 5937 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 5938 | it != end; ++it) { |
| 5939 | if (it.represents_target_render_surface()) |
| 5940 | count_represents_target_render_surface++; |
| 5941 | if (it.represents_contributing_render_surface()) |
| 5942 | count_represents_contributing_render_surface++; |
| 5943 | if (it.represents_itself()) |
| 5944 | count_represents_itself++; |
| 5945 | } |
| 5946 | |
| 5947 | // Only root layer has a render surface. |
| 5948 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 5949 | // No layer contributes a render surface to root render surface. |
| 5950 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 5951 | // All 4 layers represent itself. |
| 5952 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 5953 | } |
| 5954 | } |
| 5955 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5956 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5957 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5958 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 5959 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 5960 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 5961 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 5962 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5963 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5964 | child1->SetDrawsContent(true); |
| 5965 | child2->SetDrawsContent(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5966 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5967 | root->SetBounds(gfx::Size(50, 50)); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 5968 | root->Set3dSortingContextId(1); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5969 | root->test_properties()->should_flatten_transform = false; |
| 5970 | back_facing->SetBounds(gfx::Size(50, 50)); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5971 | back_facing->Set3dSortingContextId(1); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 5972 | back_facing->test_properties()->should_flatten_transform = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5973 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 5974 | render_surface1->Set3dSortingContextId(1); |
| 5975 | render_surface1->test_properties()->should_flatten_transform = false; |
| 5976 | render_surface1->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5977 | render_surface1->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5978 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 5979 | // Different context from the rest. |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5980 | render_surface2->Set3dSortingContextId(2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5981 | render_surface2->test_properties()->should_flatten_transform = false; |
| 5982 | render_surface2->test_properties()->force_render_surface = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5983 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 5984 | child1->SetBounds(gfx::Size(20, 20)); |
| 5985 | child2->SetBounds(gfx::Size(20, 20)); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5986 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5987 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 5988 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 5989 | EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id()); |
| 5990 | EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id()); |
| 5991 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 5992 | EXPECT_EQ(2u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 5993 | ->at(0) |
| 5994 | ->render_surface() |
| 5995 | ->layer_list() |
| 5996 | .size()); |
| 5997 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
| 5998 | ->at(1) |
| 5999 | ->render_surface() |
| 6000 | ->layer_list() |
| 6001 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6002 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6003 | gfx::Transform rotation_transform; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6004 | rotation_transform.RotateAboutXAxis(180.0); |
| 6005 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6006 | back_facing->test_properties()->transform = rotation_transform; |
jaydasika | 5aa88b8 | 2015-11-10 01:48:03 | [diff] [blame] | 6007 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6008 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6009 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6010 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6011 | // render_surface1 is in the same 3d rendering context as back_facing and is |
| 6012 | // not double sided, so it should not be in RSLL. render_surface2 is also not |
| 6013 | // double-sided, but will still be in RSLL as it's in a different 3d rendering |
| 6014 | // context. |
| 6015 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
| 6016 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6017 | ->at(0) |
| 6018 | ->render_surface() |
| 6019 | ->layer_list() |
| 6020 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6021 | } |
| 6022 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6023 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6024 | LayerImpl* root = root_layer_for_testing(); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6025 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 6026 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6027 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6028 | root->SetBounds(gfx::Size(50, 50)); |
| 6029 | root->test_properties()->should_flatten_transform = false; |
| 6030 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6031 | child->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6032 | child->test_properties()->should_flatten_transform = false; |
| 6033 | grand_child->SetBounds(gfx::Size(20, 20)); |
| 6034 | grand_child->SetDrawsContent(true); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6035 | grand_child->SetUseParentBackfaceVisibility(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6036 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6037 | ExecuteCalculateDrawProperties(root); |
| 6038 | |
| 6039 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6040 | EXPECT_EQ(grand_child, render_surface_layer_list_impl() |
| 6041 | ->at(0) |
| 6042 | ->render_surface() |
| 6043 | ->layer_list()[0]); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6044 | |
| 6045 | // As all layers have identity transform, we shouldn't check for backface |
| 6046 | // visibility. |
| 6047 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6048 | EXPECT_FALSE(child->should_check_backface_visibility()); |
| 6049 | EXPECT_FALSE(grand_child->should_check_backface_visibility()); |
| 6050 | // As there are no 3d rendering contexts, all layers should use their local |
| 6051 | // transform for backface visibility. |
| 6052 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6053 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6054 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6055 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6056 | gfx::Transform rotation_transform; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6057 | rotation_transform.RotateAboutXAxis(180.0); |
| 6058 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6059 | child->test_properties()->transform = rotation_transform; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6060 | child->Set3dSortingContextId(1); |
| 6061 | grand_child->Set3dSortingContextId(1); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6062 | child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6063 | |
| 6064 | ExecuteCalculateDrawProperties(root); |
| 6065 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6066 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6067 | ->at(0) |
| 6068 | ->render_surface() |
| 6069 | ->layer_list() |
| 6070 | .size()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6071 | |
| 6072 | // We should check for backface visibilty of child as it has a rotation |
| 6073 | // transform. We should also check for grand_child as it uses the backface |
| 6074 | // visibility of its parent. |
| 6075 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6076 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6077 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6078 | // child uses its local transform for backface visibility as it is the root of |
| 6079 | // a 3d rendering context. grand_child is in a 3d rendering context and is not |
| 6080 | // the root, but it derives its backface visibility from its parent which uses |
| 6081 | // its local transform. |
| 6082 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6083 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6084 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6085 | |
| 6086 | grand_child->SetUseParentBackfaceVisibility(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6087 | grand_child->test_properties()->double_sided = false; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6088 | grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6089 | |
| 6090 | ExecuteCalculateDrawProperties(root); |
| 6091 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6092 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6093 | ->at(0) |
| 6094 | ->render_surface() |
| 6095 | ->layer_list() |
| 6096 | .size()); |
| 6097 | |
| 6098 | // We should check the backface visibility of child as it has a rotation |
| 6099 | // transform and for grand_child as it is in a 3d rendering context and not |
| 6100 | // the root of it. |
| 6101 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6102 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6103 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6104 | // grand_child is in an existing 3d rendering context, so it should not use |
| 6105 | // local transform for backface visibility. |
| 6106 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6107 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6108 | EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility()); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6109 | } |
| 6110 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6111 | TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6112 | LayerImpl* root = root_layer_for_testing(); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6113 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6114 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6115 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6116 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6117 | gfx::Transform rotate_about_y; |
| 6118 | rotate_about_y.RotateAboutYAxis(180.0); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6119 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6120 | root->SetBounds(gfx::Size(50, 50)); |
| 6121 | root->Set3dSortingContextId(1); |
| 6122 | root->test_properties()->should_flatten_transform = false; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6123 | back_facing->test_properties()->transform = rotate_about_y; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6124 | back_facing->SetBounds(gfx::Size(50, 50)); |
| 6125 | back_facing->Set3dSortingContextId(1); |
| 6126 | back_facing->test_properties()->should_flatten_transform = false; |
| 6127 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 6128 | render_surface1->Set3dSortingContextId(1); |
| 6129 | render_surface1->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6130 | render_surface1->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6131 | render_surface1->test_properties()->force_render_surface = true; |
| 6132 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 6133 | render_surface2->Set3dSortingContextId(1); |
| 6134 | render_surface2->test_properties()->should_flatten_transform = false; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6135 | render_surface2->test_properties()->double_sided = false; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6136 | render_surface2->test_properties()->force_render_surface = true; |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6137 | ExecuteCalculateDrawProperties(root); |
| 6138 | |
| 6139 | const EffectTree& tree = |
| 6140 | root->layer_tree_impl()->property_trees()->effect_tree; |
| 6141 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6142 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6143 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6144 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6145 | |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 6146 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6147 | gfx::Transform(), back_facing->transform_tree_index(), |
| 6148 | root->layer_tree_impl()); |
| 6149 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6150 | rotate_about_y, render_surface2->transform_tree_index(), |
| 6151 | root->layer_tree_impl()); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6152 | ExecuteCalculateDrawProperties(root); |
| 6153 | EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6154 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6155 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6156 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6157 | |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 6158 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 6159 | rotate_about_y, render_surface1->transform_tree_index(), |
| 6160 | root->layer_tree_impl()); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6161 | ExecuteCalculateDrawProperties(root); |
| 6162 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6163 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6164 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 6165 | ->hidden_by_backface_visibility); |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6166 | } |
| 6167 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6168 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 6169 | // Checks that the simple case (being clipped by a scroll parent that would |
| 6170 | // have been processed before you anyhow) results in the right clips. |
| 6171 | // |
| 6172 | // + root |
| 6173 | // + scroll_parent_border |
| 6174 | // | + scroll_parent_clip |
| 6175 | // | + scroll_parent |
| 6176 | // + scroll_child |
| 6177 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6178 | LayerImpl* root = root_layer_for_testing(); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6179 | LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>(); |
| 6180 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6181 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6182 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6183 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6184 | scroll_parent->SetDrawsContent(true); |
| 6185 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6186 | scroll_parent_clip->SetMasksToBounds(true); |
| 6187 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6188 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6189 | scroll_parent->test_properties()->scroll_children = |
| 6190 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6191 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6192 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6193 | root->SetBounds(gfx::Size(50, 50)); |
| 6194 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6195 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6196 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6197 | scroll_child->SetBounds(gfx::Size(50, 50)); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6198 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6199 | |
| 6200 | EXPECT_TRUE(root->render_surface()); |
| 6201 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6202 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6203 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6204 | } |
| 6205 | |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6206 | TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) { |
| 6207 | // Tests the computation of draw transform for the scroll child when its |
| 6208 | // target is different from its scroll parent's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6209 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6210 | LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); |
| 6211 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); |
| 6212 | LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target); |
| 6213 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); |
| 6214 | |
| 6215 | scroll_parent->SetDrawsContent(true); |
| 6216 | scroll_child->SetDrawsContent(true); |
| 6217 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6218 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6219 | scroll_parent->test_properties()->scroll_children = |
| 6220 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6221 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6222 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6223 | root->SetBounds(gfx::Size(50, 50)); |
| 6224 | scroll_child_target->SetBounds(gfx::Size(50, 50)); |
| 6225 | scroll_child_target->test_properties()->force_render_surface = true; |
| 6226 | scroll_child->SetBounds(gfx::Size(50, 50)); |
| 6227 | scroll_parent_target->SetPosition(gfx::PointF(10, 10)); |
| 6228 | scroll_parent_target->SetBounds(gfx::Size(50, 50)); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6229 | scroll_parent_target->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6230 | scroll_parent_target->test_properties()->force_render_surface = true; |
| 6231 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6232 | |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6233 | float device_scale_factor = 1.5f; |
| 6234 | LayerImplList render_surface_layer_list_impl; |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 6235 | gfx::Size device_viewport_size = |
| 6236 | gfx::Size(root->bounds().width() * device_scale_factor, |
| 6237 | root->bounds().height() * device_scale_factor); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6238 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 6239 | root, device_viewport_size, gfx::Transform(), |
| 6240 | &render_surface_layer_list_impl); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6241 | inputs.device_scale_factor = device_scale_factor; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6242 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6243 | |
weiliangc | 1da3fb89 | 2016-03-14 20:23:52 | [diff] [blame] | 6244 | EXPECT_EQ(scroll_child->effect_tree_index(), |
| 6245 | scroll_child_target->effect_tree_index()); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6246 | EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); |
| 6247 | EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); |
| 6248 | gfx::Transform scale; |
| 6249 | scale.Scale(1.5f, 1.5f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6250 | EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6251 | } |
| 6252 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6253 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6254 | LayerImpl* root = root_layer_for_testing(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6255 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6256 | LayerImpl* child = AddChild<LayerImpl>(parent); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6257 | |
| 6258 | root->SetBounds(gfx::Size(50, 50)); |
| 6259 | root->SetDrawsContent(true); |
| 6260 | root->Set3dSortingContextId(1); |
| 6261 | parent->SetBounds(gfx::Size(30, 30)); |
| 6262 | parent->SetDrawsContent(true); |
| 6263 | parent->Set3dSortingContextId(1); |
| 6264 | parent->test_properties()->force_render_surface = true; |
| 6265 | child->SetBounds(gfx::Size(20, 20)); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6266 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6267 | child->Set3dSortingContextId(1); |
| 6268 | child->test_properties()->force_render_surface = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6269 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6270 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6271 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6272 | |
| 6273 | gfx::Transform singular_transform; |
| 6274 | singular_transform.Scale3d( |
| 6275 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 6276 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6277 | child->test_properties()->transform = singular_transform; |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6278 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6279 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6280 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6281 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6282 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6283 | |
| 6284 | // Ensure that the entire subtree under a layer with singular transform does |
| 6285 | // not get rendered. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6286 | parent->test_properties()->transform = singular_transform; |
| 6287 | child->test_properties()->transform = gfx::Transform(); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6288 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6289 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6290 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6291 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6292 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6293 | } |
| 6294 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6295 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 6296 | // Checks that clipping by a scroll parent that follows you in paint order |
| 6297 | // still results in correct clipping. |
| 6298 | // |
| 6299 | // + root |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6300 | // + scroll_parent_border |
| 6301 | // + scroll_parent_clip |
| 6302 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6303 | // + scroll_child |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6304 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6305 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6306 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6307 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6308 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6309 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6310 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6311 | scroll_parent->SetDrawsContent(true); |
| 6312 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6313 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6314 | root->SetBounds(gfx::Size(50, 50)); |
| 6315 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6316 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6317 | scroll_parent_clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6318 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6319 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6320 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6321 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6322 | scroll_parent->test_properties()->scroll_children = |
| 6323 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6324 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6325 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6326 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6327 | |
| 6328 | EXPECT_TRUE(root->render_surface()); |
| 6329 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6330 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6331 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6332 | } |
| 6333 | |
| 6334 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 6335 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 6336 | // you in paint order still results in correct clipping. |
| 6337 | // |
| 6338 | // + root |
| 6339 | // + scroll_child |
| 6340 | // + scroll_parent_border |
| 6341 | // | + scroll_parent_clip |
| 6342 | // | + scroll_parent |
| 6343 | // + scroll_grandparent_border |
| 6344 | // + scroll_grandparent_clip |
| 6345 | // + scroll_grandparent |
| 6346 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6347 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6348 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6349 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6350 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6351 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6352 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6353 | LayerImpl* scroll_grandparent_clip = |
| 6354 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6355 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6356 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6357 | scroll_parent->SetDrawsContent(true); |
| 6358 | scroll_grandparent->SetDrawsContent(true); |
| 6359 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6360 | |
| 6361 | scroll_parent_clip->SetMasksToBounds(true); |
| 6362 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6363 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6364 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6365 | scroll_parent->test_properties()->scroll_children = |
| 6366 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6367 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6368 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6369 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6370 | scroll_grandparent->test_properties()->scroll_children = |
| 6371 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6372 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 6373 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6374 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6375 | root->SetBounds(gfx::Size(50, 50)); |
| 6376 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 6377 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 6378 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 6379 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6380 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6381 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6382 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6383 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6384 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6385 | |
| 6386 | EXPECT_TRUE(root->render_surface()); |
| 6387 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6388 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6389 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6390 | |
| 6391 | // Despite the fact that we visited the above layers out of order to get the |
| 6392 | // correct clip, the layer lists should be unaffected. |
| 6393 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6394 | EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0)); |
| 6395 | EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1)); |
| 6396 | EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6397 | } |
| 6398 | |
| 6399 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 6400 | // 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] | 6401 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6402 | // + root |
| 6403 | // + scroll_child |
| 6404 | // + scroll_parent_border |
| 6405 | // + scroll_parent_clip |
| 6406 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6407 | // + render_surface2 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6408 | // + scroll_grandparent_border |
| 6409 | // + scroll_grandparent_clip |
| 6410 | // + scroll_grandparent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6411 | // + render_surface1 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6412 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6413 | LayerImpl* root = root_layer_for_testing(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6414 | root->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6415 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6416 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6417 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6418 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6419 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6420 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6421 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6422 | LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent); |
| 6423 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6424 | LayerImpl* scroll_grandparent_clip = |
| 6425 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6426 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
| 6427 | LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6428 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6429 | scroll_parent->SetDrawsContent(true); |
| 6430 | render_surface1->SetDrawsContent(true); |
| 6431 | scroll_grandparent->SetDrawsContent(true); |
| 6432 | render_surface2->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6433 | |
| 6434 | scroll_parent_clip->SetMasksToBounds(true); |
| 6435 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6436 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6437 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6438 | scroll_parent->test_properties()->scroll_children = |
| 6439 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6440 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6441 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6442 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6443 | scroll_grandparent->test_properties()->scroll_children = |
| 6444 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 6445 | scroll_grandparent->test_properties()->scroll_children->insert( |
| 6446 | scroll_parent_border); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6447 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6448 | root->SetBounds(gfx::Size(50, 50)); |
| 6449 | scroll_grandparent_border->SetBounds(gfx::Size(40, 40)); |
| 6450 | scroll_grandparent_clip->SetBounds(gfx::Size(20, 20)); |
| 6451 | scroll_grandparent->SetBounds(gfx::Size(50, 50)); |
| 6452 | render_surface1->SetBounds(gfx::Size(50, 50)); |
| 6453 | render_surface1->test_properties()->force_render_surface = true; |
| 6454 | scroll_parent_border->SetBounds(gfx::Size(40, 40)); |
| 6455 | scroll_parent_clip->SetBounds(gfx::Size(30, 30)); |
| 6456 | scroll_parent->SetBounds(gfx::Size(50, 50)); |
| 6457 | render_surface2->SetBounds(gfx::Size(50, 50)); |
| 6458 | render_surface2->test_properties()->force_render_surface = true; |
| 6459 | scroll_child->SetBounds(gfx::Size(50, 50)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6460 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6461 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6462 | |
| 6463 | EXPECT_TRUE(root->render_surface()); |
| 6464 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6465 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6466 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6467 | |
| 6468 | // Despite the fact that we had to process the layers out of order to get the |
| 6469 | // right clip, our render_surface_layer_list's order should be unaffected. |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6470 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6471 | EXPECT_EQ(root, render_surface_layer_list_impl()->at(0)); |
| 6472 | EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1)); |
| 6473 | EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2)); |
| 6474 | EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface()); |
| 6475 | EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface()); |
| 6476 | EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6477 | } |
| 6478 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6479 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 6480 | // Ensures that when we have a render surface between a fixed position layer |
| 6481 | // and its container, we compute the fixed position layer's draw transform |
| 6482 | // with respect to that intervening render surface, not with respect to its |
| 6483 | // container's render target. |
| 6484 | // |
| 6485 | // + root |
| 6486 | // + render_surface |
| 6487 | // + fixed |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6488 | // + child |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6489 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6490 | LayerImpl* root = root_layer_for_testing(); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6491 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 6492 | LayerImpl* fixed = AddChild<LayerImpl>(render_surface); |
| 6493 | LayerImpl* child = AddChild<LayerImpl>(fixed); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6494 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6495 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6496 | root->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6497 | |
| 6498 | LayerPositionConstraint constraint; |
| 6499 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6500 | fixed->test_properties()->position_constraint = constraint; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6501 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6502 | root->SetBounds(gfx::Size(50, 50)); |
| 6503 | render_surface->SetPosition(gfx::PointF(7.f, 9.f)); |
| 6504 | render_surface->SetBounds(gfx::Size(50, 50)); |
| 6505 | render_surface->SetDrawsContent(true); |
| 6506 | fixed->SetPosition(gfx::PointF(10.f, 15.f)); |
| 6507 | fixed->SetBounds(gfx::Size(50, 50)); |
| 6508 | fixed->SetDrawsContent(true); |
| 6509 | child->SetPosition(gfx::PointF(1.f, 2.f)); |
| 6510 | child->SetBounds(gfx::Size(50, 50)); |
| 6511 | child->SetDrawsContent(true); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6512 | ExecuteCalculateDrawProperties(root); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6513 | |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6514 | TransformTree& transform_tree = |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6515 | host_impl()->active_tree()->property_trees()->transform_tree; |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6516 | EffectTree& effect_tree = |
| 6517 | host_impl()->active_tree()->property_trees()->effect_tree; |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6518 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6519 | gfx::Transform expected_fixed_draw_transform; |
| 6520 | expected_fixed_draw_transform.Translate(10.f, 15.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6521 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6522 | expected_fixed_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6523 | draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6524 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6525 | gfx::Transform expected_fixed_screen_space_transform; |
| 6526 | expected_fixed_screen_space_transform.Translate(17.f, 24.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6527 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6528 | expected_fixed_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6529 | draw_property_utils::ScreenSpaceTransform(fixed, transform_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6530 | |
| 6531 | gfx::Transform expected_child_draw_transform; |
| 6532 | expected_child_draw_transform.Translate(11.f, 17.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6533 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6534 | expected_child_draw_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6535 | draw_property_utils::DrawTransform(child, transform_tree, effect_tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6536 | |
| 6537 | gfx::Transform expected_child_screen_space_transform; |
| 6538 | expected_child_screen_space_transform.Translate(18.f, 26.f); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 6539 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6540 | expected_child_screen_space_transform, |
jaydasika | baede2d9 | 2016-07-20 00:34:32 | [diff] [blame] | 6541 | draw_property_utils::ScreenSpaceTransform(child, transform_tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6542 | } |
| 6543 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6544 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 6545 | // This test verifies that a scrolling layer that gets snapped to |
| 6546 | // integer coordinates doesn't move a fixed position child. |
| 6547 | // |
| 6548 | // + root |
| 6549 | // + container |
| 6550 | // + scroller |
| 6551 | // + fixed |
| 6552 | // |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6553 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6554 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6555 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6556 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6557 | &task_graph_runner); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6558 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6559 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6560 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 6561 | LayerImpl* root = root_ptr.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6562 | std::unique_ptr<LayerImpl> container = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6563 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 6564 | LayerImpl* container_layer = container.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6565 | std::unique_ptr<LayerImpl> scroller = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6566 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 6567 | LayerImpl* scroll_layer = scroller.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6568 | std::unique_ptr<LayerImpl> fixed = |
| 6569 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6570 | LayerImpl* fixed_layer = fixed.get(); |
| 6571 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6572 | container->test_properties()->is_container_for_fixed_position_layers = true; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6573 | |
| 6574 | LayerPositionConstraint constraint; |
| 6575 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6576 | fixed->test_properties()->position_constraint = constraint; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6577 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6578 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6579 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6580 | gfx::Transform container_transform; |
| 6581 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 6582 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 6583 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6584 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6585 | container->test_properties()->transform = container_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6586 | container->SetBounds(gfx::Size(40, 40)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6587 | container->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6588 | scroller->SetBounds(gfx::Size(30, 30)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6589 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6590 | fixed->SetBounds(gfx::Size(50, 50)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6591 | fixed->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6592 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6593 | scroller->test_properties()->AddChild(std::move(fixed)); |
| 6594 | container->test_properties()->AddChild(std::move(scroller)); |
| 6595 | root->test_properties()->AddChild(std::move(container)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6596 | root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr)); |
| 6597 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6598 | |
| 6599 | // Rounded to integers already. |
| 6600 | { |
| 6601 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6602 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6603 | |
| 6604 | LayerImplList render_surface_layer_list; |
| 6605 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6606 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6607 | root->layer_tree_impl() |
| 6608 | ->property_trees() |
| 6609 | ->transform_tree.set_source_to_parent_updates_allowed(false); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6610 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6611 | |
| 6612 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6613 | container_layer->draw_properties().screen_space_transform, |
| 6614 | fixed_layer->draw_properties().screen_space_transform); |
| 6615 | EXPECT_VECTOR_EQ( |
| 6616 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6617 | container_offset); |
| 6618 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6619 | .screen_space_transform.To2dTranslation(), |
| 6620 | container_offset - scroll_delta); |
| 6621 | } |
| 6622 | |
| 6623 | // Scroll delta requiring rounding. |
| 6624 | { |
| 6625 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6626 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6627 | |
| 6628 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 6629 | |
| 6630 | LayerImplList render_surface_layer_list; |
| 6631 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6632 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6633 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6634 | |
| 6635 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6636 | container_layer->draw_properties().screen_space_transform, |
| 6637 | fixed_layer->draw_properties().screen_space_transform); |
| 6638 | EXPECT_VECTOR_EQ( |
| 6639 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6640 | container_offset); |
| 6641 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6642 | .screen_space_transform.To2dTranslation(), |
| 6643 | container_offset - rounded_scroll_delta); |
| 6644 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6645 | |
| 6646 | // Scale is applied earlier in the tree. |
| 6647 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6648 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6649 | gfx::Transform scaled_container_transform = container_transform; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6650 | scaled_container_transform.Scale3d(2.0, 2.0, 1.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6651 | container_layer->test_properties()->transform = scaled_container_transform; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6652 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6653 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6654 | |
| 6655 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6656 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6657 | |
| 6658 | LayerImplList render_surface_layer_list; |
| 6659 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6660 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6661 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6662 | |
| 6663 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6664 | container_layer->draw_properties().screen_space_transform, |
| 6665 | fixed_layer->draw_properties().screen_space_transform); |
| 6666 | EXPECT_VECTOR_EQ( |
| 6667 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6668 | container_offset); |
| 6669 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6670 | container_layer->test_properties()->transform = container_transform; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 6671 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6672 | } |
| 6673 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 6674 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6675 | ScrollSnappingWithAnimatedScreenSpaceTransform) { |
| 6676 | // This test verifies that a scrolling layer whose screen space transform is |
| 6677 | // animating doesn't get snapped to integer coordinates. |
| 6678 | // |
| 6679 | // + root |
| 6680 | // + animated layer |
| 6681 | // + surface |
| 6682 | // + container |
| 6683 | // + scroller |
| 6684 | // |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6685 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6686 | LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>(); |
| 6687 | LayerImpl* surface = AddChild<LayerImpl>(animated_layer); |
| 6688 | LayerImpl* container = AddChild<LayerImpl>(surface); |
| 6689 | LayerImpl* scroller = AddChild<LayerImpl>(container); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6690 | |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6691 | gfx::Transform start_scale; |
| 6692 | start_scale.Scale(1.5f, 1.5f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6693 | |
| 6694 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 6695 | animated_layer->test_properties()->transform = start_scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 6696 | animated_layer->SetBounds(gfx::Size(50, 50)); |
| 6697 | surface->SetBounds(gfx::Size(50, 50)); |
| 6698 | surface->test_properties()->force_render_surface = true; |
| 6699 | container->SetBounds(gfx::Size(50, 50)); |
| 6700 | scroller->SetBounds(gfx::Size(100, 100)); |
| 6701 | scroller->SetScrollClipLayer(container->id()); |
| 6702 | scroller->SetDrawsContent(true); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6703 | |
| 6704 | gfx::Transform end_scale; |
| 6705 | end_scale.Scale(2.f, 2.f); |
| 6706 | TransformOperations start_operations; |
| 6707 | start_operations.AppendMatrix(start_scale); |
| 6708 | TransformOperations end_operations; |
| 6709 | end_operations.AppendMatrix(end_scale); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 6710 | SetElementIdsForTesting(); |
| 6711 | |
| 6712 | AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(), |
| 6713 | timeline_impl(), 1.0, |
| 6714 | start_operations, end_operations); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6715 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6716 | SetScrollOffsetDelta(scroller, scroll_delta); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6717 | |
| 6718 | ExecuteCalculateDrawProperties(root); |
| 6719 | |
| 6720 | gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); |
| 6721 | EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 6722 | scroller->DrawTransform().To2dTranslation()); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 6723 | } |
| 6724 | |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 6725 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) { |
| 6726 | // This test verifies that a scrolling child of a scrolling layer doesn't get |
| 6727 | // snapped to integer coordinates. |
| 6728 | // |
| 6729 | // + root |
| 6730 | // + container |
| 6731 | // + scroller |
| 6732 | // + scroll_child |
| 6733 | // |
| 6734 | scoped_refptr<Layer> root = Layer::Create(); |
| 6735 | scoped_refptr<Layer> container = Layer::Create(); |
| 6736 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6737 | scoped_refptr<Layer> scroll_child = Layer::Create(); |
| 6738 | root->AddChild(container); |
| 6739 | root->AddChild(scroll_child); |
| 6740 | container->AddChild(scroller); |
| 6741 | host()->SetRootLayer(root); |
| 6742 | |
| 6743 | scroller->SetScrollClipLayerId(container->id()); |
| 6744 | scroll_child->SetScrollParent(scroller.get()); |
| 6745 | |
| 6746 | gfx::Transform rotate; |
| 6747 | rotate.RotateAboutYAxis(30); |
| 6748 | root->SetBounds(gfx::Size(50, 50)); |
| 6749 | container->SetBounds(gfx::Size(50, 50)); |
| 6750 | scroller->SetBounds(gfx::Size(100, 100)); |
| 6751 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 6752 | scroll_child->SetBounds(gfx::Size(10, 10)); |
| 6753 | scroll_child->SetTransform(rotate); |
| 6754 | |
| 6755 | ExecuteCalculateDrawProperties(root.get()); |
| 6756 | |
| 6757 | host()->host_impl()->CreatePendingTree(); |
| 6758 | host()->CommitAndCreatePendingTree(); |
| 6759 | host()->host_impl()->ActivateSyncTree(); |
| 6760 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6761 | |
| 6762 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6763 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6764 | LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id()); |
| 6765 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 6766 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 6767 | |
| 6768 | ExecuteCalculateDrawProperties(root_impl); |
| 6769 | |
| 6770 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 6771 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 6772 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6773 | |
| 6774 | gfx::Transform expected_scroll_child_screen_space_transform; |
| 6775 | expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); |
| 6776 | expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); |
| 6777 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, |
| 6778 | scroll_child_impl->ScreenSpaceTransform()); |
| 6779 | } |
| 6780 | |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 6781 | TEST_F(LayerTreeHostCommonTest, StickyPositionTop) { |
| 6782 | scoped_refptr<Layer> root = Layer::Create(); |
| 6783 | scoped_refptr<Layer> container = Layer::Create(); |
| 6784 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6785 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6786 | root->AddChild(container); |
| 6787 | container->AddChild(scroller); |
| 6788 | scroller->AddChild(sticky_pos); |
| 6789 | host()->SetRootLayer(root); |
| 6790 | scroller->SetScrollClipLayerId(container->id()); |
| 6791 | |
| 6792 | LayerStickyPositionConstraint sticky_position; |
| 6793 | sticky_position.is_sticky = true; |
| 6794 | sticky_position.is_anchored_top = true; |
| 6795 | sticky_position.top_offset = 10.0f; |
| 6796 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6797 | gfx::Rect(10, 20, 10, 10); |
| 6798 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6799 | gfx::Rect(0, 0, 50, 50); |
| 6800 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6801 | |
| 6802 | root->SetBounds(gfx::Size(100, 100)); |
| 6803 | container->SetBounds(gfx::Size(100, 100)); |
| 6804 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 6805 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6806 | sticky_pos->SetPosition(gfx::PointF(10, 20)); |
| 6807 | |
| 6808 | ExecuteCalculateDrawProperties(root.get()); |
| 6809 | host()->host_impl()->CreatePendingTree(); |
| 6810 | host()->CommitAndCreatePendingTree(); |
| 6811 | host()->host_impl()->ActivateSyncTree(); |
| 6812 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6813 | |
| 6814 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6815 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6816 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6817 | |
| 6818 | ExecuteCalculateDrawProperties(root_impl); |
| 6819 | EXPECT_VECTOR2DF_EQ( |
| 6820 | gfx::Vector2dF(10.f, 20.f), |
| 6821 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6822 | |
| 6823 | // Scroll less than sticking point, sticky element should move with scroll as |
| 6824 | // we haven't gotten to the initial sticky item location yet. |
| 6825 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 6826 | ExecuteCalculateDrawProperties(root_impl); |
| 6827 | EXPECT_VECTOR2DF_EQ( |
| 6828 | gfx::Vector2dF(5.f, 15.f), |
| 6829 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6830 | |
| 6831 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 6832 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 6833 | ExecuteCalculateDrawProperties(root_impl); |
| 6834 | EXPECT_VECTOR2DF_EQ( |
| 6835 | gfx::Vector2dF(-5.f, 10.f), |
| 6836 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6837 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f)); |
| 6838 | ExecuteCalculateDrawProperties(root_impl); |
| 6839 | EXPECT_VECTOR2DF_EQ( |
| 6840 | gfx::Vector2dF(-5.f, 10.f), |
| 6841 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6842 | |
| 6843 | // Scroll past the end of the sticky container (note: this element does not |
| 6844 | // have its own layer as it does not need to be composited). |
| 6845 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); |
| 6846 | ExecuteCalculateDrawProperties(root_impl); |
| 6847 | EXPECT_VECTOR2DF_EQ( |
| 6848 | gfx::Vector2dF(-5.f, -10.f), |
| 6849 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6850 | } |
| 6851 | |
| 6852 | TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) { |
| 6853 | scoped_refptr<Layer> root = Layer::Create(); |
| 6854 | scoped_refptr<Layer> container = Layer::Create(); |
| 6855 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6856 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6857 | root->AddChild(container); |
| 6858 | container->AddChild(scroller); |
| 6859 | scroller->AddChild(sticky_pos); |
| 6860 | host()->SetRootLayer(root); |
| 6861 | scroller->SetScrollClipLayerId(container->id()); |
| 6862 | |
| 6863 | LayerStickyPositionConstraint sticky_position; |
| 6864 | sticky_position.is_sticky = true; |
| 6865 | sticky_position.is_anchored_bottom = true; |
| 6866 | sticky_position.bottom_offset = 10.0f; |
| 6867 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6868 | gfx::Rect(0, 150, 10, 10); |
| 6869 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6870 | gfx::Rect(0, 100, 50, 50); |
| 6871 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6872 | |
| 6873 | root->SetBounds(gfx::Size(100, 100)); |
| 6874 | container->SetBounds(gfx::Size(100, 100)); |
| 6875 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 6876 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6877 | sticky_pos->SetPosition(gfx::PointF(0, 150)); |
| 6878 | |
| 6879 | ExecuteCalculateDrawProperties(root.get()); |
| 6880 | host()->host_impl()->CreatePendingTree(); |
| 6881 | host()->CommitAndCreatePendingTree(); |
| 6882 | host()->host_impl()->ActivateSyncTree(); |
| 6883 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6884 | |
| 6885 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6886 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6887 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6888 | |
| 6889 | // Initially the sticky element is moved up to the top of the container. |
| 6890 | ExecuteCalculateDrawProperties(root_impl); |
| 6891 | EXPECT_VECTOR2DF_EQ( |
| 6892 | gfx::Vector2dF(0.f, 100.f), |
| 6893 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6894 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| 6895 | ExecuteCalculateDrawProperties(root_impl); |
| 6896 | EXPECT_VECTOR2DF_EQ( |
| 6897 | gfx::Vector2dF(0.f, 95.f), |
| 6898 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6899 | |
| 6900 | // Once we get past the top of the container it moves to be aligned 10px |
| 6901 | // up from the the bottom of the scroller. |
| 6902 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 6903 | ExecuteCalculateDrawProperties(root_impl); |
| 6904 | EXPECT_VECTOR2DF_EQ( |
| 6905 | gfx::Vector2dF(0.f, 80.f), |
| 6906 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6907 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 6908 | ExecuteCalculateDrawProperties(root_impl); |
| 6909 | EXPECT_VECTOR2DF_EQ( |
| 6910 | gfx::Vector2dF(0.f, 80.f), |
| 6911 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6912 | |
| 6913 | // Once we scroll past its initial location, it sticks there. |
| 6914 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f)); |
| 6915 | ExecuteCalculateDrawProperties(root_impl); |
| 6916 | EXPECT_VECTOR2DF_EQ( |
| 6917 | gfx::Vector2dF(0.f, 0.f), |
| 6918 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6919 | } |
| 6920 | |
| 6921 | TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { |
| 6922 | scoped_refptr<Layer> root = Layer::Create(); |
| 6923 | scoped_refptr<Layer> container = Layer::Create(); |
| 6924 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 6925 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6926 | root->AddChild(container); |
| 6927 | container->AddChild(scroller); |
| 6928 | scroller->AddChild(sticky_pos); |
| 6929 | host()->SetRootLayer(root); |
| 6930 | scroller->SetScrollClipLayerId(container->id()); |
| 6931 | |
| 6932 | LayerStickyPositionConstraint sticky_position; |
| 6933 | sticky_position.is_sticky = true; |
| 6934 | sticky_position.is_anchored_left = true; |
| 6935 | sticky_position.is_anchored_right = true; |
| 6936 | sticky_position.left_offset = 10.f; |
| 6937 | sticky_position.right_offset = 10.f; |
| 6938 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 6939 | gfx::Rect(145, 0, 10, 10); |
| 6940 | sticky_position.scroll_container_relative_containing_block_rect = |
| 6941 | gfx::Rect(100, 0, 100, 100); |
| 6942 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 6943 | |
| 6944 | root->SetBounds(gfx::Size(100, 100)); |
| 6945 | container->SetBounds(gfx::Size(100, 100)); |
| 6946 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 6947 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 6948 | sticky_pos->SetPosition(gfx::PointF(145, 0)); |
| 6949 | |
| 6950 | ExecuteCalculateDrawProperties(root.get()); |
| 6951 | host()->host_impl()->CreatePendingTree(); |
| 6952 | host()->CommitAndCreatePendingTree(); |
| 6953 | host()->host_impl()->ActivateSyncTree(); |
| 6954 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6955 | |
| 6956 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6957 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6958 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 6959 | |
| 6960 | // Initially the sticky element is moved the leftmost side of the container. |
| 6961 | ExecuteCalculateDrawProperties(root_impl); |
| 6962 | EXPECT_VECTOR2DF_EQ( |
| 6963 | gfx::Vector2dF(100.f, 0.f), |
| 6964 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6965 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f)); |
| 6966 | ExecuteCalculateDrawProperties(root_impl); |
| 6967 | EXPECT_VECTOR2DF_EQ( |
| 6968 | gfx::Vector2dF(95.f, 0.f), |
| 6969 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6970 | |
| 6971 | // Once we get past the left side of the container it moves to be aligned 10px |
| 6972 | // up from the the right of the scroller. |
| 6973 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f)); |
| 6974 | ExecuteCalculateDrawProperties(root_impl); |
| 6975 | EXPECT_VECTOR2DF_EQ( |
| 6976 | gfx::Vector2dF(80.f, 0.f), |
| 6977 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6978 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f)); |
| 6979 | ExecuteCalculateDrawProperties(root_impl); |
| 6980 | EXPECT_VECTOR2DF_EQ( |
| 6981 | gfx::Vector2dF(80.f, 0.f), |
| 6982 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6983 | |
| 6984 | // When we get to the sticky element's original position we stop sticking |
| 6985 | // to the right. |
| 6986 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f)); |
| 6987 | ExecuteCalculateDrawProperties(root_impl); |
| 6988 | EXPECT_VECTOR2DF_EQ( |
| 6989 | gfx::Vector2dF(50.f, 0.f), |
| 6990 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6991 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f)); |
| 6992 | ExecuteCalculateDrawProperties(root_impl); |
| 6993 | EXPECT_VECTOR2DF_EQ( |
| 6994 | gfx::Vector2dF(40.f, 0.f), |
| 6995 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6996 | |
| 6997 | // The element starts sticking to the left once we scroll far enough. |
| 6998 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f)); |
| 6999 | ExecuteCalculateDrawProperties(root_impl); |
| 7000 | EXPECT_VECTOR2DF_EQ( |
| 7001 | gfx::Vector2dF(10.f, 0.f), |
| 7002 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7003 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f)); |
| 7004 | ExecuteCalculateDrawProperties(root_impl); |
| 7005 | EXPECT_VECTOR2DF_EQ( |
| 7006 | gfx::Vector2dF(10.f, 0.f), |
| 7007 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7008 | |
| 7009 | // Finally it stops sticking when it hits the right side of the container. |
| 7010 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f)); |
| 7011 | ExecuteCalculateDrawProperties(root_impl); |
| 7012 | EXPECT_VECTOR2DF_EQ( |
| 7013 | gfx::Vector2dF(0.f, 0.f), |
| 7014 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7015 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f)); |
| 7016 | ExecuteCalculateDrawProperties(root_impl); |
| 7017 | EXPECT_VECTOR2DF_EQ( |
| 7018 | gfx::Vector2dF(-5.f, 0.f), |
| 7019 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7020 | } |
| 7021 | |
| 7022 | // This test ensures that the compositor sticky position code correctly accounts |
| 7023 | // for the element having been given a position from the main thread sticky |
| 7024 | // position code. |
| 7025 | TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) { |
| 7026 | scoped_refptr<Layer> root = Layer::Create(); |
| 7027 | scoped_refptr<Layer> container = Layer::Create(); |
| 7028 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7029 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7030 | root->AddChild(container); |
| 7031 | container->AddChild(scroller); |
| 7032 | scroller->AddChild(sticky_pos); |
| 7033 | host()->SetRootLayer(root); |
| 7034 | scroller->SetScrollClipLayerId(container->id()); |
| 7035 | |
| 7036 | LayerStickyPositionConstraint sticky_position; |
| 7037 | sticky_position.is_sticky = true; |
| 7038 | sticky_position.is_anchored_top = true; |
| 7039 | sticky_position.top_offset = 10.0f; |
| 7040 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7041 | gfx::Rect(10, 20, 10, 10); |
| 7042 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7043 | gfx::Rect(0, 0, 50, 50); |
| 7044 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7045 | |
| 7046 | root->SetBounds(gfx::Size(100, 100)); |
| 7047 | container->SetBounds(gfx::Size(100, 100)); |
| 7048 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7049 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7050 | sticky_pos->SetPosition(gfx::PointF(10, 20)); |
| 7051 | |
| 7052 | ExecuteCalculateDrawProperties(root.get()); |
| 7053 | host()->host_impl()->CreatePendingTree(); |
| 7054 | host()->CommitAndCreatePendingTree(); |
| 7055 | host()->host_impl()->ActivateSyncTree(); |
| 7056 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7057 | |
| 7058 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7059 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7060 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7061 | |
| 7062 | ExecuteCalculateDrawProperties(root_impl); |
| 7063 | EXPECT_VECTOR2DF_EQ( |
| 7064 | gfx::Vector2dF(10.f, 20.f), |
| 7065 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7066 | |
| 7067 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7068 | // we haven't gotten to the initial sticky item location yet. |
| 7069 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); |
| 7070 | ExecuteCalculateDrawProperties(root_impl); |
| 7071 | EXPECT_VECTOR2DF_EQ( |
| 7072 | gfx::Vector2dF(5.f, 15.f), |
| 7073 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7074 | |
| 7075 | // Scroll past the sticking point, the Y coordinate should now be clamped. |
| 7076 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); |
| 7077 | ExecuteCalculateDrawProperties(root_impl); |
| 7078 | EXPECT_VECTOR2DF_EQ( |
| 7079 | gfx::Vector2dF(-5.f, 10.f), |
| 7080 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7081 | |
| 7082 | // Now the main thread commits the new position of the sticky element. |
| 7083 | scroller->SetScrollOffset(gfx::ScrollOffset(15, 15)); |
| 7084 | sticky_pos->SetPosition(gfx::PointF(10, 25)); |
| 7085 | ExecuteCalculateDrawProperties(root.get()); |
| 7086 | host()->host_impl()->CreatePendingTree(); |
| 7087 | host()->CommitAndCreatePendingTree(); |
| 7088 | host()->host_impl()->ActivateSyncTree(); |
| 7089 | layer_tree_impl = host()->host_impl()->active_tree(); |
| 7090 | root_impl = layer_tree_impl->LayerById(root->id()); |
| 7091 | scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7092 | sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7093 | |
| 7094 | // The element should still be where it was before. We reset the delta to |
| 7095 | // (0, 0) because we have synced a scroll offset of (15, 15) from the main |
| 7096 | // thread. |
| 7097 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); |
| 7098 | ExecuteCalculateDrawProperties(root_impl); |
| 7099 | EXPECT_VECTOR2DF_EQ( |
| 7100 | gfx::Vector2dF(-5.f, 10.f), |
| 7101 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7102 | |
| 7103 | // And if we scroll a little further it remains there. |
| 7104 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); |
| 7105 | ExecuteCalculateDrawProperties(root_impl); |
| 7106 | EXPECT_VECTOR2DF_EQ( |
| 7107 | gfx::Vector2dF(-5.f, 10.f), |
| 7108 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7109 | } |
| 7110 | |
| 7111 | // A transform on a sticky element should not affect its sticky position. |
| 7112 | TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) { |
| 7113 | scoped_refptr<Layer> root = Layer::Create(); |
| 7114 | scoped_refptr<Layer> container = Layer::Create(); |
| 7115 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7116 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7117 | root->AddChild(container); |
| 7118 | container->AddChild(scroller); |
| 7119 | scroller->AddChild(sticky_pos); |
| 7120 | host()->SetRootLayer(root); |
| 7121 | scroller->SetScrollClipLayerId(container->id()); |
| 7122 | gfx::Transform t; |
| 7123 | t.Scale(2, 2); |
| 7124 | sticky_pos->SetTransform(t); |
| 7125 | |
| 7126 | LayerStickyPositionConstraint sticky_position; |
| 7127 | sticky_position.is_sticky = true; |
| 7128 | sticky_position.is_anchored_top = true; |
| 7129 | sticky_position.top_offset = 0.0f; |
| 7130 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7131 | gfx::Rect(0, 20, 10, 10); |
| 7132 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7133 | gfx::Rect(0, 0, 50, 50); |
| 7134 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7135 | |
| 7136 | root->SetBounds(gfx::Size(100, 100)); |
| 7137 | container->SetBounds(gfx::Size(100, 100)); |
| 7138 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7139 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7140 | sticky_pos->SetPosition(gfx::PointF(0, 20)); |
| 7141 | |
| 7142 | ExecuteCalculateDrawProperties(root.get()); |
| 7143 | host()->host_impl()->CreatePendingTree(); |
| 7144 | host()->CommitAndCreatePendingTree(); |
| 7145 | host()->host_impl()->ActivateSyncTree(); |
| 7146 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7147 | |
| 7148 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7149 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7150 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7151 | |
| 7152 | ExecuteCalculateDrawProperties(root_impl); |
| 7153 | EXPECT_VECTOR2DF_EQ( |
| 7154 | gfx::Vector2dF(0.f, 20.f), |
| 7155 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7156 | |
| 7157 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7158 | // we haven't gotten to the initial sticky item location yet. |
| 7159 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f)); |
| 7160 | ExecuteCalculateDrawProperties(root_impl); |
| 7161 | EXPECT_VECTOR2DF_EQ( |
| 7162 | gfx::Vector2dF(0.f, 5.f), |
| 7163 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7164 | |
| 7165 | // Scroll past the sticking point, the box is positioned at the scroller |
| 7166 | // edge. |
| 7167 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7168 | ExecuteCalculateDrawProperties(root_impl); |
| 7169 | EXPECT_VECTOR2DF_EQ( |
| 7170 | gfx::Vector2dF(0.f, 0.f), |
| 7171 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7172 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7173 | ExecuteCalculateDrawProperties(root_impl); |
| 7174 | EXPECT_VECTOR2DF_EQ( |
| 7175 | gfx::Vector2dF(0.f, 0.f), |
| 7176 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7177 | |
| 7178 | // Scroll past the end of the sticky container. |
| 7179 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); |
| 7180 | ExecuteCalculateDrawProperties(root_impl); |
| 7181 | EXPECT_VECTOR2DF_EQ( |
| 7182 | gfx::Vector2dF(0.f, -10.f), |
| 7183 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7184 | } |
| 7185 | |
| 7186 | // Tests that a transform does not affect the sticking points. The sticky |
| 7187 | // element will however move relative to the viewport due to its transform. |
| 7188 | TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) { |
| 7189 | scoped_refptr<Layer> root = Layer::Create(); |
| 7190 | scoped_refptr<Layer> container = Layer::Create(); |
| 7191 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7192 | scoped_refptr<Layer> sticky_container = Layer::Create(); |
| 7193 | scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 7194 | root->AddChild(container); |
| 7195 | container->AddChild(scroller); |
| 7196 | scroller->AddChild(sticky_container); |
| 7197 | sticky_container->AddChild(sticky_pos); |
| 7198 | host()->SetRootLayer(root); |
| 7199 | scroller->SetScrollClipLayerId(container->id()); |
| 7200 | gfx::Transform t; |
| 7201 | t.Scale(2, 2); |
| 7202 | sticky_container->SetTransform(t); |
| 7203 | |
| 7204 | LayerStickyPositionConstraint sticky_position; |
| 7205 | sticky_position.is_sticky = true; |
| 7206 | sticky_position.is_anchored_top = true; |
| 7207 | sticky_position.top_offset = 0.0f; |
| 7208 | sticky_position.scroll_container_relative_sticky_box_rect = |
| 7209 | gfx::Rect(0, 20, 10, 10); |
| 7210 | sticky_position.scroll_container_relative_containing_block_rect = |
| 7211 | gfx::Rect(0, 0, 50, 50); |
| 7212 | sticky_pos->SetStickyPositionConstraint(sticky_position); |
| 7213 | |
| 7214 | root->SetBounds(gfx::Size(100, 100)); |
| 7215 | container->SetBounds(gfx::Size(100, 100)); |
| 7216 | scroller->SetBounds(gfx::Size(1000, 1000)); |
| 7217 | sticky_container->SetBounds(gfx::Size(50, 50)); |
| 7218 | sticky_pos->SetBounds(gfx::Size(10, 10)); |
| 7219 | sticky_pos->SetPosition(gfx::PointF(0, 20)); |
| 7220 | |
| 7221 | ExecuteCalculateDrawProperties(root.get()); |
| 7222 | host()->host_impl()->CreatePendingTree(); |
| 7223 | host()->CommitAndCreatePendingTree(); |
| 7224 | host()->host_impl()->ActivateSyncTree(); |
| 7225 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7226 | |
| 7227 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7228 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7229 | LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
| 7230 | |
| 7231 | ExecuteCalculateDrawProperties(root_impl); |
| 7232 | EXPECT_VECTOR2DF_EQ( |
| 7233 | gfx::Vector2dF(0.f, 40.f), |
| 7234 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7235 | |
| 7236 | // Scroll less than sticking point, sticky element should move with scroll as |
| 7237 | // we haven't gotten to the initial sticky item location yet. |
| 7238 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f)); |
| 7239 | ExecuteCalculateDrawProperties(root_impl); |
| 7240 | EXPECT_VECTOR2DF_EQ( |
| 7241 | gfx::Vector2dF(0.f, 25.f), |
| 7242 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7243 | |
| 7244 | // Scroll past the sticking point, the box is positioned at the scroller |
| 7245 | // edge but is also scaled by its container so it begins to move down. |
| 7246 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); |
| 7247 | ExecuteCalculateDrawProperties(root_impl); |
| 7248 | EXPECT_VECTOR2DF_EQ( |
| 7249 | gfx::Vector2dF(0.f, 25.f), |
| 7250 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7251 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| 7252 | ExecuteCalculateDrawProperties(root_impl); |
| 7253 | EXPECT_VECTOR2DF_EQ( |
| 7254 | gfx::Vector2dF(0.f, 30.f), |
| 7255 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7256 | |
| 7257 | // Scroll past the end of the sticky container. |
| 7258 | SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f)); |
| 7259 | ExecuteCalculateDrawProperties(root_impl); |
| 7260 | EXPECT_VECTOR2DF_EQ( |
| 7261 | gfx::Vector2dF(0.f, 30.f), |
| 7262 | sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7263 | } |
| 7264 | |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7265 | TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) { |
| 7266 | scoped_refptr<Layer> root = Layer::Create(); |
| 7267 | scoped_refptr<Layer> container = Layer::Create(); |
| 7268 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7269 | scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 7270 | |
| 7271 | scroller->SetIsContainerForFixedPositionLayers(true); |
| 7272 | root->AddChild(container); |
| 7273 | container->AddChild(scroller); |
| 7274 | scroller->AddChild(fixed_pos); |
| 7275 | host()->SetRootLayer(root); |
| 7276 | |
| 7277 | LayerPositionConstraint fixed_position; |
| 7278 | fixed_position.set_is_fixed_position(true); |
| 7279 | scroller->SetScrollClipLayerId(container->id()); |
| 7280 | fixed_pos->SetPositionConstraint(fixed_position); |
| 7281 | |
| 7282 | root->SetBounds(gfx::Size(50, 50)); |
| 7283 | container->SetBounds(gfx::Size(50, 50)); |
| 7284 | scroller->SetBounds(gfx::Size(50, 50)); |
| 7285 | fixed_pos->SetBounds(gfx::Size(50, 50)); |
| 7286 | |
| 7287 | gfx::Transform rotate; |
| 7288 | rotate.RotateAboutXAxis(20); |
| 7289 | container->SetTransform(rotate); |
| 7290 | |
| 7291 | ExecuteCalculateDrawProperties(root.get()); |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 7292 | TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree; |
jaydasika | af1582f | 2016-08-10 18:39:38 | [diff] [blame] | 7293 | gfx::Transform transform; |
| 7294 | tree.ComputeTranslation(fixed_pos->transform_tree_index(), |
| 7295 | container->transform_tree_index(), &transform); |
| 7296 | EXPECT_TRUE(transform.IsIdentity()); |
| 7297 | } |
| 7298 | |
sunxd | 8a9a6098 | 2016-07-29 18:46:56 | [diff] [blame] | 7299 | TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) { |
| 7300 | // This test verifies that a fixed pos child of a scrolling layer doesn't get |
| 7301 | // snapped to integer coordinates. |
| 7302 | // |
| 7303 | // + root |
| 7304 | // + container |
| 7305 | // + scroller |
| 7306 | // + fixed_pos |
| 7307 | // |
| 7308 | scoped_refptr<Layer> root = Layer::Create(); |
| 7309 | scoped_refptr<Layer> container = Layer::Create(); |
| 7310 | scoped_refptr<Layer> scroller = Layer::Create(); |
| 7311 | scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 7312 | |
| 7313 | scroller->SetIsContainerForFixedPositionLayers(true); |
| 7314 | |
| 7315 | root->AddChild(container); |
| 7316 | container->AddChild(scroller); |
| 7317 | scroller->AddChild(fixed_pos); |
| 7318 | host()->SetRootLayer(root); |
| 7319 | |
| 7320 | LayerPositionConstraint fixed_position; |
| 7321 | fixed_position.set_is_fixed_position(true); |
| 7322 | scroller->SetScrollClipLayerId(container->id()); |
| 7323 | fixed_pos->SetPositionConstraint(fixed_position); |
| 7324 | |
| 7325 | root->SetBounds(gfx::Size(50, 50)); |
| 7326 | container->SetBounds(gfx::Size(50, 50)); |
| 7327 | scroller->SetBounds(gfx::Size(100, 100)); |
| 7328 | scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 7329 | fixed_pos->SetBounds(gfx::Size(10, 10)); |
| 7330 | |
| 7331 | ExecuteCalculateDrawProperties(root.get()); |
| 7332 | |
| 7333 | host()->host_impl()->CreatePendingTree(); |
| 7334 | host()->CommitAndCreatePendingTree(); |
| 7335 | host()->host_impl()->ActivateSyncTree(); |
| 7336 | LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 7337 | |
| 7338 | LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 7339 | LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 7340 | LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id()); |
| 7341 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 7342 | SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 7343 | |
| 7344 | ExecuteCalculateDrawProperties(root_impl); |
| 7345 | |
| 7346 | gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 7347 | EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 7348 | scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7349 | |
| 7350 | gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f, |
| 7351 | 10.3f); |
| 7352 | EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation, |
| 7353 | fixed_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 7354 | } |
| 7355 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7356 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7357 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7358 | static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7359 | LayerTreeImpl* tree_impl, |
| 7360 | int id) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7361 | return base::WrapUnique( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7362 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7363 | } |
| 7364 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7365 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7366 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7367 | private: |
| 7368 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7369 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7370 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7371 | SetDrawsContent(true); |
| 7372 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7373 | }; |
| 7374 | |
| 7375 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7376 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7377 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7378 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 7379 | LayerTreeSettings settings = host()->GetSettings(); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7380 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7381 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7382 | &shared_bitmap_manager, &task_graph_runner); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7383 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7384 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7385 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7386 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7387 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7388 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7389 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7390 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7391 | |
| 7392 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7393 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7394 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7395 | AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get(); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7396 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7397 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 7398 | parent->SetBounds(gfx::Size(1, 2)); |
| 7399 | child->SetBounds(gfx::Size(1, 2)); |
| 7400 | grand_child->SetBounds(gfx::Size(1, 2)); |
| 7401 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7402 | child->test_properties()->AddChild(std::move(grand_child)); |
| 7403 | parent->test_properties()->AddChild(std::move(child)); |
| 7404 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7405 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 7406 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7407 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7408 | |
| 7409 | // No layers have animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7410 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7411 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7412 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7413 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7414 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7415 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7416 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7417 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7418 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7419 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7420 | TransformOperations translation; |
| 7421 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7422 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7423 | scoped_refptr<AnimationTimeline> timeline; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7424 | timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7425 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7426 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7427 | host_impl.active_tree()->SetElementIdsForTesting(); |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7428 | |
| 7429 | scoped_refptr<AnimationPlayer> grand_parent_player = |
| 7430 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7431 | timeline->AttachPlayer(grand_parent_player); |
| 7432 | grand_parent_player->AttachElement(grand_parent_raw->element_id()); |
| 7433 | |
| 7434 | scoped_refptr<AnimationPlayer> parent_player = |
| 7435 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7436 | timeline->AttachPlayer(parent_player); |
| 7437 | parent_player->AttachElement(parent_raw->element_id()); |
| 7438 | |
| 7439 | scoped_refptr<AnimationPlayer> child_player = |
| 7440 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7441 | timeline->AttachPlayer(child_player); |
| 7442 | child_player->AttachElement(child_raw->element_id()); |
| 7443 | |
| 7444 | scoped_refptr<AnimationPlayer> grand_child_player = |
| 7445 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 7446 | timeline->AttachPlayer(grand_child_player); |
| 7447 | grand_child_player->AttachElement(grand_child_raw->element_id()); |
| 7448 | |
| 7449 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7450 | translation); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7451 | |
| 7452 | // No layers have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7453 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7454 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7455 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7456 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7457 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7458 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7459 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7460 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7461 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7462 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7463 | TransformOperations scale; |
| 7464 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7465 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7466 | AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(), |
| 7467 | scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7468 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7469 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7470 | |
| 7471 | // Only |child| has a scale-affecting animation. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7472 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7473 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7474 | EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw)); |
| 7475 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7476 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7477 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7478 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7479 | EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw)); |
| 7480 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7481 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7482 | AddAnimatedTransformToPlayer(grand_parent_player.get(), 1.0, |
| 7483 | TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7484 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7485 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7486 | |
| 7487 | // |grand_parent| and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7488 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7489 | EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7490 | // We don't support combining animated scales from two nodes; 0.f means |
| 7491 | // that the maximum scale could not be computed. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7492 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7493 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7494 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7495 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7496 | EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw)); |
| 7497 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7498 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7499 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7500 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7501 | scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7502 | parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7503 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7504 | |
| 7505 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7506 | EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7507 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7508 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7509 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7510 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7511 | EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7512 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7513 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7514 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7515 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7516 | grand_parent_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 7517 | parent_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 7518 | child_player->AbortAnimations(TargetProperty::TRANSFORM, false); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7519 | |
| 7520 | TransformOperations perspective; |
| 7521 | perspective.AppendPerspective(10.f); |
| 7522 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7523 | AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(), |
| 7524 | perspective); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7525 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7526 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7527 | |
| 7528 | // |child| has a scale-affecting animation but computing the maximum of this |
| 7529 | // animation is not supported. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7530 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7531 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7532 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7533 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7534 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7535 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7536 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7537 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7538 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7539 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7540 | AbortAnimationsOnElementWithPlayer(child_raw->element_id(), timeline, |
| 7541 | TargetProperty::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7542 | gfx::Transform scale_matrix; |
| 7543 | scale_matrix.Scale(1.f, 2.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7544 | grand_parent_raw->test_properties()->transform = scale_matrix; |
| 7545 | parent_raw->test_properties()->transform = scale_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7546 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7547 | |
loyso | db00688 | 2016-09-14 00:31:51 | [diff] [blame] | 7548 | AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(), |
| 7549 | scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7550 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7551 | |
| 7552 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 7553 | // animation with maximum scale 5.f. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7554 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7555 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 7556 | EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw)); |
| 7557 | EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7558 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7559 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7560 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 7561 | EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw)); |
| 7562 | EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7563 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7564 | gfx::Transform perspective_matrix; |
| 7565 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7566 | child_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7567 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7568 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7569 | |
| 7570 | // |child| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7571 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7572 | EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw)); |
| 7573 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7574 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7575 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7576 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7577 | EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw)); |
| 7578 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7579 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7580 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7581 | parent_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7582 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7583 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7584 | |
| 7585 | // |parent| and |child| have transforms that are neither translations nor |
| 7586 | // scales. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7587 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7588 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7589 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7590 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7591 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7592 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7593 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7594 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7595 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7596 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7597 | parent_raw->test_properties()->transform = gfx::Transform(); |
| 7598 | child_raw->test_properties()->transform = gfx::Transform(); |
| 7599 | grand_parent_raw->test_properties()->transform = perspective_matrix; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7600 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7601 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7602 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7603 | |
| 7604 | // |grand_parent| has a transform that's neither a translation nor a scale. |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7605 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw)); |
| 7606 | EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw)); |
| 7607 | EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw)); |
| 7608 | EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw)); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7609 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7610 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw)); |
| 7611 | EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw)); |
| 7612 | EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw)); |
| 7613 | EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7614 | } |
| 7615 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 7616 | static void GatherDrawnLayers(const LayerImplList* rsll, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7617 | std::set<LayerImpl*>* drawn_layers) { |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 7618 | for (LayerIterator it = LayerIterator::Begin(rsll), |
| 7619 | end = LayerIterator::End(rsll); |
| 7620 | it != end; ++it) { |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7621 | LayerImpl* layer = *it; |
| 7622 | if (it.represents_itself()) |
| 7623 | drawn_layers->insert(layer); |
| 7624 | |
| 7625 | if (!it.represents_contributing_render_surface()) |
| 7626 | continue; |
| 7627 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7628 | if (layer->render_surface()->MaskLayer()) |
| 7629 | drawn_layers->insert(layer->render_surface()->MaskLayer()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7630 | } |
| 7631 | } |
| 7632 | |
| 7633 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7634 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7635 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7636 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7637 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7638 | &task_graph_runner); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7639 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7640 | std::unique_ptr<LayerImpl> grand_parent = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7641 | LayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7642 | std::unique_ptr<LayerImpl> parent = |
| 7643 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7644 | std::unique_ptr<LayerImpl> child = |
| 7645 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7646 | std::unique_ptr<LayerImpl> grand_child1 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7647 | LayerImpl::Create(host_impl.active_tree(), 7); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7648 | std::unique_ptr<LayerImpl> grand_child2 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7649 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 7650 | |
| 7651 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 7652 | LayerImpl* parent_raw = parent.get(); |
| 7653 | LayerImpl* child_raw = child.get(); |
| 7654 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 7655 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 7656 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7657 | grand_parent->SetBounds(gfx::Size(1, 2)); |
| 7658 | parent->SetBounds(gfx::Size(1, 2)); |
| 7659 | child->SetBounds(gfx::Size(1, 2)); |
| 7660 | grand_child1->SetBounds(gfx::Size(1, 2)); |
| 7661 | grand_child2->SetBounds(gfx::Size(1, 2)); |
| 7662 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7663 | child->test_properties()->AddChild(std::move(grand_child1)); |
| 7664 | child->test_properties()->AddChild(std::move(grand_child2)); |
| 7665 | parent->test_properties()->AddChild(std::move(child)); |
| 7666 | grand_parent->test_properties()->AddChild(std::move(parent)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7667 | host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent)); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7668 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7669 | // Start with nothing being drawn. |
| 7670 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7671 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7672 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7673 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7674 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7675 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7676 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7677 | |
| 7678 | std::set<LayerImpl*> expected; |
| 7679 | std::set<LayerImpl*> actual; |
| 7680 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7681 | EXPECT_EQ(expected, actual); |
| 7682 | |
| 7683 | // If we force render surface, but none of the layers are in the layer list, |
| 7684 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7685 | grand_child1_raw->SetHasRenderSurface(true); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7686 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7687 | |
| 7688 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7689 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7690 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7691 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7692 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7693 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7694 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7695 | |
| 7696 | expected.clear(); |
| 7697 | actual.clear(); |
| 7698 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7699 | EXPECT_EQ(expected, actual); |
| 7700 | |
| 7701 | // However, if we say that this layer also draws content, it will appear in |
| 7702 | // RSLL. |
| 7703 | grand_child1_raw->SetDrawsContent(true); |
| 7704 | |
| 7705 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7706 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7707 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7708 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7709 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7710 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7711 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7712 | |
| 7713 | expected.clear(); |
| 7714 | expected.insert(grand_child1_raw); |
| 7715 | |
| 7716 | actual.clear(); |
| 7717 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7718 | EXPECT_EQ(expected, actual); |
| 7719 | |
| 7720 | // Now child is forced to have a render surface, and one if its children draws |
| 7721 | // content. |
| 7722 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7723 | grand_child1_raw->SetHasRenderSurface(false); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7724 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7725 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7726 | grand_child2_raw->SetDrawsContent(true); |
| 7727 | |
| 7728 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7729 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7730 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7731 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7732 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7733 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7734 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7735 | |
| 7736 | expected.clear(); |
| 7737 | expected.insert(grand_child2_raw); |
| 7738 | |
| 7739 | actual.clear(); |
| 7740 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7741 | EXPECT_EQ(expected, actual); |
| 7742 | |
| 7743 | // Add a mask layer to child. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7744 | child_raw->test_properties()->SetMaskLayer( |
| 7745 | LayerImpl::Create(host_impl.active_tree(), 6)); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7746 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7747 | |
| 7748 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7749 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7750 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7751 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7752 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7753 | EXPECT_TRUE(child_raw->test_properties() |
| 7754 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7755 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7756 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7757 | |
| 7758 | expected.clear(); |
| 7759 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7760 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7761 | |
| 7762 | expected.clear(); |
| 7763 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7764 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7765 | |
| 7766 | actual.clear(); |
| 7767 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7768 | EXPECT_EQ(expected, actual); |
| 7769 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7770 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7771 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7772 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7773 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7774 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7775 | EXPECT_TRUE(child_raw->test_properties() |
| 7776 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7777 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7778 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7779 | |
| 7780 | expected.clear(); |
| 7781 | expected.insert(grand_child2_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7782 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7783 | |
| 7784 | actual.clear(); |
| 7785 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7786 | EXPECT_EQ(expected, actual); |
| 7787 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7788 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7789 | |
| 7790 | // With nothing drawing, we should have no layers. |
| 7791 | grand_child2_raw->SetDrawsContent(false); |
| 7792 | |
| 7793 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7794 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7795 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7796 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7797 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7798 | EXPECT_FALSE(child_raw->test_properties() |
| 7799 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7800 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7801 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7802 | |
| 7803 | expected.clear(); |
| 7804 | actual.clear(); |
| 7805 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7806 | EXPECT_EQ(expected, actual); |
| 7807 | |
| 7808 | // Child itself draws means that we should have the child and the mask in the |
| 7809 | // list. |
| 7810 | child_raw->SetDrawsContent(true); |
| 7811 | |
| 7812 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7813 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7814 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7815 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7816 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7817 | EXPECT_TRUE(child_raw->test_properties() |
| 7818 | ->mask_layer->is_drawn_render_surface_layer_list_member()); |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7819 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7820 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7821 | |
| 7822 | expected.clear(); |
| 7823 | expected.insert(child_raw); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7824 | expected.insert(child_raw->test_properties()->mask_layer); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7825 | actual.clear(); |
| 7826 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7827 | EXPECT_EQ(expected, actual); |
| 7828 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7829 | child_raw->test_properties()->SetMaskLayer(nullptr); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7830 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7831 | |
| 7832 | // Now everyone's a member! |
| 7833 | grand_parent_raw->SetDrawsContent(true); |
| 7834 | parent_raw->SetDrawsContent(true); |
| 7835 | child_raw->SetDrawsContent(true); |
| 7836 | grand_child1_raw->SetDrawsContent(true); |
| 7837 | grand_child2_raw->SetDrawsContent(true); |
| 7838 | |
| 7839 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7840 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7841 | EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7842 | EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7843 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7844 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7845 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7846 | |
| 7847 | expected.clear(); |
| 7848 | expected.insert(grand_parent_raw); |
| 7849 | expected.insert(parent_raw); |
| 7850 | expected.insert(child_raw); |
| 7851 | expected.insert(grand_child1_raw); |
| 7852 | expected.insert(grand_child2_raw); |
| 7853 | |
| 7854 | actual.clear(); |
| 7855 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7856 | EXPECT_EQ(expected, actual); |
| 7857 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7858 | |
| 7859 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7860 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7861 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7862 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 7863 | LayerTreeSettings settings = host()->GetSettings(); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7864 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7865 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7866 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7867 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7868 | std::unique_ptr<LayerImpl> root = |
| 7869 | LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7870 | LayerImpl* root_layer = root.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7871 | std::unique_ptr<LayerImpl> child1 = |
| 7872 | LayerImpl::Create(host_impl.active_tree(), 2); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7873 | LayerImpl* child1_layer = child1.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7874 | std::unique_ptr<LayerImpl> child2 = |
| 7875 | LayerImpl::Create(host_impl.active_tree(), 3); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7876 | LayerImpl* child2_layer = child2.get(); |
| 7877 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7878 | gfx::Transform scale_transform_child1, scale_transform_child2; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7879 | scale_transform_child1.Scale(2, 3); |
| 7880 | scale_transform_child2.Scale(4, 5); |
| 7881 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7882 | root->SetBounds(gfx::Size(1, 1)); |
| 7883 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7884 | child1_layer->test_properties()->transform = scale_transform_child1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7885 | child1_layer->SetBounds(gfx::Size(1, 1)); |
| 7886 | child1_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7887 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7888 | child1_layer->test_properties()->SetMaskLayer( |
| 7889 | LayerImpl::Create(host_impl.active_tree(), 4)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7890 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7891 | root->test_properties()->AddChild(std::move(child1)); |
| 7892 | root->test_properties()->AddChild(std::move(child2)); |
| 7893 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 7894 | host_impl.active_tree()->SetElementIdsForTesting(); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7895 | |
| 7896 | ExecuteCalculateDrawProperties(root_layer); |
| 7897 | |
| 7898 | TransformOperations scale; |
| 7899 | scale.AppendScale(5.f, 8.f, 3.f); |
| 7900 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7901 | scoped_refptr<AnimationTimeline> timeline = |
| 7902 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7903 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7904 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 7905 | child2_layer->test_properties()->transform = scale_transform_child2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7906 | child2_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7907 | child2_layer->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 7908 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 7909 | 1.0, TransformOperations(), scale); |
| 7910 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7911 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7912 | ExecuteCalculateDrawProperties(root_layer); |
| 7913 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7914 | EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale()); |
| 7915 | EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale()); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7916 | EXPECT_FLOAT_EQ( |
| 7917 | 3.f, |
| 7918 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7919 | EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7920 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7921 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 7922 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 7923 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7924 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7925 | // Changing page-scale would affect ideal_contents_scale and |
| 7926 | // maximum_animation_contents_scale. |
| 7927 | |
| 7928 | float page_scale_factor = 3.f; |
| 7929 | float device_scale_factor = 1.0f; |
| 7930 | std::vector<LayerImpl*> render_surface_layer_list; |
| 7931 | gfx::Size device_viewport_size = |
| 7932 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 7933 | root_layer->bounds().height() * device_scale_factor); |
| 7934 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7935 | root_layer, device_viewport_size, &render_surface_layer_list); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7936 | |
| 7937 | inputs.page_scale_factor = page_scale_factor; |
| 7938 | inputs.can_adjust_raster_scales = true; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 7939 | inputs.page_scale_layer = root_layer; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7940 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7941 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7942 | EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale()); |
| 7943 | EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7944 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7945 | 9.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7946 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7947 | EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7948 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7949 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 7950 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 7951 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7952 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7953 | // Changing device-scale would affect ideal_contents_scale and |
| 7954 | // maximum_animation_contents_scale. |
| 7955 | |
| 7956 | device_scale_factor = 4.0f; |
| 7957 | inputs.device_scale_factor = device_scale_factor; |
| 7958 | inputs.can_adjust_raster_scales = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7959 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7960 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7961 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7962 | EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale()); |
| 7963 | EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7964 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7965 | 36.f, |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 7966 | child1_layer->test_properties()->mask_layer->GetIdealContentsScale()); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7967 | EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7968 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7969 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 7970 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 7971 | EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer)); |
| 7972 | } |
| 7973 | |
| 7974 | TEST_F(LayerTreeHostCommonTest, AnimationScales) { |
| 7975 | FakeImplTaskRunnerProvider task_runner_provider; |
| 7976 | TestSharedBitmapManager shared_bitmap_manager; |
| 7977 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 7978 | LayerTreeSettings settings = host()->GetSettings(); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 7979 | settings.layer_transforms_should_scale_layer_contents = true; |
| 7980 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7981 | &shared_bitmap_manager, &task_graph_runner); |
| 7982 | |
| 7983 | std::unique_ptr<LayerImpl> root = |
| 7984 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 7985 | LayerImpl* root_layer = root.get(); |
| 7986 | std::unique_ptr<LayerImpl> child1 = |
| 7987 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7988 | LayerImpl* child1_layer = child1.get(); |
| 7989 | std::unique_ptr<LayerImpl> child2 = |
| 7990 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7991 | LayerImpl* child2_layer = child2.get(); |
| 7992 | |
| 7993 | root->test_properties()->AddChild(std::move(child1)); |
| 7994 | child1_layer->test_properties()->AddChild(std::move(child2)); |
| 7995 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 7996 | |
| 7997 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 7998 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 7999 | gfx::Transform scale_transform_child1, scale_transform_child2; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8000 | scale_transform_child1.Scale(2, 3); |
| 8001 | scale_transform_child2.Scale(4, 5); |
| 8002 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8003 | root_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8004 | child1_layer->test_properties()->transform = scale_transform_child1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8005 | child1_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8006 | child2_layer->test_properties()->transform = scale_transform_child2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8007 | child2_layer->SetBounds(gfx::Size(1, 1)); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8008 | |
| 8009 | TransformOperations scale; |
| 8010 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8011 | |
| 8012 | scoped_refptr<AnimationTimeline> timeline = |
| 8013 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8014 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 8015 | |
| 8016 | AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline, |
| 8017 | 1.0, TransformOperations(), scale); |
| 8018 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8019 | // Correctly computes animation scale when rebuilding property trees. |
| 8020 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8021 | ExecuteCalculateDrawProperties(root_layer); |
| 8022 | |
| 8023 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8024 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer)); |
| 8025 | EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer)); |
| 8026 | |
| 8027 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 8028 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer)); |
| 8029 | EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer)); |
| 8030 | |
| 8031 | // Correctly updates animation scale when layer property changes. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8032 | child1_layer->test_properties()->transform = gfx::Transform(); |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 8033 | root_layer->layer_tree_impl() |
| 8034 | ->property_trees() |
| 8035 | ->transform_tree.OnTransformAnimated(gfx::Transform(), |
| 8036 | child1_layer->transform_tree_index(), |
| 8037 | root_layer->layer_tree_impl()); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8038 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false; |
| 8039 | ExecuteCalculateDrawProperties(root_layer); |
| 8040 | EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer)); |
| 8041 | EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer)); |
| 8042 | |
| 8043 | // Do not update animation scale if already updated. |
| 8044 | host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting( |
| 8045 | child2_layer->transform_tree_index(), 100.f, 100.f); |
| 8046 | EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer)); |
| 8047 | EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer)); |
| 8048 | } |
| 8049 | |
| 8050 | TEST_F(LayerTreeHostCommonTest, |
| 8051 | AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) { |
| 8052 | // Returns empty scale if layer_transforms_should_scale_layer_contents is |
| 8053 | // false. |
| 8054 | FakeImplTaskRunnerProvider task_runner_provider; |
| 8055 | TestSharedBitmapManager shared_bitmap_manager; |
| 8056 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | cebe494 | 2016-09-07 23:27:01 | [diff] [blame] | 8057 | LayerTreeSettings settings = host()->GetSettings(); |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8058 | settings.layer_transforms_should_scale_layer_contents = false; |
| 8059 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 8060 | &shared_bitmap_manager, &task_graph_runner); |
| 8061 | |
| 8062 | std::unique_ptr<LayerImpl> root = |
| 8063 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8064 | LayerImpl* root_layer = root.get(); |
| 8065 | std::unique_ptr<LayerImpl> child = |
| 8066 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8067 | LayerImpl* child_layer = child.get(); |
| 8068 | |
| 8069 | root->test_properties()->AddChild(std::move(child)); |
| 8070 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8071 | |
| 8072 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 8073 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8074 | gfx::Transform scale_transform_child; |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8075 | scale_transform_child.Scale(4, 5); |
| 8076 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8077 | root_layer->SetBounds(gfx::Size(1, 1)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8078 | child_layer->test_properties()->transform = scale_transform_child; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8079 | child_layer->SetBounds(gfx::Size(1, 1)); |
| 8080 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8081 | TransformOperations scale; |
| 8082 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8083 | |
| 8084 | scoped_refptr<AnimationTimeline> timeline = |
| 8085 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8086 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 8087 | |
| 8088 | AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline, |
| 8089 | 1.0, TransformOperations(), scale); |
| 8090 | |
sunxd | f468675e | 2016-06-30 23:56:18 | [diff] [blame] | 8091 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8092 | ExecuteCalculateDrawProperties(root_layer); |
| 8093 | |
| 8094 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer)); |
| 8095 | EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer)); |
| 8096 | |
| 8097 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer)); |
| 8098 | EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8099 | } |
| 8100 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8101 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8102 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8103 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 8104 | LayerImpl* content = AddChild<LayerImpl>(clip); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8105 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8106 | root->SetBounds(gfx::Size(768 / 2, 3000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8107 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8108 | clip->SetBounds(gfx::Size(768 / 2, 10000)); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8109 | clip->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8110 | content->SetBounds(gfx::Size(768 / 2, 10000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8111 | content->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8112 | content->test_properties()->force_render_surface = true; |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8113 | |
| 8114 | gfx::Size device_viewport_size(768, 582); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8115 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8116 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8117 | root, device_viewport_size, gfx::Transform(), |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8118 | &render_surface_layer_list_impl); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8119 | inputs.device_scale_factor = 2.f; |
| 8120 | inputs.page_scale_factor = 1.f; |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 8121 | inputs.page_scale_layer = nullptr; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8122 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8123 | |
| 8124 | // Layers in the root render surface have their visible content rect clipped |
| 8125 | // by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8126 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8127 | |
| 8128 | // Layers drawing to a child render surface should still have their visible |
| 8129 | // content rect clipped by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8130 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8131 | } |
| 8132 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8133 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8134 | FakeImplTaskRunnerProvider task_runner_provider; |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8135 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8136 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8137 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8138 | &task_graph_runner); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8139 | |
| 8140 | // Set two layers: the root layer clips it's child, |
| 8141 | // the child draws its content. |
| 8142 | |
| 8143 | gfx::Size root_size = gfx::Size(300, 500); |
| 8144 | |
| 8145 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8146 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8147 | |
| 8148 | // Device viewport accomidated the root and the top controls. |
| 8149 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8150 | |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 8151 | host_impl.SetViewportSize(device_viewport_size); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8152 | host_impl.active_tree()->SetRootLayerForTesting( |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8153 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8154 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8155 | LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8156 | root->SetBounds(root_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8157 | root->SetMasksToBounds(true); |
| 8158 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8159 | root->test_properties()->AddChild( |
| 8160 | LayerImpl::Create(host_impl.active_tree(), 2)); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8161 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 8162 | LayerImpl* sublayer = root->test_properties()->children[0]; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8163 | sublayer->SetBounds(sublayer_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8164 | sublayer->SetDrawsContent(true); |
| 8165 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8166 | host_impl.active_tree()->BuildPropertyTreesForTesting(); |
| 8167 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8168 | LayerImplList layer_impl_list; |
| 8169 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8170 | root, device_viewport_size, &layer_impl_list); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8171 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8172 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8173 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8174 | |
| 8175 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8176 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8177 | |
| 8178 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8179 | root_size.height() + 50); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8180 | EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8181 | } |
| 8182 | |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8183 | TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8184 | scoped_refptr<Layer> root = Layer::Create(); |
| 8185 | scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create(); |
| 8186 | scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); |
| 8187 | scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create(); |
| 8188 | scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8189 | |
| 8190 | root->AddChild(inner_viewport_container_layer); |
| 8191 | inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer); |
| 8192 | inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); |
| 8193 | outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); |
| 8194 | |
| 8195 | inner_viewport_scroll_layer->SetScrollClipLayerId( |
| 8196 | inner_viewport_container_layer->id()); |
| 8197 | outer_viewport_scroll_layer->SetScrollClipLayerId( |
| 8198 | outer_viewport_container_layer->id()); |
| 8199 | |
| 8200 | inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8201 | outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8202 | |
| 8203 | host()->SetRootLayer(root); |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 8204 | host()->GetLayerTree()->RegisterViewportLayers( |
| 8205 | nullptr, root, inner_viewport_scroll_layer, outer_viewport_scroll_layer); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8206 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8207 | scoped_refptr<Layer> fixed_to_inner = Layer::Create(); |
| 8208 | scoped_refptr<Layer> fixed_to_outer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8209 | |
| 8210 | inner_viewport_scroll_layer->AddChild(fixed_to_inner); |
| 8211 | outer_viewport_scroll_layer->AddChild(fixed_to_outer); |
| 8212 | |
| 8213 | LayerPositionConstraint fixed_to_right; |
| 8214 | fixed_to_right.set_is_fixed_position(true); |
| 8215 | fixed_to_right.set_is_fixed_to_right_edge(true); |
| 8216 | |
| 8217 | fixed_to_inner->SetPositionConstraint(fixed_to_right); |
| 8218 | fixed_to_outer->SetPositionConstraint(fixed_to_right); |
| 8219 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8220 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8221 | |
| 8222 | TransformTree& transform_tree = host()->property_trees()->transform_tree; |
| 8223 | EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8224 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8225 | |
| 8226 | LayerPositionConstraint fixed_to_left; |
| 8227 | fixed_to_left.set_is_fixed_position(true); |
| 8228 | fixed_to_inner->SetPositionConstraint(fixed_to_left); |
| 8229 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8230 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8231 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8232 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8233 | |
| 8234 | fixed_to_outer->SetPositionConstraint(fixed_to_left); |
| 8235 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8236 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8237 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8238 | EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8239 | } |
| 8240 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8241 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8242 | host_impl()->CreatePendingTree(); |
| 8243 | std::unique_ptr<LayerImpl> pending_root = |
| 8244 | LayerImpl::Create(host_impl()->pending_tree(), 1); |
| 8245 | LayerImpl* root = pending_root.get(); |
| 8246 | host_impl()->pending_tree()->SetRootLayerForTesting(std::move(pending_root)); |
| 8247 | std::unique_ptr<LayerImpl> animated_ptr = |
| 8248 | LayerImpl::Create(host_impl()->pending_tree(), 2); |
| 8249 | LayerImpl* animated = animated_ptr.get(); |
| 8250 | root->test_properties()->AddChild(std::move(animated_ptr)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8251 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8252 | animated->SetDrawsContent(true); |
| 8253 | host_impl()->pending_tree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8254 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8255 | root->SetBounds(gfx::Size(100, 100)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8256 | root->SetMasksToBounds(true); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8257 | root->test_properties()->force_render_surface = true; |
| 8258 | animated->test_properties()->opacity = 0.f; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8259 | animated->SetBounds(gfx::Size(20, 20)); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8260 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8261 | AddOpacityTransitionToElementWithPlayer( |
| 8262 | animated->element_id(), timeline_impl(), 10.0, 0.f, 1.f, false); |
| 8263 | animated->test_properties()->opacity_can_animate = true; |
| 8264 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8265 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8266 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8267 | EXPECT_FALSE(animated->visible_layer_rect().IsEmpty()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8268 | } |
| 8269 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8270 | TEST_F(LayerTreeHostCommonTest, |
| 8271 | VisibleContentRectForAnimatedLayerWithSingularTransform) { |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8272 | LayerImpl* root = root_layer_for_testing(); |
| 8273 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 8274 | LayerImpl* animated = AddChild<LayerImpl>(clip); |
| 8275 | LayerImpl* surface = AddChild<LayerImpl>(animated); |
| 8276 | LayerImpl* descendant_of_animation = AddChild<LayerImpl>(surface); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8277 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8278 | SetElementIdsForTesting(); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8279 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8280 | animated->SetDrawsContent(true); |
| 8281 | surface->SetDrawsContent(true); |
| 8282 | descendant_of_animation->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8283 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8284 | gfx::Transform uninvertible_matrix; |
| 8285 | uninvertible_matrix.Scale3d(6.f, 6.f, 0.f); |
| 8286 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8287 | root->SetBounds(gfx::Size(100, 100)); |
| 8288 | clip->SetBounds(gfx::Size(10, 10)); |
| 8289 | clip->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8290 | animated->test_properties()->transform = uninvertible_matrix; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8291 | animated->SetBounds(gfx::Size(120, 120)); |
| 8292 | surface->SetBounds(gfx::Size(100, 100)); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8293 | surface->test_properties()->force_render_surface = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8294 | descendant_of_animation->SetBounds(gfx::Size(200, 200)); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8295 | |
| 8296 | TransformOperations start_transform_operations; |
| 8297 | start_transform_operations.AppendMatrix(uninvertible_matrix); |
| 8298 | TransformOperations end_transform_operations; |
| 8299 | |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8300 | AddAnimatedTransformToElementWithPlayer( |
| 8301 | animated->element_id(), timeline_impl(), 10.0, start_transform_operations, |
| 8302 | end_transform_operations); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8303 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8304 | |
| 8305 | // The animated layer has a singular transform and maps to a non-empty rect in |
| 8306 | // clipped target space, so is treated as fully visible. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8307 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8308 | |
| 8309 | // The singular transform on |animated| is flattened when inherited by |
| 8310 | // |surface|, and this happens to make it invertible. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8311 | EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect()); |
| 8312 | EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8313 | |
| 8314 | gfx::Transform zero_matrix; |
| 8315 | zero_matrix.Scale3d(0.f, 0.f, 0.f); |
jaydasika | 09e1613 | 2016-08-24 21:39:34 | [diff] [blame] | 8316 | root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 8317 | zero_matrix, animated->transform_tree_index(), root->layer_tree_impl()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8318 | // While computing visible rects by combining clips in screen space, we set |
| 8319 | // the entire layer as visible if the screen space transform is singular. This |
| 8320 | // is not always true when we combine clips in target space because if the |
| 8321 | // intersection of combined_clip in taret space with layer_rect projected to |
| 8322 | // target space is empty, we set it to an empty rect. |
| 8323 | bool skip_verify_visible_rect_calculations = true; |
| 8324 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( |
| 8325 | root, skip_verify_visible_rect_calculations); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8326 | |
| 8327 | // The animated layer maps to the empty rect in clipped target space, so is |
| 8328 | // treated as having an empty visible rect. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8329 | EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8330 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8331 | // The animated layer will be treated as fully visible when we combine clips |
| 8332 | // in screen space. |
| 8333 | gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic( |
| 8334 | root->layer_tree_impl()->property_trees(), animated); |
| 8335 | EXPECT_EQ(gfx::Rect(120, 120), visible_rect); |
| 8336 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8337 | // This time, flattening does not make |animated|'s transform invertible. This |
| 8338 | // means the clip cannot be projected into |surface|'s space, so we treat |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8339 | // |surface| and layers that draw into it as having empty visible rect. |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8340 | EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect()); |
| 8341 | EXPECT_EQ(gfx::Rect(), descendant_of_animation->visible_layer_rect()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8342 | } |
| 8343 | |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8344 | // Verify that having animated opacity but current opacity 1 still creates |
| 8345 | // a render surface. |
| 8346 | TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) { |
| 8347 | LayerImpl* root = root_layer_for_testing(); |
| 8348 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8349 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8350 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8351 | root->SetBounds(gfx::Size(50, 50)); |
| 8352 | child->SetBounds(gfx::Size(50, 50)); |
| 8353 | child->SetDrawsContent(true); |
| 8354 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8355 | grandchild->SetDrawsContent(true); |
ajuma | 20384bf | 2016-07-22 13:26:15 | [diff] [blame] | 8356 | |
| 8357 | SetElementIdsForTesting(); |
| 8358 | AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8359 | 10.0, 1.f, 0.2f, false); |
| 8360 | ExecuteCalculateDrawProperties(root); |
| 8361 | |
| 8362 | EXPECT_EQ(1.f, child->Opacity()); |
| 8363 | EXPECT_TRUE(root->has_render_surface()); |
| 8364 | EXPECT_TRUE(child->has_render_surface()); |
| 8365 | EXPECT_FALSE(grandchild->has_render_surface()); |
| 8366 | } |
| 8367 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8368 | // Verify that having an animated filter (but no current filter, as these |
| 8369 | // are mutually exclusive) correctly creates a render surface. |
| 8370 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8371 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8372 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8373 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8374 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8375 | root->SetBounds(gfx::Size(50, 50)); |
| 8376 | child->SetBounds(gfx::Size(50, 50)); |
| 8377 | grandchild->SetBounds(gfx::Size(50, 50)); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8378 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8379 | SetElementIdsForTesting(); |
| 8380 | AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8381 | 10.0, 0.1f, 0.2f); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8382 | ExecuteCalculateDrawProperties(root); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8383 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8384 | EXPECT_TRUE(root->has_render_surface()); |
| 8385 | EXPECT_TRUE(child->has_render_surface()); |
| 8386 | EXPECT_FALSE(grandchild->has_render_surface()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8387 | |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 8388 | EXPECT_TRUE(root->render_surface()->Filters().IsEmpty()); |
| 8389 | EXPECT_TRUE(child->render_surface()->Filters().IsEmpty()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8390 | |
| 8391 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8392 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 8393 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8394 | } |
| 8395 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8396 | // Verify that having a filter animation with a delayed start time creates a |
| 8397 | // render surface. |
| 8398 | TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8399 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8400 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8401 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8402 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8403 | root->SetBounds(gfx::Size(50, 50)); |
| 8404 | child->SetBounds(gfx::Size(50, 50)); |
| 8405 | grandchild->SetBounds(gfx::Size(50, 50)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8406 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8407 | SetElementIdsForTesting(); |
| 8408 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8409 | std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8410 | KeyframedFilterAnimationCurve::Create()); |
| 8411 | FilterOperations start_filters; |
| 8412 | start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f)); |
| 8413 | FilterOperations end_filters; |
| 8414 | end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f)); |
| 8415 | curve->AddKeyframe( |
| 8416 | FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 8417 | curve->AddKeyframe(FilterKeyframe::Create( |
| 8418 | base::TimeDelta::FromMilliseconds(100), end_filters, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8419 | std::unique_ptr<Animation> animation = |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8420 | Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8421 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8422 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8423 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8424 | AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(), |
| 8425 | std::move(animation)); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8426 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8427 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8428 | EXPECT_TRUE(root->has_render_surface()); |
| 8429 | EXPECT_TRUE(child->has_render_surface()); |
| 8430 | EXPECT_FALSE(grandchild->has_render_surface()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8431 | |
ajuma | cb2b7443 | 2016-07-21 19:11:15 | [diff] [blame] | 8432 | EXPECT_TRUE(root->render_surface()->Filters().IsEmpty()); |
| 8433 | EXPECT_TRUE(child->render_surface()->Filters().IsEmpty()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8434 | |
| 8435 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8436 | EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation()); |
| 8437 | EXPECT_FALSE(child->FilterIsAnimating()); |
| 8438 | EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation()); |
| 8439 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8440 | EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation()); |
| 8441 | } |
| 8442 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8443 | // Ensures that the property tree code accounts for offsets between fixed |
| 8444 | // position layers and their respective containers. |
| 8445 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8446 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8447 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8448 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8449 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8450 | root->SetBounds(gfx::Size(50, 50)); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8451 | root->SetMasksToBounds(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8452 | root->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8453 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 8454 | child->SetBounds(gfx::Size(50, 50)); |
| 8455 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 8456 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8457 | grandchild->SetDrawsContent(true); |
| 8458 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8459 | LayerPositionConstraint constraint; |
| 8460 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8461 | grandchild->test_properties()->position_constraint = constraint; |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8462 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8463 | ExecuteCalculateDrawProperties(root); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8464 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8465 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8466 | } |
| 8467 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8468 | // Ensures that the property tree code accounts for offsets between fixed |
| 8469 | // position containers and their transform tree parents, when a fixed position |
| 8470 | // layer's container is its layer tree parent, but this parent doesn't have its |
| 8471 | // own transform tree node. |
| 8472 | TEST_F(LayerTreeHostCommonTest, |
| 8473 | PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8474 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8475 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8476 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8477 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8478 | root->SetBounds(gfx::Size(50, 50)); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8479 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8480 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 8481 | child->SetPosition(gfx::PointF(1000, 1000)); |
| 8482 | child->SetBounds(gfx::Size(50, 50)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8483 | child->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8484 | grandchild->SetPosition(gfx::PointF(-1000, -1000)); |
| 8485 | grandchild->SetBounds(gfx::Size(50, 50)); |
| 8486 | grandchild->SetDrawsContent(true); |
| 8487 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8488 | LayerPositionConstraint constraint; |
| 8489 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8490 | grandchild->test_properties()->position_constraint = constraint; |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8491 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8492 | ExecuteCalculateDrawProperties(root); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8493 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8494 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8495 | } |
| 8496 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8497 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8498 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8499 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8500 | LayerImpl* fixed = AddChild<LayerImpl>(frame_clip); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8501 | gfx::Transform translate_z; |
| 8502 | translate_z.Translate3d(0, 0, 10); |
| 8503 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8504 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8505 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8506 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8507 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 8508 | frame_clip->SetBounds(gfx::Size(100, 100)); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8509 | frame_clip->SetMasksToBounds(true); |
| 8510 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8511 | fixed->SetBounds(gfx::Size(1000, 1000)); |
| 8512 | fixed->SetDrawsContent(true); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8513 | |
| 8514 | LayerPositionConstraint constraint; |
| 8515 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8516 | fixed->test_properties()->position_constraint = constraint; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8517 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8518 | ExecuteCalculateDrawProperties(root); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8519 | |
| 8520 | gfx::Rect expected(0, 0, 100, 100); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8521 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8522 | } |
| 8523 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8524 | TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8525 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8526 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8527 | LayerImpl* scroller = AddChild<LayerImpl>(frame_clip); |
| 8528 | LayerImpl* fixed = AddChild<LayerImpl>(scroller); |
| 8529 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8530 | root->SetBounds(gfx::Size(800, 800)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8531 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8532 | root->test_properties()->is_container_for_fixed_position_layers = true; |
| 8533 | frame_clip->SetPosition(gfx::PointF(500, 100)); |
| 8534 | frame_clip->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8535 | frame_clip->SetMasksToBounds(true); |
| 8536 | frame_clip->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8537 | scroller->SetBounds(gfx::Size(1000, 1000)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8538 | scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100)); |
| 8539 | scroller->SetScrollClipLayer(frame_clip->id()); |
| 8540 | scroller->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8541 | fixed->SetPosition(gfx::PointF(100, 100)); |
| 8542 | fixed->SetBounds(gfx::Size(50, 50)); |
| 8543 | fixed->SetMasksToBounds(true); |
| 8544 | fixed->SetDrawsContent(true); |
| 8545 | fixed->test_properties()->force_render_surface = true; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8546 | |
| 8547 | LayerPositionConstraint constraint; |
| 8548 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8549 | fixed->test_properties()->position_constraint = constraint; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8550 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8551 | ExecuteCalculateDrawProperties(root); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8552 | |
| 8553 | gfx::Rect expected(0, 0, 50, 50); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8554 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8555 | } |
| 8556 | |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8557 | TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) { |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8558 | gfx::Transform translate; |
| 8559 | gfx::Transform rotate; |
| 8560 | |
| 8561 | translate.Translate(10, 10); |
| 8562 | rotate.Rotate(45); |
| 8563 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8564 | scoped_refptr<Layer> root = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8565 | root->SetBounds(gfx::Size(800, 800)); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8566 | root->SetIsContainerForFixedPositionLayers(true); |
| 8567 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8568 | host()->SetRootLayer(root); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8569 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8570 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8571 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8572 | |
| 8573 | root->SetTransform(translate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8574 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8575 | |
| 8576 | root->SetTransform(rotate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8577 | EXPECT_TRUE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8578 | } |
| 8579 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8580 | TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8581 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8582 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8583 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8584 | gfx::Transform scale_matrix; |
| 8585 | scale_matrix.Scale(2.f, 2.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8586 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8587 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8588 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8589 | child->test_properties()->transform = scale_matrix; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8590 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8591 | child->SetDrawsContent(true); |
| 8592 | |
| 8593 | ExecuteCalculateDrawProperties(root); |
| 8594 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8595 | |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 8596 | child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8597 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8598 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8599 | ExecuteCalculateDrawProperties(root); |
| 8600 | EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8601 | } |
| 8602 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8603 | TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8604 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8605 | LayerImpl* scroll_parent = AddChild<LayerImpl>(root); |
| 8606 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8607 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8608 | gfx::Transform scale; |
| 8609 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8610 | |
| 8611 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8612 | scroll_child->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8613 | scroll_child->SetBounds(gfx::Size(40, 40)); |
| 8614 | scroll_child->SetDrawsContent(true); |
| 8615 | scroll_parent->SetBounds(gfx::Size(30, 30)); |
| 8616 | scroll_parent->SetDrawsContent(true); |
| 8617 | |
| 8618 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 8619 | scroll_parent->test_properties()->scroll_children = |
| 8620 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 8621 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8622 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8623 | ExecuteCalculateDrawProperties(root); |
| 8624 | EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8625 | |
| 8626 | scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8627 | scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
| 8628 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8629 | ExecuteCalculateDrawProperties(root); |
| 8630 | EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8631 | } |
| 8632 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8633 | static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8634 | |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8635 | TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) { |
| 8636 | // If the layer has a node in effect_tree, the return value of |
| 8637 | // num_copy_requests_in_target_subtree() must be equal to the actual number |
| 8638 | // of copy requests in the sub-layer_tree; Otherwise, the number is expected |
| 8639 | // to be the value of its nearest ancestor that owns an effect node and |
| 8640 | // greater than or equal to the actual number of copy requests in the |
| 8641 | // sub-layer_tree. |
| 8642 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8643 | scoped_refptr<Layer> root = Layer::Create(); |
| 8644 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 8645 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 8646 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 8647 | scoped_refptr<Layer> greatgrandchild = Layer::Create(); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8648 | |
| 8649 | root->AddChild(child1); |
| 8650 | root->AddChild(child2); |
| 8651 | child1->AddChild(grandchild); |
| 8652 | grandchild->AddChild(greatgrandchild); |
| 8653 | host()->SetRootLayer(root); |
| 8654 | |
| 8655 | child1->RequestCopyOfOutput( |
| 8656 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8657 | greatgrandchild->RequestCopyOfOutput( |
| 8658 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8659 | child2->SetOpacity(0.f); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8660 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8661 | |
| 8662 | EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2); |
| 8663 | EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2); |
| 8664 | EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0); |
| 8665 | EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2); |
| 8666 | EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1); |
| 8667 | } |
| 8668 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8669 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8670 | scoped_refptr<Layer> root = Layer::Create(); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 8671 | FakeContentLayerClient client; |
| 8672 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8673 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8674 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8675 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8676 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8677 | scoped_refptr<FakePictureLayer> greatgrandchild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8678 | FakePictureLayer::Create(&client)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8679 | |
| 8680 | root->SetBounds(gfx::Size(100, 100)); |
| 8681 | child->SetBounds(gfx::Size(10, 10)); |
| 8682 | grandchild->SetBounds(gfx::Size(10, 10)); |
| 8683 | greatgrandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8684 | |
| 8685 | root->AddChild(child); |
| 8686 | child->AddChild(grandchild); |
| 8687 | grandchild->AddChild(greatgrandchild); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8688 | host()->SetRootLayer(root); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 8689 | host()->GetLayerTree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8690 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8691 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8692 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8693 | const LayerList* update_list = GetUpdateLayerList(); |
| 8694 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8695 | |
| 8696 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8697 | // and we will configure |child| in several ways that should force the subtree |
| 8698 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8699 | // remain empty. |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8700 | gfx::Transform singular; |
| 8701 | singular.matrix().set(0, 0, 0); |
| 8702 | |
| 8703 | child->SetTransform(singular); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8704 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8705 | update_list = GetUpdateLayerList(); |
| 8706 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8707 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8708 | |
| 8709 | child->SetHideLayerAndSubtree(true); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8710 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8711 | update_list = GetUpdateLayerList(); |
| 8712 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8713 | child->SetHideLayerAndSubtree(false); |
| 8714 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8715 | gfx::Transform zero_z_scale; |
| 8716 | zero_z_scale.Scale3d(1, 1, 0); |
| 8717 | child->SetTransform(zero_z_scale); |
| 8718 | |
| 8719 | // Add a transform animation with a start delay. Now, even though |child| has |
| 8720 | // a singular transform, the subtree should still get processed. |
| 8721 | int animation_id = 0; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8722 | std::unique_ptr<Animation> animation = Animation::Create( |
| 8723 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8724 | animation_id, 1, TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8725 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8726 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8727 | AddAnimationToElementWithPlayer(child->element_id(), timeline(), |
| 8728 | std::move(animation)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8729 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8730 | update_list = GetUpdateLayerList(); |
| 8731 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8732 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8733 | RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(), |
| 8734 | animation_id); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8735 | child->SetTransform(gfx::Transform()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8736 | child->SetOpacity(0.f); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8737 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8738 | update_list = GetUpdateLayerList(); |
| 8739 | EXPECT_FALSE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8740 | |
| 8741 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8742 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8743 | // processed anyhow. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 8744 | grandchild->RequestCopyOfOutput( |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8745 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8746 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8747 | update_list = GetUpdateLayerList(); |
| 8748 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8749 | |
| 8750 | // Add an opacity animation with a start delay. |
| 8751 | animation_id = 1; |
| 8752 | animation = Animation::Create( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8753 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8754 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8755 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8756 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8757 | AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(), |
| 8758 | std::move(animation)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8759 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | 713aedbd | 2016-08-10 22:22:14 | [diff] [blame] | 8760 | update_list = GetUpdateLayerList(); |
| 8761 | EXPECT_TRUE(VerifyLayerInList(grandchild, update_list)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8762 | } |
| 8763 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8764 | TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8765 | FakeImplTaskRunnerProvider task_runner_provider; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8766 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8767 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8768 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8769 | &task_graph_runner); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8770 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8771 | std::unique_ptr<LayerImpl> root = |
| 8772 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8773 | std::unique_ptr<LayerImpl> child = |
| 8774 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8775 | std::unique_ptr<LayerImpl> grandchild = |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8776 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 8777 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8778 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8779 | FakePictureLayerImpl::Create(host_impl.active_tree(), 4)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8780 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8781 | root->SetBounds(gfx::Size(100, 100)); |
| 8782 | child->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8783 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8784 | grandchild->SetBounds(gfx::Size(10, 10)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8785 | grandchild->SetDrawsContent(true); |
| 8786 | greatgrandchild->SetDrawsContent(true); |
| 8787 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8788 | LayerImpl* root_ptr = root.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8789 | LayerImpl* child_ptr = child.get(); |
| 8790 | LayerImpl* grandchild_ptr = grandchild.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8791 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8792 | child->test_properties()->AddChild(std::move(grandchild)); |
| 8793 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8794 | host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8795 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8796 | host_impl.active_tree()->SetElementIdsForTesting(); |
| 8797 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8798 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8799 | // ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8800 | // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8801 | |
| 8802 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8803 | // and we will configure |child| in several ways that should force the subtree |
| 8804 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8805 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8806 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8807 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8808 | gfx::Transform singular; |
| 8809 | singular.matrix().set(0, 0, 0); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8810 | // This line is used to make the results of skipping and not skipping layers |
| 8811 | // different. |
| 8812 | singular.matrix().set(0, 1, 1); |
| 8813 | |
| 8814 | gfx::Transform rotate; |
| 8815 | rotate.Rotate(90); |
| 8816 | |
| 8817 | gfx::Transform rotate_back_and_translate; |
| 8818 | rotate_back_and_translate.RotateAboutYAxis(180); |
| 8819 | rotate_back_and_translate.Translate(-10, 0); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8820 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8821 | child_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8822 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8823 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8824 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8825 | child_ptr->test_properties()->transform = gfx::Transform(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8826 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8827 | child_ptr->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8828 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8829 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8830 | child_ptr->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8831 | |
jaydasika | b5bc1a2 | 2016-08-24 02:59:05 | [diff] [blame] | 8832 | child_ptr->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 8833 | 0.f, child_ptr->effect_tree_index(), child_ptr->layer_tree_impl()); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8834 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8835 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8836 | child_ptr->test_properties()->opacity = 1.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8837 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8838 | root_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8839 | // Force transform tree to have a node for child, so that ancestor's |
| 8840 | // invertible transform can be tested. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8841 | child_ptr->test_properties()->transform = rotate; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8842 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8843 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8844 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8845 | root_ptr->test_properties()->transform = gfx::Transform(); |
| 8846 | child_ptr->test_properties()->transform = gfx::Transform(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8847 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8848 | root_ptr->test_properties()->opacity = 0.f; |
| 8849 | child_ptr->test_properties()->opacity = 0.7f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8850 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8851 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8852 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8853 | root_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8854 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8855 | child_ptr->test_properties()->opacity = 0.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8856 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8857 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8858 | // processed anyhow. |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 8859 | grandchild_ptr->test_properties()->copy_requests.push_back( |
| 8860 | CopyOutputRequest::CreateEmptyRequest()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8861 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8862 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8863 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 8864 | |
| 8865 | host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests(); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8866 | child_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8867 | |
| 8868 | // A double sided render surface with backface visible should not be skipped |
| 8869 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8870 | child_ptr->SetHasRenderSurface(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8871 | child_ptr->test_properties()->double_sided = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8872 | child_ptr->test_properties()->transform = rotate_back_and_translate; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8873 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8874 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8875 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8876 | child_ptr->test_properties()->transform = gfx::Transform(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8877 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8878 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8879 | KeyframedTransformAnimationCurve::Create()); |
| 8880 | TransformOperations start; |
| 8881 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 8882 | gfx::Transform transform; |
| 8883 | transform.Scale3d(1.0, 2.0, 3.0); |
| 8884 | TransformOperations operation; |
| 8885 | operation.AppendMatrix(transform); |
| 8886 | curve->AddKeyframe( |
| 8887 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 8888 | curve->AddKeyframe(TransformKeyframe::Create( |
| 8889 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8890 | std::unique_ptr<Animation> transform_animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8891 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 8892 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8893 | host_impl.active_tree()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8894 | root_ptr->element_id(), player.get()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8895 | host_impl.active_tree() |
| 8896 | ->animation_host() |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8897 | ->GetElementAnimationsForElementId(root_ptr->element_id()) |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8898 | ->AddAnimation(std::move(transform_animation)); |
| 8899 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8900 | child_ptr->SetScrollClipLayer(root_ptr->id()); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8901 | root_ptr->test_properties()->transform = singular; |
| 8902 | child_ptr->test_properties()->transform = singular; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8903 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8904 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8905 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8906 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8907 | host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8908 | root_ptr->element_id(), player.get()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8909 | } |
| 8910 | |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8911 | TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8912 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8913 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8914 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 8915 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8916 | SetElementIdsForTesting(); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8917 | |
| 8918 | gfx::Transform singular; |
| 8919 | singular.matrix().set(0, 0, 0); |
| 8920 | singular.matrix().set(0, 1, 1); |
| 8921 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8922 | root->SetBounds(gfx::Size(10, 10)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 8923 | child->test_properties()->transform = singular; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8924 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8925 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8926 | grand_child->SetBounds(gfx::Size(10, 10)); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8927 | grand_child->SetDrawsContent(true); |
| 8928 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8929 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8930 | KeyframedTransformAnimationCurve::Create()); |
| 8931 | TransformOperations start; |
| 8932 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 8933 | gfx::Transform transform; |
| 8934 | transform.Scale3d(1.0, 2.0, 3.0); |
| 8935 | TransformOperations operation; |
| 8936 | operation.AppendMatrix(transform); |
| 8937 | curve->AddKeyframe( |
| 8938 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 8939 | curve->AddKeyframe(TransformKeyframe::Create( |
| 8940 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8941 | std::unique_ptr<Animation> transform_animation( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8942 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 8943 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8944 | host_impl()->active_tree()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8945 | grand_child->element_id(), player.get()); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8946 | host_impl() |
| 8947 | ->active_tree() |
| 8948 | ->animation_host() |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8949 | ->GetElementAnimationsForElementId(grand_child->element_id()) |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8950 | ->AddAnimation(std::move(transform_animation)); |
| 8951 | |
| 8952 | ExecuteCalculateDrawProperties(root); |
| 8953 | EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect()); |
| 8954 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
| 8955 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8956 | host_impl()->active_tree()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8957 | grand_child->element_id(), player.get()); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8958 | } |
| 8959 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8960 | TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { |
| 8961 | FakeImplTaskRunnerProvider task_runner_provider; |
| 8962 | TestSharedBitmapManager shared_bitmap_manager; |
| 8963 | TestTaskGraphRunner task_graph_runner; |
| 8964 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 8965 | &task_graph_runner); |
| 8966 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8967 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8968 | std::unique_ptr<LayerImpl> root = |
| 8969 | LayerImpl::Create(host_impl.pending_tree(), 1); |
| 8970 | std::unique_ptr<LayerImpl> child = |
| 8971 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 8972 | std::unique_ptr<LayerImpl> grandchild = |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8973 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 8974 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8975 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8976 | FakePictureLayerImpl::Create(host_impl.pending_tree(), 4)); |
| 8977 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8978 | root->SetBounds(gfx::Size(100, 100)); |
| 8979 | child->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8980 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 8981 | grandchild->SetBounds(gfx::Size(10, 10)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8982 | grandchild->SetDrawsContent(true); |
| 8983 | greatgrandchild->SetDrawsContent(true); |
| 8984 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8985 | LayerImpl* root_ptr = root.get(); |
| 8986 | LayerImpl* grandchild_ptr = grandchild.get(); |
| 8987 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8988 | child->test_properties()->AddChild(std::move(grandchild)); |
| 8989 | root->test_properties()->AddChild(std::move(child)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8990 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8991 | host_impl.pending_tree()->SetRootLayerForTesting(std::move(root)); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 8992 | host_impl.pending_tree()->SetElementIdsForTesting(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8993 | |
| 8994 | // Check the non-skipped case. |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 8995 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8996 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 8997 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8998 | std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8999 | KeyframedFloatAnimationCurve::Create()); |
loyso | 1e4e7ee | 2016-06-03 03:04:49 | [diff] [blame] | 9000 | std::unique_ptr<TimingFunction> func = |
| 9001 | CubicBezierTimingFunction::CreatePreset( |
| 9002 | CubicBezierTimingFunction::EaseType::EASE); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9003 | curve->AddKeyframe( |
| 9004 | FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func))); |
| 9005 | curve->AddKeyframe( |
| 9006 | FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9007 | std::unique_ptr<Animation> animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9008 | Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY)); |
| 9009 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 9010 | host_impl.active_tree()->animation_host()->RegisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9011 | root_ptr->element_id(), player.get()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9012 | host_impl.active_tree() |
| 9013 | ->animation_host() |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9014 | ->GetElementAnimationsForElementId(root_ptr->element_id()) |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9015 | ->AddAnimation(std::move(animation)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9016 | root_ptr->test_properties()->opacity = 0.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9017 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9018 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9019 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9020 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9021 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 9022 | host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9023 | root_ptr->element_id(), player.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9024 | } |
| 9025 | |
| 9026 | TEST_F(LayerTreeHostCommonTest, SkippingLayer) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9027 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9028 | LayerImpl* child = AddChild<LayerImpl>(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9029 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9030 | root->SetBounds(gfx::Size(100, 100)); |
| 9031 | child->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9032 | child->SetDrawsContent(true); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9033 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9034 | ExecuteCalculateDrawProperties(root); |
| 9035 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9036 | child->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9037 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9038 | child->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9039 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9040 | ExecuteCalculateDrawProperties(root); |
| 9041 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9042 | child->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9043 | |
| 9044 | child->SetBounds(gfx::Size()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9045 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9046 | ExecuteCalculateDrawProperties(root); |
| 9047 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9048 | child->SetBounds(gfx::Size(10, 10)); |
| 9049 | |
| 9050 | gfx::Transform rotate; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9051 | child->test_properties()->double_sided = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9052 | rotate.RotateAboutXAxis(180.f); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9053 | child->test_properties()->transform = rotate; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9054 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9055 | ExecuteCalculateDrawProperties(root); |
| 9056 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9057 | child->test_properties()->double_sided = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9058 | child->test_properties()->transform = gfx::Transform(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9059 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9060 | child->test_properties()->opacity = 0.f; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9061 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9062 | ExecuteCalculateDrawProperties(root); |
| 9063 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9064 | } |
| 9065 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9066 | TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) { |
| 9067 | // Ensure that the treewalk in LayerTreeHostCommom:: |
| 9068 | // PreCalculateMetaInformation happens when its required. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9069 | scoped_refptr<Layer> root = Layer::Create(); |
| 9070 | scoped_refptr<Layer> parent = Layer::Create(); |
| 9071 | scoped_refptr<Layer> child = Layer::Create(); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9072 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9073 | root->SetBounds(gfx::Size(100, 100)); |
| 9074 | parent->SetBounds(gfx::Size(100, 100)); |
| 9075 | child->SetBounds(gfx::Size(100, 100)); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9076 | child->SetClipParent(root.get()); |
| 9077 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9078 | root->AddChild(parent); |
| 9079 | parent->AddChild(child); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9080 | host()->SetRootLayer(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9081 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9082 | child->RequestCopyOfOutput( |
| 9083 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9084 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9085 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9086 | EXPECT_EQ(parent->num_unclipped_descendants(), 1u); |
| 9087 | |
| 9088 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9089 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9090 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9091 | } |
| 9092 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9093 | TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) { |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9094 | scoped_refptr<Layer> root = Layer::Create(); |
| 9095 | root->SetBounds(gfx::Size(800, 800)); |
| 9096 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9097 | gfx::Transform translate_z; |
| 9098 | translate_z.Translate3d(0, 0, 10); |
| 9099 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9100 | scoped_refptr<Layer> child = Layer::Create(); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9101 | child->SetTransform(translate_z); |
| 9102 | child->SetBounds(gfx::Size(100, 100)); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9103 | |
| 9104 | root->AddChild(child); |
| 9105 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9106 | host()->SetRootLayer(root); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9107 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9108 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9109 | EXPECT_NE(-1, child->transform_tree_index()); |
| 9110 | |
| 9111 | child->RemoveFromParent(); |
| 9112 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9113 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9114 | EXPECT_EQ(-1, child->transform_tree_index()); |
| 9115 | } |
| 9116 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9117 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { |
| 9118 | // Ensure that a Clip Node is added when a render surface applies clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9119 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9120 | LayerImpl* significant_transform = AddChildToRoot<LayerImpl>(); |
| 9121 | LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform); |
| 9122 | LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree); |
| 9123 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9124 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9125 | // This transform should be a significant one so that a transform node is |
| 9126 | // formed for it. |
| 9127 | gfx::Transform transform1; |
| 9128 | transform1.RotateAboutYAxis(45); |
| 9129 | transform1.RotateAboutXAxis(30); |
| 9130 | // This transform should be a 3d transform as we want the render surface |
| 9131 | // to flatten the transform |
| 9132 | gfx::Transform transform2; |
| 9133 | transform2.Translate3d(10, 10, 10); |
| 9134 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9135 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9136 | significant_transform->test_properties()->transform = transform1; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9137 | significant_transform->SetBounds(gfx::Size(30, 30)); |
| 9138 | layer_clips_subtree->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9139 | layer_clips_subtree->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9140 | layer_clips_subtree->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9141 | render_surface->test_properties()->transform = transform2; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9142 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9143 | render_surface->test_properties()->force_render_surface = true; |
| 9144 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9145 | test_layer->SetDrawsContent(true); |
| 9146 | |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9147 | float device_scale_factor = 1.f; |
| 9148 | float page_scale_factor = 1.f; |
| 9149 | LayerImpl* page_scale_layer = nullptr; |
| 9150 | // Visible rects computed by combining clips in target space and root space |
| 9151 | // don't match because of rotation transforms. So, we skip |
| 9152 | // verify_visible_rect_calculations. |
| 9153 | bool skip_verify_visible_rect_calculations = true; |
| 9154 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 9155 | page_scale_layer, |
| 9156 | skip_verify_visible_rect_calculations); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9157 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9158 | TransformTree& transform_tree = |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9159 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9160 | TransformNode* transform_node = |
| 9161 | transform_tree.Node(significant_transform->transform_tree_index()); |
| 9162 | EXPECT_EQ(transform_node->owner_id, significant_transform->id()); |
| 9163 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9164 | EXPECT_TRUE(root->has_render_surface()); |
| 9165 | EXPECT_FALSE(significant_transform->has_render_surface()); |
| 9166 | EXPECT_TRUE(layer_clips_subtree->has_render_surface()); |
| 9167 | EXPECT_TRUE(render_surface->has_render_surface()); |
| 9168 | EXPECT_FALSE(test_layer->has_render_surface()); |
| 9169 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9170 | ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9171 | ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9172 | EXPECT_FALSE(clip_node->applies_local_clip); |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame] | 9173 | EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect()); |
jaydasika | 5237db0 | 2016-09-20 01:34:30 | [diff] [blame] | 9174 | |
| 9175 | // Also test the visible rects computed by combining clips in root space. |
| 9176 | gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic( |
| 9177 | root->layer_tree_impl()->property_trees(), test_layer); |
| 9178 | EXPECT_EQ(gfx::Rect(30, 20), visible_rect); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9179 | } |
| 9180 | |
| 9181 | TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 9182 | // Ensure that when parent clip node's transform is an ancestor of current |
| 9183 | // clip node's target, clip is 'projected' from parent space to current |
| 9184 | // target space and visible rects are calculated correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9185 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9186 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9187 | LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 9188 | LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| 9189 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9190 | gfx::Transform transform; |
| 9191 | transform.RotateAboutYAxis(45); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9192 | |
| 9193 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9194 | clip_layer->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9195 | clip_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9196 | clip_layer->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9197 | target_layer->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9198 | target_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9199 | target_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9200 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9201 | test_layer->SetDrawsContent(true); |
| 9202 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9203 | ExecuteCalculateDrawProperties(root); |
| 9204 | |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9205 | EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9206 | } |
| 9207 | |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9208 | TEST_F(LayerTreeHostCommonTest, |
| 9209 | RenderSurfaceWithUnclippedDescendantsClipsSubtree) { |
| 9210 | // Ensure clip rect is calculated correctly when render surface has unclipped |
| 9211 | // descendants. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9212 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9213 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9214 | LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); |
| 9215 | LayerImpl* render_surface = |
| 9216 | AddChild<LayerImpl>(between_clip_parent_and_child); |
| 9217 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9218 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9219 | gfx::Transform translate; |
| 9220 | translate.Translate(2.0, 2.0); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9221 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9222 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9223 | clip_parent->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9224 | clip_parent->SetBounds(gfx::Size(30, 30)); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9225 | clip_parent->SetMasksToBounds(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9226 | between_clip_parent_and_child->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9227 | between_clip_parent_and_child->SetBounds(gfx::Size(30, 30)); |
| 9228 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9229 | render_surface->test_properties()->force_render_surface = true; |
| 9230 | test_layer->SetBounds(gfx::Size(30, 30)); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9231 | test_layer->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9232 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9233 | render_surface->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9234 | clip_parent->test_properties()->clip_children = |
| 9235 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9236 | clip_parent->test_properties()->clip_children->insert(render_surface); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9237 | |
| 9238 | ExecuteCalculateDrawProperties(root); |
| 9239 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9240 | EXPECT_TRUE(test_layer->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 9241 | EXPECT_FALSE(test_layer->render_target()->is_clipped()); |
weiliangc | 0b41eaf | 2016-03-14 21:35:56 | [diff] [blame] | 9242 | EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect()); |
| 9243 | EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9244 | } |
| 9245 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9246 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9247 | RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) { |
| 9248 | // Ensure that the visible layer rect of a descendant of a surface with |
| 9249 | // unclipped descendants is computed correctly, when the surface doesn't apply |
| 9250 | // a clip. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9251 | LayerImpl* root = root_layer_for_testing(); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9252 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9253 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9254 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9255 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 9256 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9257 | root->SetBounds(gfx::Size(30, 10)); |
| 9258 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 9259 | render_surface->SetBounds(gfx::Size(10, 15)); |
| 9260 | render_surface->test_properties()->force_render_surface = true; |
| 9261 | clip_child->SetBounds(gfx::Size(10, 10)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9262 | clip_child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9263 | child->SetBounds(gfx::Size(40, 40)); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9264 | child->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9265 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9266 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9267 | clip_parent->test_properties()->clip_children = |
| 9268 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9269 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9270 | |
| 9271 | ExecuteCalculateDrawProperties(root); |
jaydasika | 94bebdd | 2016-09-16 22:11:18 | [diff] [blame] | 9272 | EXPECT_EQ(gfx::Rect(30, 10), child->visible_layer_rect()); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9273 | } |
| 9274 | |
| 9275 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9276 | RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9277 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9278 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9279 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9280 | LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface); |
| 9281 | LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1); |
| 9282 | LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child); |
| 9283 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9284 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9285 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9286 | clip_parent->SetBounds(gfx::Size(30, 30)); |
| 9287 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9288 | render_surface->SetMasksToBounds(true); |
| 9289 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9290 | render_surface->test_properties()->force_render_surface = true; |
| 9291 | test_layer1->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9292 | test_layer1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9293 | clip_child->SetBounds(gfx::Size(50, 50)); |
| 9294 | clip_child->SetDrawsContent(true); |
| 9295 | test_layer2->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9296 | test_layer2->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9297 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9298 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9299 | clip_parent->test_properties()->clip_children = |
| 9300 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9301 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9302 | |
| 9303 | ExecuteCalculateDrawProperties(root); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9304 | EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect()); |
| 9305 | EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect()); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9306 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
| 9307 | EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect()); |
| 9308 | } |
| 9309 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9310 | TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9311 | LayerImpl* root = root_layer_for_testing(); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9312 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9313 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9314 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9315 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9316 | root->SetBounds(gfx::Size(50, 50)); |
| 9317 | clip_parent->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9318 | clip_parent->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9319 | render_surface->SetBounds(gfx::Size(30, 30)); |
| 9320 | render_surface->test_properties()->force_render_surface = true; |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9321 | render_surface->SetMasksToBounds(true); |
| 9322 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9323 | clip_child->SetBounds(gfx::Size(50, 50)); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9324 | clip_child->SetDrawsContent(true); |
| 9325 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9326 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9327 | clip_parent->test_properties()->clip_children = |
| 9328 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9329 | clip_parent->test_properties()->clip_children->insert(clip_child); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9330 | |
| 9331 | ExecuteCalculateDrawProperties(root); |
| 9332 | |
| 9333 | // The clip child should inherit its clip parent's clipping state, not its |
| 9334 | // tree parent's clipping state. |
| 9335 | EXPECT_FALSE(clip_parent->is_clipped()); |
| 9336 | EXPECT_TRUE(render_surface->is_clipped()); |
| 9337 | EXPECT_FALSE(clip_child->is_clipped()); |
| 9338 | } |
| 9339 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9340 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) { |
| 9341 | // Tests the value of render surface content rect when we have multiple types |
| 9342 | // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and |
| 9343 | // clipped surfaces. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9344 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9345 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 9346 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 9347 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9348 | LayerImpl* unclipped_desc_surface2 = |
| 9349 | AddChild<LayerImpl>(unclipped_desc_surface); |
| 9350 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2); |
| 9351 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 9352 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9353 | root->SetBounds(gfx::Size(80, 80)); |
| 9354 | unclipped_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9355 | unclipped_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9356 | unclipped_surface->SetDrawsContent(true); |
| 9357 | unclipped_surface->test_properties()->force_render_surface = true; |
| 9358 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 9359 | clip_parent->SetMasksToBounds(true); |
| 9360 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9361 | unclipped_desc_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9362 | unclipped_desc_surface->SetDrawsContent(true); |
| 9363 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9364 | unclipped_desc_surface2->SetBounds(gfx::Size(60, 60)); |
| 9365 | unclipped_desc_surface2->SetDrawsContent(true); |
| 9366 | unclipped_desc_surface2->test_properties()->force_render_surface = true; |
| 9367 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9368 | clipped_surface->SetBounds(gfx::Size(70, 70)); |
| 9369 | clipped_surface->SetDrawsContent(true); |
| 9370 | clipped_surface->test_properties()->force_render_surface = true; |
| 9371 | |
| 9372 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9373 | clip_parent->test_properties()->clip_children = |
| 9374 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9375 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9376 | |
| 9377 | ExecuteCalculateDrawProperties(root); |
| 9378 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9379 | unclipped_surface->render_surface()->content_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9380 | EXPECT_EQ(gfx::Rect(50, 50), |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9381 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9382 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9383 | unclipped_desc_surface2->render_surface()->content_rect()); |
| 9384 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9385 | clipped_surface->render_surface()->content_rect()); |
| 9386 | } |
| 9387 | |
| 9388 | TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) { |
| 9389 | // Tests the value of render surface content rect when we have a layer that |
| 9390 | // clips between the clip parent's target and clip child's target. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9391 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9392 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9393 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9394 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9395 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9396 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9397 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9398 | gfx::Transform translate; |
| 9399 | translate.Translate(10, 10); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9400 | |
jaydasika | 778cb27 | 2016-08-15 19:00:54 | [diff] [blame] | 9401 | gfx::Transform rotate; |
| 9402 | rotate.RotateAboutXAxis(10); |
| 9403 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9404 | root->SetBounds(gfx::Size(100, 100)); |
| 9405 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9406 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9407 | surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9408 | surface->test_properties()->transform = rotate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9409 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9410 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9411 | clip_parent->SetBounds(gfx::Size(50, 50)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9412 | unclipped_desc_surface->test_properties()->transform = translate; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9413 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 9414 | unclipped_desc_surface->SetDrawsContent(true); |
| 9415 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9416 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9417 | clip_child->SetDrawsContent(true); |
| 9418 | |
| 9419 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9420 | clip_parent->test_properties()->clip_children = |
| 9421 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9422 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9423 | |
| 9424 | ExecuteCalculateDrawProperties(root); |
| 9425 | |
| 9426 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9427 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9428 | } |
| 9429 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9430 | TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9431 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9432 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9433 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9434 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9435 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9436 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9437 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9438 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9439 | gfx::Transform scale; |
| 9440 | scale.Scale(2, 2); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9441 | |
| 9442 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9443 | surface->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9444 | surface->SetBounds(gfx::Size(100, 100)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9445 | surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9446 | surface->test_properties()->force_render_surface = true; |
| 9447 | clip_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9448 | clip_layer->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9449 | clip_parent->SetBounds(gfx::Size(50, 50)); |
| 9450 | unclipped_desc_surface->SetBounds(gfx::Size(100, 100)); |
| 9451 | unclipped_desc_surface->SetDrawsContent(true); |
| 9452 | unclipped_desc_surface->test_properties()->force_render_surface = true; |
| 9453 | clip_child->SetBounds(gfx::Size(100, 100)); |
| 9454 | clip_child->SetDrawsContent(true); |
| 9455 | |
| 9456 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9457 | clip_parent->test_properties()->clip_children = |
| 9458 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9459 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9460 | |
| 9461 | ExecuteCalculateDrawProperties(root); |
| 9462 | |
| 9463 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 9464 | } |
| 9465 | |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9466 | TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9467 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9468 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9469 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9470 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9471 | gfx::Transform translation; |
| 9472 | translation.Translate(10, 10); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9473 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9474 | root->SetBounds(gfx::Size(30, 30)); |
| 9475 | render_surface->SetBounds(gfx::Size(30, 30)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9476 | render_surface->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9477 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9478 | test_layer->test_properties()->transform = translation; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9479 | test_layer->SetBounds(gfx::Size(20, 20)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9480 | test_layer->SetDrawsContent(true); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9481 | test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20)); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9482 | test_layer->test_properties()->opacity = 0.f; |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9483 | |
| 9484 | ExecuteCalculateDrawProperties(root); |
weiliangc | c351772 | 2016-06-28 22:52:02 | [diff] [blame] | 9485 | EXPECT_TRANSFORMATION_MATRIX_EQ(translation, |
| 9486 | test_layer->ScreenSpaceTransform()); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9487 | } |
| 9488 | |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9489 | TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9490 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9491 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9492 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9493 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9494 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9495 | root->SetBounds(gfx::Size(30, 30)); |
| 9496 | clip_parent->SetBounds(gfx::Size(40, 40)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9497 | clip_parent->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9498 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9499 | render_surface->SetMasksToBounds(true); |
| 9500 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9501 | render_surface->test_properties()->force_render_surface = true; |
| 9502 | clip_child->SetBounds(gfx::Size(50, 50)); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9503 | clip_child->SetDrawsContent(true); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9504 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9505 | clip_child->test_properties()->clip_parent = clip_parent; |
| 9506 | clip_parent->test_properties()->clip_children = |
| 9507 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9508 | clip_parent->test_properties()->clip_children->insert(clip_child); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9509 | |
| 9510 | ExecuteCalculateDrawProperties(root); |
jaydasika | b4df403 | 2016-09-13 18:38:49 | [diff] [blame] | 9511 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9512 | } |
| 9513 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9514 | TEST_F(LayerTreeHostCommonTest, |
| 9515 | LayerClipRectLargerThanClippingRenderSurfaceRect) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9516 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9517 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9518 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9519 | |
| 9520 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9521 | root->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9522 | root->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9523 | render_surface->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9524 | render_surface->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9525 | render_surface->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9526 | render_surface->test_properties()->force_render_surface = true; |
| 9527 | test_layer->SetBounds(gfx::Size(50, 50)); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9528 | test_layer->SetMasksToBounds(true); |
| 9529 | test_layer->SetDrawsContent(true); |
| 9530 | ExecuteCalculateDrawProperties(root); |
| 9531 | |
| 9532 | EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect()); |
| 9533 | EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect()); |
| 9534 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect()); |
| 9535 | } |
| 9536 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9537 | TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) { |
| 9538 | // Tests that subtree is hidden is updated. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9539 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9540 | LayerImpl* hidden = AddChild<LayerImpl>(root); |
| 9541 | LayerImpl* test = AddChild<LayerImpl>(hidden); |
| 9542 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9543 | root->SetBounds(gfx::Size(30, 30)); |
| 9544 | hidden->SetBounds(gfx::Size(30, 30)); |
| 9545 | hidden->test_properties()->force_render_surface = true; |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9546 | hidden->test_properties()->hide_layer_and_subtree = true; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9547 | test->SetBounds(gfx::Size(30, 30)); |
| 9548 | test->test_properties()->force_render_surface = true; |
| 9549 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9550 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9551 | EXPECT_TRUE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9552 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9553 | hidden->test_properties()->hide_layer_and_subtree = false; |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9554 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9555 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9556 | EXPECT_FALSE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9557 | } |
| 9558 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9559 | TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9560 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9561 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9562 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 9563 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
| 9564 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9565 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9566 | root->SetMasksToBounds(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9567 | render_surface1->SetPosition(gfx::PointF(10, 10)); |
| 9568 | render_surface1->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9569 | render_surface1->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9570 | render_surface1->test_properties()->force_render_surface = true; |
| 9571 | render_surface2->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9572 | render_surface2->SetDrawsContent(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9573 | render_surface2->test_properties()->force_render_surface = true; |
| 9574 | clip_child->SetBounds(gfx::Size(30, 30)); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9575 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9576 | clip_child->test_properties()->clip_parent = root; |
| 9577 | root->test_properties()->clip_children = |
| 9578 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9579 | root->test_properties()->clip_children->insert(clip_child); |
| 9580 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9581 | ExecuteCalculateDrawProperties(root); |
| 9582 | |
| 9583 | EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); |
jaydasika | daf0af0 | 2016-01-06 15:33:37 | [diff] [blame] | 9584 | // A clip node is created for every render surface and for layers that have |
| 9585 | // local clip. So, here it should be craeted for every layer. |
| 9586 | EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9587 | } |
| 9588 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9589 | TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) { |
| 9590 | // Tests that a mask layer's draw properties are computed correctly. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9591 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9592 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9593 | child->test_properties()->SetMaskLayer( |
| 9594 | LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 9595 | LayerImpl* mask = child->test_properties()->mask_layer; |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9596 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9597 | gfx::Transform transform; |
| 9598 | transform.Translate(10, 10); |
| 9599 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9600 | root->SetBounds(gfx::Size(40, 40)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9601 | root->SetDrawsContent(true); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9602 | child->test_properties()->transform = transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9603 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9604 | child->SetDrawsContent(false); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9605 | mask->SetBounds(gfx::Size(20, 20)); |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9606 | ExecuteCalculateDrawProperties(root); |
| 9607 | |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9608 | // The render surface created for the mask has no contributing content, so the |
| 9609 | // mask isn't a drawn RSLL member. This means it has an empty visible rect, |
| 9610 | // but its screen space transform can still be computed correctly on-demand. |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9611 | EXPECT_FALSE(mask->is_drawn_render_surface_layer_list_member()); |
| 9612 | EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect()); |
| 9613 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9614 | |
| 9615 | // Make the child's render surface have contributing content. |
| 9616 | child->SetDrawsContent(true); |
| 9617 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9618 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9619 | EXPECT_TRUE(mask->is_drawn_render_surface_layer_list_member()); |
| 9620 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
| 9621 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9622 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9623 | transform.Translate(10, 10); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9624 | child->test_properties()->transform = transform; |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9625 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9626 | ExecuteCalculateDrawProperties(root); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 9627 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform()); |
| 9628 | EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect()); |
ajuma | db6216f2c | 2016-06-07 21:44:05 | [diff] [blame] | 9629 | } |
| 9630 | |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9631 | TEST_F(LayerTreeHostCommonTest, |
| 9632 | SublayerScaleWithTransformNodeBetweenTwoTargets) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9633 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9634 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9635 | LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1); |
| 9636 | LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets); |
| 9637 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9638 | |
| 9639 | gfx::Transform scale; |
| 9640 | scale.Scale(2.f, 2.f); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9641 | |
| 9642 | root->SetBounds(gfx::Size(30, 30)); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9643 | render_surface1->test_properties()->transform = scale; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9644 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 9645 | render_surface1->test_properties()->force_render_surface = true; |
| 9646 | between_targets->SetBounds(gfx::Size(30, 30)); |
| 9647 | render_surface2->SetBounds(gfx::Size(30, 30)); |
| 9648 | render_surface2->test_properties()->force_render_surface = true; |
| 9649 | test_layer->SetBounds(gfx::Size(30, 30)); |
| 9650 | test_layer->SetDrawsContent(true); |
| 9651 | |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9652 | // We want layer between the two targets to create a clip node and transform |
| 9653 | // node but it shouldn't create a render surface. |
| 9654 | between_targets->SetMasksToBounds(true); |
| 9655 | between_targets->Set3dSortingContextId(2); |
| 9656 | |
| 9657 | ExecuteCalculateDrawProperties(root); |
| 9658 | |
| 9659 | TransformTree& tree = |
| 9660 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9661 | TransformNode* node = tree.Node(render_surface1->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9662 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9663 | |
| 9664 | node = tree.Node(between_targets->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9665 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9666 | |
| 9667 | node = tree.Node(render_surface2->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9668 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9669 | |
| 9670 | EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect()); |
| 9671 | } |
| 9672 | |
jaydasika | 3c5633d | 2016-08-25 00:39:22 | [diff] [blame] | 9673 | TEST_F(LayerTreeHostCommonTest, NoisyTransform) { |
| 9674 | LayerImpl* root = root_layer_for_testing(); |
| 9675 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9676 | LayerImpl* scroll_child = AddChild<LayerImpl>(render_surface); |
| 9677 | LayerImpl* scroll_clip = AddChild<LayerImpl>(render_surface); |
| 9678 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_clip); |
| 9679 | |
| 9680 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
| 9681 | scroll_parent->test_properties()->scroll_children = |
| 9682 | base::MakeUnique<std::set<LayerImpl*>>(); |
| 9683 | scroll_parent->test_properties()->scroll_children->insert(scroll_child); |
| 9684 | scroll_parent->SetScrollClipLayer(scroll_clip->id()); |
| 9685 | |
| 9686 | scroll_parent->SetDrawsContent(true); |
| 9687 | scroll_child->SetDrawsContent(true); |
| 9688 | render_surface->test_properties()->force_render_surface = true; |
| 9689 | |
| 9690 | // A noisy transform that's invertible. |
| 9691 | gfx::Transform transform; |
| 9692 | transform.matrix().setDouble(0, 0, 6.12323e-17); |
| 9693 | transform.matrix().setDouble(0, 2, 1); |
| 9694 | transform.matrix().setDouble(2, 2, 6.12323e-17); |
| 9695 | transform.matrix().setDouble(2, 0, -1); |
| 9696 | |
| 9697 | scroll_child->test_properties()->transform = transform; |
| 9698 | render_surface->test_properties()->transform = transform; |
| 9699 | |
| 9700 | root->SetBounds(gfx::Size(30, 30)); |
| 9701 | scroll_child->SetBounds(gfx::Size(30, 30)); |
| 9702 | scroll_parent->SetBounds(gfx::Size(30, 30)); |
| 9703 | ExecuteCalculateDrawProperties(root); |
| 9704 | |
| 9705 | gfx::Transform expected; |
| 9706 | expected.matrix().setDouble(0, 0, 3.749395e-33); |
| 9707 | expected.matrix().setDouble(0, 2, 6.12323e-17); |
| 9708 | expected.matrix().setDouble(2, 0, -1); |
| 9709 | expected.matrix().setDouble(2, 2, 6.12323e-17); |
| 9710 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected, |
| 9711 | scroll_child->ScreenSpaceTransform()); |
| 9712 | } |
| 9713 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9714 | TEST_F(LayerTreeHostCommonTest, LargeTransformTest) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9715 | LayerImpl* root = root_layer_for_testing(); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9716 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9717 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9718 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9719 | child->SetDrawsContent(true); |
| 9720 | child->SetMasksToBounds(true); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9721 | |
| 9722 | gfx::Transform large_transform; |
| 9723 | large_transform.Scale(99999999999999999999.f, 99999999999999999999.f); |
| 9724 | large_transform.Scale(9999999999999999999.f, 9999999999999999999.f); |
| 9725 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0))); |
| 9726 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1))); |
| 9727 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9728 | root->SetBounds(gfx::Size(30, 30)); |
| 9729 | render_surface1->SetBounds(gfx::Size(30, 30)); |
| 9730 | render_surface1->test_properties()->force_render_surface = true; |
| 9731 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9732 | // TODO(sunxd): we make child have no render surface, because if the |
| 9733 | // child has one, the large transform applied to child will result in NaNs in |
| 9734 | // the draw_transform of the render_surface, thus make draw property updates |
| 9735 | // skip the child layer. We need further investigation into this to know |
| 9736 | // what exactly happens here. |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9737 | child->test_properties()->transform = large_transform; |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9738 | child->SetBounds(gfx::Size(30, 30)); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9739 | |
| 9740 | ExecuteCalculateDrawProperties(root); |
| 9741 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9742 | EXPECT_EQ(gfx::RectF(), |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9743 | render_surface1->render_surface()->DrawableContentRect()); |
| 9744 | |
| 9745 | bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) || |
| 9746 | std::isnan(child->DrawTransform().matrix().get(0, 0)); |
| 9747 | EXPECT_TRUE(is_inf_or_nan); |
| 9748 | |
| 9749 | is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) || |
| 9750 | std::isnan(child->DrawTransform().matrix().get(1, 1)); |
| 9751 | EXPECT_TRUE(is_inf_or_nan); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9752 | |
danakj | 5993194 | 2016-07-26 22:11:29 | [diff] [blame] | 9753 | // The root layer should be in the RenderSurfaceLayerListImpl. |
| 9754 | const auto* rsll = render_surface_layer_list_impl(); |
| 9755 | EXPECT_NE(std::find(rsll->begin(), rsll->end(), root), rsll->end()); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9756 | } |
| 9757 | |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9758 | TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) { |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9759 | scoped_refptr<Layer> root = Layer::Create(); |
| 9760 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 9761 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9762 | root->AddChild(child); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9763 | host()->SetRootLayer(root); |
| 9764 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9765 | root->SetBounds(gfx::Size(100, 100)); |
| 9766 | child->SetBounds(gfx::Size(20, 20)); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9767 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9768 | |
| 9769 | // Changing the opacity from 1 to non-1 value should trigger rebuild of |
| 9770 | // property trees as a new effect node will be created. |
| 9771 | child->SetOpacity(0.5f); |
| 9772 | PropertyTrees* property_trees = host()->property_trees(); |
| 9773 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 9774 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9775 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9776 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 9777 | property_trees->effect_id_to_index_map.end()); |
| 9778 | |
| 9779 | // child already has an effect node. Changing its opacity shouldn't trigger |
| 9780 | // a property trees rebuild. |
| 9781 | child->SetOpacity(0.8f); |
| 9782 | property_trees = host()->property_trees(); |
| 9783 | EXPECT_FALSE(property_trees->needs_rebuild); |
| 9784 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9785 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9786 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 9787 | property_trees->effect_id_to_index_map.end()); |
| 9788 | |
| 9789 | // Changing the opacity from non-1 value to 1 should trigger a rebuild of |
| 9790 | // property trees as the effect node may no longer be needed. |
| 9791 | child->SetOpacity(1.f); |
| 9792 | property_trees = host()->property_trees(); |
| 9793 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 9794 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9795 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9796 | EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()), |
| 9797 | property_trees->effect_id_to_index_map.end()); |
| 9798 | } |
| 9799 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9800 | TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) { |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9801 | scoped_refptr<Layer> root = Layer::Create(); |
| 9802 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 9803 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9804 | root->AddChild(animated); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9805 | host()->SetRootLayer(root); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 9806 | host()->GetLayerTree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9807 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9808 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9809 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9810 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9811 | animated->SetOpacity(0.f); |
| 9812 | |
| 9813 | scoped_refptr<AnimationPlayer> player = |
| 9814 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 9815 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9816 | |
| 9817 | player->AttachElement(animated->element_id()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9818 | |
| 9819 | int animation_id = 0; |
| 9820 | std::unique_ptr<Animation> animation = Animation::Create( |
| 9821 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 9822 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 9823 | animation->set_fill_mode(Animation::FillMode::NONE); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9824 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 9825 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9826 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 9827 | std::move(animation)); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9828 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9829 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9830 | |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 9831 | EffectTree& tree = root->GetLayerTree()->property_trees()->effect_tree; |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9832 | EffectNode* node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9833 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 9834 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9835 | |
| 9836 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
khushalsagar | 6156779 | 2016-09-17 00:13:58 | [diff] [blame] | 9837 | host()->AnimateLayers( |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9838 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 9839 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9840 | EXPECT_TRUE(node->is_currently_animating_opacity); |
| 9841 | EXPECT_TRUE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9842 | |
| 9843 | player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/); |
| 9844 | node = tree.Node(animated->effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9845 | EXPECT_FALSE(node->is_currently_animating_opacity); |
| 9846 | EXPECT_FALSE(node->has_potential_opacity_animation); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9847 | } |
| 9848 | |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9849 | TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) { |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9850 | scoped_refptr<Layer> root = Layer::Create(); |
| 9851 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 9852 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9853 | root->AddChild(animated); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9854 | host()->SetRootLayer(root); |
xingliu | 95d9e6b6 | 2016-08-18 03:53:08 | [diff] [blame] | 9855 | host()->GetLayerTree()->SetElementIdsForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9856 | |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9857 | root->SetBounds(gfx::Size(100, 100)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9858 | root->SetForceRenderSurfaceForTesting(true); |
danakj | f78fb27 | 2016-07-26 19:06:15 | [diff] [blame] | 9859 | animated->SetBounds(gfx::Size(20, 20)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9860 | |
| 9861 | scoped_refptr<AnimationPlayer> player = |
| 9862 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 9863 | timeline()->AttachPlayer(player); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9864 | player->AttachElement(animated->element_id()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9865 | |
| 9866 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 9867 | KeyframedTransformAnimationCurve::Create()); |
| 9868 | TransformOperations start; |
| 9869 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 9870 | gfx::Transform transform; |
| 9871 | transform.Scale3d(1.0, 2.0, 3.0); |
| 9872 | TransformOperations operation; |
| 9873 | operation.AppendMatrix(transform); |
| 9874 | curve->AddKeyframe( |
| 9875 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 9876 | curve->AddKeyframe(TransformKeyframe::Create( |
| 9877 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
| 9878 | std::unique_ptr<Animation> animation( |
| 9879 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 9880 | animation->set_fill_mode(Animation::FillMode::NONE); |
| 9881 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 9882 | Animation* animation_ptr = animation.get(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 9883 | AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(), |
| 9884 | std::move(animation)); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9885 | |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 9886 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get()); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9887 | |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 9888 | TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree; |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9889 | TransformNode* node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9890 | EXPECT_FALSE(node->is_currently_animating); |
| 9891 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9892 | |
| 9893 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
khushalsagar | 6156779 | 2016-09-17 00:13:58 | [diff] [blame] | 9894 | host()->AnimateLayers( |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9895 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 9896 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9897 | EXPECT_TRUE(node->is_currently_animating); |
| 9898 | EXPECT_TRUE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9899 | |
| 9900 | player->AbortAnimations(TargetProperty::TRANSFORM, |
| 9901 | false /*needs_completion*/); |
| 9902 | node = tree.Node(animated->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 9903 | EXPECT_FALSE(node->is_currently_animating); |
| 9904 | EXPECT_FALSE(node->has_potential_animation); |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9905 | } |
| 9906 | |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 9907 | TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) { |
| 9908 | LayerTreeHostCommon::ScrollUpdateInfo scroll; |
| 9909 | scroll.layer_id = 2; |
| 9910 | scroll.scroll_delta = gfx::Vector2d(5, 10); |
| 9911 | |
| 9912 | proto::ScrollUpdateInfo proto; |
| 9913 | scroll.ToProtobuf(&proto); |
| 9914 | LayerTreeHostCommon::ScrollUpdateInfo new_scroll; |
| 9915 | new_scroll.FromProtobuf(proto); |
| 9916 | |
| 9917 | EXPECT_EQ(scroll, new_scroll); |
| 9918 | } |
| 9919 | |
| 9920 | TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) { |
| 9921 | ScrollAndScaleSet scroll_and_scale_set; |
| 9922 | |
| 9923 | LayerTreeHostCommon::ScrollUpdateInfo scroll1; |
| 9924 | scroll1.layer_id = 1; |
| 9925 | scroll1.scroll_delta = gfx::Vector2d(5, 10); |
| 9926 | LayerTreeHostCommon::ScrollUpdateInfo scroll2; |
| 9927 | scroll2.layer_id = 2; |
| 9928 | scroll2.scroll_delta = gfx::Vector2d(1, 5); |
| 9929 | scroll_and_scale_set.scrolls.push_back(scroll1); |
| 9930 | scroll_and_scale_set.scrolls.push_back(scroll2); |
| 9931 | |
| 9932 | scroll_and_scale_set.page_scale_delta = 0.3f; |
| 9933 | scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f); |
| 9934 | scroll_and_scale_set.top_controls_delta = 0.9f; |
| 9935 | |
| 9936 | proto::ScrollAndScaleSet proto; |
| 9937 | scroll_and_scale_set.ToProtobuf(&proto); |
| 9938 | ScrollAndScaleSet new_scroll_and_scale_set; |
| 9939 | new_scroll_and_scale_set.FromProtobuf(proto); |
| 9940 | |
| 9941 | EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); |
| 9942 | } |
| 9943 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9944 | TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 9945 | // Test the behavior of scroll tree builder |
| 9946 | // Topology: |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9947 | // +root1(1)[inner_viewport_container_layer] |
| 9948 | // +-page_scale_layer |
| 9949 | // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling & |
| 9950 | // scrollable, inner_viewport_scroll_layer] |
| 9951 | // +------child6(6)[kScrollbarScrolling] |
| 9952 | // +--------grand_child10(10)[kScrollbarScrolling] |
| 9953 | // +----parent3(3) |
| 9954 | // +------child7(7)[scrollable] |
| 9955 | // +------child8(8)[scroll_parent=7] |
| 9956 | // +--------grand_child11(11)[scrollable] |
| 9957 | // +----parent4(4) |
| 9958 | // +------child9(9) |
| 9959 | // +--------grand_child12(12) |
| 9960 | // +----parent5(5)[contains_non_fast_scrollable_region] |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9961 | // |
| 9962 | // Expected scroll tree topology: |
| 9963 | // +property_tree_root---owner:-1 |
| 9964 | // +--root---owner:1, id:1 |
| 9965 | // +----node---owner:2, id:2 |
| 9966 | // +------node---owner:6, id:3 |
| 9967 | // +----node---owner:7, id:4 |
| 9968 | // +------node---owner:11, id:5 |
| 9969 | // +----node---owner:5, id:6 |
| 9970 | // |
| 9971 | // Extra check: |
| 9972 | // scroll_tree_index() of: |
| 9973 | // grand_child10:3 |
| 9974 | // parent3:1 |
| 9975 | // child8:4 |
| 9976 | // parent4:1 |
| 9977 | // child9:1 |
| 9978 | // grand_child12:1 |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9979 | scoped_refptr<Layer> root1 = Layer::Create(); |
| 9980 | scoped_refptr<Layer> page_scale_layer = Layer::Create(); |
| 9981 | scoped_refptr<Layer> parent2 = Layer::Create(); |
| 9982 | scoped_refptr<Layer> parent3 = Layer::Create(); |
| 9983 | scoped_refptr<Layer> parent4 = Layer::Create(); |
| 9984 | scoped_refptr<Layer> parent5 = Layer::Create(); |
| 9985 | scoped_refptr<Layer> child6 = Layer::Create(); |
| 9986 | scoped_refptr<Layer> child7 = Layer::Create(); |
| 9987 | scoped_refptr<Layer> child8 = Layer::Create(); |
| 9988 | scoped_refptr<Layer> child9 = Layer::Create(); |
| 9989 | scoped_refptr<Layer> grand_child10 = Layer::Create(); |
| 9990 | scoped_refptr<Layer> grand_child11 = Layer::Create(); |
| 9991 | scoped_refptr<Layer> grand_child12 = Layer::Create(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9992 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9993 | root1->AddChild(page_scale_layer); |
| 9994 | page_scale_layer->AddChild(parent2); |
| 9995 | page_scale_layer->AddChild(parent3); |
| 9996 | page_scale_layer->AddChild(parent4); |
| 9997 | page_scale_layer->AddChild(parent5); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9998 | parent2->AddChild(child6); |
| 9999 | parent3->AddChild(child7); |
| 10000 | parent3->AddChild(child8); |
| 10001 | parent4->AddChild(child9); |
| 10002 | child6->AddChild(grand_child10); |
| 10003 | child8->AddChild(grand_child11); |
| 10004 | child9->AddChild(grand_child12); |
| 10005 | host()->SetRootLayer(root1); |
| 10006 | |
| 10007 | parent2->AddMainThreadScrollingReasons( |
| 10008 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10009 | parent2->AddMainThreadScrollingReasons( |
| 10010 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10011 | parent2->SetScrollClipLayerId(root1->id()); |
| 10012 | child6->AddMainThreadScrollingReasons( |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10013 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10014 | grand_child10->AddMainThreadScrollingReasons( |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10015 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10016 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10017 | child7->SetScrollClipLayerId(parent3->id()); |
| 10018 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10019 | child8->SetScrollParent(child7.get()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10020 | grand_child11->SetScrollClipLayerId(parent3->id()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10021 | |
| 10022 | parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10023 | parent5->SetBounds(gfx::Size(10, 10)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10024 | |
khushalsagar | 86928f9 | 2016-08-17 21:49:05 | [diff] [blame] | 10025 | host()->GetLayerTree()->RegisterViewportLayers(nullptr, page_scale_layer, |
| 10026 | parent2, nullptr); |
jaydasika | 6ed86966 | 2016-09-21 14:29:59 | [diff] [blame] | 10027 | ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10028 | |
| 10029 | const int kInvalidPropertyTreeNodeId = -1; |
| 10030 | const int kRootPropertyTreeNodeId = 0; |
| 10031 | |
| 10032 | // Property tree root |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10033 | ScrollTree& scroll_tree = host()->property_trees()->scroll_tree; |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 10034 | PropertyTrees property_trees; |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10035 | property_trees.is_main_thread = true; |
| 10036 | property_trees.is_active = false; |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10037 | ScrollTree& expected_scroll_tree = property_trees.scroll_tree; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10038 | ScrollNode* property_tree_root = expected_scroll_tree.Node(0); |
| 10039 | property_tree_root->id = kRootPropertyTreeNodeId; |
| 10040 | property_tree_root->parent_id = kInvalidPropertyTreeNodeId; |
| 10041 | property_tree_root->owner_id = kInvalidPropertyTreeNodeId; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10042 | property_tree_root->scrollable = false; |
| 10043 | property_tree_root->main_thread_scrolling_reasons = |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10044 | MainThreadScrollingReason::kNotScrollingOnMain; |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10045 | property_tree_root->contains_non_fast_scrollable_region = false; |
| 10046 | property_tree_root->transform_id = kRootPropertyTreeNodeId; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10047 | |
| 10048 | // The node owned by root1 |
| 10049 | ScrollNode scroll_root1; |
| 10050 | scroll_root1.id = 1; |
| 10051 | scroll_root1.owner_id = root1->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10052 | scroll_root1.user_scrollable_horizontal = true; |
| 10053 | scroll_root1.user_scrollable_vertical = true; |
| 10054 | scroll_root1.transform_id = root1->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10055 | expected_scroll_tree.Insert(scroll_root1, 0); |
| 10056 | |
| 10057 | // The node owned by parent2 |
| 10058 | ScrollNode scroll_parent2; |
| 10059 | scroll_parent2.id = 2; |
| 10060 | scroll_parent2.owner_id = parent2->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10061 | scroll_parent2.scrollable = true; |
| 10062 | scroll_parent2.main_thread_scrolling_reasons = |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10063 | parent2->main_thread_scrolling_reasons(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10064 | scroll_parent2.scroll_clip_layer_bounds = root1->bounds(); |
| 10065 | scroll_parent2.bounds = parent2->bounds(); |
| 10066 | scroll_parent2.max_scroll_offset_affected_by_page_scale = true; |
| 10067 | scroll_parent2.is_inner_viewport_scroll_layer = true; |
| 10068 | scroll_parent2.user_scrollable_horizontal = true; |
| 10069 | scroll_parent2.user_scrollable_vertical = true; |
| 10070 | scroll_parent2.transform_id = parent2->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10071 | expected_scroll_tree.Insert(scroll_parent2, 1); |
| 10072 | |
| 10073 | // The node owned by child6 |
| 10074 | ScrollNode scroll_child6; |
| 10075 | scroll_child6.id = 3; |
| 10076 | scroll_child6.owner_id = child6->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10077 | scroll_child6.main_thread_scrolling_reasons = |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10078 | child6->main_thread_scrolling_reasons(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10079 | scroll_child6.should_flatten = true; |
| 10080 | scroll_child6.user_scrollable_horizontal = true; |
| 10081 | scroll_child6.user_scrollable_vertical = true; |
| 10082 | scroll_child6.transform_id = child6->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10083 | expected_scroll_tree.Insert(scroll_child6, 2); |
| 10084 | |
| 10085 | // The node owned by child7, child7 also owns a transform node |
| 10086 | ScrollNode scroll_child7; |
| 10087 | scroll_child7.id = 4; |
| 10088 | scroll_child7.owner_id = child7->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10089 | scroll_child7.scrollable = true; |
| 10090 | scroll_child7.scroll_clip_layer_bounds = parent3->bounds(); |
| 10091 | scroll_child7.bounds = child7->bounds(); |
| 10092 | scroll_child7.user_scrollable_horizontal = true; |
| 10093 | scroll_child7.user_scrollable_vertical = true; |
| 10094 | scroll_child7.transform_id = child7->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10095 | expected_scroll_tree.Insert(scroll_child7, 1); |
| 10096 | |
| 10097 | // The node owned by grand_child11, grand_child11 also owns a transform node |
| 10098 | ScrollNode scroll_grand_child11; |
| 10099 | scroll_grand_child11.id = 5; |
| 10100 | scroll_grand_child11.owner_id = grand_child11->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10101 | scroll_grand_child11.scrollable = true; |
| 10102 | scroll_grand_child11.user_scrollable_horizontal = true; |
| 10103 | scroll_grand_child11.user_scrollable_vertical = true; |
| 10104 | scroll_grand_child11.transform_id = grand_child11->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10105 | expected_scroll_tree.Insert(scroll_grand_child11, 4); |
| 10106 | |
| 10107 | // The node owned by parent5 |
| 10108 | ScrollNode scroll_parent5; |
| 10109 | scroll_parent5.id = 8; |
| 10110 | scroll_parent5.owner_id = parent5->id(); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 10111 | scroll_parent5.contains_non_fast_scrollable_region = true; |
| 10112 | scroll_parent5.bounds = gfx::Size(10, 10); |
| 10113 | scroll_parent5.should_flatten = true; |
| 10114 | scroll_parent5.user_scrollable_horizontal = true; |
| 10115 | scroll_parent5.user_scrollable_vertical = true; |
| 10116 | scroll_parent5.transform_id = parent5->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10117 | expected_scroll_tree.Insert(scroll_parent5, 1); |
| 10118 | |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10119 | expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0)); |
| 10120 | expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0)); |
| 10121 | expected_scroll_tree.SetScrollOffset(grand_child11->id(), |
| 10122 | gfx::ScrollOffset(0, 0)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10123 | expected_scroll_tree.set_needs_update(false); |
| 10124 | |
| 10125 | EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 10126 | |
| 10127 | // Check other layers' scroll_tree_index |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10128 | EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10129 | EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10130 | EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10131 | EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10132 | EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10133 | EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10134 | EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10135 | } |
| 10136 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 10137 | } // namespace |
| 10138 | } // namespace cc |