[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
| 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_impl.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 | 7b08e286 | 2014-10-27 20:29:59 | [diff] [blame] | 9 | #include <algorithm> |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 10 | #include <cmath> |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 11 | #include <utility> |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 12 | |
[email protected] | 59cb7b35 | 2012-10-30 06:45:48 | [diff] [blame] | 13 | #include "base/bind.h" |
[email protected] | 65bfd997 | 2012-10-19 03:39:37 | [diff] [blame] | 14 | #include "base/command_line.h" |
skyostil | 0fd1dad | 2015-04-13 20:11:48 | [diff] [blame] | 15 | #include "base/location.h" |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 16 | #include "base/memory/ptr_util.h" |
gab | 39cb4ed7 | 2016-05-11 17:45:19 | [diff] [blame] | 17 | #include "base/threading/thread_task_runner_handle.h" |
loyso | e926437dd | 2016-01-14 22:55:30 | [diff] [blame] | 18 | #include "cc/animation/animation_events.h" |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 19 | #include "cc/animation/animation_host.h" |
| 20 | #include "cc/animation/animation_id_provider.h" |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 21 | #include "cc/animation/transform_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 22 | #include "cc/base/math_util.h" |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 23 | #include "cc/input/main_thread_scrolling_reason.h" |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 24 | #include "cc/input/page_scale_animation.h" |
loyso | 455b4f60 | 2016-02-24 02:59:42 | [diff] [blame] | 25 | #include "cc/input/scrollbar_animation_controller_thinning.h" |
[email protected] | 3052b10f | 2013-03-18 07:41:21 | [diff] [blame] | 26 | #include "cc/input/top_controls_manager.h" |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 27 | #include "cc/layers/append_quads_data.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 28 | #include "cc/layers/heads_up_display_layer_impl.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 29 | #include "cc/layers/layer_impl.h" |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 30 | #include "cc/layers/painted_scrollbar_layer_impl.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 31 | #include "cc/layers/render_surface_impl.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 32 | #include "cc/layers/solid_color_layer_impl.h" |
[email protected] | e6e7f29 | 2014-04-24 22:23:03 | [diff] [blame] | 33 | #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 34 | #include "cc/layers/texture_layer_impl.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 35 | #include "cc/layers/video_layer_impl.h" |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 36 | #include "cc/layers/viewport.h" |
[email protected] | df3c24c9 | 2013-06-19 03:54:35 | [diff] [blame] | 37 | #include "cc/output/begin_frame_args.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 38 | #include "cc/output/compositor_frame_metadata.h" |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 39 | #include "cc/output/copy_output_request.h" |
| 40 | #include "cc/output/copy_output_result.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 41 | #include "cc/output/gl_renderer.h" |
jamesr | f313a21 | 2015-03-16 21:27:37 | [diff] [blame] | 42 | #include "cc/output/latency_info_swap_promise.h" |
[email protected] | 89e8267 | 2013-03-18 07:50:56 | [diff] [blame] | 43 | #include "cc/quads/render_pass_draw_quad.h" |
| 44 | #include "cc/quads/solid_color_draw_quad.h" |
| 45 | #include "cc/quads/texture_draw_quad.h" |
| 46 | #include "cc/quads/tile_draw_quad.h" |
khushalsagar | 8ec0740 | 2016-09-10 03:13:19 | [diff] [blame^] | 47 | #include "cc/resources/ui_resource_bitmap.h" |
| 48 | #include "cc/resources/ui_resource_manager.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 49 | #include "cc/test/animation_test_common.h" |
[email protected] | 04c5900d | 2014-08-18 13:38:36 | [diff] [blame] | 50 | #include "cc/test/begin_frame_args_test.h" |
[email protected] | 222c678 | 2013-09-05 22:24:49 | [diff] [blame] | 51 | #include "cc/test/fake_layer_tree_host_impl.h" |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 52 | #include "cc/test/fake_mask_layer_impl.h" |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 53 | #include "cc/test/fake_output_surface.h" |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 54 | #include "cc/test/fake_output_surface_client.h" |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 55 | #include "cc/test/fake_picture_layer_impl.h" |
vmpstr | 41d68f88 | 2016-03-30 01:20:23 | [diff] [blame] | 56 | #include "cc/test/fake_raster_source.h" |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 57 | #include "cc/test/fake_video_frame_provider.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 58 | #include "cc/test/geometry_test_utils.h" |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 59 | #include "cc/test/gpu_rasterization_enabled_settings.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 60 | #include "cc/test/layer_test_common.h" |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 61 | #include "cc/test/layer_tree_test.h" |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 62 | #include "cc/test/test_delegating_output_surface.h" |
reveman | 22dd929 | 2014-10-13 20:52:05 | [diff] [blame] | 63 | #include "cc/test/test_gpu_memory_buffer_manager.h" |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 64 | #include "cc/test/test_shared_bitmap_manager.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 65 | #include "cc/test/test_task_graph_runner.h" |
[email protected] | c2610b9f | 2013-10-31 06:54:59 | [diff] [blame] | 66 | #include "cc/test/test_web_graphics_context_3d.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 67 | #include "cc/trees/effect_node.h" |
danakj | 94b7e4f | 2016-07-20 01:49:38 | [diff] [blame] | 68 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 69 | #include "cc/trees/layer_tree_impl.h" |
| 70 | #include "cc/trees/single_thread_proxy.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 71 | #include "cc/trees/transform_node.h" |
[email protected] | 59cb7b35 | 2012-10-30 06:45:48 | [diff] [blame] | 72 | #include "media/base/media.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 73 | #include "testing/gmock/include/gmock/gmock.h" |
| 74 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 7bc1c51 | 2014-01-23 01:15:27 | [diff] [blame] | 75 | #include "third_party/skia/include/core/SkMallocPixelRef.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 76 | #include "ui/gfx/geometry/rect_conversions.h" |
| 77 | #include "ui/gfx/geometry/size_conversions.h" |
| 78 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 79 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 80 | #define EXPECT_SCOPED(statements) \ |
| 81 | { \ |
| 82 | SCOPED_TRACE(""); \ |
| 83 | statements; \ |
| 84 | } |
| 85 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 86 | using ::testing::Mock; |
| 87 | using ::testing::Return; |
| 88 | using ::testing::AnyNumber; |
| 89 | using ::testing::AtLeast; |
| 90 | using ::testing::_; |
[email protected] | 568285b | 2013-01-07 23:19:19 | [diff] [blame] | 91 | using media::VideoFrame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 92 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 93 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 94 | namespace { |
| 95 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 96 | class LayerTreeHostImplTest : public testing::Test, |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 97 | public LayerTreeHostImplClient { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 98 | public: |
| 99 | LayerTreeHostImplTest() |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame] | 100 | : task_runner_provider_(base::ThreadTaskRunnerHandle::Get()), |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 101 | always_main_thread_blocked_(&task_runner_provider_), |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 102 | on_can_draw_state_changed_called_(false), |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 103 | did_notify_ready_to_activate_(false), |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 104 | did_request_commit_(false), |
| 105 | did_request_redraw_(false), |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 106 | did_request_next_frame_(false), |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 107 | did_request_prepare_tiles_(false), |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 108 | did_complete_page_scale_animation_(false), |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 109 | reduce_memory_result_(true) { |
chcunningham | fd11b3c | 2015-06-09 02:09:42 | [diff] [blame] | 110 | media::InitializeMediaLibrary(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 111 | } |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 112 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 113 | LayerTreeSettings DefaultSettings() { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 114 | LayerTreeSettings settings; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 115 | settings.minimum_occlusion_tracking_size = gfx::Size(); |
jbauman | c5be44c | 2014-11-20 22:17:12 | [diff] [blame] | 116 | settings.renderer_settings.texture_id_allocation_chunk_size = 1; |
senorblanco | 8d1b3ac | 2015-05-05 00:14:26 | [diff] [blame] | 117 | settings.gpu_rasterization_enabled = true; |
weiliangc | 365a6fe | 2016-05-12 19:32:31 | [diff] [blame] | 118 | settings.verify_clip_tree_calculations = true; |
jaydasika | 7de66e95 | 2016-07-01 01:36:48 | [diff] [blame] | 119 | settings.verify_transform_tree_calculations = true; |
ericrk | 9151705c | 2016-07-26 19:53:16 | [diff] [blame] | 120 | settings.renderer_settings.buffer_to_texture_target_map = |
| 121 | DefaultBufferToTextureTargetMapForTesting(); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 122 | return settings; |
| 123 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 124 | |
danakj | aeb9506 | 2014-11-14 01:35:36 | [diff] [blame] | 125 | void SetUp() override { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 126 | CreateHostImpl(DefaultSettings(), CreateOutputSurface()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 127 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 128 | |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 129 | void TearDown() override { |
| 130 | if (host_impl_) |
| 131 | host_impl_->ReleaseOutputSurface(); |
| 132 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 133 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 134 | void DidLoseOutputSurfaceOnImplThread() override {} |
enne | 19c10858 | 2016-04-14 03:35:32 | [diff] [blame] | 135 | void SetBeginFrameSource(BeginFrameSource* source) override {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 136 | void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 137 | void DidSwapBuffersCompleteOnImplThread() override {} |
| 138 | void OnCanDrawStateChanged(bool can_draw) override { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 139 | on_can_draw_state_changed_called_ = true; |
| 140 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 141 | void NotifyReadyToActivate() override { |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 142 | did_notify_ready_to_activate_ = true; |
[email protected] | fc20d14 | 2014-07-01 00:49:15 | [diff] [blame] | 143 | host_impl_->ActivateSyncTree(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 144 | } |
ernstm | dfac03e | 2014-11-11 20:18:05 | [diff] [blame] | 145 | void NotifyReadyToDraw() override {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 146 | void SetNeedsRedrawOnImplThread() override { did_request_redraw_ = true; } |
| 147 | void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) override { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 148 | did_request_redraw_ = true; |
| 149 | } |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 150 | void SetNeedsOneBeginImplFrameOnImplThread() override { |
| 151 | did_request_next_frame_ = true; |
| 152 | } |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 153 | void SetNeedsPrepareTilesOnImplThread() override { |
| 154 | did_request_prepare_tiles_ = true; |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 155 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 156 | void SetNeedsCommitOnImplThread() override { did_request_commit_ = true; } |
sunnyps | 7d073dc | 2015-04-16 23:29:12 | [diff] [blame] | 157 | void SetVideoNeedsBeginFrames(bool needs_begin_frames) override {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 158 | void PostAnimationEventsToMainThreadOnImplThread( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 159 | std::unique_ptr<AnimationEvents> events) override {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 160 | bool IsInsideDraw() override { return false; } |
| 161 | void RenewTreePriority() override {} |
sunnyps | ae4316a | 2015-02-25 00:54:58 | [diff] [blame] | 162 | void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 163 | base::TimeDelta delay) override { |
sunnyps | ae4316a | 2015-02-25 00:54:58 | [diff] [blame] | 164 | animation_task_ = task; |
| 165 | requested_animation_delay_ = delay; |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 166 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 167 | void DidActivateSyncTree() override {} |
brianderson | 6874981 | 2015-07-07 22:39:39 | [diff] [blame] | 168 | void WillPrepareTiles() override {} |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 169 | void DidPrepareTiles() override {} |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 170 | void DidCompletePageScaleAnimationOnImplThread() override { |
| 171 | did_complete_page_scale_animation_ = true; |
| 172 | } |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 173 | void OnDrawForOutputSurface(bool resourceless_software_draw) override { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 174 | std::unique_ptr<LayerTreeHostImpl::FrameData> frame( |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 175 | new LayerTreeHostImpl::FrameData); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 176 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(frame.get())); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 177 | last_on_draw_render_passes_.clear(); |
| 178 | RenderPass::CopyAll(frame->render_passes, &last_on_draw_render_passes_); |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 179 | host_impl_->DrawLayers(frame.get()); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 180 | host_impl_->DidDrawAllLayers(*frame); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 181 | last_on_draw_frame_ = std::move(frame); |
| 182 | } |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 183 | |
| 184 | void set_reduce_memory_result(bool reduce_memory_result) { |
| 185 | reduce_memory_result_ = reduce_memory_result; |
| 186 | } |
| 187 | |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 188 | virtual bool CreateHostImpl(const LayerTreeSettings& settings, |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 189 | std::unique_ptr<OutputSurface> output_surface) { |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 190 | return CreateHostImplWithTaskRunnerProvider( |
| 191 | settings, std::move(output_surface), &task_runner_provider_); |
| 192 | } |
| 193 | |
| 194 | virtual bool CreateHostImplWithTaskRunnerProvider( |
| 195 | const LayerTreeSettings& settings, |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 196 | std::unique_ptr<OutputSurface> output_surface, |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 197 | TaskRunnerProvider* task_runner_provider) { |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 198 | if (host_impl_) |
| 199 | host_impl_->ReleaseOutputSurface(); |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 200 | host_impl_ = LayerTreeHostImpl::Create( |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 201 | settings, this, task_runner_provider, &stats_instrumentation_, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 202 | &shared_bitmap_manager_, &gpu_memory_buffer_manager_, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 203 | &task_graph_runner_, |
| 204 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 205 | output_surface_ = std::move(output_surface); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 206 | host_impl_->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 207 | bool init = host_impl_->InitializeRenderer(output_surface_.get()); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 208 | host_impl_->SetViewportSize(gfx::Size(10, 10)); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 209 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 210 | // Set the BeginFrameArgs so that methods which use it are able to. |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 211 | host_impl_->WillBeginImplFrame(CreateBeginFrameArgsForTesting( |
| 212 | BEGINFRAME_FROM_HERE, |
| 213 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(1))); |
| 214 | host_impl_->DidFinishImplFrame(); |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 215 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 216 | timeline_ = |
| 217 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 218 | host_impl_->animation_host()->AddAnimationTimeline(timeline_); |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 219 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 220 | return init; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 221 | } |
| 222 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 223 | void SetupRootLayerImpl(std::unique_ptr<LayerImpl> root) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 224 | root->SetPosition(gfx::PointF()); |
| 225 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 226 | root->SetDrawsContent(true); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 227 | root->draw_properties().visible_layer_rect = gfx::Rect(0, 0, 10, 10); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 228 | root->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 229 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 230 | } |
| 231 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 232 | static gfx::Vector2dF ScrollDelta(LayerImpl* layer_impl) { |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 233 | gfx::ScrollOffset delta = |
| 234 | layer_impl->layer_tree_impl() |
| 235 | ->property_trees() |
| 236 | ->scroll_tree.GetScrollOffsetDeltaForTesting(layer_impl->id()); |
| 237 | return gfx::Vector2dF(delta.x(), delta.y()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 238 | } |
| 239 | |
sunxd | b2e13c9 | 2016-04-23 01:00:05 | [diff] [blame] | 240 | static void ExpectClearedScrollDeltasRecursive(LayerImpl* root) { |
| 241 | for (auto* layer : *root->layer_tree_impl()) |
| 242 | ASSERT_EQ(ScrollDelta(layer), gfx::Vector2d()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 243 | } |
| 244 | |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 245 | static ::testing::AssertionResult ScrollInfoContains( |
| 246 | const ScrollAndScaleSet& scroll_info, |
| 247 | int id, |
| 248 | const gfx::Vector2d& scroll_delta) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 249 | int times_encountered = 0; |
| 250 | |
| 251 | for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
| 252 | if (scroll_info.scrolls[i].layer_id != id) |
| 253 | continue; |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 254 | |
| 255 | if (scroll_delta != scroll_info.scrolls[i].scroll_delta) { |
| 256 | return ::testing::AssertionFailure() |
| 257 | << "Expected " << scroll_delta.ToString() << ", not " |
| 258 | << scroll_info.scrolls[i].scroll_delta.ToString(); |
| 259 | } |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 260 | times_encountered++; |
| 261 | } |
| 262 | |
bokan | 4222c27 | 2016-07-18 17:24:54 | [diff] [blame] | 263 | if (id == scroll_info.inner_viewport_scroll.layer_id) { |
| 264 | if (scroll_delta != scroll_info.inner_viewport_scroll.scroll_delta) { |
| 265 | return ::testing::AssertionFailure() |
| 266 | << "Expected " << scroll_delta.ToString() << ", not " |
| 267 | << scroll_info.inner_viewport_scroll.scroll_delta.ToString(); |
| 268 | } |
| 269 | times_encountered++; |
| 270 | } |
| 271 | |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 272 | if (times_encountered != 1) |
| 273 | return ::testing::AssertionFailure() << "No layer found with id " << id; |
| 274 | return ::testing::AssertionSuccess(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static void ExpectNone(const ScrollAndScaleSet& scroll_info, int id) { |
| 278 | int times_encountered = 0; |
| 279 | |
| 280 | for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
| 281 | if (scroll_info.scrolls[i].layer_id != id) |
| 282 | continue; |
| 283 | times_encountered++; |
| 284 | } |
| 285 | |
| 286 | ASSERT_EQ(0, times_encountered); |
| 287 | } |
| 288 | |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 289 | LayerImpl* CreateScrollAndContentsLayers(LayerTreeImpl* layer_tree_impl, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 290 | const gfx::Size& content_size) { |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 291 | // Create both an inner viewport scroll layer and an outer viewport scroll |
| 292 | // layer. The MaxScrollOffset of the outer viewport scroll layer will be |
| 293 | // 0x0, so the scrolls will be applied directly to the inner viewport. |
| 294 | const int kOuterViewportClipLayerId = 116; |
| 295 | const int kOuterViewportScrollLayerId = 117; |
| 296 | const int kContentLayerId = 118; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 297 | const int kInnerViewportScrollLayerId = 2; |
| 298 | const int kInnerViewportClipLayerId = 4; |
| 299 | const int kPageScaleLayerId = 5; |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 300 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 301 | std::unique_ptr<LayerImpl> root = LayerImpl::Create(layer_tree_impl, 1); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 302 | root->SetBounds(content_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 303 | root->SetPosition(gfx::PointF()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 304 | root->test_properties()->force_render_surface = true; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 305 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 306 | std::unique_ptr<LayerImpl> inner_scroll = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 307 | LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 308 | inner_scroll->test_properties()->is_container_for_fixed_position_layers = |
| 309 | true; |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 310 | inner_scroll->layer_tree_impl() |
| 311 | ->property_trees() |
| 312 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(inner_scroll->id(), |
| 313 | gfx::ScrollOffset()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 314 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 315 | std::unique_ptr<LayerImpl> inner_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 316 | LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 317 | inner_clip->SetBounds( |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 318 | gfx::Size(content_size.width() / 2, content_size.height() / 2)); |
| 319 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 320 | std::unique_ptr<LayerImpl> page_scale = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 321 | LayerImpl::Create(layer_tree_impl, kPageScaleLayerId); |
| 322 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 323 | inner_scroll->SetScrollClipLayer(inner_clip->id()); |
| 324 | inner_scroll->SetBounds(content_size); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 325 | inner_scroll->SetPosition(gfx::PointF()); |
| 326 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 327 | std::unique_ptr<LayerImpl> outer_clip = |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 328 | LayerImpl::Create(layer_tree_impl, kOuterViewportClipLayerId); |
| 329 | outer_clip->SetBounds(content_size); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 330 | outer_clip->test_properties()->is_container_for_fixed_position_layers = |
| 331 | true; |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 332 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 333 | std::unique_ptr<LayerImpl> outer_scroll = |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 334 | LayerImpl::Create(layer_tree_impl, kOuterViewportScrollLayerId); |
| 335 | outer_scroll->SetScrollClipLayer(outer_clip->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 336 | outer_scroll->layer_tree_impl() |
| 337 | ->property_trees() |
| 338 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(outer_scroll->id(), |
| 339 | gfx::ScrollOffset()); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 340 | outer_scroll->SetBounds(content_size); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 341 | outer_scroll->SetPosition(gfx::PointF()); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 342 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 343 | std::unique_ptr<LayerImpl> contents = |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 344 | LayerImpl::Create(layer_tree_impl, kContentLayerId); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 345 | contents->SetDrawsContent(true); |
| 346 | contents->SetBounds(content_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 347 | contents->SetPosition(gfx::PointF()); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 348 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 349 | outer_scroll->test_properties()->AddChild(std::move(contents)); |
| 350 | outer_clip->test_properties()->AddChild(std::move(outer_scroll)); |
| 351 | inner_scroll->test_properties()->AddChild(std::move(outer_clip)); |
| 352 | page_scale->test_properties()->AddChild(std::move(inner_scroll)); |
| 353 | inner_clip->test_properties()->AddChild(std::move(page_scale)); |
| 354 | root->test_properties()->AddChild(std::move(inner_clip)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 355 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 356 | layer_tree_impl->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 357 | layer_tree_impl->BuildPropertyTreesForTesting(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 358 | layer_tree_impl->SetViewportLayersFromIds( |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 359 | Layer::INVALID_ID, kPageScaleLayerId, kInnerViewportScrollLayerId, |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 360 | kOuterViewportScrollLayerId); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 361 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 362 | layer_tree_impl->DidBecomeActive(); |
| 363 | return layer_tree_impl->InnerViewportScrollLayer(); |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 364 | } |
| 365 | |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 366 | LayerImpl* SetupScrollAndContentsLayers(const gfx::Size& content_size) { |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 367 | LayerImpl* scroll_layer = CreateScrollAndContentsLayers( |
| 368 | host_impl_->active_tree(), content_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 369 | host_impl_->active_tree()->DidBecomeActive(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 370 | return scroll_layer; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 371 | } |
| 372 | |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 373 | // Sets up a typical virtual viewport setup with one child content layer. |
| 374 | // Returns a pointer to the content layer. |
| 375 | LayerImpl* CreateBasicVirtualViewportLayers(const gfx::Size& viewport_size, |
| 376 | const gfx::Size& content_size) { |
| 377 | // CreateScrollAndContentsLayers makes the outer viewport unscrollable and |
| 378 | // the inner a different size from the outer. We'll reuse its layer |
| 379 | // hierarchy but adjust the sizing to our needs. |
| 380 | CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size); |
| 381 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 382 | LayerImpl* content_layer = host_impl_->OuterViewportScrollLayer() |
| 383 | ->test_properties() |
| 384 | ->children.back(); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 385 | content_layer->SetBounds(content_size); |
| 386 | host_impl_->OuterViewportScrollLayer()->SetBounds(content_size); |
| 387 | |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 388 | LayerImpl* outer_clip = |
| 389 | host_impl_->OuterViewportScrollLayer()->test_properties()->parent; |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 390 | outer_clip->SetBounds(viewport_size); |
| 391 | |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 392 | LayerImpl* inner_clip_layer = host_impl_->InnerViewportScrollLayer() |
| 393 | ->test_properties() |
| 394 | ->parent->test_properties() |
| 395 | ->parent; |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 396 | inner_clip_layer->SetBounds(viewport_size); |
| 397 | host_impl_->InnerViewportScrollLayer()->SetBounds(viewport_size); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 398 | |
| 399 | // Needs to happen before building property trees as the latter propagates |
| 400 | // these element ids to property tree nodes. |
| 401 | host_impl_->active_tree()->SetElementIdsForTesting(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 402 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 403 | |
| 404 | host_impl_->SetViewportSize(viewport_size); |
| 405 | host_impl_->active_tree()->DidBecomeActive(); |
| 406 | |
| 407 | return content_layer; |
| 408 | } |
| 409 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 410 | std::unique_ptr<LayerImpl> CreateScrollableLayer(int id, |
| 411 | const gfx::Size& size, |
| 412 | LayerImpl* clip_layer) { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 413 | DCHECK(clip_layer); |
| 414 | DCHECK(id != clip_layer->id()); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 415 | std::unique_ptr<LayerImpl> layer = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 416 | LayerImpl::Create(host_impl_->active_tree(), id); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 417 | layer->SetScrollClipLayer(clip_layer->id()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 418 | layer->SetDrawsContent(true); |
| 419 | layer->SetBounds(size); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 420 | clip_layer->SetBounds(gfx::Size(size.width() / 2, size.height() / 2)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 421 | return layer; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 422 | } |
| 423 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 424 | std::unique_ptr<ScrollState> BeginState(const gfx::Point& point) { |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 425 | ScrollStateData scroll_state_data; |
| 426 | scroll_state_data.is_beginning = true; |
bokan | 578ff4a | 2016-04-12 21:54:05 | [diff] [blame] | 427 | scroll_state_data.position_x = point.x(); |
| 428 | scroll_state_data.position_y = point.y(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 429 | std::unique_ptr<ScrollState> scroll_state( |
| 430 | new ScrollState(scroll_state_data)); |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 431 | return scroll_state; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 432 | } |
| 433 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 434 | std::unique_ptr<ScrollState> UpdateState(const gfx::Point& point, |
| 435 | const gfx::Vector2dF& delta) { |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 436 | ScrollStateData scroll_state_data; |
| 437 | scroll_state_data.delta_x = delta.x(); |
| 438 | scroll_state_data.delta_y = delta.y(); |
bokan | 578ff4a | 2016-04-12 21:54:05 | [diff] [blame] | 439 | scroll_state_data.position_x = point.x(); |
| 440 | scroll_state_data.position_y = point.y(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 441 | std::unique_ptr<ScrollState> scroll_state( |
| 442 | new ScrollState(scroll_state_data)); |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 443 | return scroll_state; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 444 | } |
| 445 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 446 | std::unique_ptr<ScrollState> EndState() { |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 447 | ScrollStateData scroll_state_data; |
| 448 | scroll_state_data.is_ending = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 449 | std::unique_ptr<ScrollState> scroll_state( |
| 450 | new ScrollState(scroll_state_data)); |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 451 | return scroll_state; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 452 | } |
| 453 | |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 454 | void DrawFrame() { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 455 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 456 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 457 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 458 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | void pinch_zoom_pan_viewport_forces_commit_redraw(float device_scale_factor); |
| 462 | void pinch_zoom_pan_viewport_test(float device_scale_factor); |
| 463 | void pinch_zoom_pan_viewport_and_scroll_test(float device_scale_factor); |
| 464 | void pinch_zoom_pan_viewport_and_scroll_boundary_test( |
| 465 | float device_scale_factor); |
| 466 | |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 467 | void SetupMouseMoveAtWithDeviceScale(float device_scale_factor); |
| 468 | |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 469 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 470 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 471 | protected: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 472 | virtual std::unique_ptr<OutputSurface> CreateOutputSurface() { |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 473 | return FakeOutputSurface::CreateDelegating3d(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | void DrawOneFrame() { |
| 477 | LayerTreeHostImpl::FrameData frame_data; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 478 | host_impl_->PrepareToDraw(&frame_data); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 479 | host_impl_->DidDrawAllLayers(frame_data); |
| 480 | } |
| 481 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 482 | static void SetScrollOffsetDelta(LayerImpl* layer_impl, |
| 483 | const gfx::Vector2dF& delta) { |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 484 | if (layer_impl->layer_tree_impl() |
| 485 | ->property_trees() |
| 486 | ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(), |
| 487 | delta)) |
| 488 | layer_impl->layer_tree_impl()->DidUpdateScrollOffset( |
| 489 | layer_impl->id(), layer_impl->transform_tree_index()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 490 | } |
| 491 | |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 492 | void BeginImplFrameAndAnimate(BeginFrameArgs begin_frame_args, |
| 493 | base::TimeTicks frame_time) { |
| 494 | begin_frame_args.frame_time = frame_time; |
| 495 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 496 | host_impl_->Animate(); |
| 497 | host_impl_->UpdateAnimationState(true); |
| 498 | host_impl_->DidFinishImplFrame(); |
| 499 | } |
| 500 | |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame] | 501 | FakeImplTaskRunnerProvider task_runner_provider_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 502 | DebugScopedSetMainThreadBlocked always_main_thread_blocked_; |
| 503 | |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 504 | TestSharedBitmapManager shared_bitmap_manager_; |
| 505 | TestGpuMemoryBufferManager gpu_memory_buffer_manager_; |
| 506 | TestTaskGraphRunner task_graph_runner_; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 507 | std::unique_ptr<OutputSurface> output_surface_; |
| 508 | std::unique_ptr<LayerTreeHostImpl> host_impl_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 509 | FakeRenderingStatsInstrumentation stats_instrumentation_; |
| 510 | bool on_can_draw_state_changed_called_; |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 511 | bool did_notify_ready_to_activate_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 512 | bool did_request_commit_; |
| 513 | bool did_request_redraw_; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 514 | bool did_request_next_frame_; |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 515 | bool did_request_prepare_tiles_; |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 516 | bool did_complete_page_scale_animation_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 517 | bool reduce_memory_result_; |
sunnyps | ae4316a | 2015-02-25 00:54:58 | [diff] [blame] | 518 | base::Closure animation_task_; |
| 519 | base::TimeDelta requested_animation_delay_; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 520 | std::unique_ptr<LayerTreeHostImpl::FrameData> last_on_draw_frame_; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 521 | RenderPassList last_on_draw_render_passes_; |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 522 | scoped_refptr<AnimationTimeline> timeline_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 523 | }; |
| 524 | |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 525 | // A test fixture for new animation timelines tests. |
| 526 | class LayerTreeHostImplTimelinesTest : public LayerTreeHostImplTest { |
| 527 | public: |
| 528 | void SetUp() override { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 529 | CreateHostImpl(DefaultSettings(), CreateOutputSurface()); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 530 | } |
| 531 | }; |
| 532 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 533 | TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 534 | // Note: It is not possible to disable the renderer once it has been set, |
| 535 | // so we do not need to test that disabling the renderer notifies us |
| 536 | // that can_draw changed. |
| 537 | EXPECT_FALSE(host_impl_->CanDraw()); |
| 538 | on_can_draw_state_changed_called_ = false; |
| 539 | |
| 540 | // Set up the root layer, which allows us to draw. |
| 541 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 542 | EXPECT_TRUE(host_impl_->CanDraw()); |
| 543 | EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 544 | on_can_draw_state_changed_called_ = false; |
| 545 | |
| 546 | // Toggle the root layer to make sure it toggles can_draw |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 547 | host_impl_->active_tree()->SetRootLayerForTesting(nullptr); |
rockot | 2176f92 | 2016-06-08 19:18:32 | [diff] [blame] | 548 | host_impl_->active_tree()->DetachLayers(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 549 | EXPECT_FALSE(host_impl_->CanDraw()); |
| 550 | EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 551 | on_can_draw_state_changed_called_ = false; |
| 552 | |
| 553 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 554 | EXPECT_TRUE(host_impl_->CanDraw()); |
| 555 | EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 556 | on_can_draw_state_changed_called_ = false; |
| 557 | |
| 558 | // Toggle the device viewport size to make sure it toggles can_draw. |
| 559 | host_impl_->SetViewportSize(gfx::Size()); |
| 560 | EXPECT_FALSE(host_impl_->CanDraw()); |
| 561 | EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 562 | on_can_draw_state_changed_called_ = false; |
| 563 | |
| 564 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 565 | EXPECT_TRUE(host_impl_->CanDraw()); |
| 566 | EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 567 | on_can_draw_state_changed_called_ = false; |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 568 | } |
| 569 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 570 | TEST_F(LayerTreeHostImplTest, ResourcelessDrawWithEmptyViewport) { |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 571 | CreateHostImpl(DefaultSettings(), |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 572 | FakeOutputSurface::CreateDelegatingSoftware()); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 573 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 574 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 575 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 576 | EXPECT_TRUE(host_impl_->CanDraw()); |
| 577 | host_impl_->SetViewportSize(gfx::Size()); |
| 578 | EXPECT_FALSE(host_impl_->CanDraw()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 579 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 580 | FakeOutputSurface* fake_output_surface = |
| 581 | static_cast<FakeOutputSurface*>(host_impl_->output_surface()); |
| 582 | EXPECT_EQ(fake_output_surface->num_sent_frames(), 0u); |
| 583 | gfx::Transform identity; |
| 584 | gfx::Rect viewport(100, 100); |
| 585 | const bool resourceless_software_draw = true; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 586 | host_impl_->OnDraw(identity, viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 587 | ASSERT_EQ(fake_output_surface->num_sent_frames(), 1u); |
| 588 | EXPECT_EQ(gfx::SizeF(100.f, 100.f), |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 589 | fake_output_surface->last_sent_frame()->metadata.root_layer_size); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 590 | } |
| 591 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 592 | TEST_F(LayerTreeHostImplTest, ScrollDeltaNoLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 593 | ASSERT_FALSE(host_impl_->active_tree()->root_layer_for_testing()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 594 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 595 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 596 | host_impl_->ProcessScrollDeltas(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 597 | ASSERT_EQ(scroll_info->scrolls.size(), 0u); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 598 | } |
| 599 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 600 | TEST_F(LayerTreeHostImplTest, ScrollDeltaTreeButNoChanges) { |
| 601 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 602 | std::unique_ptr<LayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 603 | LayerImpl::Create(host_impl_->active_tree(), 1); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 604 | root->test_properties()->AddChild( |
| 605 | LayerImpl::Create(host_impl_->active_tree(), 2)); |
| 606 | root->test_properties()->AddChild( |
| 607 | LayerImpl::Create(host_impl_->active_tree(), 3)); |
| 608 | root->test_properties()->children[1]->test_properties()->AddChild( |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 609 | LayerImpl::Create(host_impl_->active_tree(), 4)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 610 | root->test_properties()->children[1]->test_properties()->AddChild( |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 611 | LayerImpl::Create(host_impl_->active_tree(), 5)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 612 | root->test_properties() |
| 613 | ->children[1] |
| 614 | ->test_properties() |
| 615 | ->children[0] |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 616 | ->test_properties() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 617 | ->AddChild(LayerImpl::Create(host_impl_->active_tree(), 6)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 618 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 619 | } |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 620 | LayerImpl* root = *host_impl_->active_tree()->begin(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 621 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 622 | ExpectClearedScrollDeltasRecursive(root); |
[email protected] | 0ede3bb | 2012-12-09 09:14:39 | [diff] [blame] | 623 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 624 | std::unique_ptr<ScrollAndScaleSet> scroll_info; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 625 | |
| 626 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 627 | ASSERT_EQ(scroll_info->scrolls.size(), 0u); |
| 628 | ExpectClearedScrollDeltasRecursive(root); |
| 629 | |
| 630 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 631 | ASSERT_EQ(scroll_info->scrolls.size(), 0u); |
| 632 | ExpectClearedScrollDeltasRecursive(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 633 | } |
| 634 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 635 | TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 636 | gfx::ScrollOffset scroll_offset(20, 30); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 637 | gfx::Vector2d scroll_delta(11, -15); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 638 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 639 | auto root_clip_owned = LayerImpl::Create(host_impl_->active_tree(), 2); |
| 640 | auto* root_clip = root_clip_owned.get(); |
| 641 | auto root_owned = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 642 | auto* root = root_owned.get(); |
| 643 | |
| 644 | root_clip->SetBounds(gfx::Size(10, 10)); |
| 645 | root_clip->test_properties()->AddChild(std::move(root_owned)); |
| 646 | root->SetBounds(gfx::Size(110, 110)); |
| 647 | root->SetScrollClipLayer(root_clip->id()); |
| 648 | root->layer_tree_impl() |
| 649 | ->property_trees() |
| 650 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(root->id(), scroll_offset); |
| 651 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_clip_owned)); |
| 652 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 653 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 654 | std::unique_ptr<ScrollAndScaleSet> scroll_info; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 655 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 656 | root->ScrollBy(scroll_delta); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 657 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 658 | ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 659 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, root->id(), scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 660 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 661 | gfx::Vector2d scroll_delta2(-5, 27); |
| 662 | root->ScrollBy(scroll_delta2); |
| 663 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 664 | ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 665 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, root->id(), |
| 666 | scroll_delta + scroll_delta2)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 667 | |
| 668 | root->ScrollBy(gfx::Vector2d()); |
| 669 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 670 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, root->id(), |
| 671 | scroll_delta + scroll_delta2)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 672 | } |
| 673 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 674 | TEST_F(LayerTreeHostImplTest, ScrollRootCallsCommitAndRedraw) { |
| 675 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 676 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 677 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 678 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 679 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 680 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 681 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 682 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 683 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 684 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 685 | status.main_thread_scrolling_reasons); |
| 686 | |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 687 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 688 | InputHandler::WHEEL)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 689 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 690 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(0, 10), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 691 | InputHandler::WHEEL)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 692 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 693 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 694 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 695 | InputHandler::WHEEL)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 696 | EXPECT_TRUE(did_request_redraw_); |
| 697 | EXPECT_TRUE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 698 | } |
| 699 | |
jdduke | 16dde6e | 2014-10-24 00:22:56 | [diff] [blame] | 700 | TEST_F(LayerTreeHostImplTest, ScrollActiveOnlyAfterScrollMovement) { |
| 701 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 702 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 703 | |
jdduke | 16dde6e | 2014-10-24 00:22:56 | [diff] [blame] | 704 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 705 | DrawFrame(); |
| 706 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 707 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 708 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 709 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 710 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 711 | status.main_thread_scrolling_reasons); |
| 712 | |
jdduke | 16dde6e | 2014-10-24 00:22:56 | [diff] [blame] | 713 | EXPECT_FALSE(host_impl_->IsActivelyScrolling()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 714 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
jdduke | 16dde6e | 2014-10-24 00:22:56 | [diff] [blame] | 715 | EXPECT_TRUE(host_impl_->IsActivelyScrolling()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 716 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 717 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
jdduke | 16dde6e | 2014-10-24 00:22:56 | [diff] [blame] | 718 | EXPECT_FALSE(host_impl_->IsActivelyScrolling()); |
| 719 | } |
| 720 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 721 | TEST_F(LayerTreeHostImplTest, ScrollWithoutRootLayer) { |
| 722 | // We should not crash when trying to scroll an empty layer tree. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 723 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 724 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 725 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 726 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 727 | status.main_thread_scrolling_reasons); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 728 | } |
| 729 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 730 | TEST_F(LayerTreeHostImplTest, ScrollWithoutRenderer) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 731 | std::unique_ptr<TestWebGraphicsContext3D> context_owned = |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 732 | TestWebGraphicsContext3D::Create(); |
[email protected] | c9addd1 | 2013-12-08 22:43:26 | [diff] [blame] | 733 | context_owned->set_context_lost(true); |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 734 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 735 | // Initialization will fail. |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 736 | EXPECT_FALSE(CreateHostImpl( |
| 737 | DefaultSettings(), |
| 738 | FakeOutputSurface::CreateDelegating3d(std::move(context_owned)))); |
[email protected] | a90aa70 | 2012-11-07 04:48:24 | [diff] [blame] | 739 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 740 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 741 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 742 | // We should not crash when trying to scroll after the renderer initialization |
| 743 | // fails. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 744 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 745 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 746 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 747 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 748 | status.main_thread_scrolling_reasons); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 749 | } |
| 750 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 751 | TEST_F(LayerTreeHostImplTest, ReplaceTreeWhileScrolling) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 752 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 753 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 754 | DrawFrame(); |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 755 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 756 | // We should not crash if the tree is replaced while we are scrolling. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 757 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 758 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 759 | InputHandler::WHEEL) |
| 760 | .thread); |
rockot | 2176f92 | 2016-06-08 19:18:32 | [diff] [blame] | 761 | host_impl_->active_tree()->DetachLayers(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 762 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 763 | scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 764 | |
| 765 | // We should still be scrolling, because the scrolled layer also exists in the |
| 766 | // new tree. |
| 767 | gfx::Vector2d scroll_delta(0, 10); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 768 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 769 | host_impl_->ScrollEnd(EndState().get()); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 770 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 771 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 772 | EXPECT_TRUE( |
| 773 | ScrollInfoContains(*scroll_info, scroll_layer->id(), scroll_delta)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 774 | } |
| 775 | |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 776 | TEST_F(LayerTreeHostImplTest, ScrollBlocksOnWheelEventHandlers) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 777 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 778 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 779 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 780 | |
dtapuska | e7dd21de | 2016-06-09 13:41:56 | [diff] [blame] | 781 | // Wheel handlers determine whether mouse events block scroll. |
dtapuska | f206a40d | 2016-02-05 21:36:02 | [diff] [blame] | 782 | host_impl_->active_tree()->set_event_listener_properties( |
| 783 | EventListenerClass::kMouseWheel, EventListenerProperties::kBlocking); |
dtapuska | e7dd21de | 2016-06-09 13:41:56 | [diff] [blame] | 784 | EXPECT_EQ( |
| 785 | EventListenerProperties::kBlocking, |
| 786 | host_impl_->GetEventListenerProperties(EventListenerClass::kMouseWheel)); |
| 787 | |
| 788 | // But they don't influence the actual handling of the scroll gestures. |
dtapuska | cd423123 | 2016-01-28 19:18:11 | [diff] [blame] | 789 | InputHandler::ScrollStatus status = |
| 790 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 791 | InputHandler::WHEEL); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 792 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 793 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 794 | status.main_thread_scrolling_reasons); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 795 | host_impl_->ScrollEnd(EndState().get()); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | TEST_F(LayerTreeHostImplTest, ScrollBlocksOnTouchEventHandlers) { |
| 799 | LayerImpl* scroll = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 800 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 801 | DrawFrame(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 802 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 803 | |
| 804 | LayerImpl* child = 0; |
| 805 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 806 | std::unique_ptr<LayerImpl> child_layer = |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 807 | LayerImpl::Create(host_impl_->active_tree(), 6); |
| 808 | child = child_layer.get(); |
| 809 | child_layer->SetDrawsContent(true); |
| 810 | child_layer->SetPosition(gfx::PointF(0, 20)); |
| 811 | child_layer->SetBounds(gfx::Size(50, 50)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 812 | scroll->test_properties()->AddChild(std::move(child_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 813 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | // Touch handler regions determine whether touch events block scroll. |
| 817 | root->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 818 | EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 10))); |
| 819 | |
| 820 | // But they don't influence the actual handling of the scroll gestures. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 821 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 822 | BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 823 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 824 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 825 | status.main_thread_scrolling_reasons); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 826 | host_impl_->ScrollEnd(EndState().get()); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 827 | |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 828 | EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); |
dtapuska | cd423123 | 2016-01-28 19:18:11 | [diff] [blame] | 829 | root->SetTouchEventHandlerRegion(gfx::Rect()); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 830 | EXPECT_FALSE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); |
dtapuska | cd423123 | 2016-01-28 19:18:11 | [diff] [blame] | 831 | child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50)); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 832 | EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); |
| 833 | } |
| 834 | |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 835 | TEST_F(LayerTreeHostImplTest, FlingOnlyWhenScrollingTouchscreen) { |
| 836 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 837 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 838 | DrawFrame(); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 839 | |
| 840 | // Ignore the fling since no layer is being scrolled |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 841 | InputHandler::ScrollStatus status = host_impl_->FlingScrollBegin(); |
| 842 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 843 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 844 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 845 | |
| 846 | // Start scrolling a layer |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 847 | status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 848 | InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 849 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 850 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 851 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 852 | |
| 853 | // Now the fling should go ahead since we've started scrolling a layer |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 854 | status = host_impl_->FlingScrollBegin(); |
| 855 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 856 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 857 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | TEST_F(LayerTreeHostImplTest, FlingOnlyWhenScrollingTouchpad) { |
| 861 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 862 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 863 | DrawFrame(); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 864 | |
| 865 | // Ignore the fling since no layer is being scrolled |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 866 | InputHandler::ScrollStatus status = host_impl_->FlingScrollBegin(); |
| 867 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 868 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 869 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 870 | |
| 871 | // Start scrolling a layer |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 872 | status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 873 | InputHandler::WHEEL); |
| 874 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 875 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 876 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 877 | |
| 878 | // Now the fling should go ahead since we've started scrolling a layer |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 879 | status = host_impl_->FlingScrollBegin(); |
| 880 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 881 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 882 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | TEST_F(LayerTreeHostImplTest, NoFlingWhenScrollingOnMain) { |
| 886 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 887 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 888 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 889 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 890 | root->set_main_thread_scrolling_reasons( |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 891 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 892 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 893 | |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 894 | DrawFrame(); |
| 895 | |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 896 | // Start scrolling a layer |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 897 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 898 | BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 899 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 900 | EXPECT_EQ(MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 901 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 902 | |
| 903 | // The fling should be ignored since there's no layer being scrolled impl-side |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 904 | status = host_impl_->FlingScrollBegin(); |
| 905 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 906 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 907 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 908 | } |
| 909 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 910 | TEST_F(LayerTreeHostImplTest, ShouldScrollOnMainThread) { |
| 911 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 912 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 913 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 914 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 915 | root->set_main_thread_scrolling_reasons( |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 916 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 917 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 918 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 919 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 920 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 921 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 922 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 923 | EXPECT_EQ(MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 924 | status.main_thread_scrolling_reasons); |
| 925 | |
| 926 | status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 927 | InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 928 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 929 | EXPECT_EQ(MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 930 | status.main_thread_scrolling_reasons); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 931 | } |
| 932 | |
sunxd | 0b34eb5 | 2016-04-13 01:13:39 | [diff] [blame] | 933 | TEST_F(LayerTreeHostImplTest, ScrollWithOverlappingNonScrollableLayer) { |
| 934 | LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 935 | gfx::Size content_size = gfx::Size(360, 600); |
| 936 | gfx::Size scroll_content_size = gfx::Size(345, 3800); |
| 937 | gfx::Size scrollbar_size = gfx::Size(15, 600); |
| 938 | |
| 939 | host_impl_->SetViewportSize(content_size); |
| 940 | std::unique_ptr<LayerImpl> root = LayerImpl::Create(layer_tree_impl, 1); |
| 941 | root->SetBounds(content_size); |
| 942 | root->SetPosition(gfx::PointF()); |
| 943 | |
| 944 | std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 2); |
| 945 | clip->SetBounds(content_size); |
| 946 | clip->SetPosition(gfx::PointF()); |
| 947 | |
| 948 | std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 3); |
| 949 | scroll->SetBounds(scroll_content_size); |
| 950 | scroll->SetScrollClipLayer(clip->id()); |
| 951 | scroll->SetDrawsContent(true); |
| 952 | |
| 953 | std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
| 954 | SolidColorScrollbarLayerImpl::Create(layer_tree_impl, 4, VERTICAL, 10, 0, |
| 955 | false, true); |
| 956 | scrollbar->SetBounds(scrollbar_size); |
| 957 | scrollbar->SetPosition(gfx::PointF(345, 0)); |
| 958 | scrollbar->SetScrollLayerId(scroll->id()); |
sunxd | 0b34eb5 | 2016-04-13 01:13:39 | [diff] [blame] | 959 | scrollbar->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 960 | scrollbar->test_properties()->opacity = 1.f; |
sunxd | 0b34eb5 | 2016-04-13 01:13:39 | [diff] [blame] | 961 | |
| 962 | std::unique_ptr<LayerImpl> squash1 = LayerImpl::Create(layer_tree_impl, 5); |
| 963 | squash1->SetBounds(gfx::Size(140, 300)); |
| 964 | squash1->SetPosition(gfx::PointF(220, 0)); |
| 965 | squash1->SetDrawsContent(true); |
| 966 | |
| 967 | std::unique_ptr<LayerImpl> squash2 = LayerImpl::Create(layer_tree_impl, 6); |
| 968 | squash2->SetBounds(gfx::Size(140, 300)); |
| 969 | squash2->SetPosition(gfx::PointF(220, 300)); |
| 970 | squash2->SetDrawsContent(true); |
| 971 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 972 | scroll->test_properties()->AddChild(std::move(squash2)); |
| 973 | clip->test_properties()->AddChild(std::move(scroll)); |
| 974 | clip->test_properties()->AddChild(std::move(scrollbar)); |
| 975 | clip->test_properties()->AddChild(std::move(squash1)); |
| 976 | root->test_properties()->AddChild(std::move(clip)); |
sunxd | 0b34eb5 | 2016-04-13 01:13:39 | [diff] [blame] | 977 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 978 | layer_tree_impl->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 979 | layer_tree_impl->BuildPropertyTreesForTesting(); |
sunxd | 0b34eb5 | 2016-04-13 01:13:39 | [diff] [blame] | 980 | layer_tree_impl->DidBecomeActive(); |
| 981 | |
| 982 | // The point hits squash1 layer and also scroll layer, because scroll layer is |
| 983 | // not an ancestor of squash1 layer, we cannot scroll on impl thread. |
| 984 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 985 | BeginState(gfx::Point(230, 150)).get(), InputHandler::WHEEL); |
| 986 | EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); |
| 987 | EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, |
| 988 | status.main_thread_scrolling_reasons); |
| 989 | |
| 990 | // The point hits squash1 layer and also scrollbar layer. |
| 991 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(350, 150)).get(), |
| 992 | InputHandler::WHEEL); |
| 993 | EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); |
| 994 | EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, |
| 995 | status.main_thread_scrolling_reasons); |
| 996 | |
| 997 | // The point hits squash2 layer and also scroll layer, because scroll layer is |
| 998 | // an ancestor of squash2 layer, we should scroll on impl. |
| 999 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(230, 450)).get(), |
| 1000 | InputHandler::WHEEL); |
| 1001 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
| 1002 | } |
| 1003 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1004 | TEST_F(LayerTreeHostImplTest, NonFastScrollableRegionBasic) { |
| 1005 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 1006 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1007 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1008 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1009 | root->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
| 1010 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1011 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1012 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1013 | |
| 1014 | // All scroll types inside the non-fast scrollable region should fail. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1015 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 1016 | BeginState(gfx::Point(25, 25)).get(), InputHandler::WHEEL); |
| 1017 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1018 | EXPECT_EQ(MainThreadScrollingReason::kNonFastScrollableRegion, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1019 | status.main_thread_scrolling_reasons); |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 1020 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(25, 25), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1021 | InputHandler::WHEEL)); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1022 | |
| 1023 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(25, 25)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1024 | InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1025 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1026 | EXPECT_EQ(MainThreadScrollingReason::kNonFastScrollableRegion, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1027 | status.main_thread_scrolling_reasons); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1028 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1029 | gfx::Point(25, 25), InputHandler::TOUCHSCREEN)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1030 | |
| 1031 | // All scroll types outside this region should succeed. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1032 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(75, 75)).get(), |
| 1033 | InputHandler::WHEEL); |
| 1034 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1035 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1036 | status.main_thread_scrolling_reasons); |
| 1037 | |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1038 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1039 | gfx::Point(75, 75), InputHandler::TOUCHSCREEN)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1040 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1041 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1042 | gfx::Point(25, 25), InputHandler::TOUCHSCREEN)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1043 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 1044 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1045 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1046 | gfx::Point(75, 75), InputHandler::TOUCHSCREEN)); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1047 | |
| 1048 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(75, 75)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1049 | InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1050 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1051 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1052 | status.main_thread_scrolling_reasons); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1053 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1054 | gfx::Point(75, 75), InputHandler::TOUCHSCREEN)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1055 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
| 1056 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 1057 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1058 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1059 | gfx::Point(75, 75), InputHandler::TOUCHSCREEN)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | TEST_F(LayerTreeHostImplTest, NonFastScrollableRegionWithOffset) { |
| 1063 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 1064 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1065 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1066 | LayerImpl* root = *host_impl_->active_tree()->begin(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1067 | root->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
| 1068 | root->SetPosition(gfx::PointF(-25.f, 0.f)); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1069 | root->SetDrawsContent(true); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1070 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1071 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1072 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1073 | |
| 1074 | // This point would fall into the non-fast scrollable region except that we've |
| 1075 | // moved the layer down by 25 pixels. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1076 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 1077 | BeginState(gfx::Point(40, 10)).get(), InputHandler::WHEEL); |
| 1078 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1079 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1080 | status.main_thread_scrolling_reasons); |
| 1081 | |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 1082 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(40, 10), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1083 | InputHandler::WHEEL)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1084 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 1)).get()); |
| 1085 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1086 | |
| 1087 | // This point is still inside the non-fast region. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1088 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), |
| 1089 | InputHandler::WHEEL); |
| 1090 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1091 | EXPECT_EQ(MainThreadScrollingReason::kNonFastScrollableRegion, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1092 | status.main_thread_scrolling_reasons); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1093 | } |
| 1094 | |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1095 | TEST_F(LayerTreeHostImplTest, ScrollHandlerNotPresent) { |
dtapuska | f024e55 | 2016-02-03 01:19:46 | [diff] [blame] | 1096 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
| 1097 | EXPECT_FALSE(host_impl_->active_tree()->have_scroll_event_handlers()); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1098 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1099 | DrawFrame(); |
| 1100 | |
| 1101 | EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1102 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1103 | InputHandler::TOUCHSCREEN); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1104 | EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1105 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1106 | EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler()); |
| 1107 | } |
| 1108 | |
| 1109 | TEST_F(LayerTreeHostImplTest, ScrollHandlerPresent) { |
dtapuska | f024e55 | 2016-02-03 01:19:46 | [diff] [blame] | 1110 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
| 1111 | host_impl_->active_tree()->set_have_scroll_event_handlers(true); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1112 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1113 | DrawFrame(); |
| 1114 | |
| 1115 | EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1116 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1117 | InputHandler::TOUCHSCREEN); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1118 | EXPECT_TRUE(host_impl_->scroll_affects_scroll_handler()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1119 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 1120 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1121 | EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler()); |
| 1122 | } |
| 1123 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1124 | TEST_F(LayerTreeHostImplTest, ScrollByReturnsCorrectValue) { |
| 1125 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 1126 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1127 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1128 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1129 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1130 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1131 | BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1132 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1133 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1134 | status.main_thread_scrolling_reasons); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1135 | |
| 1136 | // Trying to scroll to the left/top will not succeed. |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1137 | EXPECT_FALSE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1138 | host_impl_->ScrollBy( |
| 1139 | UpdateState(gfx::Point(), gfx::Vector2d(-10, 0)).get()) |
| 1140 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1141 | EXPECT_FALSE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1142 | host_impl_->ScrollBy( |
| 1143 | UpdateState(gfx::Point(), gfx::Vector2d(0, -10)).get()) |
| 1144 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1145 | EXPECT_FALSE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1146 | host_impl_->ScrollBy( |
| 1147 | UpdateState(gfx::Point(), gfx::Vector2d(-10, -10)).get()) |
| 1148 | .did_scroll); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1149 | |
| 1150 | // Scrolling to the right/bottom will succeed. |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1151 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1152 | host_impl_->ScrollBy( |
| 1153 | UpdateState(gfx::Point(), gfx::Vector2d(10, 0)).get()) |
| 1154 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1155 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1156 | host_impl_->ScrollBy( |
| 1157 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()) |
| 1158 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1159 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1160 | host_impl_->ScrollBy( |
| 1161 | UpdateState(gfx::Point(), gfx::Vector2d(10, 10)).get()) |
| 1162 | .did_scroll); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1163 | |
| 1164 | // Scrolling to left/top will now succeed. |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1165 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1166 | host_impl_->ScrollBy( |
| 1167 | UpdateState(gfx::Point(), gfx::Vector2d(-10, 0)).get()) |
| 1168 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1169 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1170 | host_impl_->ScrollBy( |
| 1171 | UpdateState(gfx::Point(), gfx::Vector2d(0, -10)).get()) |
| 1172 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1173 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1174 | host_impl_->ScrollBy( |
| 1175 | UpdateState(gfx::Point(), gfx::Vector2d(-10, -10)).get()) |
| 1176 | .did_scroll); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1177 | |
| 1178 | // Scrolling diagonally against an edge will succeed. |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1179 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1180 | host_impl_->ScrollBy( |
| 1181 | UpdateState(gfx::Point(), gfx::Vector2d(10, -10)).get()) |
| 1182 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1183 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1184 | host_impl_->ScrollBy( |
| 1185 | UpdateState(gfx::Point(), gfx::Vector2d(-10, 0)).get()) |
| 1186 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1187 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1188 | host_impl_->ScrollBy( |
| 1189 | UpdateState(gfx::Point(), gfx::Vector2d(-10, 10)).get()) |
| 1190 | .did_scroll); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1191 | |
| 1192 | // Trying to scroll more than the available space will also succeed. |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1193 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1194 | host_impl_->ScrollBy( |
| 1195 | UpdateState(gfx::Point(), gfx::Vector2d(5000, 5000)).get()) |
| 1196 | .did_scroll); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | TEST_F(LayerTreeHostImplTest, ScrollVerticallyByPageReturnsCorrectValue) { |
| 1200 | SetupScrollAndContentsLayers(gfx::Size(200, 2000)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 1201 | host_impl_->SetViewportSize(gfx::Size(100, 1000)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1202 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1203 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1204 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1205 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1206 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1207 | InputHandler::WHEEL) |
| 1208 | .thread); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1209 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 1210 | // Trying to scroll if not user_scrollable_vertical will fail. |
| 1211 | host_impl_->InnerViewportScrollLayer()->set_user_scrollable_vertical(false); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1212 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | 2668bea6 | 2016-03-17 00:49:47 | [diff] [blame] | 1213 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1214 | EXPECT_FALSE(host_impl_->ScrollVerticallyByPage( |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 1215 | gfx::Point(), SCROLL_FORWARD)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1216 | EXPECT_FALSE(host_impl_->ScrollVerticallyByPage( |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 1217 | gfx::Point(), SCROLL_BACKWARD)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1218 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 1219 | host_impl_->InnerViewportScrollLayer()->set_user_scrollable_vertical(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1220 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | 2668bea6 | 2016-03-17 00:49:47 | [diff] [blame] | 1221 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1222 | EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 1223 | gfx::Point(), SCROLL_FORWARD)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1224 | EXPECT_FLOAT_EQ(875.f, |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1225 | ScrollDelta(host_impl_->InnerViewportScrollLayer()).y()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1226 | EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 1227 | gfx::Point(), SCROLL_BACKWARD)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1228 | } |
| 1229 | |
aelias | af915a88 | 2014-10-14 04:12:04 | [diff] [blame] | 1230 | TEST_F(LayerTreeHostImplTest, ScrollWithUserUnscrollableLayers) { |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1231 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
| 1232 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 1233 | |
| 1234 | gfx::Size overflow_size(400, 400); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 1235 | ASSERT_EQ(1u, scroll_layer->test_properties()->children.size()); |
| 1236 | LayerImpl* overflow = scroll_layer->test_properties()->children[0]; |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1237 | overflow->SetBounds(overflow_size); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 1238 | overflow->SetScrollClipLayer( |
| 1239 | scroll_layer->test_properties()->parent->test_properties()->parent->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1240 | overflow->layer_tree_impl() |
| 1241 | ->property_trees() |
| 1242 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(overflow->id(), |
| 1243 | gfx::ScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1244 | overflow->SetPosition(gfx::PointF()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1245 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1246 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1247 | DrawFrame(); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1248 | gfx::Point scroll_position(10, 10); |
| 1249 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1250 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1251 | host_impl_->ScrollBegin(BeginState(scroll_position).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1252 | InputHandler::WHEEL) |
| 1253 | .thread); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1254 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->CurrentScrollOffset()); |
| 1255 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1256 | |
| 1257 | gfx::Vector2dF scroll_delta(10, 10); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1258 | host_impl_->ScrollBy(UpdateState(scroll_position, scroll_delta).get()); |
| 1259 | host_impl_->ScrollEnd(EndState().get()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1260 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->CurrentScrollOffset()); |
| 1261 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 10), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1262 | |
| 1263 | overflow->set_user_scrollable_horizontal(false); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1264 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 1265 | |
sunxd | 2668bea6 | 2016-03-17 00:49:47 | [diff] [blame] | 1266 | DrawFrame(); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1267 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1268 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1269 | host_impl_->ScrollBegin(BeginState(scroll_position).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1270 | InputHandler::WHEEL) |
| 1271 | .thread); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1272 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->CurrentScrollOffset()); |
| 1273 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 10), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1274 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1275 | host_impl_->ScrollBy(UpdateState(scroll_position, scroll_delta).get()); |
| 1276 | host_impl_->ScrollEnd(EndState().get()); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 1277 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), scroll_layer->CurrentScrollOffset()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1278 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1279 | |
| 1280 | overflow->set_user_scrollable_vertical(false); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1281 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | 2668bea6 | 2016-03-17 00:49:47 | [diff] [blame] | 1282 | DrawFrame(); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1283 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1284 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1285 | host_impl_->ScrollBegin(BeginState(scroll_position).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1286 | InputHandler::WHEEL) |
| 1287 | .thread); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 1288 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), scroll_layer->CurrentScrollOffset()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1289 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1290 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1291 | host_impl_->ScrollBy(UpdateState(scroll_position, scroll_delta).get()); |
| 1292 | host_impl_->ScrollEnd(EndState().get()); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 1293 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 10), scroll_layer->CurrentScrollOffset()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1294 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1295 | } |
| 1296 | |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1297 | TEST_F(LayerTreeHostImplTest, AnimationSchedulingPendingTree) { |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1298 | EXPECT_FALSE(host_impl_->CommitToActiveTree()); |
| 1299 | |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1300 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1301 | |
| 1302 | host_impl_->CreatePendingTree(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1303 | auto root_owned = LayerImpl::Create(host_impl_->pending_tree(), 1); |
| 1304 | auto* root = root_owned.get(); |
| 1305 | host_impl_->pending_tree()->SetRootLayerForTesting(std::move(root_owned)); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1306 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1307 | root->test_properties()->force_render_surface = true; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1308 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 1309 | root->test_properties()->AddChild( |
| 1310 | LayerImpl::Create(host_impl_->pending_tree(), 2)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 1311 | LayerImpl* child = root->test_properties()->children[0]; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1312 | child->SetBounds(gfx::Size(10, 10)); |
| 1313 | child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); |
| 1314 | child->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1315 | |
| 1316 | host_impl_->pending_tree()->SetElementIdsForTesting(); |
| 1317 | |
| 1318 | AddAnimatedTransformToElementWithPlayer(child->element_id(), timeline(), 10.0, |
| 1319 | 3, 0); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1320 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1321 | EXPECT_FALSE(did_request_next_frame_); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1322 | EXPECT_FALSE(did_request_redraw_); |
| 1323 | EXPECT_FALSE(did_request_commit_); |
| 1324 | |
danakj | 492344054 | 2015-10-29 19:34:53 | [diff] [blame] | 1325 | host_impl_->AnimatePendingTreeAfterCommit(); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1326 | |
danakj | 492344054 | 2015-10-29 19:34:53 | [diff] [blame] | 1327 | // An animation exists on the pending layer. Doing |
| 1328 | // AnimatePendingTreeAfterCommit() requests another frame. |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1329 | // In reality, animations without has_set_start_time() == true do not need to |
| 1330 | // be continuously ticked on the pending tree, so it should not request |
| 1331 | // another animation frame here. But we currently do so blindly if any |
| 1332 | // animation exists. |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1333 | EXPECT_TRUE(did_request_next_frame_); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1334 | // The pending tree with an animation does not need to draw after animating. |
| 1335 | EXPECT_FALSE(did_request_redraw_); |
| 1336 | EXPECT_FALSE(did_request_commit_); |
| 1337 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1338 | did_request_next_frame_ = false; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1339 | did_request_redraw_ = false; |
| 1340 | did_request_commit_ = false; |
| 1341 | |
| 1342 | host_impl_->ActivateSyncTree(); |
| 1343 | |
| 1344 | // When the animation activates, we should request another animation frame |
| 1345 | // to keep the animation moving. |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1346 | EXPECT_TRUE(did_request_next_frame_); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1347 | // On activation we don't need to request a redraw for the animation, |
| 1348 | // activating will draw on its own when it's ready. |
| 1349 | EXPECT_FALSE(did_request_redraw_); |
| 1350 | EXPECT_FALSE(did_request_commit_); |
| 1351 | } |
| 1352 | |
| 1353 | TEST_F(LayerTreeHostImplTest, AnimationSchedulingActiveTree) { |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1354 | EXPECT_FALSE(host_impl_->CommitToActiveTree()); |
| 1355 | |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1356 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1357 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1358 | host_impl_->active_tree()->SetRootLayerForTesting( |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1359 | LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1360 | LayerImpl* root = *host_impl_->active_tree()->begin(); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1361 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1362 | root->test_properties()->force_render_surface = true; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1363 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 1364 | root->test_properties()->AddChild( |
| 1365 | LayerImpl::Create(host_impl_->active_tree(), 2)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 1366 | LayerImpl* child = root->test_properties()->children[0]; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1367 | child->SetBounds(gfx::Size(10, 10)); |
| 1368 | child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); |
| 1369 | child->SetDrawsContent(true); |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 1370 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1371 | host_impl_->active_tree()->SetElementIdsForTesting(); |
| 1372 | |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1373 | // Add a translate from 6,7 to 8,9. |
| 1374 | TransformOperations start; |
| 1375 | start.AppendTranslate(6.f, 7.f, 0.f); |
| 1376 | TransformOperations end; |
| 1377 | end.AppendTranslate(8.f, 9.f, 0.f); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1378 | AddAnimatedTransformToElementWithPlayer(child->element_id(), timeline(), 4.0, |
| 1379 | start, end); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1380 | |
| 1381 | base::TimeTicks now = base::TimeTicks::Now(); |
| 1382 | host_impl_->WillBeginImplFrame( |
| 1383 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now)); |
| 1384 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1385 | // TODO(crbug.com/551134): We always request a new frame and a draw for |
| 1386 | // animations that are on the pending tree, but we don't need to do that |
| 1387 | // unless they are waiting for some future time to start. |
| 1388 | EXPECT_TRUE(did_request_next_frame_); |
| 1389 | EXPECT_TRUE(did_request_redraw_); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1390 | EXPECT_FALSE(did_request_commit_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1391 | did_request_next_frame_ = false; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1392 | did_request_redraw_ = false; |
| 1393 | did_request_commit_ = false; |
| 1394 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1395 | host_impl_->ActivateAnimations(); |
| 1396 | |
| 1397 | // On activating an animation, we should request another frame so that we'll |
| 1398 | // continue ticking the animation. |
| 1399 | EXPECT_TRUE(did_request_next_frame_); |
| 1400 | EXPECT_FALSE(did_request_redraw_); |
| 1401 | EXPECT_FALSE(did_request_commit_); |
| 1402 | did_request_next_frame_ = false; |
| 1403 | did_request_redraw_ = false; |
| 1404 | did_request_commit_ = false; |
| 1405 | |
| 1406 | // The next frame after activating, we'll tick the animation again. |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1407 | host_impl_->Animate(); |
| 1408 | |
| 1409 | // An animation exists on the active layer. Doing Animate() requests another |
| 1410 | // frame after the current one. |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1411 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 492344054 | 2015-10-29 19:34:53 | [diff] [blame] | 1412 | // The animation should cause us to draw at the frame's deadline. |
| 1413 | EXPECT_TRUE(did_request_redraw_); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1414 | EXPECT_FALSE(did_request_commit_); |
| 1415 | } |
| 1416 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1417 | TEST_F(LayerTreeHostImplTest, AnimationSchedulingCommitToActiveTree) { |
| 1418 | FakeImplTaskRunnerProvider provider(nullptr); |
| 1419 | CreateHostImplWithTaskRunnerProvider(DefaultSettings(), CreateOutputSurface(), |
| 1420 | &provider); |
| 1421 | EXPECT_TRUE(host_impl_->CommitToActiveTree()); |
| 1422 | |
| 1423 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1424 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1425 | auto root_owned = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 1426 | auto* root = root_owned.get(); |
| 1427 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_owned)); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1428 | root->SetBounds(gfx::Size(50, 50)); |
| 1429 | root->SetHasRenderSurface(true); |
| 1430 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1431 | auto child_owned = LayerImpl::Create(host_impl_->active_tree(), 2); |
| 1432 | auto* child = child_owned.get(); |
| 1433 | root->test_properties()->AddChild(std::move(child_owned)); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1434 | child->SetBounds(gfx::Size(10, 10)); |
| 1435 | child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); |
| 1436 | child->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1437 | |
| 1438 | host_impl_->active_tree()->SetElementIdsForTesting(); |
| 1439 | |
| 1440 | AddAnimatedTransformToElementWithPlayer(child->element_id(), timeline(), 10.0, |
| 1441 | 3, 0); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1442 | |
| 1443 | // Set up the property trees so that UpdateDrawProperties will work in |
| 1444 | // CommitComplete below. |
| 1445 | LayerImplList list; |
| 1446 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1447 | root, gfx::Size(50, 50), &list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1448 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1449 | |
| 1450 | EXPECT_FALSE(did_request_next_frame_); |
| 1451 | EXPECT_FALSE(did_request_redraw_); |
| 1452 | EXPECT_FALSE(did_request_commit_); |
| 1453 | |
| 1454 | host_impl_->CommitComplete(); |
| 1455 | |
| 1456 | // Animations on the active tree should be started and ticked, and a new frame |
| 1457 | // should be requested to continue ticking them. |
| 1458 | EXPECT_TRUE(did_request_next_frame_); |
| 1459 | EXPECT_TRUE(did_request_redraw_); |
| 1460 | EXPECT_FALSE(did_request_commit_); |
| 1461 | |
| 1462 | // Delete the LayerTreeHostImpl before the TaskRunnerProvider goes away. |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 1463 | host_impl_->ReleaseOutputSurface(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1464 | host_impl_ = nullptr; |
| 1465 | } |
| 1466 | |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1467 | TEST_F(LayerTreeHostImplTest, AnimationSchedulingOnLayerDestruction) { |
| 1468 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1469 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1470 | host_impl_->active_tree()->SetRootLayerForTesting( |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1471 | LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1472 | LayerImpl* root = *host_impl_->active_tree()->begin(); |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1473 | root->SetBounds(gfx::Size(50, 50)); |
| 1474 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 1475 | root->test_properties()->AddChild( |
| 1476 | LayerImpl::Create(host_impl_->active_tree(), 2)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 1477 | LayerImpl* child = root->test_properties()->children[0]; |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1478 | child->SetBounds(gfx::Size(10, 10)); |
| 1479 | child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); |
| 1480 | child->SetDrawsContent(true); |
| 1481 | |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 1482 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1483 | host_impl_->active_tree()->SetElementIdsForTesting(); |
| 1484 | |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1485 | // Add a translate animation. |
| 1486 | TransformOperations start; |
| 1487 | start.AppendTranslate(6.f, 7.f, 0.f); |
| 1488 | TransformOperations end; |
| 1489 | end.AppendTranslate(8.f, 9.f, 0.f); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1490 | AddAnimatedTransformToElementWithPlayer(child->element_id(), timeline(), 4.0, |
| 1491 | start, end); |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1492 | |
| 1493 | base::TimeTicks now = base::TimeTicks::Now(); |
| 1494 | host_impl_->WillBeginImplFrame( |
| 1495 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now)); |
| 1496 | EXPECT_TRUE(did_request_next_frame_); |
| 1497 | did_request_next_frame_ = false; |
| 1498 | |
| 1499 | host_impl_->ActivateAnimations(); |
| 1500 | // On activating an animation, we should request another frame so that we'll |
| 1501 | // continue ticking the animation. |
| 1502 | EXPECT_TRUE(did_request_next_frame_); |
| 1503 | did_request_next_frame_ = false; |
| 1504 | |
| 1505 | // The next frame after activating, we'll tick the animation again. |
| 1506 | host_impl_->Animate(); |
| 1507 | // An animation exists on the active layer. Doing Animate() requests another |
| 1508 | // frame after the current one. |
| 1509 | EXPECT_TRUE(did_request_next_frame_); |
| 1510 | did_request_next_frame_ = false; |
| 1511 | |
| 1512 | // Destroy layer, unregister animation target (element). |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 1513 | child->test_properties()->parent = nullptr; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 1514 | root->test_properties()->RemoveChild(child); |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1515 | child = nullptr; |
| 1516 | |
| 1517 | // Doing Animate() doesn't request another frame after the current one. |
| 1518 | host_impl_->Animate(); |
| 1519 | EXPECT_FALSE(did_request_next_frame_); |
| 1520 | |
| 1521 | host_impl_->Animate(); |
| 1522 | EXPECT_FALSE(did_request_next_frame_); |
| 1523 | } |
| 1524 | |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1525 | class MissingTilesLayer : public LayerImpl { |
| 1526 | public: |
| 1527 | MissingTilesLayer(LayerTreeImpl* layer_tree_impl, int id) |
| 1528 | : LayerImpl(layer_tree_impl, id), has_missing_tiles_(true) {} |
| 1529 | |
| 1530 | void set_has_missing_tiles(bool has_missing_tiles) { |
| 1531 | has_missing_tiles_ = has_missing_tiles; |
| 1532 | } |
| 1533 | |
| 1534 | void AppendQuads(RenderPass* render_pass, |
| 1535 | AppendQuadsData* append_quads_data) override { |
| 1536 | append_quads_data->num_missing_tiles += has_missing_tiles_; |
| 1537 | } |
| 1538 | |
| 1539 | private: |
| 1540 | bool has_missing_tiles_; |
| 1541 | }; |
| 1542 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1543 | TEST_F(LayerTreeHostImplTest, AnimationMarksLayerNotReady) { |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1544 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1545 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1546 | host_impl_->active_tree()->SetRootLayerForTesting( |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1547 | LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1548 | LayerImpl* root = *host_impl_->active_tree()->begin(); |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1549 | root->SetBounds(gfx::Size(50, 50)); |
| 1550 | root->SetHasRenderSurface(true); |
| 1551 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 1552 | root->test_properties()->AddChild(std::unique_ptr<MissingTilesLayer>( |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1553 | new MissingTilesLayer(host_impl_->active_tree(), 2))); |
| 1554 | MissingTilesLayer* child = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 1555 | static_cast<MissingTilesLayer*>(root->test_properties()->children[0]); |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1556 | child->SetBounds(gfx::Size(10, 10)); |
| 1557 | child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); |
| 1558 | child->SetDrawsContent(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1559 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1560 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1561 | host_impl_->active_tree()->SetElementIdsForTesting(); |
| 1562 | |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1563 | EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation()); |
| 1564 | |
| 1565 | // Add a translate from 6,7 to 8,9. |
| 1566 | TransformOperations start; |
| 1567 | start.AppendTranslate(6.f, 7.f, 0.f); |
| 1568 | TransformOperations end; |
| 1569 | end.AppendTranslate(8.f, 9.f, 0.f); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1570 | int animation_id = AddAnimatedTransformToElementWithPlayer( |
| 1571 | child->element_id(), timeline(), 4.0, start, end); |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1572 | |
| 1573 | base::TimeTicks now = base::TimeTicks::Now(); |
| 1574 | host_impl_->WillBeginImplFrame( |
| 1575 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now)); |
| 1576 | |
| 1577 | host_impl_->ActivateAnimations(); |
| 1578 | host_impl_->Animate(); |
| 1579 | |
| 1580 | EXPECT_FALSE(child->was_ever_ready_since_last_transform_animation()); |
| 1581 | |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1582 | host_impl_->ResetRequiresHighResToDraw(); |
| 1583 | |
| 1584 | // Child layer has an animating transform but missing tiles. |
| 1585 | FakeLayerTreeHostImpl::FrameData frame; |
| 1586 | DrawResult result = host_impl_->PrepareToDraw(&frame); |
| 1587 | EXPECT_EQ(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS, result); |
| 1588 | host_impl_->DidDrawAllLayers(frame); |
| 1589 | |
| 1590 | child->set_has_missing_tiles(false); |
| 1591 | |
| 1592 | // Child layer has an animating and no missing tiles. |
| 1593 | result = host_impl_->PrepareToDraw(&frame); |
| 1594 | EXPECT_EQ(DRAW_SUCCESS, result); |
| 1595 | EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation()); |
| 1596 | host_impl_->DidDrawAllLayers(frame); |
| 1597 | |
| 1598 | // Remove the animation. |
| 1599 | child->set_has_missing_tiles(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1600 | RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(), |
| 1601 | animation_id); |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1602 | child->draw_properties().screen_space_transform_is_animating = false; |
| 1603 | |
| 1604 | // Child layer doesn't have an animation, but was never ready since the last |
| 1605 | // time it animated (and has missing tiles). |
| 1606 | result = host_impl_->PrepareToDraw(&frame); |
| 1607 | EXPECT_EQ(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS, result); |
| 1608 | EXPECT_FALSE(child->was_ever_ready_since_last_transform_animation()); |
| 1609 | host_impl_->DidDrawAllLayers(frame); |
| 1610 | |
| 1611 | child->set_has_missing_tiles(false); |
| 1612 | |
| 1613 | // Child layer doesn't have an animation and all tiles are ready. |
| 1614 | result = host_impl_->PrepareToDraw(&frame); |
| 1615 | EXPECT_EQ(DRAW_SUCCESS, result); |
| 1616 | EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation()); |
| 1617 | host_impl_->DidDrawAllLayers(frame); |
| 1618 | |
| 1619 | child->set_has_missing_tiles(true); |
| 1620 | |
| 1621 | // Child layer doesn't have an animation, and was ready at least once since |
| 1622 | // the last time it animated. |
| 1623 | result = host_impl_->PrepareToDraw(&frame); |
| 1624 | EXPECT_EQ(DRAW_SUCCESS, result); |
| 1625 | EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation()); |
| 1626 | host_impl_->DidDrawAllLayers(frame); |
| 1627 | } |
| 1628 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1629 | TEST_F(LayerTreeHostImplTest, ImplPinchZoom) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 1630 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1631 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 1632 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 1633 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1634 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1635 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1636 | EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 1637 | LayerImpl* container_layer = scroll_layer->scroll_clip_layer(); |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1638 | EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1639 | |
| 1640 | float min_page_scale = 1.f, max_page_scale = 4.f; |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 1641 | float page_scale_factor = 1.f; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1642 | |
| 1643 | // The impl-based pinch zoom should adjust the max scroll position. |
| 1644 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 1645 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 1646 | page_scale_factor, min_page_scale, max_page_scale); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 1647 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1648 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1649 | |
| 1650 | float page_scale_delta = 2.f; |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 1651 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1652 | host_impl_->ScrollBegin(BeginState(gfx::Point(50, 50)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1653 | InputHandler::TOUCHSCREEN); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1654 | host_impl_->PinchGestureBegin(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1655 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); |
| 1656 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1657 | host_impl_->ScrollEnd(EndState().get()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1658 | EXPECT_FALSE(did_request_next_frame_); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1659 | EXPECT_TRUE(did_request_redraw_); |
| 1660 | EXPECT_TRUE(did_request_commit_); |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1661 | EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1662 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1663 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1664 | host_impl_->ProcessScrollDeltas(); |
| 1665 | EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
| 1666 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1667 | EXPECT_EQ(gfx::ScrollOffset(75.0, 75.0).ToString(), |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1668 | scroll_layer->MaxScrollOffset().ToString()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | // Scrolling after a pinch gesture should always be in local space. The |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 1672 | // scroll deltas have the page scale factor applied. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1673 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 1674 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 1675 | page_scale_factor, min_page_scale, max_page_scale); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 1676 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1677 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1678 | |
| 1679 | float page_scale_delta = 2.f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1680 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1681 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1682 | host_impl_->PinchGestureBegin(); |
| 1683 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); |
| 1684 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1685 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1686 | |
| 1687 | gfx::Vector2d scroll_delta(0, 10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1688 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1689 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1690 | InputHandler::WHEEL) |
| 1691 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1692 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 1693 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 1694 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1695 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1696 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 1697 | EXPECT_TRUE(ScrollInfoContains( |
| 1698 | *scroll_info.get(), scroll_layer->id(), |
| 1699 | gfx::Vector2d(0, scroll_delta.y() / page_scale_delta))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1700 | } |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 1701 | } |
| 1702 | |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1703 | TEST_F(LayerTreeHostImplTest, ViewportScrollOrder) { |
| 1704 | LayerTreeSettings settings = DefaultSettings(); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1705 | CreateHostImpl(settings, |
| 1706 | CreateOutputSurface()); |
| 1707 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 4.f); |
| 1708 | |
| 1709 | const gfx::Size content_size(1000, 1000); |
| 1710 | const gfx::Size viewport_size(500, 500); |
| 1711 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 1712 | |
| 1713 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1714 | outer_scroll_layer->SetDrawsContent(true); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1715 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1716 | inner_scroll_layer->SetDrawsContent(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1717 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1718 | |
| 1719 | EXPECT_VECTOR_EQ( |
| 1720 | gfx::Vector2dF(500, 500), |
| 1721 | outer_scroll_layer->MaxScrollOffset()); |
| 1722 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1723 | host_impl_->ScrollBegin(BeginState(gfx::Point(250, 250)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1724 | InputHandler::TOUCHSCREEN); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1725 | host_impl_->PinchGestureBegin(); |
| 1726 | host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); |
| 1727 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1728 | host_impl_->ScrollEnd(EndState().get()); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1729 | |
| 1730 | // Sanity check - we're zoomed in, starting from the origin. |
| 1731 | EXPECT_VECTOR_EQ( |
| 1732 | gfx::Vector2dF(0, 0), |
| 1733 | outer_scroll_layer->CurrentScrollOffset()); |
| 1734 | EXPECT_VECTOR_EQ( |
| 1735 | gfx::Vector2dF(0, 0), |
| 1736 | inner_scroll_layer->CurrentScrollOffset()); |
| 1737 | |
| 1738 | // Scroll down - only the inner viewport should scroll. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1739 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1740 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1741 | host_impl_->ScrollBy( |
| 1742 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 1743 | host_impl_->ScrollEnd(EndState().get()); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1744 | |
| 1745 | EXPECT_VECTOR_EQ( |
| 1746 | gfx::Vector2dF(50, 50), |
| 1747 | inner_scroll_layer->CurrentScrollOffset()); |
| 1748 | EXPECT_VECTOR_EQ( |
| 1749 | gfx::Vector2dF(0, 0), |
| 1750 | outer_scroll_layer->CurrentScrollOffset()); |
| 1751 | |
| 1752 | // Scroll down - outer viewport should start scrolling after the inner is at |
| 1753 | // its maximum. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1754 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1755 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1756 | host_impl_->ScrollBy( |
| 1757 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(1000.f, 1000.f)).get()); |
| 1758 | host_impl_->ScrollEnd(EndState().get()); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1759 | |
| 1760 | EXPECT_VECTOR_EQ( |
| 1761 | gfx::Vector2dF(250, 250), |
| 1762 | inner_scroll_layer->CurrentScrollOffset()); |
| 1763 | EXPECT_VECTOR_EQ( |
| 1764 | gfx::Vector2dF(300, 300), |
| 1765 | outer_scroll_layer->CurrentScrollOffset()); |
| 1766 | } |
| 1767 | |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1768 | // Make sure scrolls smaller than a unit applied to the viewport don't get |
| 1769 | // dropped. crbug.com/539334. |
| 1770 | TEST_F(LayerTreeHostImplTest, ScrollViewportWithFractionalAmounts) { |
| 1771 | LayerTreeSettings settings = DefaultSettings(); |
| 1772 | CreateHostImpl(settings, CreateOutputSurface()); |
| 1773 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
| 1774 | |
| 1775 | const gfx::Size content_size(1000, 1000); |
| 1776 | const gfx::Size viewport_size(500, 500); |
| 1777 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 1778 | |
| 1779 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1780 | outer_scroll_layer->SetDrawsContent(true); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1781 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1782 | inner_scroll_layer->SetDrawsContent(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1783 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1784 | |
| 1785 | // Sanity checks. |
| 1786 | EXPECT_VECTOR_EQ( |
| 1787 | gfx::Vector2dF(500, 500), |
| 1788 | outer_scroll_layer->MaxScrollOffset()); |
| 1789 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll_layer->CurrentScrollOffset()); |
| 1790 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), inner_scroll_layer->CurrentScrollOffset()); |
| 1791 | |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1792 | // Scroll only the layout viewport. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1793 | host_impl_->ScrollBegin(BeginState(gfx::Point(250, 250)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1794 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1795 | host_impl_->ScrollBy( |
| 1796 | UpdateState(gfx::Point(250, 250), gfx::Vector2dF(0.125f, 0.125f)).get()); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1797 | EXPECT_VECTOR2DF_EQ( |
| 1798 | gfx::Vector2dF(0.125f, 0.125f), |
| 1799 | outer_scroll_layer->CurrentScrollOffset()); |
| 1800 | EXPECT_VECTOR2DF_EQ( |
| 1801 | gfx::Vector2dF(0, 0), |
| 1802 | inner_scroll_layer->CurrentScrollOffset()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1803 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1804 | |
| 1805 | host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 1.f, 2.f); |
| 1806 | |
| 1807 | // Now that we zoomed in, the scroll should be applied to the inner viewport. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1808 | host_impl_->ScrollBegin(BeginState(gfx::Point(250, 250)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1809 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1810 | host_impl_->ScrollBy( |
| 1811 | UpdateState(gfx::Point(250, 250), gfx::Vector2dF(0.5f, 0.5f)).get()); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1812 | EXPECT_VECTOR2DF_EQ( |
| 1813 | gfx::Vector2dF(0.125f, 0.125f), |
| 1814 | outer_scroll_layer->CurrentScrollOffset()); |
| 1815 | EXPECT_VECTOR2DF_EQ( |
| 1816 | gfx::Vector2dF(0.25f, 0.25f), |
| 1817 | inner_scroll_layer->CurrentScrollOffset()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1818 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1819 | } |
| 1820 | |
bokan | 32f1b90 | 2015-08-12 22:25:32 | [diff] [blame] | 1821 | // Tests that scrolls during a pinch gesture (i.e. "two-finger" scrolls) work |
| 1822 | // as expected. That is, scrolling during a pinch should bubble from the inner |
| 1823 | // to the outer viewport. |
| 1824 | TEST_F(LayerTreeHostImplTest, ScrollDuringPinchGesture) { |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1825 | LayerTreeSettings settings = DefaultSettings(); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1826 | CreateHostImpl(settings, |
| 1827 | CreateOutputSurface()); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 1828 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1829 | |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1830 | const gfx::Size content_size(1000, 1000); |
| 1831 | const gfx::Size viewport_size(500, 500); |
| 1832 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1833 | |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1834 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1835 | outer_scroll_layer->SetDrawsContent(true); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1836 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1837 | inner_scroll_layer->SetDrawsContent(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1838 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1839 | |
| 1840 | EXPECT_VECTOR_EQ( |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1841 | gfx::Vector2dF(500, 500), |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1842 | outer_scroll_layer->MaxScrollOffset()); |
| 1843 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1844 | host_impl_->ScrollBegin(BeginState(gfx::Point(250, 250)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1845 | InputHandler::TOUCHSCREEN); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1846 | host_impl_->PinchGestureBegin(); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1847 | |
bokan | 32f1b90 | 2015-08-12 22:25:32 | [diff] [blame] | 1848 | host_impl_->PinchGestureUpdate(2, gfx::Point(250, 250)); |
| 1849 | EXPECT_VECTOR_EQ( |
| 1850 | gfx::Vector2dF(0, 0), |
| 1851 | outer_scroll_layer->CurrentScrollOffset()); |
| 1852 | EXPECT_VECTOR_EQ( |
| 1853 | gfx::Vector2dF(125, 125), |
| 1854 | inner_scroll_layer->CurrentScrollOffset()); |
| 1855 | |
| 1856 | // Needed so that the pinch is accounted for in draw properties. |
| 1857 | DrawFrame(); |
| 1858 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1859 | host_impl_->ScrollBy( |
| 1860 | UpdateState(gfx::Point(250, 250), gfx::Vector2dF(10.f, 10.f)).get()); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1861 | EXPECT_VECTOR_EQ( |
| 1862 | gfx::Vector2dF(0, 0), |
| 1863 | outer_scroll_layer->CurrentScrollOffset()); |
| 1864 | EXPECT_VECTOR_EQ( |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1865 | gfx::Vector2dF(130, 130), |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1866 | inner_scroll_layer->CurrentScrollOffset()); |
bokan | 32f1b90 | 2015-08-12 22:25:32 | [diff] [blame] | 1867 | |
| 1868 | DrawFrame(); |
| 1869 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1870 | host_impl_->ScrollBy( |
| 1871 | UpdateState(gfx::Point(250, 250), gfx::Vector2dF(400.f, 400.f)).get()); |
bokan | 32f1b90 | 2015-08-12 22:25:32 | [diff] [blame] | 1872 | EXPECT_VECTOR_EQ( |
| 1873 | gfx::Vector2dF(80, 80), |
| 1874 | outer_scroll_layer->CurrentScrollOffset()); |
| 1875 | EXPECT_VECTOR_EQ( |
| 1876 | gfx::Vector2dF(250, 250), |
| 1877 | inner_scroll_layer->CurrentScrollOffset()); |
| 1878 | |
| 1879 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1880 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1881 | } |
| 1882 | |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1883 | // Tests the "snapping" of pinch-zoom gestures to the screen edge. That is, when |
| 1884 | // a pinch zoom is anchored within a certain margin of the screen edge, we |
| 1885 | // should assume the user means to scroll into the edge of the screen. |
| 1886 | TEST_F(LayerTreeHostImplTest, PinchZoomSnapsToScreenEdge) { |
| 1887 | LayerTreeSettings settings = DefaultSettings(); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1888 | CreateHostImpl(settings, |
| 1889 | CreateOutputSurface()); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 1890 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1891 | |
| 1892 | const gfx::Size content_size(1000, 1000); |
| 1893 | const gfx::Size viewport_size(500, 500); |
| 1894 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 1895 | |
| 1896 | int offsetFromEdge = Viewport::kPinchZoomSnapMarginDips - 5; |
| 1897 | gfx::Point anchor(viewport_size.width() - offsetFromEdge, |
| 1898 | viewport_size.height() - offsetFromEdge); |
| 1899 | |
| 1900 | // Pinch in within the margins. The scroll should stay exactly locked to the |
| 1901 | // bottom and right. |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1902 | host_impl_->ScrollBegin(BeginState(anchor).get(), InputHandler::TOUCHSCREEN); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1903 | host_impl_->PinchGestureBegin(); |
| 1904 | host_impl_->PinchGestureUpdate(2, anchor); |
| 1905 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1906 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1907 | |
| 1908 | EXPECT_VECTOR_EQ( |
| 1909 | gfx::Vector2dF(250, 250), |
| 1910 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 1911 | |
| 1912 | // Reset. |
| 1913 | host_impl_->active_tree()->SetPageScaleOnActiveTree(1.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1914 | SetScrollOffsetDelta(host_impl_->InnerViewportScrollLayer(), gfx::Vector2d()); |
| 1915 | SetScrollOffsetDelta(host_impl_->OuterViewportScrollLayer(), gfx::Vector2d()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1916 | |
| 1917 | // Pinch in within the margins. The scroll should stay exactly locked to the |
| 1918 | // top and left. |
| 1919 | anchor = gfx::Point(offsetFromEdge, offsetFromEdge); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1920 | host_impl_->ScrollBegin(BeginState(anchor).get(), InputHandler::TOUCHSCREEN); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1921 | host_impl_->PinchGestureBegin(); |
| 1922 | host_impl_->PinchGestureUpdate(2, anchor); |
| 1923 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1924 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1925 | |
| 1926 | EXPECT_VECTOR_EQ( |
| 1927 | gfx::Vector2dF(0, 0), |
| 1928 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 1929 | |
| 1930 | // Reset. |
| 1931 | host_impl_->active_tree()->SetPageScaleOnActiveTree(1.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1932 | SetScrollOffsetDelta(host_impl_->InnerViewportScrollLayer(), gfx::Vector2d()); |
| 1933 | SetScrollOffsetDelta(host_impl_->OuterViewportScrollLayer(), gfx::Vector2d()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1934 | |
| 1935 | // Pinch in just outside the margin. There should be no snapping. |
| 1936 | offsetFromEdge = Viewport::kPinchZoomSnapMarginDips; |
| 1937 | anchor = gfx::Point(offsetFromEdge, offsetFromEdge); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1938 | host_impl_->ScrollBegin(BeginState(anchor).get(), InputHandler::TOUCHSCREEN); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1939 | host_impl_->PinchGestureBegin(); |
| 1940 | host_impl_->PinchGestureUpdate(2, anchor); |
| 1941 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1942 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1943 | |
| 1944 | EXPECT_VECTOR_EQ( |
| 1945 | gfx::Vector2dF(50, 50), |
| 1946 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 1947 | |
| 1948 | // Reset. |
| 1949 | host_impl_->active_tree()->SetPageScaleOnActiveTree(1.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1950 | SetScrollOffsetDelta(host_impl_->InnerViewportScrollLayer(), gfx::Vector2d()); |
| 1951 | SetScrollOffsetDelta(host_impl_->OuterViewportScrollLayer(), gfx::Vector2d()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1952 | |
| 1953 | // Pinch in just outside the margin. There should be no snapping. |
| 1954 | offsetFromEdge = Viewport::kPinchZoomSnapMarginDips; |
| 1955 | anchor = gfx::Point(viewport_size.width() - offsetFromEdge, |
| 1956 | viewport_size.height() - offsetFromEdge); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1957 | host_impl_->ScrollBegin(BeginState(anchor).get(), InputHandler::TOUCHSCREEN); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1958 | host_impl_->PinchGestureBegin(); |
| 1959 | host_impl_->PinchGestureUpdate(2, anchor); |
| 1960 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1961 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1962 | |
| 1963 | EXPECT_VECTOR_EQ( |
| 1964 | gfx::Vector2dF(200, 200), |
| 1965 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 1966 | } |
| 1967 | |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1968 | TEST_F(LayerTreeHostImplTest, ImplPinchZoomWheelBubbleBetweenViewports) { |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1969 | const gfx::Size content_size(200, 200); |
| 1970 | const gfx::Size viewport_size(100, 100); |
| 1971 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1972 | |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1973 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1974 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1975 | |
| 1976 | // Zoom into the page by a 2X factor |
| 1977 | float min_page_scale = 1.f, max_page_scale = 4.f; |
| 1978 | float page_scale_factor = 2.f; |
| 1979 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
| 1980 | page_scale_factor, min_page_scale, max_page_scale); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 1981 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1982 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 1983 | // Scroll by a small amount, there should be no bubbling to the outer |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1984 | // viewport. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1985 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 1986 | InputHandler::WHEEL); |
| 1987 | host_impl_->ScrollBy( |
| 1988 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(10.f, 20.f)).get()); |
| 1989 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1990 | |
| 1991 | EXPECT_VECTOR_EQ( |
| 1992 | gfx::Vector2dF(5, 10), |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 1993 | inner_scroll_layer->CurrentScrollOffset()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1994 | EXPECT_VECTOR_EQ( |
| 1995 | gfx::Vector2dF(), |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 1996 | outer_scroll_layer->CurrentScrollOffset()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1997 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 1998 | // Scroll by the inner viewport's max scroll extent, the remainder |
| 1999 | // should bubble up to the outer viewport. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2000 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 2001 | InputHandler::WHEEL); |
| 2002 | host_impl_->ScrollBy( |
| 2003 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 2004 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 2005 | |
| 2006 | EXPECT_VECTOR_EQ( |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 2007 | gfx::Vector2dF(50, 50), |
| 2008 | inner_scroll_layer->CurrentScrollOffset()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 2009 | EXPECT_VECTOR_EQ( |
| 2010 | gfx::Vector2dF(5, 10), |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 2011 | outer_scroll_layer->CurrentScrollOffset()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 2012 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 2013 | // Scroll by the outer viewport's max scroll extent, it should all go to the |
| 2014 | // outer viewport. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2015 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 2016 | InputHandler::WHEEL); |
| 2017 | host_impl_->ScrollBy( |
| 2018 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(190.f, 180.f)).get()); |
| 2019 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 2020 | |
| 2021 | EXPECT_VECTOR_EQ( |
| 2022 | gfx::Vector2dF(100, 100), |
| 2023 | outer_scroll_layer->CurrentScrollOffset()); |
| 2024 | EXPECT_VECTOR_EQ( |
| 2025 | gfx::Vector2dF(50, 50), |
| 2026 | inner_scroll_layer->CurrentScrollOffset()); |
| 2027 | } |
| 2028 | |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 2029 | TEST_F(LayerTreeHostImplTest, ScrollWithSwapPromises) { |
| 2030 | ui::LatencyInfo latency_info; |
miletus | 45effdc4 | 2015-08-05 00:29:18 | [diff] [blame] | 2031 | latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, |
| 2032 | 1234); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2033 | std::unique_ptr<SwapPromise> swap_promise( |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 2034 | new LatencyInfoSwapPromise(latency_info)); |
| 2035 | |
| 2036 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 2037 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2038 | host_impl_ |
| 2039 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 2040 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 2041 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2042 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 2043 | host_impl_->QueueSwapPromiseForMainThreadScrollUpdate( |
| 2044 | std::move(swap_promise)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2045 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 2046 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2047 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 2048 | host_impl_->ProcessScrollDeltas(); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 2049 | EXPECT_EQ(1u, scroll_info->swap_promises.size()); |
miletus | 45effdc4 | 2015-08-05 00:29:18 | [diff] [blame] | 2050 | EXPECT_EQ(latency_info.trace_id(), scroll_info->swap_promises[0]->TraceId()); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 2051 | } |
| 2052 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 2053 | // Test that scrolls targeting a layer with a non-null scroll_parent() don't |
| 2054 | // bubble up. |
| 2055 | TEST_F(LayerTreeHostImplTest, ScrollDoesntBubble) { |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2056 | LayerImpl* viewport_scroll = |
| 2057 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 2058 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 2059 | |
| 2060 | // Set up two scrolling children of the root, one of which is a scroll parent |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 2061 | // to the other. Scrolls shouldn't bubbling from the child. |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2062 | LayerImpl *parent; |
| 2063 | LayerImpl *child; |
| 2064 | LayerImpl *child_clip; |
| 2065 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2066 | std::unique_ptr<LayerImpl> scroll_parent_clip = |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2067 | LayerImpl::Create(host_impl_->active_tree(), 6); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2068 | std::unique_ptr<LayerImpl> scroll_parent = |
| 2069 | CreateScrollableLayer(7, gfx::Size(10, 10), scroll_parent_clip.get()); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2070 | parent = scroll_parent.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2071 | scroll_parent_clip->test_properties()->AddChild(std::move(scroll_parent)); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2072 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2073 | viewport_scroll->test_properties()->AddChild(std::move(scroll_parent_clip)); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2074 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2075 | std::unique_ptr<LayerImpl> scroll_child_clip = |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2076 | LayerImpl::Create(host_impl_->active_tree(), 8); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2077 | std::unique_ptr<LayerImpl> scroll_child = |
| 2078 | CreateScrollableLayer(9, gfx::Size(10, 10), scroll_child_clip.get()); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2079 | child = scroll_child.get(); |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 2080 | scroll_child->SetPosition(gfx::PointF(20.f, 20.f)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2081 | scroll_child_clip->test_properties()->AddChild(std::move(scroll_child)); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2082 | |
| 2083 | child_clip = scroll_child_clip.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2084 | viewport_scroll->test_properties()->AddChild(std::move(scroll_child_clip)); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2085 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 2086 | child_clip->test_properties()->scroll_parent = parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2087 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 2088 | new std::set<LayerImpl*>); |
jaydasika | b5a1a8c | 2015-09-29 18:38:49 | [diff] [blame] | 2089 | scroll_children->insert(child_clip); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 2090 | parent->test_properties()->scroll_children.reset(scroll_children.release()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2091 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2092 | |
| 2093 | DrawFrame(); |
| 2094 | |
| 2095 | { |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2096 | host_impl_->ScrollBegin(BeginState(gfx::Point(21, 21)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2097 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2098 | host_impl_->ScrollBy( |
| 2099 | UpdateState(gfx::Point(21, 21), gfx::Vector2d(5, 5)).get()); |
| 2100 | host_impl_->ScrollBy( |
| 2101 | UpdateState(gfx::Point(21, 21), gfx::Vector2d(100, 100)).get()); |
| 2102 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2103 | |
| 2104 | // The child should be fully scrolled by the first ScrollBy. |
| 2105 | EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 5), child->CurrentScrollOffset()); |
| 2106 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 2107 | // The scroll_parent shouldn't receive the second ScrollBy. |
| 2108 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), parent->CurrentScrollOffset()); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2109 | |
| 2110 | // The viewport shouldn't have been scrolled at all. |
| 2111 | EXPECT_VECTOR_EQ( |
| 2112 | gfx::Vector2dF(0, 0), |
| 2113 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 2114 | EXPECT_VECTOR_EQ( |
| 2115 | gfx::Vector2dF(0, 0), |
| 2116 | host_impl_->OuterViewportScrollLayer()->CurrentScrollOffset()); |
| 2117 | } |
| 2118 | |
| 2119 | { |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2120 | host_impl_->ScrollBegin(BeginState(gfx::Point(21, 21)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2121 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2122 | host_impl_->ScrollBy( |
| 2123 | UpdateState(gfx::Point(21, 21), gfx::Vector2d(3, 4)).get()); |
| 2124 | host_impl_->ScrollBy( |
| 2125 | UpdateState(gfx::Point(21, 21), gfx::Vector2d(2, 1)).get()); |
| 2126 | host_impl_->ScrollBy( |
| 2127 | UpdateState(gfx::Point(21, 21), gfx::Vector2d(2, 1)).get()); |
| 2128 | host_impl_->ScrollBy( |
| 2129 | UpdateState(gfx::Point(21, 21), gfx::Vector2d(2, 1)).get()); |
| 2130 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2131 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 2132 | // The ScrollBy's should scroll the parent to its extent. |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2133 | EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 5), parent->CurrentScrollOffset()); |
| 2134 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 2135 | // The viewport shouldn't receive any scroll delta. |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2136 | EXPECT_VECTOR_EQ( |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 2137 | gfx::Vector2dF(0, 0), |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2138 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 2139 | EXPECT_VECTOR_EQ( |
| 2140 | gfx::Vector2dF(0, 0), |
| 2141 | host_impl_->OuterViewportScrollLayer()->CurrentScrollOffset()); |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2146 | TEST_F(LayerTreeHostImplTest, PinchGesture) { |
| 2147 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 2148 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 2149 | DrawFrame(); |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2150 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 2151 | LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2152 | DCHECK(scroll_layer); |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2153 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2154 | float min_page_scale = 1.f; |
| 2155 | float max_page_scale = 4.f; |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2156 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2157 | // Basic pinch zoom in gesture |
| 2158 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2159 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2160 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2161 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2162 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2163 | float page_scale_delta = 2.f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2164 | host_impl_->ScrollBegin(BeginState(gfx::Point(50, 50)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2165 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2166 | host_impl_->PinchGestureBegin(); |
| 2167 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); |
| 2168 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2169 | host_impl_->ScrollEnd(EndState().get()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2170 | EXPECT_FALSE(did_request_next_frame_); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2171 | EXPECT_TRUE(did_request_redraw_); |
| 2172 | EXPECT_TRUE(did_request_commit_); |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2173 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2174 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2175 | host_impl_->ProcessScrollDeltas(); |
| 2176 | EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
| 2177 | } |
| 2178 | |
| 2179 | // Zoom-in clamping |
| 2180 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2181 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2182 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2183 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2184 | float page_scale_delta = 10.f; |
| 2185 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2186 | host_impl_->ScrollBegin(BeginState(gfx::Point(50, 50)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2187 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2188 | host_impl_->PinchGestureBegin(); |
| 2189 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); |
| 2190 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2191 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2192 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2193 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2194 | host_impl_->ProcessScrollDeltas(); |
| 2195 | EXPECT_EQ(scroll_info->page_scale_delta, max_page_scale); |
| 2196 | } |
| 2197 | |
| 2198 | // Zoom-out clamping |
| 2199 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2200 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2201 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2202 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 2203 | scroll_layer->layer_tree_impl() |
| 2204 | ->property_trees() |
| 2205 | ->scroll_tree.CollectScrollDeltasForTesting(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2206 | scroll_layer->layer_tree_impl() |
| 2207 | ->property_trees() |
| 2208 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2209 | scroll_layer->id(), gfx::ScrollOffset(50, 50)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2210 | |
| 2211 | float page_scale_delta = 0.1f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2212 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2213 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2214 | host_impl_->PinchGestureBegin(); |
| 2215 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); |
| 2216 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2217 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2218 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2219 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2220 | host_impl_->ProcessScrollDeltas(); |
| 2221 | EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); |
| 2222 | |
| 2223 | EXPECT_TRUE(scroll_info->scrolls.empty()); |
| 2224 | } |
| 2225 | |
| 2226 | // Two-finger panning should not happen based on pinch events only |
| 2227 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2228 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2229 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2230 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 2231 | scroll_layer->layer_tree_impl() |
| 2232 | ->property_trees() |
| 2233 | ->scroll_tree.CollectScrollDeltasForTesting(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2234 | scroll_layer->layer_tree_impl() |
| 2235 | ->property_trees() |
| 2236 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2237 | scroll_layer->id(), gfx::ScrollOffset(20, 20)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2238 | |
| 2239 | float page_scale_delta = 1.f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2240 | host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2241 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2242 | host_impl_->PinchGestureBegin(); |
| 2243 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); |
| 2244 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); |
| 2245 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2246 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2247 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2248 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2249 | host_impl_->ProcessScrollDeltas(); |
| 2250 | EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
| 2251 | EXPECT_TRUE(scroll_info->scrolls.empty()); |
| 2252 | } |
| 2253 | |
| 2254 | // Two-finger panning should work with interleaved scroll events |
| 2255 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2256 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2257 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2258 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 2259 | scroll_layer->layer_tree_impl() |
| 2260 | ->property_trees() |
| 2261 | ->scroll_tree.CollectScrollDeltasForTesting(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2262 | scroll_layer->layer_tree_impl() |
| 2263 | ->property_trees() |
| 2264 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2265 | scroll_layer->id(), gfx::ScrollOffset(20, 20)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2266 | |
| 2267 | float page_scale_delta = 1.f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2268 | host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2269 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2270 | host_impl_->PinchGestureBegin(); |
| 2271 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2272 | host_impl_->ScrollBy( |
| 2273 | UpdateState(gfx::Point(10, 10), gfx::Vector2d(-10, -10)).get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2274 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); |
| 2275 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2276 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2277 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2278 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2279 | host_impl_->ProcessScrollDeltas(); |
| 2280 | EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 2281 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
| 2282 | gfx::Vector2d(-10, -10))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2283 | } |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2284 | |
| 2285 | // Two-finger panning should work when starting fully zoomed out. |
| 2286 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2287 | host_impl_->active_tree()->PushPageScaleFromMainThread(0.5f, 0.5f, 4.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2288 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 2289 | scroll_layer->layer_tree_impl() |
| 2290 | ->property_trees() |
| 2291 | ->scroll_tree.CollectScrollDeltasForTesting(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2292 | scroll_layer->layer_tree_impl() |
| 2293 | ->property_trees() |
| 2294 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 2295 | gfx::ScrollOffset(0, 0)); |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2296 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2297 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2298 | InputHandler::TOUCHSCREEN); |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2299 | host_impl_->PinchGestureBegin(); |
| 2300 | host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); |
| 2301 | host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 2302 | |
| 2303 | // Needed so layer transform includes page scale. |
| 2304 | DrawFrame(); |
| 2305 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2306 | host_impl_->ScrollBy( |
| 2307 | UpdateState(gfx::Point(0, 0), gfx::Vector2d(10, 10)).get()); |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2308 | host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10)); |
| 2309 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2310 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2311 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2312 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2313 | host_impl_->ProcessScrollDeltas(); |
| 2314 | EXPECT_EQ(scroll_info->page_scale_delta, 2.f); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 2315 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 2316 | gfx::Vector2d(10, 10))); |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2317 | } |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2318 | } |
| 2319 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2320 | TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { |
| 2321 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 2322 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 2323 | DrawFrame(); |
[email protected] | df8f44f | 2013-01-08 08:00:31 | [diff] [blame] | 2324 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 2325 | LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2326 | DCHECK(scroll_layer); |
[email protected] | df8f44f | 2013-01-08 08:00:31 | [diff] [blame] | 2327 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2328 | float min_page_scale = 0.5f; |
| 2329 | float max_page_scale = 4.f; |
| 2330 | base::TimeTicks start_time = base::TimeTicks() + |
| 2331 | base::TimeDelta::FromSeconds(1); |
| 2332 | base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 2333 | base::TimeTicks halfway_through_animation = start_time + duration / 2; |
| 2334 | base::TimeTicks end_time = start_time + duration; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2335 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2336 | BeginFrameArgs begin_frame_args = |
| 2337 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 2338 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2339 | // Non-anchor zoom-in |
| 2340 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2341 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2342 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2343 | scroll_layer->layer_tree_impl() |
| 2344 | ->property_trees() |
| 2345 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2346 | scroll_layer->id(), gfx::ScrollOffset(50, 50)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2347 | |
[email protected] | c232196 | 2014-04-28 19:16:42 | [diff] [blame] | 2348 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2349 | did_request_next_frame_ = false; |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2350 | host_impl_->active_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2351 | std::unique_ptr<PendingPageScaleAnimation>( |
| 2352 | new PendingPageScaleAnimation(gfx::Vector2d(), false, 2.f, |
| 2353 | duration))); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2354 | host_impl_->ActivateSyncTree(); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 2355 | EXPECT_FALSE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2356 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 2357 | |
| 2358 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2359 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2360 | begin_frame_args.frame_time = start_time; |
| 2361 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2362 | host_impl_->Animate(); |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2363 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2364 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2365 | host_impl_->DidFinishImplFrame(); |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2366 | |
| 2367 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2368 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2369 | begin_frame_args.frame_time = halfway_through_animation; |
| 2370 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2371 | host_impl_->Animate(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2372 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2373 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2374 | host_impl_->DidFinishImplFrame(); |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2375 | |
| 2376 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2377 | did_request_next_frame_ = false; |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2378 | did_request_commit_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2379 | begin_frame_args.frame_time = end_time; |
| 2380 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2381 | host_impl_->Animate(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2382 | EXPECT_TRUE(did_request_commit_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2383 | EXPECT_FALSE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2384 | host_impl_->DidFinishImplFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2385 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2386 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2387 | host_impl_->ProcessScrollDeltas(); |
| 2388 | EXPECT_EQ(scroll_info->page_scale_delta, 2); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 2389 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
| 2390 | gfx::Vector2d(-50, -50))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2391 | } |
| 2392 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2393 | start_time += base::TimeDelta::FromSeconds(10); |
| 2394 | halfway_through_animation += base::TimeDelta::FromSeconds(10); |
| 2395 | end_time += base::TimeDelta::FromSeconds(10); |
| 2396 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2397 | // Anchor zoom-out |
| 2398 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2399 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2400 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2401 | scroll_layer->layer_tree_impl() |
| 2402 | ->property_trees() |
| 2403 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2404 | scroll_layer->id(), gfx::ScrollOffset(50, 50)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2405 | |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 2406 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2407 | did_request_next_frame_ = false; |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2408 | host_impl_->active_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2409 | std::unique_ptr<PendingPageScaleAnimation>( |
| 2410 | new PendingPageScaleAnimation(gfx::Vector2d(25, 25), true, |
| 2411 | min_page_scale, duration))); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2412 | host_impl_->ActivateSyncTree(); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 2413 | EXPECT_FALSE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2414 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 2415 | |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2416 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2417 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2418 | begin_frame_args.frame_time = start_time; |
| 2419 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2420 | host_impl_->Animate(); |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2421 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2422 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2423 | host_impl_->DidFinishImplFrame(); |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2424 | |
| 2425 | did_request_redraw_ = false; |
| 2426 | did_request_commit_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2427 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2428 | begin_frame_args.frame_time = end_time; |
| 2429 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2430 | host_impl_->Animate(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2431 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2432 | EXPECT_FALSE(did_request_next_frame_); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2433 | EXPECT_TRUE(did_request_commit_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2434 | host_impl_->DidFinishImplFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2435 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2436 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2437 | host_impl_->ProcessScrollDeltas(); |
| 2438 | EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); |
| 2439 | // Pushed to (0,0) via clamping against contents layer size. |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 2440 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
| 2441 | gfx::Vector2d(-50, -50))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2442 | } |
[email protected] | df8f44f | 2013-01-08 08:00:31 | [diff] [blame] | 2443 | } |
| 2444 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2445 | TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) { |
| 2446 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 2447 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 2448 | DrawFrame(); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 2449 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 2450 | LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2451 | DCHECK(scroll_layer); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 2452 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2453 | float min_page_scale = 0.5f; |
| 2454 | float max_page_scale = 4.f; |
| 2455 | base::TimeTicks start_time = base::TimeTicks() + |
| 2456 | base::TimeDelta::FromSeconds(1); |
| 2457 | base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 2458 | base::TimeTicks halfway_through_animation = start_time + duration / 2; |
| 2459 | base::TimeTicks end_time = start_time + duration; |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 2460 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2461 | BeginFrameArgs begin_frame_args = |
| 2462 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 2463 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2464 | // Anchor zoom with unchanged page scale should not change scroll or scale. |
| 2465 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2466 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2467 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2468 | scroll_layer->layer_tree_impl() |
| 2469 | ->property_trees() |
| 2470 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2471 | scroll_layer->id(), gfx::ScrollOffset(50, 50)); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 2472 | |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2473 | host_impl_->active_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2474 | std::unique_ptr<PendingPageScaleAnimation>( |
| 2475 | new PendingPageScaleAnimation(gfx::Vector2d(), true, 1.f, |
| 2476 | duration))); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2477 | host_impl_->ActivateSyncTree(); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2478 | begin_frame_args.frame_time = start_time; |
| 2479 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2480 | host_impl_->Animate(); |
| 2481 | host_impl_->DidFinishImplFrame(); |
| 2482 | |
| 2483 | begin_frame_args.frame_time = halfway_through_animation; |
| 2484 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2485 | host_impl_->Animate(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2486 | EXPECT_TRUE(did_request_redraw_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2487 | host_impl_->DidFinishImplFrame(); |
| 2488 | |
| 2489 | begin_frame_args.frame_time = end_time; |
| 2490 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2491 | host_impl_->Animate(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2492 | EXPECT_TRUE(did_request_commit_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2493 | host_impl_->DidFinishImplFrame(); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 2494 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2495 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2496 | host_impl_->ProcessScrollDeltas(); |
| 2497 | EXPECT_EQ(scroll_info->page_scale_delta, 1); |
| 2498 | ExpectNone(*scroll_info, scroll_layer->id()); |
| 2499 | } |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 2500 | } |
| 2501 | |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2502 | TEST_F(LayerTreeHostImplTest, PageScaleAnimationTransferedOnSyncTreeActivate) { |
| 2503 | host_impl_->CreatePendingTree(); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 2504 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2505 | CreateScrollAndContentsLayers( |
| 2506 | host_impl_->pending_tree(), |
| 2507 | gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2508 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2509 | host_impl_->ActivateSyncTree(); |
| 2510 | DrawFrame(); |
| 2511 | |
| 2512 | LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 2513 | DCHECK(scroll_layer); |
| 2514 | |
| 2515 | float min_page_scale = 0.5f; |
| 2516 | float max_page_scale = 4.f; |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2517 | host_impl_->sync_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2518 | max_page_scale); |
| 2519 | host_impl_->ActivateSyncTree(); |
| 2520 | |
| 2521 | base::TimeTicks start_time = base::TimeTicks() + |
| 2522 | base::TimeDelta::FromSeconds(1); |
| 2523 | base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
aelias | 74c3935 | 2014-10-14 03:48:14 | [diff] [blame] | 2524 | base::TimeTicks third_through_animation = start_time + duration / 3; |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2525 | base::TimeTicks halfway_through_animation = start_time + duration / 2; |
| 2526 | base::TimeTicks end_time = start_time + duration; |
| 2527 | float target_scale = 2.f; |
| 2528 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2529 | BeginFrameArgs begin_frame_args = |
| 2530 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 2531 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2532 | scroll_layer->layer_tree_impl() |
| 2533 | ->property_trees() |
| 2534 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 2535 | gfx::ScrollOffset(50, 50)); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2536 | |
| 2537 | // Make sure TakePageScaleAnimation works properly. |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2538 | |
| 2539 | host_impl_->sync_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2540 | std::unique_ptr<PendingPageScaleAnimation>(new PendingPageScaleAnimation( |
| 2541 | gfx::Vector2d(), false, target_scale, duration))); |
| 2542 | std::unique_ptr<PendingPageScaleAnimation> psa = |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2543 | host_impl_->sync_tree()->TakePendingPageScaleAnimation(); |
| 2544 | EXPECT_EQ(target_scale, psa->scale); |
| 2545 | EXPECT_EQ(duration, psa->duration); |
| 2546 | EXPECT_EQ(nullptr, host_impl_->sync_tree()->TakePendingPageScaleAnimation()); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2547 | |
| 2548 | // Recreate the PSA. Nothing should happen here since the tree containing the |
| 2549 | // PSA hasn't been activated yet. |
| 2550 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2551 | did_request_next_frame_ = false; |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2552 | host_impl_->sync_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2553 | std::unique_ptr<PendingPageScaleAnimation>(new PendingPageScaleAnimation( |
| 2554 | gfx::Vector2d(), false, target_scale, duration))); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2555 | begin_frame_args.frame_time = halfway_through_animation; |
| 2556 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2557 | host_impl_->Animate(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2558 | EXPECT_FALSE(did_request_next_frame_); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2559 | EXPECT_FALSE(did_request_redraw_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2560 | host_impl_->DidFinishImplFrame(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2561 | |
| 2562 | // Activate the sync tree. This should cause the animation to become enabled. |
| 2563 | // It should also clear the pointer on the sync tree. |
| 2564 | host_impl_->ActivateSyncTree(); |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2565 | EXPECT_EQ(nullptr, |
| 2566 | host_impl_->sync_tree()->TakePendingPageScaleAnimation().get()); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2567 | EXPECT_FALSE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2568 | EXPECT_TRUE(did_request_next_frame_); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2569 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2570 | start_time += base::TimeDelta::FromSeconds(10); |
| 2571 | third_through_animation += base::TimeDelta::FromSeconds(10); |
| 2572 | halfway_through_animation += base::TimeDelta::FromSeconds(10); |
| 2573 | end_time += base::TimeDelta::FromSeconds(10); |
| 2574 | |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2575 | // From here on, make sure the animation runs as normal. |
| 2576 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2577 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2578 | begin_frame_args.frame_time = start_time; |
| 2579 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2580 | host_impl_->Animate(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2581 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2582 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2583 | host_impl_->DidFinishImplFrame(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2584 | |
| 2585 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2586 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2587 | begin_frame_args.frame_time = third_through_animation; |
| 2588 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2589 | host_impl_->Animate(); |
aelias | 74c3935 | 2014-10-14 03:48:14 | [diff] [blame] | 2590 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2591 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2592 | host_impl_->DidFinishImplFrame(); |
aelias | 74c3935 | 2014-10-14 03:48:14 | [diff] [blame] | 2593 | |
| 2594 | // Another activation shouldn't have any effect on the animation. |
| 2595 | host_impl_->ActivateSyncTree(); |
| 2596 | |
| 2597 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2598 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2599 | begin_frame_args.frame_time = halfway_through_animation; |
| 2600 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2601 | host_impl_->Animate(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2602 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2603 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2604 | host_impl_->DidFinishImplFrame(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2605 | |
| 2606 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2607 | did_request_next_frame_ = false; |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2608 | did_request_commit_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2609 | begin_frame_args.frame_time = end_time; |
| 2610 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2611 | host_impl_->Animate(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2612 | EXPECT_TRUE(did_request_commit_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2613 | EXPECT_FALSE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2614 | host_impl_->DidFinishImplFrame(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2615 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2616 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2617 | host_impl_->ProcessScrollDeltas(); |
| 2618 | EXPECT_EQ(scroll_info->page_scale_delta, target_scale); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 2619 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
| 2620 | gfx::Vector2d(-50, -50))); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2621 | } |
| 2622 | |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2623 | TEST_F(LayerTreeHostImplTest, PageScaleAnimationCompletedNotification) { |
| 2624 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 2625 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 2626 | DrawFrame(); |
| 2627 | |
| 2628 | LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 2629 | DCHECK(scroll_layer); |
| 2630 | |
| 2631 | base::TimeTicks start_time = |
| 2632 | base::TimeTicks() + base::TimeDelta::FromSeconds(1); |
| 2633 | base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 2634 | base::TimeTicks halfway_through_animation = start_time + duration / 2; |
| 2635 | base::TimeTicks end_time = start_time + duration; |
| 2636 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2637 | BeginFrameArgs begin_frame_args = |
| 2638 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 2639 | |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2640 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2641 | scroll_layer->layer_tree_impl() |
| 2642 | ->property_trees() |
| 2643 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 2644 | gfx::ScrollOffset(50, 50)); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2645 | |
| 2646 | did_complete_page_scale_animation_ = false; |
| 2647 | host_impl_->active_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2648 | std::unique_ptr<PendingPageScaleAnimation>(new PendingPageScaleAnimation( |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2649 | gfx::Vector2d(), false, 2.f, duration))); |
| 2650 | host_impl_->ActivateSyncTree(); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2651 | begin_frame_args.frame_time = start_time; |
| 2652 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2653 | host_impl_->Animate(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2654 | EXPECT_FALSE(did_complete_page_scale_animation_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2655 | host_impl_->DidFinishImplFrame(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2656 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2657 | begin_frame_args.frame_time = halfway_through_animation; |
| 2658 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2659 | host_impl_->Animate(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2660 | EXPECT_FALSE(did_complete_page_scale_animation_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2661 | host_impl_->DidFinishImplFrame(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2662 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2663 | begin_frame_args.frame_time = end_time; |
| 2664 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2665 | host_impl_->Animate(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2666 | EXPECT_TRUE(did_complete_page_scale_animation_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2667 | host_impl_->DidFinishImplFrame(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2668 | } |
| 2669 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 2670 | TEST_F(LayerTreeHostImplTest, MaxScrollOffsetAffectedByBoundsDelta) { |
| 2671 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 2672 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 2673 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2674 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 2675 | DrawFrame(); |
| 2676 | |
| 2677 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 2678 | LayerImpl* inner_container = inner_scroll->scroll_clip_layer(); |
| 2679 | DCHECK(inner_scroll); |
| 2680 | DCHECK(inner_container); |
| 2681 | EXPECT_EQ(gfx::ScrollOffset(50, 50), inner_scroll->MaxScrollOffset()); |
| 2682 | |
| 2683 | inner_container->SetBoundsDelta(gfx::Vector2dF(15.f, 15.f)); |
| 2684 | inner_scroll->SetBoundsDelta(gfx::Vector2dF(7.f, 7.f)); |
| 2685 | EXPECT_EQ(gfx::ScrollOffset(42, 42), inner_scroll->MaxScrollOffset()); |
| 2686 | |
| 2687 | inner_container->SetBoundsDelta(gfx::Vector2dF()); |
| 2688 | inner_scroll->SetBoundsDelta(gfx::Vector2dF()); |
| 2689 | inner_scroll->SetBounds(gfx::Size()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2690 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 2691 | DrawFrame(); |
| 2692 | |
| 2693 | inner_scroll->SetBoundsDelta(gfx::Vector2dF(60.f, 60.f)); |
| 2694 | EXPECT_EQ(gfx::ScrollOffset(10, 10), inner_scroll->MaxScrollOffset()); |
| 2695 | } |
| 2696 | |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2697 | class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { |
| 2698 | public: |
| 2699 | LayerTreeHostImplOverridePhysicalTime( |
| 2700 | const LayerTreeSettings& settings, |
| 2701 | LayerTreeHostImplClient* client, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 2702 | TaskRunnerProvider* task_runner_provider, |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 2703 | SharedBitmapManager* manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 2704 | TaskGraphRunner* task_graph_runner, |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2705 | RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 2706 | : LayerTreeHostImpl(settings, |
| 2707 | client, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 2708 | task_runner_provider, |
[email protected] | a7f3568 | 2013-10-22 23:05:57 | [diff] [blame] | 2709 | rendering_stats_instrumentation, |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 2710 | manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 2711 | nullptr, |
| 2712 | task_graph_runner, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 2713 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), |
[email protected] | dbe759a | 2013-12-02 19:23:02 | [diff] [blame] | 2714 | 0) {} |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2715 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 2716 | BeginFrameArgs CurrentBeginFrameArgs() const override { |
mithro | 06d1f3bf | 2014-12-02 02:19:15 | [diff] [blame] | 2717 | return CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, |
| 2718 | fake_current_physical_time_); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { |
| 2722 | fake_current_physical_time_ = fake_now; |
| 2723 | } |
| 2724 | |
| 2725 | private: |
| 2726 | base::TimeTicks fake_current_physical_time_; |
| 2727 | }; |
| 2728 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2729 | class LayerTreeHostImplTestScrollbarAnimation : public LayerTreeHostImplTest { |
| 2730 | protected: |
| 2731 | void SetupLayers(LayerTreeSettings settings) { |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 2732 | host_impl_->ReleaseOutputSurface(); |
| 2733 | host_impl_ = nullptr; |
| 2734 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2735 | gfx::Size content_size(100, 100); |
[email protected] | e6e7f29 | 2014-04-24 22:23:03 | [diff] [blame] | 2736 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2737 | LayerTreeHostImplOverridePhysicalTime* host_impl_override_time = |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 2738 | new LayerTreeHostImplOverridePhysicalTime( |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 2739 | settings, this, &task_runner_provider_, &shared_bitmap_manager_, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 2740 | &task_graph_runner_, &stats_instrumentation_); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2741 | host_impl_ = base::WrapUnique(host_impl_override_time); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2742 | output_surface_ = CreateOutputSurface(); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 2743 | host_impl_->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2744 | host_impl_->InitializeRenderer(output_surface_.get()); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2745 | |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 2746 | SetupScrollAndContentsLayers(content_size); |
| 2747 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f); |
| 2748 | host_impl_->SetViewportSize( |
| 2749 | gfx::Size(content_size.width() / 2, content_size.height() / 2)); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2750 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2751 | std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 2752 | SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 400, |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2753 | VERTICAL, 10, 0, false, true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 2754 | scrollbar->test_properties()->opacity = 0.f; |
| 2755 | EXPECT_FLOAT_EQ(0.f, scrollbar->test_properties()->opacity); |
[email protected] | cdc0700 | 2013-09-06 22:33:46 | [diff] [blame] | 2756 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 2757 | LayerImpl* scroll = host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 2758 | LayerImpl* root = host_impl_->active_tree()->InnerViewportContainerLayer(); |
| 2759 | scrollbar->SetScrollLayerId(scroll->id()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2760 | root->test_properties()->AddChild(std::move(scrollbar)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2761 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2762 | host_impl_->active_tree()->DidBecomeActive(); |
| 2763 | DrawFrame(); |
| 2764 | } |
sunnyps | ae4316a | 2015-02-25 00:54:58 | [diff] [blame] | 2765 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2766 | void RunTest(LayerTreeSettings::ScrollbarAnimator animator) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 2767 | LayerTreeSettings settings = DefaultSettings(); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2768 | settings.scrollbar_animator = animator; |
| 2769 | settings.scrollbar_fade_delay_ms = 20; |
| 2770 | settings.scrollbar_fade_duration_ms = 20; |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2771 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2772 | // If no animator is set, scrollbar won't show and no animation is expected. |
| 2773 | bool expecting_animations = animator != LayerTreeSettings::NO_ANIMATOR; |
| 2774 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2775 | SetupLayers(settings); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2776 | |
abhishek.ka | 7215854d | 2015-05-26 06:13:17 | [diff] [blame] | 2777 | base::TimeTicks fake_now = base::TimeTicks::Now(); |
sataya.m | 68d7d9b4 | 2014-09-22 16:01:59 | [diff] [blame] | 2778 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2779 | if (expecting_animations) { |
| 2780 | // A task will be posted to fade the initial scrollbar. |
| 2781 | EXPECT_FALSE(did_request_next_frame_); |
| 2782 | EXPECT_FALSE(did_request_redraw_); |
| 2783 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 2784 | requested_animation_delay_ = base::TimeDelta(); |
| 2785 | animation_task_ = base::Closure(); |
| 2786 | } else { |
| 2787 | EXPECT_FALSE(did_request_next_frame_); |
| 2788 | EXPECT_FALSE(did_request_redraw_); |
| 2789 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2790 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2791 | } |
sunnyps | ae4316a | 2015-02-25 00:54:58 | [diff] [blame] | 2792 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2793 | // If no scroll happened during a scroll gesture, it should have no effect. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2794 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 2795 | InputHandler::WHEEL); |
| 2796 | host_impl_->ScrollEnd(EndState().get()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2797 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2798 | EXPECT_FALSE(did_request_redraw_); |
| 2799 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2800 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2801 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2802 | // Before the scrollbar animation exists, we should not get redraws. |
| 2803 | BeginFrameArgs begin_frame_args = |
| 2804 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, fake_now); |
| 2805 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2806 | host_impl_->Animate(); |
| 2807 | EXPECT_FALSE(did_request_next_frame_); |
| 2808 | did_request_next_frame_ = false; |
| 2809 | EXPECT_FALSE(did_request_redraw_); |
| 2810 | did_request_redraw_ = false; |
| 2811 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2812 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2813 | host_impl_->DidFinishImplFrame(); |
| 2814 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2815 | // After a scroll, a scrollbar animation should be scheduled about 20ms from |
| 2816 | // now. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2817 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 2818 | InputHandler::WHEEL); |
| 2819 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2dF(0, 5)).get()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2820 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2821 | EXPECT_TRUE(did_request_redraw_); |
| 2822 | did_request_redraw_ = false; |
| 2823 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2824 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2825 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2826 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 2827 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2828 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2829 | EXPECT_FALSE(did_request_redraw_); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2830 | if (expecting_animations) { |
| 2831 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), |
| 2832 | requested_animation_delay_); |
| 2833 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 2834 | } else { |
| 2835 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2836 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2837 | } |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2838 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2839 | if (expecting_animations) { |
| 2840 | // Before the scrollbar animation begins, we should not get redraws. |
| 2841 | begin_frame_args = |
| 2842 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, fake_now); |
| 2843 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2844 | host_impl_->Animate(); |
| 2845 | EXPECT_FALSE(did_request_next_frame_); |
| 2846 | did_request_next_frame_ = false; |
| 2847 | EXPECT_FALSE(did_request_redraw_); |
| 2848 | did_request_redraw_ = false; |
| 2849 | host_impl_->DidFinishImplFrame(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2850 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2851 | // Start the scrollbar animation. |
| 2852 | fake_now += requested_animation_delay_; |
| 2853 | requested_animation_delay_ = base::TimeDelta(); |
| 2854 | animation_task_.Run(); |
| 2855 | animation_task_ = base::Closure(); |
| 2856 | EXPECT_TRUE(did_request_next_frame_); |
| 2857 | did_request_next_frame_ = false; |
| 2858 | EXPECT_FALSE(did_request_redraw_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2859 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2860 | // After the scrollbar animation begins, we should start getting redraws. |
| 2861 | begin_frame_args = |
| 2862 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, fake_now); |
| 2863 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2864 | host_impl_->Animate(); |
| 2865 | EXPECT_TRUE(did_request_next_frame_); |
| 2866 | did_request_next_frame_ = false; |
| 2867 | EXPECT_TRUE(did_request_redraw_); |
| 2868 | did_request_redraw_ = false; |
| 2869 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2870 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2871 | host_impl_->DidFinishImplFrame(); |
| 2872 | } |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2873 | |
| 2874 | // Setting the scroll offset outside a scroll should also cause the |
| 2875 | // scrollbar to appear and to schedule a scrollbar animation. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2876 | if (host_impl_->active_tree() |
| 2877 | ->property_trees() |
| 2878 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2879 | host_impl_->InnerViewportScrollLayer()->id(), |
| 2880 | gfx::ScrollOffset(5, 5))) |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 2881 | host_impl_->active_tree()->DidUpdateScrollOffset( |
| 2882 | host_impl_->InnerViewportScrollLayer()->id(), |
| 2883 | host_impl_->InnerViewportScrollLayer()->transform_tree_index()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2884 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2885 | EXPECT_FALSE(did_request_redraw_); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2886 | if (expecting_animations) { |
| 2887 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), |
| 2888 | requested_animation_delay_); |
| 2889 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 2890 | requested_animation_delay_ = base::TimeDelta(); |
| 2891 | animation_task_ = base::Closure(); |
| 2892 | } else { |
| 2893 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2894 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2895 | } |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2896 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2897 | if (expecting_animations) { |
| 2898 | // Scrolling should have stopped the animation, so we should not be |
| 2899 | // getting redraws. |
| 2900 | begin_frame_args = |
| 2901 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, fake_now); |
| 2902 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2903 | host_impl_->Animate(); |
| 2904 | EXPECT_FALSE(did_request_next_frame_); |
| 2905 | did_request_next_frame_ = false; |
| 2906 | EXPECT_FALSE(did_request_redraw_); |
| 2907 | did_request_redraw_ = false; |
| 2908 | host_impl_->DidFinishImplFrame(); |
| 2909 | } |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2910 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2911 | // Scrollbar animation is not triggered unnecessarily. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2912 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 2913 | InputHandler::WHEEL); |
| 2914 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2dF(5, 0)).get()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2915 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2916 | EXPECT_TRUE(did_request_redraw_); |
| 2917 | did_request_redraw_ = false; |
| 2918 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2919 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2920 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2921 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 2922 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2923 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2924 | EXPECT_FALSE(did_request_redraw_); |
| 2925 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2926 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2927 | |
| 2928 | // Changing page scale triggers scrollbar animation. |
| 2929 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 2930 | host_impl_->active_tree()->SetPageScaleOnActiveTree(1.1f); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2931 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2932 | EXPECT_FALSE(did_request_redraw_); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2933 | if (expecting_animations) { |
| 2934 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), |
| 2935 | requested_animation_delay_); |
| 2936 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 2937 | requested_animation_delay_ = base::TimeDelta(); |
| 2938 | animation_task_ = base::Closure(); |
| 2939 | } else { |
| 2940 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2941 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2942 | } |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2943 | } |
| 2944 | }; |
| 2945 | |
| 2946 | TEST_F(LayerTreeHostImplTestScrollbarAnimation, LinearFade) { |
| 2947 | RunTest(LayerTreeSettings::LINEAR_FADE); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2948 | } |
| 2949 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2950 | TEST_F(LayerTreeHostImplTestScrollbarAnimation, Thinning) { |
| 2951 | RunTest(LayerTreeSettings::THINNING); |
[email protected] | e6e7f29 | 2014-04-24 22:23:03 | [diff] [blame] | 2952 | } |
| 2953 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2954 | TEST_F(LayerTreeHostImplTestScrollbarAnimation, NoAnimator) { |
| 2955 | RunTest(LayerTreeSettings::NO_ANIMATOR); |
| 2956 | } |
| 2957 | |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2958 | class LayerTreeHostImplTestScrollbarOpacity : public LayerTreeHostImplTest { |
| 2959 | protected: |
| 2960 | void RunTest(LayerTreeSettings::ScrollbarAnimator animator) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 2961 | LayerTreeSettings settings = DefaultSettings(); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2962 | settings.scrollbar_animator = animator; |
| 2963 | settings.scrollbar_fade_delay_ms = 20; |
| 2964 | settings.scrollbar_fade_duration_ms = 20; |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2965 | gfx::Size content_size(100, 100); |
| 2966 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2967 | // If no animator is set, scrollbar won't show and no animation is expected. |
| 2968 | bool expecting_animations = animator != LayerTreeSettings::NO_ANIMATOR; |
| 2969 | |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2970 | CreateHostImpl(settings, CreateOutputSurface()); |
| 2971 | host_impl_->CreatePendingTree(); |
| 2972 | CreateScrollAndContentsLayers(host_impl_->pending_tree(), content_size); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2973 | std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2974 | SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400, |
| 2975 | VERTICAL, 10, 0, false, true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 2976 | scrollbar->test_properties()->opacity = 0.f; |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 2977 | LayerImpl* scroll = host_impl_->pending_tree()->OuterViewportScrollLayer(); |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 2978 | LayerImpl* container = |
| 2979 | host_impl_->pending_tree()->InnerViewportContainerLayer(); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 2980 | scrollbar->SetScrollLayerId(scroll->id()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2981 | container->test_properties()->AddChild(std::move(scrollbar)); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2982 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2983 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2984 | host_impl_->ActivateSyncTree(); |
| 2985 | |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 2986 | LayerImpl* active_scrollbar_layer = |
| 2987 | host_impl_->active_tree()->LayerById(400); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2988 | |
| 2989 | EffectNode* active_tree_node = |
| 2990 | host_impl_->active_tree()->property_trees()->effect_tree.Node( |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 2991 | active_scrollbar_layer->effect_tree_index()); |
| 2992 | EXPECT_FLOAT_EQ(active_scrollbar_layer->Opacity(), |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 2993 | active_tree_node->opacity); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2994 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2995 | if (expecting_animations) { |
| 2996 | host_impl_->ScrollbarAnimationControllerForId(scroll->id()) |
| 2997 | ->DidMouseMoveNear(0); |
| 2998 | } else { |
| 2999 | EXPECT_EQ(nullptr, |
| 3000 | host_impl_->ScrollbarAnimationControllerForId(scroll->id())); |
| 3001 | } |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3002 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 3003 | InputHandler::WHEEL); |
| 3004 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2dF(0, 5)).get()); |
| 3005 | host_impl_->ScrollEnd(EndState().get()); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 3006 | host_impl_->CreatePendingTree(); |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 3007 | // To test the case where the effect tree index of scrollbar layer changes, |
| 3008 | // we force the container layer to create a render surface. |
| 3009 | container = host_impl_->pending_tree()->InnerViewportContainerLayer(); |
| 3010 | container->test_properties()->force_render_surface = true; |
| 3011 | container->SetBounds(gfx::Size(10, 10)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3012 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 3013 | |
| 3014 | LayerImpl* pending_scrollbar_layer = |
| 3015 | host_impl_->pending_tree()->LayerById(400); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 3016 | pending_scrollbar_layer->SetNeedsPushProperties(); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 3017 | EffectNode* pending_tree_node = |
| 3018 | host_impl_->pending_tree()->property_trees()->effect_tree.Node( |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 3019 | pending_scrollbar_layer->effect_tree_index()); |
jaydasika | ae9b7a0 | 2016-05-19 16:12:52 | [diff] [blame] | 3020 | host_impl_->pending_tree() |
| 3021 | ->property_trees() |
| 3022 | ->always_use_active_tree_opacity_effect_ids.push_back(400); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 3023 | if (expecting_animations) { |
| 3024 | EXPECT_FLOAT_EQ(1.f, active_tree_node->opacity); |
| 3025 | EXPECT_FLOAT_EQ(1.f, active_scrollbar_layer->Opacity()); |
| 3026 | } else { |
| 3027 | EXPECT_FLOAT_EQ(0.f, active_tree_node->opacity); |
| 3028 | EXPECT_FLOAT_EQ(0.f, active_scrollbar_layer->Opacity()); |
| 3029 | } |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3030 | EXPECT_FLOAT_EQ(0.f, pending_tree_node->opacity); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 3031 | host_impl_->ActivateSyncTree(); |
| 3032 | active_tree_node = |
| 3033 | host_impl_->active_tree()->property_trees()->effect_tree.Node( |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 3034 | active_scrollbar_layer->effect_tree_index()); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 3035 | if (expecting_animations) { |
| 3036 | EXPECT_FLOAT_EQ(1.f, active_tree_node->opacity); |
| 3037 | EXPECT_FLOAT_EQ(1.f, active_scrollbar_layer->Opacity()); |
| 3038 | } else { |
| 3039 | EXPECT_FLOAT_EQ(0.f, active_tree_node->opacity); |
| 3040 | EXPECT_FLOAT_EQ(0.f, active_scrollbar_layer->Opacity()); |
| 3041 | } |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 3042 | } |
| 3043 | }; |
| 3044 | |
| 3045 | TEST_F(LayerTreeHostImplTestScrollbarOpacity, LinearFade) { |
| 3046 | RunTest(LayerTreeSettings::LINEAR_FADE); |
| 3047 | } |
| 3048 | |
| 3049 | TEST_F(LayerTreeHostImplTestScrollbarOpacity, Thinning) { |
| 3050 | RunTest(LayerTreeSettings::THINNING); |
| 3051 | } |
| 3052 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 3053 | TEST_F(LayerTreeHostImplTestScrollbarOpacity, NoAnimator) { |
| 3054 | RunTest(LayerTreeSettings::NO_ANIMATOR); |
| 3055 | } |
| 3056 | |
aelias | 14d87e0c | 2015-11-04 00:12:50 | [diff] [blame] | 3057 | TEST_F(LayerTreeHostImplTest, ScrollbarInnerLargerThanOuter) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 3058 | LayerTreeSettings settings = DefaultSettings(); |
aelias | 14d87e0c | 2015-11-04 00:12:50 | [diff] [blame] | 3059 | CreateHostImpl(settings, CreateOutputSurface()); |
| 3060 | |
| 3061 | gfx::Size inner_viewport_size(315, 200); |
| 3062 | gfx::Size outer_viewport_size(300, 200); |
| 3063 | gfx::Size content_size(1000, 1000); |
| 3064 | |
| 3065 | const int horiz_id = 11; |
| 3066 | const int child_clip_id = 14; |
| 3067 | const int child_scroll_id = 15; |
| 3068 | |
| 3069 | CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size); |
| 3070 | host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( |
| 3071 | inner_viewport_size); |
| 3072 | host_impl_->active_tree()->OuterViewportContainerLayer()->SetBounds( |
| 3073 | outer_viewport_size); |
| 3074 | LayerImpl* root_scroll = |
| 3075 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3076 | std::unique_ptr<SolidColorScrollbarLayerImpl> horiz_scrollbar = |
aelias | 14d87e0c | 2015-11-04 00:12:50 | [diff] [blame] | 3077 | SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), horiz_id, |
| 3078 | HORIZONTAL, 5, 5, true, true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3079 | std::unique_ptr<LayerImpl> child = |
aelias | 14d87e0c | 2015-11-04 00:12:50 | [diff] [blame] | 3080 | LayerImpl::Create(host_impl_->active_tree(), child_scroll_id); |
| 3081 | child->SetBounds(content_size); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3082 | std::unique_ptr<LayerImpl> child_clip = |
aelias | 14d87e0c | 2015-11-04 00:12:50 | [diff] [blame] | 3083 | LayerImpl::Create(host_impl_->active_tree(), child_clip_id); |
| 3084 | child->SetBounds(inner_viewport_size); |
| 3085 | |
| 3086 | horiz_scrollbar->SetScrollLayerId(root_scroll->id()); |
| 3087 | |
| 3088 | EXPECT_EQ(300, horiz_scrollbar->clip_layer_length()); |
| 3089 | } |
| 3090 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3091 | TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 3092 | LayerTreeSettings settings = DefaultSettings(); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3093 | settings.scrollbar_animator = LayerTreeSettings::LINEAR_FADE; |
| 3094 | settings.scrollbar_fade_delay_ms = 20; |
| 3095 | settings.scrollbar_fade_duration_ms = 20; |
| 3096 | CreateHostImpl(settings, CreateOutputSurface()); |
| 3097 | |
| 3098 | gfx::Size viewport_size(300, 200); |
| 3099 | gfx::Size content_size(1000, 1000); |
| 3100 | |
| 3101 | const int vert_1_id = 10; |
| 3102 | const int horiz_1_id = 11; |
| 3103 | const int vert_2_id = 12; |
| 3104 | const int horiz_2_id = 13; |
| 3105 | const int child_clip_id = 14; |
| 3106 | const int child_scroll_id = 15; |
| 3107 | |
| 3108 | CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size); |
| 3109 | host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( |
| 3110 | viewport_size); |
| 3111 | LayerImpl* root_scroll = |
| 3112 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3113 | std::unique_ptr<SolidColorScrollbarLayerImpl> vert_1_scrollbar = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3114 | SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), vert_1_id, |
| 3115 | VERTICAL, 5, 5, true, true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3116 | std::unique_ptr<SolidColorScrollbarLayerImpl> horiz_1_scrollbar = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3117 | SolidColorScrollbarLayerImpl::Create( |
| 3118 | host_impl_->active_tree(), horiz_1_id, HORIZONTAL, 5, 5, true, true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3119 | std::unique_ptr<SolidColorScrollbarLayerImpl> vert_2_scrollbar = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3120 | SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), vert_2_id, |
| 3121 | VERTICAL, 5, 5, true, true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3122 | std::unique_ptr<SolidColorScrollbarLayerImpl> horiz_2_scrollbar = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3123 | SolidColorScrollbarLayerImpl::Create( |
| 3124 | host_impl_->active_tree(), horiz_2_id, HORIZONTAL, 5, 5, true, true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3125 | std::unique_ptr<LayerImpl> child = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3126 | LayerImpl::Create(host_impl_->active_tree(), child_scroll_id); |
| 3127 | child->SetBounds(content_size); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3128 | std::unique_ptr<LayerImpl> child_clip = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3129 | LayerImpl::Create(host_impl_->active_tree(), child_clip_id); |
| 3130 | child->SetBounds(viewport_size); |
| 3131 | LayerImpl* child_ptr = child.get(); |
| 3132 | LayerImpl* child_clip_ptr = child_clip.get(); |
| 3133 | |
| 3134 | // Check scrollbar registration on the viewport layers. |
| 3135 | EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); |
| 3136 | EXPECT_EQ(nullptr, |
| 3137 | host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3138 | vert_1_scrollbar->SetScrollLayerId(root_scroll->id()); |
| 3139 | EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); |
| 3140 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3141 | horiz_1_scrollbar->SetScrollLayerId(root_scroll->id()); |
| 3142 | EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); |
| 3143 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3144 | |
| 3145 | // Changing one of the viewport layers should result in a scrollbar animation |
| 3146 | // update. |
| 3147 | animation_task_ = base::Closure(); |
| 3148 | host_impl_->active_tree()->InnerViewportContainerLayer()->SetBoundsDelta( |
| 3149 | gfx::Vector2dF(10, 10)); |
| 3150 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 3151 | animation_task_ = base::Closure(); |
| 3152 | host_impl_->active_tree()->OuterViewportScrollLayer()->SetCurrentScrollOffset( |
| 3153 | gfx::ScrollOffset(10, 10)); |
| 3154 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 3155 | animation_task_ = base::Closure(); |
| 3156 | host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( |
| 3157 | gfx::ScrollOffset(10, 10)); |
| 3158 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 3159 | animation_task_ = base::Closure(); |
| 3160 | |
| 3161 | // Check scrollbar registration on a sublayer. |
| 3162 | child->SetScrollClipLayer(child_clip->id()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3163 | child_clip->test_properties()->AddChild(std::move(child)); |
| 3164 | root_scroll->test_properties()->AddChild(std::move(child_clip)); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3165 | EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3166 | EXPECT_EQ(nullptr, |
| 3167 | host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); |
| 3168 | vert_2_scrollbar->SetScrollLayerId(child_scroll_id); |
| 3169 | EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3170 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); |
| 3171 | horiz_2_scrollbar->SetScrollLayerId(child_scroll_id); |
| 3172 | EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3173 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); |
| 3174 | |
| 3175 | // Changing one of the child layers should result in a scrollbar animation |
| 3176 | // update. |
| 3177 | animation_task_ = base::Closure(); |
| 3178 | child_clip_ptr->SetBounds(gfx::Size(200, 200)); |
| 3179 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 3180 | animation_task_ = base::Closure(); |
| 3181 | child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(10, 10)); |
| 3182 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 3183 | animation_task_ = base::Closure(); |
| 3184 | |
| 3185 | // Check scrollbar unregistration. |
| 3186 | vert_1_scrollbar.reset(); |
| 3187 | EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); |
| 3188 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3189 | horiz_1_scrollbar.reset(); |
| 3190 | EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); |
| 3191 | EXPECT_EQ(nullptr, |
| 3192 | host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3193 | |
| 3194 | EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3195 | vert_2_scrollbar.reset(); |
| 3196 | EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3197 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); |
| 3198 | horiz_2_scrollbar.reset(); |
| 3199 | EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3200 | EXPECT_EQ(nullptr, |
| 3201 | host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3202 | |
| 3203 | // Changing scroll offset should no longer trigger any animation. |
| 3204 | host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( |
| 3205 | gfx::ScrollOffset(20, 20)); |
| 3206 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 3207 | child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(20, 20)); |
| 3208 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 3209 | } |
| 3210 | |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3211 | void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( |
| 3212 | float device_scale_factor) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 3213 | LayerTreeSettings settings = DefaultSettings(); |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 3214 | settings.scrollbar_fade_delay_ms = 500; |
| 3215 | settings.scrollbar_fade_duration_ms = 300; |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 3216 | settings.scrollbar_animator = LayerTreeSettings::THINNING; |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3217 | |
| 3218 | gfx::Size viewport_size(300, 200); |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 3219 | gfx::Size device_viewport_size = |
| 3220 | gfx::ScaleToFlooredSize(viewport_size, device_scale_factor); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3221 | gfx::Size content_size(1000, 1000); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3222 | gfx::Size scrollbar_size(gfx::Size(15, viewport_size.height())); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3223 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 3224 | CreateHostImpl(settings, CreateOutputSurface()); |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 3225 | host_impl_->active_tree()->SetDeviceScaleFactor(device_scale_factor); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3226 | host_impl_->SetViewportSize(device_viewport_size); |
| 3227 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3228 | CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size); |
| 3229 | host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( |
| 3230 | viewport_size); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 3231 | LayerImpl* root_scroll = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3232 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 3233 | // The scrollbar is on the left side. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3234 | std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3235 | SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 6, |
| 3236 | VERTICAL, 5, 5, true, true); |
| 3237 | scrollbar->SetScrollLayerId(root_scroll->id()); |
| 3238 | scrollbar->SetDrawsContent(true); |
| 3239 | scrollbar->SetBounds(scrollbar_size); |
| 3240 | scrollbar->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3241 | host_impl_->active_tree() |
| 3242 | ->InnerViewportContainerLayer() |
| 3243 | ->test_properties() |
| 3244 | ->AddChild(std::move(scrollbar)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3245 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3246 | host_impl_->active_tree()->DidBecomeActive(); |
| 3247 | |
| 3248 | DrawFrame(); |
| 3249 | host_impl_->active_tree()->UpdateDrawProperties(false); |
| 3250 | |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3251 | ScrollbarAnimationControllerThinning* scrollbar_animation_controller = |
| 3252 | static_cast<ScrollbarAnimationControllerThinning*>( |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3253 | host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3254 | scrollbar_animation_controller->set_mouse_move_distance_for_test(100.f); |
| 3255 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3256 | host_impl_->MouseMoveAt(gfx::Point(200, 1)); |
[email protected] | 534236b | 2013-10-25 21:19:20 | [diff] [blame] | 3257 | EXPECT_FALSE(scrollbar_animation_controller->mouse_is_near_scrollbar()); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3258 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3259 | host_impl_->MouseMoveAt(gfx::Point(100, 50)); |
[email protected] | 534236b | 2013-10-25 21:19:20 | [diff] [blame] | 3260 | EXPECT_TRUE(scrollbar_animation_controller->mouse_is_near_scrollbar()); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3261 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3262 | host_impl_->MouseMoveAt(gfx::Point(116, 100)); |
[email protected] | 534236b | 2013-10-25 21:19:20 | [diff] [blame] | 3263 | EXPECT_FALSE(scrollbar_animation_controller->mouse_is_near_scrollbar()); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3264 | |
| 3265 | scrollbar_animation_controller->set_mouse_move_distance_for_test(102.f); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3266 | host_impl_->MouseMoveAt(gfx::Point(116, 100)); |
[email protected] | 534236b | 2013-10-25 21:19:20 | [diff] [blame] | 3267 | EXPECT_TRUE(scrollbar_animation_controller->mouse_is_near_scrollbar()); |
[email protected] | f620b0e7 | 2013-10-01 21:38:24 | [diff] [blame] | 3268 | |
| 3269 | did_request_redraw_ = false; |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3270 | EXPECT_EQ(Layer::INVALID_ID, |
| 3271 | host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); |
| 3272 | host_impl_->MouseMoveAt(gfx::Point(10, 100)); |
| 3273 | EXPECT_EQ(117, host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); |
| 3274 | host_impl_->MouseMoveAt(gfx::Point(10, 120)); |
| 3275 | EXPECT_EQ(117, host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); |
[email protected] | f620b0e7 | 2013-10-01 21:38:24 | [diff] [blame] | 3276 | host_impl_->MouseMoveAt(gfx::Point(150, 120)); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3277 | EXPECT_EQ(Layer::INVALID_ID, |
| 3278 | host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | TEST_F(LayerTreeHostImplTest, MouseMoveAtWithDeviceScaleOf1) { |
| 3282 | SetupMouseMoveAtWithDeviceScale(1.f); |
| 3283 | } |
| 3284 | |
| 3285 | TEST_F(LayerTreeHostImplTest, MouseMoveAtWithDeviceScaleOf2) { |
| 3286 | SetupMouseMoveAtWithDeviceScale(2.f); |
| 3287 | } |
| 3288 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3289 | TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) { |
| 3290 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 3291 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 3292 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 3293 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3294 | { |
| 3295 | CompositorFrameMetadata metadata = |
| 3296 | host_impl_->MakeCompositorFrameMetadata(); |
| 3297 | EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset); |
| 3298 | EXPECT_EQ(1.f, metadata.page_scale_factor); |
[email protected] | f3f611f | 2014-07-09 04:05:32 | [diff] [blame] | 3299 | EXPECT_EQ(gfx::SizeF(50.f, 50.f), metadata.scrollable_viewport_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3300 | EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); |
| 3301 | EXPECT_EQ(0.5f, metadata.min_page_scale_factor); |
| 3302 | EXPECT_EQ(4.f, metadata.max_page_scale_factor); |
jdduke | 2afdbf72 | 2015-02-12 06:28:20 | [diff] [blame] | 3303 | EXPECT_FALSE(metadata.root_overflow_x_hidden); |
| 3304 | EXPECT_FALSE(metadata.root_overflow_y_hidden); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3305 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3306 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3307 | // Scrolling should update metadata immediately. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 3308 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3309 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 3310 | InputHandler::WHEEL) |
| 3311 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3312 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3313 | { |
| 3314 | CompositorFrameMetadata metadata = |
| 3315 | host_impl_->MakeCompositorFrameMetadata(); |
| 3316 | EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); |
| 3317 | } |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3318 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3319 | { |
| 3320 | CompositorFrameMetadata metadata = |
| 3321 | host_impl_->MakeCompositorFrameMetadata(); |
| 3322 | EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); |
| 3323 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3324 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 3325 | // Root "overflow: hidden" properties should be reflected on the outer |
| 3326 | // viewport scroll layer. |
jdduke | 2afdbf72 | 2015-02-12 06:28:20 | [diff] [blame] | 3327 | { |
| 3328 | host_impl_->active_tree() |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 3329 | ->OuterViewportScrollLayer() |
jdduke | 2afdbf72 | 2015-02-12 06:28:20 | [diff] [blame] | 3330 | ->set_user_scrollable_horizontal(false); |
| 3331 | CompositorFrameMetadata metadata = |
| 3332 | host_impl_->MakeCompositorFrameMetadata(); |
| 3333 | EXPECT_TRUE(metadata.root_overflow_x_hidden); |
| 3334 | EXPECT_FALSE(metadata.root_overflow_y_hidden); |
| 3335 | |
| 3336 | host_impl_->active_tree() |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 3337 | ->OuterViewportScrollLayer() |
jdduke | 2afdbf72 | 2015-02-12 06:28:20 | [diff] [blame] | 3338 | ->set_user_scrollable_vertical(false); |
| 3339 | metadata = host_impl_->MakeCompositorFrameMetadata(); |
| 3340 | EXPECT_TRUE(metadata.root_overflow_x_hidden); |
| 3341 | EXPECT_TRUE(metadata.root_overflow_y_hidden); |
| 3342 | } |
| 3343 | |
hugo.holgersson | e5e7aa9 | 2015-08-17 14:07:19 | [diff] [blame] | 3344 | // Re-enable scrollability and verify that overflows are no longer hidden. |
| 3345 | { |
| 3346 | host_impl_->active_tree() |
| 3347 | ->OuterViewportScrollLayer() |
| 3348 | ->set_user_scrollable_horizontal(true); |
| 3349 | host_impl_->active_tree() |
| 3350 | ->OuterViewportScrollLayer() |
| 3351 | ->set_user_scrollable_vertical(true); |
| 3352 | CompositorFrameMetadata metadata = |
| 3353 | host_impl_->MakeCompositorFrameMetadata(); |
| 3354 | EXPECT_FALSE(metadata.root_overflow_x_hidden); |
| 3355 | EXPECT_FALSE(metadata.root_overflow_y_hidden); |
| 3356 | } |
| 3357 | |
| 3358 | // Root "overflow: hidden" properties should also be reflected on the |
| 3359 | // inner viewport scroll layer. |
| 3360 | { |
| 3361 | host_impl_->active_tree() |
| 3362 | ->InnerViewportScrollLayer() |
| 3363 | ->set_user_scrollable_horizontal(false); |
| 3364 | CompositorFrameMetadata metadata = |
| 3365 | host_impl_->MakeCompositorFrameMetadata(); |
| 3366 | EXPECT_TRUE(metadata.root_overflow_x_hidden); |
| 3367 | EXPECT_FALSE(metadata.root_overflow_y_hidden); |
| 3368 | |
| 3369 | host_impl_->active_tree() |
| 3370 | ->InnerViewportScrollLayer() |
| 3371 | ->set_user_scrollable_vertical(false); |
| 3372 | metadata = host_impl_->MakeCompositorFrameMetadata(); |
| 3373 | EXPECT_TRUE(metadata.root_overflow_x_hidden); |
| 3374 | EXPECT_TRUE(metadata.root_overflow_y_hidden); |
| 3375 | } |
| 3376 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3377 | // Page scale should update metadata correctly (shrinking only the viewport). |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3378 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 3379 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3380 | host_impl_->PinchGestureBegin(); |
| 3381 | host_impl_->PinchGestureUpdate(2.f, gfx::Point()); |
| 3382 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3383 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3384 | { |
| 3385 | CompositorFrameMetadata metadata = |
| 3386 | host_impl_->MakeCompositorFrameMetadata(); |
| 3387 | EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); |
| 3388 | EXPECT_EQ(2.f, metadata.page_scale_factor); |
[email protected] | f3f611f | 2014-07-09 04:05:32 | [diff] [blame] | 3389 | EXPECT_EQ(gfx::SizeF(25.f, 25.f), metadata.scrollable_viewport_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3390 | EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); |
| 3391 | EXPECT_EQ(0.5f, metadata.min_page_scale_factor); |
| 3392 | EXPECT_EQ(4.f, metadata.max_page_scale_factor); |
| 3393 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3394 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3395 | // Likewise if set from the main thread. |
| 3396 | host_impl_->ProcessScrollDeltas(); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 3397 | host_impl_->active_tree()->PushPageScaleFromMainThread(4.f, 0.5f, 4.f); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 3398 | host_impl_->active_tree()->SetPageScaleOnActiveTree(4.f); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3399 | { |
| 3400 | CompositorFrameMetadata metadata = |
| 3401 | host_impl_->MakeCompositorFrameMetadata(); |
| 3402 | EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); |
| 3403 | EXPECT_EQ(4.f, metadata.page_scale_factor); |
[email protected] | f3f611f | 2014-07-09 04:05:32 | [diff] [blame] | 3404 | EXPECT_EQ(gfx::SizeF(12.5f, 12.5f), metadata.scrollable_viewport_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3405 | EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); |
| 3406 | EXPECT_EQ(0.5f, metadata.min_page_scale_factor); |
| 3407 | EXPECT_EQ(4.f, metadata.max_page_scale_factor); |
| 3408 | } |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 3409 | } |
| 3410 | |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3411 | class DidDrawCheckLayer : public LayerImpl { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3412 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3413 | static std::unique_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { |
| 3414 | return base::WrapUnique(new DidDrawCheckLayer(tree_impl, id)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3415 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3416 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3417 | bool WillDraw(DrawMode draw_mode, ResourceProvider* provider) override { |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3418 | will_draw_called_ = true; |
| 3419 | if (will_draw_returns_false_) |
| 3420 | return false; |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3421 | return LayerImpl::WillDraw(draw_mode, provider); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3422 | } |
| 3423 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3424 | void AppendQuads(RenderPass* render_pass, |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3425 | AppendQuadsData* append_quads_data) override { |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3426 | append_quads_called_ = true; |
danakj | a8c66a5 | 2015-02-14 01:53:22 | [diff] [blame] | 3427 | LayerImpl::AppendQuads(render_pass, append_quads_data); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3428 | } |
| 3429 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3430 | void DidDraw(ResourceProvider* provider) override { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3431 | did_draw_called_ = true; |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3432 | LayerImpl::DidDraw(provider); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3433 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3434 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3435 | bool will_draw_called() const { return will_draw_called_; } |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3436 | bool append_quads_called() const { return append_quads_called_; } |
| 3437 | bool did_draw_called() const { return did_draw_called_; } |
| 3438 | |
| 3439 | void set_will_draw_returns_false() { will_draw_returns_false_ = true; } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3440 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3441 | void ClearDidDrawCheck() { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3442 | will_draw_called_ = false; |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3443 | append_quads_called_ = false; |
| 3444 | did_draw_called_ = false; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3445 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3446 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3447 | static void IgnoreResult(std::unique_ptr<CopyOutputResult> result) {} |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3448 | |
| 3449 | void AddCopyRequest() { |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 3450 | test_properties()->copy_requests.push_back( |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3451 | CopyOutputRequest::CreateRequest(base::Bind(&IgnoreResult))); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3452 | } |
| 3453 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3454 | protected: |
| 3455 | DidDrawCheckLayer(LayerTreeImpl* tree_impl, int id) |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3456 | : LayerImpl(tree_impl, id), |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3457 | will_draw_returns_false_(false), |
| 3458 | will_draw_called_(false), |
| 3459 | append_quads_called_(false), |
| 3460 | did_draw_called_(false) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3461 | SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3462 | SetDrawsContent(true); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3463 | draw_properties().visible_layer_rect = gfx::Rect(0, 0, 10, 10); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3464 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3465 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3466 | private: |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3467 | bool will_draw_returns_false_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3468 | bool will_draw_called_; |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3469 | bool append_quads_called_; |
| 3470 | bool did_draw_called_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3471 | }; |
| 3472 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3473 | TEST_F(LayerTreeHostImplTest, WillDrawReturningFalseDoesNotCall) { |
| 3474 | // The root layer is always drawn, so run this test on a child layer that |
| 3475 | // will be masked out by the root layer's bounds. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3476 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3477 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3478 | DidDrawCheckLayer* root = |
| 3479 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3480 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3481 | root->test_properties()->AddChild( |
| 3482 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 2)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3483 | root->test_properties()->force_render_surface = true; |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3484 | DidDrawCheckLayer* layer = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3485 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children[0]); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3486 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3487 | |
| 3488 | { |
| 3489 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3490 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3491 | host_impl_->DrawLayers(&frame); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3492 | host_impl_->DidDrawAllLayers(frame); |
| 3493 | |
| 3494 | EXPECT_TRUE(layer->will_draw_called()); |
| 3495 | EXPECT_TRUE(layer->append_quads_called()); |
| 3496 | EXPECT_TRUE(layer->did_draw_called()); |
| 3497 | } |
| 3498 | |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 3499 | host_impl_->SetViewportDamage(gfx::Rect(10, 10)); |
| 3500 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3501 | { |
| 3502 | LayerTreeHostImpl::FrameData frame; |
| 3503 | |
| 3504 | layer->set_will_draw_returns_false(); |
| 3505 | layer->ClearDidDrawCheck(); |
| 3506 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3507 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3508 | host_impl_->DrawLayers(&frame); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3509 | host_impl_->DidDrawAllLayers(frame); |
| 3510 | |
| 3511 | EXPECT_TRUE(layer->will_draw_called()); |
| 3512 | EXPECT_FALSE(layer->append_quads_called()); |
| 3513 | EXPECT_FALSE(layer->did_draw_called()); |
| 3514 | } |
| 3515 | } |
| 3516 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3517 | TEST_F(LayerTreeHostImplTest, DidDrawNotCalledOnHiddenLayer) { |
| 3518 | // The root layer is always drawn, so run this test on a child layer that |
| 3519 | // will be masked out by the root layer's bounds. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3520 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3521 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3522 | DidDrawCheckLayer* root = |
| 3523 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3524 | root->SetMasksToBounds(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3525 | root->test_properties()->force_render_surface = true; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3526 | root->test_properties()->AddChild( |
| 3527 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 2)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3528 | DidDrawCheckLayer* layer = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3529 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children[0]); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3530 | // Ensure visible_layer_rect for layer is empty. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3531 | layer->SetPosition(gfx::PointF(100.f, 100.f)); |
| 3532 | layer->SetBounds(gfx::Size(10, 10)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3533 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3534 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3535 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3536 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3537 | EXPECT_FALSE(layer->will_draw_called()); |
| 3538 | EXPECT_FALSE(layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3539 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3540 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3541 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3542 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3543 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3544 | EXPECT_FALSE(layer->will_draw_called()); |
| 3545 | EXPECT_FALSE(layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3546 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3547 | EXPECT_TRUE(layer->visible_layer_rect().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3548 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3549 | // Ensure visible_layer_rect for layer is not empty |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3550 | layer->SetPosition(gfx::PointF()); |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 3551 | layer->NoteLayerPropertyChanged(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3552 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3553 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3554 | EXPECT_FALSE(layer->will_draw_called()); |
| 3555 | EXPECT_FALSE(layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3556 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3557 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3558 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3559 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3560 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3561 | EXPECT_TRUE(layer->will_draw_called()); |
| 3562 | EXPECT_TRUE(layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3563 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3564 | EXPECT_FALSE(layer->visible_layer_rect().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3565 | } |
| 3566 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3567 | TEST_F(LayerTreeHostImplTest, WillDrawNotCalledOnOccludedLayer) { |
| 3568 | gfx::Size big_size(1000, 1000); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 3569 | host_impl_->SetViewportSize(big_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3570 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3571 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3572 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3573 | DidDrawCheckLayer* root = |
| 3574 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3575 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3576 | root->test_properties()->AddChild( |
| 3577 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 2)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3578 | DidDrawCheckLayer* occluded_layer = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3579 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children[0]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3580 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3581 | root->test_properties()->AddChild( |
| 3582 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 3)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3583 | root->test_properties()->force_render_surface = true; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3584 | DidDrawCheckLayer* top_layer = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3585 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children[1]); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3586 | // This layer covers the occluded_layer above. Make this layer large so it can |
| 3587 | // occlude. |
| 3588 | top_layer->SetBounds(big_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3589 | top_layer->SetContentsOpaque(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3590 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3591 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3592 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3593 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3594 | EXPECT_FALSE(occluded_layer->will_draw_called()); |
| 3595 | EXPECT_FALSE(occluded_layer->did_draw_called()); |
| 3596 | EXPECT_FALSE(top_layer->will_draw_called()); |
| 3597 | EXPECT_FALSE(top_layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3598 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3599 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3600 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3601 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3602 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3603 | EXPECT_FALSE(occluded_layer->will_draw_called()); |
| 3604 | EXPECT_FALSE(occluded_layer->did_draw_called()); |
| 3605 | EXPECT_TRUE(top_layer->will_draw_called()); |
| 3606 | EXPECT_TRUE(top_layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3607 | } |
| 3608 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3609 | TEST_F(LayerTreeHostImplTest, DidDrawCalledOnAllLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3610 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3611 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3612 | DidDrawCheckLayer* root = |
| 3613 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3614 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3615 | root->test_properties()->AddChild( |
| 3616 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 2)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3617 | root->test_properties()->force_render_surface = true; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3618 | DidDrawCheckLayer* layer1 = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3619 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children[0]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3620 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3621 | layer1->test_properties()->AddChild( |
| 3622 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 3)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3623 | DidDrawCheckLayer* layer2 = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3624 | static_cast<DidDrawCheckLayer*>(layer1->test_properties()->children[0]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3625 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3626 | layer1->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 3627 | layer1->test_properties()->should_flatten_transform = true; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3628 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3629 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3630 | EXPECT_FALSE(root->did_draw_called()); |
| 3631 | EXPECT_FALSE(layer1->did_draw_called()); |
| 3632 | EXPECT_FALSE(layer2->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3633 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3634 | LayerTreeHostImpl::FrameData frame; |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 3635 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren( |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3636 | *host_impl_->active_tree()->begin()); |
| 3637 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3638 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3639 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3640 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3641 | EXPECT_TRUE(root->did_draw_called()); |
| 3642 | EXPECT_TRUE(layer1->did_draw_called()); |
| 3643 | EXPECT_TRUE(layer2->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3644 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3645 | EXPECT_NE(root->render_surface(), layer1->render_surface()); |
thestig | d5fcf98 | 2015-05-11 18:41:38 | [diff] [blame] | 3646 | EXPECT_TRUE(layer1->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | class MissingTextureAnimatingLayer : public DidDrawCheckLayer { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3650 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3651 | static std::unique_ptr<LayerImpl> Create( |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 3652 | LayerTreeImpl* tree_impl, |
| 3653 | int id, |
| 3654 | bool tile_missing, |
| 3655 | bool had_incomplete_tile, |
| 3656 | bool animating, |
| 3657 | ResourceProvider* resource_provider, |
| 3658 | scoped_refptr<AnimationTimeline> timeline) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3659 | return base::WrapUnique(new MissingTextureAnimatingLayer( |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 3660 | tree_impl, id, tile_missing, had_incomplete_tile, animating, |
| 3661 | resource_provider, timeline)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3662 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3663 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3664 | void AppendQuads(RenderPass* render_pass, |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3665 | AppendQuadsData* append_quads_data) override { |
danakj | a8c66a5 | 2015-02-14 01:53:22 | [diff] [blame] | 3666 | LayerImpl::AppendQuads(render_pass, append_quads_data); |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3667 | if (had_incomplete_tile_) |
[email protected] | 76ca89b | 2014-07-14 20:32:05 | [diff] [blame] | 3668 | append_quads_data->num_incomplete_tiles++; |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3669 | if (tile_missing_) |
| 3670 | append_quads_data->num_missing_tiles++; |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3671 | } |
| 3672 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3673 | private: |
| 3674 | MissingTextureAnimatingLayer(LayerTreeImpl* tree_impl, |
| 3675 | int id, |
| 3676 | bool tile_missing, |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3677 | bool had_incomplete_tile, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3678 | bool animating, |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 3679 | ResourceProvider* resource_provider, |
| 3680 | scoped_refptr<AnimationTimeline> timeline) |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3681 | : DidDrawCheckLayer(tree_impl, id), |
| 3682 | tile_missing_(tile_missing), |
| 3683 | had_incomplete_tile_(had_incomplete_tile) { |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 3684 | if (animating) { |
| 3685 | this->SetElementId(LayerIdToElementIdForTesting(id)); |
| 3686 | AddAnimatedTransformToElementWithPlayer(this->element_id(), timeline, |
| 3687 | 10.0, 3, 0); |
| 3688 | } |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3689 | } |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3690 | |
| 3691 | bool tile_missing_; |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3692 | bool had_incomplete_tile_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3693 | }; |
| 3694 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3695 | struct PrepareToDrawSuccessTestCase { |
| 3696 | struct State { |
| 3697 | bool has_missing_tile = false; |
| 3698 | bool has_incomplete_tile = false; |
| 3699 | bool is_animating = false; |
| 3700 | bool has_copy_request = false; |
| 3701 | }; |
| 3702 | bool high_res_required = false; |
| 3703 | State layer_before; |
| 3704 | State layer_between; |
| 3705 | State layer_after; |
| 3706 | DrawResult expected_result; |
| 3707 | |
| 3708 | explicit PrepareToDrawSuccessTestCase(DrawResult result) |
| 3709 | : expected_result(result) {} |
| 3710 | }; |
| 3711 | |
sadrul | 0df063fc | 2016-07-27 17:36:51 | [diff] [blame] | 3712 | static void CreateLayerFromState( |
| 3713 | DidDrawCheckLayer* root, |
| 3714 | const scoped_refptr<AnimationTimeline>& timeline, |
| 3715 | const PrepareToDrawSuccessTestCase::State& state) { |
| 3716 | static int layer_id = 2; |
| 3717 | root->test_properties()->AddChild(MissingTextureAnimatingLayer::Create( |
| 3718 | root->layer_tree_impl(), layer_id++, state.has_missing_tile, |
| 3719 | state.has_incomplete_tile, state.is_animating, |
| 3720 | root->layer_tree_impl()->resource_provider(), timeline)); |
| 3721 | DidDrawCheckLayer* layer = |
| 3722 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children.back()); |
| 3723 | if (state.has_copy_request) |
| 3724 | layer->AddCopyRequest(); |
| 3725 | } |
| 3726 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3727 | TEST_F(LayerTreeHostImplTest, PrepareToDrawSucceedsAndFails) { |
| 3728 | std::vector<PrepareToDrawSuccessTestCase> cases; |
| 3729 | |
| 3730 | // 0. Default case. |
| 3731 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3732 | // 1. Animated layer first. |
| 3733 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3734 | cases.back().layer_before.is_animating = true; |
| 3735 | // 2. Animated layer between. |
| 3736 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3737 | cases.back().layer_between.is_animating = true; |
| 3738 | // 3. Animated layer last. |
| 3739 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3740 | cases.back().layer_after.is_animating = true; |
| 3741 | // 4. Missing tile first. |
| 3742 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3743 | cases.back().layer_before.has_missing_tile = true; |
| 3744 | // 5. Missing tile between. |
| 3745 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3746 | cases.back().layer_between.has_missing_tile = true; |
| 3747 | // 6. Missing tile last. |
| 3748 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3749 | cases.back().layer_after.has_missing_tile = true; |
| 3750 | // 7. Incomplete tile first. |
| 3751 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3752 | cases.back().layer_before.has_incomplete_tile = true; |
| 3753 | // 8. Incomplete tile between. |
| 3754 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3755 | cases.back().layer_between.has_incomplete_tile = true; |
| 3756 | // 9. Incomplete tile last. |
| 3757 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3758 | cases.back().layer_after.has_incomplete_tile = true; |
| 3759 | // 10. Animation with missing tile. |
| 3760 | cases.push_back( |
| 3761 | PrepareToDrawSuccessTestCase(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS)); |
| 3762 | cases.back().layer_between.has_missing_tile = true; |
| 3763 | cases.back().layer_between.is_animating = true; |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3764 | // 11. Animation with incomplete tile. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3765 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3766 | cases.back().layer_between.has_incomplete_tile = true; |
| 3767 | cases.back().layer_between.is_animating = true; |
| 3768 | |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3769 | // 12. High res required. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3770 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3771 | cases.back().high_res_required = true; |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3772 | // 13. High res required with incomplete tile. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3773 | cases.push_back( |
| 3774 | PrepareToDrawSuccessTestCase(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT)); |
| 3775 | cases.back().high_res_required = true; |
| 3776 | cases.back().layer_between.has_incomplete_tile = true; |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3777 | // 14. High res required with missing tile. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3778 | cases.push_back( |
| 3779 | PrepareToDrawSuccessTestCase(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT)); |
| 3780 | cases.back().high_res_required = true; |
| 3781 | cases.back().layer_between.has_missing_tile = true; |
| 3782 | |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3783 | // 15. High res required is higher priority than animating missing tiles. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3784 | cases.push_back( |
| 3785 | PrepareToDrawSuccessTestCase(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT)); |
| 3786 | cases.back().high_res_required = true; |
| 3787 | cases.back().layer_between.has_missing_tile = true; |
| 3788 | cases.back().layer_after.has_missing_tile = true; |
| 3789 | cases.back().layer_after.is_animating = true; |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3790 | // 16. High res required is higher priority than animating missing tiles. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3791 | cases.push_back( |
| 3792 | PrepareToDrawSuccessTestCase(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT)); |
| 3793 | cases.back().high_res_required = true; |
| 3794 | cases.back().layer_between.has_missing_tile = true; |
| 3795 | cases.back().layer_before.has_missing_tile = true; |
| 3796 | cases.back().layer_before.is_animating = true; |
| 3797 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3798 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3799 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3800 | DidDrawCheckLayer* root = |
| 3801 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3802 | root->test_properties()->force_render_surface = true; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3803 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3804 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3805 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3806 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3807 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3808 | host_impl_->DidDrawAllLayers(frame); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3809 | |
| 3810 | for (size_t i = 0; i < cases.size(); ++i) { |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 3811 | // Clean up host_impl_ state. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3812 | const auto& testcase = cases[i]; |
| 3813 | std::vector<LayerImpl*> to_remove; |
vmpstr | a2e8943 | 2016-07-20 02:05:34 | [diff] [blame] | 3814 | for (auto* child : root->test_properties()->children) |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 3815 | to_remove.push_back(child); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3816 | for (auto* child : to_remove) |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3817 | root->test_properties()->RemoveChild(child); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 3818 | timeline()->ClearPlayers(); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3819 | |
| 3820 | std::ostringstream scope; |
| 3821 | scope << "Test case: " << i; |
| 3822 | SCOPED_TRACE(scope.str()); |
| 3823 | |
sadrul | 0df063fc | 2016-07-27 17:36:51 | [diff] [blame] | 3824 | CreateLayerFromState(root, timeline(), testcase.layer_before); |
| 3825 | CreateLayerFromState(root, timeline(), testcase.layer_between); |
| 3826 | CreateLayerFromState(root, timeline(), testcase.layer_after); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3827 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3828 | |
| 3829 | if (testcase.high_res_required) |
| 3830 | host_impl_->SetRequiresHighResToDraw(); |
| 3831 | |
| 3832 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3833 | EXPECT_EQ(testcase.expected_result, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3834 | host_impl_->DrawLayers(&frame); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3835 | host_impl_->DidDrawAllLayers(frame); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3836 | } |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3837 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3838 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3839 | TEST_F(LayerTreeHostImplTest, |
| 3840 | PrepareToDrawWhenDrawAndSwapFullViewportEveryFrame) { |
| 3841 | CreateHostImpl(DefaultSettings(), |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 3842 | FakeOutputSurface::CreateDelegatingSoftware()); |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 3843 | |
| 3844 | const gfx::Transform external_transform; |
| 3845 | const gfx::Rect external_viewport; |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 3846 | const bool resourceless_software_draw = true; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 3847 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 3848 | external_transform); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3849 | |
| 3850 | std::vector<PrepareToDrawSuccessTestCase> cases; |
| 3851 | |
| 3852 | // 0. Default case. |
| 3853 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3854 | // 1. Animation with missing tile. |
| 3855 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3856 | cases.back().layer_between.has_missing_tile = true; |
| 3857 | cases.back().layer_between.is_animating = true; |
| 3858 | // 2. High res required with incomplete tile. |
| 3859 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3860 | cases.back().high_res_required = true; |
| 3861 | cases.back().layer_between.has_incomplete_tile = true; |
| 3862 | // 3. High res required with missing tile. |
| 3863 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3864 | cases.back().high_res_required = true; |
| 3865 | cases.back().layer_between.has_missing_tile = true; |
| 3866 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3867 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3868 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3869 | DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>( |
| 3870 | host_impl_->active_tree()->root_layer_for_testing()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3871 | root->test_properties()->force_render_surface = true; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3872 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3873 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 3874 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 3875 | resourceless_software_draw); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 3876 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3877 | for (size_t i = 0; i < cases.size(); ++i) { |
| 3878 | const auto& testcase = cases[i]; |
| 3879 | std::vector<LayerImpl*> to_remove; |
vmpstr | a2e8943 | 2016-07-20 02:05:34 | [diff] [blame] | 3880 | for (auto* child : root->test_properties()->children) |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 3881 | to_remove.push_back(child); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3882 | for (auto* child : to_remove) |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3883 | root->test_properties()->RemoveChild(child); |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3884 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3885 | std::ostringstream scope; |
| 3886 | scope << "Test case: " << i; |
| 3887 | SCOPED_TRACE(scope.str()); |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3888 | |
sadrul | 0df063fc | 2016-07-27 17:36:51 | [diff] [blame] | 3889 | CreateLayerFromState(root, timeline(), testcase.layer_before); |
| 3890 | CreateLayerFromState(root, timeline(), testcase.layer_between); |
| 3891 | CreateLayerFromState(root, timeline(), testcase.layer_after); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3892 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 3893 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3894 | if (testcase.high_res_required) |
| 3895 | host_impl_->SetRequiresHighResToDraw(); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 3896 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 3897 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 3898 | resourceless_software_draw); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3899 | } |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3900 | } |
| 3901 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3902 | TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3903 | std::unique_ptr<LayerImpl> root = |
| 3904 | LayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 3905 | root->SetScrollClipLayer(Layer::INVALID_ID); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3906 | root->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3907 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3908 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 3909 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 3910 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3911 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3912 | // Scroll event is ignored because layer is not scrollable. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 3913 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 3914 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 3915 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 3916 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 3917 | status.main_thread_scrolling_reasons); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3918 | EXPECT_FALSE(did_request_redraw_); |
| 3919 | EXPECT_FALSE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3920 | } |
| 3921 | |
hush | 85432c8 | 2015-07-23 00:24:54 | [diff] [blame] | 3922 | TEST_F(LayerTreeHostImplTest, ClampingAfterActivation) { |
| 3923 | host_impl_->CreatePendingTree(); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 3924 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
hush | 85432c8 | 2015-07-23 00:24:54 | [diff] [blame] | 3925 | CreateScrollAndContentsLayers(host_impl_->pending_tree(), |
| 3926 | gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3927 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
hush | 85432c8 | 2015-07-23 00:24:54 | [diff] [blame] | 3928 | host_impl_->ActivateSyncTree(); |
| 3929 | |
| 3930 | host_impl_->CreatePendingTree(); |
| 3931 | const gfx::ScrollOffset pending_scroll = gfx::ScrollOffset(-100, -100); |
| 3932 | LayerImpl* active_outer_layer = |
| 3933 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 3934 | LayerImpl* pending_outer_layer = |
| 3935 | host_impl_->pending_tree()->OuterViewportScrollLayer(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 3936 | pending_outer_layer->layer_tree_impl() |
| 3937 | ->property_trees() |
| 3938 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(pending_outer_layer->id(), |
| 3939 | pending_scroll); |
hush | 85432c8 | 2015-07-23 00:24:54 | [diff] [blame] | 3940 | |
| 3941 | host_impl_->ActivateSyncTree(); |
| 3942 | // Scrolloffsets on the active tree will be clamped after activation. |
| 3943 | EXPECT_EQ(active_outer_layer->CurrentScrollOffset(), gfx::ScrollOffset(0, 0)); |
| 3944 | } |
| 3945 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 3946 | class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { |
| 3947 | public: |
| 3948 | LayerTreeHostImplTopControlsTest() |
| 3949 | // Make the clip size the same as the layer (content) size so the layer is |
| 3950 | // non-scrollable. |
| 3951 | : layer_size_(10, 10), |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 3952 | clip_size_(layer_size_), |
| 3953 | top_controls_height_(50) { |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 3954 | viewport_size_ = gfx::Size(clip_size_.width(), |
| 3955 | clip_size_.height() + top_controls_height_); |
| 3956 | } |
| 3957 | |
| 3958 | bool CreateHostImpl(const LayerTreeSettings& settings, |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3959 | std::unique_ptr<OutputSurface> output_surface) override { |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 3960 | bool init = LayerTreeHostImplTest::CreateHostImpl( |
| 3961 | settings, std::move(output_surface)); |
bokan | aa5d1b03 | 2015-03-09 21:51:32 | [diff] [blame] | 3962 | if (init) { |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 3963 | host_impl_->active_tree()->set_top_controls_height(top_controls_height_); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 3964 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 3965 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 3966 | } |
| 3967 | return init; |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 3968 | } |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 3969 | |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 3970 | void SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 3971 | const gfx::Size& inner_viewport_size, |
| 3972 | const gfx::Size& outer_viewport_size, |
| 3973 | const gfx::Size& scroll_layer_size) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 3974 | settings_ = DefaultSettings(); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 3975 | CreateHostImpl(settings_, CreateOutputSurface()); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 3976 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 3977 | host_impl_->active_tree(), inner_viewport_size, outer_viewport_size, |
| 3978 | scroll_layer_size); |
| 3979 | } |
| 3980 | |
| 3981 | void SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 3982 | LayerTreeImpl* tree_impl, |
| 3983 | const gfx::Size& inner_viewport_size, |
| 3984 | const gfx::Size& outer_viewport_size, |
| 3985 | const gfx::Size& scroll_layer_size) { |
| 3986 | tree_impl->set_top_controls_shrink_blink_size(true); |
| 3987 | tree_impl->set_top_controls_height(top_controls_height_); |
| 3988 | tree_impl->SetCurrentTopControlsShownRatio(1.f); |
| 3989 | tree_impl->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 3990 | host_impl_->DidChangeTopControlsPosition(); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 3991 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3992 | std::unique_ptr<LayerImpl> root = LayerImpl::Create(tree_impl, 1); |
| 3993 | std::unique_ptr<LayerImpl> root_clip = LayerImpl::Create(tree_impl, 2); |
| 3994 | std::unique_ptr<LayerImpl> page_scale = LayerImpl::Create(tree_impl, 3); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 3995 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3996 | std::unique_ptr<LayerImpl> outer_scroll = LayerImpl::Create(tree_impl, 4); |
| 3997 | std::unique_ptr<LayerImpl> outer_clip = LayerImpl::Create(tree_impl, 5); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 3998 | |
| 3999 | root_clip->SetBounds(inner_viewport_size); |
| 4000 | root->SetScrollClipLayer(root_clip->id()); |
| 4001 | root->SetBounds(outer_viewport_size); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4002 | root->SetPosition(gfx::PointF()); |
| 4003 | root->SetDrawsContent(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4004 | root_clip->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 4005 | root->test_properties()->is_container_for_fixed_position_layers = true; |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4006 | outer_clip->SetBounds(outer_viewport_size); |
| 4007 | outer_scroll->SetScrollClipLayer(outer_clip->id()); |
| 4008 | outer_scroll->SetBounds(scroll_layer_size); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4009 | outer_scroll->SetPosition(gfx::PointF()); |
| 4010 | outer_scroll->SetDrawsContent(false); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 4011 | outer_scroll->test_properties()->is_container_for_fixed_position_layers = |
| 4012 | true; |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4013 | |
| 4014 | int inner_viewport_scroll_layer_id = root->id(); |
| 4015 | int outer_viewport_scroll_layer_id = outer_scroll->id(); |
| 4016 | int page_scale_layer_id = page_scale->id(); |
| 4017 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4018 | outer_clip->test_properties()->AddChild(std::move(outer_scroll)); |
| 4019 | root->test_properties()->AddChild(std::move(outer_clip)); |
| 4020 | page_scale->test_properties()->AddChild(std::move(root)); |
| 4021 | root_clip->test_properties()->AddChild(std::move(page_scale)); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4022 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4023 | tree_impl->SetRootLayerForTesting(std::move(root_clip)); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4024 | tree_impl->SetViewportLayersFromIds(Layer::INVALID_ID, page_scale_layer_id, |
| 4025 | inner_viewport_scroll_layer_id, |
| 4026 | outer_viewport_scroll_layer_id); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4027 | tree_impl->BuildPropertyTreesForTesting(); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4028 | |
| 4029 | host_impl_->SetViewportSize(inner_viewport_size); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4030 | LayerImpl* root_clip_ptr = tree_impl->root_layer_for_testing(); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4031 | EXPECT_EQ(inner_viewport_size, root_clip_ptr->bounds()); |
| 4032 | } |
| 4033 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4034 | protected: |
| 4035 | gfx::Size layer_size_; |
| 4036 | gfx::Size clip_size_; |
| 4037 | gfx::Size viewport_size_; |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4038 | float top_controls_height_; |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4039 | |
| 4040 | LayerTreeSettings settings_; |
| 4041 | }; // class LayerTreeHostImplTopControlsTest |
| 4042 | |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4043 | // Tests that, on a page with content the same size as the viewport, hiding |
| 4044 | // the top controls also increases the ScrollableSize (i.e. the content size). |
| 4045 | // Since the viewport got larger, the effective scrollable "content" also did. |
| 4046 | // This ensures, for one thing, that the overscroll glow is shown in the right |
| 4047 | // place. |
| 4048 | TEST_F(LayerTreeHostImplTopControlsTest, |
| 4049 | HidingTopControlsExpandsScrollableSize) { |
| 4050 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4051 | gfx::Size(50, 50), gfx::Size(50, 50), gfx::Size(50, 50)); |
| 4052 | |
| 4053 | LayerTreeImpl* active_tree = host_impl_->active_tree(); |
| 4054 | |
| 4055 | // Create a content layer beneath the outer viewport scroll layer. |
| 4056 | int id = host_impl_->OuterViewportScrollLayer()->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4057 | host_impl_->OuterViewportScrollLayer()->test_properties()->AddChild( |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4058 | LayerImpl::Create(host_impl_->active_tree(), id + 2)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 4059 | LayerImpl* content = |
| 4060 | active_tree->OuterViewportScrollLayer()->test_properties()->children[0]; |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4061 | content->SetBounds(gfx::Size(50, 50)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4062 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4063 | |
| 4064 | DrawFrame(); |
| 4065 | |
| 4066 | LayerImpl* inner_container = active_tree->InnerViewportContainerLayer(); |
| 4067 | LayerImpl* outer_container = active_tree->OuterViewportContainerLayer(); |
| 4068 | |
| 4069 | // The top controls should start off showing so the viewport should be shrunk. |
| 4070 | ASSERT_EQ(gfx::Size(50, 50), inner_container->bounds()); |
| 4071 | ASSERT_EQ(gfx::Size(50, 50), outer_container->bounds()); |
| 4072 | |
| 4073 | EXPECT_EQ(gfx::SizeF(50, 50), active_tree->ScrollableSize()); |
| 4074 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4075 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4076 | host_impl_ |
| 4077 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4078 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4079 | .thread); |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4080 | |
| 4081 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4082 | |
| 4083 | // Hide the top controls by a bit, the scrollable size should increase but the |
| 4084 | // actual content bounds shouldn't. |
| 4085 | { |
| 4086 | host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); |
| 4087 | ASSERT_EQ(gfx::Size(50, 75), inner_container->bounds()); |
| 4088 | ASSERT_EQ(gfx::Size(50, 75), outer_container->bounds()); |
| 4089 | EXPECT_EQ(gfx::SizeF(50, 75), active_tree->ScrollableSize()); |
| 4090 | EXPECT_EQ(gfx::SizeF(50, 50), content->BoundsForScrolling()); |
| 4091 | } |
| 4092 | |
| 4093 | // Fully hide the top controls. |
| 4094 | { |
| 4095 | host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); |
| 4096 | ASSERT_EQ(gfx::Size(50, 100), inner_container->bounds()); |
| 4097 | ASSERT_EQ(gfx::Size(50, 100), outer_container->bounds()); |
| 4098 | EXPECT_EQ(gfx::SizeF(50, 100), active_tree->ScrollableSize()); |
| 4099 | EXPECT_EQ(gfx::SizeF(50, 50), content->BoundsForScrolling()); |
| 4100 | } |
| 4101 | |
| 4102 | // Scrolling additionally shouldn't have any effect. |
| 4103 | { |
| 4104 | host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); |
| 4105 | ASSERT_EQ(gfx::Size(50, 100), inner_container->bounds()); |
| 4106 | ASSERT_EQ(gfx::Size(50, 100), outer_container->bounds()); |
| 4107 | EXPECT_EQ(gfx::SizeF(50, 100), active_tree->ScrollableSize()); |
| 4108 | EXPECT_EQ(gfx::SizeF(50, 50), content->BoundsForScrolling()); |
| 4109 | } |
| 4110 | |
| 4111 | host_impl_->top_controls_manager()->ScrollEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4112 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4113 | } |
| 4114 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4115 | TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4116 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4117 | gfx::Size(10, 10), gfx::Size(10, 10), gfx::Size(10, 10)); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4118 | DrawFrame(); |
| 4119 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4120 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4121 | host_impl_ |
| 4122 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4123 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4124 | .thread); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4125 | |
| 4126 | // Make the test scroll delta a fractional amount, to verify that the |
| 4127 | // fixed container size delta is (1) non-zero, and (2) fractional, and |
| 4128 | // (3) matches the movement of the top controls. |
| 4129 | gfx::Vector2dF top_controls_scroll_delta(0.f, 5.25f); |
| 4130 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4131 | host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
| 4132 | host_impl_->top_controls_manager()->ScrollEnd(); |
| 4133 | |
| 4134 | LayerImpl* inner_viewport_scroll_layer = |
| 4135 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
| 4136 | DCHECK(inner_viewport_scroll_layer); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4137 | host_impl_->ScrollEnd(EndState().get()); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4138 | EXPECT_FLOAT_EQ(top_controls_scroll_delta.y(), |
| 4139 | inner_viewport_scroll_layer->FixedContainerSizeDelta().y()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4140 | } |
| 4141 | |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4142 | // In this test, the outer viewport is initially unscrollable. We test that a |
| 4143 | // scroll initiated on the inner viewport, causing the top controls to show and |
| 4144 | // thus making the outer viewport scrollable, still scrolls the outer viewport. |
| 4145 | TEST_F(LayerTreeHostImplTopControlsTest, |
| 4146 | TopControlsOuterViewportBecomesScrollable) { |
| 4147 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4148 | gfx::Size(10, 50), gfx::Size(10, 50), gfx::Size(10, 100)); |
| 4149 | DrawFrame(); |
| 4150 | |
thestig | d5fcf98 | 2015-05-11 18:41:38 | [diff] [blame] | 4151 | LayerImpl* inner_scroll = |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4152 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 4153 | inner_scroll->SetDrawsContent(true); |
thestig | d5fcf98 | 2015-05-11 18:41:38 | [diff] [blame] | 4154 | LayerImpl* inner_container = |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4155 | host_impl_->active_tree()->InnerViewportContainerLayer(); |
thestig | d5fcf98 | 2015-05-11 18:41:38 | [diff] [blame] | 4156 | LayerImpl* outer_scroll = |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4157 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 4158 | outer_scroll->SetDrawsContent(true); |
thestig | d5fcf98 | 2015-05-11 18:41:38 | [diff] [blame] | 4159 | LayerImpl* outer_container = |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4160 | host_impl_->active_tree()->OuterViewportContainerLayer(); |
| 4161 | |
| 4162 | // Need SetDrawsContent so ScrollBegin's hit test finds an actual layer. |
| 4163 | outer_scroll->SetDrawsContent(true); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 4164 | host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 1.f, 2.f); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4165 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4166 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4167 | host_impl_ |
| 4168 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4169 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4170 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4171 | host_impl_->ScrollBy( |
| 4172 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, 50.f)).get()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4173 | |
| 4174 | // The entire scroll delta should have been used to hide the top controls. |
| 4175 | // The viewport layers should be resized back to their full sizes. |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4176 | EXPECT_EQ(0.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 4177 | EXPECT_EQ(0.f, inner_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4178 | EXPECT_EQ(100.f, inner_container->BoundsForScrolling().height()); |
| 4179 | EXPECT_EQ(100.f, outer_container->BoundsForScrolling().height()); |
| 4180 | |
| 4181 | // The inner viewport should be scrollable by 50px * page_scale. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4182 | host_impl_->ScrollBy( |
| 4183 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, 100.f)).get()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 4184 | EXPECT_EQ(50.f, inner_scroll->CurrentScrollOffset().y()); |
| 4185 | EXPECT_EQ(0.f, outer_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4186 | EXPECT_EQ(gfx::ScrollOffset(), outer_scroll->MaxScrollOffset()); |
| 4187 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4188 | host_impl_->ScrollEnd(EndState().get()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4189 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4190 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4191 | host_impl_ |
| 4192 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4193 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4194 | .thread); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4195 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll); |
| 4196 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4197 | host_impl_->ScrollBy( |
| 4198 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, -50.f)).get()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4199 | |
| 4200 | // The entire scroll delta should have been used to show the top controls. |
| 4201 | // The outer viewport should be resized to accomodate and scrolled to the |
| 4202 | // bottom of the document to keep the viewport in place. |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4203 | EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4204 | EXPECT_EQ(50.f, outer_container->BoundsForScrolling().height()); |
| 4205 | EXPECT_EQ(50.f, inner_container->BoundsForScrolling().height()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 4206 | EXPECT_EQ(25.f, outer_scroll->CurrentScrollOffset().y()); |
| 4207 | EXPECT_EQ(25.f, inner_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4208 | |
| 4209 | // Now when we continue scrolling, make sure the outer viewport gets scrolled |
| 4210 | // since it wasn't scrollable when the scroll began. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4211 | host_impl_->ScrollBy( |
| 4212 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, -20.f)).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 4213 | EXPECT_EQ(25.f, outer_scroll->CurrentScrollOffset().y()); |
| 4214 | EXPECT_EQ(15.f, inner_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4215 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4216 | host_impl_->ScrollBy( |
| 4217 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, -30.f)).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 4218 | EXPECT_EQ(25.f, outer_scroll->CurrentScrollOffset().y()); |
| 4219 | EXPECT_EQ(0.f, inner_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4220 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4221 | host_impl_->ScrollBy( |
| 4222 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, -50.f)).get()); |
| 4223 | host_impl_->ScrollEnd(EndState().get()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4224 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 4225 | EXPECT_EQ(0.f, outer_scroll->CurrentScrollOffset().y()); |
| 4226 | EXPECT_EQ(0.f, inner_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4227 | } |
| 4228 | |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4229 | // Test that the fixed position container delta is appropriately adjusted |
| 4230 | // by the top controls showing/hiding and page scale doesn't affect it. |
| 4231 | TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) { |
| 4232 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4233 | gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100)); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4234 | DrawFrame(); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 4235 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4236 | |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4237 | float page_scale = 1.5f; |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4238 | LayerImpl* outer_viewport_scroll_layer = |
| 4239 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 4240 | |
| 4241 | // Zoom in, since the fixed container is the outer viewport, the delta should |
| 4242 | // not be scaled. |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 4243 | host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f, 2.f); |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4244 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4245 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4246 | host_impl_ |
| 4247 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4248 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4249 | .thread); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4250 | |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4251 | // Scroll down, the top controls hiding should expand the viewport size so |
| 4252 | // the delta should be equal to the scroll distance. |
| 4253 | gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4254 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4255 | host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4256 | EXPECT_FLOAT_EQ(top_controls_height_ - top_controls_scroll_delta.y(), |
| 4257 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 4258 | EXPECT_FLOAT_EQ(top_controls_scroll_delta.y(), |
| 4259 | outer_viewport_scroll_layer->FixedContainerSizeDelta().y()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4260 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4261 | |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4262 | // Scroll past the maximum extent. The delta shouldn't be greater than the |
| 4263 | // top controls height. |
| 4264 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4265 | host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
| 4266 | host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
| 4267 | host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
| 4268 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4269 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, top_controls_height_), |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4270 | outer_viewport_scroll_layer->FixedContainerSizeDelta()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4271 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4272 | |
| 4273 | // Scroll in the direction to make the top controls show. |
| 4274 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4275 | host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta); |
| 4276 | EXPECT_EQ(top_controls_scroll_delta.y(), |
| 4277 | host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4278 | EXPECT_VECTOR_EQ( |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4279 | gfx::Vector2dF(0, top_controls_height_ - top_controls_scroll_delta.y()), |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4280 | outer_viewport_scroll_layer->FixedContainerSizeDelta()); |
| 4281 | host_impl_->top_controls_manager()->ScrollEnd(); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4282 | } |
| 4283 | |
bokan | 0223f2f72 | 2016-06-23 12:35:01 | [diff] [blame] | 4284 | // Push a top controls ratio from the main thread that we didn't send as a delta |
| 4285 | // and make sure that the ratio is clamped to the [0, 1] range. |
| 4286 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsPushUnsentRatio) { |
| 4287 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4288 | gfx::Size(10, 50), gfx::Size(10, 50), gfx::Size(10, 100)); |
| 4289 | DrawFrame(); |
| 4290 | |
| 4291 | // Need SetDrawsContent so ScrollBegin's hit test finds an actual layer. |
| 4292 | LayerImpl* inner_scroll = |
| 4293 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
| 4294 | inner_scroll->SetDrawsContent(true); |
| 4295 | LayerImpl* outer_scroll = |
| 4296 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 4297 | outer_scroll->SetDrawsContent(true); |
| 4298 | |
| 4299 | host_impl_->active_tree()->PushTopControlsFromMainThread(1); |
| 4300 | ASSERT_EQ(1.0f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 4301 | |
| 4302 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.5f); |
| 4303 | ASSERT_EQ(0.5f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 4304 | |
| 4305 | host_impl_->active_tree()->PushTopControlsFromMainThread(0); |
| 4306 | |
| 4307 | ASSERT_EQ(0, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 4308 | } |
| 4309 | |
tdresser | a4bec5df | 2015-07-14 13:23:34 | [diff] [blame] | 4310 | // Test that if only the top controls are scrolled, we shouldn't request a |
| 4311 | // commit. |
| 4312 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsDontTriggerCommit) { |
| 4313 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4314 | gfx::Size(100, 50), gfx::Size(100, 100), gfx::Size(100, 100)); |
| 4315 | DrawFrame(); |
| 4316 | |
| 4317 | // Show top controls |
| 4318 | EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 4319 | |
| 4320 | // Scroll 25px to hide top controls |
| 4321 | gfx::Vector2dF scroll_delta(0.f, 25.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4322 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4323 | host_impl_ |
| 4324 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4325 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4326 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4327 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | a4bec5df | 2015-07-14 13:23:34 | [diff] [blame] | 4328 | EXPECT_FALSE(did_request_commit_); |
| 4329 | } |
| 4330 | |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4331 | // Test that if a scrollable sublayer doesn't consume the scroll, |
| 4332 | // top controls should hide when scrolling down. |
| 4333 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollableSublayer) { |
| 4334 | gfx::Size sub_content_size(100, 400); |
| 4335 | gfx::Size sub_content_layer_size(100, 300); |
| 4336 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4337 | gfx::Size(100, 50), gfx::Size(100, 100), gfx::Size(100, 100)); |
| 4338 | DrawFrame(); |
| 4339 | |
| 4340 | // Show top controls |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4341 | EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4342 | |
| 4343 | LayerImpl* outer_viewport_scroll_layer = |
| 4344 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 4345 | int id = outer_viewport_scroll_layer->id(); |
| 4346 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4347 | std::unique_ptr<LayerImpl> child = |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4348 | LayerImpl::Create(host_impl_->active_tree(), id + 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4349 | std::unique_ptr<LayerImpl> child_clip = |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4350 | LayerImpl::Create(host_impl_->active_tree(), id + 3); |
| 4351 | |
| 4352 | child_clip->SetBounds(sub_content_layer_size); |
| 4353 | child->SetScrollClipLayer(child_clip->id()); |
| 4354 | child->SetBounds(sub_content_size); |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4355 | child->SetPosition(gfx::PointF()); |
| 4356 | child->SetDrawsContent(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 4357 | child->test_properties()->is_container_for_fixed_position_layers = true; |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4358 | |
| 4359 | // scroll child to limit |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 4360 | SetScrollOffsetDelta(child.get(), gfx::Vector2dF(0, 100.f)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4361 | child_clip->test_properties()->AddChild(std::move(child)); |
| 4362 | outer_viewport_scroll_layer->test_properties()->AddChild( |
| 4363 | std::move(child_clip)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4364 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4365 | |
| 4366 | // Scroll 25px to hide top controls |
| 4367 | gfx::Vector2dF scroll_delta(0.f, 25.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4368 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4369 | host_impl_ |
| 4370 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4371 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4372 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4373 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 4374 | host_impl_->ScrollEnd(EndState().get()); |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4375 | |
| 4376 | // Top controls should be hidden |
| 4377 | EXPECT_EQ(scroll_delta.y(), |
| 4378 | top_controls_height_ - |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4379 | host_impl_->top_controls_manager()->ContentTopOffset()); |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4380 | } |
| 4381 | |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4382 | // Ensure setting the top controls position explicitly using the setters on the |
| 4383 | // TreeImpl correctly affects the top controls manager and viewport bounds. |
| 4384 | TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 4385 | settings_ = DefaultSettings(); |
aelias | 5d3e3b4 | 2014-10-14 03:51:02 | [diff] [blame] | 4386 | CreateHostImpl(settings_, CreateOutputSurface()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4387 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4388 | layer_size_, layer_size_, layer_size_); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4389 | DrawFrame(); |
| 4390 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4391 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); |
| 4392 | host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( |
| 4393 | 30.f / top_controls_height_); |
| 4394 | host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive(); |
| 4395 | EXPECT_FLOAT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4396 | EXPECT_FLOAT_EQ(-20.f, |
| 4397 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4398 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4399 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); |
| 4400 | EXPECT_FLOAT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4401 | EXPECT_FLOAT_EQ(-50.f, |
| 4402 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4403 | |
| 4404 | host_impl_->DidChangeTopControlsPosition(); |
| 4405 | |
| 4406 | // Now that top controls have moved, expect the clip to resize. |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4407 | LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4408 | ->test_properties() |
| 4409 | ->parent->test_properties() |
| 4410 | ->parent; |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4411 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4412 | } |
| 4413 | |
| 4414 | // Test that the top_controls delta and sent delta are appropriately |
| 4415 | // applied on sync tree activation. The total top controls offset shouldn't |
| 4416 | // change after the activation. |
| 4417 | TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 4418 | settings_ = DefaultSettings(); |
aelias | 5d3e3b4 | 2014-10-14 03:51:02 | [diff] [blame] | 4419 | CreateHostImpl(settings_, CreateOutputSurface()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4420 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4421 | layer_size_, layer_size_, layer_size_); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4422 | DrawFrame(); |
| 4423 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4424 | host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( |
| 4425 | 20.f / top_controls_height_); |
| 4426 | host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive(); |
| 4427 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio( |
| 4428 | 15.f / top_controls_height_); |
| 4429 | host_impl_->active_tree() |
| 4430 | ->top_controls_shown_ratio() |
| 4431 | ->PullDeltaForMainThread(); |
| 4432 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); |
| 4433 | host_impl_->sync_tree()->PushTopControlsFromMainThread(15.f / |
| 4434 | top_controls_height_); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4435 | |
| 4436 | host_impl_->DidChangeTopControlsPosition(); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4437 | LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4438 | ->test_properties() |
| 4439 | ->parent->test_properties() |
| 4440 | ->parent; |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4441 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4442 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4443 | |
| 4444 | host_impl_->ActivateSyncTree(); |
| 4445 | |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4446 | inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4447 | ->test_properties() |
| 4448 | ->parent->test_properties() |
| 4449 | ->parent; |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4450 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4451 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4452 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4453 | EXPECT_FLOAT_EQ( |
| 4454 | -15.f, host_impl_->active_tree()->top_controls_shown_ratio()->Delta() * |
| 4455 | top_controls_height_); |
| 4456 | EXPECT_FLOAT_EQ( |
| 4457 | 15.f, |
| 4458 | host_impl_->active_tree()->top_controls_shown_ratio()->ActiveBase() * |
| 4459 | top_controls_height_); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4460 | } |
| 4461 | |
| 4462 | // Test that changing the top controls layout height is correctly applied to |
| 4463 | // the inner viewport container bounds. That is, the top controls layout |
| 4464 | // height is the amount that the inner viewport container was shrunk outside |
| 4465 | // the compositor to accommodate the top controls. |
| 4466 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 4467 | settings_ = DefaultSettings(); |
aelias | 5d3e3b4 | 2014-10-14 03:51:02 | [diff] [blame] | 4468 | CreateHostImpl(settings_, CreateOutputSurface()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4469 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4470 | layer_size_, layer_size_, layer_size_); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4471 | DrawFrame(); |
| 4472 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4473 | host_impl_->sync_tree()->PushTopControlsFromMainThread(1.f); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4474 | host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4475 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4476 | host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( |
| 4477 | 1.f); |
| 4478 | host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive(); |
| 4479 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4480 | |
| 4481 | host_impl_->DidChangeTopControlsPosition(); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4482 | LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4483 | ->test_properties() |
| 4484 | ->parent->test_properties() |
| 4485 | ->parent; |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4486 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4487 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4488 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4489 | host_impl_->sync_tree()->root_layer_for_testing()->SetBounds( |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4490 | gfx::Size(inner_clip_ptr->bounds().width(), |
| 4491 | inner_clip_ptr->bounds().height() - 50.f)); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4492 | |
| 4493 | host_impl_->ActivateSyncTree(); |
| 4494 | |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4495 | inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4496 | ->test_properties() |
| 4497 | ->parent->test_properties() |
| 4498 | ->parent; |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4499 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4500 | |
| 4501 | // The total bounds should remain unchanged since the bounds delta should |
| 4502 | // account for the difference between the layout height and the current |
| 4503 | // top controls offset. |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4504 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
| 4505 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 50.f), inner_clip_ptr->bounds_delta()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4506 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4507 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4508 | host_impl_->DidChangeTopControlsPosition(); |
| 4509 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4510 | EXPECT_EQ(1.f, host_impl_->top_controls_manager()->TopControlsShownRatio()); |
| 4511 | EXPECT_EQ(50.f, host_impl_->top_controls_manager()->TopControlsHeight()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4512 | EXPECT_EQ(50.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4513 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), inner_clip_ptr->bounds_delta()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4514 | EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height() - 50.f), |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4515 | inner_clip_ptr->bounds()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4516 | } |
| 4517 | |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4518 | // Test that showing/hiding the top controls when the viewport is fully scrolled |
| 4519 | // doesn't incorrectly change the viewport offset due to clamping from changing |
| 4520 | // viewport bounds. |
| 4521 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) { |
| 4522 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4523 | gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); |
| 4524 | DrawFrame(); |
| 4525 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4526 | EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4527 | |
| 4528 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 4529 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 4530 | |
| 4531 | // Scroll the viewports to max scroll offset. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 4532 | SetScrollOffsetDelta(outer_scroll, gfx::Vector2dF(0, 200.f)); |
| 4533 | SetScrollOffsetDelta(inner_scroll, gfx::Vector2dF(100, 100.f)); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4534 | |
| 4535 | gfx::ScrollOffset viewport_offset = |
| 4536 | host_impl_->active_tree()->TotalScrollOffset(); |
| 4537 | EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); |
| 4538 | |
| 4539 | // Hide the top controls by 25px. |
| 4540 | gfx::Vector2dF scroll_delta(0.f, 25.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4541 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4542 | host_impl_ |
| 4543 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4544 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4545 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4546 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 4547 | |
| 4548 | // scrolling down at the max extents no longer hides the top controls |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4549 | EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 4550 | |
| 4551 | // forcefully hide the top controls by 25px |
| 4552 | host_impl_->top_controls_manager()->ScrollBy(scroll_delta); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4553 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4554 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4555 | EXPECT_FLOAT_EQ(scroll_delta.y(), |
| 4556 | top_controls_height_ - |
| 4557 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4558 | |
| 4559 | inner_scroll->ClampScrollToMaxScrollOffset(); |
| 4560 | outer_scroll->ClampScrollToMaxScrollOffset(); |
| 4561 | |
| 4562 | // We should still be fully scrolled. |
| 4563 | EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), |
| 4564 | host_impl_->active_tree()->TotalScrollOffset()); |
| 4565 | |
| 4566 | viewport_offset = host_impl_->active_tree()->TotalScrollOffset(); |
| 4567 | |
| 4568 | // Bring the top controls down by 25px. |
| 4569 | scroll_delta = gfx::Vector2dF(0.f, -25.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4570 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4571 | host_impl_ |
| 4572 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4573 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4574 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4575 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 4576 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4577 | |
| 4578 | // The viewport offset shouldn't have changed. |
| 4579 | EXPECT_EQ(viewport_offset, |
| 4580 | host_impl_->active_tree()->TotalScrollOffset()); |
| 4581 | |
| 4582 | // Scroll the viewports to max scroll offset. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 4583 | SetScrollOffsetDelta(outer_scroll, gfx::Vector2dF(0, 200.f)); |
| 4584 | SetScrollOffsetDelta(inner_scroll, gfx::Vector2dF(100, 100.f)); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4585 | EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), |
| 4586 | host_impl_->active_tree()->TotalScrollOffset()); |
| 4587 | } |
| 4588 | |
| 4589 | // Test that the top controls coming in and out maintains the same aspect ratio |
| 4590 | // between the inner and outer viewports. |
| 4591 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) { |
| 4592 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4593 | gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 4594 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 2.f); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4595 | DrawFrame(); |
| 4596 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4597 | EXPECT_FLOAT_EQ(top_controls_height_, |
| 4598 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4599 | |
| 4600 | gfx::Vector2dF scroll_delta(0.f, 25.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4601 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4602 | host_impl_ |
| 4603 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4604 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4605 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4606 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 4607 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4608 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4609 | EXPECT_FLOAT_EQ(scroll_delta.y(), |
| 4610 | top_controls_height_ - |
| 4611 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4612 | |
| 4613 | // Top controls were hidden by 25px so the inner viewport should have expanded |
| 4614 | // by that much. |
| 4615 | LayerImpl* outer_container = |
| 4616 | host_impl_->active_tree()->OuterViewportContainerLayer(); |
| 4617 | LayerImpl* inner_container = |
| 4618 | host_impl_->active_tree()->InnerViewportContainerLayer(); |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4619 | EXPECT_EQ(gfx::SizeF(100.f, 100.f + 25.f), |
| 4620 | inner_container->BoundsForScrolling()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4621 | |
| 4622 | // Outer viewport should match inner's aspect ratio. The bounds are ceiled. |
| 4623 | float aspect_ratio = inner_container->BoundsForScrolling().width() / |
| 4624 | inner_container->BoundsForScrolling().height(); |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4625 | gfx::SizeF expected = |
| 4626 | gfx::SizeF(gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio))); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4627 | EXPECT_EQ(expected, outer_container->BoundsForScrolling()); |
| 4628 | EXPECT_EQ(expected, |
| 4629 | host_impl_->InnerViewportScrollLayer()->BoundsForScrolling()); |
| 4630 | } |
| 4631 | |
| 4632 | // Test that scrolling the outer viewport affects the top controls. |
| 4633 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { |
| 4634 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4635 | gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); |
| 4636 | DrawFrame(); |
| 4637 | |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4638 | EXPECT_EQ(top_controls_height_, |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4639 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4640 | |
| 4641 | // Send a gesture scroll that will scroll the outer viewport, make sure the |
| 4642 | // top controls get scrolled. |
| 4643 | gfx::Vector2dF scroll_delta(0.f, 15.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4644 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4645 | host_impl_ |
| 4646 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4647 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4648 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4649 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 4650 | |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 4651 | EXPECT_EQ(host_impl_->InnerViewportScrollLayer(), |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4652 | host_impl_->CurrentlyScrollingLayer()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4653 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4654 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4655 | EXPECT_FLOAT_EQ(scroll_delta.y(), |
| 4656 | top_controls_height_ - |
| 4657 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4658 | |
| 4659 | scroll_delta = gfx::Vector2dF(0.f, 50.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4660 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4661 | host_impl_ |
| 4662 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4663 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4664 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4665 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4666 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4667 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset()); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 4668 | EXPECT_EQ(host_impl_->InnerViewportScrollLayer(), |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4669 | host_impl_->CurrentlyScrollingLayer()); |
| 4670 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4671 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4672 | |
| 4673 | // Position the viewports such that the inner viewport will be scrolled. |
| 4674 | gfx::Vector2dF inner_viewport_offset(0.f, 25.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 4675 | SetScrollOffsetDelta(host_impl_->OuterViewportScrollLayer(), |
| 4676 | gfx::Vector2dF()); |
| 4677 | SetScrollOffsetDelta(host_impl_->InnerViewportScrollLayer(), |
| 4678 | inner_viewport_offset); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4679 | |
| 4680 | scroll_delta = gfx::Vector2dF(0.f, -65.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4681 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4682 | host_impl_ |
| 4683 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4684 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4685 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4686 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4687 | |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4688 | EXPECT_EQ(top_controls_height_, |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4689 | host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4690 | EXPECT_FLOAT_EQ( |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4691 | inner_viewport_offset.y() + (scroll_delta.y() + top_controls_height_), |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 4692 | ScrollDelta(host_impl_->InnerViewportScrollLayer()).y()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4693 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4694 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4695 | } |
| 4696 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4697 | TEST_F(LayerTreeHostImplTopControlsTest, |
| 4698 | ScrollNonScrollableRootWithTopControls) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 4699 | settings_ = DefaultSettings(); |
aelias | 5d3e3b4 | 2014-10-14 03:51:02 | [diff] [blame] | 4700 | CreateHostImpl(settings_, CreateOutputSurface()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4701 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4702 | layer_size_, layer_size_, layer_size_); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 4703 | DrawFrame(); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 4704 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4705 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4706 | host_impl_ |
| 4707 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4708 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4709 | .thread); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 4710 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4711 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4712 | host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); |
| 4713 | host_impl_->top_controls_manager()->ScrollEnd(); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4714 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4715 | // Now that top controls have moved, expect the clip to resize. |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4716 | LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4717 | ->test_properties() |
| 4718 | ->parent->test_properties() |
| 4719 | ->parent; |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4720 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 4721 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4722 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | d948c11 | 2014-01-10 02:13:53 | [diff] [blame] | 4723 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4724 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4725 | host_impl_ |
| 4726 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4727 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4728 | .thread); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4729 | |
| 4730 | float scroll_increment_y = -25.f; |
| 4731 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4732 | host_impl_->top_controls_manager()->ScrollBy( |
| 4733 | gfx::Vector2dF(0.f, scroll_increment_y)); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4734 | EXPECT_FLOAT_EQ(-scroll_increment_y, |
| 4735 | host_impl_->top_controls_manager()->ContentTopOffset()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4736 | // Now that top controls have moved, expect the clip to resize. |
| 4737 | EXPECT_EQ(gfx::Size(viewport_size_.width(), |
| 4738 | viewport_size_.height() + scroll_increment_y), |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4739 | inner_clip_ptr->bounds()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4740 | |
| 4741 | host_impl_->top_controls_manager()->ScrollBy( |
| 4742 | gfx::Vector2dF(0.f, scroll_increment_y)); |
| 4743 | host_impl_->top_controls_manager()->ScrollEnd(); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4744 | EXPECT_FLOAT_EQ(-2 * scroll_increment_y, |
| 4745 | host_impl_->top_controls_manager()->ContentTopOffset()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4746 | // Now that top controls have moved, expect the clip to resize. |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4747 | EXPECT_EQ(clip_size_, inner_clip_ptr->bounds()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4748 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4749 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4750 | |
| 4751 | // Verify the layer is once-again non-scrollable. |
| 4752 | EXPECT_EQ( |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 4753 | gfx::ScrollOffset(), |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4754 | host_impl_->active_tree()->InnerViewportScrollLayer()->MaxScrollOffset()); |
| 4755 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4756 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4757 | host_impl_ |
| 4758 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4759 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4760 | .thread); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 4761 | } |
| 4762 | |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4763 | // Tests that activating a pending tree while there's a bounds_delta on the |
| 4764 | // viewport layers from top controls doesn't cause a scroll jump. This bug was |
| 4765 | // occurring because the UpdateViewportContainerSizes was being called before |
| 4766 | // the property trees were updated with the bounds_delta. crbug.com/597266. |
| 4767 | TEST_F(LayerTreeHostImplTopControlsTest, ViewportBoundsDeltaOnTreeActivation) { |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4768 | const gfx::Size inner_viewport_size(1000, 1000); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4769 | const gfx::Size outer_viewport_size(1000, 1000); |
| 4770 | const gfx::Size content_size(2000, 2000); |
| 4771 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4772 | // Initialization |
| 4773 | { |
| 4774 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4775 | inner_viewport_size, outer_viewport_size, content_size); |
| 4776 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4777 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4778 | // Start off with the top controls hidden on both main and impl. |
| 4779 | host_impl_->active_tree()->set_top_controls_shrink_blink_size(false); |
| 4780 | host_impl_->active_tree()->PushTopControlsFromMainThread(0); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4781 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4782 | host_impl_->CreatePendingTree(); |
| 4783 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4784 | host_impl_->pending_tree(), inner_viewport_size, outer_viewport_size, |
| 4785 | content_size); |
| 4786 | host_impl_->pending_tree()->set_top_controls_shrink_blink_size(false); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4787 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4788 | // Fully scroll the viewport. |
| 4789 | host_impl_->ScrollBegin(BeginState(gfx::Point(75, 75)).get(), |
| 4790 | InputHandler::TOUCHSCREEN); |
| 4791 | host_impl_->ScrollBy( |
| 4792 | UpdateState(gfx::Point(), gfx::Vector2d(0, 2000)).get()); |
| 4793 | host_impl_->ScrollEnd(EndState().get()); |
| 4794 | } |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4795 | |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4796 | LayerImpl* outer_scroll = |
| 4797 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 4798 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4799 | ASSERT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4800 | ASSERT_EQ(1000, outer_scroll->MaxScrollOffset().y()); |
| 4801 | ASSERT_EQ(1000, outer_scroll->CurrentScrollOffset().y()); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4802 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4803 | // Kick off an animation to show the top controls. |
| 4804 | host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, true); |
| 4805 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 4806 | BeginFrameArgs begin_frame_args = |
| 4807 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4808 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4809 | // Pump an animation frame to put some delta in the top controls. |
| 4810 | { |
| 4811 | begin_frame_args.frame_time = |
| 4812 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 4813 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 4814 | host_impl_->Animate(); |
| 4815 | host_impl_->UpdateAnimationState(true); |
| 4816 | host_impl_->DidFinishImplFrame(); |
| 4817 | } |
| 4818 | |
| 4819 | // Pull the top controls delta and get it back to the pending tree so that |
| 4820 | // when we go to activate the pending tree we cause a change to top controls. |
| 4821 | { |
| 4822 | float delta = |
| 4823 | host_impl_->active_tree()->top_controls_shown_ratio()->Delta(); |
| 4824 | ASSERT_GT(delta, 0); |
| 4825 | ASSERT_LT(delta, 1); |
| 4826 | host_impl_->active_tree() |
| 4827 | ->top_controls_shown_ratio() |
| 4828 | ->PullDeltaForMainThread(); |
| 4829 | host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( |
| 4830 | delta); |
| 4831 | } |
| 4832 | |
| 4833 | // 200 is the kShowHideMaxDurationMs value from top_controls_manager.cc so the |
| 4834 | // top controls should be fully animated in this frame. |
| 4835 | { |
| 4836 | begin_frame_args.frame_time = |
| 4837 | start_time + base::TimeDelta::FromMilliseconds(200); |
| 4838 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 4839 | host_impl_->Animate(); |
| 4840 | host_impl_->UpdateAnimationState(true); |
| 4841 | host_impl_->DidFinishImplFrame(); |
| 4842 | |
| 4843 | ASSERT_EQ(50, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4844 | ASSERT_EQ(1050, outer_scroll->MaxScrollOffset().y()); |
| 4845 | // NEAR because clip layer bounds are truncated in MaxScrollOffset so we |
| 4846 | // lose some precision in the intermediate animation steps. |
| 4847 | ASSERT_NEAR(1050, outer_scroll->CurrentScrollOffset().y(), 1.f); |
| 4848 | } |
| 4849 | |
| 4850 | // Activate the pending tree which should have the same scroll value as the |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4851 | // active tree. |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4852 | { |
| 4853 | host_impl_->pending_tree() |
| 4854 | ->property_trees() |
| 4855 | ->scroll_tree.SetScrollOffsetDeltaForTesting(outer_scroll->id(), |
| 4856 | gfx::Vector2dF(0, 1050)); |
| 4857 | host_impl_->ActivateSyncTree(); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4858 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4859 | // Make sure we don't accidentally clamp the outer offset based on a bounds |
| 4860 | // delta that hasn't yet been updated. |
| 4861 | EXPECT_NEAR(1050, outer_scroll->CurrentScrollOffset().y(), 1.f); |
| 4862 | } |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4863 | } |
| 4864 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4865 | TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { |
| 4866 | // Test the configuration where a non-composited root layer is embedded in a |
| 4867 | // scrollable outer layer. |
| 4868 | gfx::Size surface_size(10, 10); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4869 | gfx::Size contents_size(20, 20); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4870 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4871 | std::unique_ptr<LayerImpl> content_layer = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4872 | LayerImpl::Create(host_impl_->active_tree(), 1); |
| 4873 | content_layer->SetDrawsContent(true); |
| 4874 | content_layer->SetPosition(gfx::PointF()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4875 | content_layer->SetBounds(contents_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4876 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4877 | std::unique_ptr<LayerImpl> scroll_clip_layer = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4878 | LayerImpl::Create(host_impl_->active_tree(), 3); |
| 4879 | scroll_clip_layer->SetBounds(surface_size); |
| 4880 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4881 | std::unique_ptr<LayerImpl> scroll_layer = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4882 | LayerImpl::Create(host_impl_->active_tree(), 2); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4883 | scroll_layer->SetScrollClipLayer(3); |
| 4884 | scroll_layer->SetBounds(contents_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4885 | scroll_layer->SetPosition(gfx::PointF()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4886 | scroll_layer->test_properties()->AddChild(std::move(content_layer)); |
| 4887 | scroll_clip_layer->test_properties()->AddChild(std::move(scroll_layer)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4888 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4889 | scroll_clip_layer->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4890 | host_impl_->active_tree()->SetRootLayerForTesting( |
| 4891 | std::move(scroll_clip_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4892 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 4893 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 4894 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 4895 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4896 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4897 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4898 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4899 | InputHandler::WHEEL) |
| 4900 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4901 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
| 4902 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4903 | EXPECT_TRUE(did_request_redraw_); |
| 4904 | EXPECT_TRUE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4905 | } |
| 4906 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4907 | TEST_F(LayerTreeHostImplTest, ScrollChildCallsCommitAndRedraw) { |
| 4908 | gfx::Size surface_size(10, 10); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4909 | gfx::Size contents_size(20, 20); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4910 | std::unique_ptr<LayerImpl> root = |
| 4911 | LayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4912 | root->SetBounds(surface_size); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4913 | root->test_properties()->AddChild( |
| 4914 | CreateScrollableLayer(2, contents_size, root.get())); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4915 | root->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4916 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4917 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 4918 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 4919 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 4920 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4921 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4922 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4923 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4924 | InputHandler::WHEEL) |
| 4925 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4926 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
| 4927 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4928 | EXPECT_TRUE(did_request_redraw_); |
| 4929 | EXPECT_TRUE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4930 | } |
| 4931 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4932 | TEST_F(LayerTreeHostImplTest, ScrollMissesChild) { |
| 4933 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4934 | std::unique_ptr<LayerImpl> root = |
| 4935 | LayerImpl::Create(host_impl_->active_tree(), 1); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4936 | root->test_properties()->AddChild( |
| 4937 | CreateScrollableLayer(2, surface_size, root.get())); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4938 | root->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4939 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4940 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 4941 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 4942 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 4943 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4944 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4945 | // Scroll event is ignored because the input coordinate is outside the layer |
| 4946 | // boundaries. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4947 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 4948 | BeginState(gfx::Point(15, 5)).get(), InputHandler::WHEEL); |
| 4949 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 4950 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4951 | status.main_thread_scrolling_reasons); |
| 4952 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4953 | EXPECT_FALSE(did_request_redraw_); |
| 4954 | EXPECT_FALSE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4955 | } |
| 4956 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4957 | TEST_F(LayerTreeHostImplTest, ScrollMissesBackfacingChild) { |
| 4958 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4959 | std::unique_ptr<LayerImpl> root = |
| 4960 | LayerImpl::Create(host_impl_->active_tree(), 1); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4961 | root->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4962 | std::unique_ptr<LayerImpl> child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4963 | CreateScrollableLayer(2, surface_size, root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4964 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4965 | gfx::Transform matrix; |
| 4966 | matrix.RotateAboutXAxis(180.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4967 | child->test_properties()->transform = matrix; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4968 | child->test_properties()->double_sided = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4969 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4970 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4971 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4972 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 4973 | |
| 4974 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 4975 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4976 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4977 | // Scroll event is ignored because the scrollable layer is not facing the |
| 4978 | // viewer and there is nothing scrollable behind it. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4979 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 4980 | BeginState(gfx::Point(5, 5)).get(), InputHandler::WHEEL); |
| 4981 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 4982 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4983 | status.main_thread_scrolling_reasons); |
| 4984 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4985 | EXPECT_FALSE(did_request_redraw_); |
| 4986 | EXPECT_FALSE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4987 | } |
| 4988 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4989 | TEST_F(LayerTreeHostImplTest, ScrollBlockedByContentLayer) { |
| 4990 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4991 | std::unique_ptr<LayerImpl> clip_layer = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4992 | LayerImpl::Create(host_impl_->active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4993 | std::unique_ptr<LayerImpl> content_layer = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4994 | CreateScrollableLayer(1, surface_size, clip_layer.get()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4995 | content_layer->set_main_thread_scrolling_reasons( |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 4996 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4997 | content_layer->SetScrollClipLayer(Layer::INVALID_ID); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4998 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4999 | // Note: we can use the same clip layer for both since both calls to |
| 5000 | // CreateScrollableLayer() use the same surface size. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5001 | std::unique_ptr<LayerImpl> scroll_layer = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5002 | CreateScrollableLayer(2, surface_size, clip_layer.get()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5003 | scroll_layer->test_properties()->AddChild(std::move(content_layer)); |
| 5004 | clip_layer->test_properties()->AddChild(std::move(scroll_layer)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5005 | clip_layer->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5006 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5007 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(clip_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5008 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 5009 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 5010 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5011 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5012 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5013 | // Scrolling fails because the content layer is asking to be scrolled on the |
| 5014 | // main thread. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5015 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 5016 | BeginState(gfx::Point(5, 5)).get(), InputHandler::WHEEL); |
| 5017 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 5018 | EXPECT_EQ(MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5019 | status.main_thread_scrolling_reasons); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5020 | } |
| 5021 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5022 | TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnMainThread) { |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5023 | gfx::Size viewport_size(20, 20); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5024 | float page_scale = 2.f; |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5025 | |
| 5026 | SetupScrollAndContentsLayers(viewport_size); |
| 5027 | |
| 5028 | // Setup the layers so that the outer viewport is scrollable. |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 5029 | host_impl_->active_tree() |
| 5030 | ->InnerViewportScrollLayer() |
| 5031 | ->test_properties() |
| 5032 | ->parent->SetBounds(viewport_size); |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5033 | host_impl_->active_tree()->OuterViewportScrollLayer()->SetBounds( |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5034 | gfx::Size(40, 40)); |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5035 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5036 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5037 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5038 | LayerImpl* root_scroll = |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5039 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5040 | LayerImpl* inner_scroll = |
| 5041 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 5042 | EXPECT_EQ(viewport_size, root_scroll->scroll_clip_layer()->bounds()); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 5043 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5044 | gfx::Vector2d scroll_delta(0, 10); |
| 5045 | gfx::Vector2d expected_scroll_delta = scroll_delta; |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5046 | gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset(); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5047 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5048 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5049 | InputHandler::WHEEL) |
| 5050 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5051 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5052 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5053 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5054 | // Set new page scale from main thread. |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5055 | host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f, 2.f); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5056 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5057 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 5058 | host_impl_->ProcessScrollDeltas(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5059 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), inner_scroll->id(), |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5060 | expected_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5061 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5062 | // The scroll range should also have been updated. |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5063 | EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5064 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5065 | // The page scale delta remains constant because the impl thread did not |
| 5066 | // scale. |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5067 | EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5068 | } |
| 5069 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5070 | TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnImplThread) { |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5071 | gfx::Size viewport_size(20, 20); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5072 | float page_scale = 2.f; |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5073 | |
| 5074 | SetupScrollAndContentsLayers(viewport_size); |
| 5075 | |
| 5076 | // Setup the layers so that the outer viewport is scrollable. |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 5077 | host_impl_->active_tree() |
| 5078 | ->InnerViewportScrollLayer() |
| 5079 | ->test_properties() |
| 5080 | ->parent->SetBounds(viewport_size); |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5081 | host_impl_->active_tree()->OuterViewportScrollLayer()->SetBounds( |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5082 | gfx::Size(40, 40)); |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5083 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5084 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 5085 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5086 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5087 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5088 | LayerImpl* root_scroll = |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5089 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5090 | LayerImpl* inner_scroll = |
| 5091 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 5092 | EXPECT_EQ(viewport_size, root_scroll->scroll_clip_layer()->bounds()); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 5093 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5094 | gfx::Vector2d scroll_delta(0, 10); |
| 5095 | gfx::Vector2d expected_scroll_delta = scroll_delta; |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5096 | gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset(); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5097 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5098 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5099 | InputHandler::WHEEL) |
| 5100 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5101 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5102 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5103 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5104 | // Set new page scale on impl thread by pinching. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5105 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5106 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5107 | host_impl_->PinchGestureBegin(); |
| 5108 | host_impl_->PinchGestureUpdate(page_scale, gfx::Point()); |
| 5109 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5110 | host_impl_->ScrollEnd(EndState().get()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5111 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5112 | DrawOneFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5113 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5114 | // The scroll delta is not scaled because the main thread did not scale. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5115 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 5116 | host_impl_->ProcessScrollDeltas(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5117 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), inner_scroll->id(), |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5118 | expected_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5119 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5120 | // The scroll range should also have been updated. |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5121 | EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5122 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5123 | // The page scale delta should match the new scale on the impl side. |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 5124 | EXPECT_EQ(page_scale, host_impl_->active_tree()->current_page_scale_factor()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5125 | } |
| 5126 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5127 | TEST_F(LayerTreeHostImplTest, PageScaleDeltaAppliedToRootScrollLayerOnly) { |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 5128 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5129 | gfx::Size surface_size(10, 10); |
| 5130 | float default_page_scale = 1.f; |
| 5131 | gfx::Transform default_page_scale_matrix; |
[email protected] | 3209161d | 2013-03-29 19:17:34 | [diff] [blame] | 5132 | default_page_scale_matrix.Scale(default_page_scale, default_page_scale); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 5133 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5134 | float new_page_scale = 2.f; |
| 5135 | gfx::Transform new_page_scale_matrix; |
| 5136 | new_page_scale_matrix.Scale(new_page_scale, new_page_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5137 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5138 | // Create a normal scrollable root layer and another scrollable child layer. |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5139 | LayerImpl* scroll = SetupScrollAndContentsLayers(surface_size); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 5140 | scroll->SetDrawsContent(true); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5141 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 5142 | LayerImpl* child = scroll->test_properties()->children[0]; |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 5143 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5144 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5145 | std::unique_ptr<LayerImpl> scrollable_child_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5146 | LayerImpl::Create(host_impl_->active_tree(), 6); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5147 | std::unique_ptr<LayerImpl> scrollable_child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5148 | CreateScrollableLayer(7, surface_size, scrollable_child_clip.get()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5149 | scrollable_child_clip->test_properties()->AddChild( |
| 5150 | std::move(scrollable_child)); |
| 5151 | child->test_properties()->AddChild(std::move(scrollable_child_clip)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 5152 | LayerImpl* grand_child = child->test_properties()->children[0]; |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 5153 | grand_child->SetDrawsContent(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5154 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5155 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5156 | // Set new page scale on impl thread by pinching. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5157 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5158 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5159 | host_impl_->PinchGestureBegin(); |
| 5160 | host_impl_->PinchGestureUpdate(new_page_scale, gfx::Point()); |
| 5161 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5162 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5163 | DrawOneFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5164 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5165 | // Make sure all the layers are drawn with the page scale delta applied, i.e., |
| 5166 | // the page scale delta on the root layer is applied hierarchically. |
| 5167 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5168 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 5169 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5170 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5171 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5172 | EXPECT_EQ(1.f, root->DrawTransform().matrix().getDouble(0, 0)); |
| 5173 | EXPECT_EQ(1.f, root->DrawTransform().matrix().getDouble(1, 1)); |
| 5174 | EXPECT_EQ(new_page_scale, scroll->DrawTransform().matrix().getDouble(0, 0)); |
| 5175 | EXPECT_EQ(new_page_scale, scroll->DrawTransform().matrix().getDouble(1, 1)); |
| 5176 | EXPECT_EQ(new_page_scale, child->DrawTransform().matrix().getDouble(0, 0)); |
| 5177 | EXPECT_EQ(new_page_scale, child->DrawTransform().matrix().getDouble(1, 1)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5178 | EXPECT_EQ(new_page_scale, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5179 | grand_child->DrawTransform().matrix().getDouble(0, 0)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5180 | EXPECT_EQ(new_page_scale, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5181 | grand_child->DrawTransform().matrix().getDouble(1, 1)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5182 | } |
| 5183 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5184 | TEST_F(LayerTreeHostImplTest, ScrollChildAndChangePageScaleOnMainThread) { |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5185 | SetupScrollAndContentsLayers(gfx::Size(30, 30)); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 5186 | |
| 5187 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5188 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 5189 | |
| 5190 | // Make the outer scroll layer scrollable. |
| 5191 | outer_scroll->SetBounds(gfx::Size(50, 50)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5192 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 5193 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5194 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5195 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5196 | gfx::Vector2d scroll_delta(0, 10); |
| 5197 | gfx::Vector2d expected_scroll_delta(scroll_delta); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 5198 | gfx::ScrollOffset expected_max_scroll(outer_scroll->MaxScrollOffset()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5199 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5200 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5201 | InputHandler::WHEEL) |
| 5202 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5203 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5204 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5205 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5206 | float page_scale = 2.f; |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 5207 | host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5208 | page_scale); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5209 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5210 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5211 | DrawOneFrame(); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 5212 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5213 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 5214 | host_impl_->ProcessScrollDeltas(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5215 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), inner_scroll->id(), |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5216 | expected_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5217 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5218 | // The scroll range should not have changed. |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 5219 | EXPECT_EQ(outer_scroll->MaxScrollOffset(), expected_max_scroll); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5220 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5221 | // The page scale delta remains constant because the impl thread did not |
| 5222 | // scale. |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5223 | EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5224 | } |
| 5225 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5226 | TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { |
| 5227 | // Scroll a child layer beyond its maximum scroll range and make sure the |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 5228 | // parent layer isn't scrolled. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5229 | gfx::Size surface_size(10, 10); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5230 | gfx::Size content_size(20, 20); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5231 | std::unique_ptr<LayerImpl> root = |
| 5232 | LayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5233 | root->SetBounds(surface_size); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5234 | root->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5235 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5236 | CreateScrollableLayer(3, content_size, root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5237 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5238 | std::unique_ptr<LayerImpl> child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5239 | CreateScrollableLayer(2, content_size, root.get()); |
| 5240 | LayerImpl* grand_child_layer = grand_child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5241 | child->test_properties()->AddChild(std::move(grand_child)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5242 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5243 | LayerImpl* child_layer = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5244 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5245 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5246 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5247 | host_impl_->active_tree()->DidBecomeActive(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5248 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5249 | grand_child_layer->layer_tree_impl() |
| 5250 | ->property_trees() |
| 5251 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(grand_child_layer->id(), |
| 5252 | gfx::ScrollOffset(0, 5)); |
| 5253 | child_layer->layer_tree_impl() |
| 5254 | ->property_trees() |
| 5255 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(child_layer->id(), |
| 5256 | gfx::ScrollOffset(3, 0)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5257 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5258 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5259 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5260 | { |
| 5261 | gfx::Vector2d scroll_delta(-8, -7); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5262 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5263 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5264 | InputHandler::WHEEL) |
| 5265 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5266 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5267 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5268 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5269 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5270 | host_impl_->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5271 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5272 | // The grand child should have scrolled up to its limit. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5273 | LayerImpl* child = host_impl_->active_tree() |
| 5274 | ->root_layer_for_testing() |
| 5275 | ->test_properties() |
| 5276 | ->children[0]; |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 5277 | LayerImpl* grand_child = child->test_properties()->children[0]; |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5278 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 5279 | gfx::Vector2d(0, -5))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5280 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 5281 | // The child should not have scrolled. |
| 5282 | ExpectNone(*scroll_info.get(), child->id()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5283 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5284 | } |
| 5285 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5286 | TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { |
| 5287 | // Scroll a child layer beyond its maximum scroll range and make sure the |
| 5288 | // the scroll doesn't bubble up to the parent layer. |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5289 | gfx::Size surface_size(20, 20); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 5290 | gfx::Size viewport_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5291 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5292 | LayerImpl::Create(host_impl_->active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5293 | std::unique_ptr<LayerImpl> root_clip = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5294 | LayerImpl::Create(host_impl_->active_tree(), 2); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5295 | root_clip->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5296 | std::unique_ptr<LayerImpl> root_scrolling = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5297 | CreateScrollableLayer(3, surface_size, root_clip.get()); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 5298 | root_scrolling->test_properties()->is_container_for_fixed_position_layers = |
| 5299 | true; |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5300 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5301 | std::unique_ptr<LayerImpl> grand_child = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5302 | CreateScrollableLayer(5, surface_size, root_clip.get()); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5303 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5304 | std::unique_ptr<LayerImpl> child = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5305 | CreateScrollableLayer(4, surface_size, root_clip.get()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5306 | LayerImpl* grand_child_layer = grand_child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5307 | child->test_properties()->AddChild(std::move(grand_child)); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5308 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5309 | LayerImpl* child_layer = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5310 | root_scrolling->test_properties()->AddChild(std::move(child)); |
| 5311 | root_clip->test_properties()->AddChild(std::move(root_scrolling)); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5312 | EXPECT_EQ(viewport_size, root_clip->bounds()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5313 | root_ptr->test_properties()->AddChild(std::move(root_clip)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5314 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5315 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5316 | host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3, |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 5317 | Layer::INVALID_ID); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5318 | host_impl_->active_tree()->DidBecomeActive(); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 5319 | host_impl_->SetViewportSize(viewport_size); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5320 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5321 | grand_child_layer->layer_tree_impl() |
| 5322 | ->property_trees() |
| 5323 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(grand_child_layer->id(), |
| 5324 | gfx::ScrollOffset(0, 2)); |
| 5325 | child_layer->layer_tree_impl() |
| 5326 | ->property_trees() |
| 5327 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(child_layer->id(), |
| 5328 | gfx::ScrollOffset(0, 3)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5329 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5330 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5331 | { |
| 5332 | gfx::Vector2d scroll_delta(0, -10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5333 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5334 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5335 | InputHandler::NON_BUBBLING_GESTURE) |
| 5336 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5337 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5338 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5339 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5340 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5341 | host_impl_->ProcessScrollDeltas(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5342 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5343 | // The grand child should have scrolled up to its limit. |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5344 | LayerImpl* child = host_impl_->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5345 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 5346 | ->test_properties() |
| 5347 | ->children[0] |
| 5348 | ->test_properties() |
| 5349 | ->children[0] |
| 5350 | ->test_properties() |
| 5351 | ->children[0]; |
| 5352 | LayerImpl* grand_child = child->test_properties()->children[0]; |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5353 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 5354 | gfx::Vector2d(0, -2))); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5355 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5356 | // The child should not have scrolled. |
| 5357 | ExpectNone(*scroll_info.get(), child->id()); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5358 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5359 | // The next time we scroll we should only scroll the parent. |
| 5360 | scroll_delta = gfx::Vector2d(0, -3); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5361 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5362 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5363 | InputHandler::NON_BUBBLING_GESTURE) |
| 5364 | .thread); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5365 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5366 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5367 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5368 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5369 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5370 | scroll_info = host_impl_->ProcessScrollDeltas(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5371 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5372 | // The child should have scrolled up to its limit. |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5373 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child->id(), |
| 5374 | gfx::Vector2d(0, -3))); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5375 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5376 | // The grand child should not have scrolled. |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5377 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 5378 | gfx::Vector2d(0, -2))); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5379 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5380 | // After scrolling the parent, another scroll on the opposite direction |
| 5381 | // should still scroll the child. |
| 5382 | scroll_delta = gfx::Vector2d(0, 7); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5383 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5384 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5385 | InputHandler::NON_BUBBLING_GESTURE) |
| 5386 | .thread); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5387 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5388 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5389 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5390 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5391 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5392 | scroll_info = host_impl_->ProcessScrollDeltas(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5393 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5394 | // The grand child should have scrolled. |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5395 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 5396 | gfx::Vector2d(0, 5))); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5397 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5398 | // The child should not have scrolled. |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5399 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child->id(), |
| 5400 | gfx::Vector2d(0, -3))); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 5401 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5402 | // Scrolling should be adjusted from viewport space. |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 5403 | host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 2.f, 2.f); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 5404 | host_impl_->active_tree()->SetPageScaleOnActiveTree(2.f); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 5405 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5406 | scroll_delta = gfx::Vector2d(0, -2); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5407 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5408 | host_impl_->ScrollBegin(BeginState(gfx::Point(1, 1)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5409 | InputHandler::NON_BUBBLING_GESTURE) |
| 5410 | .thread); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5411 | EXPECT_EQ(grand_child, host_impl_->CurrentlyScrollingLayer()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5412 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5413 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 5414 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5415 | scroll_info = host_impl_->ProcessScrollDeltas(); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 5416 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5417 | // Should have scrolled by half the amount in layer space (5 - 2/2) |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5418 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 5419 | gfx::Vector2d(0, 4))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5420 | } |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5421 | } |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5422 | TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) { |
| 5423 | // When we try to scroll a non-scrollable child layer, the scroll delta |
| 5424 | // should be applied to one of its ancestors if possible. |
| 5425 | gfx::Size surface_size(10, 10); |
| 5426 | gfx::Size content_size(20, 20); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5427 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5428 | LayerImpl::Create(host_impl_->active_tree(), 4); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5429 | std::unique_ptr<LayerImpl> root_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5430 | LayerImpl::Create(host_impl_->active_tree(), 3); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5431 | root_clip->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5432 | std::unique_ptr<LayerImpl> root_scroll = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5433 | CreateScrollableLayer(1, content_size, root_clip.get()); |
| 5434 | // Make 'root' the clip layer for child: since they have the same sizes the |
| 5435 | // child will have zero max_scroll_offset and scrolls will bubble. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5436 | std::unique_ptr<LayerImpl> child = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5437 | CreateScrollableLayer(2, content_size, root_scroll.get()); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 5438 | child->test_properties()->is_container_for_fixed_position_layers = true; |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5439 | root_scroll->SetBounds(content_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5440 | |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5441 | int root_scroll_id = root_scroll->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5442 | root_scroll->test_properties()->AddChild(std::move(child)); |
| 5443 | root_clip->test_properties()->AddChild(std::move(root_scroll)); |
| 5444 | root_ptr->test_properties()->AddChild(std::move(root_clip)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5445 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5446 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5447 | host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 2, |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 5448 | Layer::INVALID_ID); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5449 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5450 | host_impl_->active_tree()->DidBecomeActive(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5451 | |
| 5452 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5453 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5454 | { |
| 5455 | gfx::Vector2d scroll_delta(0, 4); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5456 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5457 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5458 | InputHandler::WHEEL) |
| 5459 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5460 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5461 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5462 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5463 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5464 | host_impl_->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5465 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5466 | // Only the root scroll should have scrolled. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5467 | ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5468 | EXPECT_TRUE( |
| 5469 | ScrollInfoContains(*scroll_info.get(), root_scroll_id, scroll_delta)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5470 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5471 | } |
| 5472 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5473 | TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { |
| 5474 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5475 | std::unique_ptr<LayerImpl> root_ptr = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5476 | LayerImpl::Create(host_impl_->active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5477 | std::unique_ptr<LayerImpl> root_clip = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5478 | LayerImpl::Create(host_impl_->active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5479 | std::unique_ptr<LayerImpl> root_scroll = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5480 | CreateScrollableLayer(3, surface_size, root_clip.get()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5481 | root_clip->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 5482 | root_scroll->test_properties()->is_container_for_fixed_position_layers = true; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5483 | root_clip->test_properties()->AddChild(std::move(root_scroll)); |
| 5484 | root_ptr->test_properties()->AddChild(std::move(root_clip)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5485 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5486 | host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3, |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 5487 | Layer::INVALID_ID); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5488 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5489 | host_impl_->active_tree()->DidBecomeActive(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5490 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 5491 | host_impl_->SetViewportSize(surface_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5492 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5493 | // Draw one frame and then immediately rebuild the layer tree to mimic a tree |
| 5494 | // synchronization. |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5495 | DrawFrame(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5496 | |
rockot | 2176f92 | 2016-06-08 19:18:32 | [diff] [blame] | 5497 | host_impl_->active_tree()->DetachLayers(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5498 | std::unique_ptr<LayerImpl> root_ptr2 = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5499 | LayerImpl::Create(host_impl_->active_tree(), 4); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5500 | std::unique_ptr<LayerImpl> root_clip2 = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5501 | LayerImpl::Create(host_impl_->active_tree(), 5); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5502 | std::unique_ptr<LayerImpl> root_scroll2 = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5503 | CreateScrollableLayer(6, surface_size, root_clip2.get()); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 5504 | root_scroll2->test_properties()->is_container_for_fixed_position_layers = |
| 5505 | true; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5506 | root_clip2->test_properties()->AddChild(std::move(root_scroll2)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5507 | root_clip2->test_properties()->force_render_surface = true; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5508 | root_ptr2->test_properties()->AddChild(std::move(root_clip2)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5509 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr2)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5510 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5511 | host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 6, |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 5512 | Layer::INVALID_ID); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5513 | host_impl_->active_tree()->DidBecomeActive(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5514 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5515 | // Scrolling should still work even though we did not draw yet. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5516 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5517 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5518 | InputHandler::WHEEL) |
| 5519 | .thread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5520 | } |
| 5521 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5522 | TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5523 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 5524 | scroll_layer->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5525 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5526 | // Rotate the root layer 90 degrees counter-clockwise about its center. |
| 5527 | gfx::Transform rotate_transform; |
| 5528 | rotate_transform.Rotate(-90.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5529 | host_impl_->active_tree() |
| 5530 | ->root_layer_for_testing() |
| 5531 | ->test_properties() |
| 5532 | ->transform = rotate_transform; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5533 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5534 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5535 | gfx::Size surface_size(50, 50); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 5536 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5537 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5538 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5539 | // Scroll to the right in screen coordinates with a gesture. |
| 5540 | gfx::Vector2d gesture_scroll_delta(10, 0); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5541 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5542 | host_impl_ |
| 5543 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 5544 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5545 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5546 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gesture_scroll_delta).get()); |
| 5547 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5548 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5549 | // The layer should have scrolled down in its local coordinates. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5550 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 5551 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5552 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), scroll_layer->id(), |
| 5553 | gfx::Vector2d(0, gesture_scroll_delta.x()))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5554 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5555 | // Reset and scroll down with the wheel. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5556 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5557 | gfx::Vector2d wheel_scroll_delta(0, 10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5558 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5559 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5560 | InputHandler::WHEEL) |
| 5561 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5562 | host_impl_->ScrollBy(UpdateState(gfx::Point(), wheel_scroll_delta).get()); |
| 5563 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5564 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5565 | // The layer should have scrolled down in its local coordinates. |
| 5566 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5567 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), scroll_layer->id(), |
| 5568 | wheel_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5569 | } |
| 5570 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5571 | TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5572 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5573 | int child_clip_layer_id = 6; |
| 5574 | int child_layer_id = 7; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5575 | float child_layer_angle = -20.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5576 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5577 | // Create a child layer that is rotated to a non-axis-aligned angle. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5578 | std::unique_ptr<LayerImpl> clip_layer = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5579 | LayerImpl::Create(host_impl_->active_tree(), child_clip_layer_id); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5580 | std::unique_ptr<LayerImpl> child = CreateScrollableLayer( |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 5581 | child_layer_id, scroll_layer->bounds(), clip_layer.get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5582 | gfx::Transform rotate_transform; |
| 5583 | rotate_transform.Translate(-50.0, -50.0); |
| 5584 | rotate_transform.Rotate(child_layer_angle); |
| 5585 | rotate_transform.Translate(50.0, 50.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5586 | clip_layer->test_properties()->transform = rotate_transform; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5587 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5588 | // Only allow vertical scrolling. |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5589 | clip_layer->SetBounds( |
| 5590 | gfx::Size(child->bounds().width(), child->bounds().height() / 2)); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5591 | // The rotation depends on the layer's transform origin, and the child layer |
| 5592 | // is a different size than the clip, so make sure the clip layer's origin |
| 5593 | // lines up over the child. |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 5594 | clip_layer->test_properties()->transform_origin = gfx::Point3F( |
| 5595 | clip_layer->bounds().width() * 0.5f, clip_layer->bounds().height(), 0.f); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5596 | LayerImpl* child_ptr = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5597 | clip_layer->test_properties()->AddChild(std::move(child)); |
| 5598 | scroll_layer->test_properties()->AddChild(std::move(clip_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5599 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5600 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5601 | gfx::Size surface_size(50, 50); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 5602 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5603 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5604 | { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5605 | // Scroll down in screen coordinates with a gesture. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5606 | gfx::Vector2d gesture_scroll_delta(0, 10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5607 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5608 | host_impl_ |
| 5609 | ->ScrollBegin(BeginState(gfx::Point(1, 1)).get(), |
| 5610 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5611 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5612 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gesture_scroll_delta).get()); |
| 5613 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5614 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5615 | // The child layer should have scrolled down in its local coordinates an |
| 5616 | // amount proportional to the angle between it and the input scroll delta. |
miletus | d799dd2 | 2015-03-19 04:23:17 | [diff] [blame] | 5617 | gfx::Vector2d expected_scroll_delta( |
miletus | 7a22175 | 2015-02-04 20:44:49 | [diff] [blame] | 5618 | 0, gesture_scroll_delta.y() * |
| 5619 | std::cos(MathUtil::Deg2Rad(child_layer_angle))); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5620 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5621 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5622 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child_layer_id, |
| 5623 | expected_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5624 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5625 | // The root scroll layer should not have scrolled, because the input delta |
| 5626 | // was close to the layer's axis of movement. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5627 | EXPECT_EQ(scroll_info->scrolls.size(), 1u); |
| 5628 | } |
| 5629 | { |
| 5630 | // Now reset and scroll the same amount horizontally. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5631 | SetScrollOffsetDelta(child_ptr, gfx::Vector2dF()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5632 | gfx::Vector2d gesture_scroll_delta(10, 0); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5633 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5634 | host_impl_ |
| 5635 | ->ScrollBegin(BeginState(gfx::Point(1, 1)).get(), |
| 5636 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5637 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5638 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gesture_scroll_delta).get()); |
| 5639 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5640 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 5641 | // The child layer shouldn't have scrolled. |
miletus | d799dd2 | 2015-03-19 04:23:17 | [diff] [blame] | 5642 | gfx::Vector2d expected_scroll_delta( |
miletus | 7a22175 | 2015-02-04 20:44:49 | [diff] [blame] | 5643 | 0, -gesture_scroll_delta.x() * |
| 5644 | std::sin(MathUtil::Deg2Rad(child_layer_angle))); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5645 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5646 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5647 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child_layer_id, |
| 5648 | expected_scroll_delta)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5649 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 5650 | // The root scroll layer shouldn't have scrolled. |
| 5651 | ExpectNone(*scroll_info.get(), scroll_layer->id()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5652 | } |
| 5653 | } |
| 5654 | |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5655 | TEST_F(LayerTreeHostImplTest, ScrollPerspectiveTransformedLayer) { |
| 5656 | // When scrolling an element with perspective, the distance scrolled |
| 5657 | // depends on the point at which the scroll begins. |
| 5658 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 5659 | int child_clip_layer_id = 6; |
| 5660 | int child_layer_id = 7; |
| 5661 | |
| 5662 | // Create a child layer that is rotated on its x axis, with perspective. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5663 | std::unique_ptr<LayerImpl> clip_layer = |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5664 | LayerImpl::Create(host_impl_->active_tree(), child_clip_layer_id); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5665 | std::unique_ptr<LayerImpl> child = CreateScrollableLayer( |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5666 | child_layer_id, scroll_layer->bounds(), clip_layer.get()); |
| 5667 | LayerImpl* child_ptr = child.get(); |
| 5668 | gfx::Transform perspective_transform; |
| 5669 | perspective_transform.Translate(-50.0, -50.0); |
| 5670 | perspective_transform.ApplyPerspectiveDepth(20); |
| 5671 | perspective_transform.RotateAboutXAxis(45); |
| 5672 | perspective_transform.Translate(50.0, 50.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5673 | clip_layer->test_properties()->transform = perspective_transform; |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5674 | |
| 5675 | clip_layer->SetBounds(gfx::Size(child_ptr->bounds().width() / 2, |
| 5676 | child_ptr->bounds().height() / 2)); |
| 5677 | // The transform depends on the layer's transform origin, and the child layer |
| 5678 | // is a different size than the clip, so make sure the clip layer's origin |
| 5679 | // lines up over the child. |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 5680 | clip_layer->test_properties()->transform_origin = gfx::Point3F( |
| 5681 | clip_layer->bounds().width(), clip_layer->bounds().height(), 0.f); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5682 | clip_layer->test_properties()->AddChild(std::move(child)); |
| 5683 | scroll_layer->test_properties()->AddChild(std::move(clip_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5684 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5685 | |
| 5686 | gfx::Size surface_size(50, 50); |
| 5687 | host_impl_->SetViewportSize(surface_size); |
| 5688 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5689 | std::unique_ptr<ScrollAndScaleSet> scroll_info; |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5690 | |
| 5691 | gfx::Vector2d gesture_scroll_deltas[4]; |
| 5692 | gesture_scroll_deltas[0] = gfx::Vector2d(4, 10); |
| 5693 | gesture_scroll_deltas[1] = gfx::Vector2d(4, 10); |
| 5694 | gesture_scroll_deltas[2] = gfx::Vector2d(10, 0); |
| 5695 | gesture_scroll_deltas[3] = gfx::Vector2d(10, 0); |
| 5696 | |
| 5697 | gfx::Vector2d expected_scroll_deltas[4]; |
| 5698 | // Perspective affects the vertical delta by a different |
| 5699 | // amount depending on the vertical position of the |viewport_point|. |
| 5700 | expected_scroll_deltas[0] = gfx::Vector2d(2, 8); |
| 5701 | expected_scroll_deltas[1] = gfx::Vector2d(1, 4); |
| 5702 | // Deltas which start with the same vertical position of the |
| 5703 | // |viewport_point| are subject to identical perspective effects. |
| 5704 | expected_scroll_deltas[2] = gfx::Vector2d(4, 0); |
| 5705 | expected_scroll_deltas[3] = gfx::Vector2d(4, 0); |
| 5706 | |
| 5707 | gfx::Point viewport_point(1, 1); |
| 5708 | |
| 5709 | // Scroll in screen coordinates with a gesture. Each scroll starts |
| 5710 | // where the previous scroll ended, but the scroll position is reset |
| 5711 | // for each scroll. |
| 5712 | for (int i = 0; i < 4; ++i) { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5713 | SetScrollOffsetDelta(child_ptr, gfx::Vector2dF()); |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5714 | DrawFrame(); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5715 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5716 | host_impl_ |
| 5717 | ->ScrollBegin(BeginState(viewport_point).get(), |
| 5718 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5719 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5720 | host_impl_->ScrollBy( |
| 5721 | UpdateState(viewport_point, gesture_scroll_deltas[i]).get()); |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5722 | viewport_point += gesture_scroll_deltas[i]; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5723 | host_impl_->ScrollEnd(EndState().get()); |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5724 | |
| 5725 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 5726 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child_layer_id, |
| 5727 | expected_scroll_deltas[i])); |
| 5728 | |
| 5729 | // The root scroll layer should not have scrolled, because the input delta |
| 5730 | // was close to the layer's axis of movement. |
| 5731 | EXPECT_EQ(scroll_info->scrolls.size(), 1u); |
| 5732 | } |
| 5733 | } |
| 5734 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5735 | TEST_F(LayerTreeHostImplTest, ScrollScaledLayer) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5736 | LayerImpl* scroll_layer = |
| 5737 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5738 | |
| 5739 | // Scale the layer to twice its normal size. |
| 5740 | int scale = 2; |
| 5741 | gfx::Transform scale_transform; |
| 5742 | scale_transform.Scale(scale, scale); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5743 | scroll_layer->test_properties()->parent->test_properties()->transform = |
| 5744 | scale_transform; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5745 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5746 | |
| 5747 | gfx::Size surface_size(50, 50); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 5748 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5749 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5750 | |
| 5751 | // Scroll down in screen coordinates with a gesture. |
| 5752 | gfx::Vector2d scroll_delta(0, 10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5753 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5754 | host_impl_ |
| 5755 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 5756 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5757 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5758 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5759 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5760 | |
| 5761 | // The layer should have scrolled down in its local coordinates, but half the |
| 5762 | // amount. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5763 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 5764 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5765 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), scroll_layer->id(), |
| 5766 | gfx::Vector2d(0, scroll_delta.y() / scale))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5767 | |
| 5768 | // Reset and scroll down with the wheel. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5769 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5770 | gfx::Vector2d wheel_scroll_delta(0, 10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5771 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5772 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5773 | InputHandler::WHEEL) |
| 5774 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5775 | host_impl_->ScrollBy(UpdateState(gfx::Point(), wheel_scroll_delta).get()); |
| 5776 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5777 | |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 5778 | // It should apply the scale factor to the scroll delta for the wheel event. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5779 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5780 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), scroll_layer->id(), |
| 5781 | wheel_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5782 | } |
| 5783 | |
[email protected] | a6d2ffe82 | 2014-08-21 10:11:39 | [diff] [blame] | 5784 | TEST_F(LayerTreeHostImplTest, ScrollViewportRounding) { |
| 5785 | int width = 332; |
| 5786 | int height = 20; |
| 5787 | int scale = 3; |
| 5788 | SetupScrollAndContentsLayers(gfx::Size(width, height)); |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 5789 | host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( |
| 5790 | gfx::Size(width * scale - 1, height * scale)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5791 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 5792 | |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 5793 | host_impl_->active_tree()->SetDeviceScaleFactor(scale); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 5794 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
[email protected] | a6d2ffe82 | 2014-08-21 10:11:39 | [diff] [blame] | 5795 | |
| 5796 | LayerImpl* inner_viewport_scroll_layer = |
| 5797 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5798 | EXPECT_EQ(gfx::ScrollOffset(0, 0), |
[email protected] | a6d2ffe82 | 2014-08-21 10:11:39 | [diff] [blame] | 5799 | inner_viewport_scroll_layer->MaxScrollOffset()); |
| 5800 | } |
| 5801 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5802 | class TestInputHandlerClient : public InputHandlerClient { |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5803 | public: |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5804 | TestInputHandlerClient() |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 5805 | : page_scale_factor_(0.f), |
| 5806 | min_page_scale_factor_(-1.f), |
danakj | e9f830c | 2015-09-09 21:36:16 | [diff] [blame] | 5807 | max_page_scale_factor_(-1.f) {} |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5808 | ~TestInputHandlerClient() override {} |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5809 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5810 | // InputHandlerClient implementation. |
| 5811 | void WillShutdown() override {} |
| 5812 | void Animate(base::TimeTicks time) override {} |
| 5813 | void MainThreadHasStoppedFlinging() override {} |
| 5814 | void ReconcileElasticOverscrollAndRootScroll() override {} |
| 5815 | void UpdateRootLayerStateForSynchronousInputHandler( |
| 5816 | const gfx::ScrollOffset& total_scroll_offset, |
| 5817 | const gfx::ScrollOffset& max_scroll_offset, |
| 5818 | const gfx::SizeF& scrollable_size, |
| 5819 | float page_scale_factor, |
| 5820 | float min_page_scale_factor, |
| 5821 | float max_page_scale_factor) override { |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 5822 | DCHECK(total_scroll_offset.x() <= max_scroll_offset.x()); |
| 5823 | DCHECK(total_scroll_offset.y() <= max_scroll_offset.y()); |
| 5824 | last_set_scroll_offset_ = total_scroll_offset; |
| 5825 | max_scroll_offset_ = max_scroll_offset; |
| 5826 | scrollable_size_ = scrollable_size; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5827 | page_scale_factor_ = page_scale_factor; |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 5828 | min_page_scale_factor_ = min_page_scale_factor; |
| 5829 | max_page_scale_factor_ = max_page_scale_factor; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5830 | } |
| 5831 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5832 | gfx::ScrollOffset last_set_scroll_offset() { |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5833 | return last_set_scroll_offset_; |
| 5834 | } |
| 5835 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5836 | gfx::ScrollOffset max_scroll_offset() const { |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5837 | return max_scroll_offset_; |
| 5838 | } |
| 5839 | |
| 5840 | gfx::SizeF scrollable_size() const { |
| 5841 | return scrollable_size_; |
| 5842 | } |
| 5843 | |
| 5844 | float page_scale_factor() const { |
| 5845 | return page_scale_factor_; |
| 5846 | } |
| 5847 | |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 5848 | float min_page_scale_factor() const { |
| 5849 | return min_page_scale_factor_; |
| 5850 | } |
| 5851 | |
| 5852 | float max_page_scale_factor() const { |
| 5853 | return max_page_scale_factor_; |
| 5854 | } |
| 5855 | |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5856 | private: |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5857 | gfx::ScrollOffset last_set_scroll_offset_; |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5858 | gfx::ScrollOffset max_scroll_offset_; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5859 | gfx::SizeF scrollable_size_; |
| 5860 | float page_scale_factor_; |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 5861 | float min_page_scale_factor_; |
| 5862 | float max_page_scale_factor_; |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5863 | }; |
| 5864 | |
| 5865 | TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5866 | TestInputHandlerClient scroll_watcher; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5867 | host_impl_->SetViewportSize(gfx::Size(10, 20)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5868 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 5869 | LayerImpl* clip_layer = |
| 5870 | scroll_layer->test_properties()->parent->test_properties()->parent; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5871 | clip_layer->SetBounds(gfx::Size(10, 20)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5872 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5873 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5874 | host_impl_->BindToClient(&scroll_watcher); |
| 5875 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5876 | gfx::Vector2dF initial_scroll_delta(10.f, 10.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5877 | scroll_layer->layer_tree_impl() |
| 5878 | ->property_trees() |
| 5879 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 5880 | gfx::ScrollOffset()); |
| 5881 | SetScrollOffsetDelta(scroll_layer, initial_scroll_delta); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5882 | |
| 5883 | EXPECT_EQ(gfx::ScrollOffset(), scroll_watcher.last_set_scroll_offset()); |
| 5884 | |
| 5885 | // Requesting an update results in the current scroll offset being set. |
| 5886 | host_impl_->RequestUpdateForSynchronousInputHandler(); |
| 5887 | EXPECT_EQ(gfx::ScrollOffset(initial_scroll_delta), |
| 5888 | scroll_watcher.last_set_scroll_offset()); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5889 | |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 5890 | // Setting the delegate results in the scrollable_size, max_scroll_offset, |
| 5891 | // page_scale_factor and {min|max}_page_scale_factor being set. |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5892 | EXPECT_EQ(gfx::SizeF(100, 100), scroll_watcher.scrollable_size()); |
| 5893 | EXPECT_EQ(gfx::ScrollOffset(90, 80), scroll_watcher.max_scroll_offset()); |
| 5894 | EXPECT_EQ(1.f, scroll_watcher.page_scale_factor()); |
| 5895 | EXPECT_EQ(1.f, scroll_watcher.min_page_scale_factor()); |
| 5896 | EXPECT_EQ(1.f, scroll_watcher.max_page_scale_factor()); |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5897 | |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 5898 | // Put a page scale on the tree. |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 5899 | host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 0.5f, 4.f); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5900 | EXPECT_EQ(1.f, scroll_watcher.page_scale_factor()); |
| 5901 | EXPECT_EQ(1.f, scroll_watcher.min_page_scale_factor()); |
| 5902 | EXPECT_EQ(1.f, scroll_watcher.max_page_scale_factor()); |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 5903 | // Activation will update the delegate. |
| 5904 | host_impl_->ActivateSyncTree(); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5905 | EXPECT_EQ(2.f, scroll_watcher.page_scale_factor()); |
| 5906 | EXPECT_EQ(.5f, scroll_watcher.min_page_scale_factor()); |
| 5907 | EXPECT_EQ(4.f, scroll_watcher.max_page_scale_factor()); |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 5908 | |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 5909 | // Animating page scale can change the root offset, so it should update the |
danakj | 492344054 | 2015-10-29 19:34:53 | [diff] [blame] | 5910 | // delegate. Also resets the page scale to 1 for the rest of the test. |
| 5911 | host_impl_->LayerTreeHostImpl::StartPageScaleAnimation( |
| 5912 | gfx::Vector2d(0, 0), false, 1.f, base::TimeDelta()); |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 5913 | host_impl_->Animate(); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5914 | EXPECT_EQ(1.f, scroll_watcher.page_scale_factor()); |
| 5915 | EXPECT_EQ(.5f, scroll_watcher.min_page_scale_factor()); |
| 5916 | EXPECT_EQ(4.f, scroll_watcher.max_page_scale_factor()); |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5917 | |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 5918 | // The pinch gesture doesn't put the delegate into a state where the scroll |
| 5919 | // offset is outside of the scroll range. (this is verified by DCHECKs in the |
| 5920 | // delegate). |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5921 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5922 | InputHandler::TOUCHSCREEN); |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 5923 | host_impl_->PinchGestureBegin(); |
| 5924 | host_impl_->PinchGestureUpdate(2.f, gfx::Point()); |
| 5925 | host_impl_->PinchGestureUpdate(.5f, gfx::Point()); |
| 5926 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5927 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 5928 | |
danakj | 0481b57 | 2015-09-10 01:18:01 | [diff] [blame] | 5929 | // Scrolling should be relative to the offset as given by the delegate. |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5930 | gfx::Vector2dF scroll_delta(0.f, 10.f); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5931 | gfx::ScrollOffset current_offset(7.f, 8.f); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5932 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5933 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5934 | host_impl_ |
| 5935 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 5936 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5937 | .thread); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5938 | host_impl_->SetSynchronousInputHandlerRootScrollOffset(current_offset); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5939 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5940 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5941 | EXPECT_EQ(ScrollOffsetWithDelta(current_offset, scroll_delta), |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5942 | scroll_watcher.last_set_scroll_offset()); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5943 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5944 | current_offset = gfx::ScrollOffset(42.f, 41.f); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5945 | host_impl_->SetSynchronousInputHandlerRootScrollOffset(current_offset); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5946 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5947 | EXPECT_EQ(current_offset + gfx::ScrollOffset(scroll_delta), |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5948 | scroll_watcher.last_set_scroll_offset()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5949 | host_impl_->ScrollEnd(EndState().get()); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5950 | host_impl_->SetSynchronousInputHandlerRootScrollOffset(gfx::ScrollOffset()); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5951 | |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 5952 | // Forces a full tree synchronization and ensures that the scroll delegate |
| 5953 | // sees the correct size of the new tree. |
| 5954 | gfx::Size new_size(42, 24); |
| 5955 | host_impl_->CreatePendingTree(); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 5956 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 5957 | CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5958 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
[email protected] | fc20d14 | 2014-07-01 00:49:15 | [diff] [blame] | 5959 | host_impl_->ActivateSyncTree(); |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 5960 | EXPECT_EQ(gfx::SizeF(new_size), scroll_watcher.scrollable_size()); |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 5961 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5962 | // Tear down the LayerTreeHostImpl before the InputHandlerClient. |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 5963 | host_impl_->ReleaseOutputSurface(); |
| 5964 | host_impl_ = nullptr; |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5965 | } |
| 5966 | |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 5967 | void CheckLayerScrollDelta(LayerImpl* layer, gfx::Vector2dF scroll_delta) { |
| 5968 | const gfx::Transform target_space_transform = |
| 5969 | layer->draw_properties().target_space_transform; |
| 5970 | EXPECT_TRUE(target_space_transform.IsScaleOrTranslation()); |
| 5971 | gfx::Point translated_point; |
| 5972 | target_space_transform.TransformPoint(&translated_point); |
| 5973 | gfx::Point expected_point = gfx::Point() - ToRoundedVector2d(scroll_delta); |
| 5974 | EXPECT_EQ(expected_point.ToString(), translated_point.ToString()); |
| 5975 | } |
| 5976 | |
| 5977 | TEST_F(LayerTreeHostImplTest, |
| 5978 | ExternalRootLayerScrollOffsetDelegationReflectedInNextDraw) { |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 5979 | host_impl_->SetViewportSize(gfx::Size(10, 20)); |
| 5980 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 5981 | LayerImpl* clip_layer = |
| 5982 | scroll_layer->test_properties()->parent->test_properties()->parent; |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 5983 | clip_layer->SetBounds(gfx::Size(10, 20)); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 5984 | scroll_layer->SetDrawsContent(true); |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 5985 | |
| 5986 | // Draw first frame to clear any pending draws and check scroll. |
| 5987 | DrawFrame(); |
| 5988 | CheckLayerScrollDelta(scroll_layer, gfx::Vector2dF(0.f, 0.f)); |
| 5989 | EXPECT_FALSE(host_impl_->active_tree()->needs_update_draw_properties()); |
| 5990 | |
| 5991 | // Set external scroll delta on delegate and notify LayerTreeHost. |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5992 | gfx::ScrollOffset scroll_offset(10.f, 10.f); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5993 | host_impl_->SetSynchronousInputHandlerRootScrollOffset(scroll_offset); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5994 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 5995 | |
| 5996 | // Check scroll delta reflected in layer. |
boliu | 7d5dbab | 2014-10-10 20:05:47 | [diff] [blame] | 5997 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5998 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 5999 | host_impl_->DrawLayers(&frame); |
boliu | 7d5dbab | 2014-10-10 20:05:47 | [diff] [blame] | 6000 | host_impl_->DidDrawAllLayers(frame); |
| 6001 | EXPECT_FALSE(frame.has_no_damage); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 6002 | CheckLayerScrollDelta(scroll_layer, ScrollOffsetToVector2dF(scroll_offset)); |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 6003 | } |
| 6004 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6005 | TEST_F(LayerTreeHostImplTest, OverscrollRoot) { |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6006 | InputHandlerScrollResult scroll_result; |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6007 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6008 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6009 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6010 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 6011 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6012 | DrawFrame(); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6013 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6014 | |
| 6015 | // In-bounds scrolling does not affect overscroll. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6016 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6017 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6018 | InputHandler::WHEEL) |
| 6019 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6020 | scroll_result = host_impl_->ScrollBy( |
| 6021 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6022 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6023 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 6024 | EXPECT_EQ(gfx::Vector2dF(), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6025 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6026 | |
| 6027 | // Overscroll events are reflected immediately. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6028 | scroll_result = host_impl_->ScrollBy( |
| 6029 | UpdateState(gfx::Point(), gfx::Vector2d(0, 50)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6030 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6031 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6032 | EXPECT_EQ(gfx::Vector2dF(0, 10), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6033 | EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6034 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6035 | host_impl_->accumulated_root_overscroll()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6036 | |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 6037 | // In-bounds scrolling resets accumulated overscroll for the scrolled axes. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6038 | scroll_result = host_impl_->ScrollBy( |
| 6039 | UpdateState(gfx::Point(), gfx::Vector2d(0, -50)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6040 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6041 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 6042 | EXPECT_EQ(gfx::Vector2dF(), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6043 | EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6044 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6045 | host_impl_->accumulated_root_overscroll()); |
| 6046 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6047 | scroll_result = host_impl_->ScrollBy( |
| 6048 | UpdateState(gfx::Point(), gfx::Vector2d(0, -10)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6049 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6050 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6051 | EXPECT_EQ(gfx::Vector2dF(0, -10), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6052 | EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6053 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6054 | host_impl_->accumulated_root_overscroll()); |
| 6055 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6056 | scroll_result = host_impl_->ScrollBy( |
| 6057 | UpdateState(gfx::Point(), gfx::Vector2d(10, 0)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6058 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6059 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 6060 | EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_result.unused_scroll_delta); |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 6061 | EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6062 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6063 | host_impl_->accumulated_root_overscroll()); |
| 6064 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6065 | scroll_result = host_impl_->ScrollBy( |
| 6066 | UpdateState(gfx::Point(), gfx::Vector2d(-15, 0)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6067 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6068 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6069 | EXPECT_EQ(gfx::Vector2dF(-5, 0), scroll_result.unused_scroll_delta); |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 6070 | EXPECT_EQ(gfx::Vector2dF(-5, -10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6071 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6072 | host_impl_->accumulated_root_overscroll()); |
| 6073 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6074 | scroll_result = host_impl_->ScrollBy( |
| 6075 | UpdateState(gfx::Point(), gfx::Vector2d(0, 60)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6076 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6077 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6078 | EXPECT_EQ(gfx::Vector2dF(0, 10), scroll_result.unused_scroll_delta); |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 6079 | EXPECT_EQ(gfx::Vector2dF(-5, 10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6080 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6081 | host_impl_->accumulated_root_overscroll()); |
| 6082 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6083 | scroll_result = host_impl_->ScrollBy( |
| 6084 | UpdateState(gfx::Point(), gfx::Vector2d(10, -60)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6085 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6086 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6087 | EXPECT_EQ(gfx::Vector2dF(0, -10), scroll_result.unused_scroll_delta); |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 6088 | EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6089 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6090 | host_impl_->accumulated_root_overscroll()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6091 | |
| 6092 | // Overscroll accumulates within the scope of ScrollBegin/ScrollEnd as long |
| 6093 | // as no scroll occurs. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6094 | scroll_result = host_impl_->ScrollBy( |
| 6095 | UpdateState(gfx::Point(), gfx::Vector2d(0, -20)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6096 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6097 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6098 | EXPECT_EQ(gfx::Vector2dF(0, -20), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6099 | EXPECT_EQ(gfx::Vector2dF(0, -30), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6100 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6101 | host_impl_->accumulated_root_overscroll()); |
| 6102 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6103 | scroll_result = host_impl_->ScrollBy( |
| 6104 | UpdateState(gfx::Point(), gfx::Vector2d(0, -20)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6105 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6106 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6107 | EXPECT_EQ(gfx::Vector2dF(0, -20), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6108 | EXPECT_EQ(gfx::Vector2dF(0, -50), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6109 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6110 | host_impl_->accumulated_root_overscroll()); |
| 6111 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6112 | // Overscroll resets on valid scroll. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6113 | scroll_result = host_impl_->ScrollBy( |
| 6114 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6115 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6116 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 6117 | EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6118 | EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6119 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6120 | host_impl_->accumulated_root_overscroll()); |
| 6121 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6122 | scroll_result = host_impl_->ScrollBy( |
| 6123 | UpdateState(gfx::Point(), gfx::Vector2d(0, -20)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6124 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6125 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6126 | EXPECT_EQ(gfx::Vector2dF(0, -10), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6127 | EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6128 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6129 | host_impl_->accumulated_root_overscroll()); |
| 6130 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6131 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6132 | } |
| 6133 | |
| 6134 | |
| 6135 | TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { |
| 6136 | // Scroll child layers beyond their maximum scroll range and make sure root |
| 6137 | // overscroll does not accumulate. |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6138 | InputHandlerScrollResult scroll_result; |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6139 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6140 | std::unique_ptr<LayerImpl> root_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6141 | LayerImpl::Create(host_impl_->active_tree(), 4); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6142 | root_clip->test_properties()->force_render_surface = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6143 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6144 | std::unique_ptr<LayerImpl> root = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6145 | CreateScrollableLayer(1, surface_size, root_clip.get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6146 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6147 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6148 | CreateScrollableLayer(3, surface_size, root_clip.get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6149 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6150 | std::unique_ptr<LayerImpl> child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6151 | CreateScrollableLayer(2, surface_size, root_clip.get()); |
| 6152 | LayerImpl* grand_child_layer = grand_child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6153 | child->test_properties()->AddChild(std::move(grand_child)); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6154 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6155 | LayerImpl* child_layer = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6156 | root->test_properties()->AddChild(std::move(child)); |
| 6157 | root_clip->test_properties()->AddChild(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6158 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_clip)); |
| 6159 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6160 | host_impl_->active_tree()->DidBecomeActive(); |
| 6161 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6162 | child_layer->layer_tree_impl() |
| 6163 | ->property_trees() |
| 6164 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(child_layer->id(), |
| 6165 | gfx::ScrollOffset(0, 3)); |
| 6166 | grand_child_layer->layer_tree_impl() |
| 6167 | ->property_trees() |
| 6168 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(grand_child_layer->id(), |
| 6169 | gfx::ScrollOffset(0, 2)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6170 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6171 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6172 | DrawFrame(); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6173 | { |
| 6174 | gfx::Vector2d scroll_delta(0, -10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6175 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6176 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6177 | InputHandler::NON_BUBBLING_GESTURE) |
| 6178 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6179 | scroll_result = |
| 6180 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6181 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6182 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6183 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6184 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6185 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6186 | // The next time we scroll we should only scroll the parent, but overscroll |
| 6187 | // should still not reach the root layer. |
| 6188 | scroll_delta = gfx::Vector2d(0, -30); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6189 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6190 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6191 | InputHandler::NON_BUBBLING_GESTURE) |
| 6192 | .thread); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6193 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6194 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6195 | scroll_result = |
| 6196 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6197 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6198 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6199 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_layer); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6200 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6201 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6202 | |
| 6203 | // After scrolling the parent, another scroll on the opposite direction |
[email protected] | 635b0e9 | 2014-04-02 21:48:01 | [diff] [blame] | 6204 | // should scroll the child. |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6205 | scroll_delta = gfx::Vector2d(0, 70); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6206 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6207 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6208 | InputHandler::NON_BUBBLING_GESTURE) |
| 6209 | .thread); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6210 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6211 | scroll_result = |
| 6212 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6213 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6214 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6215 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6216 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6217 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6218 | } |
| 6219 | } |
| 6220 | |
| 6221 | TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { |
| 6222 | // When we try to scroll a non-scrollable child layer, the scroll delta |
| 6223 | // should be applied to one of its ancestors if possible. Overscroll should |
| 6224 | // be reflected only when it has bubbled up to the root scrolling layer. |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6225 | InputHandlerScrollResult scroll_result; |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 6226 | SetupScrollAndContentsLayers(gfx::Size(20, 20)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6227 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6228 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6229 | DrawFrame(); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6230 | { |
| 6231 | gfx::Vector2d scroll_delta(0, 8); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6232 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6233 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6234 | InputHandler::WHEEL) |
| 6235 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6236 | scroll_result = |
| 6237 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6238 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6239 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6240 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6241 | scroll_result = |
| 6242 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6243 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6244 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6245 | EXPECT_EQ(gfx::Vector2dF(0, 6), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6246 | scroll_result = |
| 6247 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6248 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6249 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6250 | EXPECT_EQ(gfx::Vector2dF(0, 14), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6251 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6252 | } |
| 6253 | } |
| 6254 | |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6255 | TEST_F(LayerTreeHostImplTest, OverscrollAlways) { |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6256 | InputHandlerScrollResult scroll_result; |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 6257 | LayerTreeSettings settings = DefaultSettings(); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6258 | CreateHostImpl(settings, CreateOutputSurface()); |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6259 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6260 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 6261 | LayerImpl* clip_layer = |
| 6262 | scroll_layer->test_properties()->parent->test_properties()->parent; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6263 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6264 | clip_layer->SetBounds(gfx::Size(50, 50)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6265 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6266 | |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6267 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 6268 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6269 | DrawFrame(); |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6270 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6271 | |
| 6272 | // Even though the layer can't scroll the overscroll still happens. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6273 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6274 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6275 | InputHandler::WHEEL) |
| 6276 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6277 | scroll_result = host_impl_->ScrollBy( |
| 6278 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6279 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6280 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6281 | EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6282 | } |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6283 | |
[email protected] | 5b8a865c | 2014-04-03 00:35:51 | [diff] [blame] | 6284 | TEST_F(LayerTreeHostImplTest, NoOverscrollWhenNotAtEdge) { |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6285 | InputHandlerScrollResult scroll_result; |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 6286 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6287 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6288 | |
[email protected] | 485a42dc | 2014-03-26 22:44:34 | [diff] [blame] | 6289 | DrawFrame(); |
| 6290 | { |
[email protected] | 5b8a865c | 2014-04-03 00:35:51 | [diff] [blame] | 6291 | // Edge glow effect should be applicable only upon reaching Edges |
| 6292 | // of the content. unnecessary glow effect calls shouldn't be |
| 6293 | // called while scrolling up without reaching the edge of the content. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6294 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6295 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6296 | InputHandler::WHEEL) |
| 6297 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6298 | scroll_result = host_impl_->ScrollBy( |
| 6299 | UpdateState(gfx::Point(), gfx::Vector2dF(0, 100)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6300 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6301 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | 485a42dc | 2014-03-26 22:44:34 | [diff] [blame] | 6302 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6303 | host_impl_->accumulated_root_overscroll().ToString()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6304 | scroll_result = host_impl_->ScrollBy( |
| 6305 | UpdateState(gfx::Point(), gfx::Vector2dF(0, -2.30f)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6306 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6307 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | 485a42dc | 2014-03-26 22:44:34 | [diff] [blame] | 6308 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6309 | host_impl_->accumulated_root_overscroll().ToString()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6310 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 5b8a865c | 2014-04-03 00:35:51 | [diff] [blame] | 6311 | // unusedrootDelta should be subtracted from applied delta so that |
| 6312 | // unwanted glow effect calls are not called. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6313 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 6314 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6315 | InputHandler::NON_BUBBLING_GESTURE) |
| 6316 | .thread); |
| 6317 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 6318 | host_impl_->FlingScrollBegin().thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6319 | scroll_result = host_impl_->ScrollBy( |
| 6320 | UpdateState(gfx::Point(), gfx::Vector2dF(0, 20)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6321 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6322 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 6323 | EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0.000000f, 17.699997f), |
| 6324 | host_impl_->accumulated_root_overscroll()); |
[email protected] | 5b8a865c | 2014-04-03 00:35:51 | [diff] [blame] | 6325 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6326 | scroll_result = host_impl_->ScrollBy( |
| 6327 | UpdateState(gfx::Point(), gfx::Vector2dF(0.02f, -0.01f)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6328 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6329 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 6330 | EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0.000000f, 17.699997f), |
| 6331 | host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6332 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 9328ede | 2014-04-04 07:45:52 | [diff] [blame] | 6333 | // TestCase to check kEpsilon, which prevents minute values to trigger |
| 6334 | // gloweffect without reaching edge. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6335 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6336 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6337 | InputHandler::WHEEL) |
| 6338 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6339 | scroll_result = host_impl_->ScrollBy( |
| 6340 | UpdateState(gfx::Point(), gfx::Vector2dF(-0.12f, 0.1f)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6341 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6342 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | 9328ede | 2014-04-04 07:45:52 | [diff] [blame] | 6343 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6344 | host_impl_->accumulated_root_overscroll().ToString()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6345 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 485a42dc | 2014-03-26 22:44:34 | [diff] [blame] | 6346 | } |
| 6347 | } |
| 6348 | |
eseckler | 59eeb02 | 2016-07-05 10:45:17 | [diff] [blame] | 6349 | TEST_F(LayerTreeHostImplTest, OverscrollOnMainThread) { |
| 6350 | InputHandlerScrollResult scroll_result; |
| 6351 | LayerTreeSettings settings = DefaultSettings(); |
| 6352 | CreateHostImpl(settings, CreateOutputSurface()); |
| 6353 | |
| 6354 | const gfx::Size content_size(50, 50); |
| 6355 | const gfx::Size viewport_size(50, 50); |
| 6356 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 6357 | |
| 6358 | LayerImpl* scroll_layer = |
| 6359 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
| 6360 | scroll_layer->set_main_thread_scrolling_reasons( |
| 6361 | MainThreadScrollingReason::kThreadedScrollingDisabled); |
| 6362 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6363 | |
| 6364 | DrawFrame(); |
| 6365 | |
| 6366 | // Overscroll initiated outside layers will be handled by the main thread. |
| 6367 | EXPECT_EQ(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( |
| 6368 | gfx::PointF(0, 60))); |
| 6369 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, |
| 6370 | host_impl_ |
| 6371 | ->ScrollBegin(BeginState(gfx::Point(0, 60)).get(), |
| 6372 | InputHandler::WHEEL) |
| 6373 | .thread); |
| 6374 | |
| 6375 | // Overscroll initiated inside layers will be handled by the main thread. |
| 6376 | EXPECT_NE(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( |
| 6377 | gfx::PointF(0, 0))); |
| 6378 | EXPECT_EQ( |
| 6379 | InputHandler::SCROLL_ON_MAIN_THREAD, |
| 6380 | host_impl_ |
| 6381 | ->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), InputHandler::WHEEL) |
| 6382 | .thread); |
| 6383 | } |
| 6384 | |
bokan | bc115b4 | 2016-08-22 13:46:32 | [diff] [blame] | 6385 | // Test that scrolls chain correctly when a child scroller on the page (e.g. a |
| 6386 | // scrolling div) is set as the outer viewport. This happens in the |
| 6387 | // rootScroller proposal. |
| 6388 | TEST_F(LayerTreeHostImplTest, ScrollChainingWithReplacedOuterViewport) { |
| 6389 | const gfx::Size content_size(200, 200); |
| 6390 | const gfx::Size viewport_size(100, 100); |
| 6391 | |
| 6392 | LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 6393 | |
| 6394 | LayerImpl* content_layer = |
| 6395 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 6396 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
| 6397 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 6398 | |
| 6399 | LayerImpl* scroll_layer = nullptr; |
| 6400 | LayerImpl* child_scroll_layer = nullptr; |
| 6401 | |
| 6402 | // Initialization: Add two nested scrolling layers, simulating a scrolling div |
| 6403 | // with another scrolling div inside it. Set the outer "div" to be the outer |
| 6404 | // viewport. |
| 6405 | { |
| 6406 | std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10); |
| 6407 | clip->SetBounds(content_size); |
| 6408 | clip->SetPosition(gfx::PointF()); |
| 6409 | |
| 6410 | std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11); |
| 6411 | scroll->SetBounds(gfx::Size(400, 400)); |
| 6412 | scroll->SetScrollClipLayer(clip->id()); |
| 6413 | scroll->SetDrawsContent(true); |
| 6414 | |
| 6415 | std::unique_ptr<LayerImpl> clip2 = LayerImpl::Create(layer_tree_impl, 12); |
| 6416 | clip2->SetBounds(gfx::Size(300, 300)); |
| 6417 | clip2->SetPosition(gfx::PointF()); |
| 6418 | clip2->SetDrawsContent(true); |
| 6419 | |
| 6420 | std::unique_ptr<LayerImpl> scroll2 = LayerImpl::Create(layer_tree_impl, 13); |
| 6421 | scroll2->SetBounds(gfx::Size(500, 500)); |
| 6422 | scroll2->SetScrollClipLayer(clip2->id()); |
| 6423 | scroll2->SetDrawsContent(true); |
| 6424 | |
| 6425 | scroll_layer = scroll.get(); |
| 6426 | child_scroll_layer = scroll2.get(); |
| 6427 | |
| 6428 | clip2->test_properties()->AddChild(std::move(scroll2)); |
| 6429 | scroll->test_properties()->AddChild(std::move(clip2)); |
| 6430 | |
| 6431 | clip->test_properties()->AddChild(std::move(scroll)); |
| 6432 | content_layer->test_properties()->AddChild(std::move(clip)); |
| 6433 | layer_tree_impl->SetViewportLayersFromIds( |
| 6434 | Layer::INVALID_ID, layer_tree_impl->PageScaleLayer()->id(), |
| 6435 | inner_scroll_layer->id(), scroll_layer->id()); |
| 6436 | layer_tree_impl->BuildPropertyTreesForTesting(); |
| 6437 | } |
| 6438 | |
| 6439 | // Scroll should target the nested scrolling layer in the content and then |
| 6440 | // chain to the parent scrolling layer which is now set as the outer |
| 6441 | // viewport. The original outer viewport layer shouldn't get any scroll here. |
| 6442 | { |
| 6443 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6444 | InputHandler::TOUCHSCREEN); |
| 6445 | host_impl_->ScrollBy( |
| 6446 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(200.f, 200.f)).get()); |
| 6447 | host_impl_->ScrollEnd(EndState().get()); |
| 6448 | |
| 6449 | EXPECT_VECTOR_EQ(gfx::Vector2dF(200.f, 200.f), |
| 6450 | child_scroll_layer->CurrentScrollOffset()); |
| 6451 | |
| 6452 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6453 | InputHandler::TOUCHSCREEN); |
| 6454 | host_impl_->ScrollBy( |
| 6455 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(200.f, 200.f)).get()); |
| 6456 | host_impl_->ScrollEnd(EndState().get()); |
| 6457 | |
| 6458 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), |
| 6459 | outer_scroll_layer->CurrentScrollOffset()); |
| 6460 | |
| 6461 | EXPECT_VECTOR_EQ(gfx::Vector2dF(200.f, 200.f), |
| 6462 | scroll_layer->CurrentScrollOffset()); |
| 6463 | } |
| 6464 | |
| 6465 | // Now that the nested scrolling layers are fully scrolled, further scrolls |
| 6466 | // would normally chain up to the "outer viewport" but since we've set the |
| 6467 | // scrolling content as the outer viewport, it should stop chaining there. |
| 6468 | { |
| 6469 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6470 | InputHandler::TOUCHSCREEN); |
| 6471 | host_impl_->ScrollBy( |
| 6472 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 6473 | host_impl_->ScrollEnd(EndState().get()); |
| 6474 | |
| 6475 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), |
| 6476 | outer_scroll_layer->CurrentScrollOffset()); |
| 6477 | } |
| 6478 | |
| 6479 | // Zoom into the page by a 2X factor so that the inner viewport becomes |
| 6480 | // scrollable. |
| 6481 | float min_page_scale = 1.f, max_page_scale = 4.f; |
| 6482 | float page_scale_factor = 2.f; |
| 6483 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
| 6484 | page_scale_factor, min_page_scale, max_page_scale); |
| 6485 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
| 6486 | |
| 6487 | // Reset the parent scrolling layer (i.e. the current outer viewport) so that |
| 6488 | // we can ensure viewport scrolling works correctly. |
| 6489 | scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset(0, 0)); |
| 6490 | |
| 6491 | // Scrolling the content layer should now scroll the inner viewport first, |
| 6492 | // and then chain up to the current outer viewport (i.e. the parent scroll |
| 6493 | // layer). |
| 6494 | { |
| 6495 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6496 | InputHandler::TOUCHSCREEN); |
| 6497 | host_impl_->ScrollBy( |
| 6498 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 6499 | host_impl_->ScrollEnd(EndState().get()); |
| 6500 | |
| 6501 | EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f), |
| 6502 | inner_scroll_layer->CurrentScrollOffset()); |
| 6503 | |
| 6504 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6505 | InputHandler::TOUCHSCREEN); |
| 6506 | host_impl_->ScrollBy( |
| 6507 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 6508 | host_impl_->ScrollEnd(EndState().get()); |
| 6509 | |
| 6510 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), |
| 6511 | outer_scroll_layer->CurrentScrollOffset()); |
| 6512 | EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f), |
| 6513 | scroll_layer->CurrentScrollOffset()); |
| 6514 | } |
| 6515 | } |
| 6516 | |
eseckler | 59eeb02 | 2016-07-05 10:45:17 | [diff] [blame] | 6517 | TEST_F(LayerTreeHostImplTest, OverscrollOnImplThread) { |
| 6518 | InputHandlerScrollResult scroll_result; |
| 6519 | LayerTreeSettings settings = DefaultSettings(); |
| 6520 | CreateHostImpl(settings, CreateOutputSurface()); |
| 6521 | |
| 6522 | const gfx::Size content_size(50, 50); |
| 6523 | const gfx::Size viewport_size(50, 50); |
| 6524 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 6525 | |
| 6526 | // By default, no main thread scrolling reasons should exist. |
| 6527 | LayerImpl* scroll_layer = |
| 6528 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
| 6529 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
| 6530 | scroll_layer->main_thread_scrolling_reasons()); |
| 6531 | |
| 6532 | DrawFrame(); |
| 6533 | |
| 6534 | // Overscroll initiated outside layers will be handled by the impl thread. |
| 6535 | EXPECT_EQ(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( |
| 6536 | gfx::PointF(0, 60))); |
| 6537 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 6538 | host_impl_ |
| 6539 | ->ScrollBegin(BeginState(gfx::Point(0, 60)).get(), |
| 6540 | InputHandler::WHEEL) |
| 6541 | .thread); |
| 6542 | |
| 6543 | // Overscroll initiated inside layers will be handled by the impl thread. |
| 6544 | EXPECT_NE(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( |
| 6545 | gfx::PointF(0, 0))); |
| 6546 | EXPECT_EQ( |
| 6547 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 6548 | host_impl_ |
| 6549 | ->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), InputHandler::WHEEL) |
| 6550 | .thread); |
| 6551 | } |
| 6552 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 6553 | class BlendStateCheckLayer : public LayerImpl { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6554 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6555 | static std::unique_ptr<LayerImpl> Create( |
| 6556 | LayerTreeImpl* tree_impl, |
| 6557 | int id, |
| 6558 | ResourceProvider* resource_provider) { |
| 6559 | return base::WrapUnique( |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 6560 | new BlendStateCheckLayer(tree_impl, id, resource_provider)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6561 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6562 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 6563 | void AppendQuads(RenderPass* render_pass, |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 6564 | AppendQuadsData* append_quads_data) override { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6565 | quads_appended_ = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6566 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6567 | gfx::Rect opaque_rect; |
| 6568 | if (contents_opaque()) |
| 6569 | opaque_rect = quad_rect_; |
| 6570 | else |
| 6571 | opaque_rect = opaque_content_rect_; |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 6572 | gfx::Rect visible_quad_rect = quad_rect_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6573 | |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 6574 | SharedQuadState* shared_quad_state = |
| 6575 | render_pass->CreateAndAppendSharedQuadState(); |
[email protected] | 9be1adc | 2014-05-07 15:39:41 | [diff] [blame] | 6576 | PopulateSharedQuadState(shared_quad_state); |
| 6577 | |
[email protected] | f7030c3 | 2014-07-03 18:54:34 | [diff] [blame] | 6578 | TileDrawQuad* test_blending_draw_quad = |
| 6579 | render_pass->CreateAndAppendDrawQuad<TileDrawQuad>(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6580 | test_blending_draw_quad->SetNew(shared_quad_state, |
| 6581 | quad_rect_, |
| 6582 | opaque_rect, |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 6583 | visible_quad_rect, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6584 | resource_id_, |
| 6585 | gfx::RectF(0.f, 0.f, 1.f, 1.f), |
| 6586 | gfx::Size(1, 1), |
jackhou | 2422961 | 2014-12-13 23:41:00 | [diff] [blame] | 6587 | false, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6588 | false); |
| 6589 | test_blending_draw_quad->visible_rect = quad_visible_rect_; |
| 6590 | EXPECT_EQ(blend_, test_blending_draw_quad->ShouldDrawWithBlending()); |
| 6591 | EXPECT_EQ(has_render_surface_, !!render_surface()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6592 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6593 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6594 | void SetExpectation(bool blend, bool has_render_surface) { |
| 6595 | blend_ = blend; |
| 6596 | has_render_surface_ = has_render_surface; |
| 6597 | quads_appended_ = false; |
| 6598 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6599 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6600 | bool quads_appended() const { return quads_appended_; } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6601 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 6602 | void SetQuadRect(const gfx::Rect& rect) { quad_rect_ = rect; } |
| 6603 | void SetQuadVisibleRect(const gfx::Rect& rect) { quad_visible_rect_ = rect; } |
| 6604 | void SetOpaqueContentRect(const gfx::Rect& rect) { |
| 6605 | opaque_content_rect_ = rect; |
| 6606 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6607 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6608 | private: |
| 6609 | BlendStateCheckLayer(LayerTreeImpl* tree_impl, |
| 6610 | int id, |
| 6611 | ResourceProvider* resource_provider) |
| 6612 | : LayerImpl(tree_impl, id), |
| 6613 | blend_(false), |
| 6614 | has_render_surface_(false), |
| 6615 | quads_appended_(false), |
| 6616 | quad_rect_(5, 5, 5, 5), |
| 6617 | quad_visible_rect_(5, 5, 5, 5), |
| 6618 | resource_id_(resource_provider->CreateResource( |
| 6619 | gfx::Size(1, 1), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 6620 | ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
ccameron | b4d9236 | 2016-08-12 07:33:26 | [diff] [blame] | 6621 | RGBA_8888, |
| 6622 | gfx::ColorSpace())) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6623 | resource_provider->AllocateForTesting(resource_id_); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6624 | SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6625 | SetDrawsContent(true); |
| 6626 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6627 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6628 | bool blend_; |
| 6629 | bool has_render_surface_; |
| 6630 | bool quads_appended_; |
| 6631 | gfx::Rect quad_rect_; |
| 6632 | gfx::Rect opaque_content_rect_; |
| 6633 | gfx::Rect quad_visible_rect_; |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 6634 | ResourceId resource_id_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6635 | }; |
| 6636 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6637 | TEST_F(LayerTreeHostImplTest, BlendingOffWhenDrawingOpaqueLayers) { |
| 6638 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6639 | std::unique_ptr<LayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6640 | LayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6641 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6642 | root->SetDrawsContent(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6643 | root->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6644 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6645 | } |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6646 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6647 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6648 | root->test_properties()->AddChild(BlendStateCheckLayer::Create( |
| 6649 | host_impl_->active_tree(), 2, host_impl_->resource_provider())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6650 | BlendStateCheckLayer* layer1 = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 6651 | static_cast<BlendStateCheckLayer*>(root->test_properties()->children[0]); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6652 | layer1->SetPosition(gfx::PointF(2.f, 2.f)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6653 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6654 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6655 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6656 | // Opaque layer, drawn without blending. |
| 6657 | layer1->SetContentsOpaque(true); |
| 6658 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6659 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6660 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6661 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6662 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6663 | EXPECT_TRUE(layer1->quads_appended()); |
| 6664 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6665 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6666 | // Layer with translucent content and painting, so drawn with blending. |
| 6667 | layer1->SetContentsOpaque(false); |
| 6668 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6669 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6670 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6671 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6672 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6673 | EXPECT_TRUE(layer1->quads_appended()); |
| 6674 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6675 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6676 | // Layer with translucent opacity, drawn with blending. |
| 6677 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6678 | layer1->test_properties()->opacity = 0.5f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6679 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6680 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6681 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6682 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6683 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6684 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6685 | EXPECT_TRUE(layer1->quads_appended()); |
| 6686 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6687 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6688 | // Layer with translucent opacity and painting, drawn with blending. |
| 6689 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6690 | layer1->test_properties()->opacity = 0.5f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6691 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6692 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6693 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6694 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6695 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6696 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6697 | EXPECT_TRUE(layer1->quads_appended()); |
| 6698 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6699 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6700 | layer1->test_properties()->AddChild(BlendStateCheckLayer::Create( |
| 6701 | host_impl_->active_tree(), 3, host_impl_->resource_provider())); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 6702 | BlendStateCheckLayer* layer2 = static_cast<BlendStateCheckLayer*>( |
| 6703 | layer1->test_properties()->children[0]); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6704 | layer2->SetPosition(gfx::PointF(4.f, 4.f)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6705 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6706 | // 2 opaque layers, drawn without blending. |
| 6707 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6708 | layer1->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6709 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6710 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6711 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6712 | layer2->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6713 | layer2->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6714 | layer2->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6715 | layer2->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6716 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6717 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6718 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6719 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6720 | EXPECT_TRUE(layer1->quads_appended()); |
| 6721 | EXPECT_TRUE(layer2->quads_appended()); |
| 6722 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6723 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6724 | // Parent layer with translucent content, drawn with blending. |
| 6725 | // Child layer with opaque content, drawn without blending. |
| 6726 | layer1->SetContentsOpaque(false); |
| 6727 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6728 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6729 | layer2->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6730 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6731 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6732 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6733 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6734 | EXPECT_TRUE(layer1->quads_appended()); |
| 6735 | EXPECT_TRUE(layer2->quads_appended()); |
| 6736 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6737 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6738 | // Parent layer with translucent content but opaque painting, drawn without |
| 6739 | // blending. |
| 6740 | // Child layer with opaque content, drawn without blending. |
| 6741 | layer1->SetContentsOpaque(true); |
| 6742 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6743 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6744 | layer2->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6745 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6746 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6747 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6748 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6749 | EXPECT_TRUE(layer1->quads_appended()); |
| 6750 | EXPECT_TRUE(layer2->quads_appended()); |
| 6751 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6752 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6753 | // Parent layer with translucent opacity and opaque content. Since it has a |
| 6754 | // drawing child, it's drawn to a render surface which carries the opacity, |
| 6755 | // so it's itself drawn without blending. |
| 6756 | // Child layer with opaque content, drawn without blending (parent surface |
| 6757 | // carries the inherited opacity). |
| 6758 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6759 | layer1->test_properties()->opacity = 0.5f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6760 | layer1->NoteLayerPropertyChanged(); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6761 | layer1->test_properties()->force_render_surface = true; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6762 | layer1->SetExpectation(false, true); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6763 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6764 | layer2->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6765 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 6766 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren( |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6767 | host_impl_->active_tree()->root_layer_for_testing()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6768 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6769 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6770 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6771 | EXPECT_TRUE(layer1->quads_appended()); |
| 6772 | EXPECT_TRUE(layer2->quads_appended()); |
| 6773 | host_impl_->DidDrawAllLayers(frame); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6774 | layer1->test_properties()->force_render_surface = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6775 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6776 | // Draw again, but with child non-opaque, to make sure |
| 6777 | // layer1 not culled. |
| 6778 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6779 | layer1->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6780 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6781 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6782 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6783 | layer2->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6784 | layer2->test_properties()->opacity = 0.5f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6785 | layer2->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6786 | layer2->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6787 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6788 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6789 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6790 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6791 | EXPECT_TRUE(layer1->quads_appended()); |
| 6792 | EXPECT_TRUE(layer2->quads_appended()); |
| 6793 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6794 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6795 | // A second way of making the child non-opaque. |
| 6796 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6797 | layer1->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6798 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6799 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6800 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6801 | layer2->SetContentsOpaque(false); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6802 | layer2->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6803 | layer2->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6804 | layer2->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6805 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6806 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6807 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6808 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6809 | EXPECT_TRUE(layer1->quads_appended()); |
| 6810 | EXPECT_TRUE(layer2->quads_appended()); |
| 6811 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6812 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6813 | // And when the layer says its not opaque but is painted opaque, it is not |
| 6814 | // blended. |
| 6815 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6816 | layer1->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6817 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6818 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6819 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6820 | layer2->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6821 | layer2->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6822 | layer2->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6823 | layer2->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6824 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6825 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6826 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6827 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6828 | EXPECT_TRUE(layer1->quads_appended()); |
| 6829 | EXPECT_TRUE(layer2->quads_appended()); |
| 6830 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6831 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6832 | // Layer with partially opaque contents, drawn with blending. |
| 6833 | layer1->SetContentsOpaque(false); |
| 6834 | layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 6835 | layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 5, 5)); |
| 6836 | layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
| 6837 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6838 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6839 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6840 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6841 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6842 | EXPECT_TRUE(layer1->quads_appended()); |
| 6843 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6844 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6845 | // Layer with partially opaque contents partially culled, drawn with blending. |
| 6846 | layer1->SetContentsOpaque(false); |
| 6847 | layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 6848 | layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 5, 2)); |
| 6849 | layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
| 6850 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6851 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6852 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6853 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6854 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6855 | EXPECT_TRUE(layer1->quads_appended()); |
| 6856 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6857 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6858 | // Layer with partially opaque contents culled, drawn with blending. |
| 6859 | layer1->SetContentsOpaque(false); |
| 6860 | layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 6861 | layer1->SetQuadVisibleRect(gfx::Rect(7, 5, 3, 5)); |
| 6862 | layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
| 6863 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6864 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6865 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6866 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6867 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6868 | EXPECT_TRUE(layer1->quads_appended()); |
| 6869 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6870 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6871 | // Layer with partially opaque contents and translucent contents culled, drawn |
| 6872 | // without blending. |
| 6873 | layer1->SetContentsOpaque(false); |
| 6874 | layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 6875 | layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 2, 5)); |
| 6876 | layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
| 6877 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6878 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6879 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6880 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6881 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6882 | EXPECT_TRUE(layer1->quads_appended()); |
| 6883 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6884 | } |
| 6885 | |
sadrul | 32d1097 | 2016-07-30 05:26:21 | [diff] [blame] | 6886 | static bool MayContainVideoBitSetOnFrameData(LayerTreeHostImpl* host_impl) { |
| 6887 | host_impl->active_tree()->BuildPropertyTreesForTesting(); |
| 6888 | LayerTreeHostImpl::FrameData frame; |
| 6889 | EXPECT_EQ(DRAW_SUCCESS, host_impl->PrepareToDraw(&frame)); |
| 6890 | host_impl->DrawLayers(&frame); |
sadrul | 32d1097 | 2016-07-30 05:26:21 | [diff] [blame] | 6891 | host_impl->DidDrawAllLayers(frame); |
| 6892 | return frame.may_contain_video; |
| 6893 | } |
| 6894 | |
| 6895 | TEST_F(LayerTreeHostImplTest, MayContainVideo) { |
| 6896 | gfx::Size big_size(1000, 1000); |
| 6897 | host_impl_->SetViewportSize(big_size); |
| 6898 | |
| 6899 | int layer_id = 1; |
| 6900 | host_impl_->active_tree()->SetRootLayerForTesting( |
| 6901 | DidDrawCheckLayer::Create(host_impl_->active_tree(), layer_id++)); |
| 6902 | DidDrawCheckLayer* root = |
| 6903 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
| 6904 | |
| 6905 | root->test_properties()->AddChild( |
| 6906 | DidDrawCheckLayer::Create(host_impl_->active_tree(), layer_id++)); |
| 6907 | DidDrawCheckLayer* video_layer = |
| 6908 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children.back()); |
| 6909 | video_layer->set_may_contain_video(true); |
| 6910 | EXPECT_TRUE(MayContainVideoBitSetOnFrameData(host_impl_.get())); |
| 6911 | |
| 6912 | // Test with the video layer occluded. |
| 6913 | root->test_properties()->AddChild( |
| 6914 | DidDrawCheckLayer::Create(host_impl_->active_tree(), layer_id++)); |
| 6915 | DidDrawCheckLayer* large_layer = |
| 6916 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children.back()); |
| 6917 | large_layer->SetBounds(big_size); |
| 6918 | large_layer->SetContentsOpaque(true); |
| 6919 | EXPECT_FALSE(MayContainVideoBitSetOnFrameData(host_impl_.get())); |
| 6920 | |
| 6921 | // Remove the large layer. |
| 6922 | root->test_properties()->RemoveChild(large_layer); |
| 6923 | EXPECT_TRUE(MayContainVideoBitSetOnFrameData(host_impl_.get())); |
| 6924 | |
| 6925 | // Move the video layer so it goes beyond the root. |
| 6926 | video_layer->SetPosition(gfx::PointF(100.f, 100.f)); |
| 6927 | EXPECT_FALSE(MayContainVideoBitSetOnFrameData(host_impl_.get())); |
| 6928 | |
| 6929 | video_layer->SetPosition(gfx::PointF(0.f, 0.f)); |
| 6930 | video_layer->NoteLayerPropertyChanged(); |
| 6931 | EXPECT_TRUE(MayContainVideoBitSetOnFrameData(host_impl_.get())); |
| 6932 | } |
| 6933 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6934 | class LayerTreeHostImplViewportCoveredTest : public LayerTreeHostImplTest { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6935 | protected: |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 6936 | LayerTreeHostImplViewportCoveredTest() : |
| 6937 | gutter_quad_material_(DrawQuad::SOLID_COLOR), |
| 6938 | child_(NULL), |
| 6939 | did_activate_pending_tree_(false) {} |
| 6940 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6941 | std::unique_ptr<OutputSurface> CreateFakeOutputSurface(bool software) { |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 6942 | if (software) |
| 6943 | return FakeOutputSurface::CreateDelegatingSoftware(); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 6944 | return FakeOutputSurface::CreateDelegating3d(); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6945 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6946 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6947 | void SetupActiveTreeLayers() { |
| 6948 | host_impl_->active_tree()->set_background_color(SK_ColorGRAY); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6949 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6950 | LayerImpl::Create(host_impl_->active_tree(), 1)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6951 | host_impl_->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6952 | ->root_layer_for_testing() |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6953 | ->test_properties() |
| 6954 | ->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6955 | host_impl_->active_tree() |
| 6956 | ->root_layer_for_testing() |
| 6957 | ->test_properties() |
| 6958 | ->AddChild(BlendStateCheckLayer::Create( |
| 6959 | host_impl_->active_tree(), 2, host_impl_->resource_provider())); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 6960 | child_ = static_cast<BlendStateCheckLayer*>(host_impl_->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6961 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 6962 | ->test_properties() |
| 6963 | ->children[0]); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6964 | child_->SetExpectation(false, false); |
| 6965 | child_->SetContentsOpaque(true); |
| 6966 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6967 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6968 | // Expect no gutter rects. |
| 6969 | void TestLayerCoversFullViewport() { |
| 6970 | gfx::Rect layer_rect(viewport_size_); |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 6971 | child_->SetPosition(gfx::PointF(layer_rect.origin())); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6972 | child_->SetBounds(layer_rect.size()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6973 | child_->SetQuadRect(gfx::Rect(layer_rect.size())); |
| 6974 | child_->SetQuadVisibleRect(gfx::Rect(layer_rect.size())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6975 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6976 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6977 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6978 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6979 | ASSERT_EQ(1u, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6980 | |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 6981 | EXPECT_EQ(0u, CountGutterQuads(frame.render_passes[0]->quad_list)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6982 | EXPECT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 6983 | ValidateTextureDrawQuads(frame.render_passes[0]->quad_list); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6984 | |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 6985 | VerifyQuadsExactlyCoverViewport(frame.render_passes[0]->quad_list); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6986 | host_impl_->DidDrawAllLayers(frame); |
| 6987 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6988 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6989 | // Expect fullscreen gutter rect. |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 6990 | void SetUpEmptylayer() { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6991 | gfx::Rect layer_rect(0, 0, 0, 0); |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 6992 | child_->SetPosition(gfx::PointF(layer_rect.origin())); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6993 | child_->SetBounds(layer_rect.size()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6994 | child_->SetQuadRect(gfx::Rect(layer_rect.size())); |
| 6995 | child_->SetQuadVisibleRect(gfx::Rect(layer_rect.size())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6996 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 6997 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6998 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 6999 | void VerifyEmptyLayerRenderPasses(const RenderPassList& render_passes) { |
| 7000 | ASSERT_EQ(1u, render_passes.size()); |
| 7001 | |
| 7002 | EXPECT_EQ(1u, CountGutterQuads(render_passes[0]->quad_list)); |
| 7003 | EXPECT_EQ(1u, render_passes[0]->quad_list.size()); |
| 7004 | ValidateTextureDrawQuads(render_passes[0]->quad_list); |
| 7005 | |
| 7006 | VerifyQuadsExactlyCoverViewport(render_passes[0]->quad_list); |
| 7007 | } |
| 7008 | |
| 7009 | void TestEmptyLayer() { |
| 7010 | SetUpEmptylayer(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7011 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7012 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7013 | VerifyEmptyLayerRenderPasses(frame.render_passes); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7014 | host_impl_->DidDrawAllLayers(frame); |
| 7015 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7016 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7017 | void TestEmptyLayerWithOnDraw() { |
| 7018 | SetUpEmptylayer(); |
| 7019 | gfx::Transform identity; |
| 7020 | gfx::Rect viewport(viewport_size_); |
| 7021 | bool resourceless_software_draw = true; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 7022 | host_impl_->OnDraw(identity, viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7023 | VerifyEmptyLayerRenderPasses(last_on_draw_render_passes_); |
| 7024 | } |
| 7025 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7026 | // Expect four surrounding gutter rects. |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7027 | void SetUpLayerInMiddleOfViewport() { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7028 | gfx::Rect layer_rect(500, 500, 200, 200); |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 7029 | child_->SetPosition(gfx::PointF(layer_rect.origin())); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7030 | child_->SetBounds(layer_rect.size()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7031 | child_->SetQuadRect(gfx::Rect(layer_rect.size())); |
| 7032 | child_->SetQuadVisibleRect(gfx::Rect(layer_rect.size())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7033 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7034 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7035 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7036 | void VerifyLayerInMiddleOfViewport(const RenderPassList& render_passes) { |
| 7037 | ASSERT_EQ(1u, render_passes.size()); |
| 7038 | |
| 7039 | EXPECT_EQ(4u, CountGutterQuads(render_passes[0]->quad_list)); |
| 7040 | EXPECT_EQ(5u, render_passes[0]->quad_list.size()); |
| 7041 | ValidateTextureDrawQuads(render_passes[0]->quad_list); |
| 7042 | |
| 7043 | VerifyQuadsExactlyCoverViewport(render_passes[0]->quad_list); |
| 7044 | } |
| 7045 | |
| 7046 | void TestLayerInMiddleOfViewport() { |
| 7047 | SetUpLayerInMiddleOfViewport(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7048 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7049 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7050 | VerifyLayerInMiddleOfViewport(frame.render_passes); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7051 | host_impl_->DidDrawAllLayers(frame); |
| 7052 | } |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7053 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7054 | void TestLayerInMiddleOfViewportWithOnDraw() { |
| 7055 | SetUpLayerInMiddleOfViewport(); |
| 7056 | gfx::Transform identity; |
| 7057 | gfx::Rect viewport(viewport_size_); |
| 7058 | bool resourceless_software_draw = true; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 7059 | host_impl_->OnDraw(identity, viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7060 | VerifyLayerInMiddleOfViewport(last_on_draw_render_passes_); |
| 7061 | } |
| 7062 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7063 | // Expect no gutter rects. |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7064 | void SetUpLayerIsLargerThanViewport() { |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7065 | gfx::Rect layer_rect(viewport_size_.width() + 10, |
| 7066 | viewport_size_.height() + 10); |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 7067 | child_->SetPosition(gfx::PointF(layer_rect.origin())); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7068 | child_->SetBounds(layer_rect.size()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7069 | child_->SetQuadRect(gfx::Rect(layer_rect.size())); |
| 7070 | child_->SetQuadVisibleRect(gfx::Rect(layer_rect.size())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7071 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7072 | } |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7073 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7074 | void VerifyLayerIsLargerThanViewport(const RenderPassList& render_passes) { |
| 7075 | ASSERT_EQ(1u, render_passes.size()); |
| 7076 | |
| 7077 | EXPECT_EQ(0u, CountGutterQuads(render_passes[0]->quad_list)); |
| 7078 | EXPECT_EQ(1u, render_passes[0]->quad_list.size()); |
| 7079 | ValidateTextureDrawQuads(render_passes[0]->quad_list); |
| 7080 | } |
| 7081 | |
| 7082 | void TestLayerIsLargerThanViewport() { |
| 7083 | SetUpLayerIsLargerThanViewport(); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7084 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7085 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7086 | VerifyLayerIsLargerThanViewport(frame.render_passes); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7087 | host_impl_->DidDrawAllLayers(frame); |
| 7088 | } |
| 7089 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7090 | void TestLayerIsLargerThanViewportWithOnDraw() { |
| 7091 | SetUpLayerIsLargerThanViewport(); |
| 7092 | gfx::Transform identity; |
| 7093 | gfx::Rect viewport(viewport_size_); |
| 7094 | bool resourceless_software_draw = true; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 7095 | host_impl_->OnDraw(identity, viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7096 | VerifyLayerIsLargerThanViewport(last_on_draw_render_passes_); |
| 7097 | } |
| 7098 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7099 | void DidActivateSyncTree() override { did_activate_pending_tree_ = true; } |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7100 | |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7101 | void set_gutter_quad_material(DrawQuad::Material material) { |
| 7102 | gutter_quad_material_ = material; |
| 7103 | } |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 7104 | void set_gutter_texture_size(const gfx::Size& gutter_texture_size) { |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7105 | gutter_texture_size_ = gutter_texture_size; |
| 7106 | } |
| 7107 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7108 | protected: |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7109 | size_t CountGutterQuads(const QuadList& quad_list) { |
| 7110 | size_t num_gutter_quads = 0; |
vmpstr | a2e8943 | 2016-07-20 02:05:34 | [diff] [blame] | 7111 | for (auto* quad : quad_list) { |
weiliangc | 48805fce | 2014-10-29 20:30:12 | [diff] [blame] | 7112 | num_gutter_quads += (quad->material == gutter_quad_material_) ? 1 : 0; |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7113 | } |
| 7114 | return num_gutter_quads; |
| 7115 | } |
| 7116 | |
| 7117 | void VerifyQuadsExactlyCoverViewport(const QuadList& quad_list) { |
| 7118 | LayerTestCommon::VerifyQuadsExactlyCoverRect( |
| 7119 | quad_list, gfx::Rect(DipSizeToPixelSize(viewport_size_))); |
| 7120 | } |
| 7121 | |
| 7122 | // Make sure that the texture coordinates match their expectations. |
| 7123 | void ValidateTextureDrawQuads(const QuadList& quad_list) { |
vmpstr | a2e8943 | 2016-07-20 02:05:34 | [diff] [blame] | 7124 | for (auto* quad : quad_list) { |
weiliangc | 48805fce | 2014-10-29 20:30:12 | [diff] [blame] | 7125 | if (quad->material != DrawQuad::TEXTURE_CONTENT) |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7126 | continue; |
weiliangc | 48805fce | 2014-10-29 20:30:12 | [diff] [blame] | 7127 | const TextureDrawQuad* texture_quad = TextureDrawQuad::MaterialCast(quad); |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 7128 | gfx::SizeF gutter_texture_size_pixels = |
| 7129 | gfx::ScaleSize(gfx::SizeF(gutter_texture_size_), |
| 7130 | host_impl_->active_tree()->device_scale_factor()); |
weiliangc | 7eb7ee6 | 2014-10-07 00:04:40 | [diff] [blame] | 7131 | EXPECT_EQ(texture_quad->uv_top_left.x(), |
| 7132 | texture_quad->rect.x() / gutter_texture_size_pixels.width()); |
| 7133 | EXPECT_EQ(texture_quad->uv_top_left.y(), |
| 7134 | texture_quad->rect.y() / gutter_texture_size_pixels.height()); |
| 7135 | EXPECT_EQ( |
| 7136 | texture_quad->uv_bottom_right.x(), |
| 7137 | texture_quad->rect.right() / gutter_texture_size_pixels.width()); |
| 7138 | EXPECT_EQ( |
| 7139 | texture_quad->uv_bottom_right.y(), |
| 7140 | texture_quad->rect.bottom() / gutter_texture_size_pixels.height()); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7141 | } |
| 7142 | } |
| 7143 | |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 7144 | gfx::Size DipSizeToPixelSize(const gfx::Size& size) { |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 7145 | return gfx::ScaleToRoundedSize( |
| 7146 | size, host_impl_->active_tree()->device_scale_factor()); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7147 | } |
| 7148 | |
| 7149 | DrawQuad::Material gutter_quad_material_; |
| 7150 | gfx::Size gutter_texture_size_; |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7151 | gfx::Size viewport_size_; |
| 7152 | BlendStateCheckLayer* child_; |
| 7153 | bool did_activate_pending_tree_; |
| 7154 | }; |
| 7155 | |
| 7156 | TEST_F(LayerTreeHostImplViewportCoveredTest, ViewportCovered) { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7157 | viewport_size_ = gfx::Size(1000, 1000); |
| 7158 | |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 7159 | bool software = false; |
| 7160 | CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7161 | |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7162 | host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7163 | SetupActiveTreeLayers(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7164 | EXPECT_SCOPED(TestLayerCoversFullViewport()); |
| 7165 | EXPECT_SCOPED(TestEmptyLayer()); |
| 7166 | EXPECT_SCOPED(TestLayerInMiddleOfViewport()); |
| 7167 | EXPECT_SCOPED(TestLayerIsLargerThanViewport()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7168 | } |
| 7169 | |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7170 | TEST_F(LayerTreeHostImplViewportCoveredTest, ViewportCoveredScaled) { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7171 | viewport_size_ = gfx::Size(1000, 1000); |
| 7172 | |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 7173 | bool software = false; |
| 7174 | CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software)); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7175 | |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 7176 | host_impl_->active_tree()->SetDeviceScaleFactor(2.f); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7177 | host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); |
| 7178 | SetupActiveTreeLayers(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7179 | EXPECT_SCOPED(TestLayerCoversFullViewport()); |
| 7180 | EXPECT_SCOPED(TestEmptyLayer()); |
| 7181 | EXPECT_SCOPED(TestLayerInMiddleOfViewport()); |
| 7182 | EXPECT_SCOPED(TestLayerIsLargerThanViewport()); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7183 | } |
| 7184 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7185 | TEST_F(LayerTreeHostImplViewportCoveredTest, ActiveTreeGrowViewportInvalid) { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7186 | viewport_size_ = gfx::Size(1000, 1000); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7187 | |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 7188 | bool software = true; |
| 7189 | CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7190 | |
| 7191 | // Pending tree to force active_tree size invalid. Not used otherwise. |
| 7192 | host_impl_->CreatePendingTree(); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7193 | host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7194 | EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); |
| 7195 | |
| 7196 | SetupActiveTreeLayers(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7197 | EXPECT_SCOPED(TestEmptyLayerWithOnDraw()); |
| 7198 | EXPECT_SCOPED(TestLayerInMiddleOfViewportWithOnDraw()); |
| 7199 | EXPECT_SCOPED(TestLayerIsLargerThanViewportWithOnDraw()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7200 | } |
| 7201 | |
| 7202 | TEST_F(LayerTreeHostImplViewportCoveredTest, ActiveTreeShrinkViewportInvalid) { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7203 | viewport_size_ = gfx::Size(1000, 1000); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7204 | |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 7205 | bool software = true; |
| 7206 | CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7207 | |
| 7208 | // Set larger viewport and activate it to active tree. |
| 7209 | host_impl_->CreatePendingTree(); |
| 7210 | gfx::Size larger_viewport(viewport_size_.width() + 100, |
| 7211 | viewport_size_.height() + 100); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7212 | host_impl_->SetViewportSize(DipSizeToPixelSize(larger_viewport)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7213 | EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); |
[email protected] | fc20d14 | 2014-07-01 00:49:15 | [diff] [blame] | 7214 | host_impl_->ActivateSyncTree(); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7215 | EXPECT_TRUE(did_activate_pending_tree_); |
| 7216 | EXPECT_FALSE(host_impl_->active_tree()->ViewportSizeInvalid()); |
| 7217 | |
| 7218 | // Shrink pending tree viewport without activating. |
| 7219 | host_impl_->CreatePendingTree(); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7220 | host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7221 | EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); |
| 7222 | |
| 7223 | SetupActiveTreeLayers(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7224 | EXPECT_SCOPED(TestEmptyLayerWithOnDraw()); |
| 7225 | EXPECT_SCOPED(TestLayerInMiddleOfViewportWithOnDraw()); |
| 7226 | EXPECT_SCOPED(TestLayerIsLargerThanViewportWithOnDraw()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7227 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7228 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 7229 | class FakeDrawableLayerImpl: public LayerImpl { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7230 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7231 | static std::unique_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { |
| 7232 | return base::WrapUnique(new FakeDrawableLayerImpl(tree_impl, id)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7233 | } |
| 7234 | protected: |
| 7235 | FakeDrawableLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 7236 | : LayerImpl(tree_impl, id) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7237 | }; |
| 7238 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7239 | // Make sure damage tracking propagates all the way to the graphics context, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7240 | // where it should request to swap only the sub-buffer that is damaged. |
| 7241 | TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7242 | scoped_refptr<TestContextProvider> context_provider( |
[email protected] | 4bf4175 | 2013-11-05 01:34:32 | [diff] [blame] | 7243 | TestContextProvider::Create()); |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7244 | context_provider->BindToCurrentThread(); |
| 7245 | context_provider->TestContext3d()->set_have_post_sub_buffer(true); |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 7246 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7247 | std::unique_ptr<FakeOutputSurface> output_surface( |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7248 | FakeOutputSurface::CreateDelegating3d(context_provider)); |
sievers | 0668048 | 2014-10-10 20:21:50 | [diff] [blame] | 7249 | FakeOutputSurface* fake_output_surface = output_surface.get(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7250 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7251 | // This test creates its own LayerTreeHostImpl, so |
| 7252 | // that we can force partial swap enabled. |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 7253 | LayerTreeSettings settings = DefaultSettings(); |
jbauman | c5be44c | 2014-11-20 22:17:12 | [diff] [blame] | 7254 | settings.renderer_settings.partial_swap_enabled = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7255 | std::unique_ptr<LayerTreeHostImpl> layer_tree_host_impl = |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 7256 | LayerTreeHostImpl::Create( |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7257 | settings, this, &task_runner_provider_, &stats_instrumentation_, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 7258 | &shared_bitmap_manager_, NULL, &task_graph_runner_, |
| 7259 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7260 | layer_tree_host_impl->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7261 | layer_tree_host_impl->InitializeRenderer(output_surface.get()); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 7262 | layer_tree_host_impl->WillBeginImplFrame( |
| 7263 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 7264 | layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7265 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7266 | std::unique_ptr<LayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7267 | FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7268 | root->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7269 | std::unique_ptr<LayerImpl> child = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7270 | FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2); |
| 7271 | child->SetPosition(gfx::PointF(12.f, 13.f)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7272 | child->SetBounds(gfx::Size(14, 15)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7273 | child->SetDrawsContent(true); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7274 | root->SetBounds(gfx::Size(500, 500)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7275 | root->SetDrawsContent(true); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7276 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7277 | layer_tree_host_impl->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7278 | layer_tree_host_impl->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7279 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7280 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7281 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7282 | // First frame, the entire screen should get swapped. |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 7283 | EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7284 | layer_tree_host_impl->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7285 | layer_tree_host_impl->DidDrawAllLayers(frame); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7286 | gfx::Rect expected_swap_rect(500, 500); |
sievers | 0668048 | 2014-10-10 20:21:50 | [diff] [blame] | 7287 | EXPECT_EQ(expected_swap_rect.ToString(), |
| 7288 | fake_output_surface->last_swap_rect().ToString()); |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7289 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7290 | // Second frame, only the damaged area should get swapped. Damage should be |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7291 | // the union of old and new child rects: gfx::Rect(26, 28). |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 7292 | layer_tree_host_impl->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7293 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 7294 | ->test_properties() |
| 7295 | ->children[0] |
| 7296 | ->SetPosition(gfx::PointF()); |
| 7297 | layer_tree_host_impl->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7298 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 7299 | ->test_properties() |
| 7300 | ->children[0] |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 7301 | ->NoteLayerPropertyChanged(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7302 | layer_tree_host_impl->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 7303 | EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7304 | layer_tree_host_impl->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7305 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7306 | |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7307 | expected_swap_rect = gfx::Rect(26, 28); |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7308 | EXPECT_EQ(expected_swap_rect.ToString(), |
sievers | 0668048 | 2014-10-10 20:21:50 | [diff] [blame] | 7309 | fake_output_surface->last_swap_rect().ToString()); |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7310 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 7311 | layer_tree_host_impl->SetViewportSize(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7312 | // This will damage everything. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7313 | layer_tree_host_impl->active_tree() |
| 7314 | ->root_layer_for_testing() |
| 7315 | ->SetBackgroundColor(SK_ColorBLACK); |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 7316 | EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7317 | layer_tree_host_impl->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7318 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7319 | |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7320 | expected_swap_rect = gfx::Rect(10, 10); |
sievers | 0668048 | 2014-10-10 20:21:50 | [diff] [blame] | 7321 | EXPECT_EQ(expected_swap_rect.ToString(), |
| 7322 | fake_output_surface->last_swap_rect().ToString()); |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 7323 | |
| 7324 | layer_tree_host_impl->ReleaseOutputSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7325 | } |
| 7326 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7327 | TEST_F(LayerTreeHostImplTest, RootLayerDoesntCreateExtraSurface) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7328 | std::unique_ptr<LayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7329 | FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7330 | std::unique_ptr<LayerImpl> child = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7331 | FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 2); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7332 | child->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7333 | child->SetDrawsContent(true); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7334 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7335 | root->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7336 | root->test_properties()->force_render_surface = true; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7337 | root->test_properties()->AddChild(std::move(child)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7338 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7339 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7340 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7341 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7342 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7343 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7344 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7345 | EXPECT_EQ(1u, frame.render_surface_layer_list->size()); |
| 7346 | EXPECT_EQ(1u, frame.render_passes.size()); |
| 7347 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7348 | } |
| 7349 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 7350 | class FakeLayerWithQuads : public LayerImpl { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7351 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7352 | static std::unique_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { |
| 7353 | return base::WrapUnique(new FakeLayerWithQuads(tree_impl, id)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7354 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7355 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7356 | void AppendQuads(RenderPass* render_pass, |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7357 | AppendQuadsData* append_quads_data) override { |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 7358 | SharedQuadState* shared_quad_state = |
| 7359 | render_pass->CreateAndAppendSharedQuadState(); |
[email protected] | 9be1adc | 2014-05-07 15:39:41 | [diff] [blame] | 7360 | PopulateSharedQuadState(shared_quad_state); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7361 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7362 | SkColor gray = SkColorSetRGB(100, 100, 100); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 7363 | gfx::Rect quad_rect(bounds()); |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 7364 | gfx::Rect visible_quad_rect(quad_rect); |
[email protected] | f7030c3 | 2014-07-03 18:54:34 | [diff] [blame] | 7365 | SolidColorDrawQuad* my_quad = |
| 7366 | render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 7367 | my_quad->SetNew( |
| 7368 | shared_quad_state, quad_rect, visible_quad_rect, gray, false); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7369 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7370 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7371 | private: |
| 7372 | FakeLayerWithQuads(LayerTreeImpl* tree_impl, int id) |
| 7373 | : LayerImpl(tree_impl, id) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7374 | }; |
| 7375 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7376 | static std::unique_ptr<LayerTreeHostImpl> SetupLayersForOpacity( |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 7377 | LayerTreeSettings settings, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7378 | bool partial_swap, |
| 7379 | LayerTreeHostImplClient* client, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7380 | TaskRunnerProvider* task_runner_provider, |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7381 | SharedBitmapManager* manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7382 | TaskGraphRunner* task_graph_runner, |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7383 | RenderingStatsInstrumentation* stats_instrumentation, |
| 7384 | OutputSurface* output_surface) { |
jbauman | c5be44c | 2014-11-20 22:17:12 | [diff] [blame] | 7385 | settings.renderer_settings.partial_swap_enabled = partial_swap; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7386 | std::unique_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7387 | settings, client, task_runner_provider, stats_instrumentation, manager, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 7388 | nullptr, task_graph_runner, |
| 7389 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7390 | my_host_impl->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7391 | my_host_impl->InitializeRenderer(output_surface); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 7392 | my_host_impl->WillBeginImplFrame( |
| 7393 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 7394 | my_host_impl->SetViewportSize(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7395 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7396 | /* |
| 7397 | Layers are created as follows: |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7398 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7399 | +--------------------+ |
| 7400 | | 1 | |
| 7401 | | +-----------+ | |
| 7402 | | | 2 | | |
| 7403 | | | +-------------------+ |
| 7404 | | | | 3 | |
| 7405 | | | +-------------------+ |
| 7406 | | | | | |
| 7407 | | +-----------+ | |
| 7408 | | | |
| 7409 | | | |
| 7410 | +--------------------+ |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7411 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7412 | Layers 1, 2 have render surfaces |
| 7413 | */ |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7414 | std::unique_ptr<LayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7415 | LayerImpl::Create(my_host_impl->active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7416 | std::unique_ptr<LayerImpl> child = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7417 | LayerImpl::Create(my_host_impl->active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7418 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7419 | FakeLayerWithQuads::Create(my_host_impl->active_tree(), 3); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7420 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7421 | gfx::Rect root_rect(0, 0, 100, 100); |
| 7422 | gfx::Rect child_rect(10, 10, 50, 50); |
| 7423 | gfx::Rect grand_child_rect(5, 5, 150, 150); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7424 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7425 | root->test_properties()->force_render_surface = true; |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 7426 | root->SetPosition(gfx::PointF(root_rect.origin())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7427 | root->SetBounds(root_rect.size()); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7428 | root->draw_properties().visible_layer_rect = root_rect; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7429 | root->SetDrawsContent(false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7430 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7431 | child->SetPosition(gfx::PointF(child_rect.x(), child_rect.y())); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 7432 | child->test_properties()->opacity = 0.5f; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7433 | child->SetBounds(gfx::Size(child_rect.width(), child_rect.height())); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7434 | child->draw_properties().visible_layer_rect = child_rect; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7435 | child->SetDrawsContent(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7436 | child->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7437 | |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 7438 | grand_child->SetPosition(gfx::PointF(grand_child_rect.origin())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7439 | grand_child->SetBounds(grand_child_rect.size()); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7440 | grand_child->draw_properties().visible_layer_rect = grand_child_rect; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7441 | grand_child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7442 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7443 | child->test_properties()->AddChild(std::move(grand_child)); |
| 7444 | root->test_properties()->AddChild(std::move(child)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7445 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7446 | my_host_impl->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7447 | my_host_impl->active_tree()->BuildPropertyTreesForTesting(); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7448 | return my_host_impl; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7449 | } |
| 7450 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7451 | TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorPartialSwap) { |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7452 | TestSharedBitmapManager shared_bitmap_manager; |
| 7453 | TestTaskGraphRunner task_graph_runner; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7454 | scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); |
| 7455 | provider->BindToCurrentThread(); |
| 7456 | provider->TestContext3d()->set_have_post_sub_buffer(true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7457 | std::unique_ptr<OutputSurface> output_surface( |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7458 | FakeOutputSurface::CreateDelegating3d(provider)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7459 | std::unique_ptr<LayerTreeHostImpl> my_host_impl = SetupLayersForOpacity( |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 7460 | DefaultSettings(), true, this, &task_runner_provider_, |
| 7461 | &shared_bitmap_manager, &task_graph_runner, &stats_instrumentation_, |
| 7462 | output_surface.get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7463 | { |
| 7464 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 7465 | EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7466 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7467 | // Verify all quads have been computed |
| 7468 | ASSERT_EQ(2U, frame.render_passes.size()); |
| 7469 | ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 7470 | ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size()); |
| 7471 | EXPECT_EQ(DrawQuad::SOLID_COLOR, |
weiliangc | 032e929d | 2014-09-26 01:55:01 | [diff] [blame] | 7472 | frame.render_passes[0]->quad_list.front()->material); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7473 | EXPECT_EQ(DrawQuad::RENDER_PASS, |
weiliangc | 032e929d | 2014-09-26 01:55:01 | [diff] [blame] | 7474 | frame.render_passes[1]->quad_list.front()->material); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7475 | |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7476 | my_host_impl->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7477 | my_host_impl->DidDrawAllLayers(frame); |
| 7478 | } |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 7479 | my_host_impl->ReleaseOutputSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7480 | } |
| 7481 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7482 | TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorNoPartialSwap) { |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7483 | TestSharedBitmapManager shared_bitmap_manager; |
| 7484 | TestTaskGraphRunner task_graph_runner; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7485 | scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); |
| 7486 | provider->BindToCurrentThread(); |
| 7487 | provider->TestContext3d()->set_have_post_sub_buffer(true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7488 | std::unique_ptr<OutputSurface> output_surface( |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7489 | FakeOutputSurface::CreateDelegating3d(provider)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7490 | std::unique_ptr<LayerTreeHostImpl> my_host_impl = SetupLayersForOpacity( |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 7491 | DefaultSettings(), false, this, &task_runner_provider_, |
| 7492 | &shared_bitmap_manager, &task_graph_runner, &stats_instrumentation_, |
| 7493 | output_surface.get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7494 | { |
| 7495 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 7496 | EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7497 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7498 | // Verify all quads have been computed |
| 7499 | ASSERT_EQ(2U, frame.render_passes.size()); |
| 7500 | ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 7501 | ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size()); |
| 7502 | EXPECT_EQ(DrawQuad::SOLID_COLOR, |
weiliangc | 032e929d | 2014-09-26 01:55:01 | [diff] [blame] | 7503 | frame.render_passes[0]->quad_list.front()->material); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7504 | EXPECT_EQ(DrawQuad::RENDER_PASS, |
weiliangc | 032e929d | 2014-09-26 01:55:01 | [diff] [blame] | 7505 | frame.render_passes[1]->quad_list.front()->material); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7506 | |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7507 | my_host_impl->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7508 | my_host_impl->DidDrawAllLayers(frame); |
| 7509 | } |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 7510 | my_host_impl->ReleaseOutputSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7511 | } |
| 7512 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7513 | TEST_F(LayerTreeHostImplTest, LayersFreeTextures) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7514 | std::unique_ptr<TestWebGraphicsContext3D> context = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7515 | TestWebGraphicsContext3D::Create(); |
| 7516 | TestWebGraphicsContext3D* context3d = context.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7517 | std::unique_ptr<OutputSurface> output_surface( |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7518 | FakeOutputSurface::CreateDelegating3d(std::move(context))); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7519 | CreateHostImpl(DefaultSettings(), std::move(output_surface)); |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 7520 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7521 | std::unique_ptr<LayerImpl> root_layer = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7522 | LayerImpl::Create(host_impl_->active_tree(), 1); |
| 7523 | root_layer->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7524 | root_layer->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7525 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7526 | scoped_refptr<VideoFrame> softwareFrame = |
| 7527 | media::VideoFrame::CreateColorFrame( |
| 7528 | gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta()); |
| 7529 | FakeVideoFrameProvider provider; |
| 7530 | provider.set_frame(softwareFrame); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7531 | std::unique_ptr<VideoLayerImpl> video_layer = VideoLayerImpl::Create( |
[email protected] | f78c3e8 | 2014-08-08 01:24:47 | [diff] [blame] | 7532 | host_impl_->active_tree(), 4, &provider, media::VIDEO_ROTATION_0); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7533 | video_layer->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7534 | video_layer->SetDrawsContent(true); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7535 | root_layer->test_properties()->AddChild(std::move(video_layer)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7536 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7537 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7538 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7539 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7540 | EXPECT_EQ(0u, context3d->NumTextures()); |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 7541 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7542 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7543 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7544 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7545 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7546 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7547 | EXPECT_GT(context3d->NumTextures(), 0u); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7548 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7549 | // Kill the layer tree. |
rockot | 2176f92 | 2016-06-08 19:18:32 | [diff] [blame] | 7550 | host_impl_->active_tree()->DetachLayers(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7551 | // There should be no textures left in use after. |
| 7552 | EXPECT_EQ(0u, context3d->NumTextures()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7553 | } |
| 7554 | |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 7555 | class MockDrawQuadsToFillScreenContext : public TestWebGraphicsContext3D { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7556 | public: |
[email protected] | 0f996998 | 2014-01-11 02:26:37 | [diff] [blame] | 7557 | MOCK_METHOD1(useProgram, void(GLuint program)); |
| 7558 | MOCK_METHOD4(drawElements, void(GLenum mode, |
| 7559 | GLsizei count, |
| 7560 | GLenum type, |
| 7561 | GLintptr offset)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7562 | }; |
| 7563 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7564 | TEST_F(LayerTreeHostImplTest, HasTransparentBackground) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7565 | SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7566 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 7567 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7568 | host_impl_->active_tree()->set_background_color(SK_ColorWHITE); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7569 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7570 | // Verify one quad is drawn when transparent background set is not set. |
| 7571 | host_impl_->active_tree()->set_has_transparent_background(false); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7572 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7573 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7574 | { |
| 7575 | const auto& root_pass = frame.render_passes.back(); |
| 7576 | ASSERT_EQ(1u, root_pass->quad_list.size()); |
| 7577 | EXPECT_EQ(DrawQuad::SOLID_COLOR, root_pass->quad_list.front()->material); |
| 7578 | } |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7579 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7580 | host_impl_->DidDrawAllLayers(frame); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7581 | |
| 7582 | // Cause damage so we would draw something if possible. |
danakj | b902c67 | 2016-08-17 02:33:54 | [diff] [blame] | 7583 | host_impl_->SetFullViewportDamage(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7584 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7585 | // Verify no quads are drawn when transparent background is set. |
| 7586 | host_impl_->active_tree()->set_has_transparent_background(true); |
danakj | b902c67 | 2016-08-17 02:33:54 | [diff] [blame] | 7587 | host_impl_->SetFullViewportDamage(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7588 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7589 | { |
| 7590 | const auto& root_pass = frame.render_passes.back(); |
| 7591 | ASSERT_EQ(0u, root_pass->quad_list.size()); |
| 7592 | } |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7593 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7594 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7595 | } |
| 7596 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7597 | class LayerTreeHostImplTestWithDelegatingRenderer |
| 7598 | : public LayerTreeHostImplTest { |
| 7599 | protected: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7600 | std::unique_ptr<OutputSurface> CreateOutputSurface() override { |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 7601 | return FakeOutputSurface::CreateDelegating3d(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7602 | } |
| 7603 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 7604 | void DrawFrameAndTestDamage(const gfx::Rect& expected_damage) { |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7605 | bool expect_to_draw = !expected_damage.IsEmpty(); |
| 7606 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7607 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7608 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7609 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7610 | if (!expect_to_draw) { |
| 7611 | // With no damage, we don't draw, and no quads are created. |
| 7612 | ASSERT_EQ(0u, frame.render_passes.size()); |
| 7613 | } else { |
| 7614 | ASSERT_EQ(1u, frame.render_passes.size()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7615 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7616 | // Verify the damage rect for the root render pass. |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 7617 | const RenderPass* root_render_pass = frame.render_passes.back().get(); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 7618 | EXPECT_EQ(expected_damage, root_render_pass->damage_rect); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7619 | |
| 7620 | // Verify the root and child layers' quads are generated and not being |
| 7621 | // culled. |
| 7622 | ASSERT_EQ(2u, root_render_pass->quad_list.size()); |
| 7623 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 7624 | LayerImpl* child = host_impl_->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7625 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 7626 | ->test_properties() |
| 7627 | ->children[0]; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 7628 | gfx::Rect expected_child_visible_rect(child->bounds()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 7629 | EXPECT_EQ(expected_child_visible_rect, |
| 7630 | root_render_pass->quad_list.front()->visible_rect); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7631 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7632 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 7633 | gfx::Rect expected_root_visible_rect(root->bounds()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 7634 | EXPECT_EQ(expected_root_visible_rect, |
| 7635 | root_render_pass->quad_list.ElementAt(1)->visible_rect); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7636 | } |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7637 | |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 7638 | EXPECT_EQ(expect_to_draw, host_impl_->DrawLayers(&frame)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7639 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7640 | } |
| 7641 | }; |
| 7642 | |
| 7643 | TEST_F(LayerTreeHostImplTestWithDelegatingRenderer, FrameIncludesDamageRect) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7644 | std::unique_ptr<SolidColorLayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7645 | SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7646 | root->SetPosition(gfx::PointF()); |
| 7647 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7648 | root->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7649 | root->test_properties()->force_render_surface = true; |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7650 | |
| 7651 | // Child layer is in the bottom right corner. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7652 | std::unique_ptr<SolidColorLayerImpl> child = |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7653 | SolidColorLayerImpl::Create(host_impl_->active_tree(), 2); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7654 | child->SetPosition(gfx::PointF(9.f, 9.f)); |
| 7655 | child->SetBounds(gfx::Size(1, 1)); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7656 | child->SetDrawsContent(true); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7657 | root->test_properties()->AddChild(std::move(child)); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7658 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7659 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7660 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7661 | |
| 7662 | // Draw a frame. In the first frame, the entire viewport should be damaged. |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 7663 | gfx::Rect full_frame_damage(host_impl_->DrawViewportSize()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7664 | DrawFrameAndTestDamage(full_frame_damage); |
| 7665 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7666 | // The second frame has damage that doesn't touch the child layer. Its quads |
| 7667 | // should still be generated. |
| 7668 | gfx::Rect small_damage = gfx::Rect(0, 0, 1, 1); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7669 | host_impl_->active_tree()->root_layer_for_testing()->SetUpdateRect( |
| 7670 | small_damage); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7671 | DrawFrameAndTestDamage(small_damage); |
| 7672 | |
| 7673 | // The third frame should have no damage, so no quads should be generated. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7674 | gfx::Rect no_damage; |
| 7675 | DrawFrameAndTestDamage(no_damage); |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 7676 | } |
| 7677 | |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7678 | class GLRendererWithSetupQuadForAntialiasing : public GLRenderer { |
| 7679 | public: |
timav | 8a72a92 | 2014-11-07 00:47:21 | [diff] [blame] | 7680 | using GLRenderer::ShouldAntialiasQuad; |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7681 | }; |
| 7682 | |
| 7683 | TEST_F(LayerTreeHostImplTest, FarAwayQuadsDontNeedAA) { |
| 7684 | // Due to precision issues (especially on Android), sometimes far |
| 7685 | // away quads can end up thinking they need AA. |
| 7686 | float device_scale_factor = 4.f / 3.f; |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7687 | gfx::Size root_size(2000, 1000); |
| 7688 | gfx::Size device_viewport_size = |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 7689 | gfx::ScaleToCeiledSize(root_size, device_scale_factor); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7690 | host_impl_->SetViewportSize(device_viewport_size); |
| 7691 | |
| 7692 | host_impl_->CreatePendingTree(); |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 7693 | host_impl_->pending_tree()->SetDeviceScaleFactor(device_scale_factor); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 7694 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f / 16.f, |
| 7695 | 16.f); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7696 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7697 | std::unique_ptr<LayerImpl> scoped_root = |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7698 | LayerImpl::Create(host_impl_->pending_tree(), 1); |
| 7699 | LayerImpl* root = scoped_root.get(); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7700 | root->test_properties()->force_render_surface = true; |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7701 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7702 | host_impl_->pending_tree()->SetRootLayerForTesting(std::move(scoped_root)); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7703 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7704 | std::unique_ptr<LayerImpl> scoped_scrolling_layer = |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7705 | LayerImpl::Create(host_impl_->pending_tree(), 2); |
| 7706 | LayerImpl* scrolling_layer = scoped_scrolling_layer.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7707 | root->test_properties()->AddChild(std::move(scoped_scrolling_layer)); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7708 | |
| 7709 | gfx::Size content_layer_bounds(100000, 100); |
vmpstr | 41d68f88 | 2016-03-30 01:20:23 | [diff] [blame] | 7710 | scoped_refptr<FakeRasterSource> raster_source( |
| 7711 | FakeRasterSource::CreateFilled(content_layer_bounds)); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7712 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7713 | std::unique_ptr<FakePictureLayerImpl> scoped_content_layer = |
hendrikw | 9d909aa7 | 2014-11-11 20:19:52 | [diff] [blame] | 7714 | FakePictureLayerImpl::CreateWithRasterSource(host_impl_->pending_tree(), |
vmpstr | 85674026 | 2015-09-24 00:25:25 | [diff] [blame] | 7715 | 3, raster_source); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7716 | LayerImpl* content_layer = scoped_content_layer.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7717 | scrolling_layer->test_properties()->AddChild(std::move(scoped_content_layer)); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7718 | content_layer->SetBounds(content_layer_bounds); |
| 7719 | content_layer->SetDrawsContent(true); |
| 7720 | |
| 7721 | root->SetBounds(root_size); |
| 7722 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 7723 | gfx::ScrollOffset scroll_offset(100000, 0); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 7724 | scrolling_layer->SetScrollClipLayer(root->id()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7725 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
| 7726 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7727 | scrolling_layer->layer_tree_impl() |
| 7728 | ->property_trees() |
| 7729 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scrolling_layer->id(), |
| 7730 | scroll_offset); |
[email protected] | fc20d14 | 2014-07-01 00:49:15 | [diff] [blame] | 7731 | host_impl_->ActivateSyncTree(); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7732 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 7733 | bool update_lcd_text = false; |
| 7734 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7735 | ASSERT_EQ(1u, host_impl_->active_tree()->RenderSurfaceLayerList().size()); |
| 7736 | |
| 7737 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7738 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7739 | |
| 7740 | ASSERT_EQ(1u, frame.render_passes.size()); |
| 7741 | ASSERT_LE(1u, frame.render_passes[0]->quad_list.size()); |
weiliangc | 032e929d | 2014-09-26 01:55:01 | [diff] [blame] | 7742 | const DrawQuad* quad = frame.render_passes[0]->quad_list.front(); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7743 | |
rosca | f519af2 | 2015-06-17 20:57:10 | [diff] [blame] | 7744 | bool clipped = false, force_aa = false; |
| 7745 | gfx::QuadF device_layer_quad = MathUtil::MapQuad( |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7746 | quad->shared_quad_state->quad_to_target_transform, |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 7747 | gfx::QuadF(gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)), |
| 7748 | &clipped); |
rosca | f519af2 | 2015-06-17 20:57:10 | [diff] [blame] | 7749 | EXPECT_FALSE(clipped); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7750 | bool antialiased = |
timav | 8a72a92 | 2014-11-07 00:47:21 | [diff] [blame] | 7751 | GLRendererWithSetupQuadForAntialiasing::ShouldAntialiasQuad( |
rosca | f519af2 | 2015-06-17 20:57:10 | [diff] [blame] | 7752 | device_layer_quad, clipped, force_aa); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7753 | EXPECT_FALSE(antialiased); |
| 7754 | |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7755 | host_impl_->DrawLayers(&frame); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7756 | host_impl_->DidDrawAllLayers(frame); |
| 7757 | } |
| 7758 | |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 7759 | class CompositorFrameMetadataTest : public LayerTreeHostImplTest { |
| 7760 | public: |
| 7761 | CompositorFrameMetadataTest() |
| 7762 | : swap_buffers_complete_(0) {} |
| 7763 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7764 | void DidSwapBuffersCompleteOnImplThread() override { |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 7765 | swap_buffers_complete_++; |
| 7766 | } |
| 7767 | |
| 7768 | int swap_buffers_complete_; |
| 7769 | }; |
| 7770 | |
| 7771 | TEST_F(CompositorFrameMetadataTest, CompositorFrameAckCountsAsSwapComplete) { |
| 7772 | SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7773 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 7774 | { |
| 7775 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7776 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7777 | host_impl_->DrawLayers(&frame); |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 7778 | host_impl_->DidDrawAllLayers(frame); |
| 7779 | } |
fsamuel | b62b7822 | 2016-07-15 01:14:14 | [diff] [blame] | 7780 | host_impl_->ReclaimResources(ReturnedResourceArray()); |
[email protected] | c1490266 | 2014-04-18 05:06:11 | [diff] [blame] | 7781 | host_impl_->DidSwapBuffersComplete(); |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 7782 | EXPECT_EQ(swap_buffers_complete_, 1); |
| 7783 | } |
| 7784 | |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 7785 | class CountingSoftwareDevice : public SoftwareOutputDevice { |
| 7786 | public: |
| 7787 | CountingSoftwareDevice() : frames_began_(0), frames_ended_(0) {} |
| 7788 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7789 | SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override { |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 7790 | ++frames_began_; |
| 7791 | return SoftwareOutputDevice::BeginPaint(damage_rect); |
| 7792 | } |
jbauman | 95f74135 | 2015-08-07 02:10:34 | [diff] [blame] | 7793 | void EndPaint() override { |
| 7794 | SoftwareOutputDevice::EndPaint(); |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 7795 | ++frames_ended_; |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 7796 | } |
| 7797 | |
| 7798 | int frames_began_, frames_ended_; |
| 7799 | }; |
| 7800 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7801 | TEST_F(LayerTreeHostImplTest, |
| 7802 | ForcedDrawToSoftwareDeviceSkipsUnsupportedLayers) { |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 7803 | set_reduce_memory_result(false); |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 7804 | EXPECT_TRUE(CreateHostImpl(DefaultSettings(), |
| 7805 | FakeOutputSurface::CreateDelegatingSoftware())); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7806 | |
[email protected] | c05dfbb | 2014-07-10 22:49:04 | [diff] [blame] | 7807 | const gfx::Transform external_transform; |
| 7808 | const gfx::Rect external_viewport; |
[email protected] | c05dfbb | 2014-07-10 22:49:04 | [diff] [blame] | 7809 | const bool resourceless_software_draw = true; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7810 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 7811 | external_transform); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7812 | |
| 7813 | // SolidColorLayerImpl will be drawn. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7814 | std::unique_ptr<SolidColorLayerImpl> root_layer = |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7815 | SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
| 7816 | |
| 7817 | // VideoLayerImpl will not be drawn. |
| 7818 | FakeVideoFrameProvider provider; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7819 | std::unique_ptr<VideoLayerImpl> video_layer = VideoLayerImpl::Create( |
[email protected] | f78c3e8 | 2014-08-08 01:24:47 | [diff] [blame] | 7820 | host_impl_->active_tree(), 2, &provider, media::VIDEO_ROTATION_0); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7821 | video_layer->SetBounds(gfx::Size(10, 10)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7822 | video_layer->SetDrawsContent(true); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7823 | root_layer->test_properties()->AddChild(std::move(video_layer)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7824 | SetupRootLayerImpl(std::move(root_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7825 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7826 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 7827 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7828 | resourceless_software_draw); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7829 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7830 | EXPECT_EQ(1u, last_on_draw_frame_->will_draw_layers.size()); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7831 | EXPECT_EQ(host_impl_->active_tree()->root_layer_for_testing(), |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7832 | last_on_draw_frame_->will_draw_layers[0]); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7833 | } |
| 7834 | |
danakj | aa5c491 | 2016-09-10 00:28:23 | [diff] [blame] | 7835 | // Checks that we use the memory limits provided. |
| 7836 | TEST_F(LayerTreeHostImplTest, MemoryLimits) { |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 7837 | host_impl_->ReleaseOutputSurface(); |
| 7838 | host_impl_ = nullptr; |
| 7839 | |
danakj | aa5c491 | 2016-09-10 00:28:23 | [diff] [blame] | 7840 | const size_t kGpuByteLimit = 1234321; |
| 7841 | const size_t kSoftwareByteLimit = 4321234; |
| 7842 | const size_t kGpuResourceLimit = 2345432; |
| 7843 | const size_t kSoftwareResourceLimit = 5432345; |
| 7844 | const gpu::MemoryAllocation::PriorityCutoff kGpuCutoff = |
| 7845 | gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; |
| 7846 | const gpu::MemoryAllocation::PriorityCutoff kSoftwareCutoff = |
| 7847 | gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 7848 | |
| 7849 | const TileMemoryLimitPolicy kGpuTileCutoff = |
| 7850 | ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy(kGpuCutoff); |
| 7851 | const TileMemoryLimitPolicy kSoftwareTileCutoff = |
| 7852 | ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( |
| 7853 | kSoftwareCutoff); |
| 7854 | const TileMemoryLimitPolicy kNothingTileCutoff = |
| 7855 | ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( |
| 7856 | gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING); |
| 7857 | EXPECT_NE(kGpuTileCutoff, kNothingTileCutoff); |
| 7858 | EXPECT_NE(kSoftwareTileCutoff, kNothingTileCutoff); |
| 7859 | |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 7860 | LayerTreeSettings settings = DefaultSettings(); |
danakj | aa5c491 | 2016-09-10 00:28:23 | [diff] [blame] | 7861 | settings.gpu_memory_policy = |
| 7862 | ManagedMemoryPolicy(kGpuByteLimit, kGpuCutoff, kGpuResourceLimit); |
| 7863 | settings.software_memory_policy = ManagedMemoryPolicy( |
| 7864 | kSoftwareByteLimit, kSoftwareCutoff, kSoftwareResourceLimit); |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 7865 | host_impl_ = LayerTreeHostImpl::Create( |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7866 | settings, this, &task_runner_provider_, &stats_instrumentation_, |
| 7867 | &shared_bitmap_manager_, &gpu_memory_buffer_manager_, &task_graph_runner_, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 7868 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); |
[email protected] | fd32d12 | 2013-06-29 13:11:04 | [diff] [blame] | 7869 | |
danakj | aa5c491 | 2016-09-10 00:28:23 | [diff] [blame] | 7870 | // Gpu compositing. |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7871 | output_surface_ = |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7872 | FakeOutputSurface::CreateDelegating3d(TestWebGraphicsContext3D::Create()); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7873 | host_impl_->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7874 | host_impl_->InitializeRenderer(output_surface_.get()); |
danakj | aa5c491 | 2016-09-10 00:28:23 | [diff] [blame] | 7875 | { |
| 7876 | const auto& state = host_impl_->global_tile_state(); |
| 7877 | EXPECT_EQ(kGpuByteLimit, state.hard_memory_limit_in_bytes); |
| 7878 | EXPECT_EQ(kGpuResourceLimit, state.num_resources_limit); |
| 7879 | EXPECT_EQ(kGpuTileCutoff, state.memory_limit_policy); |
| 7880 | } |
| 7881 | |
| 7882 | // Not visible, drops to 0. |
| 7883 | host_impl_->SetVisible(false); |
| 7884 | { |
| 7885 | const auto& state = host_impl_->global_tile_state(); |
| 7886 | EXPECT_EQ(0u, state.hard_memory_limit_in_bytes); |
| 7887 | EXPECT_EQ(kGpuResourceLimit, state.num_resources_limit); |
| 7888 | EXPECT_EQ(kNothingTileCutoff, state.memory_limit_policy); |
| 7889 | } |
| 7890 | |
| 7891 | // Visible, is the gpu limit again. |
| 7892 | host_impl_->SetVisible(true); |
| 7893 | { |
| 7894 | const auto& state = host_impl_->global_tile_state(); |
| 7895 | EXPECT_EQ(kGpuByteLimit, state.hard_memory_limit_in_bytes); |
| 7896 | EXPECT_EQ(kGpuResourceLimit, state.num_resources_limit); |
| 7897 | } |
| 7898 | |
| 7899 | // Software compositing. |
| 7900 | host_impl_->ReleaseOutputSurface(); |
| 7901 | output_surface_ = FakeOutputSurface::CreateDelegatingSoftware(); |
| 7902 | host_impl_->InitializeRenderer(output_surface_.get()); |
| 7903 | { |
| 7904 | const auto& state = host_impl_->global_tile_state(); |
| 7905 | EXPECT_EQ(kSoftwareByteLimit, state.hard_memory_limit_in_bytes); |
| 7906 | EXPECT_EQ(kSoftwareResourceLimit, state.num_resources_limit); |
| 7907 | EXPECT_EQ(kSoftwareTileCutoff, state.memory_limit_policy); |
| 7908 | } |
| 7909 | |
| 7910 | // Not visible, drops to 0. |
| 7911 | host_impl_->SetVisible(false); |
| 7912 | { |
| 7913 | const auto& state = host_impl_->global_tile_state(); |
| 7914 | EXPECT_EQ(0u, state.hard_memory_limit_in_bytes); |
| 7915 | EXPECT_EQ(kSoftwareResourceLimit, state.num_resources_limit); |
| 7916 | EXPECT_EQ(kNothingTileCutoff, state.memory_limit_policy); |
| 7917 | } |
| 7918 | |
| 7919 | // Visible, is the software limit again. |
| 7920 | host_impl_->SetVisible(true); |
| 7921 | { |
| 7922 | const auto& state = host_impl_->global_tile_state(); |
| 7923 | EXPECT_EQ(kSoftwareByteLimit, state.hard_memory_limit_in_bytes); |
| 7924 | EXPECT_EQ(kSoftwareResourceLimit, state.num_resources_limit); |
| 7925 | EXPECT_EQ(kSoftwareTileCutoff, state.memory_limit_policy); |
| 7926 | } |
[email protected] | fd32d12 | 2013-06-29 13:11:04 | [diff] [blame] | 7927 | } |
| 7928 | |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7929 | TEST_F(LayerTreeHostImplTest, RequireHighResWhenVisible) { |
| 7930 | ASSERT_TRUE(host_impl_->active_tree()); |
| 7931 | |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7932 | // RequiresHighResToDraw is set when new output surface is used. |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7933 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7934 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7935 | host_impl_->ResetRequiresHighResToDraw(); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7936 | |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7937 | host_impl_->SetVisible(false); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7938 | EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7939 | host_impl_->SetVisible(true); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7940 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7941 | host_impl_->SetVisible(false); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7942 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7943 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7944 | host_impl_->ResetRequiresHighResToDraw(); |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7945 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7946 | EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7947 | host_impl_->SetVisible(true); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7948 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7949 | } |
| 7950 | |
[email protected] | 13525d6 | 2014-05-20 21:22:04 | [diff] [blame] | 7951 | TEST_F(LayerTreeHostImplTest, RequireHighResAfterGpuRasterizationToggles) { |
| 7952 | ASSERT_TRUE(host_impl_->active_tree()); |
| 7953 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 7954 | |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7955 | // RequiresHighResToDraw is set when new output surface is used. |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7956 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7957 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7958 | host_impl_->ResetRequiresHighResToDraw(); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7959 | |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 7960 | host_impl_->SetContentIsSuitableForGpuRasterization(true); |
| 7961 | host_impl_->SetHasGpuRasterizationTrigger(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 7962 | host_impl_->CommitComplete(); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7963 | EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 7964 | host_impl_->SetHasGpuRasterizationTrigger(true); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 7965 | host_impl_->CommitComplete(); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7966 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 7967 | host_impl_->SetHasGpuRasterizationTrigger(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 7968 | host_impl_->CommitComplete(); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7969 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 13525d6 | 2014-05-20 21:22:04 | [diff] [blame] | 7970 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7971 | host_impl_->ResetRequiresHighResToDraw(); |
[email protected] | 13525d6 | 2014-05-20 21:22:04 | [diff] [blame] | 7972 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7973 | EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 7974 | host_impl_->SetHasGpuRasterizationTrigger(true); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 7975 | host_impl_->CommitComplete(); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7976 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 13525d6 | 2014-05-20 21:22:04 | [diff] [blame] | 7977 | } |
| 7978 | |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 7979 | class LayerTreeHostImplTestPrepareTiles : public LayerTreeHostImplTest { |
[email protected] | 222c678 | 2013-09-05 22:24:49 | [diff] [blame] | 7980 | public: |
danakj | aeb9506 | 2014-11-14 01:35:36 | [diff] [blame] | 7981 | void SetUp() override { |
danakj | 431a120 | 2015-06-17 19:09:33 | [diff] [blame] | 7982 | fake_host_impl_ = |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7983 | new FakeLayerTreeHostImpl(LayerTreeSettings(), &task_runner_provider_, |
danakj | 431a120 | 2015-06-17 19:09:33 | [diff] [blame] | 7984 | &shared_bitmap_manager_, &task_graph_runner_); |
[email protected] | 222c678 | 2013-09-05 22:24:49 | [diff] [blame] | 7985 | host_impl_.reset(fake_host_impl_); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7986 | output_surface_ = CreateOutputSurface(); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7987 | host_impl_->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7988 | host_impl_->InitializeRenderer(output_surface_.get()); |
[email protected] | 222c678 | 2013-09-05 22:24:49 | [diff] [blame] | 7989 | host_impl_->SetViewportSize(gfx::Size(10, 10)); |
| 7990 | } |
| 7991 | |
| 7992 | FakeLayerTreeHostImpl* fake_host_impl_; |
| 7993 | }; |
| 7994 | |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 7995 | TEST_F(LayerTreeHostImplTestPrepareTiles, PrepareTilesWhenInvisible) { |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 7996 | EXPECT_TRUE(fake_host_impl_->prepare_tiles_needed()); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7997 | host_impl_->SetVisible(false); |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 7998 | EXPECT_FALSE(fake_host_impl_->prepare_tiles_needed()); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7999 | host_impl_->SetVisible(true); |
| 8000 | EXPECT_TRUE(fake_host_impl_->prepare_tiles_needed()); |
[email protected] | 222c678 | 2013-09-05 22:24:49 | [diff] [blame] | 8001 | } |
| 8002 | |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8003 | TEST_F(LayerTreeHostImplTest, UIResourceManagement) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8004 | std::unique_ptr<TestWebGraphicsContext3D> context = |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8005 | TestWebGraphicsContext3D::Create(); |
| 8006 | TestWebGraphicsContext3D* context3d = context.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8007 | std::unique_ptr<FakeOutputSurface> output_surface = |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 8008 | FakeOutputSurface::CreateDelegating3d(); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 8009 | CreateHostImpl(DefaultSettings(), std::move(output_surface)); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8010 | |
| 8011 | EXPECT_EQ(0u, context3d->NumTextures()); |
| 8012 | |
| 8013 | UIResourceId ui_resource_id = 1; |
[email protected] | 0046982c | 2014-03-25 22:00:51 | [diff] [blame] | 8014 | bool is_opaque = false; |
| 8015 | UIResourceBitmap bitmap(gfx::Size(1, 1), is_opaque); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8016 | host_impl_->CreateUIResource(ui_resource_id, bitmap); |
| 8017 | EXPECT_EQ(1u, context3d->NumTextures()); |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 8018 | ResourceId id1 = host_impl_->ResourceIdForUIResource(ui_resource_id); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8019 | EXPECT_NE(0u, id1); |
| 8020 | |
| 8021 | // Multiple requests with the same id is allowed. The previous texture is |
| 8022 | // deleted. |
| 8023 | host_impl_->CreateUIResource(ui_resource_id, bitmap); |
| 8024 | EXPECT_EQ(1u, context3d->NumTextures()); |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 8025 | ResourceId id2 = host_impl_->ResourceIdForUIResource(ui_resource_id); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8026 | EXPECT_NE(0u, id2); |
| 8027 | EXPECT_NE(id1, id2); |
| 8028 | |
| 8029 | // Deleting invalid UIResourceId is allowed and does not change state. |
| 8030 | host_impl_->DeleteUIResource(-1); |
| 8031 | EXPECT_EQ(1u, context3d->NumTextures()); |
| 8032 | |
| 8033 | // Should return zero for invalid UIResourceId. Number of textures should |
| 8034 | // not change. |
| 8035 | EXPECT_EQ(0u, host_impl_->ResourceIdForUIResource(-1)); |
| 8036 | EXPECT_EQ(1u, context3d->NumTextures()); |
| 8037 | |
| 8038 | host_impl_->DeleteUIResource(ui_resource_id); |
| 8039 | EXPECT_EQ(0u, host_impl_->ResourceIdForUIResource(ui_resource_id)); |
| 8040 | EXPECT_EQ(0u, context3d->NumTextures()); |
| 8041 | |
| 8042 | // Should not change state for multiple deletion on one UIResourceId |
| 8043 | host_impl_->DeleteUIResource(ui_resource_id); |
| 8044 | EXPECT_EQ(0u, context3d->NumTextures()); |
| 8045 | } |
| 8046 | |
[email protected] | 6be50ba8 | 2013-11-08 12:04:12 | [diff] [blame] | 8047 | TEST_F(LayerTreeHostImplTest, CreateETC1UIResource) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8048 | std::unique_ptr<TestWebGraphicsContext3D> context = |
[email protected] | 6be50ba8 | 2013-11-08 12:04:12 | [diff] [blame] | 8049 | TestWebGraphicsContext3D::Create(); |
| 8050 | TestWebGraphicsContext3D* context3d = context.get(); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 8051 | CreateHostImpl(DefaultSettings(), FakeOutputSurface::CreateDelegating3d()); |
[email protected] | 6be50ba8 | 2013-11-08 12:04:12 | [diff] [blame] | 8052 | |
| 8053 | EXPECT_EQ(0u, context3d->NumTextures()); |
| 8054 | |
[email protected] | 80ee233 | 2014-02-06 18:31:07 | [diff] [blame] | 8055 | gfx::Size size(4, 4); |
| 8056 | // SkImageInfo has no support for ETC1. The |info| below contains the right |
| 8057 | // total pixel size for the bitmap but not the right height and width. The |
| 8058 | // correct width/height are passed directly to UIResourceBitmap. |
[email protected] | 7bc1c51 | 2014-01-23 01:15:27 | [diff] [blame] | 8059 | SkImageInfo info = |
[email protected] | 80ee233 | 2014-02-06 18:31:07 | [diff] [blame] | 8060 | SkImageInfo::Make(4, 2, kAlpha_8_SkColorType, kPremul_SkAlphaType); |
tomhudson | 992ec28b | 2016-04-27 16:45:39 | [diff] [blame] | 8061 | sk_sp<SkPixelRef> pixel_ref(SkMallocPixelRef::NewAllocate(info, 0, 0)); |
[email protected] | 7bc1c51 | 2014-01-23 01:15:27 | [diff] [blame] | 8062 | pixel_ref->setImmutable(); |
tomhudson | 992ec28b | 2016-04-27 16:45:39 | [diff] [blame] | 8063 | UIResourceBitmap bitmap(std::move(pixel_ref), size); |
[email protected] | 6be50ba8 | 2013-11-08 12:04:12 | [diff] [blame] | 8064 | UIResourceId ui_resource_id = 1; |
| 8065 | host_impl_->CreateUIResource(ui_resource_id, bitmap); |
| 8066 | EXPECT_EQ(1u, context3d->NumTextures()); |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 8067 | ResourceId id1 = host_impl_->ResourceIdForUIResource(ui_resource_id); |
[email protected] | 6be50ba8 | 2013-11-08 12:04:12 | [diff] [blame] | 8068 | EXPECT_NE(0u, id1); |
| 8069 | } |
| 8070 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8071 | void ShutdownReleasesContext_Callback( |
| 8072 | std::unique_ptr<CopyOutputResult> result) {} |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8073 | |
| 8074 | TEST_F(LayerTreeHostImplTest, ShutdownReleasesContext) { |
| 8075 | scoped_refptr<TestContextProvider> context_provider = |
| 8076 | TestContextProvider::Create(); |
| 8077 | |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 8078 | CreateHostImpl( |
| 8079 | DefaultSettings(), |
| 8080 | base::MakeUnique<TestDelegatingOutputSurface>( |
| 8081 | context_provider, TestContextProvider::CreateWorker(), |
| 8082 | FakeOutputSurface::Create3d(context_provider), nullptr, nullptr, |
| 8083 | RendererSettings(), base::ThreadTaskRunnerHandle::Get().get(), |
danakj | 014316e | 2016-08-04 18:40:26 | [diff] [blame] | 8084 | true /* synchronous_composite */, |
| 8085 | false /* force_disable_reclaim_resources */)); |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8086 | |
| 8087 | SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
| 8088 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8089 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 8090 | root->test_properties()->copy_requests.push_back( |
| 8091 | CopyOutputRequest::CreateRequest( |
| 8092 | base::Bind(&ShutdownReleasesContext_Callback))); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8093 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8094 | |
| 8095 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8096 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 8097 | host_impl_->DrawLayers(&frame); |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8098 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8099 | |
| 8100 | // The CopyOutputResult's callback has a ref on the ContextProvider and a |
| 8101 | // texture in a texture mailbox. |
| 8102 | EXPECT_FALSE(context_provider->HasOneRef()); |
| 8103 | EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); |
| 8104 | |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 8105 | host_impl_->ReleaseOutputSurface(); |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 8106 | host_impl_ = nullptr; |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8107 | |
| 8108 | // The CopyOutputResult's callback was cancelled, the CopyOutputResult |
| 8109 | // released, and the texture deleted. |
| 8110 | EXPECT_TRUE(context_provider->HasOneRef()); |
| 8111 | EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); |
| 8112 | } |
| 8113 | |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8114 | TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) { |
| 8115 | // When flinging via touch, only the child should scroll (we should not |
| 8116 | // bubble). |
| 8117 | gfx::Size surface_size(10, 10); |
| 8118 | gfx::Size content_size(20, 20); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8119 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 8120 | LayerImpl::Create(host_impl_->active_tree(), 4); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8121 | std::unique_ptr<LayerImpl> root_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8122 | LayerImpl::Create(host_impl_->active_tree(), 3); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8123 | root_clip->test_properties()->force_render_surface = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8124 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8125 | std::unique_ptr<LayerImpl> root_scroll = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8126 | CreateScrollableLayer(1, content_size, root_clip.get()); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8127 | root_scroll->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8128 | std::unique_ptr<LayerImpl> child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8129 | CreateScrollableLayer(2, content_size, root_clip.get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8130 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8131 | root_scroll->test_properties()->AddChild(std::move(child)); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 8132 | int root_id = root_scroll->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8133 | root_clip->test_properties()->AddChild(std::move(root_scroll)); |
| 8134 | root_ptr->test_properties()->AddChild(std::move(root_clip)); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8135 | |
| 8136 | host_impl_->SetViewportSize(surface_size); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8137 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 8138 | host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 1, |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 8139 | Layer::INVALID_ID); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8140 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8141 | host_impl_->active_tree()->DidBecomeActive(); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 8142 | DrawFrame(); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8143 | { |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8144 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8145 | host_impl_ |
| 8146 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8147 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8148 | .thread); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8149 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8150 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 8151 | host_impl_->FlingScrollBegin().thread); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8152 | |
| 8153 | gfx::Vector2d scroll_delta(0, 100); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8154 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 8155 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8156 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8157 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8158 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8159 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8160 | host_impl_->ProcessScrollDeltas(); |
| 8161 | |
| 8162 | // Only the child should have scrolled. |
| 8163 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8164 | ExpectNone(*scroll_info.get(), root_id); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8165 | } |
| 8166 | } |
| 8167 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8168 | TEST_F(LayerTreeHostImplTest, TouchFlingShouldContinueScrollingCurrentLayer) { |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8169 | // Scroll a child layer beyond its maximum scroll range and make sure the |
| 8170 | // the scroll doesn't bubble up to the parent layer. |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8171 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8172 | std::unique_ptr<LayerImpl> root = |
| 8173 | LayerImpl::Create(host_impl_->active_tree(), 1); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8174 | root->test_properties()->force_render_surface = true; |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8175 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8176 | std::unique_ptr<LayerImpl> root_scrolling_owned = |
| 8177 | CreateScrollableLayer(2, surface_size, root.get()); |
| 8178 | auto* root_scrolling = root_scrolling_owned.get(); |
| 8179 | root->test_properties()->AddChild(std::move(root_scrolling_owned)); |
| 8180 | |
| 8181 | std::unique_ptr<LayerImpl> child_owned = |
| 8182 | CreateScrollableLayer(3, surface_size, root.get()); |
| 8183 | auto* child = child_owned.get(); |
| 8184 | root_scrolling->test_properties()->AddChild(std::move(child_owned)); |
| 8185 | |
| 8186 | std::unique_ptr<LayerImpl> grand_child_owned = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8187 | CreateScrollableLayer(4, surface_size, root.get()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8188 | auto* grand_child = grand_child_owned.get(); |
| 8189 | child->test_properties()->AddChild(std::move(grand_child_owned)); |
| 8190 | |
| 8191 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8192 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 8193 | host_impl_->active_tree()->DidBecomeActive(); |
| 8194 | |
| 8195 | child->layer_tree_impl() |
| 8196 | ->property_trees() |
| 8197 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(child->id(), |
| 8198 | gfx::ScrollOffset(0, 4)); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 8199 | grand_child->layer_tree_impl() |
| 8200 | ->property_trees() |
| 8201 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(grand_child->id(), |
| 8202 | gfx::ScrollOffset(0, 2)); |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8203 | |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8204 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 8205 | DrawFrame(); |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8206 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8207 | std::unique_ptr<ScrollAndScaleSet> scroll_info; |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 8208 | LayerImpl* child = host_impl_->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8209 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 8210 | ->test_properties() |
| 8211 | ->children[0] |
| 8212 | ->test_properties() |
| 8213 | ->children[0]; |
| 8214 | LayerImpl* grand_child = child->test_properties()->children[0]; |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8215 | |
| 8216 | gfx::Vector2d scroll_delta(0, -2); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8217 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8218 | host_impl_ |
| 8219 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8220 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8221 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8222 | EXPECT_TRUE( |
| 8223 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 8224 | .did_scroll); |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8225 | |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8226 | // The grand child should have scrolled up to its limit. |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8227 | scroll_info = host_impl_->ProcessScrollDeltas(); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8228 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 8229 | EXPECT_TRUE( |
| 8230 | ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8231 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
| 8232 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8233 | // The locked scrolling layer should remain set as the grand child. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8234 | EXPECT_FALSE( |
| 8235 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 8236 | .did_scroll); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8237 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8238 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 8239 | EXPECT_TRUE( |
| 8240 | ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8241 | ExpectNone(*scroll_info, child->id()); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8242 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
| 8243 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8244 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 8245 | host_impl_->FlingScrollBegin().thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8246 | EXPECT_FALSE( |
| 8247 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 8248 | .did_scroll); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8249 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8250 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8251 | // The child should not have scrolled. |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8252 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8253 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 8254 | EXPECT_TRUE( |
| 8255 | ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8256 | ExpectNone(*scroll_info, child->id()); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8257 | |
| 8258 | // As the locked layer is at it's limit, no further scrolling can occur. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8259 | EXPECT_FALSE( |
| 8260 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 8261 | .did_scroll); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8262 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8263 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8264 | } |
| 8265 | } |
| 8266 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8267 | TEST_F(LayerTreeHostImplTest, WheelFlingShouldntBubble) { |
| 8268 | // When flinging via wheel, we shouldn't bubble. |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8269 | gfx::Size surface_size(10, 10); |
| 8270 | gfx::Size content_size(20, 20); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8271 | std::unique_ptr<LayerImpl> root_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8272 | LayerImpl::Create(host_impl_->active_tree(), 3); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8273 | root_clip->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8274 | std::unique_ptr<LayerImpl> root_scroll = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8275 | CreateScrollableLayer(1, content_size, root_clip.get()); |
| 8276 | int root_scroll_id = root_scroll->id(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8277 | std::unique_ptr<LayerImpl> child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8278 | CreateScrollableLayer(2, content_size, root_clip.get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8279 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8280 | root_scroll->test_properties()->AddChild(std::move(child)); |
| 8281 | root_clip->test_properties()->AddChild(std::move(root_scroll)); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8282 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8283 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_clip)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8284 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8285 | host_impl_->active_tree()->DidBecomeActive(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8286 | |
| 8287 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 8288 | DrawFrame(); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8289 | { |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8290 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8291 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8292 | InputHandler::WHEEL) |
| 8293 | .thread); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8294 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8295 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 8296 | host_impl_->FlingScrollBegin().thread); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8297 | |
| 8298 | gfx::Vector2d scroll_delta(0, 100); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8299 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 8300 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8301 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8302 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8303 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8304 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8305 | host_impl_->ProcessScrollDeltas(); |
| 8306 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8307 | // The root shouldn't have scrolled. |
| 8308 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
| 8309 | ExpectNone(*scroll_info.get(), root_scroll_id); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8310 | } |
| 8311 | } |
| 8312 | |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8313 | TEST_F(LayerTreeHostImplTest, ScrollUnknownNotOnAncestorChain) { |
| 8314 | // If we ray cast a scroller that is not on the first layer's ancestor chain, |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8315 | // we should return SCROLL_UNKNOWN. |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8316 | gfx::Size content_size(100, 100); |
| 8317 | SetupScrollAndContentsLayers(content_size); |
| 8318 | |
| 8319 | int scroll_layer_id = 2; |
| 8320 | LayerImpl* scroll_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8321 | host_impl_->active_tree()->LayerById(scroll_layer_id); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8322 | scroll_layer->SetDrawsContent(true); |
| 8323 | |
| 8324 | int page_scale_layer_id = 5; |
| 8325 | LayerImpl* page_scale_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8326 | host_impl_->active_tree()->LayerById(page_scale_layer_id); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8327 | |
| 8328 | int occluder_layer_id = 6; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8329 | std::unique_ptr<LayerImpl> occluder_layer = |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8330 | LayerImpl::Create(host_impl_->active_tree(), occluder_layer_id); |
| 8331 | occluder_layer->SetDrawsContent(true); |
| 8332 | occluder_layer->SetBounds(content_size); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8333 | occluder_layer->SetPosition(gfx::PointF()); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8334 | |
| 8335 | // The parent of the occluder is *above* the scroller. |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8336 | page_scale_layer->test_properties()->AddChild(std::move(occluder_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8337 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8338 | |
| 8339 | DrawFrame(); |
| 8340 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8341 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 8342 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 8343 | EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 8344 | EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8345 | status.main_thread_scrolling_reasons); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8346 | } |
| 8347 | |
| 8348 | TEST_F(LayerTreeHostImplTest, ScrollUnknownScrollAncestorMismatch) { |
| 8349 | // If we ray cast a scroller this is on the first layer's ancestor chain, but |
| 8350 | // is not the first scroller we encounter when walking up from the layer, we |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8351 | // should also return SCROLL_UNKNOWN. |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8352 | gfx::Size content_size(100, 100); |
| 8353 | SetupScrollAndContentsLayers(content_size); |
| 8354 | |
| 8355 | int scroll_layer_id = 2; |
| 8356 | LayerImpl* scroll_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8357 | host_impl_->active_tree()->LayerById(scroll_layer_id); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8358 | scroll_layer->SetDrawsContent(true); |
| 8359 | |
| 8360 | int occluder_layer_id = 6; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8361 | std::unique_ptr<LayerImpl> occluder_layer = |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8362 | LayerImpl::Create(host_impl_->active_tree(), occluder_layer_id); |
| 8363 | occluder_layer->SetDrawsContent(true); |
| 8364 | occluder_layer->SetBounds(content_size); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8365 | occluder_layer->SetPosition(gfx::PointF(-10.f, -10.f)); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8366 | |
| 8367 | int child_scroll_clip_layer_id = 7; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8368 | std::unique_ptr<LayerImpl> child_scroll_clip = |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8369 | LayerImpl::Create(host_impl_->active_tree(), child_scroll_clip_layer_id); |
| 8370 | |
| 8371 | int child_scroll_layer_id = 8; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8372 | std::unique_ptr<LayerImpl> child_scroll = CreateScrollableLayer( |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8373 | child_scroll_layer_id, content_size, child_scroll_clip.get()); |
| 8374 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8375 | child_scroll->SetPosition(gfx::PointF(10.f, 10.f)); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8376 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8377 | child_scroll->test_properties()->AddChild(std::move(occluder_layer)); |
| 8378 | child_scroll_clip->test_properties()->AddChild(std::move(child_scroll)); |
| 8379 | scroll_layer->test_properties()->AddChild(std::move(child_scroll_clip)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8380 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8381 | |
| 8382 | DrawFrame(); |
| 8383 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8384 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 8385 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 8386 | EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 8387 | EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8388 | status.main_thread_scrolling_reasons); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8389 | } |
| 8390 | |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8391 | TEST_F(LayerTreeHostImplTest, NotScrollInvisibleScroller) { |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8392 | gfx::Size content_size(100, 100); |
| 8393 | SetupScrollAndContentsLayers(content_size); |
| 8394 | |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8395 | LayerImpl* root = host_impl_->active_tree()->LayerById(1); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8396 | |
| 8397 | int scroll_layer_id = 2; |
| 8398 | LayerImpl* scroll_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8399 | host_impl_->active_tree()->LayerById(scroll_layer_id); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8400 | |
| 8401 | int child_scroll_layer_id = 7; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8402 | std::unique_ptr<LayerImpl> child_scroll = |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8403 | CreateScrollableLayer(child_scroll_layer_id, content_size, root); |
| 8404 | child_scroll->SetDrawsContent(false); |
| 8405 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8406 | scroll_layer->test_properties()->AddChild(std::move(child_scroll)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8407 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8408 | |
| 8409 | DrawFrame(); |
| 8410 | |
| 8411 | // We should not have scrolled |child_scroll| even though we technically "hit" |
| 8412 | // it. The reason for this is that if the scrolling the scroll would not move |
| 8413 | // any layer that is a drawn RSLL member, then we can ignore the hit. |
| 8414 | // |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8415 | // Why SCROLL_STARTED? In this case, it's because we've bubbled out and |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8416 | // started scrolling the inner viewport. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8417 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8418 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8419 | InputHandler::WHEEL) |
| 8420 | .thread); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8421 | |
| 8422 | EXPECT_EQ(2, host_impl_->CurrentlyScrollingLayer()->id()); |
| 8423 | } |
| 8424 | |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8425 | TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleDescendent) { |
| 8426 | gfx::Size content_size(100, 100); |
| 8427 | SetupScrollAndContentsLayers(content_size); |
| 8428 | |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8429 | LayerImpl* root = host_impl_->active_tree()->LayerById(1); |
| 8430 | LayerImpl* root_scroll_layer = host_impl_->active_tree()->LayerById(2); |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8431 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8432 | std::unique_ptr<LayerImpl> invisible_scroll_layer = |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8433 | CreateScrollableLayer(7, content_size, root); |
| 8434 | invisible_scroll_layer->SetDrawsContent(false); |
| 8435 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8436 | std::unique_ptr<LayerImpl> child_layer = |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8437 | LayerImpl::Create(host_impl_->active_tree(), 8); |
| 8438 | child_layer->SetDrawsContent(false); |
| 8439 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8440 | std::unique_ptr<LayerImpl> grand_child_layer = |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8441 | LayerImpl::Create(host_impl_->active_tree(), 9); |
| 8442 | grand_child_layer->SetDrawsContent(true); |
| 8443 | grand_child_layer->SetBounds(content_size); |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8444 | // Move the grand child so it's not hit by our test point. |
| 8445 | grand_child_layer->SetPosition(gfx::PointF(10.f, 10.f)); |
| 8446 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8447 | child_layer->test_properties()->AddChild(std::move(grand_child_layer)); |
| 8448 | invisible_scroll_layer->test_properties()->AddChild(std::move(child_layer)); |
| 8449 | root_scroll_layer->test_properties()->AddChild( |
| 8450 | std::move(invisible_scroll_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8451 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8452 | |
| 8453 | DrawFrame(); |
| 8454 | |
| 8455 | // We should have scrolled |invisible_scroll_layer| as it was hit and it has |
| 8456 | // a descendant which is a drawn RSLL member. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8457 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8458 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8459 | InputHandler::WHEEL) |
| 8460 | .thread); |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8461 | |
| 8462 | EXPECT_EQ(7, host_impl_->CurrentlyScrollingLayer()->id()); |
| 8463 | } |
| 8464 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8465 | TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleScrollChild) { |
| 8466 | // This test case is very similar to the one above with one key difference: |
| 8467 | // the invisible scroller has a scroll child that is indeed draw contents. |
| 8468 | // If we attempt to initiate a gesture scroll off of the visible scroll child |
| 8469 | // we should still start the scroll child. |
| 8470 | gfx::Size content_size(100, 100); |
| 8471 | SetupScrollAndContentsLayers(content_size); |
| 8472 | |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8473 | LayerImpl* root = host_impl_->active_tree()->LayerById(1); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8474 | |
| 8475 | int scroll_layer_id = 2; |
| 8476 | LayerImpl* scroll_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8477 | host_impl_->active_tree()->LayerById(scroll_layer_id); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8478 | |
| 8479 | int scroll_child_id = 6; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8480 | std::unique_ptr<LayerImpl> scroll_child = |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8481 | LayerImpl::Create(host_impl_->active_tree(), scroll_child_id); |
| 8482 | scroll_child->SetDrawsContent(true); |
| 8483 | scroll_child->SetBounds(content_size); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8484 | // Move the scroll child so it's not hit by our test point. |
| 8485 | scroll_child->SetPosition(gfx::PointF(10.f, 10.f)); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8486 | |
| 8487 | int invisible_scroll_layer_id = 7; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8488 | std::unique_ptr<LayerImpl> invisible_scroll = |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8489 | CreateScrollableLayer(invisible_scroll_layer_id, content_size, root); |
| 8490 | invisible_scroll->SetDrawsContent(false); |
| 8491 | |
| 8492 | int container_id = 8; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8493 | std::unique_ptr<LayerImpl> container = |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8494 | LayerImpl::Create(host_impl_->active_tree(), container_id); |
| 8495 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8496 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 8497 | new std::set<LayerImpl*>); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8498 | scroll_children->insert(scroll_child.get()); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 8499 | invisible_scroll->test_properties()->scroll_children.reset( |
| 8500 | scroll_children.release()); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8501 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 8502 | scroll_child->test_properties()->scroll_parent = invisible_scroll.get(); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8503 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8504 | container->test_properties()->AddChild(std::move(invisible_scroll)); |
| 8505 | container->test_properties()->AddChild(std::move(scroll_child)); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8506 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8507 | scroll_layer->test_properties()->AddChild(std::move(container)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8508 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8509 | |
| 8510 | DrawFrame(); |
| 8511 | |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8512 | // We should have scrolled |child_scroll| even though it is invisible. |
| 8513 | // The reason for this is that if the scrolling the scroll would move a layer |
| 8514 | // that is a drawn RSLL member, then we should accept this hit. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8515 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8516 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8517 | InputHandler::WHEEL) |
| 8518 | .thread); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8519 | |
| 8520 | EXPECT_EQ(7, host_impl_->CurrentlyScrollingLayer()->id()); |
| 8521 | } |
| 8522 | |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8523 | // Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 8524 | // in CompositorFrameMetadata. |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8525 | TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8526 | std::unique_ptr<SolidColorLayerImpl> root = |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8527 | SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8528 | root->SetPosition(gfx::PointF()); |
| 8529 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8530 | root->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8531 | root->test_properties()->force_render_surface = true; |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8532 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8533 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8534 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8535 | |
| 8536 | FakeOutputSurface* fake_output_surface = |
| 8537 | static_cast<FakeOutputSurface*>(host_impl_->output_surface()); |
| 8538 | |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8539 | ui::LatencyInfo latency_info; |
| 8540 | latency_info.AddLatencyNumber( |
| 8541 | ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, 0); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8542 | std::unique_ptr<SwapPromise> swap_promise( |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8543 | new LatencyInfoSwapPromise(latency_info)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 8544 | host_impl_->active_tree()->QueuePinnedSwapPromise(std::move(swap_promise)); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8545 | |
| 8546 | gfx::Rect full_frame_damage(host_impl_->DrawViewportSize()); |
| 8547 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8548 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 8549 | EXPECT_TRUE(host_impl_->DrawLayers(&frame)); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8550 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8551 | |
[email protected] | b76029b | 2014-01-02 22:56:50 | [diff] [blame] | 8552 | const std::vector<ui::LatencyInfo>& metadata_latency_after = |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 8553 | fake_output_surface->last_sent_frame()->metadata.latency_info; |
[email protected] | b76029b | 2014-01-02 22:56:50 | [diff] [blame] | 8554 | EXPECT_EQ(1u, metadata_latency_after.size()); |
| 8555 | EXPECT_TRUE(metadata_latency_after[0].FindLatency( |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8556 | ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, NULL)); |
| 8557 | } |
| 8558 | |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8559 | TEST_F(LayerTreeHostImplTest, SelectionBoundsPassedToCompositorFrameMetadata) { |
| 8560 | int root_layer_id = 1; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8561 | std::unique_ptr<SolidColorLayerImpl> root = |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8562 | SolidColorLayerImpl::Create(host_impl_->active_tree(), root_layer_id); |
| 8563 | root->SetPosition(gfx::PointF()); |
| 8564 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8565 | root->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8566 | root->test_properties()->force_render_surface = true; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8567 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8568 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8569 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8570 | |
| 8571 | // Ensure the default frame selection bounds are empty. |
| 8572 | FakeOutputSurface* fake_output_surface = |
| 8573 | static_cast<FakeOutputSurface*>(host_impl_->output_surface()); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8574 | |
| 8575 | // Plumb the layer-local selection bounds. |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 8576 | gfx::Point selection_top(5, 0); |
| 8577 | gfx::Point selection_bottom(5, 5); |
jdduke | 449b529 | 2015-04-23 19:36:44 | [diff] [blame] | 8578 | LayerSelection selection; |
fsamuel | 5ca57df | 2016-06-04 00:34:55 | [diff] [blame] | 8579 | selection.start.type = gfx::SelectionBound::CENTER; |
jdduke | 449b529 | 2015-04-23 19:36:44 | [diff] [blame] | 8580 | selection.start.layer_id = root_layer_id; |
| 8581 | selection.start.edge_bottom = selection_bottom; |
| 8582 | selection.start.edge_top = selection_top; |
| 8583 | selection.end = selection.start; |
| 8584 | host_impl_->active_tree()->RegisterSelection(selection); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8585 | |
| 8586 | // Trigger a draw-swap sequence. |
| 8587 | host_impl_->SetNeedsRedraw(); |
| 8588 | |
| 8589 | gfx::Rect full_frame_damage(host_impl_->DrawViewportSize()); |
| 8590 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8591 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 8592 | EXPECT_TRUE(host_impl_->DrawLayers(&frame)); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8593 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8594 | |
| 8595 | // Ensure the selection bounds have propagated to the frame metadata. |
fsamuel | 5ca57df | 2016-06-04 00:34:55 | [diff] [blame] | 8596 | const Selection<gfx::SelectionBound>& selection_after = |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 8597 | fake_output_surface->last_sent_frame()->metadata.selection; |
fsamuel | 5ca57df | 2016-06-04 00:34:55 | [diff] [blame] | 8598 | EXPECT_EQ(selection.start.type, selection_after.start.type()); |
| 8599 | EXPECT_EQ(selection.end.type, selection_after.end.type()); |
| 8600 | EXPECT_EQ(gfx::PointF(selection_bottom), selection_after.start.edge_bottom()); |
| 8601 | EXPECT_EQ(gfx::PointF(selection_top), selection_after.start.edge_top()); |
| 8602 | EXPECT_TRUE(selection_after.start.visible()); |
| 8603 | EXPECT_TRUE(selection_after.start.visible()); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8604 | } |
| 8605 | |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8606 | class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { |
| 8607 | public: |
| 8608 | SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, |
| 8609 | LayerTreeHostImpl* layer_tree_host_impl, |
| 8610 | int* set_needs_commit_count, |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8611 | int* set_needs_redraw_count, |
| 8612 | int* forward_to_main_count) |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8613 | : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), |
| 8614 | set_needs_commit_count_(set_needs_commit_count), |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8615 | set_needs_redraw_count_(set_needs_redraw_count), |
| 8616 | forward_to_main_count_(forward_to_main_count) {} |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8617 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 8618 | ~SimpleSwapPromiseMonitor() override {} |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8619 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 8620 | void OnSetNeedsCommitOnMain() override { (*set_needs_commit_count_)++; } |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8621 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 8622 | void OnSetNeedsRedrawOnImpl() override { (*set_needs_redraw_count_)++; } |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8623 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 8624 | void OnForwardScrollUpdateToMainThreadOnImpl() override { |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8625 | (*forward_to_main_count_)++; |
| 8626 | } |
| 8627 | |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8628 | private: |
| 8629 | int* set_needs_commit_count_; |
| 8630 | int* set_needs_redraw_count_; |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8631 | int* forward_to_main_count_; |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8632 | }; |
| 8633 | |
| 8634 | TEST_F(LayerTreeHostImplTest, SimpleSwapPromiseMonitor) { |
| 8635 | int set_needs_commit_count = 0; |
| 8636 | int set_needs_redraw_count = 0; |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8637 | int forward_to_main_count = 0; |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8638 | |
| 8639 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8640 | std::unique_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 8641 | new SimpleSwapPromiseMonitor( |
| 8642 | NULL, host_impl_.get(), &set_needs_commit_count, |
| 8643 | &set_needs_redraw_count, &forward_to_main_count)); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8644 | host_impl_->SetNeedsRedraw(); |
| 8645 | EXPECT_EQ(0, set_needs_commit_count); |
| 8646 | EXPECT_EQ(1, set_needs_redraw_count); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8647 | EXPECT_EQ(0, forward_to_main_count); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8648 | } |
| 8649 | |
| 8650 | // Now the monitor is destroyed, SetNeedsRedraw() is no longer being |
| 8651 | // monitored. |
| 8652 | host_impl_->SetNeedsRedraw(); |
| 8653 | EXPECT_EQ(0, set_needs_commit_count); |
| 8654 | EXPECT_EQ(1, set_needs_redraw_count); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8655 | EXPECT_EQ(0, forward_to_main_count); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8656 | |
| 8657 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8658 | std::unique_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 8659 | new SimpleSwapPromiseMonitor( |
| 8660 | NULL, host_impl_.get(), &set_needs_commit_count, |
| 8661 | &set_needs_redraw_count, &forward_to_main_count)); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8662 | host_impl_->SetNeedsRedrawRect(gfx::Rect(10, 10)); |
| 8663 | EXPECT_EQ(0, set_needs_commit_count); |
| 8664 | EXPECT_EQ(2, set_needs_redraw_count); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8665 | EXPECT_EQ(0, forward_to_main_count); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8666 | } |
| 8667 | |
| 8668 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8669 | std::unique_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 8670 | new SimpleSwapPromiseMonitor( |
| 8671 | NULL, host_impl_.get(), &set_needs_commit_count, |
| 8672 | &set_needs_redraw_count, &forward_to_main_count)); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8673 | // Empty damage rect won't signal the monitor. |
| 8674 | host_impl_->SetNeedsRedrawRect(gfx::Rect()); |
| 8675 | EXPECT_EQ(0, set_needs_commit_count); |
| 8676 | EXPECT_EQ(2, set_needs_redraw_count); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8677 | EXPECT_EQ(0, forward_to_main_count); |
| 8678 | } |
| 8679 | |
| 8680 | { |
| 8681 | set_needs_commit_count = 0; |
| 8682 | set_needs_redraw_count = 0; |
| 8683 | forward_to_main_count = 0; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8684 | std::unique_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 8685 | new SimpleSwapPromiseMonitor( |
| 8686 | NULL, host_impl_.get(), &set_needs_commit_count, |
| 8687 | &set_needs_redraw_count, &forward_to_main_count)); |
dtapuska | f024e55 | 2016-02-03 01:19:46 | [diff] [blame] | 8688 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8689 | |
| 8690 | // Scrolling normally should not trigger any forwarding. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8691 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8692 | host_impl_ |
| 8693 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8694 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8695 | .thread); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 8696 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8697 | host_impl_->ScrollBy( |
| 8698 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()) |
| 8699 | .did_scroll); |
| 8700 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8701 | |
| 8702 | EXPECT_EQ(0, set_needs_commit_count); |
| 8703 | EXPECT_EQ(1, set_needs_redraw_count); |
| 8704 | EXPECT_EQ(0, forward_to_main_count); |
| 8705 | |
| 8706 | // Scrolling with a scroll handler should defer the swap to the main |
| 8707 | // thread. |
dtapuska | f024e55 | 2016-02-03 01:19:46 | [diff] [blame] | 8708 | host_impl_->active_tree()->set_have_scroll_event_handlers(true); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8709 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8710 | host_impl_ |
| 8711 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8712 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8713 | .thread); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 8714 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8715 | host_impl_->ScrollBy( |
| 8716 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()) |
| 8717 | .did_scroll); |
| 8718 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8719 | |
| 8720 | EXPECT_EQ(0, set_needs_commit_count); |
| 8721 | EXPECT_EQ(2, set_needs_redraw_count); |
| 8722 | EXPECT_EQ(1, forward_to_main_count); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8723 | } |
| 8724 | } |
| 8725 | |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8726 | class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { |
| 8727 | public: |
danakj | aeb9506 | 2014-11-14 01:35:36 | [diff] [blame] | 8728 | void SetUp() override { |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8729 | LayerTreeSettings settings = DefaultSettings(); |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8730 | CreateHostImpl(settings, CreateOutputSurface()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8731 | host_impl_->active_tree()->set_top_controls_height(top_controls_height_); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 8732 | host_impl_->sync_tree()->set_top_controls_height(top_controls_height_); |
| 8733 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f); |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8734 | } |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8735 | |
| 8736 | protected: |
| 8737 | static const int top_controls_height_; |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8738 | }; |
| 8739 | |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8740 | const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50; |
| 8741 | |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8742 | TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 8743 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 8744 | scroll_layer->layer_tree_impl() |
| 8745 | ->property_trees() |
| 8746 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 8747 | gfx::ScrollOffset(0, 10)); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 8748 | BeginFrameArgs begin_frame_args = |
| 8749 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 8750 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 8751 | host_impl_->Animate(); |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8752 | EXPECT_FALSE(did_request_redraw_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 8753 | host_impl_->DidFinishImplFrame(); |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8754 | } |
| 8755 | |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8756 | TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsHeightIsCommitted) { |
| 8757 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 8758 | EXPECT_FALSE(did_request_redraw_); |
| 8759 | host_impl_->CreatePendingTree(); |
| 8760 | host_impl_->sync_tree()->set_top_controls_height(100); |
| 8761 | host_impl_->ActivateSyncTree(); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 8762 | EXPECT_EQ(100, host_impl_->top_controls_manager()->TopControlsHeight()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8763 | } |
| 8764 | |
| 8765 | TEST_F(LayerTreeHostImplWithTopControlsTest, |
| 8766 | TopControlsStayFullyVisibleOnHeightChange) { |
| 8767 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 8768 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8769 | |
| 8770 | host_impl_->CreatePendingTree(); |
| 8771 | host_impl_->sync_tree()->set_top_controls_height(0); |
| 8772 | host_impl_->ActivateSyncTree(); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 8773 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8774 | |
| 8775 | host_impl_->CreatePendingTree(); |
| 8776 | host_impl_->sync_tree()->set_top_controls_height(50); |
| 8777 | host_impl_->ActivateSyncTree(); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 8778 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8779 | } |
| 8780 | |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 8781 | TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 8782 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 8783 | scroll_layer->layer_tree_impl() |
| 8784 | ->property_trees() |
| 8785 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 8786 | gfx::ScrollOffset(0, 10)); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 8787 | host_impl_->DidChangeTopControlsPosition(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8788 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 8789 | EXPECT_TRUE(did_request_redraw_); |
| 8790 | } |
| 8791 | |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8792 | TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8793 | InputHandlerScrollResult result; |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8794 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8795 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 8796 | |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8797 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
bokan | 55b2f15 | 2014-09-15 14:47:59 | [diff] [blame] | 8798 | host_impl_->top_controls_manager()->UpdateTopControlsState( |
| 8799 | BOTH, SHOWN, false); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8800 | DrawFrame(); |
| 8801 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8802 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8803 | host_impl_ |
| 8804 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8805 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8806 | .thread); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8807 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8808 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8809 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8810 | |
| 8811 | // Scroll just the top controls and verify that the scroll succeeds. |
| 8812 | const float residue = 10; |
| 8813 | float offset = top_controls_height_ - residue; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8814 | result = host_impl_->ScrollBy( |
| 8815 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8816 | EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
| 8817 | EXPECT_TRUE(result.did_scroll); |
lof84 | c1f962df | 2015-03-10 19:03:43 | [diff] [blame] | 8818 | EXPECT_FLOAT_EQ(-offset, |
| 8819 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8820 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8821 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8822 | |
| 8823 | // Scroll across the boundary |
| 8824 | const float content_scroll = 20; |
| 8825 | offset = residue + content_scroll; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8826 | result = host_impl_->ScrollBy( |
| 8827 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8828 | EXPECT_TRUE(result.did_scroll); |
| 8829 | EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8830 | EXPECT_EQ(-top_controls_height_, |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8831 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8832 | EXPECT_EQ(gfx::Vector2dF(0, content_scroll).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8833 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8834 | |
| 8835 | // Now scroll back to the top of the content |
| 8836 | offset = -content_scroll; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8837 | result = host_impl_->ScrollBy( |
| 8838 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8839 | EXPECT_TRUE(result.did_scroll); |
| 8840 | EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8841 | EXPECT_EQ(-top_controls_height_, |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8842 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8843 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8844 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8845 | |
| 8846 | // And scroll the top controls completely into view |
| 8847 | offset = -top_controls_height_; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8848 | result = host_impl_->ScrollBy( |
| 8849 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8850 | EXPECT_TRUE(result.did_scroll); |
| 8851 | EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8852 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8853 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8854 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8855 | |
| 8856 | // And attempt to scroll past the end |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8857 | result = host_impl_->ScrollBy( |
| 8858 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8859 | EXPECT_FALSE(result.did_scroll); |
| 8860 | EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, -50)); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8861 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8862 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8863 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8864 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8865 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8866 | } |
| 8867 | |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8868 | TEST_F(LayerTreeHostImplWithTopControlsTest, WheelUnhandledByTopControls) { |
| 8869 | SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 8870 | host_impl_->SetViewportSize(gfx::Size(50, 100)); |
| 8871 | host_impl_->active_tree()->set_top_controls_shrink_blink_size(true); |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8872 | host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, |
| 8873 | false); |
| 8874 | DrawFrame(); |
| 8875 | |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 8876 | LayerImpl* viewport_layer = host_impl_->InnerViewportScrollLayer(); |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8877 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8878 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8879 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8880 | InputHandler::WHEEL) |
| 8881 | .thread); |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8882 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 8883 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), viewport_layer->CurrentScrollOffset()); |
| 8884 | |
| 8885 | // Wheel scrolls should not affect the top controls, and should pass |
| 8886 | // directly through to the viewport. |
| 8887 | const float delta = top_controls_height_; |
| 8888 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8889 | host_impl_->ScrollBy( |
| 8890 | UpdateState(gfx::Point(), gfx::Vector2d(0, delta)).get()) |
| 8891 | .did_scroll); |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8892 | EXPECT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 8893 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, delta), |
| 8894 | viewport_layer->CurrentScrollOffset()); |
| 8895 | |
| 8896 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8897 | host_impl_->ScrollBy( |
| 8898 | UpdateState(gfx::Point(), gfx::Vector2d(0, delta)).get()) |
| 8899 | .did_scroll); |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8900 | EXPECT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 8901 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, delta * 2), |
| 8902 | viewport_layer->CurrentScrollOffset()); |
| 8903 | } |
| 8904 | |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8905 | TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { |
| 8906 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8907 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 8908 | |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8909 | host_impl_->SetViewportSize(gfx::Size(100, 200)); |
bokan | 55b2f15 | 2014-09-15 14:47:59 | [diff] [blame] | 8910 | host_impl_->top_controls_manager()->UpdateTopControlsState( |
| 8911 | BOTH, SHOWN, false); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8912 | DrawFrame(); |
| 8913 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8914 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8915 | host_impl_ |
| 8916 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8917 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8918 | .thread); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8919 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8920 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8921 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8922 | |
| 8923 | // Scroll the top controls partially. |
| 8924 | const float residue = 35; |
| 8925 | float offset = top_controls_height_ - residue; |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 8926 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8927 | host_impl_->ScrollBy( |
| 8928 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 8929 | .did_scroll); |
lof84 | c1f962df | 2015-03-10 19:03:43 | [diff] [blame] | 8930 | EXPECT_FLOAT_EQ(-offset, |
| 8931 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8932 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8933 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8934 | |
| 8935 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8936 | did_request_next_frame_ = false; |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8937 | did_request_commit_ = false; |
| 8938 | |
| 8939 | // End the scroll while the controls are still offset from their limit. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8940 | host_impl_->ScrollEnd(EndState().get()); |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 8941 | ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8942 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8943 | EXPECT_TRUE(did_request_redraw_); |
| 8944 | EXPECT_FALSE(did_request_commit_); |
| 8945 | |
| 8946 | // The top controls should properly animate until finished, despite the scroll |
| 8947 | // offset being at the origin. |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 8948 | BeginFrameArgs begin_frame_args = CreateBeginFrameArgsForTesting( |
| 8949 | BEGINFRAME_FROM_HERE, base::TimeTicks::Now()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8950 | while (did_request_next_frame_) { |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8951 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8952 | did_request_next_frame_ = false; |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8953 | did_request_commit_ = false; |
| 8954 | |
| 8955 | float old_offset = |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8956 | host_impl_->top_controls_manager()->ControlsTopOffset(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8957 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 8958 | begin_frame_args.frame_time += base::TimeDelta::FromMilliseconds(5); |
| 8959 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 8960 | host_impl_->Animate(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8961 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8962 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8963 | |
| 8964 | float new_offset = |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8965 | host_impl_->top_controls_manager()->ControlsTopOffset(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8966 | |
| 8967 | // No commit is needed as the controls are animating the content offset, |
| 8968 | // not the scroll offset. |
| 8969 | EXPECT_FALSE(did_request_commit_); |
| 8970 | |
| 8971 | if (new_offset != old_offset) |
| 8972 | EXPECT_TRUE(did_request_redraw_); |
| 8973 | |
| 8974 | if (new_offset != 0) { |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 8975 | EXPECT_TRUE(host_impl_->top_controls_manager()->has_animation()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8976 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8977 | } |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 8978 | host_impl_->DidFinishImplFrame(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8979 | } |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 8980 | EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8981 | } |
| 8982 | |
| 8983 | TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { |
| 8984 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8985 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 8986 | |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8987 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
bokan | 55b2f15 | 2014-09-15 14:47:59 | [diff] [blame] | 8988 | host_impl_->top_controls_manager()->UpdateTopControlsState( |
| 8989 | BOTH, SHOWN, false); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8990 | float initial_scroll_offset = 50; |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 8991 | scroll_layer->layer_tree_impl() |
| 8992 | ->property_trees() |
| 8993 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 8994 | scroll_layer->id(), gfx::ScrollOffset(0, initial_scroll_offset)); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8995 | DrawFrame(); |
| 8996 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8997 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8998 | host_impl_ |
| 8999 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9000 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9001 | .thread); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 9002 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9003 | EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9004 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9005 | |
| 9006 | // Scroll the top controls partially. |
| 9007 | const float residue = 15; |
| 9008 | float offset = top_controls_height_ - residue; |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 9009 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9010 | host_impl_->ScrollBy( |
| 9011 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 9012 | .did_scroll); |
lof84 | c1f962df | 2015-03-10 19:03:43 | [diff] [blame] | 9013 | EXPECT_FLOAT_EQ(-offset, |
| 9014 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9015 | EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9016 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9017 | |
| 9018 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9019 | did_request_next_frame_ = false; |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9020 | did_request_commit_ = false; |
| 9021 | |
| 9022 | // End the scroll while the controls are still offset from the limit. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9023 | host_impl_->ScrollEnd(EndState().get()); |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 9024 | ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9025 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9026 | EXPECT_TRUE(did_request_redraw_); |
| 9027 | EXPECT_FALSE(did_request_commit_); |
| 9028 | |
| 9029 | // Animate the top controls to the limit. |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9030 | BeginFrameArgs begin_frame_args = CreateBeginFrameArgsForTesting( |
| 9031 | BEGINFRAME_FROM_HERE, base::TimeTicks::Now()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9032 | while (did_request_next_frame_) { |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9033 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9034 | did_request_next_frame_ = false; |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9035 | did_request_commit_ = false; |
| 9036 | |
| 9037 | float old_offset = |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 9038 | host_impl_->top_controls_manager()->ControlsTopOffset(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9039 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9040 | begin_frame_args.frame_time += base::TimeDelta::FromMilliseconds(5); |
| 9041 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 9042 | host_impl_->Animate(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9043 | |
| 9044 | float new_offset = |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 9045 | host_impl_->top_controls_manager()->ControlsTopOffset(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9046 | |
| 9047 | if (new_offset != old_offset) { |
| 9048 | EXPECT_TRUE(did_request_redraw_); |
| 9049 | EXPECT_TRUE(did_request_commit_); |
| 9050 | } |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9051 | host_impl_->DidFinishImplFrame(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9052 | } |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 9053 | EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation()); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9054 | EXPECT_EQ(-top_controls_height_, |
| 9055 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9056 | } |
| 9057 | |
| 9058 | TEST_F(LayerTreeHostImplWithTopControlsTest, |
| 9059 | TopControlsAnimationAfterMainThreadFlingStopped) { |
| 9060 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9061 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 9062 | |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9063 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 9064 | host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, |
| 9065 | false); |
| 9066 | float initial_scroll_offset = 50; |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 9067 | scroll_layer->layer_tree_impl() |
| 9068 | ->property_trees() |
| 9069 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 9070 | scroll_layer->id(), gfx::ScrollOffset(0, initial_scroll_offset)); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9071 | DrawFrame(); |
| 9072 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9073 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9074 | host_impl_ |
| 9075 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9076 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9077 | .thread); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9078 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9079 | EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
| 9080 | scroll_layer->CurrentScrollOffset().ToString()); |
| 9081 | |
| 9082 | // Scroll the top controls partially. |
| 9083 | const float residue = 15; |
| 9084 | float offset = top_controls_height_ - residue; |
| 9085 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9086 | host_impl_->ScrollBy( |
| 9087 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 9088 | .did_scroll); |
lof84 | c1f962df | 2015-03-10 19:03:43 | [diff] [blame] | 9089 | EXPECT_FLOAT_EQ(-offset, |
| 9090 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9091 | EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
| 9092 | scroll_layer->CurrentScrollOffset().ToString()); |
| 9093 | |
| 9094 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9095 | did_request_next_frame_ = false; |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9096 | did_request_commit_ = false; |
| 9097 | |
| 9098 | // End the fling while the controls are still offset from the limit. |
| 9099 | host_impl_->MainThreadHasStoppedFlinging(); |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 9100 | ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9101 | EXPECT_TRUE(did_request_next_frame_); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9102 | EXPECT_TRUE(did_request_redraw_); |
| 9103 | EXPECT_FALSE(did_request_commit_); |
| 9104 | |
| 9105 | // Animate the top controls to the limit. |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9106 | BeginFrameArgs begin_frame_args = CreateBeginFrameArgsForTesting( |
| 9107 | BEGINFRAME_FROM_HERE, base::TimeTicks::Now()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9108 | while (did_request_next_frame_) { |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9109 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9110 | did_request_next_frame_ = false; |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9111 | did_request_commit_ = false; |
| 9112 | |
| 9113 | float old_offset = host_impl_->top_controls_manager()->ControlsTopOffset(); |
| 9114 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9115 | begin_frame_args.frame_time += base::TimeDelta::FromMilliseconds(5); |
| 9116 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 9117 | host_impl_->Animate(); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9118 | |
| 9119 | float new_offset = host_impl_->top_controls_manager()->ControlsTopOffset(); |
| 9120 | |
| 9121 | if (new_offset != old_offset) { |
| 9122 | EXPECT_TRUE(did_request_redraw_); |
| 9123 | EXPECT_TRUE(did_request_commit_); |
| 9124 | } |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9125 | host_impl_->DidFinishImplFrame(); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9126 | } |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 9127 | EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation()); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9128 | EXPECT_EQ(-top_controls_height_, |
| 9129 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9130 | } |
| 9131 | |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9132 | TEST_F(LayerTreeHostImplWithTopControlsTest, |
| 9133 | TopControlsScrollDeltaInOverScroll) { |
tdresser | 96f4a2b | 2015-07-15 14:11:54 | [diff] [blame] | 9134 | // Verifies that the overscroll delta should not have accumulated in |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9135 | // the top controls if we do a hide and show without releasing finger. |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9136 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9137 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 9138 | |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9139 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 9140 | host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, |
| 9141 | false); |
sunxd | 22ecae6 | 2016-02-11 21:38:12 | [diff] [blame] | 9142 | DrawFrame(); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9143 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9144 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9145 | host_impl_ |
| 9146 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9147 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9148 | .thread); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9149 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9150 | |
| 9151 | float offset = 50; |
| 9152 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9153 | host_impl_->ScrollBy( |
| 9154 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 9155 | .did_scroll); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9156 | EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9157 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9158 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9159 | |
| 9160 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9161 | host_impl_->ScrollBy( |
| 9162 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 9163 | .did_scroll); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9164 | EXPECT_EQ(gfx::Vector2dF(0, offset).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9165 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9166 | |
| 9167 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9168 | host_impl_->ScrollBy( |
| 9169 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 9170 | .did_scroll); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9171 | |
| 9172 | // Should have fully scrolled |
| 9173 | EXPECT_EQ(gfx::Vector2dF(0, scroll_layer->MaxScrollOffset().y()).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9174 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9175 | |
| 9176 | float overscrollamount = 10; |
| 9177 | |
| 9178 | // Overscroll the content |
| 9179 | EXPECT_FALSE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9180 | host_impl_->ScrollBy(UpdateState(gfx::Point(), |
| 9181 | gfx::Vector2d(0, overscrollamount)) |
| 9182 | .get()) |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9183 | .did_scroll); |
| 9184 | EXPECT_EQ(gfx::Vector2dF(0, 2 * offset).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9185 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9186 | EXPECT_EQ(gfx::Vector2dF(0, overscrollamount).ToString(), |
| 9187 | host_impl_->accumulated_root_overscroll().ToString()); |
| 9188 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9189 | EXPECT_TRUE(host_impl_->ScrollBy(UpdateState(gfx::Point(), |
| 9190 | gfx::Vector2d(0, -2 * offset)) |
| 9191 | .get()) |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9192 | .did_scroll); |
| 9193 | EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9194 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9195 | EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9196 | |
| 9197 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9198 | host_impl_->ScrollBy( |
| 9199 | UpdateState(gfx::Point(), gfx::Vector2d(0, -offset)).get()) |
| 9200 | .did_scroll); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9201 | EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9202 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9203 | |
| 9204 | // Top controls should be fully visible |
| 9205 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9206 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9207 | host_impl_->ScrollEnd(EndState().get()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9208 | } |
| 9209 | |
bokan | bc115b4 | 2016-08-22 13:46:32 | [diff] [blame] | 9210 | // Tests that when we set a child scroller (e.g. a scrolling div) as the outer |
| 9211 | // viewport, scrolling it controls the top controls. |
| 9212 | TEST_F(LayerTreeHostImplTopControlsTest, |
| 9213 | ReplacedOuterViewportScrollsTopControls) { |
| 9214 | const gfx::Size scroll_content_size(400, 400); |
| 9215 | const gfx::Size root_layer_size(200, 200); |
| 9216 | const gfx::Size viewport_size(100, 100); |
| 9217 | |
| 9218 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 9219 | viewport_size, viewport_size, root_layer_size); |
| 9220 | |
| 9221 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9222 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 9223 | LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 9224 | LayerImpl* scroll_layer = nullptr; |
| 9225 | |
| 9226 | // Initialization: Add a child scrolling layer to the outer scroll layer and |
| 9227 | // set its scroll layer as the outer viewport. This simulates setting a |
| 9228 | // scrolling element as the root scroller on the page. |
| 9229 | { |
| 9230 | std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10); |
| 9231 | clip->SetBounds(root_layer_size); |
| 9232 | clip->SetPosition(gfx::PointF()); |
| 9233 | |
| 9234 | std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11); |
| 9235 | scroll->SetBounds(scroll_content_size); |
| 9236 | scroll->SetScrollClipLayer(clip->id()); |
| 9237 | scroll->SetDrawsContent(true); |
| 9238 | |
| 9239 | scroll_layer = scroll.get(); |
| 9240 | |
| 9241 | clip->test_properties()->AddChild(std::move(scroll)); |
| 9242 | outer_scroll->test_properties()->AddChild(std::move(clip)); |
| 9243 | layer_tree_impl->SetViewportLayersFromIds( |
| 9244 | Layer::INVALID_ID, layer_tree_impl->PageScaleLayer()->id(), |
| 9245 | inner_scroll->id(), scroll_layer->id()); |
| 9246 | layer_tree_impl->BuildPropertyTreesForTesting(); |
| 9247 | DrawFrame(); |
| 9248 | } |
| 9249 | |
| 9250 | ASSERT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 9251 | |
| 9252 | // Scrolling should scroll the child content and the top controls. The |
| 9253 | // original outer viewport should get no scroll. |
| 9254 | { |
| 9255 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 9256 | InputHandler::TOUCHSCREEN); |
| 9257 | host_impl_->ScrollBy( |
| 9258 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 9259 | host_impl_->ScrollEnd(EndState().get()); |
| 9260 | |
| 9261 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll->CurrentScrollOffset()); |
| 9262 | EXPECT_VECTOR_EQ(gfx::Vector2dF(100.f, 50.f), |
| 9263 | scroll_layer->CurrentScrollOffset()); |
| 9264 | EXPECT_EQ(0.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 9265 | } |
| 9266 | } |
| 9267 | |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9268 | class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { |
| 9269 | public: |
| 9270 | void SetupVirtualViewportLayers(const gfx::Size& content_size, |
| 9271 | const gfx::Size& outer_viewport, |
| 9272 | const gfx::Size& inner_viewport) { |
| 9273 | LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 9274 | const int kOuterViewportClipLayerId = 6; |
| 9275 | const int kOuterViewportScrollLayerId = 7; |
| 9276 | const int kInnerViewportScrollLayerId = 2; |
| 9277 | const int kInnerViewportClipLayerId = 4; |
| 9278 | const int kPageScaleLayerId = 5; |
| 9279 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9280 | std::unique_ptr<LayerImpl> inner_scroll = |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9281 | LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 9282 | inner_scroll->test_properties()->is_container_for_fixed_position_layers = |
| 9283 | true; |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 9284 | inner_scroll->layer_tree_impl() |
| 9285 | ->property_trees() |
| 9286 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(inner_scroll->id(), |
| 9287 | gfx::ScrollOffset()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9288 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9289 | std::unique_ptr<LayerImpl> inner_clip = |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9290 | LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); |
| 9291 | inner_clip->SetBounds(inner_viewport); |
| 9292 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9293 | std::unique_ptr<LayerImpl> page_scale = |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9294 | LayerImpl::Create(layer_tree_impl, kPageScaleLayerId); |
| 9295 | |
| 9296 | inner_scroll->SetScrollClipLayer(inner_clip->id()); |
| 9297 | inner_scroll->SetBounds(outer_viewport); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9298 | inner_scroll->SetPosition(gfx::PointF()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9299 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9300 | std::unique_ptr<LayerImpl> outer_clip = |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9301 | LayerImpl::Create(layer_tree_impl, kOuterViewportClipLayerId); |
| 9302 | outer_clip->SetBounds(outer_viewport); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 9303 | outer_clip->test_properties()->is_container_for_fixed_position_layers = |
| 9304 | true; |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9305 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9306 | std::unique_ptr<LayerImpl> outer_scroll = |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9307 | LayerImpl::Create(layer_tree_impl, kOuterViewportScrollLayerId); |
| 9308 | outer_scroll->SetScrollClipLayer(outer_clip->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 9309 | outer_scroll->layer_tree_impl() |
| 9310 | ->property_trees() |
| 9311 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(outer_scroll->id(), |
| 9312 | gfx::ScrollOffset()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9313 | outer_scroll->SetBounds(content_size); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9314 | outer_scroll->SetPosition(gfx::PointF()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9315 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9316 | std::unique_ptr<LayerImpl> contents = LayerImpl::Create(layer_tree_impl, 8); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9317 | contents->SetDrawsContent(true); |
| 9318 | contents->SetBounds(content_size); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9319 | contents->SetPosition(gfx::PointF()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9320 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9321 | outer_scroll->test_properties()->AddChild(std::move(contents)); |
| 9322 | outer_clip->test_properties()->AddChild(std::move(outer_scroll)); |
| 9323 | inner_scroll->test_properties()->AddChild(std::move(outer_clip)); |
| 9324 | page_scale->test_properties()->AddChild(std::move(inner_scroll)); |
| 9325 | inner_clip->test_properties()->AddChild(std::move(page_scale)); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9326 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9327 | inner_clip->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9328 | layer_tree_impl->SetRootLayerForTesting(std::move(inner_clip)); |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 9329 | layer_tree_impl->SetViewportLayersFromIds( |
| 9330 | Layer::INVALID_ID, kPageScaleLayerId, kInnerViewportScrollLayerId, |
| 9331 | kOuterViewportScrollLayerId); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9332 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9333 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9334 | host_impl_->active_tree()->DidBecomeActive(); |
| 9335 | } |
| 9336 | }; |
| 9337 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 9338 | TEST_F(LayerTreeHostImplVirtualViewportTest, ScrollBothInnerAndOuterLayer) { |
| 9339 | gfx::Size content_size = gfx::Size(100, 160); |
| 9340 | gfx::Size outer_viewport = gfx::Size(50, 80); |
| 9341 | gfx::Size inner_viewport = gfx::Size(25, 40); |
| 9342 | |
| 9343 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
| 9344 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 9345 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9346 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9347 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 9348 | DrawFrame(); |
| 9349 | { |
| 9350 | gfx::ScrollOffset inner_expected; |
| 9351 | gfx::ScrollOffset outer_expected; |
| 9352 | EXPECT_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9353 | EXPECT_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
| 9354 | |
| 9355 | gfx::ScrollOffset current_offset(70.f, 100.f); |
| 9356 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 9357 | host_impl_->SetSynchronousInputHandlerRootScrollOffset(current_offset); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 9358 | EXPECT_EQ(gfx::ScrollOffset(25.f, 40.f), inner_scroll->MaxScrollOffset()); |
| 9359 | EXPECT_EQ(gfx::ScrollOffset(50.f, 80.f), outer_scroll->MaxScrollOffset()); |
| 9360 | |
| 9361 | // Outer viewport scrolls first. Then the rest is applied to the inner |
| 9362 | // viewport. |
| 9363 | EXPECT_EQ(gfx::ScrollOffset(20.f, 20.f), |
| 9364 | inner_scroll->CurrentScrollOffset()); |
| 9365 | EXPECT_EQ(gfx::ScrollOffset(50.f, 80.f), |
| 9366 | outer_scroll->CurrentScrollOffset()); |
| 9367 | } |
| 9368 | } |
| 9369 | |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9370 | TEST_F(LayerTreeHostImplVirtualViewportTest, FlingScrollBubblesToInner) { |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9371 | gfx::Size content_size = gfx::Size(200, 320); |
| 9372 | gfx::Size outer_viewport = gfx::Size(100, 160); |
| 9373 | gfx::Size inner_viewport = gfx::Size(50, 80); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9374 | |
| 9375 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
| 9376 | |
| 9377 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9378 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9379 | |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9380 | DrawFrame(); |
| 9381 | { |
| 9382 | gfx::Vector2dF inner_expected; |
| 9383 | gfx::Vector2dF outer_expected; |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9384 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9385 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9386 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9387 | // Scrolling the viewport always sets the outer scroll layer as the |
| 9388 | // currently scrolling layer. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9389 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9390 | host_impl_ |
| 9391 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9392 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9393 | .thread); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9394 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9395 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9396 | host_impl_->FlingScrollBegin().thread); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9397 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9398 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9399 | gfx::Vector2d scroll_delta(inner_viewport.width() / 2.f, |
| 9400 | inner_viewport.height() / 2.f); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9401 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9402 | inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9403 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9404 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9405 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 9406 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
jdduke | 2491ebe | 2015-08-10 15:41:15 | [diff] [blame] | 9407 | EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9408 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9409 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9410 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9411 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9412 | // Fling past the inner viewport boundry, make sure outer viewport scrolls. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9413 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9414 | host_impl_ |
| 9415 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9416 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9417 | .thread); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9418 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9419 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9420 | host_impl_->FlingScrollBegin().thread); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9421 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9422 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9423 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9424 | inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9425 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9426 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9427 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9428 | outer_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9429 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9430 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9431 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 9432 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
jdduke | 2491ebe | 2015-08-10 15:41:15 | [diff] [blame] | 9433 | EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9434 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9435 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9436 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9437 | } |
| 9438 | } |
| 9439 | |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9440 | TEST_F(LayerTreeHostImplVirtualViewportTest, |
| 9441 | DiagonalScrollBubblesPerfectlyToInner) { |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9442 | gfx::Size content_size = gfx::Size(200, 320); |
| 9443 | gfx::Size outer_viewport = gfx::Size(100, 160); |
| 9444 | gfx::Size inner_viewport = gfx::Size(50, 80); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9445 | |
| 9446 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
| 9447 | |
| 9448 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9449 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9450 | |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9451 | DrawFrame(); |
| 9452 | { |
| 9453 | gfx::Vector2dF inner_expected; |
| 9454 | gfx::Vector2dF outer_expected; |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9455 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9456 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9457 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9458 | // Make sure the scroll goes to the inner viewport first. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9459 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9460 | host_impl_ |
| 9461 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9462 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9463 | .thread); |
| 9464 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9465 | host_impl_->FlingScrollBegin().thread); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9466 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 9467 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9468 | |
| 9469 | // Scroll near the edge of the outer viewport. |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9470 | gfx::Vector2d scroll_delta(inner_viewport.width() / 2.f, |
| 9471 | inner_viewport.height() / 2.f); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9472 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9473 | inner_expected += scroll_delta; |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9474 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 9475 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9476 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9477 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9478 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9479 | |
| 9480 | // Now diagonal scroll across the outer viewport boundary in a single event. |
| 9481 | // The entirety of the scroll should be consumed, as bubbling between inner |
| 9482 | // and outer viewport layers is perfect. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9483 | host_impl_->ScrollBy( |
| 9484 | UpdateState(gfx::Point(), gfx::ScaleVector2d(scroll_delta, 2)).get()); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9485 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 9486 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9487 | outer_expected += scroll_delta; |
| 9488 | inner_expected += scroll_delta; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9489 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 9490 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
jdduke | 366df48 | 2015-05-05 01:07:56 | [diff] [blame] | 9491 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9492 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9493 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9494 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9495 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9496 | } |
| 9497 | } |
| 9498 | |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9499 | TEST_F(LayerTreeHostImplVirtualViewportTest, |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9500 | TouchFlingDoesntSwitchScrollingLayer) { |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9501 | gfx::Size content_size = gfx::Size(100, 160); |
| 9502 | gfx::Size outer_viewport = gfx::Size(50, 80); |
| 9503 | gfx::Size inner_viewport = gfx::Size(25, 40); |
| 9504 | |
| 9505 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
| 9506 | |
| 9507 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9508 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 9509 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9510 | std::unique_ptr<LayerImpl> child = |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9511 | CreateScrollableLayer(10, outer_viewport, outer_scroll); |
| 9512 | LayerImpl* child_scroll = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9513 | outer_scroll->test_properties()->children[0]->test_properties()->AddChild( |
| 9514 | std::move(child)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9515 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9516 | |
| 9517 | DrawFrame(); |
| 9518 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9519 | std::unique_ptr<ScrollAndScaleSet> scroll_info; |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9520 | |
| 9521 | gfx::Vector2d scroll_delta(0, inner_viewport.height()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9522 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9523 | host_impl_ |
| 9524 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9525 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9526 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9527 | EXPECT_TRUE( |
| 9528 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 9529 | .did_scroll); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9530 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 9531 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9532 | |
| 9533 | // The child should have scrolled up to its limit. |
| 9534 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 9535 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 9536 | EXPECT_TRUE( |
| 9537 | ScrollInfoContains(*scroll_info, child_scroll->id(), scroll_delta)); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9538 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); |
| 9539 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9540 | // The fling have no effect on the currently scrolling layer. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9541 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9542 | host_impl_->FlingScrollBegin().thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9543 | EXPECT_FALSE( |
| 9544 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 9545 | .did_scroll); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9546 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9547 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 9548 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9549 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9550 | // The inner viewport shouldn't have scrolled. |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9551 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9552 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 9553 | EXPECT_TRUE( |
| 9554 | ScrollInfoContains(*scroll_info, child_scroll->id(), scroll_delta)); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9555 | ExpectNone(*scroll_info, inner_scroll->id()); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9556 | |
| 9557 | // As the locked layer is at its limit, no further scrolling can occur. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9558 | EXPECT_FALSE( |
| 9559 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 9560 | .did_scroll); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9561 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9562 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 9563 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
jdduke | 366df48 | 2015-05-05 01:07:56 | [diff] [blame] | 9564 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9565 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9566 | } |
| 9567 | } |
| 9568 | |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9569 | TEST_F(LayerTreeHostImplVirtualViewportTest, |
| 9570 | ScrollBeginEventThatTargetsViewportLayerSkipsHitTest) { |
| 9571 | gfx::Size content_size = gfx::Size(100, 160); |
| 9572 | gfx::Size outer_viewport = gfx::Size(50, 80); |
| 9573 | gfx::Size inner_viewport = gfx::Size(25, 40); |
| 9574 | |
| 9575 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
| 9576 | |
| 9577 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9578 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 9579 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9580 | std::unique_ptr<LayerImpl> child = |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9581 | CreateScrollableLayer(10, outer_viewport, outer_scroll); |
| 9582 | LayerImpl* child_scroll = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9583 | outer_scroll->test_properties()->children[0]->test_properties()->AddChild( |
| 9584 | std::move(child)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9585 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9586 | |
| 9587 | DrawFrame(); |
| 9588 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9589 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9590 | host_impl_ |
| 9591 | ->RootScrollBegin(BeginState(gfx::Point()).get(), |
| 9592 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9593 | .thread); |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9594 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9595 | host_impl_->ScrollEnd(EndState().get()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9596 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9597 | host_impl_ |
| 9598 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9599 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9600 | .thread); |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9601 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9602 | host_impl_->ScrollEnd(EndState().get()); |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9603 | } |
| 9604 | |
hugo.holgersson | e5e7aa9 | 2015-08-17 14:07:19 | [diff] [blame] | 9605 | TEST_F(LayerTreeHostImplVirtualViewportTest, |
| 9606 | NoOverscrollWhenInnerViewportCantScroll) { |
| 9607 | InputHandlerScrollResult scroll_result; |
| 9608 | gfx::Size content_size = gfx::Size(100, 160); |
| 9609 | gfx::Size outer_viewport = gfx::Size(50, 80); |
| 9610 | gfx::Size inner_viewport = gfx::Size(25, 40); |
| 9611 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
hugo.holgersson | e5e7aa9 | 2015-08-17 14:07:19 | [diff] [blame] | 9612 | // Make inner viewport unscrollable. |
| 9613 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 9614 | inner_scroll->set_user_scrollable_horizontal(false); |
| 9615 | inner_scroll->set_user_scrollable_vertical(false); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9616 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 9617 | |
sunxd | 2668bea6 | 2016-03-17 00:49:47 | [diff] [blame] | 9618 | DrawFrame(); |
hugo.holgersson | e5e7aa9 | 2015-08-17 14:07:19 | [diff] [blame] | 9619 | |
| 9620 | // Ensure inner viewport doesn't react to scrolls (test it's unscrollable). |
| 9621 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), inner_scroll->CurrentScrollOffset()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9622 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9623 | host_impl_ |
| 9624 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9625 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9626 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9627 | scroll_result = host_impl_->ScrollBy( |
| 9628 | UpdateState(gfx::Point(), gfx::Vector2dF(0, 100)).get()); |
hugo.holgersson | e5e7aa9 | 2015-08-17 14:07:19 | [diff] [blame] | 9629 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), inner_scroll->CurrentScrollOffset()); |
| 9630 | |
| 9631 | // When inner viewport is unscrollable, a fling gives zero overscroll. |
| 9632 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 9633 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
| 9634 | } |
| 9635 | |
[email protected] | 4bb0f31 | 2014-02-25 02:02:32 | [diff] [blame] | 9636 | class LayerTreeHostImplWithImplicitLimitsTest : public LayerTreeHostImplTest { |
| 9637 | public: |
danakj | aeb9506 | 2014-11-14 01:35:36 | [diff] [blame] | 9638 | void SetUp() override { |
[email protected] | 4bb0f31 | 2014-02-25 02:02:32 | [diff] [blame] | 9639 | LayerTreeSettings settings = DefaultSettings(); |
[email protected] | 4bb0f31 | 2014-02-25 02:02:32 | [diff] [blame] | 9640 | settings.max_memory_for_prepaint_percentage = 50; |
| 9641 | CreateHostImpl(settings, CreateOutputSurface()); |
| 9642 | } |
| 9643 | }; |
| 9644 | |
| 9645 | TEST_F(LayerTreeHostImplWithImplicitLimitsTest, ImplicitMemoryLimits) { |
| 9646 | // Set up a memory policy and percentages which could cause |
| 9647 | // 32-bit integer overflows. |
| 9648 | ManagedMemoryPolicy mem_policy(300 * 1024 * 1024); // 300MB |
| 9649 | |
| 9650 | // Verify implicit limits are calculated correctly with no overflows |
| 9651 | host_impl_->SetMemoryPolicy(mem_policy); |
| 9652 | EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, |
| 9653 | 300u * 1024u * 1024u); |
| 9654 | EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, |
| 9655 | 150u * 1024u * 1024u); |
[email protected] | 4bb0f31 | 2014-02-25 02:02:32 | [diff] [blame] | 9656 | } |
| 9657 | |
[email protected] | ea12b550 | 2014-06-24 21:37:36 | [diff] [blame] | 9658 | TEST_F(LayerTreeHostImplTest, ExternalTransformReflectedInNextDraw) { |
| 9659 | const gfx::Size layer_size(100, 100); |
| 9660 | gfx::Transform external_transform; |
| 9661 | const gfx::Rect external_viewport(layer_size); |
[email protected] | c05dfbb | 2014-07-10 22:49:04 | [diff] [blame] | 9662 | const bool resourceless_software_draw = false; |
[email protected] | ea12b550 | 2014-06-24 21:37:36 | [diff] [blame] | 9663 | LayerImpl* layer = SetupScrollAndContentsLayers(layer_size); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 9664 | layer->SetDrawsContent(true); |
[email protected] | ea12b550 | 2014-06-24 21:37:36 | [diff] [blame] | 9665 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9666 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9667 | external_transform); |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9668 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9669 | resourceless_software_draw); |
[email protected] | ea12b550 | 2014-06-24 21:37:36 | [diff] [blame] | 9670 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9671 | external_transform, layer->draw_properties().target_space_transform); |
| 9672 | |
| 9673 | external_transform.Translate(20, 20); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9674 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9675 | external_transform); |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9676 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9677 | resourceless_software_draw); |
[email protected] | ea12b550 | 2014-06-24 21:37:36 | [diff] [blame] | 9678 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9679 | external_transform, layer->draw_properties().target_space_transform); |
| 9680 | } |
| 9681 | |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9682 | TEST_F(LayerTreeHostImplTest, ExternalTransformSetNeedsRedraw) { |
| 9683 | SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9684 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9685 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9686 | const gfx::Size viewport_size(100, 100); |
| 9687 | host_impl_->SetViewportSize(viewport_size); |
| 9688 | |
| 9689 | const gfx::Transform transform_for_tile_priority; |
| 9690 | const gfx::Transform draw_transform; |
| 9691 | const gfx::Rect viewport_for_tile_priority1(viewport_size); |
| 9692 | const gfx::Rect viewport_for_tile_priority2(50, 50); |
| 9693 | const gfx::Rect draw_viewport(viewport_size); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9694 | bool resourceless_software_draw = false; |
| 9695 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9696 | // Clear any damage. |
| 9697 | host_impl_->SetExternalTilePriorityConstraints(viewport_for_tile_priority1, |
| 9698 | transform_for_tile_priority); |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9699 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9700 | last_on_draw_frame_.reset(); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9701 | |
| 9702 | // Setting new constraints needs redraw. |
| 9703 | did_request_redraw_ = false; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9704 | host_impl_->SetExternalTilePriorityConstraints(viewport_for_tile_priority2, |
| 9705 | transform_for_tile_priority); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9706 | EXPECT_TRUE(did_request_redraw_); |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9707 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9708 | EXPECT_FALSE(last_on_draw_frame_->has_no_damage); |
| 9709 | } |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9710 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9711 | TEST_F(LayerTreeHostImplTest, OnDrawConstraintSetNeedsRedraw) { |
| 9712 | SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9713 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9714 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9715 | const gfx::Size viewport_size(100, 100); |
| 9716 | host_impl_->SetViewportSize(viewport_size); |
| 9717 | |
| 9718 | const gfx::Transform draw_transform; |
| 9719 | const gfx::Rect draw_viewport1(viewport_size); |
| 9720 | const gfx::Rect draw_viewport2(50, 50); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9721 | bool resourceless_software_draw = false; |
| 9722 | |
| 9723 | // Clear any damage. |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9724 | host_impl_->OnDraw(draw_transform, draw_viewport1, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9725 | resourceless_software_draw); |
| 9726 | last_on_draw_frame_.reset(); |
| 9727 | |
| 9728 | // Same draw params does not swap. |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9729 | did_request_redraw_ = false; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9730 | host_impl_->OnDraw(draw_transform, draw_viewport1, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9731 | resourceless_software_draw); |
| 9732 | EXPECT_FALSE(did_request_redraw_); |
| 9733 | EXPECT_TRUE(last_on_draw_frame_->has_no_damage); |
| 9734 | last_on_draw_frame_.reset(); |
| 9735 | |
| 9736 | // Different draw params does swap. |
| 9737 | did_request_redraw_ = false; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9738 | host_impl_->OnDraw(draw_transform, draw_viewport2, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9739 | resourceless_software_draw); |
| 9740 | EXPECT_TRUE(did_request_redraw_); |
| 9741 | EXPECT_FALSE(last_on_draw_frame_->has_no_damage); |
| 9742 | } |
| 9743 | |
| 9744 | class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest { |
| 9745 | protected: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9746 | std::unique_ptr<OutputSurface> CreateOutputSurface() override { |
danakj | 554c98a | 2016-07-08 00:25:07 | [diff] [blame] | 9747 | return FakeOutputSurface::CreateDelegating3d(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9748 | } |
| 9749 | }; |
| 9750 | |
| 9751 | TEST_F(ResourcelessSoftwareLayerTreeHostImplTest, |
| 9752 | ResourcelessSoftwareSetNeedsRedraw) { |
| 9753 | SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9754 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9755 | |
| 9756 | const gfx::Size viewport_size(100, 100); |
| 9757 | host_impl_->SetViewportSize(viewport_size); |
| 9758 | |
| 9759 | const gfx::Transform draw_transform; |
| 9760 | const gfx::Rect draw_viewport(viewport_size); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9761 | bool resourceless_software_draw = false; |
| 9762 | |
| 9763 | // Clear any damage. |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9764 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9765 | last_on_draw_frame_.reset(); |
| 9766 | |
| 9767 | // Always swap even if same draw params. |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9768 | resourceless_software_draw = true; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9769 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9770 | EXPECT_FALSE(last_on_draw_frame_->has_no_damage); |
| 9771 | last_on_draw_frame_.reset(); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9772 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9773 | // Next hardware draw has damage. |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9774 | resourceless_software_draw = false; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9775 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9776 | EXPECT_FALSE(last_on_draw_frame_->has_no_damage); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9777 | } |
| 9778 | |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9779 | TEST_F(ResourcelessSoftwareLayerTreeHostImplTest, |
| 9780 | ResourcelessSoftwareDrawSkipsUpdateTiles) { |
| 9781 | const gfx::Size viewport_size(100, 100); |
| 9782 | host_impl_->SetViewportSize(viewport_size); |
| 9783 | |
| 9784 | host_impl_->CreatePendingTree(); |
vmpstr | 41d68f88 | 2016-03-30 01:20:23 | [diff] [blame] | 9785 | scoped_refptr<FakeRasterSource> raster_source( |
| 9786 | FakeRasterSource::CreateFilled(viewport_size)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9787 | std::unique_ptr<FakePictureLayerImpl> layer( |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9788 | FakePictureLayerImpl::CreateWithRasterSource(host_impl_->pending_tree(), |
| 9789 | 11, raster_source)); |
| 9790 | layer->SetBounds(viewport_size); |
| 9791 | layer->SetDrawsContent(true); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9792 | host_impl_->pending_tree()->SetRootLayerForTesting(std::move(layer)); |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9793 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9794 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9795 | host_impl_->ActivateSyncTree(); |
| 9796 | |
| 9797 | const gfx::Transform draw_transform; |
| 9798 | const gfx::Rect draw_viewport(viewport_size); |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9799 | bool resourceless_software_draw = false; |
| 9800 | |
| 9801 | // Regular draw causes UpdateTiles. |
| 9802 | did_request_prepare_tiles_ = false; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9803 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9804 | EXPECT_TRUE(did_request_prepare_tiles_); |
| 9805 | host_impl_->PrepareTiles(); |
| 9806 | |
| 9807 | // Resourceless draw skips UpdateTiles. |
| 9808 | const gfx::Rect new_draw_viewport(50, 50); |
| 9809 | resourceless_software_draw = true; |
| 9810 | did_request_prepare_tiles_ = false; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9811 | host_impl_->OnDraw(draw_transform, new_draw_viewport, |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9812 | resourceless_software_draw); |
| 9813 | EXPECT_FALSE(did_request_prepare_tiles_); |
| 9814 | } |
| 9815 | |
boliu | 5a1970d | 2016-02-08 21:58:01 | [diff] [blame] | 9816 | TEST_F(LayerTreeHostImplTest, ExternalTileConstraintReflectedInPendingTree) { |
| 9817 | EXPECT_FALSE(host_impl_->CommitToActiveTree()); |
| 9818 | const gfx::Size layer_size(100, 100); |
| 9819 | host_impl_->SetViewportSize(layer_size); |
| 9820 | bool update_lcd_text = false; |
| 9821 | |
| 9822 | // Set up active and pending tree. |
| 9823 | host_impl_->CreatePendingTree(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9824 | host_impl_->pending_tree()->SetRootLayerForTesting( |
boliu | 5a1970d | 2016-02-08 21:58:01 | [diff] [blame] | 9825 | LayerImpl::Create(host_impl_->pending_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9826 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
boliu | 5a1970d | 2016-02-08 21:58:01 | [diff] [blame] | 9827 | host_impl_->pending_tree()->UpdateDrawProperties(update_lcd_text); |
| 9828 | |
| 9829 | host_impl_->ActivateSyncTree(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9830 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | 5a1970d | 2016-02-08 21:58:01 | [diff] [blame] | 9831 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
| 9832 | |
| 9833 | host_impl_->CreatePendingTree(); |
| 9834 | host_impl_->pending_tree()->UpdateDrawProperties(update_lcd_text); |
| 9835 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
| 9836 | |
| 9837 | EXPECT_FALSE(host_impl_->pending_tree()->needs_update_draw_properties()); |
| 9838 | EXPECT_FALSE(host_impl_->active_tree()->needs_update_draw_properties()); |
| 9839 | |
| 9840 | // Update external constraints should set_needs_update_draw_properties on |
| 9841 | // both trees. |
| 9842 | gfx::Transform external_transform; |
| 9843 | gfx::Rect external_viewport(10, 20); |
| 9844 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9845 | external_transform); |
| 9846 | EXPECT_TRUE(host_impl_->pending_tree()->needs_update_draw_properties()); |
| 9847 | EXPECT_TRUE(host_impl_->active_tree()->needs_update_draw_properties()); |
| 9848 | } |
| 9849 | |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9850 | TEST_F(LayerTreeHostImplTest, ExternalViewportAffectsVisibleRects) { |
| 9851 | const gfx::Size layer_size(100, 100); |
| 9852 | SetupScrollAndContentsLayers(layer_size); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 9853 | LayerImpl* content_layer = host_impl_->active_tree() |
| 9854 | ->OuterViewportScrollLayer() |
| 9855 | ->test_properties() |
| 9856 | ->children[0]; |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9857 | |
| 9858 | bool update_lcd_text = false; |
| 9859 | |
| 9860 | host_impl_->SetViewportSize(gfx::Size(90, 90)); |
| 9861 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
| 9862 | EXPECT_EQ(gfx::Rect(90, 90), content_layer->visible_layer_rect()); |
| 9863 | |
| 9864 | gfx::Transform external_transform; |
| 9865 | gfx::Rect external_viewport(10, 20); |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9866 | bool resourceless_software_draw = false; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9867 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9868 | external_transform); |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9869 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9870 | resourceless_software_draw); |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9871 | EXPECT_EQ(gfx::Rect(10, 20), content_layer->visible_layer_rect()); |
| 9872 | |
| 9873 | // Clear the external viewport. |
| 9874 | external_viewport = gfx::Rect(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9875 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9876 | external_transform); |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9877 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9878 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9879 | resourceless_software_draw); |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9880 | EXPECT_EQ(gfx::Rect(90, 90), content_layer->visible_layer_rect()); |
| 9881 | } |
| 9882 | |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9883 | TEST_F(LayerTreeHostImplTest, ExternalTransformAffectsVisibleRects) { |
| 9884 | const gfx::Size layer_size(100, 100); |
| 9885 | SetupScrollAndContentsLayers(layer_size); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 9886 | LayerImpl* content_layer = host_impl_->active_tree() |
| 9887 | ->OuterViewportScrollLayer() |
| 9888 | ->test_properties() |
| 9889 | ->children[0]; |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9890 | |
| 9891 | bool update_lcd_text = false; |
| 9892 | |
| 9893 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 9894 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
| 9895 | EXPECT_EQ(gfx::Rect(50, 50), content_layer->visible_layer_rect()); |
| 9896 | |
| 9897 | gfx::Transform external_transform; |
| 9898 | external_transform.Translate(10, 10); |
| 9899 | external_transform.Scale(2, 2); |
| 9900 | gfx::Rect external_viewport; |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9901 | bool resourceless_software_draw = false; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9902 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9903 | external_transform); |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9904 | |
| 9905 | // Visible rects should now be shifted and scaled because of the external |
| 9906 | // transform. |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9907 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9908 | resourceless_software_draw); |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9909 | EXPECT_EQ(gfx::Rect(20, 20), content_layer->visible_layer_rect()); |
| 9910 | |
| 9911 | // Clear the external transform. |
| 9912 | external_transform = gfx::Transform(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9913 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9914 | external_transform); |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9915 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9916 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9917 | resourceless_software_draw); |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9918 | EXPECT_EQ(gfx::Rect(50, 50), content_layer->visible_layer_rect()); |
| 9919 | } |
| 9920 | |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9921 | TEST_F(LayerTreeHostImplTest, ExternalTransformAffectsSublayerScaleFactor) { |
| 9922 | const gfx::Size layer_size(100, 100); |
| 9923 | SetupScrollAndContentsLayers(layer_size); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 9924 | LayerImpl* content_layer = host_impl_->active_tree() |
| 9925 | ->OuterViewportScrollLayer() |
| 9926 | ->test_properties() |
| 9927 | ->children[0]; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9928 | content_layer->test_properties()->AddChild( |
| 9929 | LayerImpl::Create(host_impl_->active_tree(), 100)); |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 9930 | LayerImpl* test_layer = host_impl_->active_tree()->LayerById(100); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9931 | test_layer->test_properties()->force_render_surface = true; |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9932 | test_layer->SetDrawsContent(true); |
| 9933 | test_layer->SetBounds(layer_size); |
| 9934 | gfx::Transform perspective_transform; |
| 9935 | perspective_transform.ApplyPerspectiveDepth(2); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9936 | test_layer->test_properties()->transform = perspective_transform; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9937 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9938 | |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9939 | bool update_lcd_text = false; |
| 9940 | |
| 9941 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 9942 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
| 9943 | TransformNode* node = |
| 9944 | host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 9945 | test_layer->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9946 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9947 | |
| 9948 | gfx::Transform external_transform; |
| 9949 | external_transform.Translate(10, 10); |
| 9950 | external_transform.Scale(2, 2); |
| 9951 | gfx::Rect external_viewport; |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9952 | bool resourceless_software_draw = false; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9953 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9954 | external_transform); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9955 | |
| 9956 | // Transform node's sublayer scale should include the device transform scale. |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9957 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9958 | resourceless_software_draw); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9959 | node = host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 9960 | test_layer->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9961 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9962 | |
| 9963 | // Clear the external transform. |
| 9964 | external_transform = gfx::Transform(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9965 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9966 | external_transform); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9967 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9968 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9969 | resourceless_software_draw); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9970 | node = host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 9971 | test_layer->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9972 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9973 | } |
| 9974 | |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 9975 | TEST_F(LayerTreeHostImplTest, ScrollAnimated) { |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 9976 | const gfx::Size content_size(1000, 1000); |
| 9977 | const gfx::Size viewport_size(50, 100); |
| 9978 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
skobes | de5abdb8 | 2015-10-20 19:16:34 | [diff] [blame] | 9979 | |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 9980 | DrawFrame(); |
| 9981 | |
| 9982 | base::TimeTicks start_time = |
| 9983 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 9984 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9985 | BeginFrameArgs begin_frame_args = |
| 9986 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 9987 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9988 | EXPECT_EQ( |
| 9989 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9990 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 9991 | |
| 9992 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
skobes | de5abdb8 | 2015-10-20 19:16:34 | [diff] [blame] | 9993 | EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), scrolling_layer); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 9994 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9995 | begin_frame_args.frame_time = start_time; |
| 9996 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 9997 | host_impl_->Animate(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 9998 | host_impl_->UpdateAnimationState(true); |
| 9999 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 10000 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10001 | host_impl_->DidFinishImplFrame(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10002 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10003 | begin_frame_args.frame_time = |
| 10004 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10005 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10006 | host_impl_->Animate(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10007 | host_impl_->UpdateAnimationState(true); |
| 10008 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 10009 | float y = scrolling_layer->CurrentScrollOffset().y(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10010 | EXPECT_TRUE(y > 1 && y < 49); |
| 10011 | |
[email protected] | 7a7d5be | 2014-07-18 22:37:26 | [diff] [blame] | 10012 | // Update target. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10013 | EXPECT_EQ( |
| 10014 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10015 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10016 | host_impl_->DidFinishImplFrame(); |
[email protected] | 7a7d5be | 2014-07-18 22:37:26 | [diff] [blame] | 10017 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10018 | begin_frame_args.frame_time = |
| 10019 | start_time + base::TimeDelta::FromMilliseconds(200); |
| 10020 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10021 | host_impl_->Animate(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10022 | host_impl_->UpdateAnimationState(true); |
| 10023 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 10024 | y = scrolling_layer->CurrentScrollOffset().y(); |
[email protected] | 7a7d5be | 2014-07-18 22:37:26 | [diff] [blame] | 10025 | EXPECT_TRUE(y > 50 && y < 100); |
| 10026 | EXPECT_EQ(scrolling_layer, host_impl_->CurrentlyScrollingLayer()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10027 | host_impl_->DidFinishImplFrame(); |
[email protected] | 7a7d5be | 2014-07-18 22:37:26 | [diff] [blame] | 10028 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10029 | begin_frame_args.frame_time = |
| 10030 | start_time + base::TimeDelta::FromMilliseconds(250); |
| 10031 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10032 | host_impl_->Animate(); |
[email protected] | 7a7d5be | 2014-07-18 22:37:26 | [diff] [blame] | 10033 | host_impl_->UpdateAnimationState(true); |
| 10034 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 10035 | EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 10036 | scrolling_layer->CurrentScrollOffset()); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10037 | EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10038 | host_impl_->DidFinishImplFrame(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10039 | } |
| 10040 | |
sahel | ebcfc33 | 2016-09-01 00:13:37 | [diff] [blame] | 10041 | TEST_F(LayerTreeHostImplTest, SecondScrollAnimatedBeginNotIgnored) { |
| 10042 | const gfx::Size content_size(1000, 1000); |
| 10043 | const gfx::Size viewport_size(50, 100); |
| 10044 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10045 | |
| 10046 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10047 | host_impl_->ScrollAnimatedBegin(gfx::Point()).thread); |
| 10048 | |
| 10049 | // The second ScrollAnimatedBegin should not get ignored. |
| 10050 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10051 | host_impl_->ScrollAnimatedBegin(gfx::Point()).thread); |
| 10052 | } |
| 10053 | |
ymalik | 04da03c | 2016-08-18 18:38:16 | [diff] [blame] | 10054 | // Verfify that a smooth scroll animation doesn't jump when UpdateTarget gets |
| 10055 | // called before the animation is started. |
| 10056 | TEST_F(LayerTreeHostImplTest, AnimatedScrollUpdateTargetBeforeStarting) { |
| 10057 | const gfx::Size content_size(1000, 1000); |
| 10058 | const gfx::Size viewport_size(50, 100); |
| 10059 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10060 | |
| 10061 | DrawFrame(); |
| 10062 | |
| 10063 | base::TimeTicks start_time = |
| 10064 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(200); |
| 10065 | |
| 10066 | BeginFrameArgs begin_frame_args = |
| 10067 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10068 | begin_frame_args.frame_time = start_time; |
| 10069 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10070 | host_impl_->UpdateAnimationState(true); |
| 10071 | host_impl_->DidFinishImplFrame(); |
| 10072 | |
| 10073 | EXPECT_EQ( |
| 10074 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10075 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
| 10076 | // This will call ScrollOffsetAnimationCurve::UpdateTarget while the animation |
| 10077 | // created above is in state ANIMATION::WAITING_FOR_TARGET_AVAILABILITY and |
| 10078 | // doesn't have a start time. |
| 10079 | EXPECT_EQ( |
| 10080 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10081 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 100)).thread); |
| 10082 | |
| 10083 | begin_frame_args.frame_time = |
| 10084 | start_time + base::TimeDelta::FromMilliseconds(250); |
| 10085 | // This is when the animation above gets promoted to STARTING. |
| 10086 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10087 | host_impl_->UpdateAnimationState(true); |
| 10088 | host_impl_->DidFinishImplFrame(); |
| 10089 | |
| 10090 | begin_frame_args.frame_time = |
| 10091 | start_time + base::TimeDelta::FromMilliseconds(300); |
| 10092 | // This is when the animation above gets ticked. |
| 10093 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10094 | host_impl_->UpdateAnimationState(true); |
| 10095 | host_impl_->DidFinishImplFrame(); |
| 10096 | |
| 10097 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10098 | EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), scrolling_layer); |
| 10099 | |
| 10100 | // Verify no jump. |
| 10101 | float y = scrolling_layer->CurrentScrollOffset().y(); |
| 10102 | EXPECT_TRUE(y > 1 && y < 49); |
| 10103 | } |
| 10104 | |
ymalik | ddfc352 | 2016-09-05 18:40:37 | [diff] [blame] | 10105 | TEST_F(LayerTreeHostImplTest, ScrollAnimatedWithDelay) { |
| 10106 | const gfx::Size content_size(1000, 1000); |
| 10107 | const gfx::Size viewport_size(50, 100); |
| 10108 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10109 | |
| 10110 | DrawFrame(); |
| 10111 | |
| 10112 | base::TimeTicks start_time = |
| 10113 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10114 | BeginFrameArgs begin_frame_args = |
| 10115 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10116 | |
| 10117 | // Create animation with a 100ms delay. |
| 10118 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10119 | host_impl_ |
| 10120 | ->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 100), |
| 10121 | base::TimeDelta::FromMilliseconds(100)) |
| 10122 | .thread); |
| 10123 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10124 | EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), scrolling_layer); |
| 10125 | |
| 10126 | // First tick, animation is started. |
| 10127 | begin_frame_args.frame_time = start_time; |
| 10128 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10129 | host_impl_->UpdateAnimationState(true); |
| 10130 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
| 10131 | host_impl_->DidFinishImplFrame(); |
| 10132 | |
| 10133 | // Second tick after 50ms, animation should be half way done since |
| 10134 | // the duration due to delay is 100ms. |
| 10135 | begin_frame_args.frame_time = |
| 10136 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10137 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10138 | host_impl_->UpdateAnimationState(true); |
| 10139 | EXPECT_EQ(50, scrolling_layer->CurrentScrollOffset().y()); |
| 10140 | host_impl_->DidFinishImplFrame(); |
| 10141 | |
| 10142 | // Update target. |
| 10143 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10144 | host_impl_ |
| 10145 | ->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 100), |
| 10146 | base::TimeDelta::FromMilliseconds(150)) |
| 10147 | .thread); |
| 10148 | |
| 10149 | // Third tick after 100ms, should be at the target position since update |
| 10150 | // target was called with a large value of jank. |
| 10151 | begin_frame_args.frame_time = |
| 10152 | start_time + base::TimeDelta::FromMilliseconds(100); |
| 10153 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10154 | host_impl_->UpdateAnimationState(true); |
| 10155 | EXPECT_LT(100, scrolling_layer->CurrentScrollOffset().y()); |
| 10156 | } |
| 10157 | |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10158 | // Test that a smooth scroll offset animation is aborted when followed by a |
| 10159 | // non-smooth scroll offset animation. |
| 10160 | TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedAborted) { |
ymalik | 399b476 | 2016-01-25 16:10:17 | [diff] [blame] | 10161 | const gfx::Size content_size(1000, 1000); |
| 10162 | const gfx::Size viewport_size(500, 500); |
| 10163 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10164 | |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10165 | DrawFrame(); |
| 10166 | |
| 10167 | base::TimeTicks start_time = |
| 10168 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10169 | |
| 10170 | BeginFrameArgs begin_frame_args = |
| 10171 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10172 | |
| 10173 | // Perform animated scroll. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10174 | EXPECT_EQ( |
| 10175 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10176 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10177 | |
| 10178 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10179 | |
| 10180 | begin_frame_args.frame_time = start_time; |
| 10181 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10182 | host_impl_->Animate(); |
| 10183 | host_impl_->UpdateAnimationState(true); |
| 10184 | |
| 10185 | EXPECT_TRUE(host_impl_->animation_host()->HasAnyAnimationTargetingProperty( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10186 | scrolling_layer->element_id(), TargetProperty::SCROLL_OFFSET)); |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10187 | |
| 10188 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
| 10189 | host_impl_->DidFinishImplFrame(); |
| 10190 | |
| 10191 | begin_frame_args.frame_time = |
| 10192 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10193 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10194 | host_impl_->Animate(); |
| 10195 | host_impl_->UpdateAnimationState(true); |
| 10196 | |
| 10197 | float y = scrolling_layer->CurrentScrollOffset().y(); |
| 10198 | EXPECT_TRUE(y > 1 && y < 49); |
| 10199 | |
| 10200 | // Perform instant scroll. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10201 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10202 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, y)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10203 | InputHandler::WHEEL) |
| 10204 | .thread); |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10205 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(0, y), |
| 10206 | InputHandler::WHEEL)); |
| 10207 | host_impl_->ScrollBy( |
| 10208 | UpdateState(gfx::Point(0, y), gfx::Vector2d(0, 50)).get()); |
| 10209 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(0, y + 50), |
| 10210 | InputHandler::WHEEL)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10211 | std::unique_ptr<ScrollState> scroll_state_end = EndState(); |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 10212 | host_impl_->ScrollEnd(scroll_state_end.get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 10213 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10214 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(), |
| 10215 | InputHandler::WHEEL)); |
| 10216 | |
| 10217 | // The instant scroll should have marked the smooth scroll animation as |
| 10218 | // aborted. |
loyso | db73537f | 2016-03-14 05:07:45 | [diff] [blame] | 10219 | EXPECT_FALSE(host_impl_->animation_host()->HasActiveAnimationForTesting( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10220 | scrolling_layer->element_id())); |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10221 | |
| 10222 | EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(0, y + 50), |
| 10223 | scrolling_layer->CurrentScrollOffset()); |
| 10224 | EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
| 10225 | host_impl_->DidFinishImplFrame(); |
| 10226 | } |
| 10227 | |
ymalik | 4c34ac55 | 2016-05-26 00:58:29 | [diff] [blame] | 10228 | // Test that a smooth scroll offset animation is marked finished when aborted |
| 10229 | // with the needs_completion flag. The animation is then finished on the |
ymalik | 6581bb3e | 2016-03-01 07:32:07 | [diff] [blame] | 10230 | // main thread. |
| 10231 | TEST_F(LayerTreeHostImplTimelinesTest, |
| 10232 | ScrollAnimatedFinishedByMainThreadScrollingReason) { |
| 10233 | const gfx::Size content_size(1000, 1000); |
| 10234 | const gfx::Size viewport_size(500, 500); |
| 10235 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10236 | |
| 10237 | DrawFrame(); |
| 10238 | |
| 10239 | base::TimeTicks start_time = |
| 10240 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10241 | |
| 10242 | BeginFrameArgs begin_frame_args = |
| 10243 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10244 | |
| 10245 | // Perform animated scroll. |
| 10246 | EXPECT_EQ( |
| 10247 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10248 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 100)).thread); |
| 10249 | |
| 10250 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10251 | |
| 10252 | begin_frame_args.frame_time = start_time; |
| 10253 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10254 | host_impl_->Animate(); |
| 10255 | host_impl_->UpdateAnimationState(true); |
| 10256 | |
| 10257 | EXPECT_TRUE(host_impl_->animation_host()->HasAnyAnimationTargetingProperty( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10258 | scrolling_layer->element_id(), TargetProperty::SCROLL_OFFSET)); |
ymalik | 6581bb3e | 2016-03-01 07:32:07 | [diff] [blame] | 10259 | |
| 10260 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
| 10261 | host_impl_->DidFinishImplFrame(); |
| 10262 | |
| 10263 | begin_frame_args.frame_time = |
| 10264 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10265 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10266 | host_impl_->Animate(); |
| 10267 | host_impl_->UpdateAnimationState(true); |
| 10268 | |
| 10269 | float y = scrolling_layer->CurrentScrollOffset().y(); |
| 10270 | EXPECT_TRUE(y > 1 && y < 49); |
| 10271 | |
ymalik | 4c34ac55 | 2016-05-26 00:58:29 | [diff] [blame] | 10272 | // Abort animation. |
| 10273 | host_impl_->animation_host()->ScrollAnimationAbort(true /*needs_completion*/); |
ymalik | 6581bb3e | 2016-03-01 07:32:07 | [diff] [blame] | 10274 | host_impl_->UpdateAnimationState(true); |
| 10275 | |
ymalik | 4c34ac55 | 2016-05-26 00:58:29 | [diff] [blame] | 10276 | // Aborting with the needs completion param should have marked the smooth |
| 10277 | // scroll animation as finished. |
loyso | db73537f | 2016-03-14 05:07:45 | [diff] [blame] | 10278 | EXPECT_FALSE(host_impl_->animation_host()->HasActiveAnimationForTesting( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10279 | scrolling_layer->element_id())); |
ymalik | 6581bb3e | 2016-03-01 07:32:07 | [diff] [blame] | 10280 | EXPECT_TRUE(y > 1 && y < 49); |
| 10281 | EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
| 10282 | host_impl_->DidFinishImplFrame(); |
| 10283 | } |
| 10284 | |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10285 | // Evolved from LayerTreeHostImplTest.ScrollAnimated. |
| 10286 | TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimated) { |
ymalik | 399b476 | 2016-01-25 16:10:17 | [diff] [blame] | 10287 | const gfx::Size content_size(1000, 1000); |
| 10288 | const gfx::Size viewport_size(500, 500); |
| 10289 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10290 | |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10291 | DrawFrame(); |
| 10292 | |
| 10293 | base::TimeTicks start_time = |
| 10294 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10295 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10296 | BeginFrameArgs begin_frame_args = |
| 10297 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10298 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10299 | EXPECT_EQ( |
| 10300 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10301 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10302 | |
| 10303 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10304 | begin_frame_args.frame_time = start_time; |
| 10305 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10306 | host_impl_->Animate(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10307 | host_impl_->UpdateAnimationState(true); |
| 10308 | |
| 10309 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10310 | host_impl_->DidFinishImplFrame(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10311 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10312 | begin_frame_args.frame_time = |
| 10313 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10314 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10315 | host_impl_->Animate(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10316 | host_impl_->UpdateAnimationState(true); |
| 10317 | |
| 10318 | float y = scrolling_layer->CurrentScrollOffset().y(); |
| 10319 | EXPECT_TRUE(y > 1 && y < 49); |
| 10320 | |
| 10321 | // Update target. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10322 | EXPECT_EQ( |
| 10323 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10324 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10325 | host_impl_->DidFinishImplFrame(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10326 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10327 | begin_frame_args.frame_time = |
| 10328 | start_time + base::TimeDelta::FromMilliseconds(200); |
| 10329 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10330 | host_impl_->Animate(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10331 | host_impl_->UpdateAnimationState(true); |
| 10332 | |
| 10333 | y = scrolling_layer->CurrentScrollOffset().y(); |
| 10334 | EXPECT_TRUE(y > 50 && y < 100); |
| 10335 | EXPECT_EQ(scrolling_layer, host_impl_->CurrentlyScrollingLayer()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10336 | host_impl_->DidFinishImplFrame(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10337 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10338 | begin_frame_args.frame_time = |
| 10339 | start_time + base::TimeDelta::FromMilliseconds(250); |
| 10340 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10341 | host_impl_->Animate(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10342 | host_impl_->UpdateAnimationState(true); |
| 10343 | |
| 10344 | EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), |
| 10345 | scrolling_layer->CurrentScrollOffset()); |
| 10346 | EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10347 | host_impl_->DidFinishImplFrame(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10348 | } |
| 10349 | |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 10350 | // Test that the scroll delta for an animated scroll is distributed correctly |
| 10351 | // between the inner and outer viewport. |
| 10352 | TEST_F(LayerTreeHostImplTimelinesTest, ImplPinchZoomScrollAnimated) { |
| 10353 | const gfx::Size content_size(200, 200); |
| 10354 | const gfx::Size viewport_size(100, 100); |
| 10355 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10356 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 10357 | |
| 10358 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
| 10359 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 10360 | |
| 10361 | // Zoom into the page by a 2X factor |
| 10362 | float min_page_scale = 1.f, max_page_scale = 4.f; |
| 10363 | float page_scale_factor = 2.f; |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 10364 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
| 10365 | page_scale_factor, min_page_scale, max_page_scale); |
| 10366 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
| 10367 | |
| 10368 | // Scroll by a small amount, there should be no bubbling to the outer |
| 10369 | // viewport. |
| 10370 | base::TimeTicks start_time = |
| 10371 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(250); |
| 10372 | BeginFrameArgs begin_frame_args = |
| 10373 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10374 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10375 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(10.f, 20.f)) |
| 10376 | .thread); |
| 10377 | host_impl_->Animate(); |
| 10378 | host_impl_->UpdateAnimationState(true); |
| 10379 | EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10380 | |
| 10381 | BeginImplFrameAndAnimate(begin_frame_args, start_time); |
| 10382 | EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 10), |
| 10383 | inner_scroll_layer->CurrentScrollOffset()); |
| 10384 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 10385 | outer_scroll_layer->CurrentScrollOffset()); |
| 10386 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll_layer->CurrentScrollOffset()); |
| 10387 | |
| 10388 | // Scroll by the inner viewport's max scroll extent, the remainder |
| 10389 | // should bubble up to the outer viewport. |
| 10390 | EXPECT_EQ( |
| 10391 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10392 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(100.f, 100.f)) |
| 10393 | .thread); |
| 10394 | host_impl_->Animate(); |
| 10395 | host_impl_->UpdateAnimationState(true); |
| 10396 | EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10397 | |
| 10398 | BeginImplFrameAndAnimate(begin_frame_args, |
| 10399 | start_time + base::TimeDelta::FromMilliseconds(350)); |
| 10400 | EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 50), |
| 10401 | inner_scroll_layer->CurrentScrollOffset()); |
| 10402 | EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 10), |
| 10403 | outer_scroll_layer->CurrentScrollOffset()); |
| 10404 | |
| 10405 | // Scroll by the outer viewport's max scroll extent, it should all go to the |
| 10406 | // outer viewport. |
| 10407 | EXPECT_EQ( |
| 10408 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10409 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(190.f, 180.f)) |
| 10410 | .thread); |
| 10411 | host_impl_->Animate(); |
| 10412 | host_impl_->UpdateAnimationState(true); |
| 10413 | EXPECT_EQ(outer_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10414 | |
| 10415 | BeginImplFrameAndAnimate(begin_frame_args, |
| 10416 | start_time + base::TimeDelta::FromMilliseconds(850)); |
| 10417 | EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 50), |
| 10418 | inner_scroll_layer->CurrentScrollOffset()); |
| 10419 | EXPECT_VECTOR_EQ(gfx::Vector2dF(100, 100), |
| 10420 | outer_scroll_layer->CurrentScrollOffset()); |
| 10421 | |
| 10422 | // Scroll upwards by the max scroll extent. The inner viewport should animate |
| 10423 | // and the remainder should bubble to the outer viewport. |
| 10424 | EXPECT_EQ( |
| 10425 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10426 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(-110.f, -120.f)) |
| 10427 | .thread); |
| 10428 | host_impl_->Animate(); |
| 10429 | host_impl_->UpdateAnimationState(true); |
| 10430 | EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10431 | |
| 10432 | BeginImplFrameAndAnimate( |
| 10433 | begin_frame_args, start_time + base::TimeDelta::FromMilliseconds(1200)); |
| 10434 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 10435 | inner_scroll_layer->CurrentScrollOffset()); |
| 10436 | EXPECT_VECTOR_EQ(gfx::Vector2dF(95, 90), |
| 10437 | outer_scroll_layer->CurrentScrollOffset()); |
| 10438 | } |
| 10439 | |
| 10440 | // Test that the correct viewport scroll layer is updated when the target offset |
| 10441 | // is updated. |
| 10442 | TEST_F(LayerTreeHostImplTimelinesTest, ImplPinchZoomScrollAnimatedUpdate) { |
| 10443 | const gfx::Size content_size(200, 200); |
| 10444 | const gfx::Size viewport_size(100, 100); |
| 10445 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10446 | |
| 10447 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
| 10448 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 10449 | |
| 10450 | // Zoom into the page by a 2X factor |
| 10451 | float min_page_scale = 1.f, max_page_scale = 4.f; |
| 10452 | float page_scale_factor = 2.f; |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 10453 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
| 10454 | page_scale_factor, min_page_scale, max_page_scale); |
| 10455 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
| 10456 | |
| 10457 | // Scroll the inner viewport. |
| 10458 | base::TimeTicks start_time = |
| 10459 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(50); |
| 10460 | BeginFrameArgs begin_frame_args = |
| 10461 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10462 | EXPECT_EQ( |
| 10463 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10464 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(90, 90)).thread); |
| 10465 | host_impl_->Animate(); |
| 10466 | host_impl_->UpdateAnimationState(true); |
| 10467 | EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10468 | |
| 10469 | BeginImplFrameAndAnimate(begin_frame_args, start_time); |
| 10470 | float inner_x = inner_scroll_layer->CurrentScrollOffset().x(); |
| 10471 | float inner_y = inner_scroll_layer->CurrentScrollOffset().y(); |
| 10472 | EXPECT_TRUE(inner_x > 0 && inner_x < 45); |
| 10473 | EXPECT_TRUE(inner_y > 0 && inner_y < 45); |
| 10474 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 10475 | outer_scroll_layer->CurrentScrollOffset()); |
| 10476 | |
| 10477 | // Update target. |
| 10478 | EXPECT_EQ( |
| 10479 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10480 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(50, 50)).thread); |
| 10481 | host_impl_->Animate(); |
| 10482 | host_impl_->UpdateAnimationState(true); |
| 10483 | EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10484 | |
| 10485 | // Verify that all the delta is applied to the inner viewport and nothing is |
| 10486 | // carried forward. |
| 10487 | BeginImplFrameAndAnimate(begin_frame_args, |
| 10488 | start_time + base::TimeDelta::FromMilliseconds(350)); |
| 10489 | EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 50), |
| 10490 | inner_scroll_layer->CurrentScrollOffset()); |
| 10491 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 10492 | outer_scroll_layer->CurrentScrollOffset()); |
| 10493 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll_layer->CurrentScrollOffset()); |
| 10494 | } |
| 10495 | |
ymalik | 399b476 | 2016-01-25 16:10:17 | [diff] [blame] | 10496 | // Test that smooth scroll offset animation doesn't happen for non user |
| 10497 | // scrollable layers. |
| 10498 | TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedNotUserScrollable) { |
| 10499 | const gfx::Size content_size(1000, 1000); |
| 10500 | const gfx::Size viewport_size(500, 500); |
| 10501 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10502 | |
| 10503 | host_impl_->OuterViewportScrollLayer()->set_user_scrollable_vertical(true); |
| 10504 | host_impl_->OuterViewportScrollLayer()->set_user_scrollable_horizontal(false); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10505 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
ymalik | 399b476 | 2016-01-25 16:10:17 | [diff] [blame] | 10506 | |
| 10507 | DrawFrame(); |
| 10508 | |
| 10509 | base::TimeTicks start_time = |
| 10510 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10511 | |
| 10512 | BeginFrameArgs begin_frame_args = |
| 10513 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10514 | |
| 10515 | EXPECT_EQ( |
| 10516 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10517 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(50, 50)).thread); |
| 10518 | |
| 10519 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10520 | begin_frame_args.frame_time = start_time; |
| 10521 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10522 | host_impl_->Animate(); |
| 10523 | host_impl_->UpdateAnimationState(true); |
| 10524 | |
| 10525 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
| 10526 | host_impl_->DidFinishImplFrame(); |
| 10527 | |
| 10528 | begin_frame_args.frame_time = |
| 10529 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10530 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10531 | host_impl_->Animate(); |
| 10532 | host_impl_->UpdateAnimationState(true); |
| 10533 | |
| 10534 | // Should not have scrolled horizontally. |
| 10535 | EXPECT_EQ(0, scrolling_layer->CurrentScrollOffset().x()); |
| 10536 | float y = scrolling_layer->CurrentScrollOffset().y(); |
| 10537 | EXPECT_TRUE(y > 1 && y < 49); |
| 10538 | |
| 10539 | // Update target. |
| 10540 | EXPECT_EQ( |
| 10541 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10542 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(50, 50)).thread); |
| 10543 | host_impl_->DidFinishImplFrame(); |
| 10544 | |
| 10545 | begin_frame_args.frame_time = |
| 10546 | start_time + base::TimeDelta::FromMilliseconds(200); |
| 10547 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10548 | host_impl_->Animate(); |
| 10549 | host_impl_->UpdateAnimationState(true); |
| 10550 | |
| 10551 | y = scrolling_layer->CurrentScrollOffset().y(); |
| 10552 | EXPECT_TRUE(y > 50 && y < 100); |
| 10553 | EXPECT_EQ(scrolling_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10554 | host_impl_->DidFinishImplFrame(); |
| 10555 | |
| 10556 | begin_frame_args.frame_time = |
| 10557 | start_time + base::TimeDelta::FromMilliseconds(250); |
| 10558 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10559 | host_impl_->Animate(); |
| 10560 | host_impl_->UpdateAnimationState(true); |
| 10561 | |
| 10562 | EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), |
| 10563 | scrolling_layer->CurrentScrollOffset()); |
| 10564 | EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
| 10565 | host_impl_->DidFinishImplFrame(); |
| 10566 | } |
| 10567 | |
skobes | 4d7f47cc8 | 2016-05-04 22:05:41 | [diff] [blame] | 10568 | // Test that smooth scrolls clamp correctly when bounds change mid-animation. |
| 10569 | TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedChangingBounds) { |
| 10570 | const gfx::Size old_content_size(1000, 1000); |
| 10571 | const gfx::Size new_content_size(750, 750); |
| 10572 | const gfx::Size viewport_size(500, 500); |
| 10573 | |
| 10574 | LayerImpl* content_layer = |
| 10575 | CreateBasicVirtualViewportLayers(viewport_size, old_content_size); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10576 | |
skobes | 4d7f47cc8 | 2016-05-04 22:05:41 | [diff] [blame] | 10577 | DrawFrame(); |
| 10578 | |
| 10579 | base::TimeTicks start_time = |
| 10580 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10581 | BeginFrameArgs begin_frame_args = |
| 10582 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10583 | |
| 10584 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(500, 500)); |
| 10585 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10586 | |
| 10587 | begin_frame_args.frame_time = start_time; |
| 10588 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10589 | host_impl_->Animate(); |
| 10590 | host_impl_->UpdateAnimationState(true); |
| 10591 | host_impl_->DidFinishImplFrame(); |
| 10592 | |
| 10593 | content_layer->SetBounds(new_content_size); |
| 10594 | scrolling_layer->SetBounds(new_content_size); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10595 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 10596 | |
skobes | 4d7f47cc8 | 2016-05-04 22:05:41 | [diff] [blame] | 10597 | DrawFrame(); |
| 10598 | |
| 10599 | begin_frame_args.frame_time = |
| 10600 | start_time + base::TimeDelta::FromMilliseconds(200); |
| 10601 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10602 | host_impl_->Animate(); |
| 10603 | host_impl_->UpdateAnimationState(true); |
| 10604 | host_impl_->DidFinishImplFrame(); |
| 10605 | |
| 10606 | EXPECT_EQ(gfx::ScrollOffset(250, 250), |
| 10607 | scrolling_layer->CurrentScrollOffset()); |
| 10608 | } |
| 10609 | |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10610 | TEST_F(LayerTreeHostImplTest, InvalidLayerNotAddedToRasterQueue) { |
| 10611 | host_impl_->CreatePendingTree(); |
| 10612 | |
| 10613 | Region empty_invalidation; |
vmpstr | 41d68f88 | 2016-03-30 01:20:23 | [diff] [blame] | 10614 | scoped_refptr<RasterSource> raster_source_with_tiles( |
| 10615 | FakeRasterSource::CreateFilled(gfx::Size(10, 10))); |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10616 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10617 | std::unique_ptr<FakePictureLayerImpl> layer = |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10618 | FakePictureLayerImpl::Create(host_impl_->pending_tree(), 11); |
| 10619 | layer->SetBounds(gfx::Size(10, 10)); |
| 10620 | layer->set_gpu_raster_max_texture_size(host_impl_->device_viewport_size()); |
| 10621 | layer->SetDrawsContent(true); |
vmpstr | 85674026 | 2015-09-24 00:25:25 | [diff] [blame] | 10622 | layer->tilings()->AddTiling(1.0f, raster_source_with_tiles); |
| 10623 | layer->UpdateRasterSource(raster_source_with_tiles, &empty_invalidation, |
| 10624 | nullptr); |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10625 | layer->tilings()->tiling_at(0)->set_resolution( |
| 10626 | TileResolution::HIGH_RESOLUTION); |
| 10627 | layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
vmpstr | cf11133 | 2016-05-04 21:20:43 | [diff] [blame] | 10628 | layer->tilings()->UpdateTilePriorities(gfx::Rect(gfx::Size(10, 10)), 1.f, 1.0, |
| 10629 | Occlusion(), true); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10630 | host_impl_->pending_tree()->SetRootLayerForTesting(std::move(layer)); |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10631 | |
| 10632 | FakePictureLayerImpl* root_layer = static_cast<FakePictureLayerImpl*>( |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10633 | host_impl_->pending_tree()->root_layer_for_testing()); |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10634 | |
| 10635 | root_layer->set_has_valid_tile_priorities(true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10636 | std::unique_ptr<RasterTilePriorityQueue> non_empty_raster_priority_queue_all = |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10637 | host_impl_->BuildRasterQueue(TreePriority::SAME_PRIORITY_FOR_BOTH_TREES, |
| 10638 | RasterTilePriorityQueue::Type::ALL); |
| 10639 | EXPECT_FALSE(non_empty_raster_priority_queue_all->IsEmpty()); |
| 10640 | |
| 10641 | root_layer->set_has_valid_tile_priorities(false); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10642 | std::unique_ptr<RasterTilePriorityQueue> empty_raster_priority_queue_all = |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10643 | host_impl_->BuildRasterQueue(TreePriority::SAME_PRIORITY_FOR_BOTH_TREES, |
| 10644 | RasterTilePriorityQueue::Type::ALL); |
| 10645 | EXPECT_TRUE(empty_raster_priority_queue_all->IsEmpty()); |
| 10646 | } |
| 10647 | |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10648 | TEST_F(LayerTreeHostImplTest, DidBecomeActive) { |
| 10649 | host_impl_->CreatePendingTree(); |
| 10650 | host_impl_->ActivateSyncTree(); |
| 10651 | host_impl_->CreatePendingTree(); |
| 10652 | |
| 10653 | LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
| 10654 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10655 | std::unique_ptr<FakePictureLayerImpl> pending_layer = |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10656 | FakePictureLayerImpl::Create(pending_tree, 10); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10657 | FakePictureLayerImpl* raw_pending_layer = pending_layer.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10658 | pending_tree->SetRootLayerForTesting(std::move(pending_layer)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10659 | ASSERT_EQ(raw_pending_layer, pending_tree->root_layer_for_testing()); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10660 | |
| 10661 | EXPECT_EQ(0u, raw_pending_layer->did_become_active_call_count()); |
| 10662 | pending_tree->DidBecomeActive(); |
| 10663 | EXPECT_EQ(1u, raw_pending_layer->did_become_active_call_count()); |
| 10664 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10665 | std::unique_ptr<FakePictureLayerImpl> mask_layer = |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10666 | FakePictureLayerImpl::Create(pending_tree, 11); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10667 | FakePictureLayerImpl* raw_mask_layer = mask_layer.get(); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 10668 | raw_pending_layer->test_properties()->SetMaskLayer(std::move(mask_layer)); |
| 10669 | ASSERT_EQ(raw_mask_layer, raw_pending_layer->test_properties()->mask_layer); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10670 | pending_tree->BuildPropertyTreesForTesting(); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10671 | |
| 10672 | EXPECT_EQ(1u, raw_pending_layer->did_become_active_call_count()); |
| 10673 | EXPECT_EQ(0u, raw_mask_layer->did_become_active_call_count()); |
| 10674 | pending_tree->DidBecomeActive(); |
| 10675 | EXPECT_EQ(2u, raw_pending_layer->did_become_active_call_count()); |
| 10676 | EXPECT_EQ(1u, raw_mask_layer->did_become_active_call_count()); |
| 10677 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10678 | std::unique_ptr<FakePictureLayerImpl> replica_layer = |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10679 | FakePictureLayerImpl::Create(pending_tree, 12); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10680 | std::unique_ptr<FakePictureLayerImpl> replica_mask_layer = |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10681 | FakePictureLayerImpl::Create(pending_tree, 13); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10682 | FakePictureLayerImpl* raw_replica_mask_layer = replica_mask_layer.get(); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 10683 | replica_layer->test_properties()->SetMaskLayer(std::move(replica_mask_layer)); |
| 10684 | raw_pending_layer->test_properties()->SetReplicaLayer( |
| 10685 | std::move(replica_layer)); |
| 10686 | ASSERT_EQ(raw_replica_mask_layer, raw_pending_layer->test_properties() |
| 10687 | ->replica_layer->test_properties() |
| 10688 | ->mask_layer); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10689 | pending_tree->BuildPropertyTreesForTesting(); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10690 | |
| 10691 | EXPECT_EQ(2u, raw_pending_layer->did_become_active_call_count()); |
| 10692 | EXPECT_EQ(1u, raw_mask_layer->did_become_active_call_count()); |
| 10693 | EXPECT_EQ(0u, raw_replica_mask_layer->did_become_active_call_count()); |
| 10694 | pending_tree->DidBecomeActive(); |
| 10695 | EXPECT_EQ(3u, raw_pending_layer->did_become_active_call_count()); |
| 10696 | EXPECT_EQ(2u, raw_mask_layer->did_become_active_call_count()); |
| 10697 | EXPECT_EQ(1u, raw_replica_mask_layer->did_become_active_call_count()); |
| 10698 | } |
| 10699 | |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10700 | TEST_F(LayerTreeHostImplTest, WheelScrollWithPageScaleFactorOnInnerLayer) { |
| 10701 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 10702 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 10703 | DrawFrame(); |
| 10704 | |
| 10705 | EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer()); |
| 10706 | |
| 10707 | float min_page_scale = 1.f, max_page_scale = 4.f; |
| 10708 | float page_scale_factor = 1.f; |
| 10709 | |
| 10710 | // The scroll deltas should have the page scale factor applied. |
| 10711 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 10712 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10713 | page_scale_factor, min_page_scale, max_page_scale); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 10714 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 10715 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10716 | |
| 10717 | float page_scale_delta = 2.f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 10718 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 10719 | InputHandler::TOUCHSCREEN); |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10720 | host_impl_->PinchGestureBegin(); |
| 10721 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); |
| 10722 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 10723 | host_impl_->ScrollEnd(EndState().get()); |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10724 | |
| 10725 | gfx::Vector2dF scroll_delta(0, 5); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10726 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 10727 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10728 | InputHandler::WHEEL) |
| 10729 | .thread); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 10730 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->CurrentScrollOffset()); |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10731 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 10732 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 10733 | host_impl_->ScrollEnd(EndState().get()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 10734 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 2.5), |
| 10735 | scroll_layer->CurrentScrollOffset()); |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10736 | } |
| 10737 | } |
| 10738 | |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10739 | class LayerTreeHostImplCountingLostSurfaces : public LayerTreeHostImplTest { |
| 10740 | public: |
| 10741 | LayerTreeHostImplCountingLostSurfaces() : num_lost_surfaces_(0) {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 10742 | void DidLoseOutputSurfaceOnImplThread() override { num_lost_surfaces_++; } |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10743 | |
| 10744 | protected: |
| 10745 | int num_lost_surfaces_; |
| 10746 | }; |
| 10747 | |
| 10748 | TEST_F(LayerTreeHostImplCountingLostSurfaces, TwiceLostSurface) { |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10749 | // Really we just need at least one client notification each time |
| 10750 | // we go from having a valid output surface to not having a valid output |
| 10751 | // surface. |
| 10752 | EXPECT_EQ(0, num_lost_surfaces_); |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10753 | host_impl_->DidLoseOutputSurface(); |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10754 | EXPECT_EQ(1, num_lost_surfaces_); |
| 10755 | host_impl_->DidLoseOutputSurface(); |
dneto | b71e30c | 2014-08-25 23:27:20 | [diff] [blame] | 10756 | EXPECT_LE(1, num_lost_surfaces_); |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10757 | } |
| 10758 | |
danakj | 61902b8 | 2015-10-30 00:30:26 | [diff] [blame] | 10759 | size_t CountRenderPassesWithId(const RenderPassList& list, RenderPassId id) { |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10760 | return std::count_if( |
| 10761 | list.begin(), list.end(), |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10762 | [id](const std::unique_ptr<RenderPass>& p) { return p->id == id; }); |
danakj | 61902b8 | 2015-10-30 00:30:26 | [diff] [blame] | 10763 | } |
| 10764 | |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10765 | TEST_F(LayerTreeHostImplTest, RemoveUnreferencedRenderPass) { |
| 10766 | LayerTreeHostImpl::FrameData frame; |
| 10767 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10768 | RenderPass* pass3 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10769 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10770 | RenderPass* pass2 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10771 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10772 | RenderPass* pass1 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10773 | |
| 10774 | pass1->SetNew(RenderPassId(1, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10775 | pass2->SetNew(RenderPassId(2, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10776 | pass3->SetNew(RenderPassId(3, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10777 | |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10778 | // Add a quad to each pass so they aren't empty. |
| 10779 | SolidColorDrawQuad* color_quad; |
| 10780 | color_quad = pass1->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 10781 | color_quad->material = DrawQuad::SOLID_COLOR; |
| 10782 | color_quad = pass2->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 10783 | color_quad->material = DrawQuad::SOLID_COLOR; |
| 10784 | color_quad = pass3->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 10785 | color_quad->material = DrawQuad::SOLID_COLOR; |
| 10786 | |
| 10787 | // pass3 is referenced by pass2. |
| 10788 | RenderPassDrawQuad* rpdq = |
| 10789 | pass2->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 10790 | rpdq->material = DrawQuad::RENDER_PASS; |
| 10791 | rpdq->render_pass_id = pass3->id; |
| 10792 | |
| 10793 | // But pass2 is not referenced by pass1. So pass2 and pass3 should be culled. |
| 10794 | FakeLayerTreeHostImpl::RemoveRenderPasses(&frame); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10795 | EXPECT_EQ(1u, frame.render_passes.size()); |
danakj | 61902b8 | 2015-10-30 00:30:26 | [diff] [blame] | 10796 | EXPECT_EQ(1u, |
| 10797 | CountRenderPassesWithId(frame.render_passes, RenderPassId(1, 0))); |
| 10798 | EXPECT_EQ(0u, |
| 10799 | CountRenderPassesWithId(frame.render_passes, RenderPassId(2, 0))); |
| 10800 | EXPECT_EQ(0u, |
| 10801 | CountRenderPassesWithId(frame.render_passes, RenderPassId(3, 0))); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10802 | EXPECT_EQ(RenderPassId(1, 0), frame.render_passes[0]->id); |
| 10803 | } |
| 10804 | |
| 10805 | TEST_F(LayerTreeHostImplTest, RemoveEmptyRenderPass) { |
| 10806 | LayerTreeHostImpl::FrameData frame; |
| 10807 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10808 | RenderPass* pass3 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10809 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10810 | RenderPass* pass2 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10811 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10812 | RenderPass* pass1 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10813 | |
| 10814 | pass1->SetNew(RenderPassId(1, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10815 | pass2->SetNew(RenderPassId(2, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10816 | pass3->SetNew(RenderPassId(3, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10817 | |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10818 | // pass1 is not empty, but pass2 and pass3 are. |
| 10819 | SolidColorDrawQuad* color_quad; |
| 10820 | color_quad = pass1->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 10821 | color_quad->material = DrawQuad::SOLID_COLOR; |
| 10822 | |
| 10823 | // pass3 is referenced by pass2. |
| 10824 | RenderPassDrawQuad* rpdq = |
| 10825 | pass2->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 10826 | rpdq->material = DrawQuad::RENDER_PASS; |
| 10827 | rpdq->render_pass_id = pass3->id; |
| 10828 | |
| 10829 | // pass2 is referenced by pass1. |
| 10830 | rpdq = pass1->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 10831 | rpdq->material = DrawQuad::RENDER_PASS; |
| 10832 | rpdq->render_pass_id = pass2->id; |
| 10833 | |
| 10834 | // Since pass3 is empty it should be removed. Then pass2 is empty too, and |
| 10835 | // should be removed. |
| 10836 | FakeLayerTreeHostImpl::RemoveRenderPasses(&frame); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10837 | EXPECT_EQ(1u, frame.render_passes.size()); |
danakj | 61902b8 | 2015-10-30 00:30:26 | [diff] [blame] | 10838 | EXPECT_EQ(1u, |
| 10839 | CountRenderPassesWithId(frame.render_passes, RenderPassId(1, 0))); |
| 10840 | EXPECT_EQ(0u, |
| 10841 | CountRenderPassesWithId(frame.render_passes, RenderPassId(2, 0))); |
| 10842 | EXPECT_EQ(0u, |
| 10843 | CountRenderPassesWithId(frame.render_passes, RenderPassId(3, 0))); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10844 | EXPECT_EQ(RenderPassId(1, 0), frame.render_passes[0]->id); |
| 10845 | // The RenderPassDrawQuad should be removed from pass1. |
| 10846 | EXPECT_EQ(1u, pass1->quad_list.size()); |
| 10847 | EXPECT_EQ(DrawQuad::SOLID_COLOR, pass1->quad_list.ElementAt(0)->material); |
| 10848 | } |
| 10849 | |
| 10850 | TEST_F(LayerTreeHostImplTest, DoNotRemoveEmptyRootRenderPass) { |
| 10851 | LayerTreeHostImpl::FrameData frame; |
| 10852 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10853 | RenderPass* pass3 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10854 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10855 | RenderPass* pass2 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10856 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10857 | RenderPass* pass1 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10858 | |
| 10859 | pass1->SetNew(RenderPassId(1, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10860 | pass2->SetNew(RenderPassId(2, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10861 | pass3->SetNew(RenderPassId(3, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10862 | |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10863 | // pass3 is referenced by pass2. |
| 10864 | RenderPassDrawQuad* rpdq = |
| 10865 | pass2->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 10866 | rpdq->material = DrawQuad::RENDER_PASS; |
| 10867 | rpdq->render_pass_id = pass3->id; |
| 10868 | |
| 10869 | // pass2 is referenced by pass1. |
| 10870 | rpdq = pass1->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 10871 | rpdq->material = DrawQuad::RENDER_PASS; |
| 10872 | rpdq->render_pass_id = pass2->id; |
| 10873 | |
| 10874 | // Since pass3 is empty it should be removed. Then pass2 is empty too, and |
| 10875 | // should be removed. Then pass1 is empty too, but it's the root so it should |
| 10876 | // not be removed. |
| 10877 | FakeLayerTreeHostImpl::RemoveRenderPasses(&frame); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10878 | EXPECT_EQ(1u, frame.render_passes.size()); |
danakj | 61902b8 | 2015-10-30 00:30:26 | [diff] [blame] | 10879 | EXPECT_EQ(1u, |
| 10880 | CountRenderPassesWithId(frame.render_passes, RenderPassId(1, 0))); |
| 10881 | EXPECT_EQ(0u, |
| 10882 | CountRenderPassesWithId(frame.render_passes, RenderPassId(2, 0))); |
| 10883 | EXPECT_EQ(0u, |
| 10884 | CountRenderPassesWithId(frame.render_passes, RenderPassId(3, 0))); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10885 | EXPECT_EQ(RenderPassId(1, 0), frame.render_passes[0]->id); |
| 10886 | // The RenderPassDrawQuad should be removed from pass1. |
| 10887 | EXPECT_EQ(0u, pass1->quad_list.size()); |
| 10888 | } |
| 10889 | |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10890 | class FakeVideoFrameController : public VideoFrameController { |
| 10891 | public: |
| 10892 | void OnBeginFrame(const BeginFrameArgs& args) override { |
| 10893 | begin_frame_args_ = args; |
dalecurtis | e8024c4 | 2015-05-29 21:22:35 | [diff] [blame] | 10894 | did_draw_frame_ = false; |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10895 | } |
| 10896 | |
dalecurtis | e8024c4 | 2015-05-29 21:22:35 | [diff] [blame] | 10897 | void DidDrawFrame() override { did_draw_frame_ = true; } |
| 10898 | |
| 10899 | const BeginFrameArgs& begin_frame_args() const { return begin_frame_args_; } |
| 10900 | |
| 10901 | bool did_draw_frame() const { return did_draw_frame_; } |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10902 | |
| 10903 | private: |
| 10904 | BeginFrameArgs begin_frame_args_; |
dalecurtis | e8024c4 | 2015-05-29 21:22:35 | [diff] [blame] | 10905 | bool did_draw_frame_ = false; |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10906 | }; |
| 10907 | |
| 10908 | TEST_F(LayerTreeHostImplTest, AddVideoFrameControllerInsideFrame) { |
| 10909 | BeginFrameArgs begin_frame_args = |
| 10910 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10911 | FakeVideoFrameController controller; |
| 10912 | |
| 10913 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10914 | EXPECT_FALSE(controller.begin_frame_args().IsValid()); |
| 10915 | host_impl_->AddVideoFrameController(&controller); |
| 10916 | EXPECT_TRUE(controller.begin_frame_args().IsValid()); |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 10917 | host_impl_->DidFinishImplFrame(); |
dalecurtis | e8024c4 | 2015-05-29 21:22:35 | [diff] [blame] | 10918 | |
| 10919 | EXPECT_FALSE(controller.did_draw_frame()); |
| 10920 | LayerTreeHostImpl::FrameData frame; |
| 10921 | host_impl_->DidDrawAllLayers(frame); |
| 10922 | EXPECT_TRUE(controller.did_draw_frame()); |
| 10923 | |
| 10924 | controller.OnBeginFrame(begin_frame_args); |
| 10925 | EXPECT_FALSE(controller.did_draw_frame()); |
| 10926 | host_impl_->RemoveVideoFrameController(&controller); |
| 10927 | host_impl_->DidDrawAllLayers(frame); |
| 10928 | EXPECT_FALSE(controller.did_draw_frame()); |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10929 | } |
| 10930 | |
| 10931 | TEST_F(LayerTreeHostImplTest, AddVideoFrameControllerOutsideFrame) { |
| 10932 | BeginFrameArgs begin_frame_args = |
| 10933 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10934 | FakeVideoFrameController controller; |
| 10935 | |
| 10936 | host_impl_->WillBeginImplFrame(begin_frame_args); |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 10937 | host_impl_->DidFinishImplFrame(); |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10938 | |
| 10939 | EXPECT_FALSE(controller.begin_frame_args().IsValid()); |
| 10940 | host_impl_->AddVideoFrameController(&controller); |
| 10941 | EXPECT_FALSE(controller.begin_frame_args().IsValid()); |
| 10942 | |
| 10943 | begin_frame_args = CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10944 | EXPECT_FALSE(controller.begin_frame_args().IsValid()); |
| 10945 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10946 | EXPECT_TRUE(controller.begin_frame_args().IsValid()); |
dalecurtis | e8024c4 | 2015-05-29 21:22:35 | [diff] [blame] | 10947 | |
| 10948 | EXPECT_FALSE(controller.did_draw_frame()); |
| 10949 | LayerTreeHostImpl::FrameData frame; |
| 10950 | host_impl_->DidDrawAllLayers(frame); |
| 10951 | EXPECT_TRUE(controller.did_draw_frame()); |
| 10952 | |
| 10953 | controller.OnBeginFrame(begin_frame_args); |
| 10954 | EXPECT_FALSE(controller.did_draw_frame()); |
| 10955 | host_impl_->RemoveVideoFrameController(&controller); |
| 10956 | host_impl_->DidDrawAllLayers(frame); |
| 10957 | EXPECT_FALSE(controller.did_draw_frame()); |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10958 | } |
| 10959 | |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10960 | TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusModes) { |
| 10961 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10962 | |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 10963 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10964 | host_impl_->SetContentIsSuitableForGpuRasterization(true); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 10965 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10966 | EXPECT_EQ(GpuRasterizationStatus::ON, host_impl_->gpu_rasterization_status()); |
| 10967 | EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 10968 | |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 10969 | host_impl_->SetHasGpuRasterizationTrigger(false); |
| 10970 | host_impl_->SetContentIsSuitableForGpuRasterization(true); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 10971 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10972 | EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT, |
| 10973 | host_impl_->gpu_rasterization_status()); |
| 10974 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10975 | |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 10976 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10977 | host_impl_->SetContentIsSuitableForGpuRasterization(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 10978 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10979 | EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, |
| 10980 | host_impl_->gpu_rasterization_status()); |
| 10981 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10982 | EXPECT_FALSE(host_impl_->use_msaa()); |
| 10983 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10984 | std::unique_ptr<TestWebGraphicsContext3D> context_with_msaa = |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10985 | TestWebGraphicsContext3D::Create(); |
| 10986 | context_with_msaa->SetMaxSamples(8); |
| 10987 | |
| 10988 | LayerTreeSettings msaaSettings = GpuRasterizationEnabledSettings(); |
| 10989 | msaaSettings.gpu_rasterization_msaa_sample_count = 4; |
| 10990 | EXPECT_TRUE(CreateHostImpl( |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 10991 | msaaSettings, |
| 10992 | FakeOutputSurface::CreateDelegating3d(std::move(context_with_msaa)))); |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 10993 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10994 | host_impl_->SetContentIsSuitableForGpuRasterization(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 10995 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10996 | EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT, |
| 10997 | host_impl_->gpu_rasterization_status()); |
| 10998 | EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 10999 | EXPECT_TRUE(host_impl_->use_msaa()); |
| 11000 | |
| 11001 | LayerTreeSettings settings = DefaultSettings(); |
| 11002 | settings.gpu_rasterization_enabled = false; |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 11003 | EXPECT_TRUE( |
| 11004 | CreateHostImpl(settings, FakeOutputSurface::CreateDelegating3d())); |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 11005 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 11006 | host_impl_->SetContentIsSuitableForGpuRasterization(true); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 11007 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 11008 | EXPECT_EQ(GpuRasterizationStatus::OFF_DEVICE, |
| 11009 | host_impl_->gpu_rasterization_status()); |
| 11010 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 11011 | |
| 11012 | settings.gpu_rasterization_forced = true; |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 11013 | EXPECT_TRUE( |
| 11014 | CreateHostImpl(settings, FakeOutputSurface::CreateDelegating3d())); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 11015 | |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 11016 | host_impl_->SetHasGpuRasterizationTrigger(false); |
| 11017 | host_impl_->SetContentIsSuitableForGpuRasterization(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 11018 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 11019 | EXPECT_EQ(GpuRasterizationStatus::ON_FORCED, |
| 11020 | host_impl_->gpu_rasterization_status()); |
| 11021 | EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 11022 | } |
| 11023 | |
ericrk | d72af43d | 2016-03-18 21:44:31 | [diff] [blame] | 11024 | class MsaaIsSlowLayerTreeHostImplTest : public LayerTreeHostImplTest { |
| 11025 | public: |
| 11026 | void CreateHostImplWithMsaaIsSlow(bool msaa_is_slow) { |
| 11027 | LayerTreeSettings settings = DefaultSettings(); |
| 11028 | settings.gpu_rasterization_enabled = true; |
| 11029 | settings.gpu_rasterization_msaa_sample_count = 4; |
| 11030 | auto context_provider = TestContextProvider::Create(); |
| 11031 | context_provider->UnboundTestContext3d()->SetMaxSamples(4); |
| 11032 | context_provider->UnboundTestContext3d()->set_msaa_is_slow(msaa_is_slow); |
| 11033 | auto msaa_is_normal_output_surface = |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 11034 | FakeOutputSurface::CreateDelegating3d(context_provider); |
ericrk | d72af43d | 2016-03-18 21:44:31 | [diff] [blame] | 11035 | EXPECT_TRUE( |
| 11036 | CreateHostImpl(settings, std::move(msaa_is_normal_output_surface))); |
| 11037 | } |
| 11038 | }; |
| 11039 | |
| 11040 | TEST_F(MsaaIsSlowLayerTreeHostImplTest, GpuRasterizationStatusMsaaIsSlow) { |
| 11041 | // Ensure that without the msaa_is_slow cap we raster unsuitable content with |
| 11042 | // msaa. |
| 11043 | CreateHostImplWithMsaaIsSlow(false); |
| 11044 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 11045 | host_impl_->SetContentIsSuitableForGpuRasterization(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 11046 | host_impl_->CommitComplete(); |
ericrk | d72af43d | 2016-03-18 21:44:31 | [diff] [blame] | 11047 | EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT, |
| 11048 | host_impl_->gpu_rasterization_status()); |
| 11049 | EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 11050 | |
| 11051 | // Ensure that with the msaa_is_slow cap we don't raster unsuitable content |
| 11052 | // with msaa. |
| 11053 | CreateHostImplWithMsaaIsSlow(true); |
| 11054 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 11055 | host_impl_->SetContentIsSuitableForGpuRasterization(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 11056 | host_impl_->CommitComplete(); |
ericrk | d72af43d | 2016-03-18 21:44:31 | [diff] [blame] | 11057 | EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, |
| 11058 | host_impl_->gpu_rasterization_status()); |
| 11059 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 11060 | } |
| 11061 | |
ericrk | 17ec17f | 2015-05-19 19:50:51 | [diff] [blame] | 11062 | // A mock output surface which lets us detect calls to ForceReclaimResources. |
| 11063 | class MockReclaimResourcesOutputSurface : public FakeOutputSurface { |
| 11064 | public: |
danakj | c070bf55 | 2016-08-10 22:41:55 | [diff] [blame] | 11065 | MockReclaimResourcesOutputSurface() |
| 11066 | : FakeOutputSurface(TestContextProvider::Create(), |
| 11067 | TestContextProvider::CreateWorker(), |
| 11068 | true) {} |
ericrk | 17ec17f | 2015-05-19 19:50:51 | [diff] [blame] | 11069 | |
| 11070 | MOCK_METHOD0(ForceReclaimResources, void()); |
ericrk | 17ec17f | 2015-05-19 19:50:51 | [diff] [blame] | 11071 | }; |
| 11072 | |
| 11073 | // Display::Draw (and the planned Display Scheduler) currently rely on resources |
| 11074 | // being reclaimed to block drawing between BeginCommit / Swap. This test |
| 11075 | // ensures that BeginCommit triggers ForceReclaimResources. See |
| 11076 | // crbug.com/489515. |
| 11077 | TEST_F(LayerTreeHostImplTest, BeginCommitReclaimsResources) { |
danakj | c070bf55 | 2016-08-10 22:41:55 | [diff] [blame] | 11078 | auto output_surface = base::MakeUnique<MockReclaimResourcesOutputSurface>(); |
ericrk | 17ec17f | 2015-05-19 19:50:51 | [diff] [blame] | 11079 | // Hold an unowned pointer to the output surface to use for mock expectations. |
| 11080 | MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); |
| 11081 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 11082 | CreateHostImpl(DefaultSettings(), std::move(output_surface)); |
ericrk | 17ec17f | 2015-05-19 19:50:51 | [diff] [blame] | 11083 | EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); |
| 11084 | host_impl_->BeginCommit(); |
| 11085 | } |
| 11086 | |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11087 | TEST_F(LayerTreeHostImplTest, UpdatePageScaleFactorOnActiveTree) { |
| 11088 | // Check page scale factor update in property trees when an update is made |
| 11089 | // on the active tree. |
| 11090 | host_impl_->CreatePendingTree(); |
| 11091 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 3.f); |
| 11092 | CreateScrollAndContentsLayers(host_impl_->pending_tree(), |
| 11093 | gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11094 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11095 | host_impl_->ActivateSyncTree(); |
| 11096 | DrawFrame(); |
| 11097 | |
| 11098 | host_impl_->CreatePendingTree(); |
| 11099 | host_impl_->active_tree()->SetPageScaleOnActiveTree(2.f); |
| 11100 | LayerImpl* page_scale_layer = host_impl_->active_tree()->PageScaleLayer(); |
| 11101 | |
| 11102 | TransformNode* active_tree_node = |
| 11103 | host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 11104 | page_scale_layer->transform_tree_index()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 11105 | // SetPageScaleOnActiveTree also updates the factors in property trees. |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 11106 | EXPECT_EQ(active_tree_node->post_local_scale_factor, 2.f); |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11107 | EXPECT_EQ(host_impl_->active_tree()->current_page_scale_factor(), 2.f); |
| 11108 | |
| 11109 | TransformNode* pending_tree_node = |
| 11110 | host_impl_->pending_tree()->property_trees()->transform_tree.Node( |
| 11111 | page_scale_layer->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 11112 | EXPECT_EQ(pending_tree_node->post_local_scale_factor, 1.f); |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11113 | EXPECT_EQ(host_impl_->pending_tree()->current_page_scale_factor(), 2.f); |
| 11114 | |
| 11115 | host_impl_->pending_tree()->UpdateDrawProperties(false); |
| 11116 | pending_tree_node = |
| 11117 | host_impl_->pending_tree()->property_trees()->transform_tree.Node( |
| 11118 | page_scale_layer->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 11119 | EXPECT_EQ(pending_tree_node->post_local_scale_factor, 2.f); |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11120 | |
| 11121 | host_impl_->ActivateSyncTree(); |
| 11122 | host_impl_->active_tree()->UpdateDrawProperties(false); |
| 11123 | active_tree_node = |
| 11124 | host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 11125 | page_scale_layer->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 11126 | EXPECT_EQ(active_tree_node->post_local_scale_factor, 2.f); |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11127 | } |
| 11128 | |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11129 | TEST_F(LayerTreeHostImplTest, SubLayerScaleForNodeInSubtreeOfPageScaleLayer) { |
| 11130 | // Checks that the sublayer scale of a transform node in the subtree of the |
| 11131 | // page scale layer is updated without a property tree rebuild. |
| 11132 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 3.f); |
| 11133 | CreateScrollAndContentsLayers(host_impl_->active_tree(), gfx::Size(100, 100)); |
| 11134 | LayerImpl* page_scale_layer = host_impl_->active_tree()->PageScaleLayer(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 11135 | page_scale_layer->test_properties()->AddChild( |
| 11136 | LayerImpl::Create(host_impl_->active_tree(), 100)); |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11137 | |
| 11138 | LayerImpl* in_subtree_of_page_scale_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 11139 | host_impl_->active_tree()->LayerById(100); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 11140 | in_subtree_of_page_scale_layer->test_properties()->force_render_surface = |
| 11141 | true; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11142 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 11143 | |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11144 | DrawFrame(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11145 | |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11146 | TransformNode* node = |
| 11147 | host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 11148 | in_subtree_of_page_scale_layer->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 11149 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11150 | |
| 11151 | host_impl_->active_tree()->SetPageScaleOnActiveTree(2.f); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11152 | |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11153 | DrawFrame(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11154 | |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 11155 | in_subtree_of_page_scale_layer = host_impl_->active_tree()->LayerById(100); |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11156 | node = host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 11157 | in_subtree_of_page_scale_layer->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 11158 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11159 | } |
| 11160 | |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11161 | TEST_F(LayerTreeHostImplTest, JitterTest) { |
| 11162 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 11163 | |
| 11164 | host_impl_->CreatePendingTree(); |
| 11165 | CreateScrollAndContentsLayers(host_impl_->pending_tree(), |
| 11166 | gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11167 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11168 | |
| 11169 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11170 | const int scroll = 5; |
| 11171 | int accumulated_scroll = 0; |
| 11172 | for (int i = 0; i < host_impl_->pending_tree()->kFixedPointHitsThreshold + 1; |
| 11173 | ++i) { |
| 11174 | host_impl_->ActivateSyncTree(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 11175 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 11176 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 11177 | host_impl_->ScrollBy( |
| 11178 | UpdateState(gfx::Point(), gfx::Vector2dF(0, scroll)).get()); |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11179 | accumulated_scroll += scroll; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 11180 | host_impl_->ScrollEnd(EndState().get()); |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11181 | host_impl_->active_tree()->UpdateDrawProperties(false); |
| 11182 | |
| 11183 | host_impl_->CreatePendingTree(); |
| 11184 | host_impl_->pending_tree()->set_source_frame_number(i + 1); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 11185 | LayerImpl* content_layer = host_impl_->pending_tree() |
| 11186 | ->OuterViewportScrollLayer() |
| 11187 | ->test_properties() |
| 11188 | ->children[0]; |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11189 | // The scroll done on the active tree is undone on the pending tree. |
| 11190 | gfx::Transform translate; |
| 11191 | translate.Translate(0, accumulated_scroll); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 11192 | content_layer->test_properties()->transform = translate; |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11193 | |
| 11194 | LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
| 11195 | pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 11196 | LayerImpl* last_scrolled_layer = pending_tree->LayerById( |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11197 | host_impl_->active_tree()->LastScrolledLayerId()); |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 11198 | |
| 11199 | // When building property trees from impl side, the builder uses the scroll |
| 11200 | // offset of layer_impl to initialize the scroll offset in scroll tree: |
| 11201 | // scroll_tree.synced_scroll_offset.PushFromMainThread( |
| 11202 | // layer->CurrentScrollOffset()). |
| 11203 | // However, layer_impl does not store scroll_offset, so it is using scroll |
| 11204 | // tree's scroll offset to initialize itself. Usually this approach works |
| 11205 | // because this is a simple assignment. However if scroll_offset's pending |
| 11206 | // delta is not zero, the delta would be counted twice. |
| 11207 | // This hacking here is to restore the damaged scroll offset. |
| 11208 | gfx::ScrollOffset pending_base = |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 11209 | pending_tree->property_trees() |
| 11210 | ->scroll_tree.GetScrollOffsetBaseForTesting( |
| 11211 | last_scrolled_layer->id()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11212 | pending_tree->BuildPropertyTreesForTesting(); |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 11213 | pending_tree->property_trees() |
| 11214 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 11215 | last_scrolled_layer->id(), pending_base); |
jaydasika | 69dc941 | 2016-06-25 00:34:57 | [diff] [blame] | 11216 | pending_tree->LayerById(content_layer->id())->SetNeedsPushProperties(); |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 11217 | |
| 11218 | pending_tree->set_needs_update_draw_properties(); |
| 11219 | pending_tree->UpdateDrawProperties(false); |
jaydasika | eaa8d085 | 2016-03-29 23:55:39 | [diff] [blame] | 11220 | float jitter = LayerTreeHostCommon::CalculateLayerJitter(content_layer); |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11221 | // There should not be any jitter measured till we hit the fixed point hits |
| 11222 | // threshold. |
| 11223 | float expected_jitter = |
| 11224 | (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; |
| 11225 | EXPECT_EQ(jitter, expected_jitter); |
| 11226 | } |
| 11227 | } |
| 11228 | |
ericrk | 563e1a015 | 2016-05-02 18:54:06 | [diff] [blame] | 11229 | // Checks that if we lose a GPU raster enabled OutputSurface and replace it |
| 11230 | // with a software OutputSurface, LayerTreeHostImpl correctly re-computes GPU |
| 11231 | // rasterization status. |
| 11232 | TEST_F(LayerTreeHostImplTest, RecomputeGpuRasterOnOutputSurfaceChange) { |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 11233 | host_impl_->ReleaseOutputSurface(); |
| 11234 | host_impl_ = nullptr; |
| 11235 | |
ericrk | 563e1a015 | 2016-05-02 18:54:06 | [diff] [blame] | 11236 | LayerTreeSettings settings = DefaultSettings(); |
| 11237 | settings.gpu_rasterization_forced = true; |
| 11238 | |
| 11239 | host_impl_ = LayerTreeHostImpl::Create( |
| 11240 | settings, this, &task_runner_provider_, &stats_instrumentation_, |
| 11241 | &shared_bitmap_manager_, &gpu_memory_buffer_manager_, &task_graph_runner_, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 11242 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); |
ericrk | 563e1a015 | 2016-05-02 18:54:06 | [diff] [blame] | 11243 | host_impl_->SetVisible(true); |
| 11244 | |
| 11245 | // InitializeRenderer with a gpu-raster enabled output surface. |
| 11246 | auto gpu_raster_output_surface = |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 11247 | FakeOutputSurface::CreateDelegating3d(TestWebGraphicsContext3D::Create()); |
ericrk | 563e1a015 | 2016-05-02 18:54:06 | [diff] [blame] | 11248 | host_impl_->InitializeRenderer(gpu_raster_output_surface.get()); |
| 11249 | EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 11250 | |
| 11251 | // Re-initialize with a software output surface. |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 11252 | output_surface_ = FakeOutputSurface::CreateDelegatingSoftware(); |
ericrk | 563e1a015 | 2016-05-02 18:54:06 | [diff] [blame] | 11253 | host_impl_->InitializeRenderer(output_surface_.get()); |
| 11254 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 11255 | } |
| 11256 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 11257 | } // namespace |
| 11258 | } // namespace cc |