[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" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 47 | #include "cc/test/animation_test_common.h" |
[email protected] | 04c5900d | 2014-08-18 13:38:36 | [diff] [blame] | 48 | #include "cc/test/begin_frame_args_test.h" |
[email protected] | 222c678 | 2013-09-05 22:24:49 | [diff] [blame] | 49 | #include "cc/test/fake_layer_tree_host_impl.h" |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 50 | #include "cc/test/fake_mask_layer_impl.h" |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 51 | #include "cc/test/fake_output_surface.h" |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 52 | #include "cc/test/fake_output_surface_client.h" |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 53 | #include "cc/test/fake_picture_layer_impl.h" |
vmpstr | 41d68f88 | 2016-03-30 01:20:23 | [diff] [blame] | 54 | #include "cc/test/fake_raster_source.h" |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 55 | #include "cc/test/fake_video_frame_provider.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 56 | #include "cc/test/geometry_test_utils.h" |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 57 | #include "cc/test/gpu_rasterization_enabled_settings.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 58 | #include "cc/test/layer_test_common.h" |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 59 | #include "cc/test/layer_tree_test.h" |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 60 | #include "cc/test/test_delegating_output_surface.h" |
reveman | 22dd929 | 2014-10-13 20:52:05 | [diff] [blame] | 61 | #include "cc/test/test_gpu_memory_buffer_manager.h" |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 62 | #include "cc/test/test_shared_bitmap_manager.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 63 | #include "cc/test/test_task_graph_runner.h" |
[email protected] | c2610b9f | 2013-10-31 06:54:59 | [diff] [blame] | 64 | #include "cc/test/test_web_graphics_context_3d.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 65 | #include "cc/trees/effect_node.h" |
danakj | 94b7e4f | 2016-07-20 01:49:38 | [diff] [blame] | 66 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 67 | #include "cc/trees/layer_tree_impl.h" |
| 68 | #include "cc/trees/single_thread_proxy.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 69 | #include "cc/trees/transform_node.h" |
[email protected] | 59cb7b35 | 2012-10-30 06:45:48 | [diff] [blame] | 70 | #include "media/base/media.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 71 | #include "testing/gmock/include/gmock/gmock.h" |
| 72 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 7bc1c51 | 2014-01-23 01:15:27 | [diff] [blame] | 73 | #include "third_party/skia/include/core/SkMallocPixelRef.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 74 | #include "ui/gfx/geometry/rect_conversions.h" |
| 75 | #include "ui/gfx/geometry/size_conversions.h" |
| 76 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 77 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 78 | #define EXPECT_SCOPED(statements) \ |
| 79 | { \ |
| 80 | SCOPED_TRACE(""); \ |
| 81 | statements; \ |
| 82 | } |
| 83 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 84 | using ::testing::Mock; |
| 85 | using ::testing::Return; |
| 86 | using ::testing::AnyNumber; |
| 87 | using ::testing::AtLeast; |
| 88 | using ::testing::_; |
[email protected] | 568285b | 2013-01-07 23:19:19 | [diff] [blame] | 89 | using media::VideoFrame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 90 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 91 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 92 | namespace { |
| 93 | |
[email protected] | c2d0c5a | 2013-02-26 04:43:36 | [diff] [blame] | 94 | class LayerTreeHostImplTest : public testing::Test, |
[email protected] | 9bdcfd64 | 2012-11-14 21:24:26 | [diff] [blame] | 95 | public LayerTreeHostImplClient { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 96 | public: |
| 97 | LayerTreeHostImplTest() |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame] | 98 | : task_runner_provider_(base::ThreadTaskRunnerHandle::Get()), |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 99 | always_main_thread_blocked_(&task_runner_provider_), |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 100 | on_can_draw_state_changed_called_(false), |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 101 | did_notify_ready_to_activate_(false), |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 102 | did_request_commit_(false), |
| 103 | did_request_redraw_(false), |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 104 | did_request_next_frame_(false), |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 105 | did_request_prepare_tiles_(false), |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 106 | did_complete_page_scale_animation_(false), |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 107 | reduce_memory_result_(true) { |
chcunningham | fd11b3c | 2015-06-09 02:09:42 | [diff] [blame] | 108 | media::InitializeMediaLibrary(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 109 | } |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 110 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 111 | LayerTreeSettings DefaultSettings() { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 112 | LayerTreeSettings settings; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 113 | settings.minimum_occlusion_tracking_size = gfx::Size(); |
jbauman | c5be44c | 2014-11-20 22:17:12 | [diff] [blame] | 114 | settings.renderer_settings.texture_id_allocation_chunk_size = 1; |
senorblanco | 8d1b3ac | 2015-05-05 00:14:26 | [diff] [blame] | 115 | settings.gpu_rasterization_enabled = true; |
weiliangc | 365a6fe | 2016-05-12 19:32:31 | [diff] [blame] | 116 | settings.verify_clip_tree_calculations = true; |
jaydasika | 7de66e95 | 2016-07-01 01:36:48 | [diff] [blame] | 117 | settings.verify_transform_tree_calculations = true; |
ericrk | 9151705c | 2016-07-26 19:53:16 | [diff] [blame] | 118 | settings.renderer_settings.buffer_to_texture_target_map = |
| 119 | DefaultBufferToTextureTargetMapForTesting(); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 120 | return settings; |
| 121 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 122 | |
danakj | aeb9506 | 2014-11-14 01:35:36 | [diff] [blame] | 123 | void SetUp() override { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 124 | CreateHostImpl(DefaultSettings(), CreateOutputSurface()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 125 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 126 | |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 127 | void TearDown() override { |
| 128 | if (host_impl_) |
| 129 | host_impl_->ReleaseOutputSurface(); |
| 130 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 131 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 132 | void DidLoseOutputSurfaceOnImplThread() override {} |
enne | 19c10858 | 2016-04-14 03:35:32 | [diff] [blame] | 133 | void SetBeginFrameSource(BeginFrameSource* source) override {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 134 | void SetEstimatedParentDrawTime(base::TimeDelta draw_time) override {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 135 | void DidSwapBuffersCompleteOnImplThread() override {} |
| 136 | void OnCanDrawStateChanged(bool can_draw) override { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 137 | on_can_draw_state_changed_called_ = true; |
| 138 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 139 | void NotifyReadyToActivate() override { |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 140 | did_notify_ready_to_activate_ = true; |
[email protected] | fc20d14 | 2014-07-01 00:49:15 | [diff] [blame] | 141 | host_impl_->ActivateSyncTree(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 142 | } |
ernstm | dfac03e | 2014-11-11 20:18:05 | [diff] [blame] | 143 | void NotifyReadyToDraw() override {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 144 | void SetNeedsRedrawOnImplThread() override { did_request_redraw_ = true; } |
| 145 | void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) override { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 146 | did_request_redraw_ = true; |
| 147 | } |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 148 | void SetNeedsOneBeginImplFrameOnImplThread() override { |
| 149 | did_request_next_frame_ = true; |
| 150 | } |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 151 | void SetNeedsPrepareTilesOnImplThread() override { |
| 152 | did_request_prepare_tiles_ = true; |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 153 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 154 | void SetNeedsCommitOnImplThread() override { did_request_commit_ = true; } |
sunnyps | 7d073dc | 2015-04-16 23:29:12 | [diff] [blame] | 155 | void SetVideoNeedsBeginFrames(bool needs_begin_frames) override {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 156 | void PostAnimationEventsToMainThreadOnImplThread( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 157 | std::unique_ptr<AnimationEvents> events) override {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 158 | bool IsInsideDraw() override { return false; } |
| 159 | void RenewTreePriority() override {} |
sunnyps | ae4316a | 2015-02-25 00:54:58 | [diff] [blame] | 160 | void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 161 | base::TimeDelta delay) override { |
sunnyps | ae4316a | 2015-02-25 00:54:58 | [diff] [blame] | 162 | animation_task_ = task; |
| 163 | requested_animation_delay_ = delay; |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 164 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 165 | void DidActivateSyncTree() override {} |
brianderson | 6874981 | 2015-07-07 22:39:39 | [diff] [blame] | 166 | void WillPrepareTiles() override {} |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 167 | void DidPrepareTiles() override {} |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 168 | void DidCompletePageScaleAnimationOnImplThread() override { |
| 169 | did_complete_page_scale_animation_ = true; |
| 170 | } |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 171 | void OnDrawForOutputSurface(bool resourceless_software_draw) override { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 172 | std::unique_ptr<LayerTreeHostImpl::FrameData> frame( |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 173 | new LayerTreeHostImpl::FrameData); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 174 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(frame.get())); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 175 | last_on_draw_render_passes_.clear(); |
| 176 | RenderPass::CopyAll(frame->render_passes, &last_on_draw_render_passes_); |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 177 | host_impl_->DrawLayers(frame.get()); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 178 | host_impl_->DidDrawAllLayers(*frame); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 179 | last_on_draw_frame_ = std::move(frame); |
| 180 | } |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 181 | |
| 182 | void set_reduce_memory_result(bool reduce_memory_result) { |
| 183 | reduce_memory_result_ = reduce_memory_result; |
| 184 | } |
| 185 | |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 186 | virtual bool CreateHostImpl(const LayerTreeSettings& settings, |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 187 | std::unique_ptr<OutputSurface> output_surface) { |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 188 | return CreateHostImplWithTaskRunnerProvider( |
| 189 | settings, std::move(output_surface), &task_runner_provider_); |
| 190 | } |
| 191 | |
| 192 | virtual bool CreateHostImplWithTaskRunnerProvider( |
| 193 | const LayerTreeSettings& settings, |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 194 | std::unique_ptr<OutputSurface> output_surface, |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 195 | TaskRunnerProvider* task_runner_provider) { |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 196 | if (host_impl_) |
| 197 | host_impl_->ReleaseOutputSurface(); |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 198 | host_impl_ = LayerTreeHostImpl::Create( |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 199 | settings, this, task_runner_provider, &stats_instrumentation_, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 200 | &shared_bitmap_manager_, &gpu_memory_buffer_manager_, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 201 | &task_graph_runner_, |
| 202 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 203 | output_surface_ = std::move(output_surface); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 204 | host_impl_->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 205 | bool init = host_impl_->InitializeRenderer(output_surface_.get()); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 206 | host_impl_->SetViewportSize(gfx::Size(10, 10)); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 207 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 208 | // Set the BeginFrameArgs so that methods which use it are able to. |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 209 | host_impl_->WillBeginImplFrame(CreateBeginFrameArgsForTesting( |
| 210 | BEGINFRAME_FROM_HERE, |
| 211 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(1))); |
| 212 | host_impl_->DidFinishImplFrame(); |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 213 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 214 | timeline_ = |
| 215 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 216 | host_impl_->animation_host()->AddAnimationTimeline(timeline_); |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 217 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 218 | return init; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 219 | } |
| 220 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 221 | void SetupRootLayerImpl(std::unique_ptr<LayerImpl> root) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 222 | root->SetPosition(gfx::PointF()); |
| 223 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 224 | root->SetDrawsContent(true); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 225 | root->draw_properties().visible_layer_rect = gfx::Rect(0, 0, 10, 10); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 226 | root->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 227 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 228 | } |
| 229 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 230 | static gfx::Vector2dF ScrollDelta(LayerImpl* layer_impl) { |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 231 | gfx::ScrollOffset delta = |
| 232 | layer_impl->layer_tree_impl() |
| 233 | ->property_trees() |
| 234 | ->scroll_tree.GetScrollOffsetDeltaForTesting(layer_impl->id()); |
| 235 | return gfx::Vector2dF(delta.x(), delta.y()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 236 | } |
| 237 | |
sunxd | b2e13c9 | 2016-04-23 01:00:05 | [diff] [blame] | 238 | static void ExpectClearedScrollDeltasRecursive(LayerImpl* root) { |
| 239 | for (auto* layer : *root->layer_tree_impl()) |
| 240 | ASSERT_EQ(ScrollDelta(layer), gfx::Vector2d()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 241 | } |
| 242 | |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 243 | static ::testing::AssertionResult ScrollInfoContains( |
| 244 | const ScrollAndScaleSet& scroll_info, |
| 245 | int id, |
| 246 | const gfx::Vector2d& scroll_delta) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 247 | int times_encountered = 0; |
| 248 | |
| 249 | for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
| 250 | if (scroll_info.scrolls[i].layer_id != id) |
| 251 | continue; |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 252 | |
| 253 | if (scroll_delta != scroll_info.scrolls[i].scroll_delta) { |
| 254 | return ::testing::AssertionFailure() |
| 255 | << "Expected " << scroll_delta.ToString() << ", not " |
| 256 | << scroll_info.scrolls[i].scroll_delta.ToString(); |
| 257 | } |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 258 | times_encountered++; |
| 259 | } |
| 260 | |
bokan | 4222c27 | 2016-07-18 17:24:54 | [diff] [blame] | 261 | if (id == scroll_info.inner_viewport_scroll.layer_id) { |
| 262 | if (scroll_delta != scroll_info.inner_viewport_scroll.scroll_delta) { |
| 263 | return ::testing::AssertionFailure() |
| 264 | << "Expected " << scroll_delta.ToString() << ", not " |
| 265 | << scroll_info.inner_viewport_scroll.scroll_delta.ToString(); |
| 266 | } |
| 267 | times_encountered++; |
| 268 | } |
| 269 | |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 270 | if (times_encountered != 1) |
| 271 | return ::testing::AssertionFailure() << "No layer found with id " << id; |
| 272 | return ::testing::AssertionSuccess(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | static void ExpectNone(const ScrollAndScaleSet& scroll_info, int id) { |
| 276 | int times_encountered = 0; |
| 277 | |
| 278 | for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
| 279 | if (scroll_info.scrolls[i].layer_id != id) |
| 280 | continue; |
| 281 | times_encountered++; |
| 282 | } |
| 283 | |
| 284 | ASSERT_EQ(0, times_encountered); |
| 285 | } |
| 286 | |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 287 | LayerImpl* CreateScrollAndContentsLayers(LayerTreeImpl* layer_tree_impl, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 288 | const gfx::Size& content_size) { |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 289 | // Create both an inner viewport scroll layer and an outer viewport scroll |
| 290 | // layer. The MaxScrollOffset of the outer viewport scroll layer will be |
| 291 | // 0x0, so the scrolls will be applied directly to the inner viewport. |
| 292 | const int kOuterViewportClipLayerId = 116; |
| 293 | const int kOuterViewportScrollLayerId = 117; |
| 294 | const int kContentLayerId = 118; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 295 | const int kInnerViewportScrollLayerId = 2; |
| 296 | const int kInnerViewportClipLayerId = 4; |
| 297 | const int kPageScaleLayerId = 5; |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 298 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 299 | std::unique_ptr<LayerImpl> root = LayerImpl::Create(layer_tree_impl, 1); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 300 | root->SetBounds(content_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 301 | root->SetPosition(gfx::PointF()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 302 | root->test_properties()->force_render_surface = true; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 303 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 304 | std::unique_ptr<LayerImpl> inner_scroll = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 305 | LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 306 | inner_scroll->test_properties()->is_container_for_fixed_position_layers = |
| 307 | true; |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 308 | inner_scroll->layer_tree_impl() |
| 309 | ->property_trees() |
| 310 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(inner_scroll->id(), |
| 311 | gfx::ScrollOffset()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 312 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 313 | std::unique_ptr<LayerImpl> inner_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 314 | LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 315 | inner_clip->SetBounds( |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 316 | gfx::Size(content_size.width() / 2, content_size.height() / 2)); |
| 317 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 318 | std::unique_ptr<LayerImpl> page_scale = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 319 | LayerImpl::Create(layer_tree_impl, kPageScaleLayerId); |
| 320 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 321 | inner_scroll->SetScrollClipLayer(inner_clip->id()); |
| 322 | inner_scroll->SetBounds(content_size); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 323 | inner_scroll->SetPosition(gfx::PointF()); |
| 324 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 325 | std::unique_ptr<LayerImpl> outer_clip = |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 326 | LayerImpl::Create(layer_tree_impl, kOuterViewportClipLayerId); |
| 327 | outer_clip->SetBounds(content_size); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 328 | outer_clip->test_properties()->is_container_for_fixed_position_layers = |
| 329 | true; |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 330 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 331 | std::unique_ptr<LayerImpl> outer_scroll = |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 332 | LayerImpl::Create(layer_tree_impl, kOuterViewportScrollLayerId); |
| 333 | outer_scroll->SetScrollClipLayer(outer_clip->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 334 | outer_scroll->layer_tree_impl() |
| 335 | ->property_trees() |
| 336 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(outer_scroll->id(), |
| 337 | gfx::ScrollOffset()); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 338 | outer_scroll->SetBounds(content_size); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 339 | outer_scroll->SetPosition(gfx::PointF()); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 340 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 341 | std::unique_ptr<LayerImpl> contents = |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 342 | LayerImpl::Create(layer_tree_impl, kContentLayerId); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 343 | contents->SetDrawsContent(true); |
| 344 | contents->SetBounds(content_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 345 | contents->SetPosition(gfx::PointF()); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 346 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 347 | outer_scroll->test_properties()->AddChild(std::move(contents)); |
| 348 | outer_clip->test_properties()->AddChild(std::move(outer_scroll)); |
| 349 | inner_scroll->test_properties()->AddChild(std::move(outer_clip)); |
| 350 | page_scale->test_properties()->AddChild(std::move(inner_scroll)); |
| 351 | inner_clip->test_properties()->AddChild(std::move(page_scale)); |
| 352 | root->test_properties()->AddChild(std::move(inner_clip)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 353 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 354 | layer_tree_impl->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 355 | layer_tree_impl->BuildPropertyTreesForTesting(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 356 | layer_tree_impl->SetViewportLayersFromIds( |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 357 | Layer::INVALID_ID, kPageScaleLayerId, kInnerViewportScrollLayerId, |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 358 | kOuterViewportScrollLayerId); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 359 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 360 | layer_tree_impl->DidBecomeActive(); |
| 361 | return layer_tree_impl->InnerViewportScrollLayer(); |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 362 | } |
| 363 | |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 364 | LayerImpl* SetupScrollAndContentsLayers(const gfx::Size& content_size) { |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 365 | LayerImpl* scroll_layer = CreateScrollAndContentsLayers( |
| 366 | host_impl_->active_tree(), content_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 367 | host_impl_->active_tree()->DidBecomeActive(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 368 | return scroll_layer; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 369 | } |
| 370 | |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 371 | // Sets up a typical virtual viewport setup with one child content layer. |
| 372 | // Returns a pointer to the content layer. |
| 373 | LayerImpl* CreateBasicVirtualViewportLayers(const gfx::Size& viewport_size, |
| 374 | const gfx::Size& content_size) { |
| 375 | // CreateScrollAndContentsLayers makes the outer viewport unscrollable and |
| 376 | // the inner a different size from the outer. We'll reuse its layer |
| 377 | // hierarchy but adjust the sizing to our needs. |
| 378 | CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size); |
| 379 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 380 | LayerImpl* content_layer = host_impl_->OuterViewportScrollLayer() |
| 381 | ->test_properties() |
| 382 | ->children.back(); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 383 | content_layer->SetBounds(content_size); |
| 384 | host_impl_->OuterViewportScrollLayer()->SetBounds(content_size); |
| 385 | |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 386 | LayerImpl* outer_clip = |
| 387 | host_impl_->OuterViewportScrollLayer()->test_properties()->parent; |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 388 | outer_clip->SetBounds(viewport_size); |
| 389 | |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 390 | LayerImpl* inner_clip_layer = host_impl_->InnerViewportScrollLayer() |
| 391 | ->test_properties() |
| 392 | ->parent->test_properties() |
| 393 | ->parent; |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 394 | inner_clip_layer->SetBounds(viewport_size); |
| 395 | host_impl_->InnerViewportScrollLayer()->SetBounds(viewport_size); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 396 | |
| 397 | // Needs to happen before building property trees as the latter propagates |
| 398 | // these element ids to property tree nodes. |
| 399 | host_impl_->active_tree()->SetElementIdsForTesting(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 400 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 401 | |
| 402 | host_impl_->SetViewportSize(viewport_size); |
| 403 | host_impl_->active_tree()->DidBecomeActive(); |
| 404 | |
| 405 | return content_layer; |
| 406 | } |
| 407 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 408 | std::unique_ptr<LayerImpl> CreateScrollableLayer(int id, |
| 409 | const gfx::Size& size, |
| 410 | LayerImpl* clip_layer) { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 411 | DCHECK(clip_layer); |
| 412 | DCHECK(id != clip_layer->id()); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 413 | std::unique_ptr<LayerImpl> layer = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 414 | LayerImpl::Create(host_impl_->active_tree(), id); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 415 | layer->SetScrollClipLayer(clip_layer->id()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 416 | layer->SetDrawsContent(true); |
| 417 | layer->SetBounds(size); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 418 | clip_layer->SetBounds(gfx::Size(size.width() / 2, size.height() / 2)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 419 | return layer; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 420 | } |
| 421 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 422 | std::unique_ptr<ScrollState> BeginState(const gfx::Point& point) { |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 423 | ScrollStateData scroll_state_data; |
| 424 | scroll_state_data.is_beginning = true; |
bokan | 578ff4a | 2016-04-12 21:54:05 | [diff] [blame] | 425 | scroll_state_data.position_x = point.x(); |
| 426 | scroll_state_data.position_y = point.y(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 427 | std::unique_ptr<ScrollState> scroll_state( |
| 428 | new ScrollState(scroll_state_data)); |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 429 | return scroll_state; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 430 | } |
| 431 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 432 | std::unique_ptr<ScrollState> UpdateState(const gfx::Point& point, |
| 433 | const gfx::Vector2dF& delta) { |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 434 | ScrollStateData scroll_state_data; |
| 435 | scroll_state_data.delta_x = delta.x(); |
| 436 | scroll_state_data.delta_y = delta.y(); |
bokan | 578ff4a | 2016-04-12 21:54:05 | [diff] [blame] | 437 | scroll_state_data.position_x = point.x(); |
| 438 | scroll_state_data.position_y = point.y(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 439 | std::unique_ptr<ScrollState> scroll_state( |
| 440 | new ScrollState(scroll_state_data)); |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 441 | return scroll_state; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 442 | } |
| 443 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 444 | std::unique_ptr<ScrollState> EndState() { |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 445 | ScrollStateData scroll_state_data; |
| 446 | scroll_state_data.is_ending = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 447 | std::unique_ptr<ScrollState> scroll_state( |
| 448 | new ScrollState(scroll_state_data)); |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 449 | return scroll_state; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 450 | } |
| 451 | |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 452 | void DrawFrame() { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 453 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 454 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 455 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 456 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | void pinch_zoom_pan_viewport_forces_commit_redraw(float device_scale_factor); |
| 460 | void pinch_zoom_pan_viewport_test(float device_scale_factor); |
| 461 | void pinch_zoom_pan_viewport_and_scroll_test(float device_scale_factor); |
| 462 | void pinch_zoom_pan_viewport_and_scroll_boundary_test( |
| 463 | float device_scale_factor); |
| 464 | |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 465 | void SetupMouseMoveAtWithDeviceScale(float device_scale_factor); |
| 466 | |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 467 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 468 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 469 | protected: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 470 | virtual std::unique_ptr<OutputSurface> CreateOutputSurface() { |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 471 | return FakeOutputSurface::CreateDelegating3d(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | void DrawOneFrame() { |
| 475 | LayerTreeHostImpl::FrameData frame_data; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 476 | host_impl_->PrepareToDraw(&frame_data); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 477 | host_impl_->DidDrawAllLayers(frame_data); |
| 478 | } |
| 479 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 480 | static void SetScrollOffsetDelta(LayerImpl* layer_impl, |
| 481 | const gfx::Vector2dF& delta) { |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 482 | if (layer_impl->layer_tree_impl() |
| 483 | ->property_trees() |
| 484 | ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(), |
| 485 | delta)) |
| 486 | layer_impl->layer_tree_impl()->DidUpdateScrollOffset( |
| 487 | layer_impl->id(), layer_impl->transform_tree_index()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 488 | } |
| 489 | |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 490 | void BeginImplFrameAndAnimate(BeginFrameArgs begin_frame_args, |
| 491 | base::TimeTicks frame_time) { |
| 492 | begin_frame_args.frame_time = frame_time; |
| 493 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 494 | host_impl_->Animate(); |
| 495 | host_impl_->UpdateAnimationState(true); |
| 496 | host_impl_->DidFinishImplFrame(); |
| 497 | } |
| 498 | |
khushalsagar | b7db1fe | 2015-11-12 00:51:27 | [diff] [blame] | 499 | FakeImplTaskRunnerProvider task_runner_provider_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 500 | DebugScopedSetMainThreadBlocked always_main_thread_blocked_; |
| 501 | |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 502 | TestSharedBitmapManager shared_bitmap_manager_; |
| 503 | TestGpuMemoryBufferManager gpu_memory_buffer_manager_; |
| 504 | TestTaskGraphRunner task_graph_runner_; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 505 | std::unique_ptr<OutputSurface> output_surface_; |
| 506 | std::unique_ptr<LayerTreeHostImpl> host_impl_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 507 | FakeRenderingStatsInstrumentation stats_instrumentation_; |
| 508 | bool on_can_draw_state_changed_called_; |
[email protected] | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 509 | bool did_notify_ready_to_activate_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 510 | bool did_request_commit_; |
| 511 | bool did_request_redraw_; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 512 | bool did_request_next_frame_; |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 513 | bool did_request_prepare_tiles_; |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 514 | bool did_complete_page_scale_animation_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 515 | bool reduce_memory_result_; |
sunnyps | ae4316a | 2015-02-25 00:54:58 | [diff] [blame] | 516 | base::Closure animation_task_; |
| 517 | base::TimeDelta requested_animation_delay_; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 518 | std::unique_ptr<LayerTreeHostImpl::FrameData> last_on_draw_frame_; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 519 | RenderPassList last_on_draw_render_passes_; |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 520 | scoped_refptr<AnimationTimeline> timeline_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 521 | }; |
| 522 | |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 523 | // A test fixture for new animation timelines tests. |
| 524 | class LayerTreeHostImplTimelinesTest : public LayerTreeHostImplTest { |
| 525 | public: |
| 526 | void SetUp() override { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 527 | CreateHostImpl(DefaultSettings(), CreateOutputSurface()); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 528 | } |
| 529 | }; |
| 530 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 531 | TEST_F(LayerTreeHostImplTest, NotifyIfCanDrawChanged) { |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 532 | // Note: It is not possible to disable the renderer once it has been set, |
| 533 | // so we do not need to test that disabling the renderer notifies us |
| 534 | // that can_draw changed. |
| 535 | EXPECT_FALSE(host_impl_->CanDraw()); |
| 536 | on_can_draw_state_changed_called_ = false; |
| 537 | |
| 538 | // Set up the root layer, which allows us to draw. |
| 539 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 540 | EXPECT_TRUE(host_impl_->CanDraw()); |
| 541 | EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 542 | on_can_draw_state_changed_called_ = false; |
| 543 | |
| 544 | // Toggle the root layer to make sure it toggles can_draw |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 545 | host_impl_->active_tree()->SetRootLayerForTesting(nullptr); |
rockot | 2176f92 | 2016-06-08 19:18:32 | [diff] [blame] | 546 | host_impl_->active_tree()->DetachLayers(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 547 | EXPECT_FALSE(host_impl_->CanDraw()); |
| 548 | EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 549 | on_can_draw_state_changed_called_ = false; |
| 550 | |
| 551 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 552 | EXPECT_TRUE(host_impl_->CanDraw()); |
| 553 | EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 554 | on_can_draw_state_changed_called_ = false; |
| 555 | |
| 556 | // Toggle the device viewport size to make sure it toggles can_draw. |
| 557 | host_impl_->SetViewportSize(gfx::Size()); |
| 558 | EXPECT_FALSE(host_impl_->CanDraw()); |
| 559 | EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 560 | on_can_draw_state_changed_called_ = false; |
| 561 | |
| 562 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 563 | EXPECT_TRUE(host_impl_->CanDraw()); |
| 564 | EXPECT_TRUE(on_can_draw_state_changed_called_); |
| 565 | on_can_draw_state_changed_called_ = false; |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 566 | } |
| 567 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 568 | TEST_F(LayerTreeHostImplTest, ResourcelessDrawWithEmptyViewport) { |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 569 | CreateHostImpl(DefaultSettings(), |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 570 | FakeOutputSurface::CreateDelegatingSoftware()); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 571 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 572 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 573 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 574 | EXPECT_TRUE(host_impl_->CanDraw()); |
| 575 | host_impl_->SetViewportSize(gfx::Size()); |
| 576 | EXPECT_FALSE(host_impl_->CanDraw()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 577 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 578 | FakeOutputSurface* fake_output_surface = |
| 579 | static_cast<FakeOutputSurface*>(host_impl_->output_surface()); |
| 580 | EXPECT_EQ(fake_output_surface->num_sent_frames(), 0u); |
| 581 | gfx::Transform identity; |
| 582 | gfx::Rect viewport(100, 100); |
| 583 | const bool resourceless_software_draw = true; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 584 | host_impl_->OnDraw(identity, viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 585 | ASSERT_EQ(fake_output_surface->num_sent_frames(), 1u); |
| 586 | EXPECT_EQ(gfx::SizeF(100.f, 100.f), |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 587 | fake_output_surface->last_sent_frame()->metadata.root_layer_size); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 588 | } |
| 589 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 590 | TEST_F(LayerTreeHostImplTest, ScrollDeltaNoLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 591 | ASSERT_FALSE(host_impl_->active_tree()->root_layer_for_testing()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 592 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 593 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 594 | host_impl_->ProcessScrollDeltas(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 595 | ASSERT_EQ(scroll_info->scrolls.size(), 0u); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 596 | } |
| 597 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 598 | TEST_F(LayerTreeHostImplTest, ScrollDeltaTreeButNoChanges) { |
| 599 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 600 | std::unique_ptr<LayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 601 | LayerImpl::Create(host_impl_->active_tree(), 1); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 602 | root->test_properties()->AddChild( |
| 603 | LayerImpl::Create(host_impl_->active_tree(), 2)); |
| 604 | root->test_properties()->AddChild( |
| 605 | LayerImpl::Create(host_impl_->active_tree(), 3)); |
| 606 | root->test_properties()->children[1]->test_properties()->AddChild( |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 607 | LayerImpl::Create(host_impl_->active_tree(), 4)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 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(), 5)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 610 | root->test_properties() |
| 611 | ->children[1] |
| 612 | ->test_properties() |
| 613 | ->children[0] |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 614 | ->test_properties() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 615 | ->AddChild(LayerImpl::Create(host_impl_->active_tree(), 6)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 616 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 617 | } |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 618 | LayerImpl* root = *host_impl_->active_tree()->begin(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 619 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 620 | ExpectClearedScrollDeltasRecursive(root); |
[email protected] | 0ede3bb | 2012-12-09 09:14:39 | [diff] [blame] | 621 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 622 | std::unique_ptr<ScrollAndScaleSet> scroll_info; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 623 | |
| 624 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 625 | ASSERT_EQ(scroll_info->scrolls.size(), 0u); |
| 626 | ExpectClearedScrollDeltasRecursive(root); |
| 627 | |
| 628 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 629 | ASSERT_EQ(scroll_info->scrolls.size(), 0u); |
| 630 | ExpectClearedScrollDeltasRecursive(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 631 | } |
| 632 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 633 | TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 634 | gfx::ScrollOffset scroll_offset(20, 30); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 635 | gfx::Vector2d scroll_delta(11, -15); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 636 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 637 | auto root_clip_owned = LayerImpl::Create(host_impl_->active_tree(), 2); |
| 638 | auto* root_clip = root_clip_owned.get(); |
| 639 | auto root_owned = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 640 | auto* root = root_owned.get(); |
| 641 | |
| 642 | root_clip->SetBounds(gfx::Size(10, 10)); |
| 643 | root_clip->test_properties()->AddChild(std::move(root_owned)); |
| 644 | root->SetBounds(gfx::Size(110, 110)); |
| 645 | root->SetScrollClipLayer(root_clip->id()); |
| 646 | root->layer_tree_impl() |
| 647 | ->property_trees() |
| 648 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(root->id(), scroll_offset); |
| 649 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_clip_owned)); |
| 650 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 651 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 652 | std::unique_ptr<ScrollAndScaleSet> scroll_info; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 653 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 654 | root->ScrollBy(scroll_delta); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 655 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 656 | ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 657 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, root->id(), scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 658 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 659 | gfx::Vector2d scroll_delta2(-5, 27); |
| 660 | root->ScrollBy(scroll_delta2); |
| 661 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 662 | ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 663 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, root->id(), |
| 664 | scroll_delta + scroll_delta2)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 665 | |
| 666 | root->ScrollBy(gfx::Vector2d()); |
| 667 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 668 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, root->id(), |
| 669 | scroll_delta + scroll_delta2)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 670 | } |
| 671 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 672 | TEST_F(LayerTreeHostImplTest, ScrollRootCallsCommitAndRedraw) { |
| 673 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 674 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 675 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 676 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 677 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 678 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 679 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 680 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 681 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 682 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 683 | status.main_thread_scrolling_reasons); |
| 684 | |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 685 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 686 | InputHandler::WHEEL)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 687 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 688 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(0, 10), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 689 | InputHandler::WHEEL)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 690 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 691 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 692 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 693 | InputHandler::WHEEL)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 694 | EXPECT_TRUE(did_request_redraw_); |
| 695 | EXPECT_TRUE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 696 | } |
| 697 | |
jdduke | 16dde6e | 2014-10-24 00:22:56 | [diff] [blame] | 698 | TEST_F(LayerTreeHostImplTest, ScrollActiveOnlyAfterScrollMovement) { |
| 699 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 700 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 701 | |
jdduke | 16dde6e | 2014-10-24 00:22:56 | [diff] [blame] | 702 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 703 | DrawFrame(); |
| 704 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 705 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 706 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 707 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 708 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 709 | status.main_thread_scrolling_reasons); |
| 710 | |
jdduke | 16dde6e | 2014-10-24 00:22:56 | [diff] [blame] | 711 | EXPECT_FALSE(host_impl_->IsActivelyScrolling()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 712 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
jdduke | 16dde6e | 2014-10-24 00:22:56 | [diff] [blame] | 713 | EXPECT_TRUE(host_impl_->IsActivelyScrolling()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 714 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 715 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
jdduke | 16dde6e | 2014-10-24 00:22:56 | [diff] [blame] | 716 | EXPECT_FALSE(host_impl_->IsActivelyScrolling()); |
| 717 | } |
| 718 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 719 | TEST_F(LayerTreeHostImplTest, ScrollWithoutRootLayer) { |
| 720 | // We should not crash when trying to scroll an empty layer tree. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 721 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 722 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 723 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 724 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 725 | status.main_thread_scrolling_reasons); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 726 | } |
| 727 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 728 | TEST_F(LayerTreeHostImplTest, ScrollWithoutRenderer) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 729 | std::unique_ptr<TestWebGraphicsContext3D> context_owned = |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 730 | TestWebGraphicsContext3D::Create(); |
[email protected] | c9addd1 | 2013-12-08 22:43:26 | [diff] [blame] | 731 | context_owned->set_context_lost(true); |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 732 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 733 | // Initialization will fail. |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 734 | EXPECT_FALSE(CreateHostImpl( |
| 735 | DefaultSettings(), |
| 736 | FakeOutputSurface::CreateDelegating3d(std::move(context_owned)))); |
[email protected] | a90aa70 | 2012-11-07 04:48:24 | [diff] [blame] | 737 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 738 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 739 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 740 | // We should not crash when trying to scroll after the renderer initialization |
| 741 | // fails. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 742 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 743 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 744 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 745 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 746 | status.main_thread_scrolling_reasons); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 747 | } |
| 748 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 749 | TEST_F(LayerTreeHostImplTest, ReplaceTreeWhileScrolling) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 750 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 751 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 752 | DrawFrame(); |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 753 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 754 | // We should not crash if the tree is replaced while we are scrolling. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 755 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 756 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 757 | InputHandler::WHEEL) |
| 758 | .thread); |
rockot | 2176f92 | 2016-06-08 19:18:32 | [diff] [blame] | 759 | host_impl_->active_tree()->DetachLayers(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 760 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 761 | scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 762 | |
| 763 | // We should still be scrolling, because the scrolled layer also exists in the |
| 764 | // new tree. |
| 765 | gfx::Vector2d scroll_delta(0, 10); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 766 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 767 | host_impl_->ScrollEnd(EndState().get()); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 768 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 769 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 770 | EXPECT_TRUE( |
| 771 | ScrollInfoContains(*scroll_info, scroll_layer->id(), scroll_delta)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 772 | } |
| 773 | |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 774 | TEST_F(LayerTreeHostImplTest, ScrollBlocksOnWheelEventHandlers) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 775 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 776 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 777 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 778 | |
dtapuska | e7dd21de | 2016-06-09 13:41:56 | [diff] [blame] | 779 | // Wheel handlers determine whether mouse events block scroll. |
dtapuska | f206a40d | 2016-02-05 21:36:02 | [diff] [blame] | 780 | host_impl_->active_tree()->set_event_listener_properties( |
| 781 | EventListenerClass::kMouseWheel, EventListenerProperties::kBlocking); |
dtapuska | e7dd21de | 2016-06-09 13:41:56 | [diff] [blame] | 782 | EXPECT_EQ( |
| 783 | EventListenerProperties::kBlocking, |
| 784 | host_impl_->GetEventListenerProperties(EventListenerClass::kMouseWheel)); |
| 785 | |
| 786 | // But they don't influence the actual handling of the scroll gestures. |
dtapuska | cd423123 | 2016-01-28 19:18:11 | [diff] [blame] | 787 | InputHandler::ScrollStatus status = |
| 788 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 789 | InputHandler::WHEEL); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 790 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 791 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 792 | status.main_thread_scrolling_reasons); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 793 | host_impl_->ScrollEnd(EndState().get()); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | TEST_F(LayerTreeHostImplTest, ScrollBlocksOnTouchEventHandlers) { |
| 797 | LayerImpl* scroll = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 798 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 799 | DrawFrame(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 800 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 801 | |
| 802 | LayerImpl* child = 0; |
| 803 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 804 | std::unique_ptr<LayerImpl> child_layer = |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 805 | LayerImpl::Create(host_impl_->active_tree(), 6); |
| 806 | child = child_layer.get(); |
| 807 | child_layer->SetDrawsContent(true); |
| 808 | child_layer->SetPosition(gfx::PointF(0, 20)); |
| 809 | child_layer->SetBounds(gfx::Size(50, 50)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 810 | scroll->test_properties()->AddChild(std::move(child_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 811 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | // Touch handler regions determine whether touch events block scroll. |
| 815 | root->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 816 | EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 10))); |
| 817 | |
| 818 | // But they don't influence the actual handling of the scroll gestures. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 819 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 820 | BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 821 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 822 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 823 | status.main_thread_scrolling_reasons); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 824 | host_impl_->ScrollEnd(EndState().get()); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 825 | |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 826 | EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); |
dtapuska | cd423123 | 2016-01-28 19:18:11 | [diff] [blame] | 827 | root->SetTouchEventHandlerRegion(gfx::Rect()); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 828 | EXPECT_FALSE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); |
dtapuska | cd423123 | 2016-01-28 19:18:11 | [diff] [blame] | 829 | child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50)); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 830 | EXPECT_TRUE(host_impl_->DoTouchEventsBlockScrollAt(gfx::Point(10, 30))); |
| 831 | } |
| 832 | |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 833 | TEST_F(LayerTreeHostImplTest, FlingOnlyWhenScrollingTouchscreen) { |
| 834 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 835 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 836 | DrawFrame(); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 837 | |
| 838 | // Ignore the fling since no layer is being scrolled |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 839 | InputHandler::ScrollStatus status = host_impl_->FlingScrollBegin(); |
| 840 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 841 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 842 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 843 | |
| 844 | // Start scrolling a layer |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 845 | status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 846 | InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 847 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 848 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 849 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 850 | |
| 851 | // Now the fling should go ahead since we've started scrolling a layer |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 852 | status = host_impl_->FlingScrollBegin(); |
| 853 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 854 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 855 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | TEST_F(LayerTreeHostImplTest, FlingOnlyWhenScrollingTouchpad) { |
| 859 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 860 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 861 | DrawFrame(); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 862 | |
| 863 | // Ignore the fling since no layer is being scrolled |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 864 | InputHandler::ScrollStatus status = host_impl_->FlingScrollBegin(); |
| 865 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 866 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 867 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 868 | |
| 869 | // Start scrolling a layer |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 870 | status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 871 | InputHandler::WHEEL); |
| 872 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 873 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 874 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 875 | |
| 876 | // Now the fling should go ahead since we've started scrolling a layer |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 877 | status = host_impl_->FlingScrollBegin(); |
| 878 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 879 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 880 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | TEST_F(LayerTreeHostImplTest, NoFlingWhenScrollingOnMain) { |
| 884 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 885 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 886 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 887 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 888 | root->set_main_thread_scrolling_reasons( |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 889 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 890 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 891 | |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 892 | DrawFrame(); |
| 893 | |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 894 | // Start scrolling a layer |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 895 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 896 | BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 897 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 898 | EXPECT_EQ(MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 899 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 900 | |
| 901 | // The fling should be ignored since there's no layer being scrolled impl-side |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 902 | status = host_impl_->FlingScrollBegin(); |
| 903 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 904 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 905 | status.main_thread_scrolling_reasons); |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 906 | } |
| 907 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 908 | TEST_F(LayerTreeHostImplTest, ShouldScrollOnMainThread) { |
| 909 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 910 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 911 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 912 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 913 | root->set_main_thread_scrolling_reasons( |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 914 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 915 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 916 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 917 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 918 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 919 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 920 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 921 | EXPECT_EQ(MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 922 | status.main_thread_scrolling_reasons); |
| 923 | |
| 924 | status = host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 925 | InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 926 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 927 | EXPECT_EQ(MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 928 | status.main_thread_scrolling_reasons); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 929 | } |
| 930 | |
sunxd | 0b34eb5 | 2016-04-13 01:13:39 | [diff] [blame] | 931 | TEST_F(LayerTreeHostImplTest, ScrollWithOverlappingNonScrollableLayer) { |
| 932 | LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 933 | gfx::Size content_size = gfx::Size(360, 600); |
| 934 | gfx::Size scroll_content_size = gfx::Size(345, 3800); |
| 935 | gfx::Size scrollbar_size = gfx::Size(15, 600); |
| 936 | |
| 937 | host_impl_->SetViewportSize(content_size); |
| 938 | std::unique_ptr<LayerImpl> root = LayerImpl::Create(layer_tree_impl, 1); |
| 939 | root->SetBounds(content_size); |
| 940 | root->SetPosition(gfx::PointF()); |
| 941 | |
| 942 | std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 2); |
| 943 | clip->SetBounds(content_size); |
| 944 | clip->SetPosition(gfx::PointF()); |
| 945 | |
| 946 | std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 3); |
| 947 | scroll->SetBounds(scroll_content_size); |
| 948 | scroll->SetScrollClipLayer(clip->id()); |
| 949 | scroll->SetDrawsContent(true); |
| 950 | |
| 951 | std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
| 952 | SolidColorScrollbarLayerImpl::Create(layer_tree_impl, 4, VERTICAL, 10, 0, |
| 953 | false, true); |
| 954 | scrollbar->SetBounds(scrollbar_size); |
| 955 | scrollbar->SetPosition(gfx::PointF(345, 0)); |
| 956 | scrollbar->SetScrollLayerId(scroll->id()); |
sunxd | 0b34eb5 | 2016-04-13 01:13:39 | [diff] [blame] | 957 | scrollbar->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 958 | scrollbar->test_properties()->opacity = 1.f; |
sunxd | 0b34eb5 | 2016-04-13 01:13:39 | [diff] [blame] | 959 | |
| 960 | std::unique_ptr<LayerImpl> squash1 = LayerImpl::Create(layer_tree_impl, 5); |
| 961 | squash1->SetBounds(gfx::Size(140, 300)); |
| 962 | squash1->SetPosition(gfx::PointF(220, 0)); |
| 963 | squash1->SetDrawsContent(true); |
| 964 | |
| 965 | std::unique_ptr<LayerImpl> squash2 = LayerImpl::Create(layer_tree_impl, 6); |
| 966 | squash2->SetBounds(gfx::Size(140, 300)); |
| 967 | squash2->SetPosition(gfx::PointF(220, 300)); |
| 968 | squash2->SetDrawsContent(true); |
| 969 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 970 | scroll->test_properties()->AddChild(std::move(squash2)); |
| 971 | clip->test_properties()->AddChild(std::move(scroll)); |
| 972 | clip->test_properties()->AddChild(std::move(scrollbar)); |
| 973 | clip->test_properties()->AddChild(std::move(squash1)); |
| 974 | root->test_properties()->AddChild(std::move(clip)); |
sunxd | 0b34eb5 | 2016-04-13 01:13:39 | [diff] [blame] | 975 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 976 | layer_tree_impl->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 977 | layer_tree_impl->BuildPropertyTreesForTesting(); |
sunxd | 0b34eb5 | 2016-04-13 01:13:39 | [diff] [blame] | 978 | layer_tree_impl->DidBecomeActive(); |
| 979 | |
| 980 | // The point hits squash1 layer and also scroll layer, because scroll layer is |
| 981 | // not an ancestor of squash1 layer, we cannot scroll on impl thread. |
| 982 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 983 | BeginState(gfx::Point(230, 150)).get(), InputHandler::WHEEL); |
| 984 | EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); |
| 985 | EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, |
| 986 | status.main_thread_scrolling_reasons); |
| 987 | |
| 988 | // The point hits squash1 layer and also scrollbar layer. |
| 989 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(350, 150)).get(), |
| 990 | InputHandler::WHEEL); |
| 991 | EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); |
| 992 | EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, |
| 993 | status.main_thread_scrolling_reasons); |
| 994 | |
| 995 | // The point hits squash2 layer and also scroll layer, because scroll layer is |
| 996 | // an ancestor of squash2 layer, we should scroll on impl. |
| 997 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(230, 450)).get(), |
| 998 | InputHandler::WHEEL); |
| 999 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
| 1000 | } |
| 1001 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1002 | TEST_F(LayerTreeHostImplTest, NonFastScrollableRegionBasic) { |
| 1003 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 1004 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1005 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1006 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1007 | root->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
| 1008 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1009 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1010 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1011 | |
| 1012 | // All scroll types inside the non-fast scrollable region should fail. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1013 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 1014 | BeginState(gfx::Point(25, 25)).get(), InputHandler::WHEEL); |
| 1015 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1016 | EXPECT_EQ(MainThreadScrollingReason::kNonFastScrollableRegion, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1017 | status.main_thread_scrolling_reasons); |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 1018 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(25, 25), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1019 | InputHandler::WHEEL)); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1020 | |
| 1021 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(25, 25)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1022 | InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1023 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1024 | EXPECT_EQ(MainThreadScrollingReason::kNonFastScrollableRegion, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1025 | status.main_thread_scrolling_reasons); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1026 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1027 | gfx::Point(25, 25), InputHandler::TOUCHSCREEN)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1028 | |
| 1029 | // All scroll types outside this region should succeed. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1030 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(75, 75)).get(), |
| 1031 | InputHandler::WHEEL); |
| 1032 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1033 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1034 | status.main_thread_scrolling_reasons); |
| 1035 | |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1036 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1037 | gfx::Point(75, 75), InputHandler::TOUCHSCREEN)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1038 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1039 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1040 | gfx::Point(25, 25), InputHandler::TOUCHSCREEN)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1041 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 1042 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1043 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1044 | gfx::Point(75, 75), InputHandler::TOUCHSCREEN)); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1045 | |
| 1046 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(75, 75)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1047 | InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1048 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1049 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1050 | status.main_thread_scrolling_reasons); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1051 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1052 | gfx::Point(75, 75), InputHandler::TOUCHSCREEN)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1053 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
| 1054 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 1055 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1056 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 1057 | gfx::Point(75, 75), InputHandler::TOUCHSCREEN)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | TEST_F(LayerTreeHostImplTest, NonFastScrollableRegionWithOffset) { |
| 1061 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 1062 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1063 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1064 | LayerImpl* root = *host_impl_->active_tree()->begin(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1065 | root->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
| 1066 | root->SetPosition(gfx::PointF(-25.f, 0.f)); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1067 | root->SetDrawsContent(true); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1068 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1069 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1070 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1071 | |
| 1072 | // This point would fall into the non-fast scrollable region except that we've |
| 1073 | // moved the layer down by 25 pixels. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1074 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 1075 | BeginState(gfx::Point(40, 10)).get(), InputHandler::WHEEL); |
| 1076 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1077 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1078 | status.main_thread_scrolling_reasons); |
| 1079 | |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 1080 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(40, 10), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1081 | InputHandler::WHEEL)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1082 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 1)).get()); |
| 1083 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1084 | |
| 1085 | // This point is still inside the non-fast region. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1086 | status = host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), |
| 1087 | InputHandler::WHEEL); |
| 1088 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1089 | EXPECT_EQ(MainThreadScrollingReason::kNonFastScrollableRegion, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1090 | status.main_thread_scrolling_reasons); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1091 | } |
| 1092 | |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1093 | TEST_F(LayerTreeHostImplTest, ScrollHandlerNotPresent) { |
dtapuska | f024e55 | 2016-02-03 01:19:46 | [diff] [blame] | 1094 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
| 1095 | EXPECT_FALSE(host_impl_->active_tree()->have_scroll_event_handlers()); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1096 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1097 | DrawFrame(); |
| 1098 | |
| 1099 | EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1100 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1101 | InputHandler::TOUCHSCREEN); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1102 | EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1103 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1104 | EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler()); |
| 1105 | } |
| 1106 | |
| 1107 | TEST_F(LayerTreeHostImplTest, ScrollHandlerPresent) { |
dtapuska | f024e55 | 2016-02-03 01:19:46 | [diff] [blame] | 1108 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
| 1109 | host_impl_->active_tree()->set_have_scroll_event_handlers(true); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1110 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1111 | DrawFrame(); |
| 1112 | |
| 1113 | EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1114 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1115 | InputHandler::TOUCHSCREEN); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1116 | EXPECT_TRUE(host_impl_->scroll_affects_scroll_handler()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1117 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 1118 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
[email protected] | f161ca9e | 2014-04-01 13:57:01 | [diff] [blame] | 1119 | EXPECT_FALSE(host_impl_->scroll_affects_scroll_handler()); |
| 1120 | } |
| 1121 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1122 | TEST_F(LayerTreeHostImplTest, ScrollByReturnsCorrectValue) { |
| 1123 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 1124 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1125 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1126 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1127 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1128 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1129 | BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1130 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 1131 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1132 | status.main_thread_scrolling_reasons); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1133 | |
| 1134 | // Trying to scroll to the left/top will not succeed. |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1135 | EXPECT_FALSE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1136 | host_impl_->ScrollBy( |
| 1137 | UpdateState(gfx::Point(), gfx::Vector2d(-10, 0)).get()) |
| 1138 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1139 | EXPECT_FALSE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1140 | host_impl_->ScrollBy( |
| 1141 | UpdateState(gfx::Point(), gfx::Vector2d(0, -10)).get()) |
| 1142 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1143 | EXPECT_FALSE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1144 | host_impl_->ScrollBy( |
| 1145 | UpdateState(gfx::Point(), gfx::Vector2d(-10, -10)).get()) |
| 1146 | .did_scroll); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1147 | |
| 1148 | // Scrolling to the right/bottom will succeed. |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1149 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1150 | host_impl_->ScrollBy( |
| 1151 | UpdateState(gfx::Point(), gfx::Vector2d(10, 0)).get()) |
| 1152 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1153 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1154 | host_impl_->ScrollBy( |
| 1155 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()) |
| 1156 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1157 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1158 | host_impl_->ScrollBy( |
| 1159 | UpdateState(gfx::Point(), gfx::Vector2d(10, 10)).get()) |
| 1160 | .did_scroll); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1161 | |
| 1162 | // Scrolling to left/top will now succeed. |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1163 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1164 | host_impl_->ScrollBy( |
| 1165 | UpdateState(gfx::Point(), gfx::Vector2d(-10, 0)).get()) |
| 1166 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1167 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1168 | host_impl_->ScrollBy( |
| 1169 | UpdateState(gfx::Point(), gfx::Vector2d(0, -10)).get()) |
| 1170 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1171 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1172 | host_impl_->ScrollBy( |
| 1173 | UpdateState(gfx::Point(), gfx::Vector2d(-10, -10)).get()) |
| 1174 | .did_scroll); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1175 | |
| 1176 | // Scrolling diagonally against an edge will succeed. |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1177 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1178 | host_impl_->ScrollBy( |
| 1179 | UpdateState(gfx::Point(), gfx::Vector2d(10, -10)).get()) |
| 1180 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1181 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1182 | host_impl_->ScrollBy( |
| 1183 | UpdateState(gfx::Point(), gfx::Vector2d(-10, 0)).get()) |
| 1184 | .did_scroll); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1185 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1186 | host_impl_->ScrollBy( |
| 1187 | UpdateState(gfx::Point(), gfx::Vector2d(-10, 10)).get()) |
| 1188 | .did_scroll); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1189 | |
| 1190 | // Trying to scroll more than the available space will also succeed. |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 1191 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1192 | host_impl_->ScrollBy( |
| 1193 | UpdateState(gfx::Point(), gfx::Vector2d(5000, 5000)).get()) |
| 1194 | .did_scroll); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | TEST_F(LayerTreeHostImplTest, ScrollVerticallyByPageReturnsCorrectValue) { |
| 1198 | SetupScrollAndContentsLayers(gfx::Size(200, 2000)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 1199 | host_impl_->SetViewportSize(gfx::Size(100, 1000)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1200 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1201 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1202 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1203 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1204 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1205 | InputHandler::WHEEL) |
| 1206 | .thread); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1207 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 1208 | // Trying to scroll if not user_scrollable_vertical will fail. |
| 1209 | host_impl_->InnerViewportScrollLayer()->set_user_scrollable_vertical(false); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1210 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | 2668bea6 | 2016-03-17 00:49:47 | [diff] [blame] | 1211 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1212 | EXPECT_FALSE(host_impl_->ScrollVerticallyByPage( |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 1213 | gfx::Point(), SCROLL_FORWARD)); |
[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_BACKWARD)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1216 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 1217 | host_impl_->InnerViewportScrollLayer()->set_user_scrollable_vertical(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1218 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | 2668bea6 | 2016-03-17 00:49:47 | [diff] [blame] | 1219 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1220 | EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 1221 | gfx::Point(), SCROLL_FORWARD)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1222 | EXPECT_FLOAT_EQ(875.f, |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1223 | ScrollDelta(host_impl_->InnerViewportScrollLayer()).y()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1224 | EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 1225 | gfx::Point(), SCROLL_BACKWARD)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1226 | } |
| 1227 | |
aelias | af915a88 | 2014-10-14 04:12:04 | [diff] [blame] | 1228 | TEST_F(LayerTreeHostImplTest, ScrollWithUserUnscrollableLayers) { |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1229 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
| 1230 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 1231 | |
| 1232 | gfx::Size overflow_size(400, 400); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 1233 | ASSERT_EQ(1u, scroll_layer->test_properties()->children.size()); |
| 1234 | LayerImpl* overflow = scroll_layer->test_properties()->children[0]; |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1235 | overflow->SetBounds(overflow_size); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 1236 | overflow->SetScrollClipLayer( |
| 1237 | scroll_layer->test_properties()->parent->test_properties()->parent->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1238 | overflow->layer_tree_impl() |
| 1239 | ->property_trees() |
| 1240 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(overflow->id(), |
| 1241 | gfx::ScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1242 | overflow->SetPosition(gfx::PointF()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1243 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1244 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1245 | DrawFrame(); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1246 | gfx::Point scroll_position(10, 10); |
| 1247 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1248 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1249 | host_impl_->ScrollBegin(BeginState(scroll_position).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1250 | InputHandler::WHEEL) |
| 1251 | .thread); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1252 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->CurrentScrollOffset()); |
| 1253 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1254 | |
| 1255 | gfx::Vector2dF scroll_delta(10, 10); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1256 | host_impl_->ScrollBy(UpdateState(scroll_position, scroll_delta).get()); |
| 1257 | host_impl_->ScrollEnd(EndState().get()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1258 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->CurrentScrollOffset()); |
| 1259 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 10), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1260 | |
| 1261 | overflow->set_user_scrollable_horizontal(false); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1262 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 1263 | |
sunxd | 2668bea6 | 2016-03-17 00:49:47 | [diff] [blame] | 1264 | DrawFrame(); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1265 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1266 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1267 | host_impl_->ScrollBegin(BeginState(scroll_position).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1268 | InputHandler::WHEEL) |
| 1269 | .thread); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1270 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->CurrentScrollOffset()); |
| 1271 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 10), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1272 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1273 | host_impl_->ScrollBy(UpdateState(scroll_position, scroll_delta).get()); |
| 1274 | host_impl_->ScrollEnd(EndState().get()); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 1275 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), scroll_layer->CurrentScrollOffset()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1276 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1277 | |
| 1278 | overflow->set_user_scrollable_vertical(false); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1279 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | 2668bea6 | 2016-03-17 00:49:47 | [diff] [blame] | 1280 | DrawFrame(); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1281 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1282 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1283 | host_impl_->ScrollBegin(BeginState(scroll_position).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1284 | InputHandler::WHEEL) |
| 1285 | .thread); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 1286 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), scroll_layer->CurrentScrollOffset()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1287 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1288 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1289 | host_impl_->ScrollBy(UpdateState(scroll_position, scroll_delta).get()); |
| 1290 | host_impl_->ScrollEnd(EndState().get()); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 1291 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 10), scroll_layer->CurrentScrollOffset()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 1292 | EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 1293 | } |
| 1294 | |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1295 | TEST_F(LayerTreeHostImplTest, AnimationSchedulingPendingTree) { |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1296 | EXPECT_FALSE(host_impl_->CommitToActiveTree()); |
| 1297 | |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1298 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1299 | |
| 1300 | host_impl_->CreatePendingTree(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1301 | auto root_owned = LayerImpl::Create(host_impl_->pending_tree(), 1); |
| 1302 | auto* root = root_owned.get(); |
| 1303 | host_impl_->pending_tree()->SetRootLayerForTesting(std::move(root_owned)); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1304 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1305 | root->test_properties()->force_render_surface = true; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1306 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 1307 | root->test_properties()->AddChild( |
| 1308 | LayerImpl::Create(host_impl_->pending_tree(), 2)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 1309 | LayerImpl* child = root->test_properties()->children[0]; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1310 | child->SetBounds(gfx::Size(10, 10)); |
| 1311 | child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); |
| 1312 | child->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1313 | |
| 1314 | host_impl_->pending_tree()->SetElementIdsForTesting(); |
| 1315 | |
| 1316 | AddAnimatedTransformToElementWithPlayer(child->element_id(), timeline(), 10.0, |
| 1317 | 3, 0); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1318 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1319 | EXPECT_FALSE(did_request_next_frame_); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1320 | EXPECT_FALSE(did_request_redraw_); |
| 1321 | EXPECT_FALSE(did_request_commit_); |
| 1322 | |
danakj | 492344054 | 2015-10-29 19:34:53 | [diff] [blame] | 1323 | host_impl_->AnimatePendingTreeAfterCommit(); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1324 | |
danakj | 492344054 | 2015-10-29 19:34:53 | [diff] [blame] | 1325 | // An animation exists on the pending layer. Doing |
| 1326 | // AnimatePendingTreeAfterCommit() requests another frame. |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1327 | // In reality, animations without has_set_start_time() == true do not need to |
| 1328 | // be continuously ticked on the pending tree, so it should not request |
| 1329 | // another animation frame here. But we currently do so blindly if any |
| 1330 | // animation exists. |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1331 | EXPECT_TRUE(did_request_next_frame_); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1332 | // The pending tree with an animation does not need to draw after animating. |
| 1333 | EXPECT_FALSE(did_request_redraw_); |
| 1334 | EXPECT_FALSE(did_request_commit_); |
| 1335 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1336 | did_request_next_frame_ = false; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1337 | did_request_redraw_ = false; |
| 1338 | did_request_commit_ = false; |
| 1339 | |
| 1340 | host_impl_->ActivateSyncTree(); |
| 1341 | |
| 1342 | // When the animation activates, we should request another animation frame |
| 1343 | // to keep the animation moving. |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1344 | EXPECT_TRUE(did_request_next_frame_); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1345 | // On activation we don't need to request a redraw for the animation, |
| 1346 | // activating will draw on its own when it's ready. |
| 1347 | EXPECT_FALSE(did_request_redraw_); |
| 1348 | EXPECT_FALSE(did_request_commit_); |
| 1349 | } |
| 1350 | |
| 1351 | TEST_F(LayerTreeHostImplTest, AnimationSchedulingActiveTree) { |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1352 | EXPECT_FALSE(host_impl_->CommitToActiveTree()); |
| 1353 | |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1354 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1355 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1356 | host_impl_->active_tree()->SetRootLayerForTesting( |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1357 | LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1358 | LayerImpl* root = *host_impl_->active_tree()->begin(); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1359 | root->SetBounds(gfx::Size(50, 50)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1360 | root->test_properties()->force_render_surface = true; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1361 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 1362 | root->test_properties()->AddChild( |
| 1363 | LayerImpl::Create(host_impl_->active_tree(), 2)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 1364 | LayerImpl* child = root->test_properties()->children[0]; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1365 | child->SetBounds(gfx::Size(10, 10)); |
| 1366 | child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); |
| 1367 | child->SetDrawsContent(true); |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 1368 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1369 | host_impl_->active_tree()->SetElementIdsForTesting(); |
| 1370 | |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1371 | // Add a translate from 6,7 to 8,9. |
| 1372 | TransformOperations start; |
| 1373 | start.AppendTranslate(6.f, 7.f, 0.f); |
| 1374 | TransformOperations end; |
| 1375 | end.AppendTranslate(8.f, 9.f, 0.f); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1376 | AddAnimatedTransformToElementWithPlayer(child->element_id(), timeline(), 4.0, |
| 1377 | start, end); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1378 | |
| 1379 | base::TimeTicks now = base::TimeTicks::Now(); |
| 1380 | host_impl_->WillBeginImplFrame( |
| 1381 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now)); |
| 1382 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1383 | // TODO(crbug.com/551134): We always request a new frame and a draw for |
| 1384 | // animations that are on the pending tree, but we don't need to do that |
| 1385 | // unless they are waiting for some future time to start. |
| 1386 | EXPECT_TRUE(did_request_next_frame_); |
| 1387 | EXPECT_TRUE(did_request_redraw_); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1388 | EXPECT_FALSE(did_request_commit_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1389 | did_request_next_frame_ = false; |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1390 | did_request_redraw_ = false; |
| 1391 | did_request_commit_ = false; |
| 1392 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1393 | host_impl_->ActivateAnimations(); |
| 1394 | |
| 1395 | // On activating an animation, we should request another frame so that we'll |
| 1396 | // continue ticking the animation. |
| 1397 | EXPECT_TRUE(did_request_next_frame_); |
| 1398 | EXPECT_FALSE(did_request_redraw_); |
| 1399 | EXPECT_FALSE(did_request_commit_); |
| 1400 | did_request_next_frame_ = false; |
| 1401 | did_request_redraw_ = false; |
| 1402 | did_request_commit_ = false; |
| 1403 | |
| 1404 | // The next frame after activating, we'll tick the animation again. |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1405 | host_impl_->Animate(); |
| 1406 | |
| 1407 | // An animation exists on the active layer. Doing Animate() requests another |
| 1408 | // frame after the current one. |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1409 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 492344054 | 2015-10-29 19:34:53 | [diff] [blame] | 1410 | // The animation should cause us to draw at the frame's deadline. |
| 1411 | EXPECT_TRUE(did_request_redraw_); |
danakj | b56d7d8 | 2015-08-28 19:28:59 | [diff] [blame] | 1412 | EXPECT_FALSE(did_request_commit_); |
| 1413 | } |
| 1414 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1415 | TEST_F(LayerTreeHostImplTest, AnimationSchedulingCommitToActiveTree) { |
| 1416 | FakeImplTaskRunnerProvider provider(nullptr); |
| 1417 | CreateHostImplWithTaskRunnerProvider(DefaultSettings(), CreateOutputSurface(), |
| 1418 | &provider); |
| 1419 | EXPECT_TRUE(host_impl_->CommitToActiveTree()); |
| 1420 | |
| 1421 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1422 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1423 | auto root_owned = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 1424 | auto* root = root_owned.get(); |
| 1425 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_owned)); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1426 | root->SetBounds(gfx::Size(50, 50)); |
| 1427 | root->SetHasRenderSurface(true); |
| 1428 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1429 | auto child_owned = LayerImpl::Create(host_impl_->active_tree(), 2); |
| 1430 | auto* child = child_owned.get(); |
| 1431 | root->test_properties()->AddChild(std::move(child_owned)); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1432 | child->SetBounds(gfx::Size(10, 10)); |
| 1433 | child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); |
| 1434 | child->SetDrawsContent(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1435 | |
| 1436 | host_impl_->active_tree()->SetElementIdsForTesting(); |
| 1437 | |
| 1438 | AddAnimatedTransformToElementWithPlayer(child->element_id(), timeline(), 10.0, |
| 1439 | 3, 0); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1440 | |
| 1441 | // Set up the property trees so that UpdateDrawProperties will work in |
| 1442 | // CommitComplete below. |
| 1443 | LayerImplList list; |
| 1444 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1445 | root, gfx::Size(50, 50), &list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1446 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1447 | |
| 1448 | EXPECT_FALSE(did_request_next_frame_); |
| 1449 | EXPECT_FALSE(did_request_redraw_); |
| 1450 | EXPECT_FALSE(did_request_commit_); |
| 1451 | |
| 1452 | host_impl_->CommitComplete(); |
| 1453 | |
| 1454 | // Animations on the active tree should be started and ticked, and a new frame |
| 1455 | // should be requested to continue ticking them. |
| 1456 | EXPECT_TRUE(did_request_next_frame_); |
| 1457 | EXPECT_TRUE(did_request_redraw_); |
| 1458 | EXPECT_FALSE(did_request_commit_); |
| 1459 | |
| 1460 | // Delete the LayerTreeHostImpl before the TaskRunnerProvider goes away. |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 1461 | host_impl_->ReleaseOutputSurface(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1462 | host_impl_ = nullptr; |
| 1463 | } |
| 1464 | |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1465 | TEST_F(LayerTreeHostImplTest, AnimationSchedulingOnLayerDestruction) { |
| 1466 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1467 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1468 | host_impl_->active_tree()->SetRootLayerForTesting( |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1469 | LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1470 | LayerImpl* root = *host_impl_->active_tree()->begin(); |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1471 | root->SetBounds(gfx::Size(50, 50)); |
| 1472 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 1473 | root->test_properties()->AddChild( |
| 1474 | LayerImpl::Create(host_impl_->active_tree(), 2)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 1475 | LayerImpl* child = root->test_properties()->children[0]; |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1476 | child->SetBounds(gfx::Size(10, 10)); |
| 1477 | child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); |
| 1478 | child->SetDrawsContent(true); |
| 1479 | |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 1480 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1481 | host_impl_->active_tree()->SetElementIdsForTesting(); |
| 1482 | |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1483 | // Add a translate animation. |
| 1484 | TransformOperations start; |
| 1485 | start.AppendTranslate(6.f, 7.f, 0.f); |
| 1486 | TransformOperations end; |
| 1487 | end.AppendTranslate(8.f, 9.f, 0.f); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1488 | AddAnimatedTransformToElementWithPlayer(child->element_id(), timeline(), 4.0, |
| 1489 | start, end); |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1490 | |
| 1491 | base::TimeTicks now = base::TimeTicks::Now(); |
| 1492 | host_impl_->WillBeginImplFrame( |
| 1493 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now)); |
| 1494 | EXPECT_TRUE(did_request_next_frame_); |
| 1495 | did_request_next_frame_ = false; |
| 1496 | |
| 1497 | host_impl_->ActivateAnimations(); |
| 1498 | // On activating an animation, we should request another frame so that we'll |
| 1499 | // continue ticking the animation. |
| 1500 | EXPECT_TRUE(did_request_next_frame_); |
| 1501 | did_request_next_frame_ = false; |
| 1502 | |
| 1503 | // The next frame after activating, we'll tick the animation again. |
| 1504 | host_impl_->Animate(); |
| 1505 | // An animation exists on the active layer. Doing Animate() requests another |
| 1506 | // frame after the current one. |
| 1507 | EXPECT_TRUE(did_request_next_frame_); |
| 1508 | did_request_next_frame_ = false; |
| 1509 | |
| 1510 | // Destroy layer, unregister animation target (element). |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 1511 | child->test_properties()->parent = nullptr; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 1512 | root->test_properties()->RemoveChild(child); |
loyso | 638ef70 | 2016-06-07 02:51:57 | [diff] [blame] | 1513 | child = nullptr; |
| 1514 | |
| 1515 | // Doing Animate() doesn't request another frame after the current one. |
| 1516 | host_impl_->Animate(); |
| 1517 | EXPECT_FALSE(did_request_next_frame_); |
| 1518 | |
| 1519 | host_impl_->Animate(); |
| 1520 | EXPECT_FALSE(did_request_next_frame_); |
| 1521 | } |
| 1522 | |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1523 | class MissingTilesLayer : public LayerImpl { |
| 1524 | public: |
| 1525 | MissingTilesLayer(LayerTreeImpl* layer_tree_impl, int id) |
| 1526 | : LayerImpl(layer_tree_impl, id), has_missing_tiles_(true) {} |
| 1527 | |
| 1528 | void set_has_missing_tiles(bool has_missing_tiles) { |
| 1529 | has_missing_tiles_ = has_missing_tiles; |
| 1530 | } |
| 1531 | |
| 1532 | void AppendQuads(RenderPass* render_pass, |
| 1533 | AppendQuadsData* append_quads_data) override { |
| 1534 | append_quads_data->num_missing_tiles += has_missing_tiles_; |
| 1535 | } |
| 1536 | |
| 1537 | private: |
| 1538 | bool has_missing_tiles_; |
| 1539 | }; |
| 1540 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1541 | TEST_F(LayerTreeHostImplTest, AnimationMarksLayerNotReady) { |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1542 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1543 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 1544 | host_impl_->active_tree()->SetRootLayerForTesting( |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1545 | LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1546 | LayerImpl* root = *host_impl_->active_tree()->begin(); |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1547 | root->SetBounds(gfx::Size(50, 50)); |
| 1548 | root->SetHasRenderSurface(true); |
| 1549 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 1550 | root->test_properties()->AddChild(std::unique_ptr<MissingTilesLayer>( |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1551 | new MissingTilesLayer(host_impl_->active_tree(), 2))); |
| 1552 | MissingTilesLayer* child = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 1553 | static_cast<MissingTilesLayer*>(root->test_properties()->children[0]); |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1554 | child->SetBounds(gfx::Size(10, 10)); |
| 1555 | child->draw_properties().visible_layer_rect = gfx::Rect(10, 10); |
| 1556 | child->SetDrawsContent(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1557 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1558 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1559 | host_impl_->active_tree()->SetElementIdsForTesting(); |
| 1560 | |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1561 | EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation()); |
| 1562 | |
| 1563 | // Add a translate from 6,7 to 8,9. |
| 1564 | TransformOperations start; |
| 1565 | start.AppendTranslate(6.f, 7.f, 0.f); |
| 1566 | TransformOperations end; |
| 1567 | end.AppendTranslate(8.f, 9.f, 0.f); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1568 | int animation_id = AddAnimatedTransformToElementWithPlayer( |
| 1569 | child->element_id(), timeline(), 4.0, start, end); |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1570 | |
| 1571 | base::TimeTicks now = base::TimeTicks::Now(); |
| 1572 | host_impl_->WillBeginImplFrame( |
| 1573 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now)); |
| 1574 | |
| 1575 | host_impl_->ActivateAnimations(); |
| 1576 | host_impl_->Animate(); |
| 1577 | |
| 1578 | EXPECT_FALSE(child->was_ever_ready_since_last_transform_animation()); |
| 1579 | |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1580 | host_impl_->ResetRequiresHighResToDraw(); |
| 1581 | |
| 1582 | // Child layer has an animating transform but missing tiles. |
| 1583 | FakeLayerTreeHostImpl::FrameData frame; |
| 1584 | DrawResult result = host_impl_->PrepareToDraw(&frame); |
| 1585 | EXPECT_EQ(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS, result); |
| 1586 | host_impl_->DidDrawAllLayers(frame); |
| 1587 | |
| 1588 | child->set_has_missing_tiles(false); |
| 1589 | |
| 1590 | // Child layer has an animating and no missing tiles. |
| 1591 | result = host_impl_->PrepareToDraw(&frame); |
| 1592 | EXPECT_EQ(DRAW_SUCCESS, result); |
| 1593 | EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation()); |
| 1594 | host_impl_->DidDrawAllLayers(frame); |
| 1595 | |
| 1596 | // Remove the animation. |
| 1597 | child->set_has_missing_tiles(true); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 1598 | RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(), |
| 1599 | animation_id); |
vmpstr | e1564a5 | 2015-11-24 19:43:15 | [diff] [blame] | 1600 | child->draw_properties().screen_space_transform_is_animating = false; |
| 1601 | |
| 1602 | // Child layer doesn't have an animation, but was never ready since the last |
| 1603 | // time it animated (and has missing tiles). |
| 1604 | result = host_impl_->PrepareToDraw(&frame); |
| 1605 | EXPECT_EQ(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS, result); |
| 1606 | EXPECT_FALSE(child->was_ever_ready_since_last_transform_animation()); |
| 1607 | host_impl_->DidDrawAllLayers(frame); |
| 1608 | |
| 1609 | child->set_has_missing_tiles(false); |
| 1610 | |
| 1611 | // Child layer doesn't have an animation and all tiles are ready. |
| 1612 | result = host_impl_->PrepareToDraw(&frame); |
| 1613 | EXPECT_EQ(DRAW_SUCCESS, result); |
| 1614 | EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation()); |
| 1615 | host_impl_->DidDrawAllLayers(frame); |
| 1616 | |
| 1617 | child->set_has_missing_tiles(true); |
| 1618 | |
| 1619 | // Child layer doesn't have an animation, and was ready at least once since |
| 1620 | // the last time it animated. |
| 1621 | result = host_impl_->PrepareToDraw(&frame); |
| 1622 | EXPECT_EQ(DRAW_SUCCESS, result); |
| 1623 | EXPECT_TRUE(child->was_ever_ready_since_last_transform_animation()); |
| 1624 | host_impl_->DidDrawAllLayers(frame); |
| 1625 | } |
| 1626 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1627 | TEST_F(LayerTreeHostImplTest, ImplPinchZoom) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 1628 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1629 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 1630 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 1631 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 1632 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1633 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1634 | EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 1635 | LayerImpl* container_layer = scroll_layer->scroll_clip_layer(); |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1636 | EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1637 | |
| 1638 | float min_page_scale = 1.f, max_page_scale = 4.f; |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 1639 | float page_scale_factor = 1.f; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1640 | |
| 1641 | // The impl-based pinch zoom should adjust the max scroll position. |
| 1642 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 1643 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 1644 | page_scale_factor, min_page_scale, max_page_scale); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 1645 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1646 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1647 | |
| 1648 | float page_scale_delta = 2.f; |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 1649 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1650 | host_impl_->ScrollBegin(BeginState(gfx::Point(50, 50)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1651 | InputHandler::TOUCHSCREEN); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1652 | host_impl_->PinchGestureBegin(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1653 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); |
| 1654 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1655 | host_impl_->ScrollEnd(EndState().get()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 1656 | EXPECT_FALSE(did_request_next_frame_); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1657 | EXPECT_TRUE(did_request_redraw_); |
| 1658 | EXPECT_TRUE(did_request_commit_); |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1659 | EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1660 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1661 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1662 | host_impl_->ProcessScrollDeltas(); |
| 1663 | EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
| 1664 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1665 | EXPECT_EQ(gfx::ScrollOffset(75.0, 75.0).ToString(), |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1666 | scroll_layer->MaxScrollOffset().ToString()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | // Scrolling after a pinch gesture should always be in local space. The |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 1670 | // scroll deltas have the page scale factor applied. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1671 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 1672 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 1673 | page_scale_factor, min_page_scale, max_page_scale); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 1674 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1675 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1676 | |
| 1677 | float page_scale_delta = 2.f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1678 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1679 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1680 | host_impl_->PinchGestureBegin(); |
| 1681 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); |
| 1682 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1683 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1684 | |
| 1685 | gfx::Vector2d scroll_delta(0, 10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1686 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1687 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 1688 | InputHandler::WHEEL) |
| 1689 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1690 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 1691 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 1692 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 1693 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1694 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 1695 | EXPECT_TRUE(ScrollInfoContains( |
| 1696 | *scroll_info.get(), scroll_layer->id(), |
| 1697 | gfx::Vector2d(0, scroll_delta.y() / page_scale_delta))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 1698 | } |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 1699 | } |
| 1700 | |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1701 | TEST_F(LayerTreeHostImplTest, ViewportScrollOrder) { |
| 1702 | LayerTreeSettings settings = DefaultSettings(); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1703 | CreateHostImpl(settings, |
| 1704 | CreateOutputSurface()); |
| 1705 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 4.f); |
| 1706 | |
| 1707 | const gfx::Size content_size(1000, 1000); |
| 1708 | const gfx::Size viewport_size(500, 500); |
| 1709 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 1710 | |
| 1711 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1712 | outer_scroll_layer->SetDrawsContent(true); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1713 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1714 | inner_scroll_layer->SetDrawsContent(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1715 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1716 | |
| 1717 | EXPECT_VECTOR_EQ( |
| 1718 | gfx::Vector2dF(500, 500), |
| 1719 | outer_scroll_layer->MaxScrollOffset()); |
| 1720 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1721 | host_impl_->ScrollBegin(BeginState(gfx::Point(250, 250)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1722 | InputHandler::TOUCHSCREEN); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1723 | host_impl_->PinchGestureBegin(); |
| 1724 | host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); |
| 1725 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1726 | host_impl_->ScrollEnd(EndState().get()); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1727 | |
| 1728 | // Sanity check - we're zoomed in, starting from the origin. |
| 1729 | EXPECT_VECTOR_EQ( |
| 1730 | gfx::Vector2dF(0, 0), |
| 1731 | outer_scroll_layer->CurrentScrollOffset()); |
| 1732 | EXPECT_VECTOR_EQ( |
| 1733 | gfx::Vector2dF(0, 0), |
| 1734 | inner_scroll_layer->CurrentScrollOffset()); |
| 1735 | |
| 1736 | // Scroll down - only the inner viewport should scroll. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1737 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1738 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1739 | host_impl_->ScrollBy( |
| 1740 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 1741 | host_impl_->ScrollEnd(EndState().get()); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1742 | |
| 1743 | EXPECT_VECTOR_EQ( |
| 1744 | gfx::Vector2dF(50, 50), |
| 1745 | inner_scroll_layer->CurrentScrollOffset()); |
| 1746 | EXPECT_VECTOR_EQ( |
| 1747 | gfx::Vector2dF(0, 0), |
| 1748 | outer_scroll_layer->CurrentScrollOffset()); |
| 1749 | |
| 1750 | // Scroll down - outer viewport should start scrolling after the inner is at |
| 1751 | // its maximum. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1752 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1753 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1754 | host_impl_->ScrollBy( |
| 1755 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(1000.f, 1000.f)).get()); |
| 1756 | host_impl_->ScrollEnd(EndState().get()); |
bokan | eaee880f | 2015-08-04 18:01:07 | [diff] [blame] | 1757 | |
| 1758 | EXPECT_VECTOR_EQ( |
| 1759 | gfx::Vector2dF(250, 250), |
| 1760 | inner_scroll_layer->CurrentScrollOffset()); |
| 1761 | EXPECT_VECTOR_EQ( |
| 1762 | gfx::Vector2dF(300, 300), |
| 1763 | outer_scroll_layer->CurrentScrollOffset()); |
| 1764 | } |
| 1765 | |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1766 | // Make sure scrolls smaller than a unit applied to the viewport don't get |
| 1767 | // dropped. crbug.com/539334. |
| 1768 | TEST_F(LayerTreeHostImplTest, ScrollViewportWithFractionalAmounts) { |
| 1769 | LayerTreeSettings settings = DefaultSettings(); |
| 1770 | CreateHostImpl(settings, CreateOutputSurface()); |
| 1771 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
| 1772 | |
| 1773 | const gfx::Size content_size(1000, 1000); |
| 1774 | const gfx::Size viewport_size(500, 500); |
| 1775 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 1776 | |
| 1777 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1778 | outer_scroll_layer->SetDrawsContent(true); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1779 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1780 | inner_scroll_layer->SetDrawsContent(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1781 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1782 | |
| 1783 | // Sanity checks. |
| 1784 | EXPECT_VECTOR_EQ( |
| 1785 | gfx::Vector2dF(500, 500), |
| 1786 | outer_scroll_layer->MaxScrollOffset()); |
| 1787 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll_layer->CurrentScrollOffset()); |
| 1788 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), inner_scroll_layer->CurrentScrollOffset()); |
| 1789 | |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1790 | // Scroll only the layout viewport. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1791 | host_impl_->ScrollBegin(BeginState(gfx::Point(250, 250)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1792 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1793 | host_impl_->ScrollBy( |
| 1794 | UpdateState(gfx::Point(250, 250), gfx::Vector2dF(0.125f, 0.125f)).get()); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1795 | EXPECT_VECTOR2DF_EQ( |
| 1796 | gfx::Vector2dF(0.125f, 0.125f), |
| 1797 | outer_scroll_layer->CurrentScrollOffset()); |
| 1798 | EXPECT_VECTOR2DF_EQ( |
| 1799 | gfx::Vector2dF(0, 0), |
| 1800 | inner_scroll_layer->CurrentScrollOffset()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1801 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1802 | |
| 1803 | host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 1.f, 2.f); |
| 1804 | |
| 1805 | // Now that we zoomed in, the scroll should be applied to the inner viewport. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1806 | host_impl_->ScrollBegin(BeginState(gfx::Point(250, 250)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1807 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1808 | host_impl_->ScrollBy( |
| 1809 | UpdateState(gfx::Point(250, 250), gfx::Vector2dF(0.5f, 0.5f)).get()); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1810 | EXPECT_VECTOR2DF_EQ( |
| 1811 | gfx::Vector2dF(0.125f, 0.125f), |
| 1812 | outer_scroll_layer->CurrentScrollOffset()); |
| 1813 | EXPECT_VECTOR2DF_EQ( |
| 1814 | gfx::Vector2dF(0.25f, 0.25f), |
| 1815 | inner_scroll_layer->CurrentScrollOffset()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1816 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 49c85a92 | 2015-10-07 21:08:03 | [diff] [blame] | 1817 | } |
| 1818 | |
bokan | 32f1b90 | 2015-08-12 22:25:32 | [diff] [blame] | 1819 | // Tests that scrolls during a pinch gesture (i.e. "two-finger" scrolls) work |
| 1820 | // as expected. That is, scrolling during a pinch should bubble from the inner |
| 1821 | // to the outer viewport. |
| 1822 | TEST_F(LayerTreeHostImplTest, ScrollDuringPinchGesture) { |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1823 | LayerTreeSettings settings = DefaultSettings(); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1824 | CreateHostImpl(settings, |
| 1825 | CreateOutputSurface()); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 1826 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1827 | |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1828 | const gfx::Size content_size(1000, 1000); |
| 1829 | const gfx::Size viewport_size(500, 500); |
| 1830 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1831 | |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1832 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1833 | outer_scroll_layer->SetDrawsContent(true); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1834 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 1835 | inner_scroll_layer->SetDrawsContent(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 1836 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1837 | |
| 1838 | EXPECT_VECTOR_EQ( |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1839 | gfx::Vector2dF(500, 500), |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1840 | outer_scroll_layer->MaxScrollOffset()); |
| 1841 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1842 | host_impl_->ScrollBegin(BeginState(gfx::Point(250, 250)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1843 | InputHandler::TOUCHSCREEN); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1844 | host_impl_->PinchGestureBegin(); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1845 | |
bokan | 32f1b90 | 2015-08-12 22:25:32 | [diff] [blame] | 1846 | host_impl_->PinchGestureUpdate(2, gfx::Point(250, 250)); |
| 1847 | EXPECT_VECTOR_EQ( |
| 1848 | gfx::Vector2dF(0, 0), |
| 1849 | outer_scroll_layer->CurrentScrollOffset()); |
| 1850 | EXPECT_VECTOR_EQ( |
| 1851 | gfx::Vector2dF(125, 125), |
| 1852 | inner_scroll_layer->CurrentScrollOffset()); |
| 1853 | |
| 1854 | // Needed so that the pinch is accounted for in draw properties. |
| 1855 | DrawFrame(); |
| 1856 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1857 | host_impl_->ScrollBy( |
| 1858 | UpdateState(gfx::Point(250, 250), gfx::Vector2dF(10.f, 10.f)).get()); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1859 | EXPECT_VECTOR_EQ( |
| 1860 | gfx::Vector2dF(0, 0), |
| 1861 | outer_scroll_layer->CurrentScrollOffset()); |
| 1862 | EXPECT_VECTOR_EQ( |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1863 | gfx::Vector2dF(130, 130), |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1864 | inner_scroll_layer->CurrentScrollOffset()); |
bokan | 32f1b90 | 2015-08-12 22:25:32 | [diff] [blame] | 1865 | |
| 1866 | DrawFrame(); |
| 1867 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1868 | host_impl_->ScrollBy( |
| 1869 | UpdateState(gfx::Point(250, 250), gfx::Vector2dF(400.f, 400.f)).get()); |
bokan | 32f1b90 | 2015-08-12 22:25:32 | [diff] [blame] | 1870 | EXPECT_VECTOR_EQ( |
| 1871 | gfx::Vector2dF(80, 80), |
| 1872 | outer_scroll_layer->CurrentScrollOffset()); |
| 1873 | EXPECT_VECTOR_EQ( |
| 1874 | gfx::Vector2dF(250, 250), |
| 1875 | inner_scroll_layer->CurrentScrollOffset()); |
| 1876 | |
| 1877 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1878 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 9e556961 | 2015-06-09 18:41:20 | [diff] [blame] | 1879 | } |
| 1880 | |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1881 | // Tests the "snapping" of pinch-zoom gestures to the screen edge. That is, when |
| 1882 | // a pinch zoom is anchored within a certain margin of the screen edge, we |
| 1883 | // should assume the user means to scroll into the edge of the screen. |
| 1884 | TEST_F(LayerTreeHostImplTest, PinchZoomSnapsToScreenEdge) { |
| 1885 | LayerTreeSettings settings = DefaultSettings(); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1886 | CreateHostImpl(settings, |
| 1887 | CreateOutputSurface()); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 1888 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1889 | |
| 1890 | const gfx::Size content_size(1000, 1000); |
| 1891 | const gfx::Size viewport_size(500, 500); |
| 1892 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 1893 | |
| 1894 | int offsetFromEdge = Viewport::kPinchZoomSnapMarginDips - 5; |
| 1895 | gfx::Point anchor(viewport_size.width() - offsetFromEdge, |
| 1896 | viewport_size.height() - offsetFromEdge); |
| 1897 | |
| 1898 | // Pinch in within the margins. The scroll should stay exactly locked to the |
| 1899 | // bottom and right. |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1900 | host_impl_->ScrollBegin(BeginState(anchor).get(), InputHandler::TOUCHSCREEN); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1901 | host_impl_->PinchGestureBegin(); |
| 1902 | host_impl_->PinchGestureUpdate(2, anchor); |
| 1903 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1904 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1905 | |
| 1906 | EXPECT_VECTOR_EQ( |
| 1907 | gfx::Vector2dF(250, 250), |
| 1908 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 1909 | |
| 1910 | // Reset. |
| 1911 | host_impl_->active_tree()->SetPageScaleOnActiveTree(1.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1912 | SetScrollOffsetDelta(host_impl_->InnerViewportScrollLayer(), gfx::Vector2d()); |
| 1913 | SetScrollOffsetDelta(host_impl_->OuterViewportScrollLayer(), gfx::Vector2d()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1914 | |
| 1915 | // Pinch in within the margins. The scroll should stay exactly locked to the |
| 1916 | // top and left. |
| 1917 | anchor = gfx::Point(offsetFromEdge, offsetFromEdge); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1918 | host_impl_->ScrollBegin(BeginState(anchor).get(), InputHandler::TOUCHSCREEN); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1919 | host_impl_->PinchGestureBegin(); |
| 1920 | host_impl_->PinchGestureUpdate(2, anchor); |
| 1921 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1922 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1923 | |
| 1924 | EXPECT_VECTOR_EQ( |
| 1925 | gfx::Vector2dF(0, 0), |
| 1926 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 1927 | |
| 1928 | // Reset. |
| 1929 | host_impl_->active_tree()->SetPageScaleOnActiveTree(1.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1930 | SetScrollOffsetDelta(host_impl_->InnerViewportScrollLayer(), gfx::Vector2d()); |
| 1931 | SetScrollOffsetDelta(host_impl_->OuterViewportScrollLayer(), gfx::Vector2d()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1932 | |
| 1933 | // Pinch in just outside the margin. There should be no snapping. |
| 1934 | offsetFromEdge = Viewport::kPinchZoomSnapMarginDips; |
| 1935 | anchor = gfx::Point(offsetFromEdge, offsetFromEdge); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1936 | host_impl_->ScrollBegin(BeginState(anchor).get(), InputHandler::TOUCHSCREEN); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1937 | host_impl_->PinchGestureBegin(); |
| 1938 | host_impl_->PinchGestureUpdate(2, anchor); |
| 1939 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1940 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1941 | |
| 1942 | EXPECT_VECTOR_EQ( |
| 1943 | gfx::Vector2dF(50, 50), |
| 1944 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 1945 | |
| 1946 | // Reset. |
| 1947 | host_impl_->active_tree()->SetPageScaleOnActiveTree(1.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 1948 | SetScrollOffsetDelta(host_impl_->InnerViewportScrollLayer(), gfx::Vector2d()); |
| 1949 | SetScrollOffsetDelta(host_impl_->OuterViewportScrollLayer(), gfx::Vector2d()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1950 | |
| 1951 | // Pinch in just outside the margin. There should be no snapping. |
| 1952 | offsetFromEdge = Viewport::kPinchZoomSnapMarginDips; |
| 1953 | anchor = gfx::Point(viewport_size.width() - offsetFromEdge, |
| 1954 | viewport_size.height() - offsetFromEdge); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 1955 | host_impl_->ScrollBegin(BeginState(anchor).get(), InputHandler::TOUCHSCREEN); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1956 | host_impl_->PinchGestureBegin(); |
| 1957 | host_impl_->PinchGestureUpdate(2, anchor); |
| 1958 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1959 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1960 | |
| 1961 | EXPECT_VECTOR_EQ( |
| 1962 | gfx::Vector2dF(200, 200), |
| 1963 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 1964 | } |
| 1965 | |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1966 | TEST_F(LayerTreeHostImplTest, ImplPinchZoomWheelBubbleBetweenViewports) { |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1967 | const gfx::Size content_size(200, 200); |
| 1968 | const gfx::Size viewport_size(100, 100); |
| 1969 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1970 | |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1971 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
bokan | 499dd08 | 2015-06-24 15:35:19 | [diff] [blame] | 1972 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1973 | |
| 1974 | // Zoom into the page by a 2X factor |
| 1975 | float min_page_scale = 1.f, max_page_scale = 4.f; |
| 1976 | float page_scale_factor = 2.f; |
| 1977 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
| 1978 | page_scale_factor, min_page_scale, max_page_scale); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 1979 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1980 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 1981 | // Scroll by a small amount, there should be no bubbling to the outer |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1982 | // viewport. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1983 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 1984 | InputHandler::WHEEL); |
| 1985 | host_impl_->ScrollBy( |
| 1986 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(10.f, 20.f)).get()); |
| 1987 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1988 | |
| 1989 | EXPECT_VECTOR_EQ( |
| 1990 | gfx::Vector2dF(5, 10), |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 1991 | inner_scroll_layer->CurrentScrollOffset()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1992 | EXPECT_VECTOR_EQ( |
| 1993 | gfx::Vector2dF(), |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 1994 | outer_scroll_layer->CurrentScrollOffset()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 1995 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 1996 | // Scroll by the inner viewport's max scroll extent, the remainder |
| 1997 | // should bubble up to the outer viewport. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 1998 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 1999 | InputHandler::WHEEL); |
| 2000 | host_impl_->ScrollBy( |
| 2001 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 2002 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 2003 | |
| 2004 | EXPECT_VECTOR_EQ( |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 2005 | gfx::Vector2dF(50, 50), |
| 2006 | inner_scroll_layer->CurrentScrollOffset()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 2007 | EXPECT_VECTOR_EQ( |
| 2008 | gfx::Vector2dF(5, 10), |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 2009 | outer_scroll_layer->CurrentScrollOffset()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 2010 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 2011 | // Scroll by the outer viewport's max scroll extent, it should all go to the |
| 2012 | // outer viewport. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2013 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 2014 | InputHandler::WHEEL); |
| 2015 | host_impl_->ScrollBy( |
| 2016 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(190.f, 180.f)).get()); |
| 2017 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 74efa33 | 2015-05-20 19:50:07 | [diff] [blame] | 2018 | |
| 2019 | EXPECT_VECTOR_EQ( |
| 2020 | gfx::Vector2dF(100, 100), |
| 2021 | outer_scroll_layer->CurrentScrollOffset()); |
| 2022 | EXPECT_VECTOR_EQ( |
| 2023 | gfx::Vector2dF(50, 50), |
| 2024 | inner_scroll_layer->CurrentScrollOffset()); |
| 2025 | } |
| 2026 | |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 2027 | TEST_F(LayerTreeHostImplTest, ScrollWithSwapPromises) { |
| 2028 | ui::LatencyInfo latency_info; |
miletus | 45effdc4 | 2015-08-05 00:29:18 | [diff] [blame] | 2029 | latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, |
| 2030 | 1234); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2031 | std::unique_ptr<SwapPromise> swap_promise( |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 2032 | new LatencyInfoSwapPromise(latency_info)); |
| 2033 | |
| 2034 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 2035 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2036 | host_impl_ |
| 2037 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 2038 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 2039 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2040 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 2041 | host_impl_->QueueSwapPromiseForMainThreadScrollUpdate( |
| 2042 | std::move(swap_promise)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2043 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 2044 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2045 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 2046 | host_impl_->ProcessScrollDeltas(); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 2047 | EXPECT_EQ(1u, scroll_info->swap_promises.size()); |
miletus | 45effdc4 | 2015-08-05 00:29:18 | [diff] [blame] | 2048 | EXPECT_EQ(latency_info.trace_id(), scroll_info->swap_promises[0]->TraceId()); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 2049 | } |
| 2050 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 2051 | // Test that scrolls targeting a layer with a non-null scroll_parent() don't |
| 2052 | // bubble up. |
| 2053 | TEST_F(LayerTreeHostImplTest, ScrollDoesntBubble) { |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2054 | LayerImpl* viewport_scroll = |
| 2055 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 2056 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 2057 | |
| 2058 | // 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] | 2059 | // to the other. Scrolls shouldn't bubbling from the child. |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2060 | LayerImpl *parent; |
| 2061 | LayerImpl *child; |
| 2062 | LayerImpl *child_clip; |
| 2063 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2064 | std::unique_ptr<LayerImpl> scroll_parent_clip = |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2065 | LayerImpl::Create(host_impl_->active_tree(), 6); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2066 | std::unique_ptr<LayerImpl> scroll_parent = |
| 2067 | CreateScrollableLayer(7, gfx::Size(10, 10), scroll_parent_clip.get()); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2068 | parent = scroll_parent.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2069 | scroll_parent_clip->test_properties()->AddChild(std::move(scroll_parent)); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2070 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2071 | viewport_scroll->test_properties()->AddChild(std::move(scroll_parent_clip)); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2072 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2073 | std::unique_ptr<LayerImpl> scroll_child_clip = |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2074 | LayerImpl::Create(host_impl_->active_tree(), 8); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2075 | std::unique_ptr<LayerImpl> scroll_child = |
| 2076 | CreateScrollableLayer(9, gfx::Size(10, 10), scroll_child_clip.get()); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2077 | child = scroll_child.get(); |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 2078 | scroll_child->SetPosition(gfx::PointF(20.f, 20.f)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2079 | scroll_child_clip->test_properties()->AddChild(std::move(scroll_child)); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2080 | |
| 2081 | child_clip = scroll_child_clip.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2082 | viewport_scroll->test_properties()->AddChild(std::move(scroll_child_clip)); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2083 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 2084 | child_clip->test_properties()->scroll_parent = parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2085 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 2086 | new std::set<LayerImpl*>); |
jaydasika | b5a1a8c | 2015-09-29 18:38:49 | [diff] [blame] | 2087 | scroll_children->insert(child_clip); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 2088 | parent->test_properties()->scroll_children.reset(scroll_children.release()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2089 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2090 | |
| 2091 | DrawFrame(); |
| 2092 | |
| 2093 | { |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2094 | host_impl_->ScrollBegin(BeginState(gfx::Point(21, 21)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2095 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2096 | host_impl_->ScrollBy( |
| 2097 | UpdateState(gfx::Point(21, 21), gfx::Vector2d(5, 5)).get()); |
| 2098 | host_impl_->ScrollBy( |
| 2099 | UpdateState(gfx::Point(21, 21), gfx::Vector2d(100, 100)).get()); |
| 2100 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2101 | |
| 2102 | // The child should be fully scrolled by the first ScrollBy. |
| 2103 | EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 5), child->CurrentScrollOffset()); |
| 2104 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 2105 | // The scroll_parent shouldn't receive the second ScrollBy. |
| 2106 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), parent->CurrentScrollOffset()); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2107 | |
| 2108 | // The viewport shouldn't have been scrolled at all. |
| 2109 | EXPECT_VECTOR_EQ( |
| 2110 | gfx::Vector2dF(0, 0), |
| 2111 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 2112 | EXPECT_VECTOR_EQ( |
| 2113 | gfx::Vector2dF(0, 0), |
| 2114 | host_impl_->OuterViewportScrollLayer()->CurrentScrollOffset()); |
| 2115 | } |
| 2116 | |
| 2117 | { |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2118 | host_impl_->ScrollBegin(BeginState(gfx::Point(21, 21)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2119 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2120 | host_impl_->ScrollBy( |
| 2121 | UpdateState(gfx::Point(21, 21), gfx::Vector2d(3, 4)).get()); |
| 2122 | host_impl_->ScrollBy( |
| 2123 | UpdateState(gfx::Point(21, 21), gfx::Vector2d(2, 1)).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_->ScrollEnd(EndState().get()); |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2129 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 2130 | // The ScrollBy's should scroll the parent to its extent. |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2131 | EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 5), parent->CurrentScrollOffset()); |
| 2132 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 2133 | // The viewport shouldn't receive any scroll delta. |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2134 | EXPECT_VECTOR_EQ( |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 2135 | gfx::Vector2dF(0, 0), |
bokan | 79ab8af | 2015-06-11 14:01:15 | [diff] [blame] | 2136 | host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 2137 | EXPECT_VECTOR_EQ( |
| 2138 | gfx::Vector2dF(0, 0), |
| 2139 | host_impl_->OuterViewportScrollLayer()->CurrentScrollOffset()); |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2144 | TEST_F(LayerTreeHostImplTest, PinchGesture) { |
| 2145 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 2146 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 2147 | DrawFrame(); |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2148 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 2149 | LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2150 | DCHECK(scroll_layer); |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2151 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2152 | float min_page_scale = 1.f; |
| 2153 | float max_page_scale = 4.f; |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2154 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2155 | // Basic pinch zoom in gesture |
| 2156 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2157 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2158 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2159 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2160 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2161 | float page_scale_delta = 2.f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2162 | host_impl_->ScrollBegin(BeginState(gfx::Point(50, 50)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2163 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2164 | host_impl_->PinchGestureBegin(); |
| 2165 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); |
| 2166 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2167 | host_impl_->ScrollEnd(EndState().get()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2168 | EXPECT_FALSE(did_request_next_frame_); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2169 | EXPECT_TRUE(did_request_redraw_); |
| 2170 | EXPECT_TRUE(did_request_commit_); |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2171 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2172 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2173 | host_impl_->ProcessScrollDeltas(); |
| 2174 | EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
| 2175 | } |
| 2176 | |
| 2177 | // Zoom-in clamping |
| 2178 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2179 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2180 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2181 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2182 | float page_scale_delta = 10.f; |
| 2183 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2184 | host_impl_->ScrollBegin(BeginState(gfx::Point(50, 50)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2185 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2186 | host_impl_->PinchGestureBegin(); |
| 2187 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); |
| 2188 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2189 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2190 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2191 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2192 | host_impl_->ProcessScrollDeltas(); |
| 2193 | EXPECT_EQ(scroll_info->page_scale_delta, max_page_scale); |
| 2194 | } |
| 2195 | |
| 2196 | // Zoom-out clamping |
| 2197 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2198 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2199 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2200 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 2201 | scroll_layer->layer_tree_impl() |
| 2202 | ->property_trees() |
| 2203 | ->scroll_tree.CollectScrollDeltasForTesting(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2204 | scroll_layer->layer_tree_impl() |
| 2205 | ->property_trees() |
| 2206 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2207 | scroll_layer->id(), gfx::ScrollOffset(50, 50)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2208 | |
| 2209 | float page_scale_delta = 0.1f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2210 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2211 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2212 | host_impl_->PinchGestureBegin(); |
| 2213 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); |
| 2214 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2215 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2216 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2217 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2218 | host_impl_->ProcessScrollDeltas(); |
| 2219 | EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); |
| 2220 | |
| 2221 | EXPECT_TRUE(scroll_info->scrolls.empty()); |
| 2222 | } |
| 2223 | |
| 2224 | // Two-finger panning should not happen based on pinch events only |
| 2225 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2226 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2227 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2228 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 2229 | scroll_layer->layer_tree_impl() |
| 2230 | ->property_trees() |
| 2231 | ->scroll_tree.CollectScrollDeltasForTesting(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2232 | scroll_layer->layer_tree_impl() |
| 2233 | ->property_trees() |
| 2234 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2235 | scroll_layer->id(), gfx::ScrollOffset(20, 20)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2236 | |
| 2237 | float page_scale_delta = 1.f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2238 | host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2239 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2240 | host_impl_->PinchGestureBegin(); |
| 2241 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); |
| 2242 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); |
| 2243 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2244 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2245 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2246 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2247 | host_impl_->ProcessScrollDeltas(); |
| 2248 | EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
| 2249 | EXPECT_TRUE(scroll_info->scrolls.empty()); |
| 2250 | } |
| 2251 | |
| 2252 | // Two-finger panning should work with interleaved scroll events |
| 2253 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2254 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2255 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2256 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 2257 | scroll_layer->layer_tree_impl() |
| 2258 | ->property_trees() |
| 2259 | ->scroll_tree.CollectScrollDeltasForTesting(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2260 | scroll_layer->layer_tree_impl() |
| 2261 | ->property_trees() |
| 2262 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2263 | scroll_layer->id(), gfx::ScrollOffset(20, 20)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2264 | |
| 2265 | float page_scale_delta = 1.f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2266 | host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2267 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2268 | host_impl_->PinchGestureBegin(); |
| 2269 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2270 | host_impl_->ScrollBy( |
| 2271 | UpdateState(gfx::Point(10, 10), gfx::Vector2d(-10, -10)).get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2272 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); |
| 2273 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2274 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2275 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2276 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2277 | host_impl_->ProcessScrollDeltas(); |
| 2278 | EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 2279 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
| 2280 | gfx::Vector2d(-10, -10))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2281 | } |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2282 | |
| 2283 | // Two-finger panning should work when starting fully zoomed out. |
| 2284 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2285 | host_impl_->active_tree()->PushPageScaleFromMainThread(0.5f, 0.5f, 4.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2286 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 2287 | scroll_layer->layer_tree_impl() |
| 2288 | ->property_trees() |
| 2289 | ->scroll_tree.CollectScrollDeltasForTesting(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2290 | scroll_layer->layer_tree_impl() |
| 2291 | ->property_trees() |
| 2292 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 2293 | gfx::ScrollOffset(0, 0)); |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2294 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2295 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 2296 | InputHandler::TOUCHSCREEN); |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2297 | host_impl_->PinchGestureBegin(); |
| 2298 | host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); |
| 2299 | host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 2300 | |
| 2301 | // Needed so layer transform includes page scale. |
| 2302 | DrawFrame(); |
| 2303 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2304 | host_impl_->ScrollBy( |
| 2305 | UpdateState(gfx::Point(0, 0), gfx::Vector2d(10, 10)).get()); |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2306 | host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10)); |
| 2307 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2308 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2309 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2310 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2311 | host_impl_->ProcessScrollDeltas(); |
| 2312 | EXPECT_EQ(scroll_info->page_scale_delta, 2.f); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 2313 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 2314 | gfx::Vector2d(10, 10))); |
[email protected] | 9ec24df | 2013-08-09 23:32:57 | [diff] [blame] | 2315 | } |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2316 | } |
| 2317 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2318 | TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { |
| 2319 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 2320 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 2321 | DrawFrame(); |
[email protected] | df8f44f | 2013-01-08 08:00:31 | [diff] [blame] | 2322 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 2323 | LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2324 | DCHECK(scroll_layer); |
[email protected] | df8f44f | 2013-01-08 08:00:31 | [diff] [blame] | 2325 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2326 | float min_page_scale = 0.5f; |
| 2327 | float max_page_scale = 4.f; |
| 2328 | base::TimeTicks start_time = base::TimeTicks() + |
| 2329 | base::TimeDelta::FromSeconds(1); |
| 2330 | base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 2331 | base::TimeTicks halfway_through_animation = start_time + duration / 2; |
| 2332 | base::TimeTicks end_time = start_time + duration; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2333 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2334 | BeginFrameArgs begin_frame_args = |
| 2335 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 2336 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2337 | // Non-anchor zoom-in |
| 2338 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2339 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2340 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2341 | scroll_layer->layer_tree_impl() |
| 2342 | ->property_trees() |
| 2343 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2344 | scroll_layer->id(), gfx::ScrollOffset(50, 50)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2345 | |
[email protected] | c232196 | 2014-04-28 19:16:42 | [diff] [blame] | 2346 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2347 | did_request_next_frame_ = false; |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2348 | host_impl_->active_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2349 | std::unique_ptr<PendingPageScaleAnimation>( |
| 2350 | new PendingPageScaleAnimation(gfx::Vector2d(), false, 2.f, |
| 2351 | duration))); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2352 | host_impl_->ActivateSyncTree(); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 2353 | EXPECT_FALSE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2354 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 2355 | |
| 2356 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2357 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2358 | begin_frame_args.frame_time = start_time; |
| 2359 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2360 | host_impl_->Animate(); |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2361 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2362 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2363 | host_impl_->DidFinishImplFrame(); |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2364 | |
| 2365 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2366 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2367 | begin_frame_args.frame_time = halfway_through_animation; |
| 2368 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2369 | host_impl_->Animate(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2370 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2371 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2372 | host_impl_->DidFinishImplFrame(); |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2373 | |
| 2374 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2375 | did_request_next_frame_ = false; |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2376 | did_request_commit_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2377 | begin_frame_args.frame_time = end_time; |
| 2378 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2379 | host_impl_->Animate(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2380 | EXPECT_TRUE(did_request_commit_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2381 | EXPECT_FALSE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2382 | host_impl_->DidFinishImplFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2383 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2384 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2385 | host_impl_->ProcessScrollDeltas(); |
| 2386 | EXPECT_EQ(scroll_info->page_scale_delta, 2); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 2387 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
| 2388 | gfx::Vector2d(-50, -50))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2389 | } |
| 2390 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2391 | start_time += base::TimeDelta::FromSeconds(10); |
| 2392 | halfway_through_animation += base::TimeDelta::FromSeconds(10); |
| 2393 | end_time += base::TimeDelta::FromSeconds(10); |
| 2394 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2395 | // Anchor zoom-out |
| 2396 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2397 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2398 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2399 | scroll_layer->layer_tree_impl() |
| 2400 | ->property_trees() |
| 2401 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2402 | scroll_layer->id(), gfx::ScrollOffset(50, 50)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2403 | |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 2404 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2405 | did_request_next_frame_ = false; |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2406 | host_impl_->active_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2407 | std::unique_ptr<PendingPageScaleAnimation>( |
| 2408 | new PendingPageScaleAnimation(gfx::Vector2d(25, 25), true, |
| 2409 | min_page_scale, duration))); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2410 | host_impl_->ActivateSyncTree(); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 2411 | EXPECT_FALSE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2412 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 2413 | |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2414 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2415 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2416 | begin_frame_args.frame_time = start_time; |
| 2417 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2418 | host_impl_->Animate(); |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2419 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2420 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2421 | host_impl_->DidFinishImplFrame(); |
[email protected] | 34e1b51 | 2013-09-26 17:32:33 | [diff] [blame] | 2422 | |
| 2423 | did_request_redraw_ = false; |
| 2424 | did_request_commit_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2425 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2426 | begin_frame_args.frame_time = end_time; |
| 2427 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2428 | host_impl_->Animate(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2429 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2430 | EXPECT_FALSE(did_request_next_frame_); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2431 | EXPECT_TRUE(did_request_commit_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2432 | host_impl_->DidFinishImplFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2433 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2434 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2435 | host_impl_->ProcessScrollDeltas(); |
| 2436 | EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); |
| 2437 | // Pushed to (0,0) via clamping against contents layer size. |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 2438 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
| 2439 | gfx::Vector2d(-50, -50))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2440 | } |
[email protected] | df8f44f | 2013-01-08 08:00:31 | [diff] [blame] | 2441 | } |
| 2442 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2443 | TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) { |
| 2444 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 2445 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 2446 | DrawFrame(); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 2447 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 2448 | LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2449 | DCHECK(scroll_layer); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 2450 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2451 | float min_page_scale = 0.5f; |
| 2452 | float max_page_scale = 4.f; |
| 2453 | base::TimeTicks start_time = base::TimeTicks() + |
| 2454 | base::TimeDelta::FromSeconds(1); |
| 2455 | base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 2456 | base::TimeTicks halfway_through_animation = start_time + duration / 2; |
| 2457 | base::TimeTicks end_time = start_time + duration; |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 2458 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2459 | BeginFrameArgs begin_frame_args = |
| 2460 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 2461 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2462 | // Anchor zoom with unchanged page scale should not change scroll or scale. |
| 2463 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2464 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2465 | max_page_scale); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2466 | scroll_layer->layer_tree_impl() |
| 2467 | ->property_trees() |
| 2468 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2469 | scroll_layer->id(), gfx::ScrollOffset(50, 50)); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 2470 | |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2471 | host_impl_->active_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2472 | std::unique_ptr<PendingPageScaleAnimation>( |
| 2473 | new PendingPageScaleAnimation(gfx::Vector2d(), true, 1.f, |
| 2474 | duration))); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2475 | host_impl_->ActivateSyncTree(); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2476 | begin_frame_args.frame_time = start_time; |
| 2477 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2478 | host_impl_->Animate(); |
| 2479 | host_impl_->DidFinishImplFrame(); |
| 2480 | |
| 2481 | begin_frame_args.frame_time = halfway_through_animation; |
| 2482 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2483 | host_impl_->Animate(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2484 | EXPECT_TRUE(did_request_redraw_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2485 | host_impl_->DidFinishImplFrame(); |
| 2486 | |
| 2487 | begin_frame_args.frame_time = end_time; |
| 2488 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2489 | host_impl_->Animate(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2490 | EXPECT_TRUE(did_request_commit_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2491 | host_impl_->DidFinishImplFrame(); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 2492 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2493 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 2494 | host_impl_->ProcessScrollDeltas(); |
| 2495 | EXPECT_EQ(scroll_info->page_scale_delta, 1); |
| 2496 | ExpectNone(*scroll_info, scroll_layer->id()); |
| 2497 | } |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 2498 | } |
| 2499 | |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2500 | TEST_F(LayerTreeHostImplTest, PageScaleAnimationTransferedOnSyncTreeActivate) { |
| 2501 | host_impl_->CreatePendingTree(); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 2502 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2503 | CreateScrollAndContentsLayers( |
| 2504 | host_impl_->pending_tree(), |
| 2505 | gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2506 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2507 | host_impl_->ActivateSyncTree(); |
| 2508 | DrawFrame(); |
| 2509 | |
| 2510 | LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 2511 | DCHECK(scroll_layer); |
| 2512 | |
| 2513 | float min_page_scale = 0.5f; |
| 2514 | float max_page_scale = 4.f; |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 2515 | host_impl_->sync_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2516 | max_page_scale); |
| 2517 | host_impl_->ActivateSyncTree(); |
| 2518 | |
| 2519 | base::TimeTicks start_time = base::TimeTicks() + |
| 2520 | base::TimeDelta::FromSeconds(1); |
| 2521 | base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
aelias | 74c3935 | 2014-10-14 03:48:14 | [diff] [blame] | 2522 | base::TimeTicks third_through_animation = start_time + duration / 3; |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2523 | base::TimeTicks halfway_through_animation = start_time + duration / 2; |
| 2524 | base::TimeTicks end_time = start_time + duration; |
| 2525 | float target_scale = 2.f; |
| 2526 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2527 | BeginFrameArgs begin_frame_args = |
| 2528 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 2529 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2530 | scroll_layer->layer_tree_impl() |
| 2531 | ->property_trees() |
| 2532 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 2533 | gfx::ScrollOffset(50, 50)); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2534 | |
| 2535 | // Make sure TakePageScaleAnimation works properly. |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2536 | |
| 2537 | host_impl_->sync_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2538 | std::unique_ptr<PendingPageScaleAnimation>(new PendingPageScaleAnimation( |
| 2539 | gfx::Vector2d(), false, target_scale, duration))); |
| 2540 | std::unique_ptr<PendingPageScaleAnimation> psa = |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2541 | host_impl_->sync_tree()->TakePendingPageScaleAnimation(); |
| 2542 | EXPECT_EQ(target_scale, psa->scale); |
| 2543 | EXPECT_EQ(duration, psa->duration); |
| 2544 | EXPECT_EQ(nullptr, host_impl_->sync_tree()->TakePendingPageScaleAnimation()); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2545 | |
| 2546 | // Recreate the PSA. Nothing should happen here since the tree containing the |
| 2547 | // PSA hasn't been activated yet. |
| 2548 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2549 | did_request_next_frame_ = false; |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2550 | host_impl_->sync_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2551 | std::unique_ptr<PendingPageScaleAnimation>(new PendingPageScaleAnimation( |
| 2552 | gfx::Vector2d(), false, target_scale, duration))); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2553 | begin_frame_args.frame_time = halfway_through_animation; |
| 2554 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2555 | host_impl_->Animate(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2556 | EXPECT_FALSE(did_request_next_frame_); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2557 | EXPECT_FALSE(did_request_redraw_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2558 | host_impl_->DidFinishImplFrame(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2559 | |
| 2560 | // Activate the sync tree. This should cause the animation to become enabled. |
| 2561 | // It should also clear the pointer on the sync tree. |
| 2562 | host_impl_->ActivateSyncTree(); |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 2563 | EXPECT_EQ(nullptr, |
| 2564 | host_impl_->sync_tree()->TakePendingPageScaleAnimation().get()); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2565 | EXPECT_FALSE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2566 | EXPECT_TRUE(did_request_next_frame_); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2567 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2568 | start_time += base::TimeDelta::FromSeconds(10); |
| 2569 | third_through_animation += base::TimeDelta::FromSeconds(10); |
| 2570 | halfway_through_animation += base::TimeDelta::FromSeconds(10); |
| 2571 | end_time += base::TimeDelta::FromSeconds(10); |
| 2572 | |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2573 | // From here on, make sure the animation runs as normal. |
| 2574 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2575 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2576 | begin_frame_args.frame_time = start_time; |
| 2577 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2578 | host_impl_->Animate(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2579 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2580 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2581 | host_impl_->DidFinishImplFrame(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2582 | |
| 2583 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2584 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2585 | begin_frame_args.frame_time = third_through_animation; |
| 2586 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2587 | host_impl_->Animate(); |
aelias | 74c3935 | 2014-10-14 03:48:14 | [diff] [blame] | 2588 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2589 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2590 | host_impl_->DidFinishImplFrame(); |
aelias | 74c3935 | 2014-10-14 03:48:14 | [diff] [blame] | 2591 | |
| 2592 | // Another activation shouldn't have any effect on the animation. |
| 2593 | host_impl_->ActivateSyncTree(); |
| 2594 | |
| 2595 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2596 | did_request_next_frame_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2597 | begin_frame_args.frame_time = halfway_through_animation; |
| 2598 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2599 | host_impl_->Animate(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2600 | EXPECT_TRUE(did_request_redraw_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2601 | EXPECT_TRUE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2602 | host_impl_->DidFinishImplFrame(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2603 | |
| 2604 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2605 | did_request_next_frame_ = false; |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2606 | did_request_commit_ = false; |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2607 | begin_frame_args.frame_time = end_time; |
| 2608 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2609 | host_impl_->Animate(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2610 | EXPECT_TRUE(did_request_commit_); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2611 | EXPECT_FALSE(did_request_next_frame_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2612 | host_impl_->DidFinishImplFrame(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2613 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2614 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2615 | host_impl_->ProcessScrollDeltas(); |
| 2616 | EXPECT_EQ(scroll_info->page_scale_delta, target_scale); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 2617 | EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
| 2618 | gfx::Vector2d(-50, -50))); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 2619 | } |
| 2620 | |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2621 | TEST_F(LayerTreeHostImplTest, PageScaleAnimationCompletedNotification) { |
| 2622 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 2623 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 2624 | DrawFrame(); |
| 2625 | |
| 2626 | LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 2627 | DCHECK(scroll_layer); |
| 2628 | |
| 2629 | base::TimeTicks start_time = |
| 2630 | base::TimeTicks() + base::TimeDelta::FromSeconds(1); |
| 2631 | base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
| 2632 | base::TimeTicks halfway_through_animation = start_time + duration / 2; |
| 2633 | base::TimeTicks end_time = start_time + duration; |
| 2634 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2635 | BeginFrameArgs begin_frame_args = |
| 2636 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 2637 | |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2638 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2639 | scroll_layer->layer_tree_impl() |
| 2640 | ->property_trees() |
| 2641 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 2642 | gfx::ScrollOffset(50, 50)); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2643 | |
| 2644 | did_complete_page_scale_animation_ = false; |
| 2645 | host_impl_->active_tree()->SetPendingPageScaleAnimation( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2646 | std::unique_ptr<PendingPageScaleAnimation>(new PendingPageScaleAnimation( |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2647 | gfx::Vector2d(), false, 2.f, duration))); |
| 2648 | host_impl_->ActivateSyncTree(); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2649 | begin_frame_args.frame_time = start_time; |
| 2650 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2651 | host_impl_->Animate(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2652 | EXPECT_FALSE(did_complete_page_scale_animation_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2653 | host_impl_->DidFinishImplFrame(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2654 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2655 | begin_frame_args.frame_time = halfway_through_animation; |
| 2656 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2657 | host_impl_->Animate(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2658 | EXPECT_FALSE(did_complete_page_scale_animation_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2659 | host_impl_->DidFinishImplFrame(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2660 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2661 | begin_frame_args.frame_time = end_time; |
| 2662 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2663 | host_impl_->Animate(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2664 | EXPECT_TRUE(did_complete_page_scale_animation_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 2665 | host_impl_->DidFinishImplFrame(); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 2666 | } |
| 2667 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 2668 | TEST_F(LayerTreeHostImplTest, MaxScrollOffsetAffectedByBoundsDelta) { |
| 2669 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 2670 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 2671 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2672 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 2673 | DrawFrame(); |
| 2674 | |
| 2675 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 2676 | LayerImpl* inner_container = inner_scroll->scroll_clip_layer(); |
| 2677 | DCHECK(inner_scroll); |
| 2678 | DCHECK(inner_container); |
| 2679 | EXPECT_EQ(gfx::ScrollOffset(50, 50), inner_scroll->MaxScrollOffset()); |
| 2680 | |
| 2681 | inner_container->SetBoundsDelta(gfx::Vector2dF(15.f, 15.f)); |
| 2682 | inner_scroll->SetBoundsDelta(gfx::Vector2dF(7.f, 7.f)); |
| 2683 | EXPECT_EQ(gfx::ScrollOffset(42, 42), inner_scroll->MaxScrollOffset()); |
| 2684 | |
| 2685 | inner_container->SetBoundsDelta(gfx::Vector2dF()); |
| 2686 | inner_scroll->SetBoundsDelta(gfx::Vector2dF()); |
| 2687 | inner_scroll->SetBounds(gfx::Size()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2688 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 2689 | DrawFrame(); |
| 2690 | |
| 2691 | inner_scroll->SetBoundsDelta(gfx::Vector2dF(60.f, 60.f)); |
| 2692 | EXPECT_EQ(gfx::ScrollOffset(10, 10), inner_scroll->MaxScrollOffset()); |
| 2693 | } |
| 2694 | |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2695 | class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { |
| 2696 | public: |
| 2697 | LayerTreeHostImplOverridePhysicalTime( |
| 2698 | const LayerTreeSettings& settings, |
| 2699 | LayerTreeHostImplClient* client, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 2700 | TaskRunnerProvider* task_runner_provider, |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 2701 | SharedBitmapManager* manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 2702 | TaskGraphRunner* task_graph_runner, |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2703 | RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 2704 | : LayerTreeHostImpl(settings, |
| 2705 | client, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 2706 | task_runner_provider, |
[email protected] | a7f3568 | 2013-10-22 23:05:57 | [diff] [blame] | 2707 | rendering_stats_instrumentation, |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 2708 | manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 2709 | nullptr, |
| 2710 | task_graph_runner, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 2711 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), |
[email protected] | dbe759a | 2013-12-02 19:23:02 | [diff] [blame] | 2712 | 0) {} |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2713 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 2714 | BeginFrameArgs CurrentBeginFrameArgs() const override { |
mithro | 06d1f3bf | 2014-12-02 02:19:15 | [diff] [blame] | 2715 | return CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, |
| 2716 | fake_current_physical_time_); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { |
| 2720 | fake_current_physical_time_ = fake_now; |
| 2721 | } |
| 2722 | |
| 2723 | private: |
| 2724 | base::TimeTicks fake_current_physical_time_; |
| 2725 | }; |
| 2726 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2727 | class LayerTreeHostImplTestScrollbarAnimation : public LayerTreeHostImplTest { |
| 2728 | protected: |
| 2729 | void SetupLayers(LayerTreeSettings settings) { |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 2730 | host_impl_->ReleaseOutputSurface(); |
| 2731 | host_impl_ = nullptr; |
| 2732 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2733 | gfx::Size content_size(100, 100); |
[email protected] | e6e7f29 | 2014-04-24 22:23:03 | [diff] [blame] | 2734 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2735 | LayerTreeHostImplOverridePhysicalTime* host_impl_override_time = |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 2736 | new LayerTreeHostImplOverridePhysicalTime( |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 2737 | settings, this, &task_runner_provider_, &shared_bitmap_manager_, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 2738 | &task_graph_runner_, &stats_instrumentation_); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2739 | host_impl_ = base::WrapUnique(host_impl_override_time); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2740 | output_surface_ = CreateOutputSurface(); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 2741 | host_impl_->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 2742 | host_impl_->InitializeRenderer(output_surface_.get()); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2743 | |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 2744 | SetupScrollAndContentsLayers(content_size); |
| 2745 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f); |
| 2746 | host_impl_->SetViewportSize( |
| 2747 | gfx::Size(content_size.width() / 2, content_size.height() / 2)); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2748 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2749 | std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 2750 | SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 400, |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2751 | VERTICAL, 10, 0, false, true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 2752 | scrollbar->test_properties()->opacity = 0.f; |
| 2753 | EXPECT_FLOAT_EQ(0.f, scrollbar->test_properties()->opacity); |
[email protected] | cdc0700 | 2013-09-06 22:33:46 | [diff] [blame] | 2754 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 2755 | LayerImpl* scroll = host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 2756 | LayerImpl* root = host_impl_->active_tree()->InnerViewportContainerLayer(); |
| 2757 | scrollbar->SetScrollLayerId(scroll->id()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2758 | root->test_properties()->AddChild(std::move(scrollbar)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2759 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2760 | host_impl_->active_tree()->DidBecomeActive(); |
| 2761 | DrawFrame(); |
| 2762 | } |
sunnyps | ae4316a | 2015-02-25 00:54:58 | [diff] [blame] | 2763 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2764 | void RunTest(LayerTreeSettings::ScrollbarAnimator animator) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 2765 | LayerTreeSettings settings = DefaultSettings(); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2766 | settings.scrollbar_animator = animator; |
| 2767 | settings.scrollbar_fade_delay_ms = 20; |
| 2768 | settings.scrollbar_fade_duration_ms = 20; |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2769 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2770 | // If no animator is set, scrollbar won't show and no animation is expected. |
| 2771 | bool expecting_animations = animator != LayerTreeSettings::NO_ANIMATOR; |
| 2772 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2773 | SetupLayers(settings); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2774 | |
abhishek.ka | 7215854d | 2015-05-26 06:13:17 | [diff] [blame] | 2775 | base::TimeTicks fake_now = base::TimeTicks::Now(); |
sataya.m | 68d7d9b4 | 2014-09-22 16:01:59 | [diff] [blame] | 2776 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2777 | if (expecting_animations) { |
| 2778 | // A task will be posted to fade the initial scrollbar. |
| 2779 | EXPECT_FALSE(did_request_next_frame_); |
| 2780 | EXPECT_FALSE(did_request_redraw_); |
| 2781 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 2782 | requested_animation_delay_ = base::TimeDelta(); |
| 2783 | animation_task_ = base::Closure(); |
| 2784 | } else { |
| 2785 | EXPECT_FALSE(did_request_next_frame_); |
| 2786 | EXPECT_FALSE(did_request_redraw_); |
| 2787 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2788 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2789 | } |
sunnyps | ae4316a | 2015-02-25 00:54:58 | [diff] [blame] | 2790 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2791 | // If no scroll happened during a scroll gesture, it should have no effect. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2792 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 2793 | InputHandler::WHEEL); |
| 2794 | host_impl_->ScrollEnd(EndState().get()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2795 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2796 | EXPECT_FALSE(did_request_redraw_); |
| 2797 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2798 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2799 | |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2800 | // Before the scrollbar animation exists, we should not get redraws. |
| 2801 | BeginFrameArgs begin_frame_args = |
| 2802 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, fake_now); |
| 2803 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2804 | host_impl_->Animate(); |
| 2805 | EXPECT_FALSE(did_request_next_frame_); |
| 2806 | did_request_next_frame_ = false; |
| 2807 | EXPECT_FALSE(did_request_redraw_); |
| 2808 | did_request_redraw_ = false; |
| 2809 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2810 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2811 | host_impl_->DidFinishImplFrame(); |
| 2812 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2813 | // After a scroll, a scrollbar animation should be scheduled about 20ms from |
| 2814 | // now. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2815 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 2816 | InputHandler::WHEEL); |
| 2817 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2dF(0, 5)).get()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2818 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2819 | EXPECT_TRUE(did_request_redraw_); |
| 2820 | did_request_redraw_ = false; |
| 2821 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2822 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2823 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2824 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 2825 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2826 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2827 | EXPECT_FALSE(did_request_redraw_); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2828 | if (expecting_animations) { |
| 2829 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), |
| 2830 | requested_animation_delay_); |
| 2831 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 2832 | } else { |
| 2833 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2834 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2835 | } |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2836 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2837 | if (expecting_animations) { |
| 2838 | // Before the scrollbar animation begins, we should not get redraws. |
| 2839 | begin_frame_args = |
| 2840 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, fake_now); |
| 2841 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2842 | host_impl_->Animate(); |
| 2843 | EXPECT_FALSE(did_request_next_frame_); |
| 2844 | did_request_next_frame_ = false; |
| 2845 | EXPECT_FALSE(did_request_redraw_); |
| 2846 | did_request_redraw_ = false; |
| 2847 | host_impl_->DidFinishImplFrame(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2848 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2849 | // Start the scrollbar animation. |
| 2850 | fake_now += requested_animation_delay_; |
| 2851 | requested_animation_delay_ = base::TimeDelta(); |
| 2852 | animation_task_.Run(); |
| 2853 | animation_task_ = base::Closure(); |
| 2854 | EXPECT_TRUE(did_request_next_frame_); |
| 2855 | did_request_next_frame_ = false; |
| 2856 | EXPECT_FALSE(did_request_redraw_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2857 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2858 | // After the scrollbar animation begins, we should start getting redraws. |
| 2859 | begin_frame_args = |
| 2860 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, fake_now); |
| 2861 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2862 | host_impl_->Animate(); |
| 2863 | EXPECT_TRUE(did_request_next_frame_); |
| 2864 | did_request_next_frame_ = false; |
| 2865 | EXPECT_TRUE(did_request_redraw_); |
| 2866 | did_request_redraw_ = false; |
| 2867 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2868 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2869 | host_impl_->DidFinishImplFrame(); |
| 2870 | } |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2871 | |
| 2872 | // Setting the scroll offset outside a scroll should also cause the |
| 2873 | // scrollbar to appear and to schedule a scrollbar animation. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 2874 | if (host_impl_->active_tree() |
| 2875 | ->property_trees() |
| 2876 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 2877 | host_impl_->InnerViewportScrollLayer()->id(), |
| 2878 | gfx::ScrollOffset(5, 5))) |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 2879 | host_impl_->active_tree()->DidUpdateScrollOffset( |
| 2880 | host_impl_->InnerViewportScrollLayer()->id(), |
| 2881 | host_impl_->InnerViewportScrollLayer()->transform_tree_index()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2882 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2883 | EXPECT_FALSE(did_request_redraw_); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2884 | if (expecting_animations) { |
| 2885 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), |
| 2886 | requested_animation_delay_); |
| 2887 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 2888 | requested_animation_delay_ = base::TimeDelta(); |
| 2889 | animation_task_ = base::Closure(); |
| 2890 | } else { |
| 2891 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2892 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2893 | } |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2894 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2895 | if (expecting_animations) { |
| 2896 | // Scrolling should have stopped the animation, so we should not be |
| 2897 | // getting redraws. |
| 2898 | begin_frame_args = |
| 2899 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, fake_now); |
| 2900 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 2901 | host_impl_->Animate(); |
| 2902 | EXPECT_FALSE(did_request_next_frame_); |
| 2903 | did_request_next_frame_ = false; |
| 2904 | EXPECT_FALSE(did_request_redraw_); |
| 2905 | did_request_redraw_ = false; |
| 2906 | host_impl_->DidFinishImplFrame(); |
| 2907 | } |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2908 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2909 | // Scrollbar animation is not triggered unnecessarily. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2910 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 2911 | InputHandler::WHEEL); |
| 2912 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2dF(5, 0)).get()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2913 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2914 | EXPECT_TRUE(did_request_redraw_); |
| 2915 | did_request_redraw_ = false; |
| 2916 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2917 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2918 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 2919 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 2920 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2921 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2922 | EXPECT_FALSE(did_request_redraw_); |
| 2923 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2924 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2925 | |
| 2926 | // Changing page scale triggers scrollbar animation. |
| 2927 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 2928 | host_impl_->active_tree()->SetPageScaleOnActiveTree(1.1f); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 2929 | EXPECT_FALSE(did_request_next_frame_); |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2930 | EXPECT_FALSE(did_request_redraw_); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2931 | if (expecting_animations) { |
| 2932 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), |
| 2933 | requested_animation_delay_); |
| 2934 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 2935 | requested_animation_delay_ = base::TimeDelta(); |
| 2936 | animation_task_ = base::Closure(); |
| 2937 | } else { |
| 2938 | EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
| 2939 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 2940 | } |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2941 | } |
| 2942 | }; |
| 2943 | |
| 2944 | TEST_F(LayerTreeHostImplTestScrollbarAnimation, LinearFade) { |
| 2945 | RunTest(LayerTreeSettings::LINEAR_FADE); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2946 | } |
| 2947 | |
sunnyps | 102dbf69 | 2015-03-07 02:17:46 | [diff] [blame] | 2948 | TEST_F(LayerTreeHostImplTestScrollbarAnimation, Thinning) { |
| 2949 | RunTest(LayerTreeSettings::THINNING); |
[email protected] | e6e7f29 | 2014-04-24 22:23:03 | [diff] [blame] | 2950 | } |
| 2951 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2952 | TEST_F(LayerTreeHostImplTestScrollbarAnimation, NoAnimator) { |
| 2953 | RunTest(LayerTreeSettings::NO_ANIMATOR); |
| 2954 | } |
| 2955 | |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2956 | class LayerTreeHostImplTestScrollbarOpacity : public LayerTreeHostImplTest { |
| 2957 | protected: |
| 2958 | void RunTest(LayerTreeSettings::ScrollbarAnimator animator) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 2959 | LayerTreeSettings settings = DefaultSettings(); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2960 | settings.scrollbar_animator = animator; |
| 2961 | settings.scrollbar_fade_delay_ms = 20; |
| 2962 | settings.scrollbar_fade_duration_ms = 20; |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2963 | gfx::Size content_size(100, 100); |
| 2964 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2965 | // If no animator is set, scrollbar won't show and no animation is expected. |
| 2966 | bool expecting_animations = animator != LayerTreeSettings::NO_ANIMATOR; |
| 2967 | |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2968 | CreateHostImpl(settings, CreateOutputSurface()); |
| 2969 | host_impl_->CreatePendingTree(); |
| 2970 | CreateScrollAndContentsLayers(host_impl_->pending_tree(), content_size); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2971 | std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2972 | SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400, |
| 2973 | VERTICAL, 10, 0, false, true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 2974 | scrollbar->test_properties()->opacity = 0.f; |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 2975 | LayerImpl* scroll = host_impl_->pending_tree()->OuterViewportScrollLayer(); |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 2976 | LayerImpl* container = |
| 2977 | host_impl_->pending_tree()->InnerViewportContainerLayer(); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 2978 | scrollbar->SetScrollLayerId(scroll->id()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 2979 | container->test_properties()->AddChild(std::move(scrollbar)); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2980 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 2981 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2982 | host_impl_->ActivateSyncTree(); |
| 2983 | |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 2984 | LayerImpl* active_scrollbar_layer = |
| 2985 | host_impl_->active_tree()->LayerById(400); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2986 | |
| 2987 | EffectNode* active_tree_node = |
| 2988 | host_impl_->active_tree()->property_trees()->effect_tree.Node( |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 2989 | active_scrollbar_layer->effect_tree_index()); |
| 2990 | EXPECT_FLOAT_EQ(active_scrollbar_layer->Opacity(), |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 2991 | active_tree_node->opacity); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 2992 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 2993 | if (expecting_animations) { |
| 2994 | host_impl_->ScrollbarAnimationControllerForId(scroll->id()) |
| 2995 | ->DidMouseMoveNear(0); |
| 2996 | } else { |
| 2997 | EXPECT_EQ(nullptr, |
| 2998 | host_impl_->ScrollbarAnimationControllerForId(scroll->id())); |
| 2999 | } |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3000 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 3001 | InputHandler::WHEEL); |
| 3002 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2dF(0, 5)).get()); |
| 3003 | host_impl_->ScrollEnd(EndState().get()); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 3004 | host_impl_->CreatePendingTree(); |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 3005 | // To test the case where the effect tree index of scrollbar layer changes, |
| 3006 | // we force the container layer to create a render surface. |
| 3007 | container = host_impl_->pending_tree()->InnerViewportContainerLayer(); |
| 3008 | container->test_properties()->force_render_surface = true; |
| 3009 | container->SetBounds(gfx::Size(10, 10)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3010 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 3011 | |
| 3012 | LayerImpl* pending_scrollbar_layer = |
| 3013 | host_impl_->pending_tree()->LayerById(400); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 3014 | pending_scrollbar_layer->SetNeedsPushProperties(); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 3015 | EffectNode* pending_tree_node = |
| 3016 | host_impl_->pending_tree()->property_trees()->effect_tree.Node( |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 3017 | pending_scrollbar_layer->effect_tree_index()); |
jaydasika | ae9b7a0 | 2016-05-19 16:12:52 | [diff] [blame] | 3018 | host_impl_->pending_tree() |
| 3019 | ->property_trees() |
| 3020 | ->always_use_active_tree_opacity_effect_ids.push_back(400); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 3021 | if (expecting_animations) { |
| 3022 | EXPECT_FLOAT_EQ(1.f, active_tree_node->opacity); |
| 3023 | EXPECT_FLOAT_EQ(1.f, active_scrollbar_layer->Opacity()); |
| 3024 | } else { |
| 3025 | EXPECT_FLOAT_EQ(0.f, active_tree_node->opacity); |
| 3026 | EXPECT_FLOAT_EQ(0.f, active_scrollbar_layer->Opacity()); |
| 3027 | } |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 3028 | EXPECT_FLOAT_EQ(0.f, pending_tree_node->opacity); |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 3029 | host_impl_->ActivateSyncTree(); |
| 3030 | active_tree_node = |
| 3031 | host_impl_->active_tree()->property_trees()->effect_tree.Node( |
jaydasika | 52c0018 | 2016-06-02 08:57:17 | [diff] [blame] | 3032 | active_scrollbar_layer->effect_tree_index()); |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 3033 | if (expecting_animations) { |
| 3034 | EXPECT_FLOAT_EQ(1.f, active_tree_node->opacity); |
| 3035 | EXPECT_FLOAT_EQ(1.f, active_scrollbar_layer->Opacity()); |
| 3036 | } else { |
| 3037 | EXPECT_FLOAT_EQ(0.f, active_tree_node->opacity); |
| 3038 | EXPECT_FLOAT_EQ(0.f, active_scrollbar_layer->Opacity()); |
| 3039 | } |
jaydasika | 4f290d8 | 2015-09-18 20:25:21 | [diff] [blame] | 3040 | } |
| 3041 | }; |
| 3042 | |
| 3043 | TEST_F(LayerTreeHostImplTestScrollbarOpacity, LinearFade) { |
| 3044 | RunTest(LayerTreeSettings::LINEAR_FADE); |
| 3045 | } |
| 3046 | |
| 3047 | TEST_F(LayerTreeHostImplTestScrollbarOpacity, Thinning) { |
| 3048 | RunTest(LayerTreeSettings::THINNING); |
| 3049 | } |
| 3050 | |
eseckler | 025a020 | 2016-08-05 09:16:12 | [diff] [blame] | 3051 | TEST_F(LayerTreeHostImplTestScrollbarOpacity, NoAnimator) { |
| 3052 | RunTest(LayerTreeSettings::NO_ANIMATOR); |
| 3053 | } |
| 3054 | |
aelias | 14d87e0c | 2015-11-04 00:12:50 | [diff] [blame] | 3055 | TEST_F(LayerTreeHostImplTest, ScrollbarInnerLargerThanOuter) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 3056 | LayerTreeSettings settings = DefaultSettings(); |
aelias | 14d87e0c | 2015-11-04 00:12:50 | [diff] [blame] | 3057 | CreateHostImpl(settings, CreateOutputSurface()); |
| 3058 | |
| 3059 | gfx::Size inner_viewport_size(315, 200); |
| 3060 | gfx::Size outer_viewport_size(300, 200); |
| 3061 | gfx::Size content_size(1000, 1000); |
| 3062 | |
| 3063 | const int horiz_id = 11; |
| 3064 | const int child_clip_id = 14; |
| 3065 | const int child_scroll_id = 15; |
| 3066 | |
| 3067 | CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size); |
| 3068 | host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( |
| 3069 | inner_viewport_size); |
| 3070 | host_impl_->active_tree()->OuterViewportContainerLayer()->SetBounds( |
| 3071 | outer_viewport_size); |
| 3072 | LayerImpl* root_scroll = |
| 3073 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3074 | std::unique_ptr<SolidColorScrollbarLayerImpl> horiz_scrollbar = |
aelias | 14d87e0c | 2015-11-04 00:12:50 | [diff] [blame] | 3075 | SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), horiz_id, |
| 3076 | HORIZONTAL, 5, 5, true, true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3077 | std::unique_ptr<LayerImpl> child = |
aelias | 14d87e0c | 2015-11-04 00:12:50 | [diff] [blame] | 3078 | LayerImpl::Create(host_impl_->active_tree(), child_scroll_id); |
| 3079 | child->SetBounds(content_size); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3080 | std::unique_ptr<LayerImpl> child_clip = |
aelias | 14d87e0c | 2015-11-04 00:12:50 | [diff] [blame] | 3081 | LayerImpl::Create(host_impl_->active_tree(), child_clip_id); |
| 3082 | child->SetBounds(inner_viewport_size); |
| 3083 | |
| 3084 | horiz_scrollbar->SetScrollLayerId(root_scroll->id()); |
| 3085 | |
| 3086 | EXPECT_EQ(300, horiz_scrollbar->clip_layer_length()); |
| 3087 | } |
| 3088 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3089 | TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 3090 | LayerTreeSettings settings = DefaultSettings(); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3091 | settings.scrollbar_animator = LayerTreeSettings::LINEAR_FADE; |
| 3092 | settings.scrollbar_fade_delay_ms = 20; |
| 3093 | settings.scrollbar_fade_duration_ms = 20; |
| 3094 | CreateHostImpl(settings, CreateOutputSurface()); |
| 3095 | |
| 3096 | gfx::Size viewport_size(300, 200); |
| 3097 | gfx::Size content_size(1000, 1000); |
| 3098 | |
| 3099 | const int vert_1_id = 10; |
| 3100 | const int horiz_1_id = 11; |
| 3101 | const int vert_2_id = 12; |
| 3102 | const int horiz_2_id = 13; |
| 3103 | const int child_clip_id = 14; |
| 3104 | const int child_scroll_id = 15; |
| 3105 | |
| 3106 | CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size); |
| 3107 | host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( |
| 3108 | viewport_size); |
| 3109 | LayerImpl* root_scroll = |
| 3110 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3111 | std::unique_ptr<SolidColorScrollbarLayerImpl> vert_1_scrollbar = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3112 | SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), vert_1_id, |
| 3113 | VERTICAL, 5, 5, true, true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3114 | std::unique_ptr<SolidColorScrollbarLayerImpl> horiz_1_scrollbar = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3115 | SolidColorScrollbarLayerImpl::Create( |
| 3116 | host_impl_->active_tree(), horiz_1_id, HORIZONTAL, 5, 5, true, true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3117 | std::unique_ptr<SolidColorScrollbarLayerImpl> vert_2_scrollbar = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3118 | SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), vert_2_id, |
| 3119 | VERTICAL, 5, 5, true, true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3120 | std::unique_ptr<SolidColorScrollbarLayerImpl> horiz_2_scrollbar = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3121 | SolidColorScrollbarLayerImpl::Create( |
| 3122 | host_impl_->active_tree(), horiz_2_id, HORIZONTAL, 5, 5, true, true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3123 | std::unique_ptr<LayerImpl> child = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3124 | LayerImpl::Create(host_impl_->active_tree(), child_scroll_id); |
| 3125 | child->SetBounds(content_size); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3126 | std::unique_ptr<LayerImpl> child_clip = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3127 | LayerImpl::Create(host_impl_->active_tree(), child_clip_id); |
| 3128 | child->SetBounds(viewport_size); |
| 3129 | LayerImpl* child_ptr = child.get(); |
| 3130 | LayerImpl* child_clip_ptr = child_clip.get(); |
| 3131 | |
| 3132 | // Check scrollbar registration on the viewport layers. |
| 3133 | EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); |
| 3134 | EXPECT_EQ(nullptr, |
| 3135 | host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3136 | vert_1_scrollbar->SetScrollLayerId(root_scroll->id()); |
| 3137 | EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); |
| 3138 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3139 | horiz_1_scrollbar->SetScrollLayerId(root_scroll->id()); |
| 3140 | EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); |
| 3141 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3142 | |
| 3143 | // Changing one of the viewport layers should result in a scrollbar animation |
| 3144 | // update. |
| 3145 | animation_task_ = base::Closure(); |
| 3146 | host_impl_->active_tree()->InnerViewportContainerLayer()->SetBoundsDelta( |
| 3147 | gfx::Vector2dF(10, 10)); |
| 3148 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 3149 | animation_task_ = base::Closure(); |
| 3150 | host_impl_->active_tree()->OuterViewportScrollLayer()->SetCurrentScrollOffset( |
| 3151 | gfx::ScrollOffset(10, 10)); |
| 3152 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 3153 | animation_task_ = base::Closure(); |
| 3154 | host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( |
| 3155 | gfx::ScrollOffset(10, 10)); |
| 3156 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 3157 | animation_task_ = base::Closure(); |
| 3158 | |
| 3159 | // Check scrollbar registration on a sublayer. |
| 3160 | child->SetScrollClipLayer(child_clip->id()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3161 | child_clip->test_properties()->AddChild(std::move(child)); |
| 3162 | root_scroll->test_properties()->AddChild(std::move(child_clip)); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3163 | EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3164 | EXPECT_EQ(nullptr, |
| 3165 | host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); |
| 3166 | vert_2_scrollbar->SetScrollLayerId(child_scroll_id); |
| 3167 | EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3168 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); |
| 3169 | horiz_2_scrollbar->SetScrollLayerId(child_scroll_id); |
| 3170 | EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3171 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); |
| 3172 | |
| 3173 | // Changing one of the child layers should result in a scrollbar animation |
| 3174 | // update. |
| 3175 | animation_task_ = base::Closure(); |
| 3176 | child_clip_ptr->SetBounds(gfx::Size(200, 200)); |
| 3177 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 3178 | animation_task_ = base::Closure(); |
| 3179 | child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(10, 10)); |
| 3180 | EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
| 3181 | animation_task_ = base::Closure(); |
| 3182 | |
| 3183 | // Check scrollbar unregistration. |
| 3184 | vert_1_scrollbar.reset(); |
| 3185 | EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); |
| 3186 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3187 | horiz_1_scrollbar.reset(); |
| 3188 | EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); |
| 3189 | EXPECT_EQ(nullptr, |
| 3190 | host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3191 | |
| 3192 | EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3193 | vert_2_scrollbar.reset(); |
| 3194 | EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3195 | EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); |
| 3196 | horiz_2_scrollbar.reset(); |
| 3197 | EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); |
| 3198 | EXPECT_EQ(nullptr, |
| 3199 | host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
| 3200 | |
| 3201 | // Changing scroll offset should no longer trigger any animation. |
| 3202 | host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( |
| 3203 | gfx::ScrollOffset(20, 20)); |
| 3204 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 3205 | child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(20, 20)); |
| 3206 | EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
| 3207 | } |
| 3208 | |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3209 | void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( |
| 3210 | float device_scale_factor) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 3211 | LayerTreeSettings settings = DefaultSettings(); |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 3212 | settings.scrollbar_fade_delay_ms = 500; |
| 3213 | settings.scrollbar_fade_duration_ms = 300; |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 3214 | settings.scrollbar_animator = LayerTreeSettings::THINNING; |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3215 | |
| 3216 | gfx::Size viewport_size(300, 200); |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 3217 | gfx::Size device_viewport_size = |
| 3218 | gfx::ScaleToFlooredSize(viewport_size, device_scale_factor); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3219 | gfx::Size content_size(1000, 1000); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3220 | gfx::Size scrollbar_size(gfx::Size(15, viewport_size.height())); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3221 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 3222 | CreateHostImpl(settings, CreateOutputSurface()); |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 3223 | host_impl_->active_tree()->SetDeviceScaleFactor(device_scale_factor); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3224 | host_impl_->SetViewportSize(device_viewport_size); |
| 3225 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3226 | CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size); |
| 3227 | host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( |
| 3228 | viewport_size); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 3229 | LayerImpl* root_scroll = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3230 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 3231 | // The scrollbar is on the left side. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3232 | std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3233 | SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 6, |
| 3234 | VERTICAL, 5, 5, true, true); |
| 3235 | scrollbar->SetScrollLayerId(root_scroll->id()); |
| 3236 | scrollbar->SetDrawsContent(true); |
| 3237 | scrollbar->SetBounds(scrollbar_size); |
| 3238 | scrollbar->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3239 | host_impl_->active_tree() |
| 3240 | ->InnerViewportContainerLayer() |
| 3241 | ->test_properties() |
| 3242 | ->AddChild(std::move(scrollbar)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3243 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3244 | host_impl_->active_tree()->DidBecomeActive(); |
| 3245 | |
| 3246 | DrawFrame(); |
| 3247 | host_impl_->active_tree()->UpdateDrawProperties(false); |
| 3248 | |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3249 | ScrollbarAnimationControllerThinning* scrollbar_animation_controller = |
| 3250 | static_cast<ScrollbarAnimationControllerThinning*>( |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3251 | host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3252 | scrollbar_animation_controller->set_mouse_move_distance_for_test(100.f); |
| 3253 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3254 | host_impl_->MouseMoveAt(gfx::Point(200, 1)); |
[email protected] | 534236b | 2013-10-25 21:19:20 | [diff] [blame] | 3255 | EXPECT_FALSE(scrollbar_animation_controller->mouse_is_near_scrollbar()); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3256 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3257 | host_impl_->MouseMoveAt(gfx::Point(100, 50)); |
[email protected] | 534236b | 2013-10-25 21:19:20 | [diff] [blame] | 3258 | EXPECT_TRUE(scrollbar_animation_controller->mouse_is_near_scrollbar()); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3259 | |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3260 | host_impl_->MouseMoveAt(gfx::Point(116, 100)); |
[email protected] | 534236b | 2013-10-25 21:19:20 | [diff] [blame] | 3261 | EXPECT_FALSE(scrollbar_animation_controller->mouse_is_near_scrollbar()); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3262 | |
| 3263 | scrollbar_animation_controller->set_mouse_move_distance_for_test(102.f); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3264 | host_impl_->MouseMoveAt(gfx::Point(116, 100)); |
[email protected] | 534236b | 2013-10-25 21:19:20 | [diff] [blame] | 3265 | EXPECT_TRUE(scrollbar_animation_controller->mouse_is_near_scrollbar()); |
[email protected] | f620b0e7 | 2013-10-01 21:38:24 | [diff] [blame] | 3266 | |
| 3267 | did_request_redraw_ = false; |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3268 | EXPECT_EQ(Layer::INVALID_ID, |
| 3269 | host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); |
| 3270 | host_impl_->MouseMoveAt(gfx::Point(10, 100)); |
| 3271 | EXPECT_EQ(117, host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); |
| 3272 | host_impl_->MouseMoveAt(gfx::Point(10, 120)); |
| 3273 | EXPECT_EQ(117, host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); |
[email protected] | f620b0e7 | 2013-10-01 21:38:24 | [diff] [blame] | 3274 | host_impl_->MouseMoveAt(gfx::Point(150, 120)); |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 3275 | EXPECT_EQ(Layer::INVALID_ID, |
| 3276 | host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 3277 | } |
| 3278 | |
| 3279 | TEST_F(LayerTreeHostImplTest, MouseMoveAtWithDeviceScaleOf1) { |
| 3280 | SetupMouseMoveAtWithDeviceScale(1.f); |
| 3281 | } |
| 3282 | |
| 3283 | TEST_F(LayerTreeHostImplTest, MouseMoveAtWithDeviceScaleOf2) { |
| 3284 | SetupMouseMoveAtWithDeviceScale(2.f); |
| 3285 | } |
| 3286 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3287 | TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) { |
| 3288 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 3289 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 3290 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 3291 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3292 | { |
| 3293 | CompositorFrameMetadata metadata = |
| 3294 | host_impl_->MakeCompositorFrameMetadata(); |
| 3295 | EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset); |
| 3296 | EXPECT_EQ(1.f, metadata.page_scale_factor); |
[email protected] | f3f611f | 2014-07-09 04:05:32 | [diff] [blame] | 3297 | EXPECT_EQ(gfx::SizeF(50.f, 50.f), metadata.scrollable_viewport_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3298 | EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); |
| 3299 | EXPECT_EQ(0.5f, metadata.min_page_scale_factor); |
| 3300 | EXPECT_EQ(4.f, metadata.max_page_scale_factor); |
jdduke | 2afdbf72 | 2015-02-12 06:28:20 | [diff] [blame] | 3301 | EXPECT_FALSE(metadata.root_overflow_x_hidden); |
| 3302 | EXPECT_FALSE(metadata.root_overflow_y_hidden); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3303 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3304 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3305 | // Scrolling should update metadata immediately. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 3306 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3307 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 3308 | InputHandler::WHEEL) |
| 3309 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3310 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3311 | { |
| 3312 | CompositorFrameMetadata metadata = |
| 3313 | host_impl_->MakeCompositorFrameMetadata(); |
| 3314 | EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); |
| 3315 | } |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3316 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3317 | { |
| 3318 | CompositorFrameMetadata metadata = |
| 3319 | host_impl_->MakeCompositorFrameMetadata(); |
| 3320 | EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); |
| 3321 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3322 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 3323 | // Root "overflow: hidden" properties should be reflected on the outer |
| 3324 | // viewport scroll layer. |
jdduke | 2afdbf72 | 2015-02-12 06:28:20 | [diff] [blame] | 3325 | { |
| 3326 | host_impl_->active_tree() |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 3327 | ->OuterViewportScrollLayer() |
jdduke | 2afdbf72 | 2015-02-12 06:28:20 | [diff] [blame] | 3328 | ->set_user_scrollable_horizontal(false); |
| 3329 | CompositorFrameMetadata metadata = |
| 3330 | host_impl_->MakeCompositorFrameMetadata(); |
| 3331 | EXPECT_TRUE(metadata.root_overflow_x_hidden); |
| 3332 | EXPECT_FALSE(metadata.root_overflow_y_hidden); |
| 3333 | |
| 3334 | host_impl_->active_tree() |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 3335 | ->OuterViewportScrollLayer() |
jdduke | 2afdbf72 | 2015-02-12 06:28:20 | [diff] [blame] | 3336 | ->set_user_scrollable_vertical(false); |
| 3337 | metadata = host_impl_->MakeCompositorFrameMetadata(); |
| 3338 | EXPECT_TRUE(metadata.root_overflow_x_hidden); |
| 3339 | EXPECT_TRUE(metadata.root_overflow_y_hidden); |
| 3340 | } |
| 3341 | |
hugo.holgersson | e5e7aa9 | 2015-08-17 14:07:19 | [diff] [blame] | 3342 | // Re-enable scrollability and verify that overflows are no longer hidden. |
| 3343 | { |
| 3344 | host_impl_->active_tree() |
| 3345 | ->OuterViewportScrollLayer() |
| 3346 | ->set_user_scrollable_horizontal(true); |
| 3347 | host_impl_->active_tree() |
| 3348 | ->OuterViewportScrollLayer() |
| 3349 | ->set_user_scrollable_vertical(true); |
| 3350 | CompositorFrameMetadata metadata = |
| 3351 | host_impl_->MakeCompositorFrameMetadata(); |
| 3352 | EXPECT_FALSE(metadata.root_overflow_x_hidden); |
| 3353 | EXPECT_FALSE(metadata.root_overflow_y_hidden); |
| 3354 | } |
| 3355 | |
| 3356 | // Root "overflow: hidden" properties should also be reflected on the |
| 3357 | // inner viewport scroll layer. |
| 3358 | { |
| 3359 | host_impl_->active_tree() |
| 3360 | ->InnerViewportScrollLayer() |
| 3361 | ->set_user_scrollable_horizontal(false); |
| 3362 | CompositorFrameMetadata metadata = |
| 3363 | host_impl_->MakeCompositorFrameMetadata(); |
| 3364 | EXPECT_TRUE(metadata.root_overflow_x_hidden); |
| 3365 | EXPECT_FALSE(metadata.root_overflow_y_hidden); |
| 3366 | |
| 3367 | host_impl_->active_tree() |
| 3368 | ->InnerViewportScrollLayer() |
| 3369 | ->set_user_scrollable_vertical(false); |
| 3370 | metadata = host_impl_->MakeCompositorFrameMetadata(); |
| 3371 | EXPECT_TRUE(metadata.root_overflow_x_hidden); |
| 3372 | EXPECT_TRUE(metadata.root_overflow_y_hidden); |
| 3373 | } |
| 3374 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3375 | // Page scale should update metadata correctly (shrinking only the viewport). |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3376 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 3377 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3378 | host_impl_->PinchGestureBegin(); |
| 3379 | host_impl_->PinchGestureUpdate(2.f, gfx::Point()); |
| 3380 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 3381 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3382 | { |
| 3383 | CompositorFrameMetadata metadata = |
| 3384 | host_impl_->MakeCompositorFrameMetadata(); |
| 3385 | EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); |
| 3386 | EXPECT_EQ(2.f, metadata.page_scale_factor); |
[email protected] | f3f611f | 2014-07-09 04:05:32 | [diff] [blame] | 3387 | EXPECT_EQ(gfx::SizeF(25.f, 25.f), metadata.scrollable_viewport_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3388 | EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); |
| 3389 | EXPECT_EQ(0.5f, metadata.min_page_scale_factor); |
| 3390 | EXPECT_EQ(4.f, metadata.max_page_scale_factor); |
| 3391 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3392 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3393 | // Likewise if set from the main thread. |
| 3394 | host_impl_->ProcessScrollDeltas(); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 3395 | host_impl_->active_tree()->PushPageScaleFromMainThread(4.f, 0.5f, 4.f); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 3396 | host_impl_->active_tree()->SetPageScaleOnActiveTree(4.f); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3397 | { |
| 3398 | CompositorFrameMetadata metadata = |
| 3399 | host_impl_->MakeCompositorFrameMetadata(); |
| 3400 | EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); |
| 3401 | EXPECT_EQ(4.f, metadata.page_scale_factor); |
[email protected] | f3f611f | 2014-07-09 04:05:32 | [diff] [blame] | 3402 | EXPECT_EQ(gfx::SizeF(12.5f, 12.5f), metadata.scrollable_viewport_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3403 | EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); |
| 3404 | EXPECT_EQ(0.5f, metadata.min_page_scale_factor); |
| 3405 | EXPECT_EQ(4.f, metadata.max_page_scale_factor); |
| 3406 | } |
[email protected] | f2b5a5be | 2013-01-08 00:34:36 | [diff] [blame] | 3407 | } |
| 3408 | |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3409 | class DidDrawCheckLayer : public LayerImpl { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3410 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3411 | static std::unique_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { |
| 3412 | return base::WrapUnique(new DidDrawCheckLayer(tree_impl, id)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3413 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3414 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3415 | bool WillDraw(DrawMode draw_mode, ResourceProvider* provider) override { |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3416 | will_draw_called_ = true; |
| 3417 | if (will_draw_returns_false_) |
| 3418 | return false; |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3419 | return LayerImpl::WillDraw(draw_mode, provider); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3420 | } |
| 3421 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3422 | void AppendQuads(RenderPass* render_pass, |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3423 | AppendQuadsData* append_quads_data) override { |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3424 | append_quads_called_ = true; |
danakj | a8c66a5 | 2015-02-14 01:53:22 | [diff] [blame] | 3425 | LayerImpl::AppendQuads(render_pass, append_quads_data); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3426 | } |
| 3427 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3428 | void DidDraw(ResourceProvider* provider) override { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3429 | did_draw_called_ = true; |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3430 | LayerImpl::DidDraw(provider); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3431 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3432 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3433 | bool will_draw_called() const { return will_draw_called_; } |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3434 | bool append_quads_called() const { return append_quads_called_; } |
| 3435 | bool did_draw_called() const { return did_draw_called_; } |
| 3436 | |
| 3437 | void set_will_draw_returns_false() { will_draw_returns_false_ = true; } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3438 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3439 | void ClearDidDrawCheck() { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3440 | will_draw_called_ = false; |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3441 | append_quads_called_ = false; |
| 3442 | did_draw_called_ = false; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3443 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3444 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3445 | static void IgnoreResult(std::unique_ptr<CopyOutputResult> result) {} |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3446 | |
| 3447 | void AddCopyRequest() { |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 3448 | test_properties()->copy_requests.push_back( |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3449 | CopyOutputRequest::CreateRequest(base::Bind(&IgnoreResult))); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3450 | } |
| 3451 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3452 | protected: |
| 3453 | DidDrawCheckLayer(LayerTreeImpl* tree_impl, int id) |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3454 | : LayerImpl(tree_impl, id), |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3455 | will_draw_returns_false_(false), |
| 3456 | will_draw_called_(false), |
| 3457 | append_quads_called_(false), |
| 3458 | did_draw_called_(false) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3459 | SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3460 | SetDrawsContent(true); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3461 | draw_properties().visible_layer_rect = gfx::Rect(0, 0, 10, 10); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3462 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3463 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3464 | private: |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3465 | bool will_draw_returns_false_; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3466 | bool will_draw_called_; |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3467 | bool append_quads_called_; |
| 3468 | bool did_draw_called_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3469 | }; |
| 3470 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3471 | TEST_F(LayerTreeHostImplTest, WillDrawReturningFalseDoesNotCall) { |
| 3472 | // The root layer is always drawn, so run this test on a child layer that |
| 3473 | // will be masked out by the root layer's bounds. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3474 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3475 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3476 | DidDrawCheckLayer* root = |
| 3477 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3478 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3479 | root->test_properties()->AddChild( |
| 3480 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 2)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3481 | root->test_properties()->force_render_surface = true; |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3482 | DidDrawCheckLayer* layer = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3483 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children[0]); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3484 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3485 | |
| 3486 | { |
| 3487 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3488 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3489 | host_impl_->DrawLayers(&frame); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3490 | host_impl_->DidDrawAllLayers(frame); |
| 3491 | |
| 3492 | EXPECT_TRUE(layer->will_draw_called()); |
| 3493 | EXPECT_TRUE(layer->append_quads_called()); |
| 3494 | EXPECT_TRUE(layer->did_draw_called()); |
| 3495 | } |
| 3496 | |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 3497 | host_impl_->SetViewportDamage(gfx::Rect(10, 10)); |
| 3498 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3499 | { |
| 3500 | LayerTreeHostImpl::FrameData frame; |
| 3501 | |
| 3502 | layer->set_will_draw_returns_false(); |
| 3503 | layer->ClearDidDrawCheck(); |
| 3504 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3505 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3506 | host_impl_->DrawLayers(&frame); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 3507 | host_impl_->DidDrawAllLayers(frame); |
| 3508 | |
| 3509 | EXPECT_TRUE(layer->will_draw_called()); |
| 3510 | EXPECT_FALSE(layer->append_quads_called()); |
| 3511 | EXPECT_FALSE(layer->did_draw_called()); |
| 3512 | } |
| 3513 | } |
| 3514 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3515 | TEST_F(LayerTreeHostImplTest, DidDrawNotCalledOnHiddenLayer) { |
| 3516 | // The root layer is always drawn, so run this test on a child layer that |
| 3517 | // will be masked out by the root layer's bounds. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3518 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3519 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3520 | DidDrawCheckLayer* root = |
| 3521 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3522 | root->SetMasksToBounds(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3523 | root->test_properties()->force_render_surface = true; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3524 | root->test_properties()->AddChild( |
| 3525 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 2)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3526 | DidDrawCheckLayer* layer = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3527 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children[0]); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3528 | // Ensure visible_layer_rect for layer is empty. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3529 | layer->SetPosition(gfx::PointF(100.f, 100.f)); |
| 3530 | layer->SetBounds(gfx::Size(10, 10)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3531 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3532 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3533 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3534 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3535 | EXPECT_FALSE(layer->will_draw_called()); |
| 3536 | EXPECT_FALSE(layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3537 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3538 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3539 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3540 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3541 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3542 | EXPECT_FALSE(layer->will_draw_called()); |
| 3543 | EXPECT_FALSE(layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3544 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3545 | EXPECT_TRUE(layer->visible_layer_rect().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3546 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3547 | // Ensure visible_layer_rect for layer is not empty |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3548 | layer->SetPosition(gfx::PointF()); |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 3549 | layer->NoteLayerPropertyChanged(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3550 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3551 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3552 | EXPECT_FALSE(layer->will_draw_called()); |
| 3553 | EXPECT_FALSE(layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3554 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3555 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3556 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3557 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3558 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3559 | EXPECT_TRUE(layer->will_draw_called()); |
| 3560 | EXPECT_TRUE(layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3561 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3562 | EXPECT_FALSE(layer->visible_layer_rect().IsEmpty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3563 | } |
| 3564 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3565 | TEST_F(LayerTreeHostImplTest, WillDrawNotCalledOnOccludedLayer) { |
| 3566 | gfx::Size big_size(1000, 1000); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 3567 | host_impl_->SetViewportSize(big_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3568 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3569 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3570 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3571 | DidDrawCheckLayer* root = |
| 3572 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3573 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3574 | root->test_properties()->AddChild( |
| 3575 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 2)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3576 | DidDrawCheckLayer* occluded_layer = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3577 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children[0]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3578 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3579 | root->test_properties()->AddChild( |
| 3580 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 3)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3581 | root->test_properties()->force_render_surface = true; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3582 | DidDrawCheckLayer* top_layer = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3583 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children[1]); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3584 | // This layer covers the occluded_layer above. Make this layer large so it can |
| 3585 | // occlude. |
| 3586 | top_layer->SetBounds(big_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3587 | top_layer->SetContentsOpaque(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3588 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3589 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3590 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3591 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3592 | EXPECT_FALSE(occluded_layer->will_draw_called()); |
| 3593 | EXPECT_FALSE(occluded_layer->did_draw_called()); |
| 3594 | EXPECT_FALSE(top_layer->will_draw_called()); |
| 3595 | EXPECT_FALSE(top_layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3596 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3597 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3598 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3599 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3600 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3601 | EXPECT_FALSE(occluded_layer->will_draw_called()); |
| 3602 | EXPECT_FALSE(occluded_layer->did_draw_called()); |
| 3603 | EXPECT_TRUE(top_layer->will_draw_called()); |
| 3604 | EXPECT_TRUE(top_layer->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3605 | } |
| 3606 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3607 | TEST_F(LayerTreeHostImplTest, DidDrawCalledOnAllLayers) { |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3608 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3609 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3610 | DidDrawCheckLayer* root = |
| 3611 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3612 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3613 | root->test_properties()->AddChild( |
| 3614 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 2)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3615 | root->test_properties()->force_render_surface = true; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3616 | DidDrawCheckLayer* layer1 = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3617 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children[0]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3618 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3619 | layer1->test_properties()->AddChild( |
| 3620 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 3)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3621 | DidDrawCheckLayer* layer2 = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 3622 | static_cast<DidDrawCheckLayer*>(layer1->test_properties()->children[0]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3623 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3624 | layer1->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 3625 | layer1->test_properties()->should_flatten_transform = true; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3626 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3627 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3628 | EXPECT_FALSE(root->did_draw_called()); |
| 3629 | EXPECT_FALSE(layer1->did_draw_called()); |
| 3630 | EXPECT_FALSE(layer2->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3631 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3632 | LayerTreeHostImpl::FrameData frame; |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 3633 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren( |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3634 | *host_impl_->active_tree()->begin()); |
| 3635 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3636 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3637 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3638 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3639 | EXPECT_TRUE(root->did_draw_called()); |
| 3640 | EXPECT_TRUE(layer1->did_draw_called()); |
| 3641 | EXPECT_TRUE(layer2->did_draw_called()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3642 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3643 | EXPECT_NE(root->render_surface(), layer1->render_surface()); |
thestig | d5fcf98 | 2015-05-11 18:41:38 | [diff] [blame] | 3644 | EXPECT_TRUE(layer1->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | class MissingTextureAnimatingLayer : public DidDrawCheckLayer { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3648 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3649 | static std::unique_ptr<LayerImpl> Create( |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 3650 | LayerTreeImpl* tree_impl, |
| 3651 | int id, |
| 3652 | bool tile_missing, |
| 3653 | bool had_incomplete_tile, |
| 3654 | bool animating, |
| 3655 | ResourceProvider* resource_provider, |
| 3656 | scoped_refptr<AnimationTimeline> timeline) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3657 | return base::WrapUnique(new MissingTextureAnimatingLayer( |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 3658 | tree_impl, id, tile_missing, had_incomplete_tile, animating, |
| 3659 | resource_provider, timeline)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3660 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3661 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3662 | void AppendQuads(RenderPass* render_pass, |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 3663 | AppendQuadsData* append_quads_data) override { |
danakj | a8c66a5 | 2015-02-14 01:53:22 | [diff] [blame] | 3664 | LayerImpl::AppendQuads(render_pass, append_quads_data); |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3665 | if (had_incomplete_tile_) |
[email protected] | 76ca89b | 2014-07-14 20:32:05 | [diff] [blame] | 3666 | append_quads_data->num_incomplete_tiles++; |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3667 | if (tile_missing_) |
| 3668 | append_quads_data->num_missing_tiles++; |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3669 | } |
| 3670 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3671 | private: |
| 3672 | MissingTextureAnimatingLayer(LayerTreeImpl* tree_impl, |
| 3673 | int id, |
| 3674 | bool tile_missing, |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3675 | bool had_incomplete_tile, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3676 | bool animating, |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 3677 | ResourceProvider* resource_provider, |
| 3678 | scoped_refptr<AnimationTimeline> timeline) |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3679 | : DidDrawCheckLayer(tree_impl, id), |
| 3680 | tile_missing_(tile_missing), |
| 3681 | had_incomplete_tile_(had_incomplete_tile) { |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 3682 | if (animating) { |
| 3683 | this->SetElementId(LayerIdToElementIdForTesting(id)); |
| 3684 | AddAnimatedTransformToElementWithPlayer(this->element_id(), timeline, |
| 3685 | 10.0, 3, 0); |
| 3686 | } |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3687 | } |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3688 | |
| 3689 | bool tile_missing_; |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3690 | bool had_incomplete_tile_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3691 | }; |
| 3692 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3693 | struct PrepareToDrawSuccessTestCase { |
| 3694 | struct State { |
| 3695 | bool has_missing_tile = false; |
| 3696 | bool has_incomplete_tile = false; |
| 3697 | bool is_animating = false; |
| 3698 | bool has_copy_request = false; |
| 3699 | }; |
| 3700 | bool high_res_required = false; |
| 3701 | State layer_before; |
| 3702 | State layer_between; |
| 3703 | State layer_after; |
| 3704 | DrawResult expected_result; |
| 3705 | |
| 3706 | explicit PrepareToDrawSuccessTestCase(DrawResult result) |
| 3707 | : expected_result(result) {} |
| 3708 | }; |
| 3709 | |
sadrul | 0df063fc | 2016-07-27 17:36:51 | [diff] [blame] | 3710 | static void CreateLayerFromState( |
| 3711 | DidDrawCheckLayer* root, |
| 3712 | const scoped_refptr<AnimationTimeline>& timeline, |
| 3713 | const PrepareToDrawSuccessTestCase::State& state) { |
| 3714 | static int layer_id = 2; |
| 3715 | root->test_properties()->AddChild(MissingTextureAnimatingLayer::Create( |
| 3716 | root->layer_tree_impl(), layer_id++, state.has_missing_tile, |
| 3717 | state.has_incomplete_tile, state.is_animating, |
| 3718 | root->layer_tree_impl()->resource_provider(), timeline)); |
| 3719 | DidDrawCheckLayer* layer = |
| 3720 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children.back()); |
| 3721 | if (state.has_copy_request) |
| 3722 | layer->AddCopyRequest(); |
| 3723 | } |
| 3724 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3725 | TEST_F(LayerTreeHostImplTest, PrepareToDrawSucceedsAndFails) { |
| 3726 | std::vector<PrepareToDrawSuccessTestCase> cases; |
| 3727 | |
| 3728 | // 0. Default case. |
| 3729 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3730 | // 1. Animated layer first. |
| 3731 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3732 | cases.back().layer_before.is_animating = true; |
| 3733 | // 2. Animated layer between. |
| 3734 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3735 | cases.back().layer_between.is_animating = true; |
| 3736 | // 3. Animated layer last. |
| 3737 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3738 | cases.back().layer_after.is_animating = true; |
| 3739 | // 4. Missing tile first. |
| 3740 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3741 | cases.back().layer_before.has_missing_tile = true; |
| 3742 | // 5. Missing tile between. |
| 3743 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3744 | cases.back().layer_between.has_missing_tile = true; |
| 3745 | // 6. Missing tile last. |
| 3746 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3747 | cases.back().layer_after.has_missing_tile = true; |
| 3748 | // 7. Incomplete tile first. |
| 3749 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3750 | cases.back().layer_before.has_incomplete_tile = true; |
| 3751 | // 8. Incomplete tile between. |
| 3752 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3753 | cases.back().layer_between.has_incomplete_tile = true; |
| 3754 | // 9. Incomplete tile last. |
| 3755 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3756 | cases.back().layer_after.has_incomplete_tile = true; |
| 3757 | // 10. Animation with missing tile. |
| 3758 | cases.push_back( |
| 3759 | PrepareToDrawSuccessTestCase(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS)); |
| 3760 | cases.back().layer_between.has_missing_tile = true; |
| 3761 | cases.back().layer_between.is_animating = true; |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3762 | // 11. Animation with incomplete tile. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3763 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3764 | cases.back().layer_between.has_incomplete_tile = true; |
| 3765 | cases.back().layer_between.is_animating = true; |
| 3766 | |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3767 | // 12. High res required. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3768 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3769 | cases.back().high_res_required = true; |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3770 | // 13. High res required with incomplete tile. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3771 | cases.push_back( |
| 3772 | PrepareToDrawSuccessTestCase(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT)); |
| 3773 | cases.back().high_res_required = true; |
| 3774 | cases.back().layer_between.has_incomplete_tile = true; |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3775 | // 14. High res required with missing tile. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3776 | cases.push_back( |
| 3777 | PrepareToDrawSuccessTestCase(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT)); |
| 3778 | cases.back().high_res_required = true; |
| 3779 | cases.back().layer_between.has_missing_tile = true; |
| 3780 | |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3781 | // 15. High res required is higher priority than animating missing tiles. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3782 | cases.push_back( |
| 3783 | PrepareToDrawSuccessTestCase(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT)); |
| 3784 | cases.back().high_res_required = true; |
| 3785 | cases.back().layer_between.has_missing_tile = true; |
| 3786 | cases.back().layer_after.has_missing_tile = true; |
| 3787 | cases.back().layer_after.is_animating = true; |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 3788 | // 16. High res required is higher priority than animating missing tiles. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3789 | cases.push_back( |
| 3790 | PrepareToDrawSuccessTestCase(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT)); |
| 3791 | cases.back().high_res_required = true; |
| 3792 | cases.back().layer_between.has_missing_tile = true; |
| 3793 | cases.back().layer_before.has_missing_tile = true; |
| 3794 | cases.back().layer_before.is_animating = true; |
| 3795 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3796 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3797 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3798 | DidDrawCheckLayer* root = |
| 3799 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3800 | root->test_properties()->force_render_surface = true; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3801 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3802 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3803 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3804 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3805 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3806 | host_impl_->DidDrawAllLayers(frame); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3807 | |
| 3808 | for (size_t i = 0; i < cases.size(); ++i) { |
loyso | 2b91c08 | 2016-01-06 00:38:38 | [diff] [blame] | 3809 | // Clean up host_impl_ state. |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3810 | const auto& testcase = cases[i]; |
| 3811 | std::vector<LayerImpl*> to_remove; |
vmpstr | a2e8943 | 2016-07-20 02:05:34 | [diff] [blame] | 3812 | for (auto* child : root->test_properties()->children) |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 3813 | to_remove.push_back(child); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3814 | for (auto* child : to_remove) |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3815 | root->test_properties()->RemoveChild(child); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 3816 | timeline()->ClearPlayers(); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3817 | |
| 3818 | std::ostringstream scope; |
| 3819 | scope << "Test case: " << i; |
| 3820 | SCOPED_TRACE(scope.str()); |
| 3821 | |
sadrul | 0df063fc | 2016-07-27 17:36:51 | [diff] [blame] | 3822 | CreateLayerFromState(root, timeline(), testcase.layer_before); |
| 3823 | CreateLayerFromState(root, timeline(), testcase.layer_between); |
| 3824 | CreateLayerFromState(root, timeline(), testcase.layer_after); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3825 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3826 | |
| 3827 | if (testcase.high_res_required) |
| 3828 | host_impl_->SetRequiresHighResToDraw(); |
| 3829 | |
| 3830 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3831 | EXPECT_EQ(testcase.expected_result, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 3832 | host_impl_->DrawLayers(&frame); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3833 | host_impl_->DidDrawAllLayers(frame); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3834 | } |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3835 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3836 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3837 | TEST_F(LayerTreeHostImplTest, |
| 3838 | PrepareToDrawWhenDrawAndSwapFullViewportEveryFrame) { |
| 3839 | CreateHostImpl(DefaultSettings(), |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 3840 | FakeOutputSurface::CreateDelegatingSoftware()); |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 3841 | |
| 3842 | const gfx::Transform external_transform; |
| 3843 | const gfx::Rect external_viewport; |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 3844 | const bool resourceless_software_draw = true; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 3845 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 3846 | external_transform); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3847 | |
| 3848 | std::vector<PrepareToDrawSuccessTestCase> cases; |
| 3849 | |
| 3850 | // 0. Default case. |
| 3851 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3852 | // 1. Animation with missing tile. |
| 3853 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3854 | cases.back().layer_between.has_missing_tile = true; |
| 3855 | cases.back().layer_between.is_animating = true; |
| 3856 | // 2. High res required with incomplete tile. |
| 3857 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3858 | cases.back().high_res_required = true; |
| 3859 | cases.back().layer_between.has_incomplete_tile = true; |
| 3860 | // 3. High res required with missing tile. |
| 3861 | cases.push_back(PrepareToDrawSuccessTestCase(DRAW_SUCCESS)); |
| 3862 | cases.back().high_res_required = true; |
| 3863 | cases.back().layer_between.has_missing_tile = true; |
| 3864 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3865 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3866 | DidDrawCheckLayer::Create(host_impl_->active_tree(), 1)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3867 | DidDrawCheckLayer* root = static_cast<DidDrawCheckLayer*>( |
| 3868 | host_impl_->active_tree()->root_layer_for_testing()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3869 | root->test_properties()->force_render_surface = true; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3870 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3871 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 3872 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 3873 | resourceless_software_draw); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 3874 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3875 | for (size_t i = 0; i < cases.size(); ++i) { |
| 3876 | const auto& testcase = cases[i]; |
| 3877 | std::vector<LayerImpl*> to_remove; |
vmpstr | a2e8943 | 2016-07-20 02:05:34 | [diff] [blame] | 3878 | for (auto* child : root->test_properties()->children) |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 3879 | to_remove.push_back(child); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3880 | for (auto* child : to_remove) |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 3881 | root->test_properties()->RemoveChild(child); |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 3882 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3883 | std::ostringstream scope; |
| 3884 | scope << "Test case: " << i; |
| 3885 | SCOPED_TRACE(scope.str()); |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3886 | |
sadrul | 0df063fc | 2016-07-27 17:36:51 | [diff] [blame] | 3887 | CreateLayerFromState(root, timeline(), testcase.layer_before); |
| 3888 | CreateLayerFromState(root, timeline(), testcase.layer_between); |
| 3889 | CreateLayerFromState(root, timeline(), testcase.layer_after); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3890 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 3891 | |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3892 | if (testcase.high_res_required) |
| 3893 | host_impl_->SetRequiresHighResToDraw(); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 3894 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 3895 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 3896 | resourceless_software_draw); |
danakj | ec8b22b | 2015-03-11 02:20:34 | [diff] [blame] | 3897 | } |
[email protected] | 1001f5c | 2014-06-13 19:57:18 | [diff] [blame] | 3898 | } |
| 3899 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3900 | TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3901 | std::unique_ptr<LayerImpl> root = |
| 3902 | LayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 3903 | root->SetScrollClipLayer(Layer::INVALID_ID); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 3904 | root->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 3905 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3906 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 3907 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 3908 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3909 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3910 | // Scroll event is ignored because layer is not scrollable. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 3911 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 3912 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 3913 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 3914 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 3915 | status.main_thread_scrolling_reasons); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 3916 | EXPECT_FALSE(did_request_redraw_); |
| 3917 | EXPECT_FALSE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 3918 | } |
| 3919 | |
hush | 85432c8 | 2015-07-23 00:24:54 | [diff] [blame] | 3920 | TEST_F(LayerTreeHostImplTest, ClampingAfterActivation) { |
| 3921 | host_impl_->CreatePendingTree(); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 3922 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
hush | 85432c8 | 2015-07-23 00:24:54 | [diff] [blame] | 3923 | CreateScrollAndContentsLayers(host_impl_->pending_tree(), |
| 3924 | gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 3925 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
hush | 85432c8 | 2015-07-23 00:24:54 | [diff] [blame] | 3926 | host_impl_->ActivateSyncTree(); |
| 3927 | |
| 3928 | host_impl_->CreatePendingTree(); |
| 3929 | const gfx::ScrollOffset pending_scroll = gfx::ScrollOffset(-100, -100); |
| 3930 | LayerImpl* active_outer_layer = |
| 3931 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 3932 | LayerImpl* pending_outer_layer = |
| 3933 | host_impl_->pending_tree()->OuterViewportScrollLayer(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 3934 | pending_outer_layer->layer_tree_impl() |
| 3935 | ->property_trees() |
| 3936 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(pending_outer_layer->id(), |
| 3937 | pending_scroll); |
hush | 85432c8 | 2015-07-23 00:24:54 | [diff] [blame] | 3938 | |
| 3939 | host_impl_->ActivateSyncTree(); |
| 3940 | // Scrolloffsets on the active tree will be clamped after activation. |
| 3941 | EXPECT_EQ(active_outer_layer->CurrentScrollOffset(), gfx::ScrollOffset(0, 0)); |
| 3942 | } |
| 3943 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 3944 | class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { |
| 3945 | public: |
| 3946 | LayerTreeHostImplTopControlsTest() |
| 3947 | // Make the clip size the same as the layer (content) size so the layer is |
| 3948 | // non-scrollable. |
| 3949 | : layer_size_(10, 10), |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 3950 | clip_size_(layer_size_), |
| 3951 | top_controls_height_(50) { |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 3952 | viewport_size_ = gfx::Size(clip_size_.width(), |
| 3953 | clip_size_.height() + top_controls_height_); |
| 3954 | } |
| 3955 | |
| 3956 | bool CreateHostImpl(const LayerTreeSettings& settings, |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3957 | std::unique_ptr<OutputSurface> output_surface) override { |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 3958 | bool init = LayerTreeHostImplTest::CreateHostImpl( |
| 3959 | settings, std::move(output_surface)); |
bokan | aa5d1b03 | 2015-03-09 21:51:32 | [diff] [blame] | 3960 | if (init) { |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 3961 | host_impl_->active_tree()->set_top_controls_height(top_controls_height_); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 3962 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 3963 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 3964 | } |
| 3965 | return init; |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 3966 | } |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 3967 | |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 3968 | void SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 3969 | const gfx::Size& inner_viewport_size, |
| 3970 | const gfx::Size& outer_viewport_size, |
| 3971 | const gfx::Size& scroll_layer_size) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 3972 | settings_ = DefaultSettings(); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 3973 | CreateHostImpl(settings_, CreateOutputSurface()); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 3974 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 3975 | host_impl_->active_tree(), inner_viewport_size, outer_viewport_size, |
| 3976 | scroll_layer_size); |
| 3977 | } |
| 3978 | |
| 3979 | void SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 3980 | LayerTreeImpl* tree_impl, |
| 3981 | const gfx::Size& inner_viewport_size, |
| 3982 | const gfx::Size& outer_viewport_size, |
| 3983 | const gfx::Size& scroll_layer_size) { |
| 3984 | tree_impl->set_top_controls_shrink_blink_size(true); |
| 3985 | tree_impl->set_top_controls_height(top_controls_height_); |
| 3986 | tree_impl->SetCurrentTopControlsShownRatio(1.f); |
| 3987 | tree_impl->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 3988 | host_impl_->DidChangeTopControlsPosition(); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 3989 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3990 | std::unique_ptr<LayerImpl> root = LayerImpl::Create(tree_impl, 1); |
| 3991 | std::unique_ptr<LayerImpl> root_clip = LayerImpl::Create(tree_impl, 2); |
| 3992 | std::unique_ptr<LayerImpl> page_scale = LayerImpl::Create(tree_impl, 3); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 3993 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3994 | std::unique_ptr<LayerImpl> outer_scroll = LayerImpl::Create(tree_impl, 4); |
| 3995 | std::unique_ptr<LayerImpl> outer_clip = LayerImpl::Create(tree_impl, 5); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 3996 | |
| 3997 | root_clip->SetBounds(inner_viewport_size); |
| 3998 | root->SetScrollClipLayer(root_clip->id()); |
| 3999 | root->SetBounds(outer_viewport_size); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4000 | root->SetPosition(gfx::PointF()); |
| 4001 | root->SetDrawsContent(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4002 | root_clip->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 4003 | root->test_properties()->is_container_for_fixed_position_layers = true; |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4004 | outer_clip->SetBounds(outer_viewport_size); |
| 4005 | outer_scroll->SetScrollClipLayer(outer_clip->id()); |
| 4006 | outer_scroll->SetBounds(scroll_layer_size); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4007 | outer_scroll->SetPosition(gfx::PointF()); |
| 4008 | outer_scroll->SetDrawsContent(false); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 4009 | outer_scroll->test_properties()->is_container_for_fixed_position_layers = |
| 4010 | true; |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4011 | |
| 4012 | int inner_viewport_scroll_layer_id = root->id(); |
| 4013 | int outer_viewport_scroll_layer_id = outer_scroll->id(); |
| 4014 | int page_scale_layer_id = page_scale->id(); |
| 4015 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4016 | outer_clip->test_properties()->AddChild(std::move(outer_scroll)); |
| 4017 | root->test_properties()->AddChild(std::move(outer_clip)); |
| 4018 | page_scale->test_properties()->AddChild(std::move(root)); |
| 4019 | root_clip->test_properties()->AddChild(std::move(page_scale)); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4020 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4021 | tree_impl->SetRootLayerForTesting(std::move(root_clip)); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4022 | tree_impl->SetViewportLayersFromIds(Layer::INVALID_ID, page_scale_layer_id, |
| 4023 | inner_viewport_scroll_layer_id, |
| 4024 | outer_viewport_scroll_layer_id); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4025 | tree_impl->BuildPropertyTreesForTesting(); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4026 | |
| 4027 | host_impl_->SetViewportSize(inner_viewport_size); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4028 | LayerImpl* root_clip_ptr = tree_impl->root_layer_for_testing(); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4029 | EXPECT_EQ(inner_viewport_size, root_clip_ptr->bounds()); |
| 4030 | } |
| 4031 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4032 | protected: |
| 4033 | gfx::Size layer_size_; |
| 4034 | gfx::Size clip_size_; |
| 4035 | gfx::Size viewport_size_; |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4036 | float top_controls_height_; |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4037 | |
| 4038 | LayerTreeSettings settings_; |
| 4039 | }; // class LayerTreeHostImplTopControlsTest |
| 4040 | |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4041 | // Tests that, on a page with content the same size as the viewport, hiding |
| 4042 | // the top controls also increases the ScrollableSize (i.e. the content size). |
| 4043 | // Since the viewport got larger, the effective scrollable "content" also did. |
| 4044 | // This ensures, for one thing, that the overscroll glow is shown in the right |
| 4045 | // place. |
| 4046 | TEST_F(LayerTreeHostImplTopControlsTest, |
| 4047 | HidingTopControlsExpandsScrollableSize) { |
| 4048 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4049 | gfx::Size(50, 50), gfx::Size(50, 50), gfx::Size(50, 50)); |
| 4050 | |
| 4051 | LayerTreeImpl* active_tree = host_impl_->active_tree(); |
| 4052 | |
| 4053 | // Create a content layer beneath the outer viewport scroll layer. |
| 4054 | int id = host_impl_->OuterViewportScrollLayer()->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4055 | host_impl_->OuterViewportScrollLayer()->test_properties()->AddChild( |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4056 | LayerImpl::Create(host_impl_->active_tree(), id + 2)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 4057 | LayerImpl* content = |
| 4058 | active_tree->OuterViewportScrollLayer()->test_properties()->children[0]; |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4059 | content->SetBounds(gfx::Size(50, 50)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4060 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4061 | |
| 4062 | DrawFrame(); |
| 4063 | |
| 4064 | LayerImpl* inner_container = active_tree->InnerViewportContainerLayer(); |
| 4065 | LayerImpl* outer_container = active_tree->OuterViewportContainerLayer(); |
| 4066 | |
| 4067 | // The top controls should start off showing so the viewport should be shrunk. |
| 4068 | ASSERT_EQ(gfx::Size(50, 50), inner_container->bounds()); |
| 4069 | ASSERT_EQ(gfx::Size(50, 50), outer_container->bounds()); |
| 4070 | |
| 4071 | EXPECT_EQ(gfx::SizeF(50, 50), active_tree->ScrollableSize()); |
| 4072 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4073 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4074 | host_impl_ |
| 4075 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4076 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4077 | .thread); |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4078 | |
| 4079 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4080 | |
| 4081 | // Hide the top controls by a bit, the scrollable size should increase but the |
| 4082 | // actual content bounds shouldn't. |
| 4083 | { |
| 4084 | host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); |
| 4085 | ASSERT_EQ(gfx::Size(50, 75), inner_container->bounds()); |
| 4086 | ASSERT_EQ(gfx::Size(50, 75), outer_container->bounds()); |
| 4087 | EXPECT_EQ(gfx::SizeF(50, 75), active_tree->ScrollableSize()); |
| 4088 | EXPECT_EQ(gfx::SizeF(50, 50), content->BoundsForScrolling()); |
| 4089 | } |
| 4090 | |
| 4091 | // Fully hide the top controls. |
| 4092 | { |
| 4093 | host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); |
| 4094 | ASSERT_EQ(gfx::Size(50, 100), inner_container->bounds()); |
| 4095 | ASSERT_EQ(gfx::Size(50, 100), outer_container->bounds()); |
| 4096 | EXPECT_EQ(gfx::SizeF(50, 100), active_tree->ScrollableSize()); |
| 4097 | EXPECT_EQ(gfx::SizeF(50, 50), content->BoundsForScrolling()); |
| 4098 | } |
| 4099 | |
| 4100 | // Scrolling additionally shouldn't have any effect. |
| 4101 | { |
| 4102 | host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); |
| 4103 | ASSERT_EQ(gfx::Size(50, 100), inner_container->bounds()); |
| 4104 | ASSERT_EQ(gfx::Size(50, 100), outer_container->bounds()); |
| 4105 | EXPECT_EQ(gfx::SizeF(50, 100), active_tree->ScrollableSize()); |
| 4106 | EXPECT_EQ(gfx::SizeF(50, 50), content->BoundsForScrolling()); |
| 4107 | } |
| 4108 | |
| 4109 | host_impl_->top_controls_manager()->ScrollEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4110 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 4111 | } |
| 4112 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4113 | TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4114 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4115 | gfx::Size(10, 10), gfx::Size(10, 10), gfx::Size(10, 10)); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4116 | DrawFrame(); |
| 4117 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4118 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4119 | host_impl_ |
| 4120 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4121 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4122 | .thread); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4123 | |
| 4124 | // Make the test scroll delta a fractional amount, to verify that the |
| 4125 | // fixed container size delta is (1) non-zero, and (2) fractional, and |
| 4126 | // (3) matches the movement of the top controls. |
| 4127 | gfx::Vector2dF top_controls_scroll_delta(0.f, 5.25f); |
| 4128 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4129 | host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
| 4130 | host_impl_->top_controls_manager()->ScrollEnd(); |
| 4131 | |
| 4132 | LayerImpl* inner_viewport_scroll_layer = |
| 4133 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
| 4134 | DCHECK(inner_viewport_scroll_layer); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4135 | host_impl_->ScrollEnd(EndState().get()); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4136 | EXPECT_FLOAT_EQ(top_controls_scroll_delta.y(), |
| 4137 | inner_viewport_scroll_layer->FixedContainerSizeDelta().y()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4138 | } |
| 4139 | |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4140 | // In this test, the outer viewport is initially unscrollable. We test that a |
| 4141 | // scroll initiated on the inner viewport, causing the top controls to show and |
| 4142 | // thus making the outer viewport scrollable, still scrolls the outer viewport. |
| 4143 | TEST_F(LayerTreeHostImplTopControlsTest, |
| 4144 | TopControlsOuterViewportBecomesScrollable) { |
| 4145 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4146 | gfx::Size(10, 50), gfx::Size(10, 50), gfx::Size(10, 100)); |
| 4147 | DrawFrame(); |
| 4148 | |
thestig | d5fcf98 | 2015-05-11 18:41:38 | [diff] [blame] | 4149 | LayerImpl* inner_scroll = |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4150 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 4151 | inner_scroll->SetDrawsContent(true); |
thestig | d5fcf98 | 2015-05-11 18:41:38 | [diff] [blame] | 4152 | LayerImpl* inner_container = |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4153 | host_impl_->active_tree()->InnerViewportContainerLayer(); |
thestig | d5fcf98 | 2015-05-11 18:41:38 | [diff] [blame] | 4154 | LayerImpl* outer_scroll = |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4155 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 4156 | outer_scroll->SetDrawsContent(true); |
thestig | d5fcf98 | 2015-05-11 18:41:38 | [diff] [blame] | 4157 | LayerImpl* outer_container = |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4158 | host_impl_->active_tree()->OuterViewportContainerLayer(); |
| 4159 | |
| 4160 | // Need SetDrawsContent so ScrollBegin's hit test finds an actual layer. |
| 4161 | outer_scroll->SetDrawsContent(true); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 4162 | host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 1.f, 2.f); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4163 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4164 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4165 | host_impl_ |
| 4166 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4167 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4168 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4169 | host_impl_->ScrollBy( |
| 4170 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, 50.f)).get()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4171 | |
| 4172 | // The entire scroll delta should have been used to hide the top controls. |
| 4173 | // The viewport layers should be resized back to their full sizes. |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4174 | EXPECT_EQ(0.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 4175 | EXPECT_EQ(0.f, inner_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4176 | EXPECT_EQ(100.f, inner_container->BoundsForScrolling().height()); |
| 4177 | EXPECT_EQ(100.f, outer_container->BoundsForScrolling().height()); |
| 4178 | |
| 4179 | // The inner viewport should be scrollable by 50px * page_scale. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4180 | host_impl_->ScrollBy( |
| 4181 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, 100.f)).get()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 4182 | EXPECT_EQ(50.f, inner_scroll->CurrentScrollOffset().y()); |
| 4183 | EXPECT_EQ(0.f, outer_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4184 | EXPECT_EQ(gfx::ScrollOffset(), outer_scroll->MaxScrollOffset()); |
| 4185 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4186 | host_impl_->ScrollEnd(EndState().get()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4187 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4188 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4189 | host_impl_ |
| 4190 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4191 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4192 | .thread); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4193 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll); |
| 4194 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4195 | host_impl_->ScrollBy( |
| 4196 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, -50.f)).get()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4197 | |
| 4198 | // The entire scroll delta should have been used to show the top controls. |
| 4199 | // The outer viewport should be resized to accomodate and scrolled to the |
| 4200 | // bottom of the document to keep the viewport in place. |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4201 | EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4202 | EXPECT_EQ(50.f, outer_container->BoundsForScrolling().height()); |
| 4203 | EXPECT_EQ(50.f, inner_container->BoundsForScrolling().height()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 4204 | EXPECT_EQ(25.f, outer_scroll->CurrentScrollOffset().y()); |
| 4205 | EXPECT_EQ(25.f, inner_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4206 | |
| 4207 | // Now when we continue scrolling, make sure the outer viewport gets scrolled |
| 4208 | // since it wasn't scrollable when the scroll began. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4209 | host_impl_->ScrollBy( |
| 4210 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, -20.f)).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 4211 | EXPECT_EQ(25.f, outer_scroll->CurrentScrollOffset().y()); |
| 4212 | EXPECT_EQ(15.f, inner_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4213 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4214 | host_impl_->ScrollBy( |
| 4215 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, -30.f)).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 4216 | EXPECT_EQ(25.f, outer_scroll->CurrentScrollOffset().y()); |
| 4217 | EXPECT_EQ(0.f, inner_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4218 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4219 | host_impl_->ScrollBy( |
| 4220 | UpdateState(gfx::Point(), gfx::Vector2dF(0.f, -50.f)).get()); |
| 4221 | host_impl_->ScrollEnd(EndState().get()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4222 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 4223 | EXPECT_EQ(0.f, outer_scroll->CurrentScrollOffset().y()); |
| 4224 | EXPECT_EQ(0.f, inner_scroll->CurrentScrollOffset().y()); |
bokan | a203a4b1 | 2014-11-18 16:28:08 | [diff] [blame] | 4225 | } |
| 4226 | |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4227 | // Test that the fixed position container delta is appropriately adjusted |
| 4228 | // by the top controls showing/hiding and page scale doesn't affect it. |
| 4229 | TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) { |
| 4230 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4231 | gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100)); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4232 | DrawFrame(); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 4233 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4234 | |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4235 | float page_scale = 1.5f; |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4236 | LayerImpl* outer_viewport_scroll_layer = |
| 4237 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 4238 | |
| 4239 | // Zoom in, since the fixed container is the outer viewport, the delta should |
| 4240 | // not be scaled. |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 4241 | host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f, 2.f); |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4242 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4243 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4244 | host_impl_ |
| 4245 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4246 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4247 | .thread); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4248 | |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4249 | // Scroll down, the top controls hiding should expand the viewport size so |
| 4250 | // the delta should be equal to the scroll distance. |
| 4251 | gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4252 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4253 | host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4254 | EXPECT_FLOAT_EQ(top_controls_height_ - top_controls_scroll_delta.y(), |
| 4255 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 4256 | EXPECT_FLOAT_EQ(top_controls_scroll_delta.y(), |
| 4257 | outer_viewport_scroll_layer->FixedContainerSizeDelta().y()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4258 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4259 | |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4260 | // Scroll past the maximum extent. The delta shouldn't be greater than the |
| 4261 | // top controls height. |
| 4262 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4263 | host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
| 4264 | host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
| 4265 | host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
| 4266 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4267 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, top_controls_height_), |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4268 | outer_viewport_scroll_layer->FixedContainerSizeDelta()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4269 | host_impl_->ScrollEnd(EndState().get()); |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4270 | |
| 4271 | // Scroll in the direction to make the top controls show. |
| 4272 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4273 | host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta); |
| 4274 | EXPECT_EQ(top_controls_scroll_delta.y(), |
| 4275 | host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4276 | EXPECT_VECTOR_EQ( |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4277 | gfx::Vector2dF(0, top_controls_height_ - top_controls_scroll_delta.y()), |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 4278 | outer_viewport_scroll_layer->FixedContainerSizeDelta()); |
| 4279 | host_impl_->top_controls_manager()->ScrollEnd(); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4280 | } |
| 4281 | |
bokan | 0223f2f72 | 2016-06-23 12:35:01 | [diff] [blame] | 4282 | // Push a top controls ratio from the main thread that we didn't send as a delta |
| 4283 | // and make sure that the ratio is clamped to the [0, 1] range. |
| 4284 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsPushUnsentRatio) { |
| 4285 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4286 | gfx::Size(10, 50), gfx::Size(10, 50), gfx::Size(10, 100)); |
| 4287 | DrawFrame(); |
| 4288 | |
| 4289 | // Need SetDrawsContent so ScrollBegin's hit test finds an actual layer. |
| 4290 | LayerImpl* inner_scroll = |
| 4291 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
| 4292 | inner_scroll->SetDrawsContent(true); |
| 4293 | LayerImpl* outer_scroll = |
| 4294 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 4295 | outer_scroll->SetDrawsContent(true); |
| 4296 | |
| 4297 | host_impl_->active_tree()->PushTopControlsFromMainThread(1); |
| 4298 | ASSERT_EQ(1.0f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 4299 | |
| 4300 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.5f); |
| 4301 | ASSERT_EQ(0.5f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 4302 | |
| 4303 | host_impl_->active_tree()->PushTopControlsFromMainThread(0); |
| 4304 | |
| 4305 | ASSERT_EQ(0, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 4306 | } |
| 4307 | |
tdresser | a4bec5df | 2015-07-14 13:23:34 | [diff] [blame] | 4308 | // Test that if only the top controls are scrolled, we shouldn't request a |
| 4309 | // commit. |
| 4310 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsDontTriggerCommit) { |
| 4311 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4312 | gfx::Size(100, 50), gfx::Size(100, 100), gfx::Size(100, 100)); |
| 4313 | DrawFrame(); |
| 4314 | |
| 4315 | // Show top controls |
| 4316 | EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 4317 | |
| 4318 | // Scroll 25px to hide top controls |
| 4319 | gfx::Vector2dF scroll_delta(0.f, 25.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4320 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4321 | host_impl_ |
| 4322 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4323 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4324 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4325 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | a4bec5df | 2015-07-14 13:23:34 | [diff] [blame] | 4326 | EXPECT_FALSE(did_request_commit_); |
| 4327 | } |
| 4328 | |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4329 | // Test that if a scrollable sublayer doesn't consume the scroll, |
| 4330 | // top controls should hide when scrolling down. |
| 4331 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollableSublayer) { |
| 4332 | gfx::Size sub_content_size(100, 400); |
| 4333 | gfx::Size sub_content_layer_size(100, 300); |
| 4334 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4335 | gfx::Size(100, 50), gfx::Size(100, 100), gfx::Size(100, 100)); |
| 4336 | DrawFrame(); |
| 4337 | |
| 4338 | // Show top controls |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4339 | EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4340 | |
| 4341 | LayerImpl* outer_viewport_scroll_layer = |
| 4342 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 4343 | int id = outer_viewport_scroll_layer->id(); |
| 4344 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4345 | std::unique_ptr<LayerImpl> child = |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4346 | LayerImpl::Create(host_impl_->active_tree(), id + 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4347 | std::unique_ptr<LayerImpl> child_clip = |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4348 | LayerImpl::Create(host_impl_->active_tree(), id + 3); |
| 4349 | |
| 4350 | child_clip->SetBounds(sub_content_layer_size); |
| 4351 | child->SetScrollClipLayer(child_clip->id()); |
| 4352 | child->SetBounds(sub_content_size); |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4353 | child->SetPosition(gfx::PointF()); |
| 4354 | child->SetDrawsContent(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 4355 | child->test_properties()->is_container_for_fixed_position_layers = true; |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4356 | |
| 4357 | // scroll child to limit |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 4358 | SetScrollOffsetDelta(child.get(), gfx::Vector2dF(0, 100.f)); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4359 | child_clip->test_properties()->AddChild(std::move(child)); |
| 4360 | outer_viewport_scroll_layer->test_properties()->AddChild( |
| 4361 | std::move(child_clip)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4362 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4363 | |
| 4364 | // Scroll 25px to hide top controls |
| 4365 | gfx::Vector2dF scroll_delta(0.f, 25.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4366 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4367 | host_impl_ |
| 4368 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4369 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4370 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4371 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 4372 | host_impl_->ScrollEnd(EndState().get()); |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4373 | |
| 4374 | // Top controls should be hidden |
| 4375 | EXPECT_EQ(scroll_delta.y(), |
| 4376 | top_controls_height_ - |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4377 | host_impl_->top_controls_manager()->ContentTopOffset()); |
elisabets | 01d84d3 | 2014-12-15 12:50:05 | [diff] [blame] | 4378 | } |
| 4379 | |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4380 | // Ensure setting the top controls position explicitly using the setters on the |
| 4381 | // TreeImpl correctly affects the top controls manager and viewport bounds. |
| 4382 | TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 4383 | settings_ = DefaultSettings(); |
aelias | 5d3e3b4 | 2014-10-14 03:51:02 | [diff] [blame] | 4384 | CreateHostImpl(settings_, CreateOutputSurface()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4385 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4386 | layer_size_, layer_size_, layer_size_); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4387 | DrawFrame(); |
| 4388 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4389 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); |
| 4390 | host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( |
| 4391 | 30.f / top_controls_height_); |
| 4392 | host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive(); |
| 4393 | EXPECT_FLOAT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4394 | EXPECT_FLOAT_EQ(-20.f, |
| 4395 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4396 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4397 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); |
| 4398 | EXPECT_FLOAT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4399 | EXPECT_FLOAT_EQ(-50.f, |
| 4400 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4401 | |
| 4402 | host_impl_->DidChangeTopControlsPosition(); |
| 4403 | |
| 4404 | // Now that top controls have moved, expect the clip to resize. |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4405 | LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4406 | ->test_properties() |
| 4407 | ->parent->test_properties() |
| 4408 | ->parent; |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4409 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | // Test that the top_controls delta and sent delta are appropriately |
| 4413 | // applied on sync tree activation. The total top controls offset shouldn't |
| 4414 | // change after the activation. |
| 4415 | TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 4416 | settings_ = DefaultSettings(); |
aelias | 5d3e3b4 | 2014-10-14 03:51:02 | [diff] [blame] | 4417 | CreateHostImpl(settings_, CreateOutputSurface()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4418 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4419 | layer_size_, layer_size_, layer_size_); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4420 | DrawFrame(); |
| 4421 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4422 | host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( |
| 4423 | 20.f / top_controls_height_); |
| 4424 | host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive(); |
| 4425 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio( |
| 4426 | 15.f / top_controls_height_); |
| 4427 | host_impl_->active_tree() |
| 4428 | ->top_controls_shown_ratio() |
| 4429 | ->PullDeltaForMainThread(); |
| 4430 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); |
| 4431 | host_impl_->sync_tree()->PushTopControlsFromMainThread(15.f / |
| 4432 | top_controls_height_); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4433 | |
| 4434 | host_impl_->DidChangeTopControlsPosition(); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4435 | LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4436 | ->test_properties() |
| 4437 | ->parent->test_properties() |
| 4438 | ->parent; |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4439 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4440 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4441 | |
| 4442 | host_impl_->ActivateSyncTree(); |
| 4443 | |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4444 | inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4445 | ->test_properties() |
| 4446 | ->parent->test_properties() |
| 4447 | ->parent; |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4448 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4449 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4450 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4451 | EXPECT_FLOAT_EQ( |
| 4452 | -15.f, host_impl_->active_tree()->top_controls_shown_ratio()->Delta() * |
| 4453 | top_controls_height_); |
| 4454 | EXPECT_FLOAT_EQ( |
| 4455 | 15.f, |
| 4456 | host_impl_->active_tree()->top_controls_shown_ratio()->ActiveBase() * |
| 4457 | top_controls_height_); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4458 | } |
| 4459 | |
| 4460 | // Test that changing the top controls layout height is correctly applied to |
| 4461 | // the inner viewport container bounds. That is, the top controls layout |
| 4462 | // height is the amount that the inner viewport container was shrunk outside |
| 4463 | // the compositor to accommodate the top controls. |
| 4464 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 4465 | settings_ = DefaultSettings(); |
aelias | 5d3e3b4 | 2014-10-14 03:51:02 | [diff] [blame] | 4466 | CreateHostImpl(settings_, CreateOutputSurface()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4467 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4468 | layer_size_, layer_size_, layer_size_); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4469 | DrawFrame(); |
| 4470 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4471 | host_impl_->sync_tree()->PushTopControlsFromMainThread(1.f); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4472 | host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4473 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4474 | host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( |
| 4475 | 1.f); |
| 4476 | host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive(); |
| 4477 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4478 | |
| 4479 | host_impl_->DidChangeTopControlsPosition(); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4480 | LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4481 | ->test_properties() |
| 4482 | ->parent->test_properties() |
| 4483 | ->parent; |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4484 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4485 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4486 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4487 | host_impl_->sync_tree()->root_layer_for_testing()->SetBounds( |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4488 | gfx::Size(inner_clip_ptr->bounds().width(), |
| 4489 | inner_clip_ptr->bounds().height() - 50.f)); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4490 | |
| 4491 | host_impl_->ActivateSyncTree(); |
| 4492 | |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4493 | inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4494 | ->test_properties() |
| 4495 | ->parent->test_properties() |
| 4496 | ->parent; |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4497 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4498 | |
| 4499 | // The total bounds should remain unchanged since the bounds delta should |
| 4500 | // account for the difference between the layout height and the current |
| 4501 | // top controls offset. |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4502 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
| 4503 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 50.f), inner_clip_ptr->bounds_delta()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4504 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4505 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4506 | host_impl_->DidChangeTopControlsPosition(); |
| 4507 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4508 | EXPECT_EQ(1.f, host_impl_->top_controls_manager()->TopControlsShownRatio()); |
| 4509 | EXPECT_EQ(50.f, host_impl_->top_controls_manager()->TopControlsHeight()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4510 | EXPECT_EQ(50.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4511 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), inner_clip_ptr->bounds_delta()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4512 | EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height() - 50.f), |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4513 | inner_clip_ptr->bounds()); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4514 | } |
| 4515 | |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4516 | // Test that showing/hiding the top controls when the viewport is fully scrolled |
| 4517 | // doesn't incorrectly change the viewport offset due to clamping from changing |
| 4518 | // viewport bounds. |
| 4519 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) { |
| 4520 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4521 | gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); |
| 4522 | DrawFrame(); |
| 4523 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4524 | EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4525 | |
| 4526 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 4527 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 4528 | |
| 4529 | // Scroll the viewports to max scroll offset. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 4530 | SetScrollOffsetDelta(outer_scroll, gfx::Vector2dF(0, 200.f)); |
| 4531 | SetScrollOffsetDelta(inner_scroll, gfx::Vector2dF(100, 100.f)); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4532 | |
| 4533 | gfx::ScrollOffset viewport_offset = |
| 4534 | host_impl_->active_tree()->TotalScrollOffset(); |
| 4535 | EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); |
| 4536 | |
| 4537 | // Hide the top controls by 25px. |
| 4538 | gfx::Vector2dF scroll_delta(0.f, 25.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4539 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4540 | host_impl_ |
| 4541 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4542 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4543 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4544 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 4545 | |
| 4546 | // scrolling down at the max extents no longer hides the top controls |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4547 | EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 4548 | |
| 4549 | // forcefully hide the top controls by 25px |
| 4550 | host_impl_->top_controls_manager()->ScrollBy(scroll_delta); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4551 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4552 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4553 | EXPECT_FLOAT_EQ(scroll_delta.y(), |
| 4554 | top_controls_height_ - |
| 4555 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4556 | |
| 4557 | inner_scroll->ClampScrollToMaxScrollOffset(); |
| 4558 | outer_scroll->ClampScrollToMaxScrollOffset(); |
| 4559 | |
| 4560 | // We should still be fully scrolled. |
| 4561 | EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), |
| 4562 | host_impl_->active_tree()->TotalScrollOffset()); |
| 4563 | |
| 4564 | viewport_offset = host_impl_->active_tree()->TotalScrollOffset(); |
| 4565 | |
| 4566 | // Bring the top controls down by 25px. |
| 4567 | scroll_delta = gfx::Vector2dF(0.f, -25.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4568 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4569 | host_impl_ |
| 4570 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4571 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4572 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4573 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 4574 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4575 | |
| 4576 | // The viewport offset shouldn't have changed. |
| 4577 | EXPECT_EQ(viewport_offset, |
| 4578 | host_impl_->active_tree()->TotalScrollOffset()); |
| 4579 | |
| 4580 | // Scroll the viewports to max scroll offset. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 4581 | SetScrollOffsetDelta(outer_scroll, gfx::Vector2dF(0, 200.f)); |
| 4582 | SetScrollOffsetDelta(inner_scroll, gfx::Vector2dF(100, 100.f)); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4583 | EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), |
| 4584 | host_impl_->active_tree()->TotalScrollOffset()); |
| 4585 | } |
| 4586 | |
| 4587 | // Test that the top controls coming in and out maintains the same aspect ratio |
| 4588 | // between the inner and outer viewports. |
| 4589 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) { |
| 4590 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4591 | gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 4592 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 2.f); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4593 | DrawFrame(); |
| 4594 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4595 | EXPECT_FLOAT_EQ(top_controls_height_, |
| 4596 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4597 | |
| 4598 | gfx::Vector2dF scroll_delta(0.f, 25.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4599 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4600 | host_impl_ |
| 4601 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4602 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4603 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4604 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 4605 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4606 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4607 | EXPECT_FLOAT_EQ(scroll_delta.y(), |
| 4608 | top_controls_height_ - |
| 4609 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4610 | |
| 4611 | // Top controls were hidden by 25px so the inner viewport should have expanded |
| 4612 | // by that much. |
| 4613 | LayerImpl* outer_container = |
| 4614 | host_impl_->active_tree()->OuterViewportContainerLayer(); |
| 4615 | LayerImpl* inner_container = |
| 4616 | host_impl_->active_tree()->InnerViewportContainerLayer(); |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4617 | EXPECT_EQ(gfx::SizeF(100.f, 100.f + 25.f), |
| 4618 | inner_container->BoundsForScrolling()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4619 | |
| 4620 | // Outer viewport should match inner's aspect ratio. The bounds are ceiled. |
| 4621 | float aspect_ratio = inner_container->BoundsForScrolling().width() / |
| 4622 | inner_container->BoundsForScrolling().height(); |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4623 | gfx::SizeF expected = |
| 4624 | gfx::SizeF(gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio))); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4625 | EXPECT_EQ(expected, outer_container->BoundsForScrolling()); |
| 4626 | EXPECT_EQ(expected, |
| 4627 | host_impl_->InnerViewportScrollLayer()->BoundsForScrolling()); |
| 4628 | } |
| 4629 | |
| 4630 | // Test that scrolling the outer viewport affects the top controls. |
| 4631 | TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { |
| 4632 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4633 | gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); |
| 4634 | DrawFrame(); |
| 4635 | |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4636 | EXPECT_EQ(top_controls_height_, |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4637 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4638 | |
| 4639 | // Send a gesture scroll that will scroll the outer viewport, make sure the |
| 4640 | // top controls get scrolled. |
| 4641 | gfx::Vector2dF scroll_delta(0.f, 15.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4642 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4643 | host_impl_ |
| 4644 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4645 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4646 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4647 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 4648 | |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 4649 | EXPECT_EQ(host_impl_->InnerViewportScrollLayer(), |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4650 | host_impl_->CurrentlyScrollingLayer()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4651 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4652 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4653 | EXPECT_FLOAT_EQ(scroll_delta.y(), |
| 4654 | top_controls_height_ - |
| 4655 | host_impl_->top_controls_manager()->ContentTopOffset()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4656 | |
| 4657 | scroll_delta = gfx::Vector2dF(0.f, 50.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4658 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4659 | host_impl_ |
| 4660 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4661 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4662 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4663 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4664 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4665 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset()); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 4666 | EXPECT_EQ(host_impl_->InnerViewportScrollLayer(), |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4667 | host_impl_->CurrentlyScrollingLayer()); |
| 4668 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4669 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4670 | |
| 4671 | // Position the viewports such that the inner viewport will be scrolled. |
| 4672 | gfx::Vector2dF inner_viewport_offset(0.f, 25.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 4673 | SetScrollOffsetDelta(host_impl_->OuterViewportScrollLayer(), |
| 4674 | gfx::Vector2dF()); |
| 4675 | SetScrollOffsetDelta(host_impl_->InnerViewportScrollLayer(), |
| 4676 | inner_viewport_offset); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4677 | |
| 4678 | scroll_delta = gfx::Vector2dF(0.f, -65.f); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4679 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4680 | host_impl_ |
| 4681 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4682 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4683 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4684 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4685 | |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4686 | EXPECT_EQ(top_controls_height_, |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4687 | host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4688 | EXPECT_FLOAT_EQ( |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 4689 | inner_viewport_offset.y() + (scroll_delta.y() + top_controls_height_), |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 4690 | ScrollDelta(host_impl_->InnerViewportScrollLayer()).y()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4691 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4692 | host_impl_->ScrollEnd(EndState().get()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 4693 | } |
| 4694 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4695 | TEST_F(LayerTreeHostImplTopControlsTest, |
| 4696 | ScrollNonScrollableRootWithTopControls) { |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 4697 | settings_ = DefaultSettings(); |
aelias | 5d3e3b4 | 2014-10-14 03:51:02 | [diff] [blame] | 4698 | CreateHostImpl(settings_, CreateOutputSurface()); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4699 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4700 | layer_size_, layer_size_, layer_size_); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 4701 | DrawFrame(); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 4702 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4703 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4704 | host_impl_ |
| 4705 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4706 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4707 | .thread); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 4708 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4709 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4710 | host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); |
| 4711 | host_impl_->top_controls_manager()->ScrollEnd(); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 4712 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4713 | // Now that top controls have moved, expect the clip to resize. |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 4714 | LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() |
| 4715 | ->test_properties() |
| 4716 | ->parent->test_properties() |
| 4717 | ->parent; |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4718 | EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 4719 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4720 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | d948c11 | 2014-01-10 02:13:53 | [diff] [blame] | 4721 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4722 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4723 | host_impl_ |
| 4724 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4725 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4726 | .thread); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4727 | |
| 4728 | float scroll_increment_y = -25.f; |
| 4729 | host_impl_->top_controls_manager()->ScrollBegin(); |
| 4730 | host_impl_->top_controls_manager()->ScrollBy( |
| 4731 | gfx::Vector2dF(0.f, scroll_increment_y)); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4732 | EXPECT_FLOAT_EQ(-scroll_increment_y, |
| 4733 | host_impl_->top_controls_manager()->ContentTopOffset()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4734 | // Now that top controls have moved, expect the clip to resize. |
| 4735 | EXPECT_EQ(gfx::Size(viewport_size_.width(), |
| 4736 | viewport_size_.height() + scroll_increment_y), |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4737 | inner_clip_ptr->bounds()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4738 | |
| 4739 | host_impl_->top_controls_manager()->ScrollBy( |
| 4740 | gfx::Vector2dF(0.f, scroll_increment_y)); |
| 4741 | host_impl_->top_controls_manager()->ScrollEnd(); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 4742 | EXPECT_FLOAT_EQ(-2 * scroll_increment_y, |
| 4743 | host_impl_->top_controls_manager()->ContentTopOffset()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4744 | // Now that top controls have moved, expect the clip to resize. |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 4745 | EXPECT_EQ(clip_size_, inner_clip_ptr->bounds()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4746 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4747 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4748 | |
| 4749 | // Verify the layer is once-again non-scrollable. |
| 4750 | EXPECT_EQ( |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 4751 | gfx::ScrollOffset(), |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 4752 | host_impl_->active_tree()->InnerViewportScrollLayer()->MaxScrollOffset()); |
| 4753 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4754 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 4755 | host_impl_ |
| 4756 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 4757 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4758 | .thread); |
[email protected] | c8415bf9 | 2013-02-17 18:57:27 | [diff] [blame] | 4759 | } |
| 4760 | |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4761 | // Tests that activating a pending tree while there's a bounds_delta on the |
| 4762 | // viewport layers from top controls doesn't cause a scroll jump. This bug was |
| 4763 | // occurring because the UpdateViewportContainerSizes was being called before |
| 4764 | // the property trees were updated with the bounds_delta. crbug.com/597266. |
| 4765 | TEST_F(LayerTreeHostImplTopControlsTest, ViewportBoundsDeltaOnTreeActivation) { |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4766 | const gfx::Size inner_viewport_size(1000, 1000); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4767 | const gfx::Size outer_viewport_size(1000, 1000); |
| 4768 | const gfx::Size content_size(2000, 2000); |
| 4769 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4770 | // Initialization |
| 4771 | { |
| 4772 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4773 | inner_viewport_size, outer_viewport_size, content_size); |
| 4774 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4775 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4776 | // Start off with the top controls hidden on both main and impl. |
| 4777 | host_impl_->active_tree()->set_top_controls_shrink_blink_size(false); |
| 4778 | host_impl_->active_tree()->PushTopControlsFromMainThread(0); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4779 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4780 | host_impl_->CreatePendingTree(); |
| 4781 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4782 | host_impl_->pending_tree(), inner_viewport_size, outer_viewport_size, |
| 4783 | content_size); |
| 4784 | host_impl_->pending_tree()->set_top_controls_shrink_blink_size(false); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4785 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4786 | // Fully scroll the viewport. |
| 4787 | host_impl_->ScrollBegin(BeginState(gfx::Point(75, 75)).get(), |
| 4788 | InputHandler::TOUCHSCREEN); |
| 4789 | host_impl_->ScrollBy( |
| 4790 | UpdateState(gfx::Point(), gfx::Vector2d(0, 2000)).get()); |
| 4791 | host_impl_->ScrollEnd(EndState().get()); |
| 4792 | } |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4793 | |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4794 | LayerImpl* outer_scroll = |
| 4795 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 4796 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4797 | ASSERT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4798 | ASSERT_EQ(1000, outer_scroll->MaxScrollOffset().y()); |
| 4799 | ASSERT_EQ(1000, outer_scroll->CurrentScrollOffset().y()); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4800 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4801 | // Kick off an animation to show the top controls. |
| 4802 | host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, true); |
| 4803 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 4804 | BeginFrameArgs begin_frame_args = |
| 4805 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4806 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4807 | // Pump an animation frame to put some delta in the top controls. |
| 4808 | { |
| 4809 | begin_frame_args.frame_time = |
| 4810 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 4811 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 4812 | host_impl_->Animate(); |
| 4813 | host_impl_->UpdateAnimationState(true); |
| 4814 | host_impl_->DidFinishImplFrame(); |
| 4815 | } |
| 4816 | |
| 4817 | // Pull the top controls delta and get it back to the pending tree so that |
| 4818 | // when we go to activate the pending tree we cause a change to top controls. |
| 4819 | { |
| 4820 | float delta = |
| 4821 | host_impl_->active_tree()->top_controls_shown_ratio()->Delta(); |
| 4822 | ASSERT_GT(delta, 0); |
| 4823 | ASSERT_LT(delta, 1); |
| 4824 | host_impl_->active_tree() |
| 4825 | ->top_controls_shown_ratio() |
| 4826 | ->PullDeltaForMainThread(); |
| 4827 | host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( |
| 4828 | delta); |
| 4829 | } |
| 4830 | |
| 4831 | // 200 is the kShowHideMaxDurationMs value from top_controls_manager.cc so the |
| 4832 | // top controls should be fully animated in this frame. |
| 4833 | { |
| 4834 | begin_frame_args.frame_time = |
| 4835 | start_time + base::TimeDelta::FromMilliseconds(200); |
| 4836 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 4837 | host_impl_->Animate(); |
| 4838 | host_impl_->UpdateAnimationState(true); |
| 4839 | host_impl_->DidFinishImplFrame(); |
| 4840 | |
| 4841 | ASSERT_EQ(50, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4842 | ASSERT_EQ(1050, outer_scroll->MaxScrollOffset().y()); |
| 4843 | // NEAR because clip layer bounds are truncated in MaxScrollOffset so we |
| 4844 | // lose some precision in the intermediate animation steps. |
| 4845 | ASSERT_NEAR(1050, outer_scroll->CurrentScrollOffset().y(), 1.f); |
| 4846 | } |
| 4847 | |
| 4848 | // Activate the pending tree which should have the same scroll value as the |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4849 | // active tree. |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4850 | { |
| 4851 | host_impl_->pending_tree() |
| 4852 | ->property_trees() |
| 4853 | ->scroll_tree.SetScrollOffsetDeltaForTesting(outer_scroll->id(), |
| 4854 | gfx::Vector2dF(0, 1050)); |
| 4855 | host_impl_->ActivateSyncTree(); |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4856 | |
bokan | fe9e63e | 2016-07-19 19:19:08 | [diff] [blame] | 4857 | // Make sure we don't accidentally clamp the outer offset based on a bounds |
| 4858 | // delta that hasn't yet been updated. |
| 4859 | EXPECT_NEAR(1050, outer_scroll->CurrentScrollOffset().y(), 1.f); |
| 4860 | } |
bokan | 7ad75ed | 2016-03-30 19:29:57 | [diff] [blame] | 4861 | } |
| 4862 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4863 | TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { |
| 4864 | // Test the configuration where a non-composited root layer is embedded in a |
| 4865 | // scrollable outer layer. |
| 4866 | gfx::Size surface_size(10, 10); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4867 | gfx::Size contents_size(20, 20); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4868 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4869 | std::unique_ptr<LayerImpl> content_layer = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4870 | LayerImpl::Create(host_impl_->active_tree(), 1); |
| 4871 | content_layer->SetDrawsContent(true); |
| 4872 | content_layer->SetPosition(gfx::PointF()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4873 | content_layer->SetBounds(contents_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4874 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4875 | std::unique_ptr<LayerImpl> scroll_clip_layer = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4876 | LayerImpl::Create(host_impl_->active_tree(), 3); |
| 4877 | scroll_clip_layer->SetBounds(surface_size); |
| 4878 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4879 | std::unique_ptr<LayerImpl> scroll_layer = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4880 | LayerImpl::Create(host_impl_->active_tree(), 2); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4881 | scroll_layer->SetScrollClipLayer(3); |
| 4882 | scroll_layer->SetBounds(contents_size); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4883 | scroll_layer->SetPosition(gfx::PointF()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4884 | scroll_layer->test_properties()->AddChild(std::move(content_layer)); |
| 4885 | scroll_clip_layer->test_properties()->AddChild(std::move(scroll_layer)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4886 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4887 | scroll_clip_layer->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4888 | host_impl_->active_tree()->SetRootLayerForTesting( |
| 4889 | std::move(scroll_clip_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4890 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 4891 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 4892 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 4893 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4894 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4895 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4896 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4897 | InputHandler::WHEEL) |
| 4898 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4899 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
| 4900 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4901 | EXPECT_TRUE(did_request_redraw_); |
| 4902 | EXPECT_TRUE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4903 | } |
| 4904 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4905 | TEST_F(LayerTreeHostImplTest, ScrollChildCallsCommitAndRedraw) { |
| 4906 | gfx::Size surface_size(10, 10); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4907 | gfx::Size contents_size(20, 20); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4908 | std::unique_ptr<LayerImpl> root = |
| 4909 | LayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4910 | root->SetBounds(surface_size); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4911 | root->test_properties()->AddChild( |
| 4912 | CreateScrollableLayer(2, contents_size, root.get())); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4913 | root->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4914 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4915 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 4916 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 4917 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 4918 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4919 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4920 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4921 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4922 | InputHandler::WHEEL) |
| 4923 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 4924 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
| 4925 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4926 | EXPECT_TRUE(did_request_redraw_); |
| 4927 | EXPECT_TRUE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4928 | } |
| 4929 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4930 | TEST_F(LayerTreeHostImplTest, ScrollMissesChild) { |
| 4931 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4932 | std::unique_ptr<LayerImpl> root = |
| 4933 | LayerImpl::Create(host_impl_->active_tree(), 1); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4934 | root->test_properties()->AddChild( |
| 4935 | CreateScrollableLayer(2, surface_size, root.get())); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4936 | root->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4937 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4938 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 4939 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 4940 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 4941 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4942 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4943 | // Scroll event is ignored because the input coordinate is outside the layer |
| 4944 | // boundaries. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4945 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 4946 | BeginState(gfx::Point(15, 5)).get(), InputHandler::WHEEL); |
| 4947 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 4948 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4949 | status.main_thread_scrolling_reasons); |
| 4950 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4951 | EXPECT_FALSE(did_request_redraw_); |
| 4952 | EXPECT_FALSE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4953 | } |
| 4954 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4955 | TEST_F(LayerTreeHostImplTest, ScrollMissesBackfacingChild) { |
| 4956 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4957 | std::unique_ptr<LayerImpl> root = |
| 4958 | LayerImpl::Create(host_impl_->active_tree(), 1); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4959 | root->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4960 | std::unique_ptr<LayerImpl> child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4961 | CreateScrollableLayer(2, surface_size, root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4962 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4963 | gfx::Transform matrix; |
| 4964 | matrix.RotateAboutXAxis(180.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 4965 | child->test_properties()->transform = matrix; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4966 | child->test_properties()->double_sided = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4967 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 4968 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 4969 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 4970 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 4971 | |
| 4972 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 4973 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4974 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4975 | // Scroll event is ignored because the scrollable layer is not facing the |
| 4976 | // viewer and there is nothing scrollable behind it. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4977 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 4978 | BeginState(gfx::Point(5, 5)).get(), InputHandler::WHEEL); |
| 4979 | EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 4980 | EXPECT_EQ(MainThreadScrollingReason::kNoScrollingLayer, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4981 | status.main_thread_scrolling_reasons); |
| 4982 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4983 | EXPECT_FALSE(did_request_redraw_); |
| 4984 | EXPECT_FALSE(did_request_commit_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4985 | } |
| 4986 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 4987 | TEST_F(LayerTreeHostImplTest, ScrollBlockedByContentLayer) { |
| 4988 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4989 | std::unique_ptr<LayerImpl> clip_layer = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4990 | LayerImpl::Create(host_impl_->active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4991 | std::unique_ptr<LayerImpl> content_layer = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4992 | CreateScrollableLayer(1, surface_size, clip_layer.get()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 4993 | content_layer->set_main_thread_scrolling_reasons( |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 4994 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4995 | content_layer->SetScrollClipLayer(Layer::INVALID_ID); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4996 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 4997 | // Note: we can use the same clip layer for both since both calls to |
| 4998 | // CreateScrollableLayer() use the same surface size. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4999 | std::unique_ptr<LayerImpl> scroll_layer = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5000 | CreateScrollableLayer(2, surface_size, clip_layer.get()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5001 | scroll_layer->test_properties()->AddChild(std::move(content_layer)); |
| 5002 | clip_layer->test_properties()->AddChild(std::move(scroll_layer)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5003 | clip_layer->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5004 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5005 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(clip_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5006 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 5007 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 5008 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5009 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5010 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5011 | // Scrolling fails because the content layer is asking to be scrolled on the |
| 5012 | // main thread. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5013 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 5014 | BeginState(gfx::Point(5, 5)).get(), InputHandler::WHEEL); |
| 5015 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 5016 | EXPECT_EQ(MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5017 | status.main_thread_scrolling_reasons); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5018 | } |
| 5019 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5020 | TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnMainThread) { |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5021 | gfx::Size viewport_size(20, 20); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5022 | float page_scale = 2.f; |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5023 | |
| 5024 | SetupScrollAndContentsLayers(viewport_size); |
| 5025 | |
| 5026 | // Setup the layers so that the outer viewport is scrollable. |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 5027 | host_impl_->active_tree() |
| 5028 | ->InnerViewportScrollLayer() |
| 5029 | ->test_properties() |
| 5030 | ->parent->SetBounds(viewport_size); |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5031 | host_impl_->active_tree()->OuterViewportScrollLayer()->SetBounds( |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5032 | gfx::Size(40, 40)); |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5033 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5034 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5035 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5036 | LayerImpl* root_scroll = |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5037 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5038 | LayerImpl* inner_scroll = |
| 5039 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 5040 | EXPECT_EQ(viewport_size, root_scroll->scroll_clip_layer()->bounds()); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 5041 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5042 | gfx::Vector2d scroll_delta(0, 10); |
| 5043 | gfx::Vector2d expected_scroll_delta = scroll_delta; |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5044 | gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset(); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5045 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5046 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5047 | InputHandler::WHEEL) |
| 5048 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5049 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5050 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5051 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5052 | // Set new page scale from main thread. |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5053 | host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f, 2.f); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5054 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5055 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 5056 | host_impl_->ProcessScrollDeltas(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5057 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), inner_scroll->id(), |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5058 | expected_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5059 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5060 | // The scroll range should also have been updated. |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5061 | EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5062 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5063 | // The page scale delta remains constant because the impl thread did not |
| 5064 | // scale. |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5065 | EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5066 | } |
| 5067 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5068 | TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnImplThread) { |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5069 | gfx::Size viewport_size(20, 20); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5070 | float page_scale = 2.f; |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5071 | |
| 5072 | SetupScrollAndContentsLayers(viewport_size); |
| 5073 | |
| 5074 | // Setup the layers so that the outer viewport is scrollable. |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 5075 | host_impl_->active_tree() |
| 5076 | ->InnerViewportScrollLayer() |
| 5077 | ->test_properties() |
| 5078 | ->parent->SetBounds(viewport_size); |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5079 | host_impl_->active_tree()->OuterViewportScrollLayer()->SetBounds( |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5080 | gfx::Size(40, 40)); |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5081 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5082 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 5083 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5084 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5085 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5086 | LayerImpl* root_scroll = |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 5087 | host_impl_->active_tree()->OuterViewportScrollLayer(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5088 | LayerImpl* inner_scroll = |
| 5089 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 5090 | EXPECT_EQ(viewport_size, root_scroll->scroll_clip_layer()->bounds()); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 5091 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5092 | gfx::Vector2d scroll_delta(0, 10); |
| 5093 | gfx::Vector2d expected_scroll_delta = scroll_delta; |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5094 | gfx::ScrollOffset expected_max_scroll = root_scroll->MaxScrollOffset(); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5095 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5096 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5097 | InputHandler::WHEEL) |
| 5098 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5099 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5100 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5101 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5102 | // Set new page scale on impl thread by pinching. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5103 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5104 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5105 | host_impl_->PinchGestureBegin(); |
| 5106 | host_impl_->PinchGestureUpdate(page_scale, gfx::Point()); |
| 5107 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5108 | host_impl_->ScrollEnd(EndState().get()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5109 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5110 | DrawOneFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5111 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5112 | // The scroll delta is not scaled because the main thread did not scale. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5113 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 5114 | host_impl_->ProcessScrollDeltas(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5115 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), inner_scroll->id(), |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5116 | expected_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5117 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5118 | // The scroll range should also have been updated. |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5119 | EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5120 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5121 | // The page scale delta should match the new scale on the impl side. |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 5122 | EXPECT_EQ(page_scale, host_impl_->active_tree()->current_page_scale_factor()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5123 | } |
| 5124 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5125 | TEST_F(LayerTreeHostImplTest, PageScaleDeltaAppliedToRootScrollLayerOnly) { |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 5126 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5127 | gfx::Size surface_size(10, 10); |
| 5128 | float default_page_scale = 1.f; |
| 5129 | gfx::Transform default_page_scale_matrix; |
[email protected] | 3209161d | 2013-03-29 19:17:34 | [diff] [blame] | 5130 | default_page_scale_matrix.Scale(default_page_scale, default_page_scale); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 5131 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5132 | float new_page_scale = 2.f; |
| 5133 | gfx::Transform new_page_scale_matrix; |
| 5134 | new_page_scale_matrix.Scale(new_page_scale, new_page_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5135 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5136 | // Create a normal scrollable root layer and another scrollable child layer. |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5137 | LayerImpl* scroll = SetupScrollAndContentsLayers(surface_size); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 5138 | scroll->SetDrawsContent(true); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5139 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 5140 | LayerImpl* child = scroll->test_properties()->children[0]; |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 5141 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5142 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5143 | std::unique_ptr<LayerImpl> scrollable_child_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5144 | LayerImpl::Create(host_impl_->active_tree(), 6); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5145 | std::unique_ptr<LayerImpl> scrollable_child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5146 | CreateScrollableLayer(7, surface_size, scrollable_child_clip.get()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5147 | scrollable_child_clip->test_properties()->AddChild( |
| 5148 | std::move(scrollable_child)); |
| 5149 | child->test_properties()->AddChild(std::move(scrollable_child_clip)); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 5150 | LayerImpl* grand_child = child->test_properties()->children[0]; |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 5151 | grand_child->SetDrawsContent(true); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5152 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5153 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5154 | // Set new page scale on impl thread by pinching. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5155 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5156 | InputHandler::TOUCHSCREEN); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5157 | host_impl_->PinchGestureBegin(); |
| 5158 | host_impl_->PinchGestureUpdate(new_page_scale, gfx::Point()); |
| 5159 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5160 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5161 | DrawOneFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5162 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5163 | // Make sure all the layers are drawn with the page scale delta applied, i.e., |
| 5164 | // the page scale delta on the root layer is applied hierarchically. |
| 5165 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5166 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 5167 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5168 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5169 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5170 | EXPECT_EQ(1.f, root->DrawTransform().matrix().getDouble(0, 0)); |
| 5171 | EXPECT_EQ(1.f, root->DrawTransform().matrix().getDouble(1, 1)); |
| 5172 | EXPECT_EQ(new_page_scale, scroll->DrawTransform().matrix().getDouble(0, 0)); |
| 5173 | EXPECT_EQ(new_page_scale, scroll->DrawTransform().matrix().getDouble(1, 1)); |
| 5174 | EXPECT_EQ(new_page_scale, child->DrawTransform().matrix().getDouble(0, 0)); |
| 5175 | EXPECT_EQ(new_page_scale, child->DrawTransform().matrix().getDouble(1, 1)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5176 | EXPECT_EQ(new_page_scale, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5177 | grand_child->DrawTransform().matrix().getDouble(0, 0)); |
[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(1, 1)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5180 | } |
| 5181 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5182 | TEST_F(LayerTreeHostImplTest, ScrollChildAndChangePageScaleOnMainThread) { |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5183 | SetupScrollAndContentsLayers(gfx::Size(30, 30)); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 5184 | |
| 5185 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5186 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 5187 | |
| 5188 | // Make the outer scroll layer scrollable. |
| 5189 | outer_scroll->SetBounds(gfx::Size(50, 50)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5190 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 5191 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5192 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5193 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5194 | gfx::Vector2d scroll_delta(0, 10); |
| 5195 | gfx::Vector2d expected_scroll_delta(scroll_delta); |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 5196 | gfx::ScrollOffset expected_max_scroll(outer_scroll->MaxScrollOffset()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5197 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5198 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5199 | InputHandler::WHEEL) |
| 5200 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5201 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5202 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5203 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5204 | float page_scale = 2.f; |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 5205 | host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5206 | page_scale); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5207 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5208 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5209 | DrawOneFrame(); |
[email protected] | 1c0c9bc | 2012-10-08 22:41:48 | [diff] [blame] | 5210 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5211 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 5212 | host_impl_->ProcessScrollDeltas(); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 5213 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), inner_scroll->id(), |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5214 | expected_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5215 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5216 | // The scroll range should not have changed. |
bokan | f553cb3b | 2015-07-23 18:54:05 | [diff] [blame] | 5217 | EXPECT_EQ(outer_scroll->MaxScrollOffset(), expected_max_scroll); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5218 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5219 | // The page scale delta remains constant because the impl thread did not |
| 5220 | // scale. |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5221 | EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5222 | } |
| 5223 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5224 | TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { |
| 5225 | // Scroll a child layer beyond its maximum scroll range and make sure the |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 5226 | // parent layer isn't scrolled. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5227 | gfx::Size surface_size(10, 10); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5228 | gfx::Size content_size(20, 20); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5229 | std::unique_ptr<LayerImpl> root = |
| 5230 | LayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5231 | root->SetBounds(surface_size); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5232 | root->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5233 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5234 | CreateScrollableLayer(3, content_size, root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5235 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5236 | std::unique_ptr<LayerImpl> child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5237 | CreateScrollableLayer(2, content_size, root.get()); |
| 5238 | LayerImpl* grand_child_layer = grand_child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5239 | child->test_properties()->AddChild(std::move(grand_child)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5240 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5241 | LayerImpl* child_layer = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5242 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5243 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5244 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5245 | host_impl_->active_tree()->DidBecomeActive(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5246 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5247 | grand_child_layer->layer_tree_impl() |
| 5248 | ->property_trees() |
| 5249 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(grand_child_layer->id(), |
| 5250 | gfx::ScrollOffset(0, 5)); |
| 5251 | child_layer->layer_tree_impl() |
| 5252 | ->property_trees() |
| 5253 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(child_layer->id(), |
| 5254 | gfx::ScrollOffset(3, 0)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5255 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5256 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5257 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5258 | { |
| 5259 | gfx::Vector2d scroll_delta(-8, -7); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5260 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5261 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5262 | InputHandler::WHEEL) |
| 5263 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5264 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5265 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5266 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5267 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5268 | host_impl_->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5269 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5270 | // The grand child should have scrolled up to its limit. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5271 | LayerImpl* child = host_impl_->active_tree() |
| 5272 | ->root_layer_for_testing() |
| 5273 | ->test_properties() |
| 5274 | ->children[0]; |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 5275 | LayerImpl* grand_child = child->test_properties()->children[0]; |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5276 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 5277 | gfx::Vector2d(0, -5))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5278 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 5279 | // The child should not have scrolled. |
| 5280 | ExpectNone(*scroll_info.get(), child->id()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5281 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5282 | } |
| 5283 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5284 | TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { |
| 5285 | // Scroll a child layer beyond its maximum scroll range and make sure the |
| 5286 | // the scroll doesn't bubble up to the parent layer. |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5287 | gfx::Size surface_size(20, 20); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 5288 | gfx::Size viewport_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5289 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5290 | LayerImpl::Create(host_impl_->active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5291 | std::unique_ptr<LayerImpl> root_clip = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5292 | LayerImpl::Create(host_impl_->active_tree(), 2); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5293 | root_clip->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5294 | std::unique_ptr<LayerImpl> root_scrolling = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5295 | CreateScrollableLayer(3, surface_size, root_clip.get()); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 5296 | root_scrolling->test_properties()->is_container_for_fixed_position_layers = |
| 5297 | true; |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5298 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5299 | std::unique_ptr<LayerImpl> grand_child = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5300 | CreateScrollableLayer(5, surface_size, root_clip.get()); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5301 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5302 | std::unique_ptr<LayerImpl> child = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5303 | CreateScrollableLayer(4, surface_size, root_clip.get()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5304 | LayerImpl* grand_child_layer = grand_child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5305 | child->test_properties()->AddChild(std::move(grand_child)); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5306 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5307 | LayerImpl* child_layer = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5308 | root_scrolling->test_properties()->AddChild(std::move(child)); |
| 5309 | root_clip->test_properties()->AddChild(std::move(root_scrolling)); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5310 | EXPECT_EQ(viewport_size, root_clip->bounds()); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5311 | root_ptr->test_properties()->AddChild(std::move(root_clip)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5312 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5313 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5314 | host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3, |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 5315 | Layer::INVALID_ID); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5316 | host_impl_->active_tree()->DidBecomeActive(); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 5317 | host_impl_->SetViewportSize(viewport_size); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5318 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5319 | grand_child_layer->layer_tree_impl() |
| 5320 | ->property_trees() |
| 5321 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(grand_child_layer->id(), |
| 5322 | gfx::ScrollOffset(0, 2)); |
| 5323 | child_layer->layer_tree_impl() |
| 5324 | ->property_trees() |
| 5325 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(child_layer->id(), |
| 5326 | gfx::ScrollOffset(0, 3)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5327 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5328 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5329 | { |
| 5330 | gfx::Vector2d scroll_delta(0, -10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5331 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5332 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5333 | InputHandler::NON_BUBBLING_GESTURE) |
| 5334 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5335 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5336 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5337 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5338 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5339 | host_impl_->ProcessScrollDeltas(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5340 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5341 | // The grand child should have scrolled up to its limit. |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5342 | LayerImpl* child = host_impl_->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5343 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 5344 | ->test_properties() |
| 5345 | ->children[0] |
| 5346 | ->test_properties() |
| 5347 | ->children[0] |
| 5348 | ->test_properties() |
| 5349 | ->children[0]; |
| 5350 | LayerImpl* grand_child = child->test_properties()->children[0]; |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5351 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 5352 | gfx::Vector2d(0, -2))); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5353 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5354 | // The child should not have scrolled. |
| 5355 | ExpectNone(*scroll_info.get(), child->id()); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5356 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5357 | // The next time we scroll we should only scroll the parent. |
| 5358 | scroll_delta = gfx::Vector2d(0, -3); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5359 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5360 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5361 | InputHandler::NON_BUBBLING_GESTURE) |
| 5362 | .thread); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5363 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5364 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5365 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5366 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5367 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5368 | scroll_info = host_impl_->ProcessScrollDeltas(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5369 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5370 | // The child should have scrolled up to its limit. |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5371 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child->id(), |
| 5372 | gfx::Vector2d(0, -3))); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5373 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5374 | // The grand child should not have scrolled. |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5375 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 5376 | gfx::Vector2d(0, -2))); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5377 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5378 | // After scrolling the parent, another scroll on the opposite direction |
| 5379 | // should still scroll the child. |
| 5380 | scroll_delta = gfx::Vector2d(0, 7); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5381 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5382 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5383 | InputHandler::NON_BUBBLING_GESTURE) |
| 5384 | .thread); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5385 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5386 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
[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_->ScrollEnd(EndState().get()); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5389 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5390 | scroll_info = host_impl_->ProcessScrollDeltas(); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5391 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5392 | // The grand child should have scrolled. |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5393 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 5394 | gfx::Vector2d(0, 5))); |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5395 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5396 | // The child should not have scrolled. |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5397 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child->id(), |
| 5398 | gfx::Vector2d(0, -3))); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 5399 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5400 | // Scrolling should be adjusted from viewport space. |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 5401 | host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 2.f, 2.f); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 5402 | host_impl_->active_tree()->SetPageScaleOnActiveTree(2.f); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 5403 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5404 | scroll_delta = gfx::Vector2d(0, -2); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5405 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5406 | host_impl_->ScrollBegin(BeginState(gfx::Point(1, 1)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5407 | InputHandler::NON_BUBBLING_GESTURE) |
| 5408 | .thread); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5409 | EXPECT_EQ(grand_child, host_impl_->CurrentlyScrollingLayer()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5410 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5411 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 5412 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5413 | scroll_info = host_impl_->ProcessScrollDeltas(); |
[email protected] | f493727 | 2013-02-07 05:54:50 | [diff] [blame] | 5414 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5415 | // Should have scrolled by half the amount in layer space (5 - 2/2) |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5416 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 5417 | gfx::Vector2d(0, 4))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5418 | } |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 5419 | } |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5420 | TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) { |
| 5421 | // When we try to scroll a non-scrollable child layer, the scroll delta |
| 5422 | // should be applied to one of its ancestors if possible. |
| 5423 | gfx::Size surface_size(10, 10); |
| 5424 | gfx::Size content_size(20, 20); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5425 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5426 | LayerImpl::Create(host_impl_->active_tree(), 4); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5427 | std::unique_ptr<LayerImpl> root_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5428 | LayerImpl::Create(host_impl_->active_tree(), 3); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5429 | root_clip->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5430 | std::unique_ptr<LayerImpl> root_scroll = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5431 | CreateScrollableLayer(1, content_size, root_clip.get()); |
| 5432 | // Make 'root' the clip layer for child: since they have the same sizes the |
| 5433 | // child will have zero max_scroll_offset and scrolls will bubble. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5434 | std::unique_ptr<LayerImpl> child = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5435 | CreateScrollableLayer(2, content_size, root_scroll.get()); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 5436 | child->test_properties()->is_container_for_fixed_position_layers = true; |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5437 | root_scroll->SetBounds(content_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5438 | |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5439 | int root_scroll_id = root_scroll->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5440 | root_scroll->test_properties()->AddChild(std::move(child)); |
| 5441 | root_clip->test_properties()->AddChild(std::move(root_scroll)); |
| 5442 | root_ptr->test_properties()->AddChild(std::move(root_clip)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5443 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5444 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5445 | host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 2, |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 5446 | Layer::INVALID_ID); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5447 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5448 | host_impl_->active_tree()->DidBecomeActive(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5449 | |
| 5450 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5451 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5452 | { |
| 5453 | gfx::Vector2d scroll_delta(0, 4); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5454 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5455 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5456 | InputHandler::WHEEL) |
| 5457 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5458 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5459 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5460 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5461 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5462 | host_impl_->ProcessScrollDeltas(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5463 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5464 | // Only the root scroll should have scrolled. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5465 | ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5466 | EXPECT_TRUE( |
| 5467 | ScrollInfoContains(*scroll_info.get(), root_scroll_id, scroll_delta)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5468 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5469 | } |
| 5470 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5471 | TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { |
| 5472 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5473 | std::unique_ptr<LayerImpl> root_ptr = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5474 | LayerImpl::Create(host_impl_->active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5475 | std::unique_ptr<LayerImpl> root_clip = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5476 | LayerImpl::Create(host_impl_->active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5477 | std::unique_ptr<LayerImpl> root_scroll = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5478 | CreateScrollableLayer(3, surface_size, root_clip.get()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5479 | root_clip->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 5480 | root_scroll->test_properties()->is_container_for_fixed_position_layers = true; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5481 | root_clip->test_properties()->AddChild(std::move(root_scroll)); |
| 5482 | root_ptr->test_properties()->AddChild(std::move(root_clip)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5483 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5484 | host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3, |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 5485 | Layer::INVALID_ID); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5486 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5487 | host_impl_->active_tree()->DidBecomeActive(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5488 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 5489 | host_impl_->SetViewportSize(surface_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5490 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5491 | // Draw one frame and then immediately rebuild the layer tree to mimic a tree |
| 5492 | // synchronization. |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5493 | DrawFrame(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5494 | |
rockot | 2176f92 | 2016-06-08 19:18:32 | [diff] [blame] | 5495 | host_impl_->active_tree()->DetachLayers(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5496 | std::unique_ptr<LayerImpl> root_ptr2 = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5497 | LayerImpl::Create(host_impl_->active_tree(), 4); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5498 | std::unique_ptr<LayerImpl> root_clip2 = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5499 | LayerImpl::Create(host_impl_->active_tree(), 5); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5500 | std::unique_ptr<LayerImpl> root_scroll2 = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5501 | CreateScrollableLayer(6, surface_size, root_clip2.get()); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 5502 | root_scroll2->test_properties()->is_container_for_fixed_position_layers = |
| 5503 | true; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5504 | root_clip2->test_properties()->AddChild(std::move(root_scroll2)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 5505 | root_clip2->test_properties()->force_render_surface = true; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5506 | root_ptr2->test_properties()->AddChild(std::move(root_clip2)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 5507 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr2)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5508 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 5509 | host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 6, |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 5510 | Layer::INVALID_ID); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5511 | host_impl_->active_tree()->DidBecomeActive(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5512 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5513 | // Scrolling should still work even though we did not draw yet. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5514 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5515 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5516 | InputHandler::WHEEL) |
| 5517 | .thread); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5518 | } |
| 5519 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5520 | TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5521 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 5522 | scroll_layer->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5523 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5524 | // Rotate the root layer 90 degrees counter-clockwise about its center. |
| 5525 | gfx::Transform rotate_transform; |
| 5526 | rotate_transform.Rotate(-90.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5527 | host_impl_->active_tree() |
| 5528 | ->root_layer_for_testing() |
| 5529 | ->test_properties() |
| 5530 | ->transform = rotate_transform; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5531 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5532 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5533 | gfx::Size surface_size(50, 50); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 5534 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5535 | DrawFrame(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5536 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5537 | // Scroll to the right in screen coordinates with a gesture. |
| 5538 | gfx::Vector2d gesture_scroll_delta(10, 0); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5539 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5540 | host_impl_ |
| 5541 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 5542 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5543 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5544 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gesture_scroll_delta).get()); |
| 5545 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5546 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5547 | // The layer should have scrolled down in its local coordinates. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5548 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 5549 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5550 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), scroll_layer->id(), |
| 5551 | gfx::Vector2d(0, gesture_scroll_delta.x()))); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5552 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5553 | // Reset and scroll down with the wheel. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5554 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5555 | gfx::Vector2d wheel_scroll_delta(0, 10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5556 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5557 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5558 | InputHandler::WHEEL) |
| 5559 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5560 | host_impl_->ScrollBy(UpdateState(gfx::Point(), wheel_scroll_delta).get()); |
| 5561 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5562 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5563 | // The layer should have scrolled down in its local coordinates. |
| 5564 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5565 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), scroll_layer->id(), |
| 5566 | wheel_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5567 | } |
| 5568 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5569 | TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5570 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5571 | int child_clip_layer_id = 6; |
| 5572 | int child_layer_id = 7; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5573 | float child_layer_angle = -20.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5574 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5575 | // Create a child layer that is rotated to a non-axis-aligned angle. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5576 | std::unique_ptr<LayerImpl> clip_layer = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5577 | LayerImpl::Create(host_impl_->active_tree(), child_clip_layer_id); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5578 | std::unique_ptr<LayerImpl> child = CreateScrollableLayer( |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 5579 | child_layer_id, scroll_layer->bounds(), clip_layer.get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5580 | gfx::Transform rotate_transform; |
| 5581 | rotate_transform.Translate(-50.0, -50.0); |
| 5582 | rotate_transform.Rotate(child_layer_angle); |
| 5583 | rotate_transform.Translate(50.0, 50.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5584 | clip_layer->test_properties()->transform = rotate_transform; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5585 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5586 | // Only allow vertical scrolling. |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5587 | clip_layer->SetBounds( |
| 5588 | gfx::Size(child->bounds().width(), child->bounds().height() / 2)); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5589 | // The rotation depends on the layer's transform origin, and the child layer |
| 5590 | // is a different size than the clip, so make sure the clip layer's origin |
| 5591 | // lines up over the child. |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 5592 | clip_layer->test_properties()->transform_origin = gfx::Point3F( |
| 5593 | clip_layer->bounds().width() * 0.5f, clip_layer->bounds().height(), 0.f); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5594 | LayerImpl* child_ptr = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5595 | clip_layer->test_properties()->AddChild(std::move(child)); |
| 5596 | scroll_layer->test_properties()->AddChild(std::move(clip_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5597 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5598 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5599 | gfx::Size surface_size(50, 50); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 5600 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5601 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5602 | { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5603 | // Scroll down in screen coordinates with a gesture. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5604 | gfx::Vector2d gesture_scroll_delta(0, 10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5605 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5606 | host_impl_ |
| 5607 | ->ScrollBegin(BeginState(gfx::Point(1, 1)).get(), |
| 5608 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5609 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5610 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gesture_scroll_delta).get()); |
| 5611 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5612 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5613 | // The child layer should have scrolled down in its local coordinates an |
| 5614 | // amount proportional to the angle between it and the input scroll delta. |
miletus | d799dd2 | 2015-03-19 04:23:17 | [diff] [blame] | 5615 | gfx::Vector2d expected_scroll_delta( |
miletus | 7a22175 | 2015-02-04 20:44:49 | [diff] [blame] | 5616 | 0, gesture_scroll_delta.y() * |
| 5617 | std::cos(MathUtil::Deg2Rad(child_layer_angle))); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5618 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5619 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5620 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child_layer_id, |
| 5621 | expected_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5622 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5623 | // The root scroll layer should not have scrolled, because the input delta |
| 5624 | // was close to the layer's axis of movement. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5625 | EXPECT_EQ(scroll_info->scrolls.size(), 1u); |
| 5626 | } |
| 5627 | { |
| 5628 | // Now reset and scroll the same amount horizontally. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5629 | SetScrollOffsetDelta(child_ptr, gfx::Vector2dF()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5630 | gfx::Vector2d gesture_scroll_delta(10, 0); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5631 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5632 | host_impl_ |
| 5633 | ->ScrollBegin(BeginState(gfx::Point(1, 1)).get(), |
| 5634 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5635 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5636 | host_impl_->ScrollBy(UpdateState(gfx::Point(), gesture_scroll_delta).get()); |
| 5637 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5638 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 5639 | // The child layer shouldn't have scrolled. |
miletus | d799dd2 | 2015-03-19 04:23:17 | [diff] [blame] | 5640 | gfx::Vector2d expected_scroll_delta( |
miletus | 7a22175 | 2015-02-04 20:44:49 | [diff] [blame] | 5641 | 0, -gesture_scroll_delta.x() * |
| 5642 | std::sin(MathUtil::Deg2Rad(child_layer_angle))); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5643 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5644 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5645 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child_layer_id, |
| 5646 | expected_scroll_delta)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5647 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 5648 | // The root scroll layer shouldn't have scrolled. |
| 5649 | ExpectNone(*scroll_info.get(), scroll_layer->id()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5650 | } |
| 5651 | } |
| 5652 | |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5653 | TEST_F(LayerTreeHostImplTest, ScrollPerspectiveTransformedLayer) { |
| 5654 | // When scrolling an element with perspective, the distance scrolled |
| 5655 | // depends on the point at which the scroll begins. |
| 5656 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 5657 | int child_clip_layer_id = 6; |
| 5658 | int child_layer_id = 7; |
| 5659 | |
| 5660 | // Create a child layer that is rotated on its x axis, with perspective. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5661 | std::unique_ptr<LayerImpl> clip_layer = |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5662 | LayerImpl::Create(host_impl_->active_tree(), child_clip_layer_id); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5663 | std::unique_ptr<LayerImpl> child = CreateScrollableLayer( |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5664 | child_layer_id, scroll_layer->bounds(), clip_layer.get()); |
| 5665 | LayerImpl* child_ptr = child.get(); |
| 5666 | gfx::Transform perspective_transform; |
| 5667 | perspective_transform.Translate(-50.0, -50.0); |
| 5668 | perspective_transform.ApplyPerspectiveDepth(20); |
| 5669 | perspective_transform.RotateAboutXAxis(45); |
| 5670 | perspective_transform.Translate(50.0, 50.0); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5671 | clip_layer->test_properties()->transform = perspective_transform; |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5672 | |
| 5673 | clip_layer->SetBounds(gfx::Size(child_ptr->bounds().width() / 2, |
| 5674 | child_ptr->bounds().height() / 2)); |
| 5675 | // The transform depends on the layer's transform origin, and the child layer |
| 5676 | // is a different size than the clip, so make sure the clip layer's origin |
| 5677 | // lines up over the child. |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 5678 | clip_layer->test_properties()->transform_origin = gfx::Point3F( |
| 5679 | clip_layer->bounds().width(), clip_layer->bounds().height(), 0.f); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 5680 | clip_layer->test_properties()->AddChild(std::move(child)); |
| 5681 | scroll_layer->test_properties()->AddChild(std::move(clip_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5682 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5683 | |
| 5684 | gfx::Size surface_size(50, 50); |
| 5685 | host_impl_->SetViewportSize(surface_size); |
| 5686 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5687 | std::unique_ptr<ScrollAndScaleSet> scroll_info; |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5688 | |
| 5689 | gfx::Vector2d gesture_scroll_deltas[4]; |
| 5690 | gesture_scroll_deltas[0] = gfx::Vector2d(4, 10); |
| 5691 | gesture_scroll_deltas[1] = gfx::Vector2d(4, 10); |
| 5692 | gesture_scroll_deltas[2] = gfx::Vector2d(10, 0); |
| 5693 | gesture_scroll_deltas[3] = gfx::Vector2d(10, 0); |
| 5694 | |
| 5695 | gfx::Vector2d expected_scroll_deltas[4]; |
| 5696 | // Perspective affects the vertical delta by a different |
| 5697 | // amount depending on the vertical position of the |viewport_point|. |
| 5698 | expected_scroll_deltas[0] = gfx::Vector2d(2, 8); |
| 5699 | expected_scroll_deltas[1] = gfx::Vector2d(1, 4); |
| 5700 | // Deltas which start with the same vertical position of the |
| 5701 | // |viewport_point| are subject to identical perspective effects. |
| 5702 | expected_scroll_deltas[2] = gfx::Vector2d(4, 0); |
| 5703 | expected_scroll_deltas[3] = gfx::Vector2d(4, 0); |
| 5704 | |
| 5705 | gfx::Point viewport_point(1, 1); |
| 5706 | |
| 5707 | // Scroll in screen coordinates with a gesture. Each scroll starts |
| 5708 | // where the previous scroll ended, but the scroll position is reset |
| 5709 | // for each scroll. |
| 5710 | for (int i = 0; i < 4; ++i) { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5711 | SetScrollOffsetDelta(child_ptr, gfx::Vector2dF()); |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5712 | DrawFrame(); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5713 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5714 | host_impl_ |
| 5715 | ->ScrollBegin(BeginState(viewport_point).get(), |
| 5716 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5717 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5718 | host_impl_->ScrollBy( |
| 5719 | UpdateState(viewport_point, gesture_scroll_deltas[i]).get()); |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5720 | viewport_point += gesture_scroll_deltas[i]; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5721 | host_impl_->ScrollEnd(EndState().get()); |
tdresser | e8575f59 | 2015-07-03 12:53:13 | [diff] [blame] | 5722 | |
| 5723 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 5724 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child_layer_id, |
| 5725 | expected_scroll_deltas[i])); |
| 5726 | |
| 5727 | // The root scroll layer should not have scrolled, because the input delta |
| 5728 | // was close to the layer's axis of movement. |
| 5729 | EXPECT_EQ(scroll_info->scrolls.size(), 1u); |
| 5730 | } |
| 5731 | } |
| 5732 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5733 | TEST_F(LayerTreeHostImplTest, ScrollScaledLayer) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5734 | LayerImpl* scroll_layer = |
| 5735 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5736 | |
| 5737 | // Scale the layer to twice its normal size. |
| 5738 | int scale = 2; |
| 5739 | gfx::Transform scale_transform; |
| 5740 | scale_transform.Scale(scale, scale); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 5741 | scroll_layer->test_properties()->parent->test_properties()->transform = |
| 5742 | scale_transform; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5743 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5744 | |
| 5745 | gfx::Size surface_size(50, 50); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 5746 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 5747 | DrawFrame(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5748 | |
| 5749 | // Scroll down in screen coordinates with a gesture. |
| 5750 | gfx::Vector2d scroll_delta(0, 10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5751 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5752 | host_impl_ |
| 5753 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 5754 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5755 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5756 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5757 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5758 | |
| 5759 | // The layer should have scrolled down in its local coordinates, but half the |
| 5760 | // amount. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5761 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 5762 | host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5763 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), scroll_layer->id(), |
| 5764 | gfx::Vector2d(0, scroll_delta.y() / scale))); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5765 | |
| 5766 | // Reset and scroll down with the wheel. |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5767 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5768 | gfx::Vector2d wheel_scroll_delta(0, 10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5769 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5770 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5771 | InputHandler::WHEEL) |
| 5772 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5773 | host_impl_->ScrollBy(UpdateState(gfx::Point(), wheel_scroll_delta).get()); |
| 5774 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 5775 | |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 5776 | // 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] | 5777 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 5778 | EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), scroll_layer->id(), |
| 5779 | wheel_scroll_delta)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5780 | } |
| 5781 | |
[email protected] | a6d2ffe82 | 2014-08-21 10:11:39 | [diff] [blame] | 5782 | TEST_F(LayerTreeHostImplTest, ScrollViewportRounding) { |
| 5783 | int width = 332; |
| 5784 | int height = 20; |
| 5785 | int scale = 3; |
| 5786 | SetupScrollAndContentsLayers(gfx::Size(width, height)); |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 5787 | host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( |
| 5788 | gfx::Size(width * scale - 1, height * scale)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5789 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 5790 | |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 5791 | host_impl_->active_tree()->SetDeviceScaleFactor(scale); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 5792 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
[email protected] | a6d2ffe82 | 2014-08-21 10:11:39 | [diff] [blame] | 5793 | |
| 5794 | LayerImpl* inner_viewport_scroll_layer = |
| 5795 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5796 | EXPECT_EQ(gfx::ScrollOffset(0, 0), |
[email protected] | a6d2ffe82 | 2014-08-21 10:11:39 | [diff] [blame] | 5797 | inner_viewport_scroll_layer->MaxScrollOffset()); |
| 5798 | } |
| 5799 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5800 | class TestInputHandlerClient : public InputHandlerClient { |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5801 | public: |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5802 | TestInputHandlerClient() |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 5803 | : page_scale_factor_(0.f), |
| 5804 | min_page_scale_factor_(-1.f), |
danakj | e9f830c | 2015-09-09 21:36:16 | [diff] [blame] | 5805 | max_page_scale_factor_(-1.f) {} |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5806 | ~TestInputHandlerClient() override {} |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5807 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5808 | // InputHandlerClient implementation. |
| 5809 | void WillShutdown() override {} |
| 5810 | void Animate(base::TimeTicks time) override {} |
| 5811 | void MainThreadHasStoppedFlinging() override {} |
| 5812 | void ReconcileElasticOverscrollAndRootScroll() override {} |
| 5813 | void UpdateRootLayerStateForSynchronousInputHandler( |
| 5814 | const gfx::ScrollOffset& total_scroll_offset, |
| 5815 | const gfx::ScrollOffset& max_scroll_offset, |
| 5816 | const gfx::SizeF& scrollable_size, |
| 5817 | float page_scale_factor, |
| 5818 | float min_page_scale_factor, |
| 5819 | float max_page_scale_factor) override { |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 5820 | DCHECK(total_scroll_offset.x() <= max_scroll_offset.x()); |
| 5821 | DCHECK(total_scroll_offset.y() <= max_scroll_offset.y()); |
| 5822 | last_set_scroll_offset_ = total_scroll_offset; |
| 5823 | max_scroll_offset_ = max_scroll_offset; |
| 5824 | scrollable_size_ = scrollable_size; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5825 | page_scale_factor_ = page_scale_factor; |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 5826 | min_page_scale_factor_ = min_page_scale_factor; |
| 5827 | max_page_scale_factor_ = max_page_scale_factor; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5828 | } |
| 5829 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5830 | gfx::ScrollOffset last_set_scroll_offset() { |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5831 | return last_set_scroll_offset_; |
| 5832 | } |
| 5833 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5834 | gfx::ScrollOffset max_scroll_offset() const { |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5835 | return max_scroll_offset_; |
| 5836 | } |
| 5837 | |
| 5838 | gfx::SizeF scrollable_size() const { |
| 5839 | return scrollable_size_; |
| 5840 | } |
| 5841 | |
| 5842 | float page_scale_factor() const { |
| 5843 | return page_scale_factor_; |
| 5844 | } |
| 5845 | |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 5846 | float min_page_scale_factor() const { |
| 5847 | return min_page_scale_factor_; |
| 5848 | } |
| 5849 | |
| 5850 | float max_page_scale_factor() const { |
| 5851 | return max_page_scale_factor_; |
| 5852 | } |
| 5853 | |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5854 | private: |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5855 | gfx::ScrollOffset last_set_scroll_offset_; |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5856 | gfx::ScrollOffset max_scroll_offset_; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5857 | gfx::SizeF scrollable_size_; |
| 5858 | float page_scale_factor_; |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 5859 | float min_page_scale_factor_; |
| 5860 | float max_page_scale_factor_; |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5861 | }; |
| 5862 | |
| 5863 | TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5864 | TestInputHandlerClient scroll_watcher; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5865 | host_impl_->SetViewportSize(gfx::Size(10, 20)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5866 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 5867 | LayerImpl* clip_layer = |
| 5868 | scroll_layer->test_properties()->parent->test_properties()->parent; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 5869 | clip_layer->SetBounds(gfx::Size(10, 20)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5870 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5871 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5872 | host_impl_->BindToClient(&scroll_watcher); |
| 5873 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5874 | gfx::Vector2dF initial_scroll_delta(10.f, 10.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 5875 | scroll_layer->layer_tree_impl() |
| 5876 | ->property_trees() |
| 5877 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 5878 | gfx::ScrollOffset()); |
| 5879 | SetScrollOffsetDelta(scroll_layer, initial_scroll_delta); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5880 | |
| 5881 | EXPECT_EQ(gfx::ScrollOffset(), scroll_watcher.last_set_scroll_offset()); |
| 5882 | |
| 5883 | // Requesting an update results in the current scroll offset being set. |
| 5884 | host_impl_->RequestUpdateForSynchronousInputHandler(); |
| 5885 | EXPECT_EQ(gfx::ScrollOffset(initial_scroll_delta), |
| 5886 | scroll_watcher.last_set_scroll_offset()); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5887 | |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 5888 | // Setting the delegate results in the scrollable_size, max_scroll_offset, |
| 5889 | // page_scale_factor and {min|max}_page_scale_factor being set. |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5890 | EXPECT_EQ(gfx::SizeF(100, 100), scroll_watcher.scrollable_size()); |
| 5891 | EXPECT_EQ(gfx::ScrollOffset(90, 80), scroll_watcher.max_scroll_offset()); |
| 5892 | EXPECT_EQ(1.f, scroll_watcher.page_scale_factor()); |
| 5893 | EXPECT_EQ(1.f, scroll_watcher.min_page_scale_factor()); |
| 5894 | EXPECT_EQ(1.f, scroll_watcher.max_page_scale_factor()); |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5895 | |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 5896 | // Put a page scale on the tree. |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 5897 | host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 0.5f, 4.f); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5898 | EXPECT_EQ(1.f, scroll_watcher.page_scale_factor()); |
| 5899 | EXPECT_EQ(1.f, scroll_watcher.min_page_scale_factor()); |
| 5900 | EXPECT_EQ(1.f, scroll_watcher.max_page_scale_factor()); |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 5901 | // Activation will update the delegate. |
| 5902 | host_impl_->ActivateSyncTree(); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5903 | EXPECT_EQ(2.f, scroll_watcher.page_scale_factor()); |
| 5904 | EXPECT_EQ(.5f, scroll_watcher.min_page_scale_factor()); |
| 5905 | EXPECT_EQ(4.f, scroll_watcher.max_page_scale_factor()); |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 5906 | |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 5907 | // Animating page scale can change the root offset, so it should update the |
danakj | 492344054 | 2015-10-29 19:34:53 | [diff] [blame] | 5908 | // delegate. Also resets the page scale to 1 for the rest of the test. |
| 5909 | host_impl_->LayerTreeHostImpl::StartPageScaleAnimation( |
| 5910 | gfx::Vector2d(0, 0), false, 1.f, base::TimeDelta()); |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 5911 | host_impl_->Animate(); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5912 | EXPECT_EQ(1.f, scroll_watcher.page_scale_factor()); |
| 5913 | EXPECT_EQ(.5f, scroll_watcher.min_page_scale_factor()); |
| 5914 | EXPECT_EQ(4.f, scroll_watcher.max_page_scale_factor()); |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 5915 | |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 5916 | // The pinch gesture doesn't put the delegate into a state where the scroll |
| 5917 | // offset is outside of the scroll range. (this is verified by DCHECKs in the |
| 5918 | // delegate). |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5919 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5920 | InputHandler::TOUCHSCREEN); |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 5921 | host_impl_->PinchGestureBegin(); |
| 5922 | host_impl_->PinchGestureUpdate(2.f, gfx::Point()); |
| 5923 | host_impl_->PinchGestureUpdate(.5f, gfx::Point()); |
| 5924 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5925 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 5926 | |
danakj | 0481b57 | 2015-09-10 01:18:01 | [diff] [blame] | 5927 | // Scrolling should be relative to the offset as given by the delegate. |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5928 | gfx::Vector2dF scroll_delta(0.f, 10.f); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5929 | gfx::ScrollOffset current_offset(7.f, 8.f); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5930 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5931 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 5932 | host_impl_ |
| 5933 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 5934 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 5935 | .thread); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5936 | host_impl_->SetSynchronousInputHandlerRootScrollOffset(current_offset); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5937 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5938 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5939 | EXPECT_EQ(ScrollOffsetWithDelta(current_offset, scroll_delta), |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5940 | scroll_watcher.last_set_scroll_offset()); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5941 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5942 | current_offset = gfx::ScrollOffset(42.f, 41.f); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5943 | host_impl_->SetSynchronousInputHandlerRootScrollOffset(current_offset); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5944 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5945 | EXPECT_EQ(current_offset + gfx::ScrollOffset(scroll_delta), |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5946 | scroll_watcher.last_set_scroll_offset()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 5947 | host_impl_->ScrollEnd(EndState().get()); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5948 | host_impl_->SetSynchronousInputHandlerRootScrollOffset(gfx::ScrollOffset()); |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5949 | |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 5950 | // Forces a full tree synchronization and ensures that the scroll delegate |
| 5951 | // sees the correct size of the new tree. |
| 5952 | gfx::Size new_size(42, 24); |
| 5953 | host_impl_->CreatePendingTree(); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 5954 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 5955 | CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5956 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
[email protected] | fc20d14 | 2014-07-01 00:49:15 | [diff] [blame] | 5957 | host_impl_->ActivateSyncTree(); |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 5958 | EXPECT_EQ(gfx::SizeF(new_size), scroll_watcher.scrollable_size()); |
[email protected] | 7d1b07e | 2013-10-01 17:31:30 | [diff] [blame] | 5959 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5960 | // Tear down the LayerTreeHostImpl before the InputHandlerClient. |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 5961 | host_impl_->ReleaseOutputSurface(); |
| 5962 | host_impl_ = nullptr; |
[email protected] | 0a0d142 | 2013-05-02 09:14:52 | [diff] [blame] | 5963 | } |
| 5964 | |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 5965 | void CheckLayerScrollDelta(LayerImpl* layer, gfx::Vector2dF scroll_delta) { |
| 5966 | const gfx::Transform target_space_transform = |
| 5967 | layer->draw_properties().target_space_transform; |
| 5968 | EXPECT_TRUE(target_space_transform.IsScaleOrTranslation()); |
| 5969 | gfx::Point translated_point; |
| 5970 | target_space_transform.TransformPoint(&translated_point); |
| 5971 | gfx::Point expected_point = gfx::Point() - ToRoundedVector2d(scroll_delta); |
| 5972 | EXPECT_EQ(expected_point.ToString(), translated_point.ToString()); |
| 5973 | } |
| 5974 | |
| 5975 | TEST_F(LayerTreeHostImplTest, |
| 5976 | ExternalRootLayerScrollOffsetDelegationReflectedInNextDraw) { |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 5977 | host_impl_->SetViewportSize(gfx::Size(10, 20)); |
| 5978 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 5979 | LayerImpl* clip_layer = |
| 5980 | scroll_layer->test_properties()->parent->test_properties()->parent; |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 5981 | clip_layer->SetBounds(gfx::Size(10, 20)); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 5982 | scroll_layer->SetDrawsContent(true); |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 5983 | |
| 5984 | // Draw first frame to clear any pending draws and check scroll. |
| 5985 | DrawFrame(); |
| 5986 | CheckLayerScrollDelta(scroll_layer, gfx::Vector2dF(0.f, 0.f)); |
| 5987 | EXPECT_FALSE(host_impl_->active_tree()->needs_update_draw_properties()); |
| 5988 | |
| 5989 | // Set external scroll delta on delegate and notify LayerTreeHost. |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 5990 | gfx::ScrollOffset scroll_offset(10.f, 10.f); |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 5991 | host_impl_->SetSynchronousInputHandlerRootScrollOffset(scroll_offset); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5992 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 5993 | |
| 5994 | // Check scroll delta reflected in layer. |
boliu | 7d5dbab | 2014-10-10 20:05:47 | [diff] [blame] | 5995 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 5996 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 5997 | host_impl_->DrawLayers(&frame); |
boliu | 7d5dbab | 2014-10-10 20:05:47 | [diff] [blame] | 5998 | host_impl_->DidDrawAllLayers(frame); |
| 5999 | EXPECT_FALSE(frame.has_no_damage); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 6000 | CheckLayerScrollDelta(scroll_layer, ScrollOffsetToVector2dF(scroll_offset)); |
[email protected] | b4a3d46 | 2014-06-17 09:17:08 | [diff] [blame] | 6001 | } |
| 6002 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6003 | TEST_F(LayerTreeHostImplTest, OverscrollRoot) { |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6004 | InputHandlerScrollResult scroll_result; |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6005 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6006 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6007 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6008 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 6009 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6010 | DrawFrame(); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6011 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6012 | |
| 6013 | // In-bounds scrolling does not affect overscroll. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6014 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6015 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6016 | InputHandler::WHEEL) |
| 6017 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6018 | scroll_result = host_impl_->ScrollBy( |
| 6019 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6020 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6021 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 6022 | EXPECT_EQ(gfx::Vector2dF(), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6023 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6024 | |
| 6025 | // Overscroll events are reflected immediately. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6026 | scroll_result = host_impl_->ScrollBy( |
| 6027 | UpdateState(gfx::Point(), gfx::Vector2d(0, 50)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6028 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6029 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6030 | EXPECT_EQ(gfx::Vector2dF(0, 10), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6031 | EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6032 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6033 | host_impl_->accumulated_root_overscroll()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6034 | |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 6035 | // In-bounds scrolling resets accumulated overscroll for the scrolled axes. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6036 | scroll_result = host_impl_->ScrollBy( |
| 6037 | UpdateState(gfx::Point(), gfx::Vector2d(0, -50)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6038 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6039 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 6040 | EXPECT_EQ(gfx::Vector2dF(), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6041 | EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6042 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6043 | host_impl_->accumulated_root_overscroll()); |
| 6044 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6045 | scroll_result = host_impl_->ScrollBy( |
| 6046 | UpdateState(gfx::Point(), gfx::Vector2d(0, -10)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6047 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6048 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6049 | EXPECT_EQ(gfx::Vector2dF(0, -10), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6050 | EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6051 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6052 | host_impl_->accumulated_root_overscroll()); |
| 6053 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6054 | scroll_result = host_impl_->ScrollBy( |
| 6055 | UpdateState(gfx::Point(), gfx::Vector2d(10, 0)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6056 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6057 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 6058 | EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_result.unused_scroll_delta); |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 6059 | EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6060 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6061 | host_impl_->accumulated_root_overscroll()); |
| 6062 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6063 | scroll_result = host_impl_->ScrollBy( |
| 6064 | UpdateState(gfx::Point(), gfx::Vector2d(-15, 0)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6065 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6066 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6067 | EXPECT_EQ(gfx::Vector2dF(-5, 0), scroll_result.unused_scroll_delta); |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 6068 | EXPECT_EQ(gfx::Vector2dF(-5, -10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6069 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6070 | host_impl_->accumulated_root_overscroll()); |
| 6071 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6072 | scroll_result = host_impl_->ScrollBy( |
| 6073 | UpdateState(gfx::Point(), gfx::Vector2d(0, 60)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6074 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6075 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6076 | EXPECT_EQ(gfx::Vector2dF(0, 10), scroll_result.unused_scroll_delta); |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 6077 | EXPECT_EQ(gfx::Vector2dF(-5, 10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6078 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6079 | host_impl_->accumulated_root_overscroll()); |
| 6080 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6081 | scroll_result = host_impl_->ScrollBy( |
| 6082 | UpdateState(gfx::Point(), gfx::Vector2d(10, -60)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6083 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6084 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6085 | EXPECT_EQ(gfx::Vector2dF(0, -10), scroll_result.unused_scroll_delta); |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 6086 | EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6087 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6088 | host_impl_->accumulated_root_overscroll()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6089 | |
| 6090 | // Overscroll accumulates within the scope of ScrollBegin/ScrollEnd as long |
| 6091 | // as no scroll occurs. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6092 | scroll_result = host_impl_->ScrollBy( |
| 6093 | UpdateState(gfx::Point(), gfx::Vector2d(0, -20)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6094 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6095 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6096 | EXPECT_EQ(gfx::Vector2dF(0, -20), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6097 | EXPECT_EQ(gfx::Vector2dF(0, -30), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6098 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6099 | host_impl_->accumulated_root_overscroll()); |
| 6100 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6101 | scroll_result = host_impl_->ScrollBy( |
| 6102 | UpdateState(gfx::Point(), gfx::Vector2d(0, -20)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6103 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6104 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6105 | EXPECT_EQ(gfx::Vector2dF(0, -20), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6106 | EXPECT_EQ(gfx::Vector2dF(0, -50), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6107 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6108 | host_impl_->accumulated_root_overscroll()); |
| 6109 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6110 | // Overscroll resets on valid scroll. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6111 | scroll_result = host_impl_->ScrollBy( |
| 6112 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6113 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6114 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 6115 | EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6116 | EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6117 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6118 | host_impl_->accumulated_root_overscroll()); |
| 6119 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6120 | scroll_result = host_impl_->ScrollBy( |
| 6121 | UpdateState(gfx::Point(), gfx::Vector2d(0, -20)).get()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6122 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6123 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 6124 | EXPECT_EQ(gfx::Vector2dF(0, -10), scroll_result.unused_scroll_delta); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6125 | EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 6126 | EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 6127 | host_impl_->accumulated_root_overscroll()); |
| 6128 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6129 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6130 | } |
| 6131 | |
| 6132 | |
| 6133 | TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { |
| 6134 | // Scroll child layers beyond their maximum scroll range and make sure root |
| 6135 | // overscroll does not accumulate. |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6136 | InputHandlerScrollResult scroll_result; |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6137 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6138 | std::unique_ptr<LayerImpl> root_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6139 | LayerImpl::Create(host_impl_->active_tree(), 4); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6140 | root_clip->test_properties()->force_render_surface = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6141 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6142 | std::unique_ptr<LayerImpl> root = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6143 | CreateScrollableLayer(1, surface_size, root_clip.get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6144 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6145 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6146 | CreateScrollableLayer(3, surface_size, root_clip.get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6147 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6148 | std::unique_ptr<LayerImpl> child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6149 | CreateScrollableLayer(2, surface_size, root_clip.get()); |
| 6150 | LayerImpl* grand_child_layer = grand_child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6151 | child->test_properties()->AddChild(std::move(grand_child)); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6152 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6153 | LayerImpl* child_layer = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6154 | root->test_properties()->AddChild(std::move(child)); |
| 6155 | root_clip->test_properties()->AddChild(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6156 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_clip)); |
| 6157 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6158 | host_impl_->active_tree()->DidBecomeActive(); |
| 6159 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6160 | child_layer->layer_tree_impl() |
| 6161 | ->property_trees() |
| 6162 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(child_layer->id(), |
| 6163 | gfx::ScrollOffset(0, 3)); |
| 6164 | grand_child_layer->layer_tree_impl() |
| 6165 | ->property_trees() |
| 6166 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(grand_child_layer->id(), |
| 6167 | gfx::ScrollOffset(0, 2)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6168 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6169 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6170 | DrawFrame(); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6171 | { |
| 6172 | gfx::Vector2d scroll_delta(0, -10); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6173 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6174 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6175 | InputHandler::NON_BUBBLING_GESTURE) |
| 6176 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6177 | scroll_result = |
| 6178 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6179 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6180 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6181 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6182 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6183 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6184 | // The next time we scroll we should only scroll the parent, but overscroll |
| 6185 | // should still not reach the root layer. |
| 6186 | scroll_delta = gfx::Vector2d(0, -30); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6187 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6188 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6189 | InputHandler::NON_BUBBLING_GESTURE) |
| 6190 | .thread); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6191 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6192 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6193 | scroll_result = |
| 6194 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6195 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6196 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6197 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_layer); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6198 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6199 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6200 | |
| 6201 | // After scrolling the parent, another scroll on the opposite direction |
[email protected] | 635b0e9 | 2014-04-02 21:48:01 | [diff] [blame] | 6202 | // should scroll the child. |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6203 | scroll_delta = gfx::Vector2d(0, 70); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6204 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6205 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6206 | InputHandler::NON_BUBBLING_GESTURE) |
| 6207 | .thread); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6208 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6209 | scroll_result = |
| 6210 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6211 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6212 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6213 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6214 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6215 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6216 | } |
| 6217 | } |
| 6218 | |
| 6219 | TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { |
| 6220 | // When we try to scroll a non-scrollable child layer, the scroll delta |
| 6221 | // should be applied to one of its ancestors if possible. Overscroll should |
| 6222 | // be reflected only when it has bubbled up to the root scrolling layer. |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6223 | InputHandlerScrollResult scroll_result; |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 6224 | SetupScrollAndContentsLayers(gfx::Size(20, 20)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6225 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6226 | |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6227 | DrawFrame(); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6228 | { |
| 6229 | gfx::Vector2d scroll_delta(0, 8); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6230 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6231 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6232 | InputHandler::WHEEL) |
| 6233 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6234 | scroll_result = |
| 6235 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6236 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6237 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6238 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6239 | scroll_result = |
| 6240 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6241 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6242 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6243 | EXPECT_EQ(gfx::Vector2dF(0, 6), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6244 | scroll_result = |
| 6245 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6246 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6247 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6248 | EXPECT_EQ(gfx::Vector2dF(0, 14), host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6249 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6250 | } |
| 6251 | } |
| 6252 | |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6253 | TEST_F(LayerTreeHostImplTest, OverscrollAlways) { |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6254 | InputHandlerScrollResult scroll_result; |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 6255 | LayerTreeSettings settings = DefaultSettings(); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6256 | CreateHostImpl(settings, CreateOutputSurface()); |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6257 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6258 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 6259 | LayerImpl* clip_layer = |
| 6260 | scroll_layer->test_properties()->parent->test_properties()->parent; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6261 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6262 | clip_layer->SetBounds(gfx::Size(50, 50)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6263 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6264 | |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6265 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 6266 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6267 | DrawFrame(); |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6268 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6269 | |
| 6270 | // Even though the layer can't scroll the overscroll still happens. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6271 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6272 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6273 | InputHandler::WHEEL) |
| 6274 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6275 | scroll_result = host_impl_->ScrollBy( |
| 6276 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6277 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6278 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6279 | EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); |
[email protected] | 34d4343 | 2013-09-26 20:04:10 | [diff] [blame] | 6280 | } |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 6281 | |
[email protected] | 5b8a865c | 2014-04-03 00:35:51 | [diff] [blame] | 6282 | TEST_F(LayerTreeHostImplTest, NoOverscrollWhenNotAtEdge) { |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6283 | InputHandlerScrollResult scroll_result; |
bokan | 1f86d8f | 2015-07-30 16:08:54 | [diff] [blame] | 6284 | SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6285 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6286 | |
[email protected] | 485a42dc | 2014-03-26 22:44:34 | [diff] [blame] | 6287 | DrawFrame(); |
| 6288 | { |
[email protected] | 5b8a865c | 2014-04-03 00:35:51 | [diff] [blame] | 6289 | // Edge glow effect should be applicable only upon reaching Edges |
| 6290 | // of the content. unnecessary glow effect calls shouldn't be |
| 6291 | // called while scrolling up without reaching the edge of the content. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6292 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6293 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6294 | InputHandler::WHEEL) |
| 6295 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6296 | scroll_result = host_impl_->ScrollBy( |
| 6297 | UpdateState(gfx::Point(), gfx::Vector2dF(0, 100)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6298 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6299 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | 485a42dc | 2014-03-26 22:44:34 | [diff] [blame] | 6300 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6301 | host_impl_->accumulated_root_overscroll().ToString()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6302 | scroll_result = host_impl_->ScrollBy( |
| 6303 | UpdateState(gfx::Point(), gfx::Vector2dF(0, -2.30f)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6304 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6305 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | 485a42dc | 2014-03-26 22:44:34 | [diff] [blame] | 6306 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6307 | host_impl_->accumulated_root_overscroll().ToString()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6308 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 5b8a865c | 2014-04-03 00:35:51 | [diff] [blame] | 6309 | // unusedrootDelta should be subtracted from applied delta so that |
| 6310 | // unwanted glow effect calls are not called. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6311 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 6312 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6313 | InputHandler::NON_BUBBLING_GESTURE) |
| 6314 | .thread); |
| 6315 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 6316 | host_impl_->FlingScrollBegin().thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6317 | scroll_result = host_impl_->ScrollBy( |
| 6318 | UpdateState(gfx::Point(), gfx::Vector2dF(0, 20)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6319 | EXPECT_TRUE(scroll_result.did_scroll); |
| 6320 | EXPECT_TRUE(scroll_result.did_overscroll_root); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 6321 | EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0.000000f, 17.699997f), |
| 6322 | host_impl_->accumulated_root_overscroll()); |
[email protected] | 5b8a865c | 2014-04-03 00:35:51 | [diff] [blame] | 6323 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6324 | scroll_result = host_impl_->ScrollBy( |
| 6325 | UpdateState(gfx::Point(), gfx::Vector2dF(0.02f, -0.01f)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6326 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6327 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 6328 | EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0.000000f, 17.699997f), |
| 6329 | host_impl_->accumulated_root_overscroll()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6330 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 9328ede | 2014-04-04 07:45:52 | [diff] [blame] | 6331 | // TestCase to check kEpsilon, which prevents minute values to trigger |
| 6332 | // gloweffect without reaching edge. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6333 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6334 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 6335 | InputHandler::WHEEL) |
| 6336 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6337 | scroll_result = host_impl_->ScrollBy( |
| 6338 | UpdateState(gfx::Point(), gfx::Vector2dF(-0.12f, 0.1f)).get()); |
tdresser | deeba3f | 2015-07-10 19:26:58 | [diff] [blame] | 6339 | EXPECT_FALSE(scroll_result.did_scroll); |
| 6340 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
[email protected] | 9328ede | 2014-04-04 07:45:52 | [diff] [blame] | 6341 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6342 | host_impl_->accumulated_root_overscroll().ToString()); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 6343 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | 485a42dc | 2014-03-26 22:44:34 | [diff] [blame] | 6344 | } |
| 6345 | } |
| 6346 | |
eseckler | 59eeb02 | 2016-07-05 10:45:17 | [diff] [blame] | 6347 | TEST_F(LayerTreeHostImplTest, OverscrollOnMainThread) { |
| 6348 | InputHandlerScrollResult scroll_result; |
| 6349 | LayerTreeSettings settings = DefaultSettings(); |
| 6350 | CreateHostImpl(settings, CreateOutputSurface()); |
| 6351 | |
| 6352 | const gfx::Size content_size(50, 50); |
| 6353 | const gfx::Size viewport_size(50, 50); |
| 6354 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 6355 | |
| 6356 | LayerImpl* scroll_layer = |
| 6357 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
| 6358 | scroll_layer->set_main_thread_scrolling_reasons( |
| 6359 | MainThreadScrollingReason::kThreadedScrollingDisabled); |
| 6360 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6361 | |
| 6362 | DrawFrame(); |
| 6363 | |
| 6364 | // Overscroll initiated outside layers will be handled by the main thread. |
| 6365 | EXPECT_EQ(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( |
| 6366 | gfx::PointF(0, 60))); |
| 6367 | EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, |
| 6368 | host_impl_ |
| 6369 | ->ScrollBegin(BeginState(gfx::Point(0, 60)).get(), |
| 6370 | InputHandler::WHEEL) |
| 6371 | .thread); |
| 6372 | |
| 6373 | // Overscroll initiated inside layers will be handled by the main thread. |
| 6374 | EXPECT_NE(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( |
| 6375 | gfx::PointF(0, 0))); |
| 6376 | EXPECT_EQ( |
| 6377 | InputHandler::SCROLL_ON_MAIN_THREAD, |
| 6378 | host_impl_ |
| 6379 | ->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), InputHandler::WHEEL) |
| 6380 | .thread); |
| 6381 | } |
| 6382 | |
bokan | bc115b4 | 2016-08-22 13:46:32 | [diff] [blame] | 6383 | // Test that scrolls chain correctly when a child scroller on the page (e.g. a |
| 6384 | // scrolling div) is set as the outer viewport. This happens in the |
| 6385 | // rootScroller proposal. |
| 6386 | TEST_F(LayerTreeHostImplTest, ScrollChainingWithReplacedOuterViewport) { |
| 6387 | const gfx::Size content_size(200, 200); |
| 6388 | const gfx::Size viewport_size(100, 100); |
| 6389 | |
| 6390 | LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 6391 | |
| 6392 | LayerImpl* content_layer = |
| 6393 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 6394 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
| 6395 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 6396 | |
| 6397 | LayerImpl* scroll_layer = nullptr; |
| 6398 | LayerImpl* child_scroll_layer = nullptr; |
| 6399 | |
| 6400 | // Initialization: Add two nested scrolling layers, simulating a scrolling div |
| 6401 | // with another scrolling div inside it. Set the outer "div" to be the outer |
| 6402 | // viewport. |
| 6403 | { |
| 6404 | std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10); |
| 6405 | clip->SetBounds(content_size); |
| 6406 | clip->SetPosition(gfx::PointF()); |
| 6407 | |
| 6408 | std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11); |
| 6409 | scroll->SetBounds(gfx::Size(400, 400)); |
| 6410 | scroll->SetScrollClipLayer(clip->id()); |
| 6411 | scroll->SetDrawsContent(true); |
| 6412 | |
| 6413 | std::unique_ptr<LayerImpl> clip2 = LayerImpl::Create(layer_tree_impl, 12); |
| 6414 | clip2->SetBounds(gfx::Size(300, 300)); |
| 6415 | clip2->SetPosition(gfx::PointF()); |
| 6416 | clip2->SetDrawsContent(true); |
| 6417 | |
| 6418 | std::unique_ptr<LayerImpl> scroll2 = LayerImpl::Create(layer_tree_impl, 13); |
| 6419 | scroll2->SetBounds(gfx::Size(500, 500)); |
| 6420 | scroll2->SetScrollClipLayer(clip2->id()); |
| 6421 | scroll2->SetDrawsContent(true); |
| 6422 | |
| 6423 | scroll_layer = scroll.get(); |
| 6424 | child_scroll_layer = scroll2.get(); |
| 6425 | |
| 6426 | clip2->test_properties()->AddChild(std::move(scroll2)); |
| 6427 | scroll->test_properties()->AddChild(std::move(clip2)); |
| 6428 | |
| 6429 | clip->test_properties()->AddChild(std::move(scroll)); |
| 6430 | content_layer->test_properties()->AddChild(std::move(clip)); |
| 6431 | layer_tree_impl->SetViewportLayersFromIds( |
| 6432 | Layer::INVALID_ID, layer_tree_impl->PageScaleLayer()->id(), |
| 6433 | inner_scroll_layer->id(), scroll_layer->id()); |
| 6434 | layer_tree_impl->BuildPropertyTreesForTesting(); |
| 6435 | } |
| 6436 | |
| 6437 | // Scroll should target the nested scrolling layer in the content and then |
| 6438 | // chain to the parent scrolling layer which is now set as the outer |
| 6439 | // viewport. The original outer viewport layer shouldn't get any scroll here. |
| 6440 | { |
| 6441 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6442 | InputHandler::TOUCHSCREEN); |
| 6443 | host_impl_->ScrollBy( |
| 6444 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(200.f, 200.f)).get()); |
| 6445 | host_impl_->ScrollEnd(EndState().get()); |
| 6446 | |
| 6447 | EXPECT_VECTOR_EQ(gfx::Vector2dF(200.f, 200.f), |
| 6448 | child_scroll_layer->CurrentScrollOffset()); |
| 6449 | |
| 6450 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6451 | InputHandler::TOUCHSCREEN); |
| 6452 | host_impl_->ScrollBy( |
| 6453 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(200.f, 200.f)).get()); |
| 6454 | host_impl_->ScrollEnd(EndState().get()); |
| 6455 | |
| 6456 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), |
| 6457 | outer_scroll_layer->CurrentScrollOffset()); |
| 6458 | |
| 6459 | EXPECT_VECTOR_EQ(gfx::Vector2dF(200.f, 200.f), |
| 6460 | scroll_layer->CurrentScrollOffset()); |
| 6461 | } |
| 6462 | |
| 6463 | // Now that the nested scrolling layers are fully scrolled, further scrolls |
| 6464 | // would normally chain up to the "outer viewport" but since we've set the |
| 6465 | // scrolling content as the outer viewport, it should stop chaining there. |
| 6466 | { |
| 6467 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6468 | InputHandler::TOUCHSCREEN); |
| 6469 | host_impl_->ScrollBy( |
| 6470 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 6471 | host_impl_->ScrollEnd(EndState().get()); |
| 6472 | |
| 6473 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), |
| 6474 | outer_scroll_layer->CurrentScrollOffset()); |
| 6475 | } |
| 6476 | |
| 6477 | // Zoom into the page by a 2X factor so that the inner viewport becomes |
| 6478 | // scrollable. |
| 6479 | float min_page_scale = 1.f, max_page_scale = 4.f; |
| 6480 | float page_scale_factor = 2.f; |
| 6481 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
| 6482 | page_scale_factor, min_page_scale, max_page_scale); |
| 6483 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
| 6484 | |
| 6485 | // Reset the parent scrolling layer (i.e. the current outer viewport) so that |
| 6486 | // we can ensure viewport scrolling works correctly. |
| 6487 | scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset(0, 0)); |
| 6488 | |
| 6489 | // Scrolling the content layer should now scroll the inner viewport first, |
| 6490 | // and then chain up to the current outer viewport (i.e. the parent scroll |
| 6491 | // layer). |
| 6492 | { |
| 6493 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6494 | InputHandler::TOUCHSCREEN); |
| 6495 | host_impl_->ScrollBy( |
| 6496 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 6497 | host_impl_->ScrollEnd(EndState().get()); |
| 6498 | |
| 6499 | EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f), |
| 6500 | inner_scroll_layer->CurrentScrollOffset()); |
| 6501 | |
| 6502 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6503 | InputHandler::TOUCHSCREEN); |
| 6504 | host_impl_->ScrollBy( |
| 6505 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 6506 | host_impl_->ScrollEnd(EndState().get()); |
| 6507 | |
| 6508 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), |
| 6509 | outer_scroll_layer->CurrentScrollOffset()); |
| 6510 | EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f), |
| 6511 | scroll_layer->CurrentScrollOffset()); |
| 6512 | } |
| 6513 | } |
| 6514 | |
eseckler | 59eeb02 | 2016-07-05 10:45:17 | [diff] [blame] | 6515 | TEST_F(LayerTreeHostImplTest, OverscrollOnImplThread) { |
| 6516 | InputHandlerScrollResult scroll_result; |
| 6517 | LayerTreeSettings settings = DefaultSettings(); |
| 6518 | CreateHostImpl(settings, CreateOutputSurface()); |
| 6519 | |
| 6520 | const gfx::Size content_size(50, 50); |
| 6521 | const gfx::Size viewport_size(50, 50); |
| 6522 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 6523 | |
| 6524 | // By default, no main thread scrolling reasons should exist. |
| 6525 | LayerImpl* scroll_layer = |
| 6526 | host_impl_->active_tree()->InnerViewportScrollLayer(); |
| 6527 | EXPECT_EQ(MainThreadScrollingReason::kNotScrollingOnMain, |
| 6528 | scroll_layer->main_thread_scrolling_reasons()); |
| 6529 | |
| 6530 | DrawFrame(); |
| 6531 | |
| 6532 | // Overscroll initiated outside layers will be handled by the impl thread. |
| 6533 | EXPECT_EQ(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( |
| 6534 | gfx::PointF(0, 60))); |
| 6535 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 6536 | host_impl_ |
| 6537 | ->ScrollBegin(BeginState(gfx::Point(0, 60)).get(), |
| 6538 | InputHandler::WHEEL) |
| 6539 | .thread); |
| 6540 | |
| 6541 | // Overscroll initiated inside layers will be handled by the impl thread. |
| 6542 | EXPECT_NE(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( |
| 6543 | gfx::PointF(0, 0))); |
| 6544 | EXPECT_EQ( |
| 6545 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 6546 | host_impl_ |
| 6547 | ->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), InputHandler::WHEEL) |
| 6548 | .thread); |
| 6549 | } |
| 6550 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 6551 | class BlendStateCheckLayer : public LayerImpl { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6552 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6553 | static std::unique_ptr<LayerImpl> Create( |
| 6554 | LayerTreeImpl* tree_impl, |
| 6555 | int id, |
| 6556 | ResourceProvider* resource_provider) { |
| 6557 | return base::WrapUnique( |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 6558 | new BlendStateCheckLayer(tree_impl, id, resource_provider)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6559 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6560 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 6561 | void AppendQuads(RenderPass* render_pass, |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 6562 | AppendQuadsData* append_quads_data) override { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6563 | quads_appended_ = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6564 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6565 | gfx::Rect opaque_rect; |
| 6566 | if (contents_opaque()) |
| 6567 | opaque_rect = quad_rect_; |
| 6568 | else |
| 6569 | opaque_rect = opaque_content_rect_; |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 6570 | gfx::Rect visible_quad_rect = quad_rect_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6571 | |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 6572 | SharedQuadState* shared_quad_state = |
| 6573 | render_pass->CreateAndAppendSharedQuadState(); |
[email protected] | 9be1adc | 2014-05-07 15:39:41 | [diff] [blame] | 6574 | PopulateSharedQuadState(shared_quad_state); |
| 6575 | |
[email protected] | f7030c3 | 2014-07-03 18:54:34 | [diff] [blame] | 6576 | TileDrawQuad* test_blending_draw_quad = |
| 6577 | render_pass->CreateAndAppendDrawQuad<TileDrawQuad>(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6578 | test_blending_draw_quad->SetNew(shared_quad_state, |
| 6579 | quad_rect_, |
| 6580 | opaque_rect, |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 6581 | visible_quad_rect, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6582 | resource_id_, |
| 6583 | gfx::RectF(0.f, 0.f, 1.f, 1.f), |
| 6584 | gfx::Size(1, 1), |
jackhou | 2422961 | 2014-12-13 23:41:00 | [diff] [blame] | 6585 | false, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6586 | false); |
| 6587 | test_blending_draw_quad->visible_rect = quad_visible_rect_; |
| 6588 | EXPECT_EQ(blend_, test_blending_draw_quad->ShouldDrawWithBlending()); |
| 6589 | EXPECT_EQ(has_render_surface_, !!render_surface()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6590 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6591 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6592 | void SetExpectation(bool blend, bool has_render_surface) { |
| 6593 | blend_ = blend; |
| 6594 | has_render_surface_ = has_render_surface; |
| 6595 | quads_appended_ = false; |
| 6596 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6597 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6598 | bool quads_appended() const { return quads_appended_; } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6599 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 6600 | void SetQuadRect(const gfx::Rect& rect) { quad_rect_ = rect; } |
| 6601 | void SetQuadVisibleRect(const gfx::Rect& rect) { quad_visible_rect_ = rect; } |
| 6602 | void SetOpaqueContentRect(const gfx::Rect& rect) { |
| 6603 | opaque_content_rect_ = rect; |
| 6604 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6605 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6606 | private: |
| 6607 | BlendStateCheckLayer(LayerTreeImpl* tree_impl, |
| 6608 | int id, |
| 6609 | ResourceProvider* resource_provider) |
| 6610 | : LayerImpl(tree_impl, id), |
| 6611 | blend_(false), |
| 6612 | has_render_surface_(false), |
| 6613 | quads_appended_(false), |
| 6614 | quad_rect_(5, 5, 5, 5), |
| 6615 | quad_visible_rect_(5, 5, 5, 5), |
| 6616 | resource_id_(resource_provider->CreateResource( |
| 6617 | gfx::Size(1, 1), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 6618 | ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
ccameron | b4d9236 | 2016-08-12 07:33:26 | [diff] [blame] | 6619 | RGBA_8888, |
| 6620 | gfx::ColorSpace())) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6621 | resource_provider->AllocateForTesting(resource_id_); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6622 | SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6623 | SetDrawsContent(true); |
| 6624 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6625 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6626 | bool blend_; |
| 6627 | bool has_render_surface_; |
| 6628 | bool quads_appended_; |
| 6629 | gfx::Rect quad_rect_; |
| 6630 | gfx::Rect opaque_content_rect_; |
| 6631 | gfx::Rect quad_visible_rect_; |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 6632 | ResourceId resource_id_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6633 | }; |
| 6634 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6635 | TEST_F(LayerTreeHostImplTest, BlendingOffWhenDrawingOpaqueLayers) { |
| 6636 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6637 | std::unique_ptr<LayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6638 | LayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6639 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6640 | root->SetDrawsContent(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6641 | root->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6642 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6643 | } |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6644 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6645 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6646 | root->test_properties()->AddChild(BlendStateCheckLayer::Create( |
| 6647 | host_impl_->active_tree(), 2, host_impl_->resource_provider())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6648 | BlendStateCheckLayer* layer1 = |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 6649 | static_cast<BlendStateCheckLayer*>(root->test_properties()->children[0]); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6650 | layer1->SetPosition(gfx::PointF(2.f, 2.f)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6651 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6652 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6653 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6654 | // Opaque layer, drawn without blending. |
| 6655 | layer1->SetContentsOpaque(true); |
| 6656 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6657 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6658 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6659 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6660 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6661 | EXPECT_TRUE(layer1->quads_appended()); |
| 6662 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6663 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6664 | // Layer with translucent content and painting, so drawn with blending. |
| 6665 | layer1->SetContentsOpaque(false); |
| 6666 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6667 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6668 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6669 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6670 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6671 | EXPECT_TRUE(layer1->quads_appended()); |
| 6672 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6673 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6674 | // Layer with translucent opacity, drawn with blending. |
| 6675 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6676 | layer1->test_properties()->opacity = 0.5f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6677 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6678 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6679 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6680 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6681 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6682 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6683 | EXPECT_TRUE(layer1->quads_appended()); |
| 6684 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6685 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6686 | // Layer with translucent opacity and painting, drawn with blending. |
| 6687 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6688 | layer1->test_properties()->opacity = 0.5f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6689 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6690 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6691 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6692 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6693 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6694 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6695 | EXPECT_TRUE(layer1->quads_appended()); |
| 6696 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6697 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 6698 | layer1->test_properties()->AddChild(BlendStateCheckLayer::Create( |
| 6699 | host_impl_->active_tree(), 3, host_impl_->resource_provider())); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 6700 | BlendStateCheckLayer* layer2 = static_cast<BlendStateCheckLayer*>( |
| 6701 | layer1->test_properties()->children[0]); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6702 | layer2->SetPosition(gfx::PointF(4.f, 4.f)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6703 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6704 | // 2 opaque layers, drawn without blending. |
| 6705 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6706 | layer1->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6707 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6708 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6709 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6710 | layer2->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6711 | layer2->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6712 | layer2->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6713 | layer2->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6714 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6715 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6716 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6717 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6718 | EXPECT_TRUE(layer1->quads_appended()); |
| 6719 | EXPECT_TRUE(layer2->quads_appended()); |
| 6720 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6721 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6722 | // Parent layer with translucent content, drawn with blending. |
| 6723 | // Child layer with opaque content, drawn without blending. |
| 6724 | layer1->SetContentsOpaque(false); |
| 6725 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6726 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6727 | layer2->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6728 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6729 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6730 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6731 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6732 | EXPECT_TRUE(layer1->quads_appended()); |
| 6733 | EXPECT_TRUE(layer2->quads_appended()); |
| 6734 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6735 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6736 | // Parent layer with translucent content but opaque painting, drawn without |
| 6737 | // blending. |
| 6738 | // Child layer with opaque content, drawn without blending. |
| 6739 | layer1->SetContentsOpaque(true); |
| 6740 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6741 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6742 | layer2->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6743 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6744 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6745 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6746 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6747 | EXPECT_TRUE(layer1->quads_appended()); |
| 6748 | EXPECT_TRUE(layer2->quads_appended()); |
| 6749 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6750 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6751 | // Parent layer with translucent opacity and opaque content. Since it has a |
| 6752 | // drawing child, it's drawn to a render surface which carries the opacity, |
| 6753 | // so it's itself drawn without blending. |
| 6754 | // Child layer with opaque content, drawn without blending (parent surface |
| 6755 | // carries the inherited opacity). |
| 6756 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6757 | layer1->test_properties()->opacity = 0.5f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6758 | layer1->NoteLayerPropertyChanged(); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6759 | layer1->test_properties()->force_render_surface = true; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6760 | layer1->SetExpectation(false, true); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6761 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6762 | layer2->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6763 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 6764 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren( |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6765 | host_impl_->active_tree()->root_layer_for_testing()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6766 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6767 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6768 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6769 | EXPECT_TRUE(layer1->quads_appended()); |
| 6770 | EXPECT_TRUE(layer2->quads_appended()); |
| 6771 | host_impl_->DidDrawAllLayers(frame); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6772 | layer1->test_properties()->force_render_surface = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6773 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6774 | // Draw again, but with child non-opaque, to make sure |
| 6775 | // layer1 not culled. |
| 6776 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6777 | layer1->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6778 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6779 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6780 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6781 | layer2->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6782 | layer2->test_properties()->opacity = 0.5f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6783 | layer2->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6784 | layer2->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6785 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6786 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6787 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6788 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6789 | EXPECT_TRUE(layer1->quads_appended()); |
| 6790 | EXPECT_TRUE(layer2->quads_appended()); |
| 6791 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6792 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6793 | // A second way of making the child non-opaque. |
| 6794 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6795 | layer1->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6796 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6797 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6798 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6799 | layer2->SetContentsOpaque(false); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6800 | layer2->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6801 | layer2->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6802 | layer2->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6803 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6804 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6805 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6806 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6807 | EXPECT_TRUE(layer1->quads_appended()); |
| 6808 | EXPECT_TRUE(layer2->quads_appended()); |
| 6809 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6810 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6811 | // And when the layer says its not opaque but is painted opaque, it is not |
| 6812 | // blended. |
| 6813 | layer1->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6814 | layer1->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6815 | layer1->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6816 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6817 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6818 | layer2->SetContentsOpaque(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 6819 | layer2->test_properties()->opacity = 1.f; |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 6820 | layer2->NoteLayerPropertyChanged(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6821 | layer2->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6822 | layer2->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6823 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6824 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6825 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6826 | EXPECT_TRUE(layer1->quads_appended()); |
| 6827 | EXPECT_TRUE(layer2->quads_appended()); |
| 6828 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6829 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6830 | // Layer with partially opaque contents, drawn with blending. |
| 6831 | layer1->SetContentsOpaque(false); |
| 6832 | layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 6833 | layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 5, 5)); |
| 6834 | layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
| 6835 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6836 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6837 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6838 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6839 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6840 | EXPECT_TRUE(layer1->quads_appended()); |
| 6841 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6842 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6843 | // Layer with partially opaque contents partially culled, drawn with blending. |
| 6844 | layer1->SetContentsOpaque(false); |
| 6845 | layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 6846 | layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 5, 2)); |
| 6847 | layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
| 6848 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6849 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6850 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6851 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6852 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6853 | EXPECT_TRUE(layer1->quads_appended()); |
| 6854 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6855 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6856 | // Layer with partially opaque contents culled, drawn with blending. |
| 6857 | layer1->SetContentsOpaque(false); |
| 6858 | layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 6859 | layer1->SetQuadVisibleRect(gfx::Rect(7, 5, 3, 5)); |
| 6860 | layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
| 6861 | layer1->SetExpectation(true, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6862 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6863 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6864 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6865 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6866 | EXPECT_TRUE(layer1->quads_appended()); |
| 6867 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6868 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6869 | // Layer with partially opaque contents and translucent contents culled, drawn |
| 6870 | // without blending. |
| 6871 | layer1->SetContentsOpaque(false); |
| 6872 | layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); |
| 6873 | layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 2, 5)); |
| 6874 | layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
| 6875 | layer1->SetExpectation(false, false); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 6876 | layer1->SetUpdateRect(gfx::Rect(layer1->bounds())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6877 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6878 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 6879 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6880 | EXPECT_TRUE(layer1->quads_appended()); |
| 6881 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6882 | } |
| 6883 | |
sadrul | 32d1097 | 2016-07-30 05:26:21 | [diff] [blame] | 6884 | static bool MayContainVideoBitSetOnFrameData(LayerTreeHostImpl* host_impl) { |
| 6885 | host_impl->active_tree()->BuildPropertyTreesForTesting(); |
| 6886 | LayerTreeHostImpl::FrameData frame; |
| 6887 | EXPECT_EQ(DRAW_SUCCESS, host_impl->PrepareToDraw(&frame)); |
| 6888 | host_impl->DrawLayers(&frame); |
sadrul | 32d1097 | 2016-07-30 05:26:21 | [diff] [blame] | 6889 | host_impl->DidDrawAllLayers(frame); |
| 6890 | return frame.may_contain_video; |
| 6891 | } |
| 6892 | |
| 6893 | TEST_F(LayerTreeHostImplTest, MayContainVideo) { |
| 6894 | gfx::Size big_size(1000, 1000); |
| 6895 | host_impl_->SetViewportSize(big_size); |
| 6896 | |
| 6897 | int layer_id = 1; |
| 6898 | host_impl_->active_tree()->SetRootLayerForTesting( |
| 6899 | DidDrawCheckLayer::Create(host_impl_->active_tree(), layer_id++)); |
| 6900 | DidDrawCheckLayer* root = |
| 6901 | static_cast<DidDrawCheckLayer*>(*host_impl_->active_tree()->begin()); |
| 6902 | |
| 6903 | root->test_properties()->AddChild( |
| 6904 | DidDrawCheckLayer::Create(host_impl_->active_tree(), layer_id++)); |
| 6905 | DidDrawCheckLayer* video_layer = |
| 6906 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children.back()); |
| 6907 | video_layer->set_may_contain_video(true); |
| 6908 | EXPECT_TRUE(MayContainVideoBitSetOnFrameData(host_impl_.get())); |
| 6909 | |
| 6910 | // Test with the video layer occluded. |
| 6911 | root->test_properties()->AddChild( |
| 6912 | DidDrawCheckLayer::Create(host_impl_->active_tree(), layer_id++)); |
| 6913 | DidDrawCheckLayer* large_layer = |
| 6914 | static_cast<DidDrawCheckLayer*>(root->test_properties()->children.back()); |
| 6915 | large_layer->SetBounds(big_size); |
| 6916 | large_layer->SetContentsOpaque(true); |
| 6917 | EXPECT_FALSE(MayContainVideoBitSetOnFrameData(host_impl_.get())); |
| 6918 | |
| 6919 | // Remove the large layer. |
| 6920 | root->test_properties()->RemoveChild(large_layer); |
| 6921 | EXPECT_TRUE(MayContainVideoBitSetOnFrameData(host_impl_.get())); |
| 6922 | |
| 6923 | // Move the video layer so it goes beyond the root. |
| 6924 | video_layer->SetPosition(gfx::PointF(100.f, 100.f)); |
| 6925 | EXPECT_FALSE(MayContainVideoBitSetOnFrameData(host_impl_.get())); |
| 6926 | |
| 6927 | video_layer->SetPosition(gfx::PointF(0.f, 0.f)); |
| 6928 | video_layer->NoteLayerPropertyChanged(); |
| 6929 | EXPECT_TRUE(MayContainVideoBitSetOnFrameData(host_impl_.get())); |
| 6930 | } |
| 6931 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6932 | class LayerTreeHostImplViewportCoveredTest : public LayerTreeHostImplTest { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 6933 | protected: |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 6934 | LayerTreeHostImplViewportCoveredTest() : |
| 6935 | gutter_quad_material_(DrawQuad::SOLID_COLOR), |
| 6936 | child_(NULL), |
| 6937 | did_activate_pending_tree_(false) {} |
| 6938 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6939 | std::unique_ptr<OutputSurface> CreateFakeOutputSurface(bool software) { |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 6940 | if (software) |
| 6941 | return FakeOutputSurface::CreateDelegatingSoftware(); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 6942 | return FakeOutputSurface::CreateDelegating3d(); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6943 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6944 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6945 | void SetupActiveTreeLayers() { |
| 6946 | host_impl_->active_tree()->set_background_color(SK_ColorGRAY); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6947 | host_impl_->active_tree()->SetRootLayerForTesting( |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6948 | LayerImpl::Create(host_impl_->active_tree(), 1)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6949 | host_impl_->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6950 | ->root_layer_for_testing() |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6951 | ->test_properties() |
| 6952 | ->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6953 | host_impl_->active_tree() |
| 6954 | ->root_layer_for_testing() |
| 6955 | ->test_properties() |
| 6956 | ->AddChild(BlendStateCheckLayer::Create( |
| 6957 | host_impl_->active_tree(), 2, host_impl_->resource_provider())); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 6958 | child_ = static_cast<BlendStateCheckLayer*>(host_impl_->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 6959 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 6960 | ->test_properties() |
| 6961 | ->children[0]); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6962 | child_->SetExpectation(false, false); |
| 6963 | child_->SetContentsOpaque(true); |
| 6964 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6965 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6966 | // Expect no gutter rects. |
| 6967 | void TestLayerCoversFullViewport() { |
| 6968 | gfx::Rect layer_rect(viewport_size_); |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 6969 | child_->SetPosition(gfx::PointF(layer_rect.origin())); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6970 | child_->SetBounds(layer_rect.size()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6971 | child_->SetQuadRect(gfx::Rect(layer_rect.size())); |
| 6972 | child_->SetQuadVisibleRect(gfx::Rect(layer_rect.size())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6973 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6974 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6975 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6976 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6977 | ASSERT_EQ(1u, frame.render_passes.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6978 | |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 6979 | EXPECT_EQ(0u, CountGutterQuads(frame.render_passes[0]->quad_list)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6980 | EXPECT_EQ(1u, frame.render_passes[0]->quad_list.size()); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 6981 | ValidateTextureDrawQuads(frame.render_passes[0]->quad_list); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6982 | |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 6983 | VerifyQuadsExactlyCoverViewport(frame.render_passes[0]->quad_list); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6984 | host_impl_->DidDrawAllLayers(frame); |
| 6985 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6986 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6987 | // Expect fullscreen gutter rect. |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 6988 | void SetUpEmptylayer() { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 6989 | gfx::Rect layer_rect(0, 0, 0, 0); |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 6990 | child_->SetPosition(gfx::PointF(layer_rect.origin())); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6991 | child_->SetBounds(layer_rect.size()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 6992 | child_->SetQuadRect(gfx::Rect(layer_rect.size())); |
| 6993 | child_->SetQuadVisibleRect(gfx::Rect(layer_rect.size())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 6994 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 6995 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6996 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 6997 | void VerifyEmptyLayerRenderPasses(const RenderPassList& render_passes) { |
| 6998 | ASSERT_EQ(1u, render_passes.size()); |
| 6999 | |
| 7000 | EXPECT_EQ(1u, CountGutterQuads(render_passes[0]->quad_list)); |
| 7001 | EXPECT_EQ(1u, render_passes[0]->quad_list.size()); |
| 7002 | ValidateTextureDrawQuads(render_passes[0]->quad_list); |
| 7003 | |
| 7004 | VerifyQuadsExactlyCoverViewport(render_passes[0]->quad_list); |
| 7005 | } |
| 7006 | |
| 7007 | void TestEmptyLayer() { |
| 7008 | SetUpEmptylayer(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7009 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7010 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7011 | VerifyEmptyLayerRenderPasses(frame.render_passes); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7012 | host_impl_->DidDrawAllLayers(frame); |
| 7013 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7014 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7015 | void TestEmptyLayerWithOnDraw() { |
| 7016 | SetUpEmptylayer(); |
| 7017 | gfx::Transform identity; |
| 7018 | gfx::Rect viewport(viewport_size_); |
| 7019 | bool resourceless_software_draw = true; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 7020 | host_impl_->OnDraw(identity, viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7021 | VerifyEmptyLayerRenderPasses(last_on_draw_render_passes_); |
| 7022 | } |
| 7023 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7024 | // Expect four surrounding gutter rects. |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7025 | void SetUpLayerInMiddleOfViewport() { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7026 | gfx::Rect layer_rect(500, 500, 200, 200); |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 7027 | child_->SetPosition(gfx::PointF(layer_rect.origin())); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7028 | child_->SetBounds(layer_rect.size()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7029 | child_->SetQuadRect(gfx::Rect(layer_rect.size())); |
| 7030 | child_->SetQuadVisibleRect(gfx::Rect(layer_rect.size())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7031 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7032 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7033 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7034 | void VerifyLayerInMiddleOfViewport(const RenderPassList& render_passes) { |
| 7035 | ASSERT_EQ(1u, render_passes.size()); |
| 7036 | |
| 7037 | EXPECT_EQ(4u, CountGutterQuads(render_passes[0]->quad_list)); |
| 7038 | EXPECT_EQ(5u, render_passes[0]->quad_list.size()); |
| 7039 | ValidateTextureDrawQuads(render_passes[0]->quad_list); |
| 7040 | |
| 7041 | VerifyQuadsExactlyCoverViewport(render_passes[0]->quad_list); |
| 7042 | } |
| 7043 | |
| 7044 | void TestLayerInMiddleOfViewport() { |
| 7045 | SetUpLayerInMiddleOfViewport(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7046 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7047 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7048 | VerifyLayerInMiddleOfViewport(frame.render_passes); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7049 | host_impl_->DidDrawAllLayers(frame); |
| 7050 | } |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7051 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7052 | void TestLayerInMiddleOfViewportWithOnDraw() { |
| 7053 | SetUpLayerInMiddleOfViewport(); |
| 7054 | gfx::Transform identity; |
| 7055 | gfx::Rect viewport(viewport_size_); |
| 7056 | bool resourceless_software_draw = true; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 7057 | host_impl_->OnDraw(identity, viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7058 | VerifyLayerInMiddleOfViewport(last_on_draw_render_passes_); |
| 7059 | } |
| 7060 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7061 | // Expect no gutter rects. |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7062 | void SetUpLayerIsLargerThanViewport() { |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7063 | gfx::Rect layer_rect(viewport_size_.width() + 10, |
| 7064 | viewport_size_.height() + 10); |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 7065 | child_->SetPosition(gfx::PointF(layer_rect.origin())); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7066 | child_->SetBounds(layer_rect.size()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7067 | child_->SetQuadRect(gfx::Rect(layer_rect.size())); |
| 7068 | child_->SetQuadVisibleRect(gfx::Rect(layer_rect.size())); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7069 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7070 | } |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7071 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7072 | void VerifyLayerIsLargerThanViewport(const RenderPassList& render_passes) { |
| 7073 | ASSERT_EQ(1u, render_passes.size()); |
| 7074 | |
| 7075 | EXPECT_EQ(0u, CountGutterQuads(render_passes[0]->quad_list)); |
| 7076 | EXPECT_EQ(1u, render_passes[0]->quad_list.size()); |
| 7077 | ValidateTextureDrawQuads(render_passes[0]->quad_list); |
| 7078 | } |
| 7079 | |
| 7080 | void TestLayerIsLargerThanViewport() { |
| 7081 | SetUpLayerIsLargerThanViewport(); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7082 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7083 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7084 | VerifyLayerIsLargerThanViewport(frame.render_passes); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7085 | host_impl_->DidDrawAllLayers(frame); |
| 7086 | } |
| 7087 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7088 | void TestLayerIsLargerThanViewportWithOnDraw() { |
| 7089 | SetUpLayerIsLargerThanViewport(); |
| 7090 | gfx::Transform identity; |
| 7091 | gfx::Rect viewport(viewport_size_); |
| 7092 | bool resourceless_software_draw = true; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 7093 | host_impl_->OnDraw(identity, viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7094 | VerifyLayerIsLargerThanViewport(last_on_draw_render_passes_); |
| 7095 | } |
| 7096 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7097 | void DidActivateSyncTree() override { did_activate_pending_tree_ = true; } |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7098 | |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7099 | void set_gutter_quad_material(DrawQuad::Material material) { |
| 7100 | gutter_quad_material_ = material; |
| 7101 | } |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 7102 | void set_gutter_texture_size(const gfx::Size& gutter_texture_size) { |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7103 | gutter_texture_size_ = gutter_texture_size; |
| 7104 | } |
| 7105 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7106 | protected: |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7107 | size_t CountGutterQuads(const QuadList& quad_list) { |
| 7108 | size_t num_gutter_quads = 0; |
vmpstr | a2e8943 | 2016-07-20 02:05:34 | [diff] [blame] | 7109 | for (auto* quad : quad_list) { |
weiliangc | 48805fce | 2014-10-29 20:30:12 | [diff] [blame] | 7110 | num_gutter_quads += (quad->material == gutter_quad_material_) ? 1 : 0; |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7111 | } |
| 7112 | return num_gutter_quads; |
| 7113 | } |
| 7114 | |
| 7115 | void VerifyQuadsExactlyCoverViewport(const QuadList& quad_list) { |
| 7116 | LayerTestCommon::VerifyQuadsExactlyCoverRect( |
| 7117 | quad_list, gfx::Rect(DipSizeToPixelSize(viewport_size_))); |
| 7118 | } |
| 7119 | |
| 7120 | // Make sure that the texture coordinates match their expectations. |
| 7121 | void ValidateTextureDrawQuads(const QuadList& quad_list) { |
vmpstr | a2e8943 | 2016-07-20 02:05:34 | [diff] [blame] | 7122 | for (auto* quad : quad_list) { |
weiliangc | 48805fce | 2014-10-29 20:30:12 | [diff] [blame] | 7123 | if (quad->material != DrawQuad::TEXTURE_CONTENT) |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7124 | continue; |
weiliangc | 48805fce | 2014-10-29 20:30:12 | [diff] [blame] | 7125 | const TextureDrawQuad* texture_quad = TextureDrawQuad::MaterialCast(quad); |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 7126 | gfx::SizeF gutter_texture_size_pixels = |
| 7127 | gfx::ScaleSize(gfx::SizeF(gutter_texture_size_), |
| 7128 | host_impl_->active_tree()->device_scale_factor()); |
weiliangc | 7eb7ee6 | 2014-10-07 00:04:40 | [diff] [blame] | 7129 | EXPECT_EQ(texture_quad->uv_top_left.x(), |
| 7130 | texture_quad->rect.x() / gutter_texture_size_pixels.width()); |
| 7131 | EXPECT_EQ(texture_quad->uv_top_left.y(), |
| 7132 | texture_quad->rect.y() / gutter_texture_size_pixels.height()); |
| 7133 | EXPECT_EQ( |
| 7134 | texture_quad->uv_bottom_right.x(), |
| 7135 | texture_quad->rect.right() / gutter_texture_size_pixels.width()); |
| 7136 | EXPECT_EQ( |
| 7137 | texture_quad->uv_bottom_right.y(), |
| 7138 | texture_quad->rect.bottom() / gutter_texture_size_pixels.height()); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7139 | } |
| 7140 | } |
| 7141 | |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 7142 | gfx::Size DipSizeToPixelSize(const gfx::Size& size) { |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 7143 | return gfx::ScaleToRoundedSize( |
| 7144 | size, host_impl_->active_tree()->device_scale_factor()); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7145 | } |
| 7146 | |
| 7147 | DrawQuad::Material gutter_quad_material_; |
| 7148 | gfx::Size gutter_texture_size_; |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7149 | gfx::Size viewport_size_; |
| 7150 | BlendStateCheckLayer* child_; |
| 7151 | bool did_activate_pending_tree_; |
| 7152 | }; |
| 7153 | |
| 7154 | TEST_F(LayerTreeHostImplViewportCoveredTest, ViewportCovered) { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7155 | viewport_size_ = gfx::Size(1000, 1000); |
| 7156 | |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 7157 | bool software = false; |
| 7158 | CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7159 | |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7160 | host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7161 | SetupActiveTreeLayers(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7162 | EXPECT_SCOPED(TestLayerCoversFullViewport()); |
| 7163 | EXPECT_SCOPED(TestEmptyLayer()); |
| 7164 | EXPECT_SCOPED(TestLayerInMiddleOfViewport()); |
| 7165 | EXPECT_SCOPED(TestLayerIsLargerThanViewport()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7166 | } |
| 7167 | |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7168 | TEST_F(LayerTreeHostImplViewportCoveredTest, ViewportCoveredScaled) { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7169 | viewport_size_ = gfx::Size(1000, 1000); |
| 7170 | |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 7171 | bool software = false; |
| 7172 | CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software)); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7173 | |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 7174 | host_impl_->active_tree()->SetDeviceScaleFactor(2.f); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7175 | host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); |
| 7176 | SetupActiveTreeLayers(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7177 | EXPECT_SCOPED(TestLayerCoversFullViewport()); |
| 7178 | EXPECT_SCOPED(TestEmptyLayer()); |
| 7179 | EXPECT_SCOPED(TestLayerInMiddleOfViewport()); |
| 7180 | EXPECT_SCOPED(TestLayerIsLargerThanViewport()); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7181 | } |
| 7182 | |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7183 | TEST_F(LayerTreeHostImplViewportCoveredTest, ActiveTreeGrowViewportInvalid) { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7184 | viewport_size_ = gfx::Size(1000, 1000); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7185 | |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 7186 | bool software = true; |
| 7187 | CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7188 | |
| 7189 | // Pending tree to force active_tree size invalid. Not used otherwise. |
| 7190 | host_impl_->CreatePendingTree(); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7191 | host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7192 | EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); |
| 7193 | |
| 7194 | SetupActiveTreeLayers(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7195 | EXPECT_SCOPED(TestEmptyLayerWithOnDraw()); |
| 7196 | EXPECT_SCOPED(TestLayerInMiddleOfViewportWithOnDraw()); |
| 7197 | EXPECT_SCOPED(TestLayerIsLargerThanViewportWithOnDraw()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7198 | } |
| 7199 | |
| 7200 | TEST_F(LayerTreeHostImplViewportCoveredTest, ActiveTreeShrinkViewportInvalid) { |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7201 | viewport_size_ = gfx::Size(1000, 1000); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 7202 | |
boliu | 8ca8390 | 2015-10-23 04:36:13 | [diff] [blame] | 7203 | bool software = true; |
| 7204 | CreateHostImpl(DefaultSettings(), CreateFakeOutputSurface(software)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7205 | |
| 7206 | // Set larger viewport and activate it to active tree. |
| 7207 | host_impl_->CreatePendingTree(); |
| 7208 | gfx::Size larger_viewport(viewport_size_.width() + 100, |
| 7209 | viewport_size_.height() + 100); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7210 | host_impl_->SetViewportSize(DipSizeToPixelSize(larger_viewport)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7211 | EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); |
[email protected] | fc20d14 | 2014-07-01 00:49:15 | [diff] [blame] | 7212 | host_impl_->ActivateSyncTree(); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7213 | EXPECT_TRUE(did_activate_pending_tree_); |
| 7214 | EXPECT_FALSE(host_impl_->active_tree()->ViewportSizeInvalid()); |
| 7215 | |
| 7216 | // Shrink pending tree viewport without activating. |
| 7217 | host_impl_->CreatePendingTree(); |
[email protected] | 9f4f6a3 | 2013-09-04 21:35:12 | [diff] [blame] | 7218 | host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7219 | EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); |
| 7220 | |
| 7221 | SetupActiveTreeLayers(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7222 | EXPECT_SCOPED(TestEmptyLayerWithOnDraw()); |
| 7223 | EXPECT_SCOPED(TestLayerInMiddleOfViewportWithOnDraw()); |
| 7224 | EXPECT_SCOPED(TestLayerIsLargerThanViewportWithOnDraw()); |
[email protected] | 6133cc23 | 2013-07-30 18:47:07 | [diff] [blame] | 7225 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7226 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 7227 | class FakeDrawableLayerImpl: public LayerImpl { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7228 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7229 | static std::unique_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { |
| 7230 | return base::WrapUnique(new FakeDrawableLayerImpl(tree_impl, id)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7231 | } |
| 7232 | protected: |
| 7233 | FakeDrawableLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 7234 | : LayerImpl(tree_impl, id) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7235 | }; |
| 7236 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7237 | // Make sure damage tracking propagates all the way to the graphics context, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7238 | // where it should request to swap only the sub-buffer that is damaged. |
| 7239 | TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7240 | scoped_refptr<TestContextProvider> context_provider( |
[email protected] | 4bf4175 | 2013-11-05 01:34:32 | [diff] [blame] | 7241 | TestContextProvider::Create()); |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7242 | context_provider->BindToCurrentThread(); |
| 7243 | context_provider->TestContext3d()->set_have_post_sub_buffer(true); |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 7244 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7245 | std::unique_ptr<FakeOutputSurface> output_surface( |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7246 | FakeOutputSurface::CreateDelegating3d(context_provider)); |
sievers | 0668048 | 2014-10-10 20:21:50 | [diff] [blame] | 7247 | FakeOutputSurface* fake_output_surface = output_surface.get(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7248 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7249 | // This test creates its own LayerTreeHostImpl, so |
| 7250 | // that we can force partial swap enabled. |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 7251 | LayerTreeSettings settings = DefaultSettings(); |
jbauman | c5be44c | 2014-11-20 22:17:12 | [diff] [blame] | 7252 | settings.renderer_settings.partial_swap_enabled = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7253 | std::unique_ptr<LayerTreeHostImpl> layer_tree_host_impl = |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 7254 | LayerTreeHostImpl::Create( |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7255 | settings, this, &task_runner_provider_, &stats_instrumentation_, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 7256 | &shared_bitmap_manager_, NULL, &task_graph_runner_, |
| 7257 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7258 | layer_tree_host_impl->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7259 | layer_tree_host_impl->InitializeRenderer(output_surface.get()); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 7260 | layer_tree_host_impl->WillBeginImplFrame( |
| 7261 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 7262 | layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7263 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7264 | std::unique_ptr<LayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7265 | FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7266 | root->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7267 | std::unique_ptr<LayerImpl> child = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7268 | FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2); |
| 7269 | child->SetPosition(gfx::PointF(12.f, 13.f)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7270 | child->SetBounds(gfx::Size(14, 15)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7271 | child->SetDrawsContent(true); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7272 | root->SetBounds(gfx::Size(500, 500)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7273 | root->SetDrawsContent(true); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7274 | root->test_properties()->AddChild(std::move(child)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7275 | layer_tree_host_impl->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7276 | layer_tree_host_impl->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7277 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7278 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7279 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7280 | // First frame, the entire screen should get swapped. |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 7281 | EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7282 | layer_tree_host_impl->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7283 | layer_tree_host_impl->DidDrawAllLayers(frame); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7284 | gfx::Rect expected_swap_rect(500, 500); |
sievers | 0668048 | 2014-10-10 20:21:50 | [diff] [blame] | 7285 | EXPECT_EQ(expected_swap_rect.ToString(), |
| 7286 | fake_output_surface->last_swap_rect().ToString()); |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7287 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7288 | // Second frame, only the damaged area should get swapped. Damage should be |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7289 | // the union of old and new child rects: gfx::Rect(26, 28). |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 7290 | layer_tree_host_impl->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7291 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 7292 | ->test_properties() |
| 7293 | ->children[0] |
| 7294 | ->SetPosition(gfx::PointF()); |
| 7295 | layer_tree_host_impl->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7296 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 7297 | ->test_properties() |
| 7298 | ->children[0] |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 7299 | ->NoteLayerPropertyChanged(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7300 | layer_tree_host_impl->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 7301 | EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7302 | layer_tree_host_impl->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7303 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7304 | |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7305 | expected_swap_rect = gfx::Rect(26, 28); |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7306 | EXPECT_EQ(expected_swap_rect.ToString(), |
sievers | 0668048 | 2014-10-10 20:21:50 | [diff] [blame] | 7307 | fake_output_surface->last_swap_rect().ToString()); |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7308 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 7309 | layer_tree_host_impl->SetViewportSize(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7310 | // This will damage everything. |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7311 | layer_tree_host_impl->active_tree() |
| 7312 | ->root_layer_for_testing() |
| 7313 | ->SetBackgroundColor(SK_ColorBLACK); |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 7314 | EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7315 | layer_tree_host_impl->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7316 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | d9a5460 | 2013-12-10 07:01:59 | [diff] [blame] | 7317 | |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7318 | expected_swap_rect = gfx::Rect(10, 10); |
sievers | 0668048 | 2014-10-10 20:21:50 | [diff] [blame] | 7319 | EXPECT_EQ(expected_swap_rect.ToString(), |
| 7320 | fake_output_surface->last_swap_rect().ToString()); |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 7321 | |
| 7322 | layer_tree_host_impl->ReleaseOutputSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7323 | } |
| 7324 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7325 | TEST_F(LayerTreeHostImplTest, RootLayerDoesntCreateExtraSurface) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7326 | std::unique_ptr<LayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7327 | FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7328 | std::unique_ptr<LayerImpl> child = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7329 | FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 2); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7330 | child->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7331 | child->SetDrawsContent(true); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7332 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7333 | root->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7334 | root->test_properties()->force_render_surface = true; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7335 | root->test_properties()->AddChild(std::move(child)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7336 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7337 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7338 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7339 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7340 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7341 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7342 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7343 | EXPECT_EQ(1u, frame.render_surface_layer_list->size()); |
| 7344 | EXPECT_EQ(1u, frame.render_passes.size()); |
| 7345 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7346 | } |
| 7347 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 7348 | class FakeLayerWithQuads : public LayerImpl { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7349 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7350 | static std::unique_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { |
| 7351 | return base::WrapUnique(new FakeLayerWithQuads(tree_impl, id)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7352 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7353 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7354 | void AppendQuads(RenderPass* render_pass, |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7355 | AppendQuadsData* append_quads_data) override { |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 7356 | SharedQuadState* shared_quad_state = |
| 7357 | render_pass->CreateAndAppendSharedQuadState(); |
[email protected] | 9be1adc | 2014-05-07 15:39:41 | [diff] [blame] | 7358 | PopulateSharedQuadState(shared_quad_state); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7359 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7360 | SkColor gray = SkColorSetRGB(100, 100, 100); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 7361 | gfx::Rect quad_rect(bounds()); |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 7362 | gfx::Rect visible_quad_rect(quad_rect); |
[email protected] | f7030c3 | 2014-07-03 18:54:34 | [diff] [blame] | 7363 | SolidColorDrawQuad* my_quad = |
| 7364 | render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 7365 | my_quad->SetNew( |
| 7366 | shared_quad_state, quad_rect, visible_quad_rect, gray, false); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7367 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7368 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7369 | private: |
| 7370 | FakeLayerWithQuads(LayerTreeImpl* tree_impl, int id) |
| 7371 | : LayerImpl(tree_impl, id) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7372 | }; |
| 7373 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7374 | static std::unique_ptr<LayerTreeHostImpl> SetupLayersForOpacity( |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 7375 | LayerTreeSettings settings, |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7376 | bool partial_swap, |
| 7377 | LayerTreeHostImplClient* client, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7378 | TaskRunnerProvider* task_runner_provider, |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7379 | SharedBitmapManager* manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7380 | TaskGraphRunner* task_graph_runner, |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7381 | RenderingStatsInstrumentation* stats_instrumentation, |
| 7382 | OutputSurface* output_surface) { |
jbauman | c5be44c | 2014-11-20 22:17:12 | [diff] [blame] | 7383 | settings.renderer_settings.partial_swap_enabled = partial_swap; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7384 | std::unique_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7385 | settings, client, task_runner_provider, stats_instrumentation, manager, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 7386 | nullptr, task_graph_runner, |
| 7387 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7388 | my_host_impl->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7389 | my_host_impl->InitializeRenderer(output_surface); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 7390 | my_host_impl->WillBeginImplFrame( |
| 7391 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 7392 | my_host_impl->SetViewportSize(gfx::Size(100, 100)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7393 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7394 | /* |
| 7395 | Layers are created as follows: |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7396 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7397 | +--------------------+ |
| 7398 | | 1 | |
| 7399 | | +-----------+ | |
| 7400 | | | 2 | | |
| 7401 | | | +-------------------+ |
| 7402 | | | | 3 | |
| 7403 | | | +-------------------+ |
| 7404 | | | | | |
| 7405 | | +-----------+ | |
| 7406 | | | |
| 7407 | | | |
| 7408 | +--------------------+ |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7409 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7410 | Layers 1, 2 have render surfaces |
| 7411 | */ |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7412 | std::unique_ptr<LayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7413 | LayerImpl::Create(my_host_impl->active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7414 | std::unique_ptr<LayerImpl> child = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7415 | LayerImpl::Create(my_host_impl->active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7416 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7417 | FakeLayerWithQuads::Create(my_host_impl->active_tree(), 3); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7418 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7419 | gfx::Rect root_rect(0, 0, 100, 100); |
| 7420 | gfx::Rect child_rect(10, 10, 50, 50); |
| 7421 | gfx::Rect grand_child_rect(5, 5, 150, 150); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7422 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7423 | root->test_properties()->force_render_surface = true; |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 7424 | root->SetPosition(gfx::PointF(root_rect.origin())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7425 | root->SetBounds(root_rect.size()); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7426 | root->draw_properties().visible_layer_rect = root_rect; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7427 | root->SetDrawsContent(false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7428 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7429 | child->SetPosition(gfx::PointF(child_rect.x(), child_rect.y())); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 7430 | child->test_properties()->opacity = 0.5f; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7431 | child->SetBounds(gfx::Size(child_rect.width(), child_rect.height())); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7432 | child->draw_properties().visible_layer_rect = child_rect; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7433 | child->SetDrawsContent(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7434 | child->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7435 | |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 7436 | grand_child->SetPosition(gfx::PointF(grand_child_rect.origin())); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7437 | grand_child->SetBounds(grand_child_rect.size()); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7438 | grand_child->draw_properties().visible_layer_rect = grand_child_rect; |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7439 | grand_child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7440 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7441 | child->test_properties()->AddChild(std::move(grand_child)); |
| 7442 | root->test_properties()->AddChild(std::move(child)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7443 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7444 | my_host_impl->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7445 | my_host_impl->active_tree()->BuildPropertyTreesForTesting(); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7446 | return my_host_impl; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7447 | } |
| 7448 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7449 | TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorPartialSwap) { |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7450 | TestSharedBitmapManager shared_bitmap_manager; |
| 7451 | TestTaskGraphRunner task_graph_runner; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7452 | scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); |
| 7453 | provider->BindToCurrentThread(); |
| 7454 | provider->TestContext3d()->set_have_post_sub_buffer(true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7455 | std::unique_ptr<OutputSurface> output_surface( |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7456 | FakeOutputSurface::CreateDelegating3d(provider)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7457 | std::unique_ptr<LayerTreeHostImpl> my_host_impl = SetupLayersForOpacity( |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 7458 | DefaultSettings(), true, this, &task_runner_provider_, |
| 7459 | &shared_bitmap_manager, &task_graph_runner, &stats_instrumentation_, |
| 7460 | output_surface.get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7461 | { |
| 7462 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 7463 | EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7464 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7465 | // Verify all quads have been computed |
| 7466 | ASSERT_EQ(2U, frame.render_passes.size()); |
| 7467 | ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 7468 | ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size()); |
| 7469 | EXPECT_EQ(DrawQuad::SOLID_COLOR, |
weiliangc | 032e929d | 2014-09-26 01:55:01 | [diff] [blame] | 7470 | frame.render_passes[0]->quad_list.front()->material); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7471 | EXPECT_EQ(DrawQuad::RENDER_PASS, |
weiliangc | 032e929d | 2014-09-26 01:55:01 | [diff] [blame] | 7472 | frame.render_passes[1]->quad_list.front()->material); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7473 | |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7474 | my_host_impl->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7475 | my_host_impl->DidDrawAllLayers(frame); |
| 7476 | } |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 7477 | my_host_impl->ReleaseOutputSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7478 | } |
| 7479 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7480 | TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorNoPartialSwap) { |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7481 | TestSharedBitmapManager shared_bitmap_manager; |
| 7482 | TestTaskGraphRunner task_graph_runner; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7483 | scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); |
| 7484 | provider->BindToCurrentThread(); |
| 7485 | provider->TestContext3d()->set_have_post_sub_buffer(true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7486 | std::unique_ptr<OutputSurface> output_surface( |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7487 | FakeOutputSurface::CreateDelegating3d(provider)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7488 | std::unique_ptr<LayerTreeHostImpl> my_host_impl = SetupLayersForOpacity( |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 7489 | DefaultSettings(), false, this, &task_runner_provider_, |
| 7490 | &shared_bitmap_manager, &task_graph_runner, &stats_instrumentation_, |
| 7491 | output_surface.get()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7492 | { |
| 7493 | LayerTreeHostImpl::FrameData frame; |
[email protected] | 2aae9679 | 2014-05-15 23:10:50 | [diff] [blame] | 7494 | EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7495 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7496 | // Verify all quads have been computed |
| 7497 | ASSERT_EQ(2U, frame.render_passes.size()); |
| 7498 | ASSERT_EQ(1U, frame.render_passes[0]->quad_list.size()); |
| 7499 | ASSERT_EQ(1U, frame.render_passes[1]->quad_list.size()); |
| 7500 | EXPECT_EQ(DrawQuad::SOLID_COLOR, |
weiliangc | 032e929d | 2014-09-26 01:55:01 | [diff] [blame] | 7501 | frame.render_passes[0]->quad_list.front()->material); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7502 | EXPECT_EQ(DrawQuad::RENDER_PASS, |
weiliangc | 032e929d | 2014-09-26 01:55:01 | [diff] [blame] | 7503 | frame.render_passes[1]->quad_list.front()->material); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7504 | |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7505 | my_host_impl->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7506 | my_host_impl->DidDrawAllLayers(frame); |
| 7507 | } |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 7508 | my_host_impl->ReleaseOutputSurface(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7509 | } |
| 7510 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7511 | TEST_F(LayerTreeHostImplTest, LayersFreeTextures) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7512 | std::unique_ptr<TestWebGraphicsContext3D> context = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7513 | TestWebGraphicsContext3D::Create(); |
| 7514 | TestWebGraphicsContext3D* context3d = context.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7515 | std::unique_ptr<OutputSurface> output_surface( |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7516 | FakeOutputSurface::CreateDelegating3d(std::move(context))); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7517 | CreateHostImpl(DefaultSettings(), std::move(output_surface)); |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 7518 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7519 | std::unique_ptr<LayerImpl> root_layer = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7520 | LayerImpl::Create(host_impl_->active_tree(), 1); |
| 7521 | root_layer->SetBounds(gfx::Size(10, 10)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7522 | root_layer->test_properties()->force_render_surface = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7523 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7524 | scoped_refptr<VideoFrame> softwareFrame = |
| 7525 | media::VideoFrame::CreateColorFrame( |
| 7526 | gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta()); |
| 7527 | FakeVideoFrameProvider provider; |
| 7528 | provider.set_frame(softwareFrame); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7529 | std::unique_ptr<VideoLayerImpl> video_layer = VideoLayerImpl::Create( |
[email protected] | f78c3e8 | 2014-08-08 01:24:47 | [diff] [blame] | 7530 | host_impl_->active_tree(), 4, &provider, media::VIDEO_ROTATION_0); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7531 | video_layer->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7532 | video_layer->SetDrawsContent(true); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7533 | root_layer->test_properties()->AddChild(std::move(video_layer)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7534 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7535 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7536 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7537 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7538 | EXPECT_EQ(0u, context3d->NumTextures()); |
[email protected] | d993b60 | 2013-01-04 02:08:12 | [diff] [blame] | 7539 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7540 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7541 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7542 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7543 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7544 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7545 | EXPECT_GT(context3d->NumTextures(), 0u); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7546 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7547 | // Kill the layer tree. |
rockot | 2176f92 | 2016-06-08 19:18:32 | [diff] [blame] | 7548 | host_impl_->active_tree()->DetachLayers(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7549 | // There should be no textures left in use after. |
| 7550 | EXPECT_EQ(0u, context3d->NumTextures()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7551 | } |
| 7552 | |
[email protected] | c8756fbe | 2013-02-12 01:53:49 | [diff] [blame] | 7553 | class MockDrawQuadsToFillScreenContext : public TestWebGraphicsContext3D { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7554 | public: |
[email protected] | 0f996998 | 2014-01-11 02:26:37 | [diff] [blame] | 7555 | MOCK_METHOD1(useProgram, void(GLuint program)); |
| 7556 | MOCK_METHOD4(drawElements, void(GLenum mode, |
| 7557 | GLsizei count, |
| 7558 | GLenum type, |
| 7559 | GLintptr offset)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7560 | }; |
| 7561 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7562 | TEST_F(LayerTreeHostImplTest, HasTransparentBackground) { |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7563 | SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7564 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 7565 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7566 | host_impl_->active_tree()->set_background_color(SK_ColorWHITE); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7567 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7568 | // Verify one quad is drawn when transparent background set is not set. |
| 7569 | host_impl_->active_tree()->set_has_transparent_background(false); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7570 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7571 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7572 | { |
| 7573 | const auto& root_pass = frame.render_passes.back(); |
| 7574 | ASSERT_EQ(1u, root_pass->quad_list.size()); |
| 7575 | EXPECT_EQ(DrawQuad::SOLID_COLOR, root_pass->quad_list.front()->material); |
| 7576 | } |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7577 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7578 | host_impl_->DidDrawAllLayers(frame); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7579 | |
| 7580 | // Cause damage so we would draw something if possible. |
danakj | b902c67 | 2016-08-17 02:33:54 | [diff] [blame] | 7581 | host_impl_->SetFullViewportDamage(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7582 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7583 | // Verify no quads are drawn when transparent background is set. |
| 7584 | host_impl_->active_tree()->set_has_transparent_background(true); |
danakj | b902c67 | 2016-08-17 02:33:54 | [diff] [blame] | 7585 | host_impl_->SetFullViewportDamage(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7586 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7587 | { |
| 7588 | const auto& root_pass = frame.render_passes.back(); |
| 7589 | ASSERT_EQ(0u, root_pass->quad_list.size()); |
| 7590 | } |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7591 | host_impl_->DrawLayers(&frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7592 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7593 | } |
| 7594 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7595 | class LayerTreeHostImplTestWithDelegatingRenderer |
| 7596 | : public LayerTreeHostImplTest { |
| 7597 | protected: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7598 | std::unique_ptr<OutputSurface> CreateOutputSurface() override { |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 7599 | return FakeOutputSurface::CreateDelegating3d(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7600 | } |
| 7601 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 7602 | void DrawFrameAndTestDamage(const gfx::Rect& expected_damage) { |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7603 | bool expect_to_draw = !expected_damage.IsEmpty(); |
| 7604 | |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7605 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7606 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7607 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7608 | if (!expect_to_draw) { |
| 7609 | // With no damage, we don't draw, and no quads are created. |
| 7610 | ASSERT_EQ(0u, frame.render_passes.size()); |
| 7611 | } else { |
| 7612 | ASSERT_EQ(1u, frame.render_passes.size()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7613 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7614 | // Verify the damage rect for the root render pass. |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 7615 | const RenderPass* root_render_pass = frame.render_passes.back().get(); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 7616 | EXPECT_EQ(expected_damage, root_render_pass->damage_rect); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7617 | |
| 7618 | // Verify the root and child layers' quads are generated and not being |
| 7619 | // culled. |
| 7620 | ASSERT_EQ(2u, root_render_pass->quad_list.size()); |
| 7621 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 7622 | LayerImpl* child = host_impl_->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7623 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 7624 | ->test_properties() |
| 7625 | ->children[0]; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 7626 | gfx::Rect expected_child_visible_rect(child->bounds()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 7627 | EXPECT_EQ(expected_child_visible_rect, |
| 7628 | root_render_pass->quad_list.front()->visible_rect); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7629 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7630 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 7631 | gfx::Rect expected_root_visible_rect(root->bounds()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 7632 | EXPECT_EQ(expected_root_visible_rect, |
| 7633 | root_render_pass->quad_list.ElementAt(1)->visible_rect); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7634 | } |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7635 | |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 7636 | EXPECT_EQ(expect_to_draw, host_impl_->DrawLayers(&frame)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7637 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7638 | } |
| 7639 | }; |
| 7640 | |
| 7641 | TEST_F(LayerTreeHostImplTestWithDelegatingRenderer, FrameIncludesDamageRect) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7642 | std::unique_ptr<SolidColorLayerImpl> root = |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7643 | SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7644 | root->SetPosition(gfx::PointF()); |
| 7645 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7646 | root->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7647 | root->test_properties()->force_render_surface = true; |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7648 | |
| 7649 | // Child layer is in the bottom right corner. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7650 | std::unique_ptr<SolidColorLayerImpl> child = |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7651 | SolidColorLayerImpl::Create(host_impl_->active_tree(), 2); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7652 | child->SetPosition(gfx::PointF(9.f, 9.f)); |
| 7653 | child->SetBounds(gfx::Size(1, 1)); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7654 | child->SetDrawsContent(true); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7655 | root->test_properties()->AddChild(std::move(child)); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7656 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7657 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7658 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7659 | |
| 7660 | // Draw a frame. In the first frame, the entire viewport should be damaged. |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 7661 | gfx::Rect full_frame_damage(host_impl_->DrawViewportSize()); |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7662 | DrawFrameAndTestDamage(full_frame_damage); |
| 7663 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7664 | // The second frame has damage that doesn't touch the child layer. Its quads |
| 7665 | // should still be generated. |
| 7666 | gfx::Rect small_damage = gfx::Rect(0, 0, 1, 1); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7667 | host_impl_->active_tree()->root_layer_for_testing()->SetUpdateRect( |
| 7668 | small_damage); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 7669 | DrawFrameAndTestDamage(small_damage); |
| 7670 | |
| 7671 | // The third frame should have no damage, so no quads should be generated. |
[email protected] | aa04363 | 2013-03-25 03:39:42 | [diff] [blame] | 7672 | gfx::Rect no_damage; |
| 7673 | DrawFrameAndTestDamage(no_damage); |
[email protected] | ea9d8f2 | 2012-12-08 03:39:29 | [diff] [blame] | 7674 | } |
| 7675 | |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7676 | class GLRendererWithSetupQuadForAntialiasing : public GLRenderer { |
| 7677 | public: |
timav | 8a72a92 | 2014-11-07 00:47:21 | [diff] [blame] | 7678 | using GLRenderer::ShouldAntialiasQuad; |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7679 | }; |
| 7680 | |
| 7681 | TEST_F(LayerTreeHostImplTest, FarAwayQuadsDontNeedAA) { |
| 7682 | // Due to precision issues (especially on Android), sometimes far |
| 7683 | // away quads can end up thinking they need AA. |
| 7684 | float device_scale_factor = 4.f / 3.f; |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7685 | gfx::Size root_size(2000, 1000); |
| 7686 | gfx::Size device_viewport_size = |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 7687 | gfx::ScaleToCeiledSize(root_size, device_scale_factor); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7688 | host_impl_->SetViewportSize(device_viewport_size); |
| 7689 | |
| 7690 | host_impl_->CreatePendingTree(); |
ajuma | 1d48e01 | 2015-09-25 22:24:16 | [diff] [blame] | 7691 | host_impl_->pending_tree()->SetDeviceScaleFactor(device_scale_factor); |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 7692 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f / 16.f, |
| 7693 | 16.f); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7694 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7695 | std::unique_ptr<LayerImpl> scoped_root = |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7696 | LayerImpl::Create(host_impl_->pending_tree(), 1); |
| 7697 | LayerImpl* root = scoped_root.get(); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7698 | root->test_properties()->force_render_surface = true; |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7699 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7700 | host_impl_->pending_tree()->SetRootLayerForTesting(std::move(scoped_root)); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7701 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7702 | std::unique_ptr<LayerImpl> scoped_scrolling_layer = |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7703 | LayerImpl::Create(host_impl_->pending_tree(), 2); |
| 7704 | LayerImpl* scrolling_layer = scoped_scrolling_layer.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7705 | root->test_properties()->AddChild(std::move(scoped_scrolling_layer)); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7706 | |
| 7707 | gfx::Size content_layer_bounds(100000, 100); |
vmpstr | 41d68f88 | 2016-03-30 01:20:23 | [diff] [blame] | 7708 | scoped_refptr<FakeRasterSource> raster_source( |
| 7709 | FakeRasterSource::CreateFilled(content_layer_bounds)); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7710 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7711 | std::unique_ptr<FakePictureLayerImpl> scoped_content_layer = |
hendrikw | 9d909aa7 | 2014-11-11 20:19:52 | [diff] [blame] | 7712 | FakePictureLayerImpl::CreateWithRasterSource(host_impl_->pending_tree(), |
vmpstr | 85674026 | 2015-09-24 00:25:25 | [diff] [blame] | 7713 | 3, raster_source); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7714 | LayerImpl* content_layer = scoped_content_layer.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7715 | scrolling_layer->test_properties()->AddChild(std::move(scoped_content_layer)); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7716 | content_layer->SetBounds(content_layer_bounds); |
| 7717 | content_layer->SetDrawsContent(true); |
| 7718 | |
| 7719 | root->SetBounds(root_size); |
| 7720 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 7721 | gfx::ScrollOffset scroll_offset(100000, 0); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 7722 | scrolling_layer->SetScrollClipLayer(root->id()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7723 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
| 7724 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7725 | scrolling_layer->layer_tree_impl() |
| 7726 | ->property_trees() |
| 7727 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scrolling_layer->id(), |
| 7728 | scroll_offset); |
[email protected] | fc20d14 | 2014-07-01 00:49:15 | [diff] [blame] | 7729 | host_impl_->ActivateSyncTree(); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7730 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 7731 | bool update_lcd_text = false; |
| 7732 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7733 | ASSERT_EQ(1u, host_impl_->active_tree()->RenderSurfaceLayerList().size()); |
| 7734 | |
| 7735 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7736 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7737 | |
| 7738 | ASSERT_EQ(1u, frame.render_passes.size()); |
| 7739 | ASSERT_LE(1u, frame.render_passes[0]->quad_list.size()); |
weiliangc | 032e929d | 2014-09-26 01:55:01 | [diff] [blame] | 7740 | const DrawQuad* quad = frame.render_passes[0]->quad_list.front(); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7741 | |
rosca | f519af2 | 2015-06-17 20:57:10 | [diff] [blame] | 7742 | bool clipped = false, force_aa = false; |
| 7743 | gfx::QuadF device_layer_quad = MathUtil::MapQuad( |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7744 | quad->shared_quad_state->quad_to_target_transform, |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 7745 | gfx::QuadF(gfx::RectF(quad->shared_quad_state->visible_quad_layer_rect)), |
| 7746 | &clipped); |
rosca | f519af2 | 2015-06-17 20:57:10 | [diff] [blame] | 7747 | EXPECT_FALSE(clipped); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7748 | bool antialiased = |
timav | 8a72a92 | 2014-11-07 00:47:21 | [diff] [blame] | 7749 | GLRendererWithSetupQuadForAntialiasing::ShouldAntialiasQuad( |
rosca | f519af2 | 2015-06-17 20:57:10 | [diff] [blame] | 7750 | device_layer_quad, clipped, force_aa); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7751 | EXPECT_FALSE(antialiased); |
| 7752 | |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7753 | host_impl_->DrawLayers(&frame); |
[email protected] | 46b79d5 | 2013-09-07 04:29:29 | [diff] [blame] | 7754 | host_impl_->DidDrawAllLayers(frame); |
| 7755 | } |
| 7756 | |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 7757 | class CompositorFrameMetadataTest : public LayerTreeHostImplTest { |
| 7758 | public: |
| 7759 | CompositorFrameMetadataTest() |
| 7760 | : swap_buffers_complete_(0) {} |
| 7761 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7762 | void DidSwapBuffersCompleteOnImplThread() override { |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 7763 | swap_buffers_complete_++; |
| 7764 | } |
| 7765 | |
| 7766 | int swap_buffers_complete_; |
| 7767 | }; |
| 7768 | |
| 7769 | TEST_F(CompositorFrameMetadataTest, CompositorFrameAckCountsAsSwapComplete) { |
| 7770 | SetupRootLayerImpl(FakeLayerWithQuads::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7771 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 7772 | { |
| 7773 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7774 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 7775 | host_impl_->DrawLayers(&frame); |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 7776 | host_impl_->DidDrawAllLayers(frame); |
| 7777 | } |
fsamuel | b62b7822 | 2016-07-15 01:14:14 | [diff] [blame] | 7778 | host_impl_->ReclaimResources(ReturnedResourceArray()); |
[email protected] | c1490266 | 2014-04-18 05:06:11 | [diff] [blame] | 7779 | host_impl_->DidSwapBuffersComplete(); |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 7780 | EXPECT_EQ(swap_buffers_complete_, 1); |
| 7781 | } |
| 7782 | |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 7783 | class CountingSoftwareDevice : public SoftwareOutputDevice { |
| 7784 | public: |
| 7785 | CountingSoftwareDevice() : frames_began_(0), frames_ended_(0) {} |
| 7786 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7787 | SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override { |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 7788 | ++frames_began_; |
| 7789 | return SoftwareOutputDevice::BeginPaint(damage_rect); |
| 7790 | } |
jbauman | 95f74135 | 2015-08-07 02:10:34 | [diff] [blame] | 7791 | void EndPaint() override { |
| 7792 | SoftwareOutputDevice::EndPaint(); |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 7793 | ++frames_ended_; |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 7794 | } |
| 7795 | |
| 7796 | int frames_began_, frames_ended_; |
| 7797 | }; |
| 7798 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7799 | TEST_F(LayerTreeHostImplTest, |
| 7800 | ForcedDrawToSoftwareDeviceSkipsUnsupportedLayers) { |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 7801 | set_reduce_memory_result(false); |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 7802 | EXPECT_TRUE(CreateHostImpl(DefaultSettings(), |
| 7803 | FakeOutputSurface::CreateDelegatingSoftware())); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7804 | |
[email protected] | c05dfbb | 2014-07-10 22:49:04 | [diff] [blame] | 7805 | const gfx::Transform external_transform; |
| 7806 | const gfx::Rect external_viewport; |
[email protected] | c05dfbb | 2014-07-10 22:49:04 | [diff] [blame] | 7807 | const bool resourceless_software_draw = true; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7808 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 7809 | external_transform); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7810 | |
| 7811 | // SolidColorLayerImpl will be drawn. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7812 | std::unique_ptr<SolidColorLayerImpl> root_layer = |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7813 | SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
| 7814 | |
| 7815 | // VideoLayerImpl will not be drawn. |
| 7816 | FakeVideoFrameProvider provider; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7817 | std::unique_ptr<VideoLayerImpl> video_layer = VideoLayerImpl::Create( |
[email protected] | f78c3e8 | 2014-08-08 01:24:47 | [diff] [blame] | 7818 | host_impl_->active_tree(), 2, &provider, media::VIDEO_ROTATION_0); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7819 | video_layer->SetBounds(gfx::Size(10, 10)); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7820 | video_layer->SetDrawsContent(true); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 7821 | root_layer->test_properties()->AddChild(std::move(video_layer)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7822 | SetupRootLayerImpl(std::move(root_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 7823 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7824 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 7825 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7826 | resourceless_software_draw); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7827 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7828 | EXPECT_EQ(1u, last_on_draw_frame_->will_draw_layers.size()); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 7829 | EXPECT_EQ(host_impl_->active_tree()->root_layer_for_testing(), |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 7830 | last_on_draw_frame_->will_draw_layers[0]); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 7831 | } |
| 7832 | |
danakj | aa5c491 | 2016-09-10 00:28:23 | [diff] [blame] | 7833 | // Checks that we use the memory limits provided. |
| 7834 | TEST_F(LayerTreeHostImplTest, MemoryLimits) { |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 7835 | host_impl_->ReleaseOutputSurface(); |
| 7836 | host_impl_ = nullptr; |
| 7837 | |
danakj | aa5c491 | 2016-09-10 00:28:23 | [diff] [blame] | 7838 | const size_t kGpuByteLimit = 1234321; |
| 7839 | const size_t kSoftwareByteLimit = 4321234; |
| 7840 | const size_t kGpuResourceLimit = 2345432; |
| 7841 | const size_t kSoftwareResourceLimit = 5432345; |
| 7842 | const gpu::MemoryAllocation::PriorityCutoff kGpuCutoff = |
| 7843 | gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; |
| 7844 | const gpu::MemoryAllocation::PriorityCutoff kSoftwareCutoff = |
| 7845 | gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 7846 | |
| 7847 | const TileMemoryLimitPolicy kGpuTileCutoff = |
| 7848 | ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy(kGpuCutoff); |
| 7849 | const TileMemoryLimitPolicy kSoftwareTileCutoff = |
| 7850 | ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( |
| 7851 | kSoftwareCutoff); |
| 7852 | const TileMemoryLimitPolicy kNothingTileCutoff = |
| 7853 | ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( |
| 7854 | gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING); |
| 7855 | EXPECT_NE(kGpuTileCutoff, kNothingTileCutoff); |
| 7856 | EXPECT_NE(kSoftwareTileCutoff, kNothingTileCutoff); |
| 7857 | |
weiliangc | 8f4ef0d | 2015-11-27 00:15:55 | [diff] [blame] | 7858 | LayerTreeSettings settings = DefaultSettings(); |
danakj | aa5c491 | 2016-09-10 00:28:23 | [diff] [blame] | 7859 | settings.gpu_memory_policy = |
| 7860 | ManagedMemoryPolicy(kGpuByteLimit, kGpuCutoff, kGpuResourceLimit); |
| 7861 | settings.software_memory_policy = ManagedMemoryPolicy( |
| 7862 | kSoftwareByteLimit, kSoftwareCutoff, kSoftwareResourceLimit); |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 7863 | host_impl_ = LayerTreeHostImpl::Create( |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7864 | settings, this, &task_runner_provider_, &stats_instrumentation_, |
| 7865 | &shared_bitmap_manager_, &gpu_memory_buffer_manager_, &task_graph_runner_, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 7866 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); |
[email protected] | fd32d12 | 2013-06-29 13:11:04 | [diff] [blame] | 7867 | |
danakj | aa5c491 | 2016-09-10 00:28:23 | [diff] [blame] | 7868 | // Gpu compositing. |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7869 | output_surface_ = |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 7870 | FakeOutputSurface::CreateDelegating3d(TestWebGraphicsContext3D::Create()); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7871 | host_impl_->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7872 | host_impl_->InitializeRenderer(output_surface_.get()); |
danakj | aa5c491 | 2016-09-10 00:28:23 | [diff] [blame] | 7873 | { |
| 7874 | const auto& state = host_impl_->global_tile_state(); |
| 7875 | EXPECT_EQ(kGpuByteLimit, state.hard_memory_limit_in_bytes); |
| 7876 | EXPECT_EQ(kGpuResourceLimit, state.num_resources_limit); |
| 7877 | EXPECT_EQ(kGpuTileCutoff, state.memory_limit_policy); |
| 7878 | } |
| 7879 | |
| 7880 | // Not visible, drops to 0. |
| 7881 | host_impl_->SetVisible(false); |
| 7882 | { |
| 7883 | const auto& state = host_impl_->global_tile_state(); |
| 7884 | EXPECT_EQ(0u, state.hard_memory_limit_in_bytes); |
| 7885 | EXPECT_EQ(kGpuResourceLimit, state.num_resources_limit); |
| 7886 | EXPECT_EQ(kNothingTileCutoff, state.memory_limit_policy); |
| 7887 | } |
| 7888 | |
| 7889 | // Visible, is the gpu limit again. |
| 7890 | host_impl_->SetVisible(true); |
| 7891 | { |
| 7892 | const auto& state = host_impl_->global_tile_state(); |
| 7893 | EXPECT_EQ(kGpuByteLimit, state.hard_memory_limit_in_bytes); |
| 7894 | EXPECT_EQ(kGpuResourceLimit, state.num_resources_limit); |
| 7895 | } |
| 7896 | |
| 7897 | // Software compositing. |
| 7898 | host_impl_->ReleaseOutputSurface(); |
| 7899 | output_surface_ = FakeOutputSurface::CreateDelegatingSoftware(); |
| 7900 | host_impl_->InitializeRenderer(output_surface_.get()); |
| 7901 | { |
| 7902 | const auto& state = host_impl_->global_tile_state(); |
| 7903 | EXPECT_EQ(kSoftwareByteLimit, state.hard_memory_limit_in_bytes); |
| 7904 | EXPECT_EQ(kSoftwareResourceLimit, state.num_resources_limit); |
| 7905 | EXPECT_EQ(kSoftwareTileCutoff, state.memory_limit_policy); |
| 7906 | } |
| 7907 | |
| 7908 | // Not visible, drops to 0. |
| 7909 | host_impl_->SetVisible(false); |
| 7910 | { |
| 7911 | const auto& state = host_impl_->global_tile_state(); |
| 7912 | EXPECT_EQ(0u, state.hard_memory_limit_in_bytes); |
| 7913 | EXPECT_EQ(kSoftwareResourceLimit, state.num_resources_limit); |
| 7914 | EXPECT_EQ(kNothingTileCutoff, state.memory_limit_policy); |
| 7915 | } |
| 7916 | |
| 7917 | // Visible, is the software limit again. |
| 7918 | host_impl_->SetVisible(true); |
| 7919 | { |
| 7920 | const auto& state = host_impl_->global_tile_state(); |
| 7921 | EXPECT_EQ(kSoftwareByteLimit, state.hard_memory_limit_in_bytes); |
| 7922 | EXPECT_EQ(kSoftwareResourceLimit, state.num_resources_limit); |
| 7923 | EXPECT_EQ(kSoftwareTileCutoff, state.memory_limit_policy); |
| 7924 | } |
[email protected] | fd32d12 | 2013-06-29 13:11:04 | [diff] [blame] | 7925 | } |
| 7926 | |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7927 | TEST_F(LayerTreeHostImplTest, RequireHighResWhenVisible) { |
| 7928 | ASSERT_TRUE(host_impl_->active_tree()); |
| 7929 | |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7930 | // RequiresHighResToDraw is set when new output surface is used. |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7931 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7932 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7933 | host_impl_->ResetRequiresHighResToDraw(); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7934 | |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7935 | host_impl_->SetVisible(false); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7936 | EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7937 | host_impl_->SetVisible(true); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7938 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7939 | host_impl_->SetVisible(false); |
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 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7942 | host_impl_->ResetRequiresHighResToDraw(); |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7943 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7944 | EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7945 | host_impl_->SetVisible(true); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7946 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 1060805 | 2014-05-13 21:30:03 | [diff] [blame] | 7947 | } |
| 7948 | |
[email protected] | 13525d6 | 2014-05-20 21:22:04 | [diff] [blame] | 7949 | TEST_F(LayerTreeHostImplTest, RequireHighResAfterGpuRasterizationToggles) { |
| 7950 | ASSERT_TRUE(host_impl_->active_tree()); |
| 7951 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 7952 | |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7953 | // RequiresHighResToDraw is set when new output surface is used. |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7954 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7955 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7956 | host_impl_->ResetRequiresHighResToDraw(); |
sohan.jyoti | 9d1e420 | 2014-09-23 21:02:33 | [diff] [blame] | 7957 | |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 7958 | host_impl_->SetContentIsSuitableForGpuRasterization(true); |
| 7959 | host_impl_->SetHasGpuRasterizationTrigger(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 7960 | host_impl_->CommitComplete(); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7961 | EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 7962 | host_impl_->SetHasGpuRasterizationTrigger(true); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 7963 | host_impl_->CommitComplete(); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7964 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 7965 | host_impl_->SetHasGpuRasterizationTrigger(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 7966 | host_impl_->CommitComplete(); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7967 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 13525d6 | 2014-05-20 21:22:04 | [diff] [blame] | 7968 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7969 | host_impl_->ResetRequiresHighResToDraw(); |
[email protected] | 13525d6 | 2014-05-20 21:22:04 | [diff] [blame] | 7970 | |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7971 | EXPECT_FALSE(host_impl_->RequiresHighResToDraw()); |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 7972 | host_impl_->SetHasGpuRasterizationTrigger(true); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 7973 | host_impl_->CommitComplete(); |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 7974 | EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); |
[email protected] | 13525d6 | 2014-05-20 21:22:04 | [diff] [blame] | 7975 | } |
| 7976 | |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 7977 | class LayerTreeHostImplTestPrepareTiles : public LayerTreeHostImplTest { |
[email protected] | 222c678 | 2013-09-05 22:24:49 | [diff] [blame] | 7978 | public: |
danakj | aeb9506 | 2014-11-14 01:35:36 | [diff] [blame] | 7979 | void SetUp() override { |
danakj | 431a120 | 2015-06-17 19:09:33 | [diff] [blame] | 7980 | fake_host_impl_ = |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7981 | new FakeLayerTreeHostImpl(LayerTreeSettings(), &task_runner_provider_, |
danakj | 431a120 | 2015-06-17 19:09:33 | [diff] [blame] | 7982 | &shared_bitmap_manager_, &task_graph_runner_); |
[email protected] | 222c678 | 2013-09-05 22:24:49 | [diff] [blame] | 7983 | host_impl_.reset(fake_host_impl_); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7984 | output_surface_ = CreateOutputSurface(); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7985 | host_impl_->SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 7986 | host_impl_->InitializeRenderer(output_surface_.get()); |
[email protected] | 222c678 | 2013-09-05 22:24:49 | [diff] [blame] | 7987 | host_impl_->SetViewportSize(gfx::Size(10, 10)); |
| 7988 | } |
| 7989 | |
| 7990 | FakeLayerTreeHostImpl* fake_host_impl_; |
| 7991 | }; |
| 7992 | |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 7993 | TEST_F(LayerTreeHostImplTestPrepareTiles, PrepareTilesWhenInvisible) { |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 7994 | EXPECT_TRUE(fake_host_impl_->prepare_tiles_needed()); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7995 | host_impl_->SetVisible(false); |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 7996 | EXPECT_FALSE(fake_host_impl_->prepare_tiles_needed()); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 7997 | host_impl_->SetVisible(true); |
| 7998 | EXPECT_TRUE(fake_host_impl_->prepare_tiles_needed()); |
[email protected] | 222c678 | 2013-09-05 22:24:49 | [diff] [blame] | 7999 | } |
| 8000 | |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8001 | TEST_F(LayerTreeHostImplTest, UIResourceManagement) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8002 | std::unique_ptr<TestWebGraphicsContext3D> context = |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8003 | TestWebGraphicsContext3D::Create(); |
| 8004 | TestWebGraphicsContext3D* context3d = context.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8005 | std::unique_ptr<FakeOutputSurface> output_surface = |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 8006 | FakeOutputSurface::CreateDelegating3d(); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 8007 | CreateHostImpl(DefaultSettings(), std::move(output_surface)); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8008 | |
| 8009 | EXPECT_EQ(0u, context3d->NumTextures()); |
| 8010 | |
| 8011 | UIResourceId ui_resource_id = 1; |
[email protected] | 0046982c | 2014-03-25 22:00:51 | [diff] [blame] | 8012 | bool is_opaque = false; |
| 8013 | UIResourceBitmap bitmap(gfx::Size(1, 1), is_opaque); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8014 | host_impl_->CreateUIResource(ui_resource_id, bitmap); |
| 8015 | EXPECT_EQ(1u, context3d->NumTextures()); |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 8016 | ResourceId id1 = host_impl_->ResourceIdForUIResource(ui_resource_id); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8017 | EXPECT_NE(0u, id1); |
| 8018 | |
| 8019 | // Multiple requests with the same id is allowed. The previous texture is |
| 8020 | // deleted. |
| 8021 | host_impl_->CreateUIResource(ui_resource_id, bitmap); |
| 8022 | EXPECT_EQ(1u, context3d->NumTextures()); |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 8023 | ResourceId id2 = host_impl_->ResourceIdForUIResource(ui_resource_id); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 8024 | EXPECT_NE(0u, id2); |
| 8025 | EXPECT_NE(id1, id2); |
| 8026 | |
| 8027 | // Deleting invalid UIResourceId is allowed and does not change state. |
| 8028 | host_impl_->DeleteUIResource(-1); |
| 8029 | EXPECT_EQ(1u, context3d->NumTextures()); |
| 8030 | |
| 8031 | // Should return zero for invalid UIResourceId. Number of textures should |
| 8032 | // not change. |
| 8033 | EXPECT_EQ(0u, host_impl_->ResourceIdForUIResource(-1)); |
| 8034 | EXPECT_EQ(1u, context3d->NumTextures()); |
| 8035 | |
| 8036 | host_impl_->DeleteUIResource(ui_resource_id); |
| 8037 | EXPECT_EQ(0u, host_impl_->ResourceIdForUIResource(ui_resource_id)); |
| 8038 | EXPECT_EQ(0u, context3d->NumTextures()); |
| 8039 | |
| 8040 | // Should not change state for multiple deletion on one UIResourceId |
| 8041 | host_impl_->DeleteUIResource(ui_resource_id); |
| 8042 | EXPECT_EQ(0u, context3d->NumTextures()); |
| 8043 | } |
| 8044 | |
[email protected] | 6be50ba8 | 2013-11-08 12:04:12 | [diff] [blame] | 8045 | TEST_F(LayerTreeHostImplTest, CreateETC1UIResource) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8046 | std::unique_ptr<TestWebGraphicsContext3D> context = |
[email protected] | 6be50ba8 | 2013-11-08 12:04:12 | [diff] [blame] | 8047 | TestWebGraphicsContext3D::Create(); |
| 8048 | TestWebGraphicsContext3D* context3d = context.get(); |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 8049 | CreateHostImpl(DefaultSettings(), FakeOutputSurface::CreateDelegating3d()); |
[email protected] | 6be50ba8 | 2013-11-08 12:04:12 | [diff] [blame] | 8050 | |
| 8051 | EXPECT_EQ(0u, context3d->NumTextures()); |
| 8052 | |
[email protected] | 80ee233 | 2014-02-06 18:31:07 | [diff] [blame] | 8053 | gfx::Size size(4, 4); |
| 8054 | // SkImageInfo has no support for ETC1. The |info| below contains the right |
| 8055 | // total pixel size for the bitmap but not the right height and width. The |
| 8056 | // correct width/height are passed directly to UIResourceBitmap. |
[email protected] | 7bc1c51 | 2014-01-23 01:15:27 | [diff] [blame] | 8057 | SkImageInfo info = |
[email protected] | 80ee233 | 2014-02-06 18:31:07 | [diff] [blame] | 8058 | SkImageInfo::Make(4, 2, kAlpha_8_SkColorType, kPremul_SkAlphaType); |
tomhudson | 992ec28b | 2016-04-27 16:45:39 | [diff] [blame] | 8059 | sk_sp<SkPixelRef> pixel_ref(SkMallocPixelRef::NewAllocate(info, 0, 0)); |
[email protected] | 7bc1c51 | 2014-01-23 01:15:27 | [diff] [blame] | 8060 | pixel_ref->setImmutable(); |
tomhudson | 992ec28b | 2016-04-27 16:45:39 | [diff] [blame] | 8061 | UIResourceBitmap bitmap(std::move(pixel_ref), size); |
[email protected] | 6be50ba8 | 2013-11-08 12:04:12 | [diff] [blame] | 8062 | UIResourceId ui_resource_id = 1; |
| 8063 | host_impl_->CreateUIResource(ui_resource_id, bitmap); |
| 8064 | EXPECT_EQ(1u, context3d->NumTextures()); |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 8065 | ResourceId id1 = host_impl_->ResourceIdForUIResource(ui_resource_id); |
[email protected] | 6be50ba8 | 2013-11-08 12:04:12 | [diff] [blame] | 8066 | EXPECT_NE(0u, id1); |
| 8067 | } |
| 8068 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8069 | void ShutdownReleasesContext_Callback( |
| 8070 | std::unique_ptr<CopyOutputResult> result) {} |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8071 | |
| 8072 | TEST_F(LayerTreeHostImplTest, ShutdownReleasesContext) { |
| 8073 | scoped_refptr<TestContextProvider> context_provider = |
| 8074 | TestContextProvider::Create(); |
| 8075 | |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 8076 | CreateHostImpl( |
| 8077 | DefaultSettings(), |
| 8078 | base::MakeUnique<TestDelegatingOutputSurface>( |
| 8079 | context_provider, TestContextProvider::CreateWorker(), |
| 8080 | FakeOutputSurface::Create3d(context_provider), nullptr, nullptr, |
| 8081 | RendererSettings(), base::ThreadTaskRunnerHandle::Get().get(), |
danakj | 014316e | 2016-08-04 18:40:26 | [diff] [blame] | 8082 | true /* synchronous_composite */, |
| 8083 | false /* force_disable_reclaim_resources */)); |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8084 | |
| 8085 | SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
| 8086 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8087 | LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing(); |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 8088 | root->test_properties()->copy_requests.push_back( |
| 8089 | CopyOutputRequest::CreateRequest( |
| 8090 | base::Bind(&ShutdownReleasesContext_Callback))); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8091 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8092 | |
| 8093 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8094 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
mithro | 248d172 | 2015-05-05 05:23:45 | [diff] [blame] | 8095 | host_impl_->DrawLayers(&frame); |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8096 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8097 | |
| 8098 | // The CopyOutputResult's callback has a ref on the ContextProvider and a |
| 8099 | // texture in a texture mailbox. |
| 8100 | EXPECT_FALSE(context_provider->HasOneRef()); |
| 8101 | EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); |
| 8102 | |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 8103 | host_impl_->ReleaseOutputSurface(); |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 8104 | host_impl_ = nullptr; |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 8105 | |
| 8106 | // The CopyOutputResult's callback was cancelled, the CopyOutputResult |
| 8107 | // released, and the texture deleted. |
| 8108 | EXPECT_TRUE(context_provider->HasOneRef()); |
| 8109 | EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); |
| 8110 | } |
| 8111 | |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8112 | TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) { |
| 8113 | // When flinging via touch, only the child should scroll (we should not |
| 8114 | // bubble). |
| 8115 | gfx::Size surface_size(10, 10); |
| 8116 | gfx::Size content_size(20, 20); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8117 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 8118 | LayerImpl::Create(host_impl_->active_tree(), 4); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8119 | std::unique_ptr<LayerImpl> root_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8120 | LayerImpl::Create(host_impl_->active_tree(), 3); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8121 | root_clip->test_properties()->force_render_surface = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8122 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8123 | std::unique_ptr<LayerImpl> root_scroll = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8124 | CreateScrollableLayer(1, content_size, root_clip.get()); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8125 | root_scroll->test_properties()->is_container_for_fixed_position_layers = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8126 | std::unique_ptr<LayerImpl> child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8127 | CreateScrollableLayer(2, content_size, root_clip.get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8128 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8129 | root_scroll->test_properties()->AddChild(std::move(child)); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 8130 | int root_id = root_scroll->id(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8131 | root_clip->test_properties()->AddChild(std::move(root_scroll)); |
| 8132 | root_ptr->test_properties()->AddChild(std::move(root_clip)); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8133 | |
| 8134 | host_impl_->SetViewportSize(surface_size); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8135 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
sunxd | 67669657 | 2016-01-07 16:28:30 | [diff] [blame] | 8136 | host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 1, |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 8137 | Layer::INVALID_ID); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8138 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8139 | host_impl_->active_tree()->DidBecomeActive(); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 8140 | DrawFrame(); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8141 | { |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8142 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8143 | host_impl_ |
| 8144 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8145 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8146 | .thread); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8147 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8148 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 8149 | host_impl_->FlingScrollBegin().thread); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8150 | |
| 8151 | gfx::Vector2d scroll_delta(0, 100); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8152 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 8153 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8154 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8155 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8156 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8157 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8158 | host_impl_->ProcessScrollDeltas(); |
| 8159 | |
| 8160 | // Only the child should have scrolled. |
| 8161 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8162 | ExpectNone(*scroll_info.get(), root_id); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8163 | } |
| 8164 | } |
| 8165 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8166 | TEST_F(LayerTreeHostImplTest, TouchFlingShouldContinueScrollingCurrentLayer) { |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8167 | // Scroll a child layer beyond its maximum scroll range and make sure the |
| 8168 | // the scroll doesn't bubble up to the parent layer. |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8169 | gfx::Size surface_size(10, 10); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8170 | std::unique_ptr<LayerImpl> root = |
| 8171 | LayerImpl::Create(host_impl_->active_tree(), 1); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8172 | root->test_properties()->force_render_surface = true; |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8173 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8174 | std::unique_ptr<LayerImpl> root_scrolling_owned = |
| 8175 | CreateScrollableLayer(2, surface_size, root.get()); |
| 8176 | auto* root_scrolling = root_scrolling_owned.get(); |
| 8177 | root->test_properties()->AddChild(std::move(root_scrolling_owned)); |
| 8178 | |
| 8179 | std::unique_ptr<LayerImpl> child_owned = |
| 8180 | CreateScrollableLayer(3, surface_size, root.get()); |
| 8181 | auto* child = child_owned.get(); |
| 8182 | root_scrolling->test_properties()->AddChild(std::move(child_owned)); |
| 8183 | |
| 8184 | std::unique_ptr<LayerImpl> grand_child_owned = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8185 | CreateScrollableLayer(4, surface_size, root.get()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8186 | auto* grand_child = grand_child_owned.get(); |
| 8187 | child->test_properties()->AddChild(std::move(grand_child_owned)); |
| 8188 | |
| 8189 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
| 8190 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 8191 | host_impl_->active_tree()->DidBecomeActive(); |
| 8192 | |
| 8193 | child->layer_tree_impl() |
| 8194 | ->property_trees() |
| 8195 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(child->id(), |
| 8196 | gfx::ScrollOffset(0, 4)); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 8197 | grand_child->layer_tree_impl() |
| 8198 | ->property_trees() |
| 8199 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(grand_child->id(), |
| 8200 | gfx::ScrollOffset(0, 2)); |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8201 | |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8202 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 8203 | DrawFrame(); |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8204 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8205 | std::unique_ptr<ScrollAndScaleSet> scroll_info; |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 8206 | LayerImpl* child = host_impl_->active_tree() |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8207 | ->root_layer_for_testing() |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 8208 | ->test_properties() |
| 8209 | ->children[0] |
| 8210 | ->test_properties() |
| 8211 | ->children[0]; |
| 8212 | LayerImpl* grand_child = child->test_properties()->children[0]; |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8213 | |
| 8214 | gfx::Vector2d scroll_delta(0, -2); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8215 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8216 | host_impl_ |
| 8217 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8218 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8219 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8220 | EXPECT_TRUE( |
| 8221 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 8222 | .did_scroll); |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8223 | |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8224 | // The grand child should have scrolled up to its limit. |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8225 | scroll_info = host_impl_->ProcessScrollDeltas(); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8226 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 8227 | EXPECT_TRUE( |
| 8228 | ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8229 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
| 8230 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8231 | // The locked scrolling layer should remain set as the grand child. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8232 | EXPECT_FALSE( |
| 8233 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 8234 | .did_scroll); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8235 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8236 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 8237 | EXPECT_TRUE( |
| 8238 | ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8239 | ExpectNone(*scroll_info, child->id()); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8240 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
| 8241 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8242 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 8243 | host_impl_->FlingScrollBegin().thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8244 | EXPECT_FALSE( |
| 8245 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 8246 | .did_scroll); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8247 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8248 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8249 | // The child should not have scrolled. |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8250 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8251 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 8252 | EXPECT_TRUE( |
| 8253 | ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8254 | ExpectNone(*scroll_info, child->id()); |
[email protected] | db10261 | 2013-12-20 22:04:12 | [diff] [blame] | 8255 | |
| 8256 | // As the locked layer is at it's limit, no further scrolling can occur. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8257 | EXPECT_FALSE( |
| 8258 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 8259 | .did_scroll); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8260 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8261 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | d41d7cb9 | 2013-10-15 16:08:09 | [diff] [blame] | 8262 | } |
| 8263 | } |
| 8264 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8265 | TEST_F(LayerTreeHostImplTest, WheelFlingShouldntBubble) { |
| 8266 | // When flinging via wheel, we shouldn't bubble. |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8267 | gfx::Size surface_size(10, 10); |
| 8268 | gfx::Size content_size(20, 20); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8269 | std::unique_ptr<LayerImpl> root_clip = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8270 | LayerImpl::Create(host_impl_->active_tree(), 3); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8271 | root_clip->test_properties()->force_render_surface = true; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8272 | std::unique_ptr<LayerImpl> root_scroll = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8273 | CreateScrollableLayer(1, content_size, root_clip.get()); |
| 8274 | int root_scroll_id = root_scroll->id(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8275 | std::unique_ptr<LayerImpl> child = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8276 | CreateScrollableLayer(2, content_size, root_clip.get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8277 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8278 | root_scroll->test_properties()->AddChild(std::move(child)); |
| 8279 | root_clip->test_properties()->AddChild(std::move(root_scroll)); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8280 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8281 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_clip)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8282 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8283 | host_impl_->active_tree()->DidBecomeActive(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8284 | |
| 8285 | host_impl_->SetViewportSize(surface_size); |
[email protected] | ce2e811 | 2013-11-28 07:44:36 | [diff] [blame] | 8286 | DrawFrame(); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8287 | { |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8288 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8289 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8290 | InputHandler::WHEEL) |
| 8291 | .thread); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8292 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8293 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 8294 | host_impl_->FlingScrollBegin().thread); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8295 | |
| 8296 | gfx::Vector2d scroll_delta(0, 100); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8297 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 8298 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8299 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8300 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8301 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8302 | std::unique_ptr<ScrollAndScaleSet> scroll_info = |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8303 | host_impl_->ProcessScrollDeltas(); |
| 8304 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 8305 | // The root shouldn't have scrolled. |
| 8306 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
| 8307 | ExpectNone(*scroll_info.get(), root_scroll_id); |
[email protected] | df0c4234 | 2013-10-08 20:52:12 | [diff] [blame] | 8308 | } |
| 8309 | } |
| 8310 | |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8311 | TEST_F(LayerTreeHostImplTest, ScrollUnknownNotOnAncestorChain) { |
| 8312 | // 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] | 8313 | // we should return SCROLL_UNKNOWN. |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8314 | gfx::Size content_size(100, 100); |
| 8315 | SetupScrollAndContentsLayers(content_size); |
| 8316 | |
| 8317 | int scroll_layer_id = 2; |
| 8318 | LayerImpl* scroll_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8319 | host_impl_->active_tree()->LayerById(scroll_layer_id); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8320 | scroll_layer->SetDrawsContent(true); |
| 8321 | |
| 8322 | int page_scale_layer_id = 5; |
| 8323 | LayerImpl* page_scale_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8324 | host_impl_->active_tree()->LayerById(page_scale_layer_id); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8325 | |
| 8326 | int occluder_layer_id = 6; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8327 | std::unique_ptr<LayerImpl> occluder_layer = |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8328 | LayerImpl::Create(host_impl_->active_tree(), occluder_layer_id); |
| 8329 | occluder_layer->SetDrawsContent(true); |
| 8330 | occluder_layer->SetBounds(content_size); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8331 | occluder_layer->SetPosition(gfx::PointF()); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8332 | |
| 8333 | // The parent of the occluder is *above* the scroller. |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8334 | page_scale_layer->test_properties()->AddChild(std::move(occluder_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8335 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8336 | |
| 8337 | DrawFrame(); |
| 8338 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8339 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 8340 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 8341 | EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 8342 | EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8343 | status.main_thread_scrolling_reasons); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8344 | } |
| 8345 | |
| 8346 | TEST_F(LayerTreeHostImplTest, ScrollUnknownScrollAncestorMismatch) { |
| 8347 | // If we ray cast a scroller this is on the first layer's ancestor chain, but |
| 8348 | // is not the first scroller we encounter when walking up from the layer, we |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8349 | // should also return SCROLL_UNKNOWN. |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8350 | gfx::Size content_size(100, 100); |
| 8351 | SetupScrollAndContentsLayers(content_size); |
| 8352 | |
| 8353 | int scroll_layer_id = 2; |
| 8354 | LayerImpl* scroll_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8355 | host_impl_->active_tree()->LayerById(scroll_layer_id); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8356 | scroll_layer->SetDrawsContent(true); |
| 8357 | |
| 8358 | int occluder_layer_id = 6; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8359 | std::unique_ptr<LayerImpl> occluder_layer = |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8360 | LayerImpl::Create(host_impl_->active_tree(), occluder_layer_id); |
| 8361 | occluder_layer->SetDrawsContent(true); |
| 8362 | occluder_layer->SetBounds(content_size); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8363 | occluder_layer->SetPosition(gfx::PointF(-10.f, -10.f)); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8364 | |
| 8365 | int child_scroll_clip_layer_id = 7; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8366 | std::unique_ptr<LayerImpl> child_scroll_clip = |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8367 | LayerImpl::Create(host_impl_->active_tree(), child_scroll_clip_layer_id); |
| 8368 | |
| 8369 | int child_scroll_layer_id = 8; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8370 | std::unique_ptr<LayerImpl> child_scroll = CreateScrollableLayer( |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8371 | child_scroll_layer_id, content_size, child_scroll_clip.get()); |
| 8372 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8373 | child_scroll->SetPosition(gfx::PointF(10.f, 10.f)); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8374 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8375 | child_scroll->test_properties()->AddChild(std::move(occluder_layer)); |
| 8376 | child_scroll_clip->test_properties()->AddChild(std::move(child_scroll)); |
| 8377 | scroll_layer->test_properties()->AddChild(std::move(child_scroll_clip)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8378 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8379 | |
| 8380 | DrawFrame(); |
| 8381 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8382 | InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 8383 | BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 8384 | EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 8385 | EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8386 | status.main_thread_scrolling_reasons); |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 8387 | } |
| 8388 | |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8389 | TEST_F(LayerTreeHostImplTest, NotScrollInvisibleScroller) { |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8390 | gfx::Size content_size(100, 100); |
| 8391 | SetupScrollAndContentsLayers(content_size); |
| 8392 | |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8393 | LayerImpl* root = host_impl_->active_tree()->LayerById(1); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8394 | |
| 8395 | int scroll_layer_id = 2; |
| 8396 | LayerImpl* scroll_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8397 | host_impl_->active_tree()->LayerById(scroll_layer_id); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8398 | |
| 8399 | int child_scroll_layer_id = 7; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8400 | std::unique_ptr<LayerImpl> child_scroll = |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8401 | CreateScrollableLayer(child_scroll_layer_id, content_size, root); |
| 8402 | child_scroll->SetDrawsContent(false); |
| 8403 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8404 | scroll_layer->test_properties()->AddChild(std::move(child_scroll)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8405 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8406 | |
| 8407 | DrawFrame(); |
| 8408 | |
| 8409 | // We should not have scrolled |child_scroll| even though we technically "hit" |
| 8410 | // it. The reason for this is that if the scrolling the scroll would not move |
| 8411 | // any layer that is a drawn RSLL member, then we can ignore the hit. |
| 8412 | // |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8413 | // Why SCROLL_STARTED? In this case, it's because we've bubbled out and |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8414 | // started scrolling the inner viewport. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8415 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8416 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8417 | InputHandler::WHEEL) |
| 8418 | .thread); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8419 | |
| 8420 | EXPECT_EQ(2, host_impl_->CurrentlyScrollingLayer()->id()); |
| 8421 | } |
| 8422 | |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8423 | TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleDescendent) { |
| 8424 | gfx::Size content_size(100, 100); |
| 8425 | SetupScrollAndContentsLayers(content_size); |
| 8426 | |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8427 | LayerImpl* root = host_impl_->active_tree()->LayerById(1); |
| 8428 | LayerImpl* root_scroll_layer = host_impl_->active_tree()->LayerById(2); |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8429 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8430 | std::unique_ptr<LayerImpl> invisible_scroll_layer = |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8431 | CreateScrollableLayer(7, content_size, root); |
| 8432 | invisible_scroll_layer->SetDrawsContent(false); |
| 8433 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8434 | std::unique_ptr<LayerImpl> child_layer = |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8435 | LayerImpl::Create(host_impl_->active_tree(), 8); |
| 8436 | child_layer->SetDrawsContent(false); |
| 8437 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8438 | std::unique_ptr<LayerImpl> grand_child_layer = |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8439 | LayerImpl::Create(host_impl_->active_tree(), 9); |
| 8440 | grand_child_layer->SetDrawsContent(true); |
| 8441 | grand_child_layer->SetBounds(content_size); |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8442 | // Move the grand child so it's not hit by our test point. |
| 8443 | grand_child_layer->SetPosition(gfx::PointF(10.f, 10.f)); |
| 8444 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8445 | child_layer->test_properties()->AddChild(std::move(grand_child_layer)); |
| 8446 | invisible_scroll_layer->test_properties()->AddChild(std::move(child_layer)); |
| 8447 | root_scroll_layer->test_properties()->AddChild( |
| 8448 | std::move(invisible_scroll_layer)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8449 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8450 | |
| 8451 | DrawFrame(); |
| 8452 | |
| 8453 | // We should have scrolled |invisible_scroll_layer| as it was hit and it has |
| 8454 | // a descendant which is a drawn RSLL member. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8455 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8456 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8457 | InputHandler::WHEEL) |
| 8458 | .thread); |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8459 | |
| 8460 | EXPECT_EQ(7, host_impl_->CurrentlyScrollingLayer()->id()); |
| 8461 | } |
| 8462 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8463 | TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleScrollChild) { |
| 8464 | // This test case is very similar to the one above with one key difference: |
| 8465 | // the invisible scroller has a scroll child that is indeed draw contents. |
| 8466 | // If we attempt to initiate a gesture scroll off of the visible scroll child |
| 8467 | // we should still start the scroll child. |
| 8468 | gfx::Size content_size(100, 100); |
| 8469 | SetupScrollAndContentsLayers(content_size); |
| 8470 | |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8471 | LayerImpl* root = host_impl_->active_tree()->LayerById(1); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8472 | |
| 8473 | int scroll_layer_id = 2; |
| 8474 | LayerImpl* scroll_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 8475 | host_impl_->active_tree()->LayerById(scroll_layer_id); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8476 | |
| 8477 | int scroll_child_id = 6; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8478 | std::unique_ptr<LayerImpl> scroll_child = |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8479 | LayerImpl::Create(host_impl_->active_tree(), scroll_child_id); |
| 8480 | scroll_child->SetDrawsContent(true); |
| 8481 | scroll_child->SetBounds(content_size); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8482 | // Move the scroll child so it's not hit by our test point. |
| 8483 | scroll_child->SetPosition(gfx::PointF(10.f, 10.f)); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8484 | |
| 8485 | int invisible_scroll_layer_id = 7; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8486 | std::unique_ptr<LayerImpl> invisible_scroll = |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8487 | CreateScrollableLayer(invisible_scroll_layer_id, content_size, root); |
| 8488 | invisible_scroll->SetDrawsContent(false); |
| 8489 | |
| 8490 | int container_id = 8; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8491 | std::unique_ptr<LayerImpl> container = |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8492 | LayerImpl::Create(host_impl_->active_tree(), container_id); |
| 8493 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8494 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 8495 | new std::set<LayerImpl*>); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8496 | scroll_children->insert(scroll_child.get()); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 8497 | invisible_scroll->test_properties()->scroll_children.reset( |
| 8498 | scroll_children.release()); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8499 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 8500 | scroll_child->test_properties()->scroll_parent = invisible_scroll.get(); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8501 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8502 | container->test_properties()->AddChild(std::move(invisible_scroll)); |
| 8503 | container->test_properties()->AddChild(std::move(scroll_child)); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8504 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 8505 | scroll_layer->test_properties()->AddChild(std::move(container)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8506 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8507 | |
| 8508 | DrawFrame(); |
| 8509 | |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 8510 | // We should have scrolled |child_scroll| even though it is invisible. |
| 8511 | // The reason for this is that if the scrolling the scroll would move a layer |
| 8512 | // that is a drawn RSLL member, then we should accept this hit. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8513 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8514 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8515 | InputHandler::WHEEL) |
| 8516 | .thread); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8517 | |
| 8518 | EXPECT_EQ(7, host_impl_->CurrentlyScrollingLayer()->id()); |
| 8519 | } |
| 8520 | |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8521 | // Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 8522 | // in CompositorFrameMetadata. |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8523 | TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8524 | std::unique_ptr<SolidColorLayerImpl> root = |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8525 | SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8526 | root->SetPosition(gfx::PointF()); |
| 8527 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8528 | root->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8529 | root->test_properties()->force_render_surface = true; |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8530 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8531 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8532 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8533 | |
| 8534 | FakeOutputSurface* fake_output_surface = |
| 8535 | static_cast<FakeOutputSurface*>(host_impl_->output_surface()); |
| 8536 | |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8537 | ui::LatencyInfo latency_info; |
| 8538 | latency_info.AddLatencyNumber( |
| 8539 | ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, 0); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8540 | std::unique_ptr<SwapPromise> swap_promise( |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8541 | new LatencyInfoSwapPromise(latency_info)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 8542 | host_impl_->active_tree()->QueuePinnedSwapPromise(std::move(swap_promise)); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8543 | |
| 8544 | gfx::Rect full_frame_damage(host_impl_->DrawViewportSize()); |
| 8545 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8546 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 8547 | EXPECT_TRUE(host_impl_->DrawLayers(&frame)); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8548 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8549 | |
[email protected] | b76029b | 2014-01-02 22:56:50 | [diff] [blame] | 8550 | const std::vector<ui::LatencyInfo>& metadata_latency_after = |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 8551 | fake_output_surface->last_sent_frame()->metadata.latency_info; |
[email protected] | b76029b | 2014-01-02 22:56:50 | [diff] [blame] | 8552 | EXPECT_EQ(1u, metadata_latency_after.size()); |
| 8553 | EXPECT_TRUE(metadata_latency_after[0].FindLatency( |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 8554 | ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, NULL)); |
| 8555 | } |
| 8556 | |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8557 | TEST_F(LayerTreeHostImplTest, SelectionBoundsPassedToCompositorFrameMetadata) { |
| 8558 | int root_layer_id = 1; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8559 | std::unique_ptr<SolidColorLayerImpl> root = |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8560 | SolidColorLayerImpl::Create(host_impl_->active_tree(), root_layer_id); |
| 8561 | root->SetPosition(gfx::PointF()); |
| 8562 | root->SetBounds(gfx::Size(10, 10)); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8563 | root->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8564 | root->test_properties()->force_render_surface = true; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8565 | |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 8566 | host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8567 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8568 | |
| 8569 | // Ensure the default frame selection bounds are empty. |
| 8570 | FakeOutputSurface* fake_output_surface = |
| 8571 | static_cast<FakeOutputSurface*>(host_impl_->output_surface()); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8572 | |
| 8573 | // Plumb the layer-local selection bounds. |
danakj | a2fdbc70 | 2015-10-20 23:05:24 | [diff] [blame] | 8574 | gfx::Point selection_top(5, 0); |
| 8575 | gfx::Point selection_bottom(5, 5); |
jdduke | 449b529 | 2015-04-23 19:36:44 | [diff] [blame] | 8576 | LayerSelection selection; |
fsamuel | 5ca57df | 2016-06-04 00:34:55 | [diff] [blame] | 8577 | selection.start.type = gfx::SelectionBound::CENTER; |
jdduke | 449b529 | 2015-04-23 19:36:44 | [diff] [blame] | 8578 | selection.start.layer_id = root_layer_id; |
| 8579 | selection.start.edge_bottom = selection_bottom; |
| 8580 | selection.start.edge_top = selection_top; |
| 8581 | selection.end = selection.start; |
| 8582 | host_impl_->active_tree()->RegisterSelection(selection); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8583 | |
| 8584 | // Trigger a draw-swap sequence. |
| 8585 | host_impl_->SetNeedsRedraw(); |
| 8586 | |
| 8587 | gfx::Rect full_frame_damage(host_impl_->DrawViewportSize()); |
| 8588 | LayerTreeHostImpl::FrameData frame; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8589 | EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
danakj | aecfcfba | 2016-09-07 22:33:18 | [diff] [blame] | 8590 | EXPECT_TRUE(host_impl_->DrawLayers(&frame)); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8591 | host_impl_->DidDrawAllLayers(frame); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8592 | |
| 8593 | // Ensure the selection bounds have propagated to the frame metadata. |
fsamuel | 5ca57df | 2016-06-04 00:34:55 | [diff] [blame] | 8594 | const Selection<gfx::SelectionBound>& selection_after = |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 8595 | fake_output_surface->last_sent_frame()->metadata.selection; |
fsamuel | 5ca57df | 2016-06-04 00:34:55 | [diff] [blame] | 8596 | EXPECT_EQ(selection.start.type, selection_after.start.type()); |
| 8597 | EXPECT_EQ(selection.end.type, selection_after.end.type()); |
| 8598 | EXPECT_EQ(gfx::PointF(selection_bottom), selection_after.start.edge_bottom()); |
| 8599 | EXPECT_EQ(gfx::PointF(selection_top), selection_after.start.edge_top()); |
| 8600 | EXPECT_TRUE(selection_after.start.visible()); |
| 8601 | EXPECT_TRUE(selection_after.start.visible()); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 8602 | } |
| 8603 | |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8604 | class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { |
| 8605 | public: |
| 8606 | SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, |
| 8607 | LayerTreeHostImpl* layer_tree_host_impl, |
| 8608 | int* set_needs_commit_count, |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8609 | int* set_needs_redraw_count, |
| 8610 | int* forward_to_main_count) |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8611 | : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), |
| 8612 | set_needs_commit_count_(set_needs_commit_count), |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8613 | set_needs_redraw_count_(set_needs_redraw_count), |
| 8614 | forward_to_main_count_(forward_to_main_count) {} |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8615 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 8616 | ~SimpleSwapPromiseMonitor() override {} |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8617 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 8618 | void OnSetNeedsCommitOnMain() override { (*set_needs_commit_count_)++; } |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8619 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 8620 | void OnSetNeedsRedrawOnImpl() override { (*set_needs_redraw_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 OnForwardScrollUpdateToMainThreadOnImpl() override { |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8623 | (*forward_to_main_count_)++; |
| 8624 | } |
| 8625 | |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8626 | private: |
| 8627 | int* set_needs_commit_count_; |
| 8628 | int* set_needs_redraw_count_; |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8629 | int* forward_to_main_count_; |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8630 | }; |
| 8631 | |
| 8632 | TEST_F(LayerTreeHostImplTest, SimpleSwapPromiseMonitor) { |
| 8633 | int set_needs_commit_count = 0; |
| 8634 | int set_needs_redraw_count = 0; |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8635 | int forward_to_main_count = 0; |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8636 | |
| 8637 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8638 | std::unique_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 8639 | new SimpleSwapPromiseMonitor( |
| 8640 | NULL, host_impl_.get(), &set_needs_commit_count, |
| 8641 | &set_needs_redraw_count, &forward_to_main_count)); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8642 | host_impl_->SetNeedsRedraw(); |
| 8643 | EXPECT_EQ(0, set_needs_commit_count); |
| 8644 | EXPECT_EQ(1, set_needs_redraw_count); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8645 | EXPECT_EQ(0, forward_to_main_count); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8646 | } |
| 8647 | |
| 8648 | // Now the monitor is destroyed, SetNeedsRedraw() is no longer being |
| 8649 | // monitored. |
| 8650 | host_impl_->SetNeedsRedraw(); |
| 8651 | EXPECT_EQ(0, set_needs_commit_count); |
| 8652 | EXPECT_EQ(1, set_needs_redraw_count); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8653 | EXPECT_EQ(0, forward_to_main_count); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8654 | |
| 8655 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8656 | std::unique_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 8657 | new SimpleSwapPromiseMonitor( |
| 8658 | NULL, host_impl_.get(), &set_needs_commit_count, |
| 8659 | &set_needs_redraw_count, &forward_to_main_count)); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8660 | host_impl_->SetNeedsRedrawRect(gfx::Rect(10, 10)); |
| 8661 | EXPECT_EQ(0, set_needs_commit_count); |
| 8662 | EXPECT_EQ(2, set_needs_redraw_count); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8663 | EXPECT_EQ(0, forward_to_main_count); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8664 | } |
| 8665 | |
| 8666 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8667 | std::unique_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 8668 | new SimpleSwapPromiseMonitor( |
| 8669 | NULL, host_impl_.get(), &set_needs_commit_count, |
| 8670 | &set_needs_redraw_count, &forward_to_main_count)); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8671 | // Empty damage rect won't signal the monitor. |
| 8672 | host_impl_->SetNeedsRedrawRect(gfx::Rect()); |
| 8673 | EXPECT_EQ(0, set_needs_commit_count); |
| 8674 | EXPECT_EQ(2, set_needs_redraw_count); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8675 | EXPECT_EQ(0, forward_to_main_count); |
| 8676 | } |
| 8677 | |
| 8678 | { |
| 8679 | set_needs_commit_count = 0; |
| 8680 | set_needs_redraw_count = 0; |
| 8681 | forward_to_main_count = 0; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8682 | std::unique_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 8683 | new SimpleSwapPromiseMonitor( |
| 8684 | NULL, host_impl_.get(), &set_needs_commit_count, |
| 8685 | &set_needs_redraw_count, &forward_to_main_count)); |
dtapuska | f024e55 | 2016-02-03 01:19:46 | [diff] [blame] | 8686 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8687 | |
| 8688 | // Scrolling normally should not trigger any forwarding. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8689 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8690 | host_impl_ |
| 8691 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8692 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8693 | .thread); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 8694 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8695 | host_impl_->ScrollBy( |
| 8696 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()) |
| 8697 | .did_scroll); |
| 8698 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8699 | |
| 8700 | EXPECT_EQ(0, set_needs_commit_count); |
| 8701 | EXPECT_EQ(1, set_needs_redraw_count); |
| 8702 | EXPECT_EQ(0, forward_to_main_count); |
| 8703 | |
| 8704 | // Scrolling with a scroll handler should defer the swap to the main |
| 8705 | // thread. |
dtapuska | f024e55 | 2016-02-03 01:19:46 | [diff] [blame] | 8706 | host_impl_->active_tree()->set_have_scroll_event_handlers(true); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8707 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8708 | host_impl_ |
| 8709 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8710 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8711 | .thread); |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 8712 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8713 | host_impl_->ScrollBy( |
| 8714 | UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get()) |
| 8715 | .did_scroll); |
| 8716 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | dab0a42 | 2014-08-13 16:09:46 | [diff] [blame] | 8717 | |
| 8718 | EXPECT_EQ(0, set_needs_commit_count); |
| 8719 | EXPECT_EQ(2, set_needs_redraw_count); |
| 8720 | EXPECT_EQ(1, forward_to_main_count); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 8721 | } |
| 8722 | } |
| 8723 | |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8724 | class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { |
| 8725 | public: |
danakj | aeb9506 | 2014-11-14 01:35:36 | [diff] [blame] | 8726 | void SetUp() override { |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8727 | LayerTreeSettings settings = DefaultSettings(); |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8728 | CreateHostImpl(settings, CreateOutputSurface()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8729 | host_impl_->active_tree()->set_top_controls_height(top_controls_height_); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 8730 | host_impl_->sync_tree()->set_top_controls_height(top_controls_height_); |
| 8731 | host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f); |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8732 | } |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8733 | |
| 8734 | protected: |
| 8735 | static const int top_controls_height_; |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8736 | }; |
| 8737 | |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8738 | const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50; |
| 8739 | |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8740 | TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 8741 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 8742 | scroll_layer->layer_tree_impl() |
| 8743 | ->property_trees() |
| 8744 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 8745 | gfx::ScrollOffset(0, 10)); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 8746 | BeginFrameArgs begin_frame_args = |
| 8747 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 8748 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 8749 | host_impl_->Animate(); |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8750 | EXPECT_FALSE(did_request_redraw_); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 8751 | host_impl_->DidFinishImplFrame(); |
[email protected] | 68d3fc1 | 2014-02-18 16:31:08 | [diff] [blame] | 8752 | } |
| 8753 | |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8754 | TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsHeightIsCommitted) { |
| 8755 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 8756 | EXPECT_FALSE(did_request_redraw_); |
| 8757 | host_impl_->CreatePendingTree(); |
| 8758 | host_impl_->sync_tree()->set_top_controls_height(100); |
| 8759 | host_impl_->ActivateSyncTree(); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 8760 | EXPECT_EQ(100, host_impl_->top_controls_manager()->TopControlsHeight()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8761 | } |
| 8762 | |
| 8763 | TEST_F(LayerTreeHostImplWithTopControlsTest, |
| 8764 | TopControlsStayFullyVisibleOnHeightChange) { |
| 8765 | SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 8766 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8767 | |
| 8768 | host_impl_->CreatePendingTree(); |
| 8769 | host_impl_->sync_tree()->set_top_controls_height(0); |
| 8770 | host_impl_->ActivateSyncTree(); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 8771 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8772 | |
| 8773 | host_impl_->CreatePendingTree(); |
| 8774 | host_impl_->sync_tree()->set_top_controls_height(50); |
| 8775 | host_impl_->ActivateSyncTree(); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 8776 | EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset()); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 8777 | } |
| 8778 | |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 8779 | TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 8780 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 8781 | scroll_layer->layer_tree_impl() |
| 8782 | ->property_trees() |
| 8783 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 8784 | gfx::ScrollOffset(0, 10)); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 8785 | host_impl_->DidChangeTopControlsPosition(); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8786 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 8787 | EXPECT_TRUE(did_request_redraw_); |
| 8788 | } |
| 8789 | |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8790 | TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8791 | InputHandlerScrollResult result; |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8792 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8793 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 8794 | |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8795 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
bokan | 55b2f15 | 2014-09-15 14:47:59 | [diff] [blame] | 8796 | host_impl_->top_controls_manager()->UpdateTopControlsState( |
| 8797 | BOTH, SHOWN, false); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8798 | DrawFrame(); |
| 8799 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8800 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8801 | host_impl_ |
| 8802 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8803 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8804 | .thread); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8805 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8806 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8807 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8808 | |
| 8809 | // Scroll just the top controls and verify that the scroll succeeds. |
| 8810 | const float residue = 10; |
| 8811 | float offset = top_controls_height_ - residue; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8812 | result = host_impl_->ScrollBy( |
| 8813 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8814 | EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
| 8815 | EXPECT_TRUE(result.did_scroll); |
lof84 | c1f962df | 2015-03-10 19:03:43 | [diff] [blame] | 8816 | EXPECT_FLOAT_EQ(-offset, |
| 8817 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8818 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8819 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8820 | |
| 8821 | // Scroll across the boundary |
| 8822 | const float content_scroll = 20; |
| 8823 | offset = residue + content_scroll; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8824 | result = host_impl_->ScrollBy( |
| 8825 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8826 | EXPECT_TRUE(result.did_scroll); |
| 8827 | EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8828 | EXPECT_EQ(-top_controls_height_, |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8829 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8830 | EXPECT_EQ(gfx::Vector2dF(0, content_scroll).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8831 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8832 | |
| 8833 | // Now scroll back to the top of the content |
| 8834 | offset = -content_scroll; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8835 | result = host_impl_->ScrollBy( |
| 8836 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8837 | EXPECT_TRUE(result.did_scroll); |
| 8838 | EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8839 | EXPECT_EQ(-top_controls_height_, |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8840 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8841 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8842 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8843 | |
| 8844 | // And scroll the top controls completely into view |
| 8845 | offset = -top_controls_height_; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8846 | result = host_impl_->ScrollBy( |
| 8847 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8848 | EXPECT_TRUE(result.did_scroll); |
| 8849 | EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8850 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8851 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8852 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8853 | |
| 8854 | // And attempt to scroll past the end |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8855 | result = host_impl_->ScrollBy( |
| 8856 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); |
tdresser | 7befa9c | 2015-07-16 17:47:28 | [diff] [blame] | 8857 | EXPECT_FALSE(result.did_scroll); |
| 8858 | EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, -50)); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8859 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8860 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8861 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8862 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8863 | host_impl_->ScrollEnd(EndState().get()); |
[email protected] | f42cffb | 2014-03-08 18:03:25 | [diff] [blame] | 8864 | } |
| 8865 | |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8866 | TEST_F(LayerTreeHostImplWithTopControlsTest, WheelUnhandledByTopControls) { |
| 8867 | SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 8868 | host_impl_->SetViewportSize(gfx::Size(50, 100)); |
| 8869 | host_impl_->active_tree()->set_top_controls_shrink_blink_size(true); |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8870 | host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, |
| 8871 | false); |
| 8872 | DrawFrame(); |
| 8873 | |
bokan | 0c33a09 | 2015-07-29 18:27:56 | [diff] [blame] | 8874 | LayerImpl* viewport_layer = host_impl_->InnerViewportScrollLayer(); |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8875 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8876 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8877 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8878 | InputHandler::WHEEL) |
| 8879 | .thread); |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8880 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 8881 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), viewport_layer->CurrentScrollOffset()); |
| 8882 | |
| 8883 | // Wheel scrolls should not affect the top controls, and should pass |
| 8884 | // directly through to the viewport. |
| 8885 | const float delta = top_controls_height_; |
| 8886 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8887 | host_impl_->ScrollBy( |
| 8888 | UpdateState(gfx::Point(), gfx::Vector2d(0, delta)).get()) |
| 8889 | .did_scroll); |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8890 | EXPECT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 8891 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, delta), |
| 8892 | viewport_layer->CurrentScrollOffset()); |
| 8893 | |
| 8894 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8895 | host_impl_->ScrollBy( |
| 8896 | UpdateState(gfx::Point(), gfx::Vector2d(0, delta)).get()) |
| 8897 | .did_scroll); |
jdduke | 7f366ae | 2015-07-17 00:36:02 | [diff] [blame] | 8898 | EXPECT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 8899 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, delta * 2), |
| 8900 | viewport_layer->CurrentScrollOffset()); |
| 8901 | } |
| 8902 | |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8903 | TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { |
| 8904 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8905 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 8906 | |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8907 | host_impl_->SetViewportSize(gfx::Size(100, 200)); |
bokan | 55b2f15 | 2014-09-15 14:47:59 | [diff] [blame] | 8908 | host_impl_->top_controls_manager()->UpdateTopControlsState( |
| 8909 | BOTH, SHOWN, false); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8910 | DrawFrame(); |
| 8911 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8912 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8913 | host_impl_ |
| 8914 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8915 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8916 | .thread); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8917 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8918 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8919 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8920 | |
| 8921 | // Scroll the top controls partially. |
| 8922 | const float residue = 35; |
| 8923 | float offset = top_controls_height_ - residue; |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 8924 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8925 | host_impl_->ScrollBy( |
| 8926 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 8927 | .did_scroll); |
lof84 | c1f962df | 2015-03-10 19:03:43 | [diff] [blame] | 8928 | EXPECT_FLOAT_EQ(-offset, |
| 8929 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8930 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8931 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8932 | |
| 8933 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8934 | did_request_next_frame_ = false; |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8935 | did_request_commit_ = false; |
| 8936 | |
| 8937 | // End the scroll while the controls are still offset from their limit. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 8938 | host_impl_->ScrollEnd(EndState().get()); |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 8939 | ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8940 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8941 | EXPECT_TRUE(did_request_redraw_); |
| 8942 | EXPECT_FALSE(did_request_commit_); |
| 8943 | |
| 8944 | // The top controls should properly animate until finished, despite the scroll |
| 8945 | // offset being at the origin. |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 8946 | BeginFrameArgs begin_frame_args = CreateBeginFrameArgsForTesting( |
| 8947 | BEGINFRAME_FROM_HERE, base::TimeTicks::Now()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8948 | while (did_request_next_frame_) { |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8949 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8950 | did_request_next_frame_ = false; |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8951 | did_request_commit_ = false; |
| 8952 | |
| 8953 | float old_offset = |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8954 | host_impl_->top_controls_manager()->ControlsTopOffset(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8955 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 8956 | begin_frame_args.frame_time += base::TimeDelta::FromMilliseconds(5); |
| 8957 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 8958 | host_impl_->Animate(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8959 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8960 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8961 | |
| 8962 | float new_offset = |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 8963 | host_impl_->top_controls_manager()->ControlsTopOffset(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8964 | |
| 8965 | // No commit is needed as the controls are animating the content offset, |
| 8966 | // not the scroll offset. |
| 8967 | EXPECT_FALSE(did_request_commit_); |
| 8968 | |
| 8969 | if (new_offset != old_offset) |
| 8970 | EXPECT_TRUE(did_request_redraw_); |
| 8971 | |
| 8972 | if (new_offset != 0) { |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 8973 | EXPECT_TRUE(host_impl_->top_controls_manager()->has_animation()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 8974 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8975 | } |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 8976 | host_impl_->DidFinishImplFrame(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8977 | } |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 8978 | EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8979 | } |
| 8980 | |
| 8981 | TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { |
| 8982 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 8983 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 8984 | |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8985 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
bokan | 55b2f15 | 2014-09-15 14:47:59 | [diff] [blame] | 8986 | host_impl_->top_controls_manager()->UpdateTopControlsState( |
| 8987 | BOTH, SHOWN, false); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8988 | float initial_scroll_offset = 50; |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 8989 | scroll_layer->layer_tree_impl() |
| 8990 | ->property_trees() |
| 8991 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 8992 | scroll_layer->id(), gfx::ScrollOffset(0, initial_scroll_offset)); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 8993 | DrawFrame(); |
| 8994 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8995 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 8996 | host_impl_ |
| 8997 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8998 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 8999 | .thread); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 9000 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9001 | EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9002 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9003 | |
| 9004 | // Scroll the top controls partially. |
| 9005 | const float residue = 15; |
| 9006 | float offset = top_controls_height_ - residue; |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 9007 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9008 | host_impl_->ScrollBy( |
| 9009 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 9010 | .did_scroll); |
lof84 | c1f962df | 2015-03-10 19:03:43 | [diff] [blame] | 9011 | EXPECT_FLOAT_EQ(-offset, |
| 9012 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9013 | EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9014 | scroll_layer->CurrentScrollOffset().ToString()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9015 | |
| 9016 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9017 | did_request_next_frame_ = false; |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9018 | did_request_commit_ = false; |
| 9019 | |
| 9020 | // End the scroll while the controls are still offset from the limit. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9021 | host_impl_->ScrollEnd(EndState().get()); |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 9022 | ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9023 | EXPECT_TRUE(did_request_next_frame_); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9024 | EXPECT_TRUE(did_request_redraw_); |
| 9025 | EXPECT_FALSE(did_request_commit_); |
| 9026 | |
| 9027 | // Animate the top controls to the limit. |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9028 | BeginFrameArgs begin_frame_args = CreateBeginFrameArgsForTesting( |
| 9029 | BEGINFRAME_FROM_HERE, base::TimeTicks::Now()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9030 | while (did_request_next_frame_) { |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9031 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9032 | did_request_next_frame_ = false; |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9033 | did_request_commit_ = false; |
| 9034 | |
| 9035 | float old_offset = |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 9036 | host_impl_->top_controls_manager()->ControlsTopOffset(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9037 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9038 | begin_frame_args.frame_time += base::TimeDelta::FromMilliseconds(5); |
| 9039 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 9040 | host_impl_->Animate(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9041 | |
| 9042 | float new_offset = |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 9043 | host_impl_->top_controls_manager()->ControlsTopOffset(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9044 | |
| 9045 | if (new_offset != old_offset) { |
| 9046 | EXPECT_TRUE(did_request_redraw_); |
| 9047 | EXPECT_TRUE(did_request_commit_); |
| 9048 | } |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9049 | host_impl_->DidFinishImplFrame(); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9050 | } |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 9051 | EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation()); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9052 | EXPECT_EQ(-top_controls_height_, |
| 9053 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9054 | } |
| 9055 | |
| 9056 | TEST_F(LayerTreeHostImplWithTopControlsTest, |
| 9057 | TopControlsAnimationAfterMainThreadFlingStopped) { |
| 9058 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9059 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 9060 | |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9061 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 9062 | host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, |
| 9063 | false); |
| 9064 | float initial_scroll_offset = 50; |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 9065 | scroll_layer->layer_tree_impl() |
| 9066 | ->property_trees() |
| 9067 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 9068 | scroll_layer->id(), gfx::ScrollOffset(0, initial_scroll_offset)); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9069 | DrawFrame(); |
| 9070 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9071 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9072 | host_impl_ |
| 9073 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9074 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9075 | .thread); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9076 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9077 | EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
| 9078 | scroll_layer->CurrentScrollOffset().ToString()); |
| 9079 | |
| 9080 | // Scroll the top controls partially. |
| 9081 | const float residue = 15; |
| 9082 | float offset = top_controls_height_ - residue; |
| 9083 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9084 | host_impl_->ScrollBy( |
| 9085 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 9086 | .did_scroll); |
lof84 | c1f962df | 2015-03-10 19:03:43 | [diff] [blame] | 9087 | EXPECT_FLOAT_EQ(-offset, |
| 9088 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9089 | EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
| 9090 | scroll_layer->CurrentScrollOffset().ToString()); |
| 9091 | |
| 9092 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9093 | did_request_next_frame_ = false; |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9094 | did_request_commit_ = false; |
| 9095 | |
| 9096 | // End the fling while the controls are still offset from the limit. |
| 9097 | host_impl_->MainThreadHasStoppedFlinging(); |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 9098 | ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9099 | EXPECT_TRUE(did_request_next_frame_); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9100 | EXPECT_TRUE(did_request_redraw_); |
| 9101 | EXPECT_FALSE(did_request_commit_); |
| 9102 | |
| 9103 | // Animate the top controls to the limit. |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9104 | BeginFrameArgs begin_frame_args = CreateBeginFrameArgsForTesting( |
| 9105 | BEGINFRAME_FROM_HERE, base::TimeTicks::Now()); |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9106 | while (did_request_next_frame_) { |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9107 | did_request_redraw_ = false; |
danakj | a18e826a | 2015-12-03 00:27:03 | [diff] [blame] | 9108 | did_request_next_frame_ = false; |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9109 | did_request_commit_ = false; |
| 9110 | |
| 9111 | float old_offset = host_impl_->top_controls_manager()->ControlsTopOffset(); |
| 9112 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9113 | begin_frame_args.frame_time += base::TimeDelta::FromMilliseconds(5); |
| 9114 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 9115 | host_impl_->Animate(); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9116 | |
| 9117 | float new_offset = host_impl_->top_controls_manager()->ControlsTopOffset(); |
| 9118 | |
| 9119 | if (new_offset != old_offset) { |
| 9120 | EXPECT_TRUE(did_request_redraw_); |
| 9121 | EXPECT_TRUE(did_request_commit_); |
| 9122 | } |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9123 | host_impl_->DidFinishImplFrame(); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9124 | } |
loyso | 8b876b7 | 2016-01-08 04:27:38 | [diff] [blame] | 9125 | EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation()); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 9126 | EXPECT_EQ(-top_controls_height_, |
| 9127 | host_impl_->top_controls_manager()->ControlsTopOffset()); |
[email protected] | ac3446d | 2014-08-13 08:51:20 | [diff] [blame] | 9128 | } |
| 9129 | |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9130 | TEST_F(LayerTreeHostImplWithTopControlsTest, |
| 9131 | TopControlsScrollDeltaInOverScroll) { |
tdresser | 96f4a2b | 2015-07-15 14:11:54 | [diff] [blame] | 9132 | // Verifies that the overscroll delta should not have accumulated in |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9133 | // the top controls if we do a hide and show without releasing finger. |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9134 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9135 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 9136 | |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9137 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 9138 | host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, |
| 9139 | false); |
sunxd | 22ecae6 | 2016-02-11 21:38:12 | [diff] [blame] | 9140 | DrawFrame(); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9141 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9142 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9143 | host_impl_ |
| 9144 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9145 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9146 | .thread); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9147 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9148 | |
| 9149 | float offset = 50; |
| 9150 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9151 | host_impl_->ScrollBy( |
| 9152 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 9153 | .did_scroll); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9154 | EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9155 | EXPECT_EQ(gfx::Vector2dF().ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9156 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9157 | |
| 9158 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9159 | host_impl_->ScrollBy( |
| 9160 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 9161 | .did_scroll); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9162 | EXPECT_EQ(gfx::Vector2dF(0, offset).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9163 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9164 | |
| 9165 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9166 | host_impl_->ScrollBy( |
| 9167 | UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) |
| 9168 | .did_scroll); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9169 | |
| 9170 | // Should have fully scrolled |
| 9171 | EXPECT_EQ(gfx::Vector2dF(0, scroll_layer->MaxScrollOffset().y()).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9172 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9173 | |
| 9174 | float overscrollamount = 10; |
| 9175 | |
| 9176 | // Overscroll the content |
| 9177 | EXPECT_FALSE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9178 | host_impl_->ScrollBy(UpdateState(gfx::Point(), |
| 9179 | gfx::Vector2d(0, overscrollamount)) |
| 9180 | .get()) |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9181 | .did_scroll); |
| 9182 | EXPECT_EQ(gfx::Vector2dF(0, 2 * offset).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9183 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9184 | EXPECT_EQ(gfx::Vector2dF(0, overscrollamount).ToString(), |
| 9185 | host_impl_->accumulated_root_overscroll().ToString()); |
| 9186 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9187 | EXPECT_TRUE(host_impl_->ScrollBy(UpdateState(gfx::Point(), |
| 9188 | gfx::Vector2d(0, -2 * offset)) |
| 9189 | .get()) |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9190 | .did_scroll); |
| 9191 | EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9192 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9193 | EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9194 | |
| 9195 | EXPECT_TRUE( |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9196 | host_impl_->ScrollBy( |
| 9197 | UpdateState(gfx::Point(), gfx::Vector2d(0, -offset)).get()) |
| 9198 | .did_scroll); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9199 | EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9200 | scroll_layer->CurrentScrollOffset().ToString()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9201 | |
| 9202 | // Top controls should be fully visible |
| 9203 | EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 9204 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9205 | host_impl_->ScrollEnd(EndState().get()); |
sujiths.s | 344435e | 2014-11-08 03:04:03 | [diff] [blame] | 9206 | } |
| 9207 | |
bokan | bc115b4 | 2016-08-22 13:46:32 | [diff] [blame] | 9208 | // Tests that when we set a child scroller (e.g. a scrolling div) as the outer |
| 9209 | // viewport, scrolling it controls the top controls. |
| 9210 | TEST_F(LayerTreeHostImplTopControlsTest, |
| 9211 | ReplacedOuterViewportScrollsTopControls) { |
| 9212 | const gfx::Size scroll_content_size(400, 400); |
| 9213 | const gfx::Size root_layer_size(200, 200); |
| 9214 | const gfx::Size viewport_size(100, 100); |
| 9215 | |
| 9216 | SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 9217 | viewport_size, viewport_size, root_layer_size); |
| 9218 | |
| 9219 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9220 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 9221 | LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 9222 | LayerImpl* scroll_layer = nullptr; |
| 9223 | |
| 9224 | // Initialization: Add a child scrolling layer to the outer scroll layer and |
| 9225 | // set its scroll layer as the outer viewport. This simulates setting a |
| 9226 | // scrolling element as the root scroller on the page. |
| 9227 | { |
| 9228 | std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10); |
| 9229 | clip->SetBounds(root_layer_size); |
| 9230 | clip->SetPosition(gfx::PointF()); |
| 9231 | |
| 9232 | std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11); |
| 9233 | scroll->SetBounds(scroll_content_size); |
| 9234 | scroll->SetScrollClipLayer(clip->id()); |
| 9235 | scroll->SetDrawsContent(true); |
| 9236 | |
| 9237 | scroll_layer = scroll.get(); |
| 9238 | |
| 9239 | clip->test_properties()->AddChild(std::move(scroll)); |
| 9240 | outer_scroll->test_properties()->AddChild(std::move(clip)); |
| 9241 | layer_tree_impl->SetViewportLayersFromIds( |
| 9242 | Layer::INVALID_ID, layer_tree_impl->PageScaleLayer()->id(), |
| 9243 | inner_scroll->id(), scroll_layer->id()); |
| 9244 | layer_tree_impl->BuildPropertyTreesForTesting(); |
| 9245 | DrawFrame(); |
| 9246 | } |
| 9247 | |
| 9248 | ASSERT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 9249 | |
| 9250 | // Scrolling should scroll the child content and the top controls. The |
| 9251 | // original outer viewport should get no scroll. |
| 9252 | { |
| 9253 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 9254 | InputHandler::TOUCHSCREEN); |
| 9255 | host_impl_->ScrollBy( |
| 9256 | UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 9257 | host_impl_->ScrollEnd(EndState().get()); |
| 9258 | |
| 9259 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll->CurrentScrollOffset()); |
| 9260 | EXPECT_VECTOR_EQ(gfx::Vector2dF(100.f, 50.f), |
| 9261 | scroll_layer->CurrentScrollOffset()); |
| 9262 | EXPECT_EQ(0.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 9263 | } |
| 9264 | } |
| 9265 | |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9266 | class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { |
| 9267 | public: |
| 9268 | void SetupVirtualViewportLayers(const gfx::Size& content_size, |
| 9269 | const gfx::Size& outer_viewport, |
| 9270 | const gfx::Size& inner_viewport) { |
| 9271 | LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 9272 | const int kOuterViewportClipLayerId = 6; |
| 9273 | const int kOuterViewportScrollLayerId = 7; |
| 9274 | const int kInnerViewportScrollLayerId = 2; |
| 9275 | const int kInnerViewportClipLayerId = 4; |
| 9276 | const int kPageScaleLayerId = 5; |
| 9277 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9278 | std::unique_ptr<LayerImpl> inner_scroll = |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9279 | LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 9280 | inner_scroll->test_properties()->is_container_for_fixed_position_layers = |
| 9281 | true; |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 9282 | inner_scroll->layer_tree_impl() |
| 9283 | ->property_trees() |
| 9284 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(inner_scroll->id(), |
| 9285 | gfx::ScrollOffset()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9286 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9287 | std::unique_ptr<LayerImpl> inner_clip = |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9288 | LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); |
| 9289 | inner_clip->SetBounds(inner_viewport); |
| 9290 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9291 | std::unique_ptr<LayerImpl> page_scale = |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9292 | LayerImpl::Create(layer_tree_impl, kPageScaleLayerId); |
| 9293 | |
| 9294 | inner_scroll->SetScrollClipLayer(inner_clip->id()); |
| 9295 | inner_scroll->SetBounds(outer_viewport); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9296 | inner_scroll->SetPosition(gfx::PointF()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9297 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9298 | std::unique_ptr<LayerImpl> outer_clip = |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9299 | LayerImpl::Create(layer_tree_impl, kOuterViewportClipLayerId); |
| 9300 | outer_clip->SetBounds(outer_viewport); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 9301 | outer_clip->test_properties()->is_container_for_fixed_position_layers = |
| 9302 | true; |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9303 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9304 | std::unique_ptr<LayerImpl> outer_scroll = |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9305 | LayerImpl::Create(layer_tree_impl, kOuterViewportScrollLayerId); |
| 9306 | outer_scroll->SetScrollClipLayer(outer_clip->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 9307 | outer_scroll->layer_tree_impl() |
| 9308 | ->property_trees() |
| 9309 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(outer_scroll->id(), |
| 9310 | gfx::ScrollOffset()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9311 | outer_scroll->SetBounds(content_size); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9312 | outer_scroll->SetPosition(gfx::PointF()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9313 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9314 | std::unique_ptr<LayerImpl> contents = LayerImpl::Create(layer_tree_impl, 8); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9315 | contents->SetDrawsContent(true); |
| 9316 | contents->SetBounds(content_size); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9317 | contents->SetPosition(gfx::PointF()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9318 | |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9319 | outer_scroll->test_properties()->AddChild(std::move(contents)); |
| 9320 | outer_clip->test_properties()->AddChild(std::move(outer_scroll)); |
| 9321 | inner_scroll->test_properties()->AddChild(std::move(outer_clip)); |
| 9322 | page_scale->test_properties()->AddChild(std::move(inner_scroll)); |
| 9323 | inner_clip->test_properties()->AddChild(std::move(page_scale)); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9324 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9325 | inner_clip->test_properties()->force_render_surface = true; |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9326 | layer_tree_impl->SetRootLayerForTesting(std::move(inner_clip)); |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 9327 | layer_tree_impl->SetViewportLayersFromIds( |
| 9328 | Layer::INVALID_ID, kPageScaleLayerId, kInnerViewportScrollLayerId, |
| 9329 | kOuterViewportScrollLayerId); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9330 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9331 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9332 | host_impl_->active_tree()->DidBecomeActive(); |
| 9333 | } |
| 9334 | }; |
| 9335 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 9336 | TEST_F(LayerTreeHostImplVirtualViewportTest, ScrollBothInnerAndOuterLayer) { |
| 9337 | gfx::Size content_size = gfx::Size(100, 160); |
| 9338 | gfx::Size outer_viewport = gfx::Size(50, 80); |
| 9339 | gfx::Size inner_viewport = gfx::Size(25, 40); |
| 9340 | |
| 9341 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
| 9342 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 9343 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9344 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9345 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 9346 | DrawFrame(); |
| 9347 | { |
| 9348 | gfx::ScrollOffset inner_expected; |
| 9349 | gfx::ScrollOffset outer_expected; |
| 9350 | EXPECT_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9351 | EXPECT_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
| 9352 | |
| 9353 | gfx::ScrollOffset current_offset(70.f, 100.f); |
| 9354 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 9355 | host_impl_->SetSynchronousInputHandlerRootScrollOffset(current_offset); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 9356 | EXPECT_EQ(gfx::ScrollOffset(25.f, 40.f), inner_scroll->MaxScrollOffset()); |
| 9357 | EXPECT_EQ(gfx::ScrollOffset(50.f, 80.f), outer_scroll->MaxScrollOffset()); |
| 9358 | |
| 9359 | // Outer viewport scrolls first. Then the rest is applied to the inner |
| 9360 | // viewport. |
| 9361 | EXPECT_EQ(gfx::ScrollOffset(20.f, 20.f), |
| 9362 | inner_scroll->CurrentScrollOffset()); |
| 9363 | EXPECT_EQ(gfx::ScrollOffset(50.f, 80.f), |
| 9364 | outer_scroll->CurrentScrollOffset()); |
| 9365 | } |
| 9366 | } |
| 9367 | |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9368 | TEST_F(LayerTreeHostImplVirtualViewportTest, FlingScrollBubblesToInner) { |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9369 | gfx::Size content_size = gfx::Size(200, 320); |
| 9370 | gfx::Size outer_viewport = gfx::Size(100, 160); |
| 9371 | gfx::Size inner_viewport = gfx::Size(50, 80); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9372 | |
| 9373 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
| 9374 | |
| 9375 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9376 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9377 | |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9378 | DrawFrame(); |
| 9379 | { |
| 9380 | gfx::Vector2dF inner_expected; |
| 9381 | gfx::Vector2dF outer_expected; |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9382 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9383 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9384 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9385 | // Scrolling the viewport always sets the outer scroll layer as the |
| 9386 | // currently scrolling layer. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9387 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9388 | host_impl_ |
| 9389 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9390 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9391 | .thread); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9392 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9393 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9394 | host_impl_->FlingScrollBegin().thread); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9395 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9396 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9397 | gfx::Vector2d scroll_delta(inner_viewport.width() / 2.f, |
| 9398 | inner_viewport.height() / 2.f); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9399 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9400 | inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9401 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9402 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9403 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 9404 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
jdduke | 2491ebe | 2015-08-10 15:41:15 | [diff] [blame] | 9405 | EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9406 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9407 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9408 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9409 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9410 | // Fling past the inner viewport boundry, make sure outer viewport scrolls. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9411 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9412 | host_impl_ |
| 9413 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9414 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9415 | .thread); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9416 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9417 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9418 | host_impl_->FlingScrollBegin().thread); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9419 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9420 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9421 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9422 | inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9423 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9424 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9425 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9426 | outer_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); |
tdresser | a3f3a94 | 2015-09-28 21:15:39 | [diff] [blame] | 9427 | EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9428 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9429 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 9430 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
jdduke | 2491ebe | 2015-08-10 15:41:15 | [diff] [blame] | 9431 | EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9432 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9433 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9434 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
[email protected] | 09a6f2c | 2014-02-20 20:19:14 | [diff] [blame] | 9435 | } |
| 9436 | } |
| 9437 | |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9438 | TEST_F(LayerTreeHostImplVirtualViewportTest, |
| 9439 | DiagonalScrollBubblesPerfectlyToInner) { |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9440 | gfx::Size content_size = gfx::Size(200, 320); |
| 9441 | gfx::Size outer_viewport = gfx::Size(100, 160); |
| 9442 | gfx::Size inner_viewport = gfx::Size(50, 80); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9443 | |
| 9444 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
| 9445 | |
| 9446 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9447 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9448 | |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9449 | DrawFrame(); |
| 9450 | { |
| 9451 | gfx::Vector2dF inner_expected; |
| 9452 | gfx::Vector2dF outer_expected; |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9453 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9454 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9455 | |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9456 | // Make sure the scroll goes to the inner viewport first. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9457 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9458 | host_impl_ |
| 9459 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9460 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9461 | .thread); |
| 9462 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9463 | host_impl_->FlingScrollBegin().thread); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9464 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 9465 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9466 | |
| 9467 | // Scroll near the edge of the outer viewport. |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9468 | gfx::Vector2d scroll_delta(inner_viewport.width() / 2.f, |
| 9469 | inner_viewport.height() / 2.f); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9470 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
bokan | 1f01388f | 2015-09-15 20:55:54 | [diff] [blame] | 9471 | inner_expected += scroll_delta; |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9472 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 9473 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9474 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9475 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9476 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9477 | |
| 9478 | // Now diagonal scroll across the outer viewport boundary in a single event. |
| 9479 | // The entirety of the scroll should be consumed, as bubbling between inner |
| 9480 | // and outer viewport layers is perfect. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9481 | host_impl_->ScrollBy( |
| 9482 | UpdateState(gfx::Point(), gfx::ScaleVector2d(scroll_delta, 2)).get()); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9483 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 9484 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9485 | outer_expected += scroll_delta; |
| 9486 | inner_expected += scroll_delta; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9487 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 9488 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
jdduke | 366df48 | 2015-05-05 01:07:56 | [diff] [blame] | 9489 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9490 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9491 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9492 | EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 9493 | EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
jdduke | a7173dd | 2014-11-19 22:05:28 | [diff] [blame] | 9494 | } |
| 9495 | } |
| 9496 | |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9497 | TEST_F(LayerTreeHostImplVirtualViewportTest, |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9498 | TouchFlingDoesntSwitchScrollingLayer) { |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9499 | gfx::Size content_size = gfx::Size(100, 160); |
| 9500 | gfx::Size outer_viewport = gfx::Size(50, 80); |
| 9501 | gfx::Size inner_viewport = gfx::Size(25, 40); |
| 9502 | |
| 9503 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
| 9504 | |
| 9505 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9506 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 9507 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9508 | std::unique_ptr<LayerImpl> child = |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9509 | CreateScrollableLayer(10, outer_viewport, outer_scroll); |
| 9510 | LayerImpl* child_scroll = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9511 | outer_scroll->test_properties()->children[0]->test_properties()->AddChild( |
| 9512 | std::move(child)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9513 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9514 | |
| 9515 | DrawFrame(); |
| 9516 | { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9517 | std::unique_ptr<ScrollAndScaleSet> scroll_info; |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9518 | |
| 9519 | gfx::Vector2d scroll_delta(0, inner_viewport.height()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9520 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9521 | host_impl_ |
| 9522 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9523 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9524 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9525 | EXPECT_TRUE( |
| 9526 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 9527 | .did_scroll); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9528 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 9529 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9530 | |
| 9531 | // The child should have scrolled up to its limit. |
| 9532 | scroll_info = host_impl_->ProcessScrollDeltas(); |
| 9533 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 9534 | EXPECT_TRUE( |
| 9535 | ScrollInfoContains(*scroll_info, child_scroll->id(), scroll_delta)); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9536 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); |
| 9537 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9538 | // The fling have no effect on the currently scrolling layer. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9539 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9540 | host_impl_->FlingScrollBegin().thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9541 | EXPECT_FALSE( |
| 9542 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 9543 | .did_scroll); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9544 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9545 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 9546 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9547 | |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9548 | // The inner viewport shouldn't have scrolled. |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9549 | scroll_info = host_impl_->ProcessScrollDeltas(); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9550 | ASSERT_EQ(1u, scroll_info->scrolls.size()); |
tdresser | 9997795 | 2015-07-02 19:49:18 | [diff] [blame] | 9551 | EXPECT_TRUE( |
| 9552 | ScrollInfoContains(*scroll_info, child_scroll->id(), scroll_delta)); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9553 | ExpectNone(*scroll_info, inner_scroll->id()); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9554 | |
| 9555 | // As the locked layer is at its limit, no further scrolling can occur. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9556 | EXPECT_FALSE( |
| 9557 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()) |
| 9558 | .did_scroll); |
tdresser | a3b162b8 | 2015-09-29 17:51:43 | [diff] [blame] | 9559 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9560 | host_impl_->ScrollEnd(EndState().get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 9561 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
jdduke | 366df48 | 2015-05-05 01:07:56 | [diff] [blame] | 9562 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9563 | gfx::Point(), InputHandler::TOUCHSCREEN)); |
jdduke | 14ffa6b | 2014-12-06 07:12:40 | [diff] [blame] | 9564 | } |
| 9565 | } |
| 9566 | |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9567 | TEST_F(LayerTreeHostImplVirtualViewportTest, |
| 9568 | ScrollBeginEventThatTargetsViewportLayerSkipsHitTest) { |
| 9569 | gfx::Size content_size = gfx::Size(100, 160); |
| 9570 | gfx::Size outer_viewport = gfx::Size(50, 80); |
| 9571 | gfx::Size inner_viewport = gfx::Size(25, 40); |
| 9572 | |
| 9573 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
| 9574 | |
| 9575 | LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9576 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 9577 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9578 | std::unique_ptr<LayerImpl> child = |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9579 | CreateScrollableLayer(10, outer_viewport, outer_scroll); |
| 9580 | LayerImpl* child_scroll = child.get(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9581 | outer_scroll->test_properties()->children[0]->test_properties()->AddChild( |
| 9582 | std::move(child)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9583 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9584 | |
| 9585 | DrawFrame(); |
| 9586 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9587 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9588 | host_impl_ |
| 9589 | ->RootScrollBegin(BeginState(gfx::Point()).get(), |
| 9590 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9591 | .thread); |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9592 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9593 | host_impl_->ScrollEnd(EndState().get()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9594 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9595 | host_impl_ |
| 9596 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9597 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9598 | .thread); |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9599 | EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9600 | host_impl_->ScrollEnd(EndState().get()); |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 9601 | } |
| 9602 | |
hugo.holgersson | e5e7aa9 | 2015-08-17 14:07:19 | [diff] [blame] | 9603 | TEST_F(LayerTreeHostImplVirtualViewportTest, |
| 9604 | NoOverscrollWhenInnerViewportCantScroll) { |
| 9605 | InputHandlerScrollResult scroll_result; |
| 9606 | gfx::Size content_size = gfx::Size(100, 160); |
| 9607 | gfx::Size outer_viewport = gfx::Size(50, 80); |
| 9608 | gfx::Size inner_viewport = gfx::Size(25, 40); |
| 9609 | SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
hugo.holgersson | e5e7aa9 | 2015-08-17 14:07:19 | [diff] [blame] | 9610 | // Make inner viewport unscrollable. |
| 9611 | LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 9612 | inner_scroll->set_user_scrollable_horizontal(false); |
| 9613 | inner_scroll->set_user_scrollable_vertical(false); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9614 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 9615 | |
sunxd | 2668bea6 | 2016-03-17 00:49:47 | [diff] [blame] | 9616 | DrawFrame(); |
hugo.holgersson | e5e7aa9 | 2015-08-17 14:07:19 | [diff] [blame] | 9617 | |
| 9618 | // Ensure inner viewport doesn't react to scrolls (test it's unscrollable). |
| 9619 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), inner_scroll->CurrentScrollOffset()); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9620 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 9621 | host_impl_ |
| 9622 | ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 9623 | InputHandler::TOUCHSCREEN) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9624 | .thread); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 9625 | scroll_result = host_impl_->ScrollBy( |
| 9626 | UpdateState(gfx::Point(), gfx::Vector2dF(0, 100)).get()); |
hugo.holgersson | e5e7aa9 | 2015-08-17 14:07:19 | [diff] [blame] | 9627 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), inner_scroll->CurrentScrollOffset()); |
| 9628 | |
| 9629 | // When inner viewport is unscrollable, a fling gives zero overscroll. |
| 9630 | EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 9631 | EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
| 9632 | } |
| 9633 | |
[email protected] | 4bb0f31 | 2014-02-25 02:02:32 | [diff] [blame] | 9634 | class LayerTreeHostImplWithImplicitLimitsTest : public LayerTreeHostImplTest { |
| 9635 | public: |
danakj | aeb9506 | 2014-11-14 01:35:36 | [diff] [blame] | 9636 | void SetUp() override { |
[email protected] | 4bb0f31 | 2014-02-25 02:02:32 | [diff] [blame] | 9637 | LayerTreeSettings settings = DefaultSettings(); |
[email protected] | 4bb0f31 | 2014-02-25 02:02:32 | [diff] [blame] | 9638 | settings.max_memory_for_prepaint_percentage = 50; |
| 9639 | CreateHostImpl(settings, CreateOutputSurface()); |
| 9640 | } |
| 9641 | }; |
| 9642 | |
| 9643 | TEST_F(LayerTreeHostImplWithImplicitLimitsTest, ImplicitMemoryLimits) { |
| 9644 | // Set up a memory policy and percentages which could cause |
| 9645 | // 32-bit integer overflows. |
| 9646 | ManagedMemoryPolicy mem_policy(300 * 1024 * 1024); // 300MB |
| 9647 | |
| 9648 | // Verify implicit limits are calculated correctly with no overflows |
| 9649 | host_impl_->SetMemoryPolicy(mem_policy); |
| 9650 | EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, |
| 9651 | 300u * 1024u * 1024u); |
| 9652 | EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, |
| 9653 | 150u * 1024u * 1024u); |
[email protected] | 4bb0f31 | 2014-02-25 02:02:32 | [diff] [blame] | 9654 | } |
| 9655 | |
[email protected] | ea12b550 | 2014-06-24 21:37:36 | [diff] [blame] | 9656 | TEST_F(LayerTreeHostImplTest, ExternalTransformReflectedInNextDraw) { |
| 9657 | const gfx::Size layer_size(100, 100); |
| 9658 | gfx::Transform external_transform; |
| 9659 | const gfx::Rect external_viewport(layer_size); |
[email protected] | c05dfbb | 2014-07-10 22:49:04 | [diff] [blame] | 9660 | const bool resourceless_software_draw = false; |
[email protected] | ea12b550 | 2014-06-24 21:37:36 | [diff] [blame] | 9661 | LayerImpl* layer = SetupScrollAndContentsLayers(layer_size); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 9662 | layer->SetDrawsContent(true); |
[email protected] | ea12b550 | 2014-06-24 21:37:36 | [diff] [blame] | 9663 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9664 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9665 | external_transform); |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9666 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9667 | resourceless_software_draw); |
[email protected] | ea12b550 | 2014-06-24 21:37:36 | [diff] [blame] | 9668 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9669 | external_transform, layer->draw_properties().target_space_transform); |
| 9670 | |
| 9671 | external_transform.Translate(20, 20); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9672 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9673 | external_transform); |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9674 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9675 | resourceless_software_draw); |
[email protected] | ea12b550 | 2014-06-24 21:37:36 | [diff] [blame] | 9676 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9677 | external_transform, layer->draw_properties().target_space_transform); |
| 9678 | } |
| 9679 | |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9680 | TEST_F(LayerTreeHostImplTest, ExternalTransformSetNeedsRedraw) { |
| 9681 | SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9682 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9683 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9684 | const gfx::Size viewport_size(100, 100); |
| 9685 | host_impl_->SetViewportSize(viewport_size); |
| 9686 | |
| 9687 | const gfx::Transform transform_for_tile_priority; |
| 9688 | const gfx::Transform draw_transform; |
| 9689 | const gfx::Rect viewport_for_tile_priority1(viewport_size); |
| 9690 | const gfx::Rect viewport_for_tile_priority2(50, 50); |
| 9691 | const gfx::Rect draw_viewport(viewport_size); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9692 | bool resourceless_software_draw = false; |
| 9693 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9694 | // Clear any damage. |
| 9695 | host_impl_->SetExternalTilePriorityConstraints(viewport_for_tile_priority1, |
| 9696 | transform_for_tile_priority); |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9697 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9698 | last_on_draw_frame_.reset(); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9699 | |
| 9700 | // Setting new constraints needs redraw. |
| 9701 | did_request_redraw_ = false; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9702 | host_impl_->SetExternalTilePriorityConstraints(viewport_for_tile_priority2, |
| 9703 | transform_for_tile_priority); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9704 | EXPECT_TRUE(did_request_redraw_); |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9705 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9706 | EXPECT_FALSE(last_on_draw_frame_->has_no_damage); |
| 9707 | } |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9708 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9709 | TEST_F(LayerTreeHostImplTest, OnDrawConstraintSetNeedsRedraw) { |
| 9710 | SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9711 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9712 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9713 | const gfx::Size viewport_size(100, 100); |
| 9714 | host_impl_->SetViewportSize(viewport_size); |
| 9715 | |
| 9716 | const gfx::Transform draw_transform; |
| 9717 | const gfx::Rect draw_viewport1(viewport_size); |
| 9718 | const gfx::Rect draw_viewport2(50, 50); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9719 | bool resourceless_software_draw = false; |
| 9720 | |
| 9721 | // Clear any damage. |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9722 | host_impl_->OnDraw(draw_transform, draw_viewport1, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9723 | resourceless_software_draw); |
| 9724 | last_on_draw_frame_.reset(); |
| 9725 | |
| 9726 | // Same draw params does not swap. |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9727 | did_request_redraw_ = false; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9728 | host_impl_->OnDraw(draw_transform, draw_viewport1, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9729 | resourceless_software_draw); |
| 9730 | EXPECT_FALSE(did_request_redraw_); |
| 9731 | EXPECT_TRUE(last_on_draw_frame_->has_no_damage); |
| 9732 | last_on_draw_frame_.reset(); |
| 9733 | |
| 9734 | // Different draw params does swap. |
| 9735 | did_request_redraw_ = false; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9736 | host_impl_->OnDraw(draw_transform, draw_viewport2, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9737 | resourceless_software_draw); |
| 9738 | EXPECT_TRUE(did_request_redraw_); |
| 9739 | EXPECT_FALSE(last_on_draw_frame_->has_no_damage); |
| 9740 | } |
| 9741 | |
| 9742 | class ResourcelessSoftwareLayerTreeHostImplTest : public LayerTreeHostImplTest { |
| 9743 | protected: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9744 | std::unique_ptr<OutputSurface> CreateOutputSurface() override { |
danakj | 554c98a | 2016-07-08 00:25:07 | [diff] [blame] | 9745 | return FakeOutputSurface::CreateDelegating3d(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9746 | } |
| 9747 | }; |
| 9748 | |
| 9749 | TEST_F(ResourcelessSoftwareLayerTreeHostImplTest, |
| 9750 | ResourcelessSoftwareSetNeedsRedraw) { |
| 9751 | SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9752 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9753 | |
| 9754 | const gfx::Size viewport_size(100, 100); |
| 9755 | host_impl_->SetViewportSize(viewport_size); |
| 9756 | |
| 9757 | const gfx::Transform draw_transform; |
| 9758 | const gfx::Rect draw_viewport(viewport_size); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9759 | bool resourceless_software_draw = false; |
| 9760 | |
| 9761 | // Clear any damage. |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9762 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9763 | last_on_draw_frame_.reset(); |
| 9764 | |
| 9765 | // Always swap even if same draw params. |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9766 | resourceless_software_draw = true; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9767 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9768 | EXPECT_FALSE(last_on_draw_frame_->has_no_damage); |
| 9769 | last_on_draw_frame_.reset(); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9770 | |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9771 | // Next hardware draw has damage. |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9772 | resourceless_software_draw = false; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9773 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9774 | EXPECT_FALSE(last_on_draw_frame_->has_no_damage); |
boliu | daa9bdb | 2015-10-17 15:11:49 | [diff] [blame] | 9775 | } |
| 9776 | |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9777 | TEST_F(ResourcelessSoftwareLayerTreeHostImplTest, |
| 9778 | ResourcelessSoftwareDrawSkipsUpdateTiles) { |
| 9779 | const gfx::Size viewport_size(100, 100); |
| 9780 | host_impl_->SetViewportSize(viewport_size); |
| 9781 | |
| 9782 | host_impl_->CreatePendingTree(); |
vmpstr | 41d68f88 | 2016-03-30 01:20:23 | [diff] [blame] | 9783 | scoped_refptr<FakeRasterSource> raster_source( |
| 9784 | FakeRasterSource::CreateFilled(viewport_size)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9785 | std::unique_ptr<FakePictureLayerImpl> layer( |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9786 | FakePictureLayerImpl::CreateWithRasterSource(host_impl_->pending_tree(), |
| 9787 | 11, raster_source)); |
| 9788 | layer->SetBounds(viewport_size); |
| 9789 | layer->SetDrawsContent(true); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9790 | host_impl_->pending_tree()->SetRootLayerForTesting(std::move(layer)); |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9791 | |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9792 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9793 | host_impl_->ActivateSyncTree(); |
| 9794 | |
| 9795 | const gfx::Transform draw_transform; |
| 9796 | const gfx::Rect draw_viewport(viewport_size); |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9797 | bool resourceless_software_draw = false; |
| 9798 | |
| 9799 | // Regular draw causes UpdateTiles. |
| 9800 | did_request_prepare_tiles_ = false; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9801 | host_impl_->OnDraw(draw_transform, draw_viewport, resourceless_software_draw); |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9802 | EXPECT_TRUE(did_request_prepare_tiles_); |
| 9803 | host_impl_->PrepareTiles(); |
| 9804 | |
| 9805 | // Resourceless draw skips UpdateTiles. |
| 9806 | const gfx::Rect new_draw_viewport(50, 50); |
| 9807 | resourceless_software_draw = true; |
| 9808 | did_request_prepare_tiles_ = false; |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9809 | host_impl_->OnDraw(draw_transform, new_draw_viewport, |
boliu | 99b904a | 2016-01-26 22:18:01 | [diff] [blame] | 9810 | resourceless_software_draw); |
| 9811 | EXPECT_FALSE(did_request_prepare_tiles_); |
| 9812 | } |
| 9813 | |
boliu | 5a1970d | 2016-02-08 21:58:01 | [diff] [blame] | 9814 | TEST_F(LayerTreeHostImplTest, ExternalTileConstraintReflectedInPendingTree) { |
| 9815 | EXPECT_FALSE(host_impl_->CommitToActiveTree()); |
| 9816 | const gfx::Size layer_size(100, 100); |
| 9817 | host_impl_->SetViewportSize(layer_size); |
| 9818 | bool update_lcd_text = false; |
| 9819 | |
| 9820 | // Set up active and pending tree. |
| 9821 | host_impl_->CreatePendingTree(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 9822 | host_impl_->pending_tree()->SetRootLayerForTesting( |
boliu | 5a1970d | 2016-02-08 21:58:01 | [diff] [blame] | 9823 | LayerImpl::Create(host_impl_->pending_tree(), 1)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9824 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
boliu | 5a1970d | 2016-02-08 21:58:01 | [diff] [blame] | 9825 | host_impl_->pending_tree()->UpdateDrawProperties(update_lcd_text); |
| 9826 | |
| 9827 | host_impl_->ActivateSyncTree(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9828 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
boliu | 5a1970d | 2016-02-08 21:58:01 | [diff] [blame] | 9829 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
| 9830 | |
| 9831 | host_impl_->CreatePendingTree(); |
| 9832 | host_impl_->pending_tree()->UpdateDrawProperties(update_lcd_text); |
| 9833 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
| 9834 | |
| 9835 | EXPECT_FALSE(host_impl_->pending_tree()->needs_update_draw_properties()); |
| 9836 | EXPECT_FALSE(host_impl_->active_tree()->needs_update_draw_properties()); |
| 9837 | |
| 9838 | // Update external constraints should set_needs_update_draw_properties on |
| 9839 | // both trees. |
| 9840 | gfx::Transform external_transform; |
| 9841 | gfx::Rect external_viewport(10, 20); |
| 9842 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9843 | external_transform); |
| 9844 | EXPECT_TRUE(host_impl_->pending_tree()->needs_update_draw_properties()); |
| 9845 | EXPECT_TRUE(host_impl_->active_tree()->needs_update_draw_properties()); |
| 9846 | } |
| 9847 | |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9848 | TEST_F(LayerTreeHostImplTest, ExternalViewportAffectsVisibleRects) { |
| 9849 | const gfx::Size layer_size(100, 100); |
| 9850 | SetupScrollAndContentsLayers(layer_size); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 9851 | LayerImpl* content_layer = host_impl_->active_tree() |
| 9852 | ->OuterViewportScrollLayer() |
| 9853 | ->test_properties() |
| 9854 | ->children[0]; |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9855 | |
| 9856 | bool update_lcd_text = false; |
| 9857 | |
| 9858 | host_impl_->SetViewportSize(gfx::Size(90, 90)); |
| 9859 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
| 9860 | EXPECT_EQ(gfx::Rect(90, 90), content_layer->visible_layer_rect()); |
| 9861 | |
| 9862 | gfx::Transform external_transform; |
| 9863 | gfx::Rect external_viewport(10, 20); |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9864 | bool resourceless_software_draw = false; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9865 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9866 | external_transform); |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9867 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9868 | resourceless_software_draw); |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9869 | EXPECT_EQ(gfx::Rect(10, 20), content_layer->visible_layer_rect()); |
| 9870 | |
| 9871 | // Clear the external viewport. |
| 9872 | external_viewport = gfx::Rect(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9873 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9874 | external_transform); |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9875 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9876 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9877 | resourceless_software_draw); |
ajuma | ed5bee1 | 2015-10-21 13:06:32 | [diff] [blame] | 9878 | EXPECT_EQ(gfx::Rect(90, 90), content_layer->visible_layer_rect()); |
| 9879 | } |
| 9880 | |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9881 | TEST_F(LayerTreeHostImplTest, ExternalTransformAffectsVisibleRects) { |
| 9882 | const gfx::Size layer_size(100, 100); |
| 9883 | SetupScrollAndContentsLayers(layer_size); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 9884 | LayerImpl* content_layer = host_impl_->active_tree() |
| 9885 | ->OuterViewportScrollLayer() |
| 9886 | ->test_properties() |
| 9887 | ->children[0]; |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9888 | |
| 9889 | bool update_lcd_text = false; |
| 9890 | |
| 9891 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 9892 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
| 9893 | EXPECT_EQ(gfx::Rect(50, 50), content_layer->visible_layer_rect()); |
| 9894 | |
| 9895 | gfx::Transform external_transform; |
| 9896 | external_transform.Translate(10, 10); |
| 9897 | external_transform.Scale(2, 2); |
| 9898 | gfx::Rect external_viewport; |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9899 | bool resourceless_software_draw = false; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9900 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9901 | external_transform); |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9902 | |
| 9903 | // Visible rects should now be shifted and scaled because of the external |
| 9904 | // transform. |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9905 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9906 | resourceless_software_draw); |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9907 | EXPECT_EQ(gfx::Rect(20, 20), content_layer->visible_layer_rect()); |
| 9908 | |
| 9909 | // Clear the external transform. |
| 9910 | external_transform = gfx::Transform(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9911 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9912 | external_transform); |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9913 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9914 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9915 | resourceless_software_draw); |
jaydasika | f18cd96 | 2015-10-23 17:29:06 | [diff] [blame] | 9916 | EXPECT_EQ(gfx::Rect(50, 50), content_layer->visible_layer_rect()); |
| 9917 | } |
| 9918 | |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9919 | TEST_F(LayerTreeHostImplTest, ExternalTransformAffectsSublayerScaleFactor) { |
| 9920 | const gfx::Size layer_size(100, 100); |
| 9921 | SetupScrollAndContentsLayers(layer_size); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 9922 | LayerImpl* content_layer = host_impl_->active_tree() |
| 9923 | ->OuterViewportScrollLayer() |
| 9924 | ->test_properties() |
| 9925 | ->children[0]; |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 9926 | content_layer->test_properties()->AddChild( |
| 9927 | LayerImpl::Create(host_impl_->active_tree(), 100)); |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 9928 | LayerImpl* test_layer = host_impl_->active_tree()->LayerById(100); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9929 | test_layer->test_properties()->force_render_surface = true; |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9930 | test_layer->SetDrawsContent(true); |
| 9931 | test_layer->SetBounds(layer_size); |
| 9932 | gfx::Transform perspective_transform; |
| 9933 | perspective_transform.ApplyPerspectiveDepth(2); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 9934 | test_layer->test_properties()->transform = perspective_transform; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 9935 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9936 | |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9937 | bool update_lcd_text = false; |
| 9938 | |
| 9939 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 9940 | host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); |
| 9941 | TransformNode* node = |
| 9942 | host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 9943 | test_layer->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9944 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9945 | |
| 9946 | gfx::Transform external_transform; |
| 9947 | external_transform.Translate(10, 10); |
| 9948 | external_transform.Scale(2, 2); |
| 9949 | gfx::Rect external_viewport; |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9950 | bool resourceless_software_draw = false; |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9951 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9952 | external_transform); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9953 | |
| 9954 | // Transform node's sublayer scale should include the device transform scale. |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9955 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9956 | resourceless_software_draw); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9957 | node = host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 9958 | test_layer->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9959 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9960 | |
| 9961 | // Clear the external transform. |
| 9962 | external_transform = gfx::Transform(); |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9963 | host_impl_->SetExternalTilePriorityConstraints(external_viewport, |
| 9964 | external_transform); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9965 | |
boliu | 31c233ed | 2016-07-29 05:38:59 | [diff] [blame] | 9966 | host_impl_->OnDraw(external_transform, external_viewport, |
boliu | 7097ee5b | 2015-12-17 03:16:09 | [diff] [blame] | 9967 | resourceless_software_draw); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9968 | node = host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 9969 | test_layer->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 9970 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | 049b3fb | 2015-10-23 21:21:57 | [diff] [blame] | 9971 | } |
| 9972 | |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 9973 | TEST_F(LayerTreeHostImplTest, ScrollAnimated) { |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 9974 | const gfx::Size content_size(1000, 1000); |
| 9975 | const gfx::Size viewport_size(50, 100); |
| 9976 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
skobes | de5abdb8 | 2015-10-20 19:16:34 | [diff] [blame] | 9977 | |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 9978 | DrawFrame(); |
| 9979 | |
| 9980 | base::TimeTicks start_time = |
| 9981 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 9982 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9983 | BeginFrameArgs begin_frame_args = |
| 9984 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 9985 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 9986 | EXPECT_EQ( |
| 9987 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9988 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 9989 | |
| 9990 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
skobes | de5abdb8 | 2015-10-20 19:16:34 | [diff] [blame] | 9991 | EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), scrolling_layer); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 9992 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9993 | begin_frame_args.frame_time = start_time; |
| 9994 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 9995 | host_impl_->Animate(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 9996 | host_impl_->UpdateAnimationState(true); |
| 9997 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 9998 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 9999 | host_impl_->DidFinishImplFrame(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10000 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10001 | begin_frame_args.frame_time = |
| 10002 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10003 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10004 | host_impl_->Animate(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10005 | host_impl_->UpdateAnimationState(true); |
| 10006 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 10007 | float y = scrolling_layer->CurrentScrollOffset().y(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10008 | EXPECT_TRUE(y > 1 && y < 49); |
| 10009 | |
[email protected] | 7a7d5be | 2014-07-18 22:37:26 | [diff] [blame] | 10010 | // Update target. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10011 | EXPECT_EQ( |
| 10012 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10013 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10014 | host_impl_->DidFinishImplFrame(); |
[email protected] | 7a7d5be | 2014-07-18 22:37:26 | [diff] [blame] | 10015 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10016 | begin_frame_args.frame_time = |
| 10017 | start_time + base::TimeDelta::FromMilliseconds(200); |
| 10018 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10019 | host_impl_->Animate(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10020 | host_impl_->UpdateAnimationState(true); |
| 10021 | |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 10022 | y = scrolling_layer->CurrentScrollOffset().y(); |
[email protected] | 7a7d5be | 2014-07-18 22:37:26 | [diff] [blame] | 10023 | EXPECT_TRUE(y > 50 && y < 100); |
| 10024 | EXPECT_EQ(scrolling_layer, host_impl_->CurrentlyScrollingLayer()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10025 | host_impl_->DidFinishImplFrame(); |
[email protected] | 7a7d5be | 2014-07-18 22:37:26 | [diff] [blame] | 10026 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10027 | begin_frame_args.frame_time = |
| 10028 | start_time + base::TimeDelta::FromMilliseconds(250); |
| 10029 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10030 | host_impl_->Animate(); |
[email protected] | 7a7d5be | 2014-07-18 22:37:26 | [diff] [blame] | 10031 | host_impl_->UpdateAnimationState(true); |
| 10032 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 10033 | EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 10034 | scrolling_layer->CurrentScrollOffset()); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10035 | EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10036 | host_impl_->DidFinishImplFrame(); |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 10037 | } |
| 10038 | |
sahel | ebcfc33 | 2016-09-01 00:13:37 | [diff] [blame] | 10039 | TEST_F(LayerTreeHostImplTest, SecondScrollAnimatedBeginNotIgnored) { |
| 10040 | const gfx::Size content_size(1000, 1000); |
| 10041 | const gfx::Size viewport_size(50, 100); |
| 10042 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10043 | |
| 10044 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10045 | host_impl_->ScrollAnimatedBegin(gfx::Point()).thread); |
| 10046 | |
| 10047 | // The second ScrollAnimatedBegin should not get ignored. |
| 10048 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10049 | host_impl_->ScrollAnimatedBegin(gfx::Point()).thread); |
| 10050 | } |
| 10051 | |
ymalik | 04da03c | 2016-08-18 18:38:16 | [diff] [blame] | 10052 | // Verfify that a smooth scroll animation doesn't jump when UpdateTarget gets |
| 10053 | // called before the animation is started. |
| 10054 | TEST_F(LayerTreeHostImplTest, AnimatedScrollUpdateTargetBeforeStarting) { |
| 10055 | const gfx::Size content_size(1000, 1000); |
| 10056 | const gfx::Size viewport_size(50, 100); |
| 10057 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10058 | |
| 10059 | DrawFrame(); |
| 10060 | |
| 10061 | base::TimeTicks start_time = |
| 10062 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(200); |
| 10063 | |
| 10064 | BeginFrameArgs begin_frame_args = |
| 10065 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10066 | begin_frame_args.frame_time = start_time; |
| 10067 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10068 | host_impl_->UpdateAnimationState(true); |
| 10069 | host_impl_->DidFinishImplFrame(); |
| 10070 | |
| 10071 | EXPECT_EQ( |
| 10072 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10073 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
| 10074 | // This will call ScrollOffsetAnimationCurve::UpdateTarget while the animation |
| 10075 | // created above is in state ANIMATION::WAITING_FOR_TARGET_AVAILABILITY and |
| 10076 | // doesn't have a start time. |
| 10077 | EXPECT_EQ( |
| 10078 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10079 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 100)).thread); |
| 10080 | |
| 10081 | begin_frame_args.frame_time = |
| 10082 | start_time + base::TimeDelta::FromMilliseconds(250); |
| 10083 | // This is when the animation above gets promoted to STARTING. |
| 10084 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10085 | host_impl_->UpdateAnimationState(true); |
| 10086 | host_impl_->DidFinishImplFrame(); |
| 10087 | |
| 10088 | begin_frame_args.frame_time = |
| 10089 | start_time + base::TimeDelta::FromMilliseconds(300); |
| 10090 | // This is when the animation above gets ticked. |
| 10091 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10092 | host_impl_->UpdateAnimationState(true); |
| 10093 | host_impl_->DidFinishImplFrame(); |
| 10094 | |
| 10095 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10096 | EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), scrolling_layer); |
| 10097 | |
| 10098 | // Verify no jump. |
| 10099 | float y = scrolling_layer->CurrentScrollOffset().y(); |
| 10100 | EXPECT_TRUE(y > 1 && y < 49); |
| 10101 | } |
| 10102 | |
ymalik | ddfc352 | 2016-09-05 18:40:37 | [diff] [blame] | 10103 | TEST_F(LayerTreeHostImplTest, ScrollAnimatedWithDelay) { |
| 10104 | const gfx::Size content_size(1000, 1000); |
| 10105 | const gfx::Size viewport_size(50, 100); |
| 10106 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10107 | |
| 10108 | DrawFrame(); |
| 10109 | |
| 10110 | base::TimeTicks start_time = |
| 10111 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10112 | BeginFrameArgs begin_frame_args = |
| 10113 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10114 | |
| 10115 | // Create animation with a 100ms delay. |
| 10116 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10117 | host_impl_ |
| 10118 | ->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 100), |
| 10119 | base::TimeDelta::FromMilliseconds(100)) |
| 10120 | .thread); |
| 10121 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10122 | EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), scrolling_layer); |
| 10123 | |
| 10124 | // First tick, animation is started. |
| 10125 | begin_frame_args.frame_time = start_time; |
| 10126 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10127 | host_impl_->UpdateAnimationState(true); |
| 10128 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
| 10129 | host_impl_->DidFinishImplFrame(); |
| 10130 | |
| 10131 | // Second tick after 50ms, animation should be half way done since |
| 10132 | // the duration due to delay is 100ms. |
| 10133 | begin_frame_args.frame_time = |
| 10134 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10135 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10136 | host_impl_->UpdateAnimationState(true); |
| 10137 | EXPECT_EQ(50, scrolling_layer->CurrentScrollOffset().y()); |
| 10138 | host_impl_->DidFinishImplFrame(); |
| 10139 | |
| 10140 | // Update target. |
| 10141 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10142 | host_impl_ |
| 10143 | ->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 100), |
| 10144 | base::TimeDelta::FromMilliseconds(150)) |
| 10145 | .thread); |
| 10146 | |
| 10147 | // Third tick after 100ms, should be at the target position since update |
| 10148 | // target was called with a large value of jank. |
| 10149 | begin_frame_args.frame_time = |
| 10150 | start_time + base::TimeDelta::FromMilliseconds(100); |
| 10151 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10152 | host_impl_->UpdateAnimationState(true); |
| 10153 | EXPECT_LT(100, scrolling_layer->CurrentScrollOffset().y()); |
| 10154 | } |
| 10155 | |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10156 | // Test that a smooth scroll offset animation is aborted when followed by a |
| 10157 | // non-smooth scroll offset animation. |
| 10158 | TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedAborted) { |
ymalik | 399b476 | 2016-01-25 16:10:17 | [diff] [blame] | 10159 | const gfx::Size content_size(1000, 1000); |
| 10160 | const gfx::Size viewport_size(500, 500); |
| 10161 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10162 | |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10163 | DrawFrame(); |
| 10164 | |
| 10165 | base::TimeTicks start_time = |
| 10166 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10167 | |
| 10168 | BeginFrameArgs begin_frame_args = |
| 10169 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10170 | |
| 10171 | // Perform animated scroll. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10172 | EXPECT_EQ( |
| 10173 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10174 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10175 | |
| 10176 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10177 | |
| 10178 | begin_frame_args.frame_time = start_time; |
| 10179 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10180 | host_impl_->Animate(); |
| 10181 | host_impl_->UpdateAnimationState(true); |
| 10182 | |
| 10183 | EXPECT_TRUE(host_impl_->animation_host()->HasAnyAnimationTargetingProperty( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10184 | scrolling_layer->element_id(), TargetProperty::SCROLL_OFFSET)); |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10185 | |
| 10186 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
| 10187 | host_impl_->DidFinishImplFrame(); |
| 10188 | |
| 10189 | begin_frame_args.frame_time = |
| 10190 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10191 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10192 | host_impl_->Animate(); |
| 10193 | host_impl_->UpdateAnimationState(true); |
| 10194 | |
| 10195 | float y = scrolling_layer->CurrentScrollOffset().y(); |
| 10196 | EXPECT_TRUE(y > 1 && y < 49); |
| 10197 | |
| 10198 | // Perform instant scroll. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10199 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10200 | host_impl_->ScrollBegin(BeginState(gfx::Point(0, y)).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10201 | InputHandler::WHEEL) |
| 10202 | .thread); |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10203 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(0, y), |
| 10204 | InputHandler::WHEEL)); |
| 10205 | host_impl_->ScrollBy( |
| 10206 | UpdateState(gfx::Point(0, y), gfx::Vector2d(0, 50)).get()); |
| 10207 | EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(0, y + 50), |
| 10208 | InputHandler::WHEEL)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10209 | std::unique_ptr<ScrollState> scroll_state_end = EndState(); |
tdresser | ebe6e34c | 2016-02-10 18:46:06 | [diff] [blame] | 10210 | host_impl_->ScrollEnd(scroll_state_end.get()); |
sahel | 7adc4a7 | 2016-08-25 19:53:49 | [diff] [blame] | 10211 | host_impl_->ClearCurrentlyScrollingLayerForTesting(); |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10212 | EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(), |
| 10213 | InputHandler::WHEEL)); |
| 10214 | |
| 10215 | // The instant scroll should have marked the smooth scroll animation as |
| 10216 | // aborted. |
loyso | db73537f | 2016-03-14 05:07:45 | [diff] [blame] | 10217 | EXPECT_FALSE(host_impl_->animation_host()->HasActiveAnimationForTesting( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10218 | scrolling_layer->element_id())); |
ymalik | 0f419206 | 2016-01-14 17:18:35 | [diff] [blame] | 10219 | |
| 10220 | EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(0, y + 50), |
| 10221 | scrolling_layer->CurrentScrollOffset()); |
| 10222 | EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
| 10223 | host_impl_->DidFinishImplFrame(); |
| 10224 | } |
| 10225 | |
ymalik | 4c34ac55 | 2016-05-26 00:58:29 | [diff] [blame] | 10226 | // Test that a smooth scroll offset animation is marked finished when aborted |
| 10227 | // with the needs_completion flag. The animation is then finished on the |
ymalik | 6581bb3e | 2016-03-01 07:32:07 | [diff] [blame] | 10228 | // main thread. |
| 10229 | TEST_F(LayerTreeHostImplTimelinesTest, |
| 10230 | ScrollAnimatedFinishedByMainThreadScrollingReason) { |
| 10231 | const gfx::Size content_size(1000, 1000); |
| 10232 | const gfx::Size viewport_size(500, 500); |
| 10233 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10234 | |
| 10235 | DrawFrame(); |
| 10236 | |
| 10237 | base::TimeTicks start_time = |
| 10238 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10239 | |
| 10240 | BeginFrameArgs begin_frame_args = |
| 10241 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10242 | |
| 10243 | // Perform animated scroll. |
| 10244 | EXPECT_EQ( |
| 10245 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10246 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 100)).thread); |
| 10247 | |
| 10248 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10249 | |
| 10250 | begin_frame_args.frame_time = start_time; |
| 10251 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10252 | host_impl_->Animate(); |
| 10253 | host_impl_->UpdateAnimationState(true); |
| 10254 | |
| 10255 | EXPECT_TRUE(host_impl_->animation_host()->HasAnyAnimationTargetingProperty( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10256 | scrolling_layer->element_id(), TargetProperty::SCROLL_OFFSET)); |
ymalik | 6581bb3e | 2016-03-01 07:32:07 | [diff] [blame] | 10257 | |
| 10258 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
| 10259 | host_impl_->DidFinishImplFrame(); |
| 10260 | |
| 10261 | begin_frame_args.frame_time = |
| 10262 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10263 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10264 | host_impl_->Animate(); |
| 10265 | host_impl_->UpdateAnimationState(true); |
| 10266 | |
| 10267 | float y = scrolling_layer->CurrentScrollOffset().y(); |
| 10268 | EXPECT_TRUE(y > 1 && y < 49); |
| 10269 | |
ymalik | 4c34ac55 | 2016-05-26 00:58:29 | [diff] [blame] | 10270 | // Abort animation. |
| 10271 | host_impl_->animation_host()->ScrollAnimationAbort(true /*needs_completion*/); |
ymalik | 6581bb3e | 2016-03-01 07:32:07 | [diff] [blame] | 10272 | host_impl_->UpdateAnimationState(true); |
| 10273 | |
ymalik | 4c34ac55 | 2016-05-26 00:58:29 | [diff] [blame] | 10274 | // Aborting with the needs completion param should have marked the smooth |
| 10275 | // scroll animation as finished. |
loyso | db73537f | 2016-03-14 05:07:45 | [diff] [blame] | 10276 | EXPECT_FALSE(host_impl_->animation_host()->HasActiveAnimationForTesting( |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 10277 | scrolling_layer->element_id())); |
ymalik | 6581bb3e | 2016-03-01 07:32:07 | [diff] [blame] | 10278 | EXPECT_TRUE(y > 1 && y < 49); |
| 10279 | EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
| 10280 | host_impl_->DidFinishImplFrame(); |
| 10281 | } |
| 10282 | |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10283 | // Evolved from LayerTreeHostImplTest.ScrollAnimated. |
| 10284 | TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimated) { |
ymalik | 399b476 | 2016-01-25 16:10:17 | [diff] [blame] | 10285 | const gfx::Size content_size(1000, 1000); |
| 10286 | const gfx::Size viewport_size(500, 500); |
| 10287 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10288 | |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10289 | DrawFrame(); |
| 10290 | |
| 10291 | base::TimeTicks start_time = |
| 10292 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10293 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10294 | BeginFrameArgs begin_frame_args = |
| 10295 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10296 | |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10297 | EXPECT_EQ( |
| 10298 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10299 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10300 | |
| 10301 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10302 | begin_frame_args.frame_time = start_time; |
| 10303 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10304 | host_impl_->Animate(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10305 | host_impl_->UpdateAnimationState(true); |
| 10306 | |
| 10307 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10308 | host_impl_->DidFinishImplFrame(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10309 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10310 | begin_frame_args.frame_time = |
| 10311 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10312 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10313 | host_impl_->Animate(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10314 | host_impl_->UpdateAnimationState(true); |
| 10315 | |
| 10316 | float y = scrolling_layer->CurrentScrollOffset().y(); |
| 10317 | EXPECT_TRUE(y > 1 && y < 49); |
| 10318 | |
| 10319 | // Update target. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10320 | EXPECT_EQ( |
| 10321 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10322 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(0, 50)).thread); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10323 | host_impl_->DidFinishImplFrame(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10324 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10325 | begin_frame_args.frame_time = |
| 10326 | start_time + base::TimeDelta::FromMilliseconds(200); |
| 10327 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10328 | host_impl_->Animate(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10329 | host_impl_->UpdateAnimationState(true); |
| 10330 | |
| 10331 | y = scrolling_layer->CurrentScrollOffset().y(); |
| 10332 | EXPECT_TRUE(y > 50 && y < 100); |
| 10333 | EXPECT_EQ(scrolling_layer, host_impl_->CurrentlyScrollingLayer()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10334 | host_impl_->DidFinishImplFrame(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10335 | |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10336 | begin_frame_args.frame_time = |
| 10337 | start_time + base::TimeDelta::FromMilliseconds(250); |
| 10338 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10339 | host_impl_->Animate(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10340 | host_impl_->UpdateAnimationState(true); |
| 10341 | |
| 10342 | EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), |
| 10343 | scrolling_layer->CurrentScrollOffset()); |
| 10344 | EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
danakj | 12e2f6e | 2015-08-19 22:25:44 | [diff] [blame] | 10345 | host_impl_->DidFinishImplFrame(); |
loyso | ce3bb82 | 2015-07-08 02:40:47 | [diff] [blame] | 10346 | } |
| 10347 | |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 10348 | // Test that the scroll delta for an animated scroll is distributed correctly |
| 10349 | // between the inner and outer viewport. |
| 10350 | TEST_F(LayerTreeHostImplTimelinesTest, ImplPinchZoomScrollAnimated) { |
| 10351 | const gfx::Size content_size(200, 200); |
| 10352 | const gfx::Size viewport_size(100, 100); |
| 10353 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10354 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 10355 | |
| 10356 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
| 10357 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 10358 | |
| 10359 | // Zoom into the page by a 2X factor |
| 10360 | float min_page_scale = 1.f, max_page_scale = 4.f; |
| 10361 | float page_scale_factor = 2.f; |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 10362 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
| 10363 | page_scale_factor, min_page_scale, max_page_scale); |
| 10364 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
| 10365 | |
| 10366 | // Scroll by a small amount, there should be no bubbling to the outer |
| 10367 | // viewport. |
| 10368 | base::TimeTicks start_time = |
| 10369 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(250); |
| 10370 | BeginFrameArgs begin_frame_args = |
| 10371 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10372 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10373 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(10.f, 20.f)) |
| 10374 | .thread); |
| 10375 | host_impl_->Animate(); |
| 10376 | host_impl_->UpdateAnimationState(true); |
| 10377 | EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10378 | |
| 10379 | BeginImplFrameAndAnimate(begin_frame_args, start_time); |
| 10380 | EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 10), |
| 10381 | inner_scroll_layer->CurrentScrollOffset()); |
| 10382 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 10383 | outer_scroll_layer->CurrentScrollOffset()); |
| 10384 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll_layer->CurrentScrollOffset()); |
| 10385 | |
| 10386 | // Scroll by the inner viewport's max scroll extent, the remainder |
| 10387 | // should bubble up to the outer viewport. |
| 10388 | EXPECT_EQ( |
| 10389 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10390 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(100.f, 100.f)) |
| 10391 | .thread); |
| 10392 | host_impl_->Animate(); |
| 10393 | host_impl_->UpdateAnimationState(true); |
| 10394 | EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10395 | |
| 10396 | BeginImplFrameAndAnimate(begin_frame_args, |
| 10397 | start_time + base::TimeDelta::FromMilliseconds(350)); |
| 10398 | EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 50), |
| 10399 | inner_scroll_layer->CurrentScrollOffset()); |
| 10400 | EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 10), |
| 10401 | outer_scroll_layer->CurrentScrollOffset()); |
| 10402 | |
| 10403 | // Scroll by the outer viewport's max scroll extent, it should all go to the |
| 10404 | // outer viewport. |
| 10405 | EXPECT_EQ( |
| 10406 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10407 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(190.f, 180.f)) |
| 10408 | .thread); |
| 10409 | host_impl_->Animate(); |
| 10410 | host_impl_->UpdateAnimationState(true); |
| 10411 | EXPECT_EQ(outer_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10412 | |
| 10413 | BeginImplFrameAndAnimate(begin_frame_args, |
| 10414 | start_time + base::TimeDelta::FromMilliseconds(850)); |
| 10415 | EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 50), |
| 10416 | inner_scroll_layer->CurrentScrollOffset()); |
| 10417 | EXPECT_VECTOR_EQ(gfx::Vector2dF(100, 100), |
| 10418 | outer_scroll_layer->CurrentScrollOffset()); |
| 10419 | |
| 10420 | // Scroll upwards by the max scroll extent. The inner viewport should animate |
| 10421 | // and the remainder should bubble to the outer viewport. |
| 10422 | EXPECT_EQ( |
| 10423 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10424 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(-110.f, -120.f)) |
| 10425 | .thread); |
| 10426 | host_impl_->Animate(); |
| 10427 | host_impl_->UpdateAnimationState(true); |
| 10428 | EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10429 | |
| 10430 | BeginImplFrameAndAnimate( |
| 10431 | begin_frame_args, start_time + base::TimeDelta::FromMilliseconds(1200)); |
| 10432 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 10433 | inner_scroll_layer->CurrentScrollOffset()); |
| 10434 | EXPECT_VECTOR_EQ(gfx::Vector2dF(95, 90), |
| 10435 | outer_scroll_layer->CurrentScrollOffset()); |
| 10436 | } |
| 10437 | |
| 10438 | // Test that the correct viewport scroll layer is updated when the target offset |
| 10439 | // is updated. |
| 10440 | TEST_F(LayerTreeHostImplTimelinesTest, ImplPinchZoomScrollAnimatedUpdate) { |
| 10441 | const gfx::Size content_size(200, 200); |
| 10442 | const gfx::Size viewport_size(100, 100); |
| 10443 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10444 | |
| 10445 | LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
| 10446 | LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 10447 | |
| 10448 | // Zoom into the page by a 2X factor |
| 10449 | float min_page_scale = 1.f, max_page_scale = 4.f; |
| 10450 | float page_scale_factor = 2.f; |
ymalik | 99740e85 | 2016-04-07 04:18:13 | [diff] [blame] | 10451 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
| 10452 | page_scale_factor, min_page_scale, max_page_scale); |
| 10453 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
| 10454 | |
| 10455 | // Scroll the inner viewport. |
| 10456 | base::TimeTicks start_time = |
| 10457 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(50); |
| 10458 | BeginFrameArgs begin_frame_args = |
| 10459 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10460 | EXPECT_EQ( |
| 10461 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10462 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(90, 90)).thread); |
| 10463 | host_impl_->Animate(); |
| 10464 | host_impl_->UpdateAnimationState(true); |
| 10465 | EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10466 | |
| 10467 | BeginImplFrameAndAnimate(begin_frame_args, start_time); |
| 10468 | float inner_x = inner_scroll_layer->CurrentScrollOffset().x(); |
| 10469 | float inner_y = inner_scroll_layer->CurrentScrollOffset().y(); |
| 10470 | EXPECT_TRUE(inner_x > 0 && inner_x < 45); |
| 10471 | EXPECT_TRUE(inner_y > 0 && inner_y < 45); |
| 10472 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 10473 | outer_scroll_layer->CurrentScrollOffset()); |
| 10474 | |
| 10475 | // Update target. |
| 10476 | EXPECT_EQ( |
| 10477 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10478 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(50, 50)).thread); |
| 10479 | host_impl_->Animate(); |
| 10480 | host_impl_->UpdateAnimationState(true); |
| 10481 | EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10482 | |
| 10483 | // Verify that all the delta is applied to the inner viewport and nothing is |
| 10484 | // carried forward. |
| 10485 | BeginImplFrameAndAnimate(begin_frame_args, |
| 10486 | start_time + base::TimeDelta::FromMilliseconds(350)); |
| 10487 | EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 50), |
| 10488 | inner_scroll_layer->CurrentScrollOffset()); |
| 10489 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 10490 | outer_scroll_layer->CurrentScrollOffset()); |
| 10491 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll_layer->CurrentScrollOffset()); |
| 10492 | } |
| 10493 | |
ymalik | 399b476 | 2016-01-25 16:10:17 | [diff] [blame] | 10494 | // Test that smooth scroll offset animation doesn't happen for non user |
| 10495 | // scrollable layers. |
| 10496 | TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedNotUserScrollable) { |
| 10497 | const gfx::Size content_size(1000, 1000); |
| 10498 | const gfx::Size viewport_size(500, 500); |
| 10499 | CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 10500 | |
| 10501 | host_impl_->OuterViewportScrollLayer()->set_user_scrollable_vertical(true); |
| 10502 | host_impl_->OuterViewportScrollLayer()->set_user_scrollable_horizontal(false); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10503 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
ymalik | 399b476 | 2016-01-25 16:10:17 | [diff] [blame] | 10504 | |
| 10505 | DrawFrame(); |
| 10506 | |
| 10507 | base::TimeTicks start_time = |
| 10508 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10509 | |
| 10510 | BeginFrameArgs begin_frame_args = |
| 10511 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10512 | |
| 10513 | EXPECT_EQ( |
| 10514 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10515 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(50, 50)).thread); |
| 10516 | |
| 10517 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10518 | begin_frame_args.frame_time = start_time; |
| 10519 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10520 | host_impl_->Animate(); |
| 10521 | host_impl_->UpdateAnimationState(true); |
| 10522 | |
| 10523 | EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); |
| 10524 | host_impl_->DidFinishImplFrame(); |
| 10525 | |
| 10526 | begin_frame_args.frame_time = |
| 10527 | start_time + base::TimeDelta::FromMilliseconds(50); |
| 10528 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10529 | host_impl_->Animate(); |
| 10530 | host_impl_->UpdateAnimationState(true); |
| 10531 | |
| 10532 | // Should not have scrolled horizontally. |
| 10533 | EXPECT_EQ(0, scrolling_layer->CurrentScrollOffset().x()); |
| 10534 | float y = scrolling_layer->CurrentScrollOffset().y(); |
| 10535 | EXPECT_TRUE(y > 1 && y < 49); |
| 10536 | |
| 10537 | // Update target. |
| 10538 | EXPECT_EQ( |
| 10539 | InputHandler::SCROLL_ON_IMPL_THREAD, |
| 10540 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(50, 50)).thread); |
| 10541 | host_impl_->DidFinishImplFrame(); |
| 10542 | |
| 10543 | begin_frame_args.frame_time = |
| 10544 | start_time + base::TimeDelta::FromMilliseconds(200); |
| 10545 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10546 | host_impl_->Animate(); |
| 10547 | host_impl_->UpdateAnimationState(true); |
| 10548 | |
| 10549 | y = scrolling_layer->CurrentScrollOffset().y(); |
| 10550 | EXPECT_TRUE(y > 50 && y < 100); |
| 10551 | EXPECT_EQ(scrolling_layer, host_impl_->CurrentlyScrollingLayer()); |
| 10552 | host_impl_->DidFinishImplFrame(); |
| 10553 | |
| 10554 | begin_frame_args.frame_time = |
| 10555 | start_time + base::TimeDelta::FromMilliseconds(250); |
| 10556 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10557 | host_impl_->Animate(); |
| 10558 | host_impl_->UpdateAnimationState(true); |
| 10559 | |
| 10560 | EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), |
| 10561 | scrolling_layer->CurrentScrollOffset()); |
| 10562 | EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
| 10563 | host_impl_->DidFinishImplFrame(); |
| 10564 | } |
| 10565 | |
skobes | 4d7f47cc8 | 2016-05-04 22:05:41 | [diff] [blame] | 10566 | // Test that smooth scrolls clamp correctly when bounds change mid-animation. |
| 10567 | TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedChangingBounds) { |
| 10568 | const gfx::Size old_content_size(1000, 1000); |
| 10569 | const gfx::Size new_content_size(750, 750); |
| 10570 | const gfx::Size viewport_size(500, 500); |
| 10571 | |
| 10572 | LayerImpl* content_layer = |
| 10573 | CreateBasicVirtualViewportLayers(viewport_size, old_content_size); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10574 | |
skobes | 4d7f47cc8 | 2016-05-04 22:05:41 | [diff] [blame] | 10575 | DrawFrame(); |
| 10576 | |
| 10577 | base::TimeTicks start_time = |
| 10578 | base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
| 10579 | BeginFrameArgs begin_frame_args = |
| 10580 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10581 | |
| 10582 | host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(500, 500)); |
| 10583 | LayerImpl* scrolling_layer = host_impl_->CurrentlyScrollingLayer(); |
| 10584 | |
| 10585 | begin_frame_args.frame_time = start_time; |
| 10586 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10587 | host_impl_->Animate(); |
| 10588 | host_impl_->UpdateAnimationState(true); |
| 10589 | host_impl_->DidFinishImplFrame(); |
| 10590 | |
| 10591 | content_layer->SetBounds(new_content_size); |
| 10592 | scrolling_layer->SetBounds(new_content_size); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10593 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 10594 | |
skobes | 4d7f47cc8 | 2016-05-04 22:05:41 | [diff] [blame] | 10595 | DrawFrame(); |
| 10596 | |
| 10597 | begin_frame_args.frame_time = |
| 10598 | start_time + base::TimeDelta::FromMilliseconds(200); |
| 10599 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10600 | host_impl_->Animate(); |
| 10601 | host_impl_->UpdateAnimationState(true); |
| 10602 | host_impl_->DidFinishImplFrame(); |
| 10603 | |
| 10604 | EXPECT_EQ(gfx::ScrollOffset(250, 250), |
| 10605 | scrolling_layer->CurrentScrollOffset()); |
| 10606 | } |
| 10607 | |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10608 | TEST_F(LayerTreeHostImplTest, InvalidLayerNotAddedToRasterQueue) { |
| 10609 | host_impl_->CreatePendingTree(); |
| 10610 | |
| 10611 | Region empty_invalidation; |
vmpstr | 41d68f88 | 2016-03-30 01:20:23 | [diff] [blame] | 10612 | scoped_refptr<RasterSource> raster_source_with_tiles( |
| 10613 | FakeRasterSource::CreateFilled(gfx::Size(10, 10))); |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10614 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10615 | std::unique_ptr<FakePictureLayerImpl> layer = |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10616 | FakePictureLayerImpl::Create(host_impl_->pending_tree(), 11); |
| 10617 | layer->SetBounds(gfx::Size(10, 10)); |
| 10618 | layer->set_gpu_raster_max_texture_size(host_impl_->device_viewport_size()); |
| 10619 | layer->SetDrawsContent(true); |
vmpstr | 85674026 | 2015-09-24 00:25:25 | [diff] [blame] | 10620 | layer->tilings()->AddTiling(1.0f, raster_source_with_tiles); |
| 10621 | layer->UpdateRasterSource(raster_source_with_tiles, &empty_invalidation, |
| 10622 | nullptr); |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10623 | layer->tilings()->tiling_at(0)->set_resolution( |
| 10624 | TileResolution::HIGH_RESOLUTION); |
| 10625 | layer->tilings()->tiling_at(0)->CreateAllTilesForTesting(); |
vmpstr | cf11133 | 2016-05-04 21:20:43 | [diff] [blame] | 10626 | layer->tilings()->UpdateTilePriorities(gfx::Rect(gfx::Size(10, 10)), 1.f, 1.0, |
| 10627 | Occlusion(), true); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10628 | host_impl_->pending_tree()->SetRootLayerForTesting(std::move(layer)); |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10629 | |
| 10630 | FakePictureLayerImpl* root_layer = static_cast<FakePictureLayerImpl*>( |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10631 | host_impl_->pending_tree()->root_layer_for_testing()); |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10632 | |
| 10633 | root_layer->set_has_valid_tile_priorities(true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10634 | std::unique_ptr<RasterTilePriorityQueue> non_empty_raster_priority_queue_all = |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10635 | host_impl_->BuildRasterQueue(TreePriority::SAME_PRIORITY_FOR_BOTH_TREES, |
| 10636 | RasterTilePriorityQueue::Type::ALL); |
| 10637 | EXPECT_FALSE(non_empty_raster_priority_queue_all->IsEmpty()); |
| 10638 | |
| 10639 | root_layer->set_has_valid_tile_priorities(false); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10640 | std::unique_ptr<RasterTilePriorityQueue> empty_raster_priority_queue_all = |
hendrikw | 72abb58 | 2015-05-08 18:19:53 | [diff] [blame] | 10641 | host_impl_->BuildRasterQueue(TreePriority::SAME_PRIORITY_FOR_BOTH_TREES, |
| 10642 | RasterTilePriorityQueue::Type::ALL); |
| 10643 | EXPECT_TRUE(empty_raster_priority_queue_all->IsEmpty()); |
| 10644 | } |
| 10645 | |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10646 | TEST_F(LayerTreeHostImplTest, DidBecomeActive) { |
| 10647 | host_impl_->CreatePendingTree(); |
| 10648 | host_impl_->ActivateSyncTree(); |
| 10649 | host_impl_->CreatePendingTree(); |
| 10650 | |
| 10651 | LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
| 10652 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10653 | std::unique_ptr<FakePictureLayerImpl> pending_layer = |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10654 | FakePictureLayerImpl::Create(pending_tree, 10); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10655 | FakePictureLayerImpl* raw_pending_layer = pending_layer.get(); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10656 | pending_tree->SetRootLayerForTesting(std::move(pending_layer)); |
jaydasika | bf1875a | 2016-06-28 03:39:59 | [diff] [blame] | 10657 | ASSERT_EQ(raw_pending_layer, pending_tree->root_layer_for_testing()); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10658 | |
| 10659 | EXPECT_EQ(0u, raw_pending_layer->did_become_active_call_count()); |
| 10660 | pending_tree->DidBecomeActive(); |
| 10661 | EXPECT_EQ(1u, raw_pending_layer->did_become_active_call_count()); |
| 10662 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10663 | std::unique_ptr<FakePictureLayerImpl> mask_layer = |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10664 | FakePictureLayerImpl::Create(pending_tree, 11); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10665 | FakePictureLayerImpl* raw_mask_layer = mask_layer.get(); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 10666 | raw_pending_layer->test_properties()->SetMaskLayer(std::move(mask_layer)); |
| 10667 | ASSERT_EQ(raw_mask_layer, raw_pending_layer->test_properties()->mask_layer); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10668 | pending_tree->BuildPropertyTreesForTesting(); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10669 | |
| 10670 | EXPECT_EQ(1u, raw_pending_layer->did_become_active_call_count()); |
| 10671 | EXPECT_EQ(0u, raw_mask_layer->did_become_active_call_count()); |
| 10672 | pending_tree->DidBecomeActive(); |
| 10673 | EXPECT_EQ(2u, raw_pending_layer->did_become_active_call_count()); |
| 10674 | EXPECT_EQ(1u, raw_mask_layer->did_become_active_call_count()); |
| 10675 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10676 | std::unique_ptr<FakePictureLayerImpl> replica_layer = |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10677 | FakePictureLayerImpl::Create(pending_tree, 12); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10678 | std::unique_ptr<FakePictureLayerImpl> replica_mask_layer = |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10679 | FakePictureLayerImpl::Create(pending_tree, 13); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10680 | FakePictureLayerImpl* raw_replica_mask_layer = replica_mask_layer.get(); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 10681 | replica_layer->test_properties()->SetMaskLayer(std::move(replica_mask_layer)); |
| 10682 | raw_pending_layer->test_properties()->SetReplicaLayer( |
| 10683 | std::move(replica_layer)); |
| 10684 | ASSERT_EQ(raw_replica_mask_layer, raw_pending_layer->test_properties() |
| 10685 | ->replica_layer->test_properties() |
| 10686 | ->mask_layer); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 10687 | pending_tree->BuildPropertyTreesForTesting(); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 10688 | |
| 10689 | EXPECT_EQ(2u, raw_pending_layer->did_become_active_call_count()); |
| 10690 | EXPECT_EQ(1u, raw_mask_layer->did_become_active_call_count()); |
| 10691 | EXPECT_EQ(0u, raw_replica_mask_layer->did_become_active_call_count()); |
| 10692 | pending_tree->DidBecomeActive(); |
| 10693 | EXPECT_EQ(3u, raw_pending_layer->did_become_active_call_count()); |
| 10694 | EXPECT_EQ(2u, raw_mask_layer->did_become_active_call_count()); |
| 10695 | EXPECT_EQ(1u, raw_replica_mask_layer->did_become_active_call_count()); |
| 10696 | } |
| 10697 | |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10698 | TEST_F(LayerTreeHostImplTest, WheelScrollWithPageScaleFactorOnInnerLayer) { |
| 10699 | LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 10700 | host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 10701 | DrawFrame(); |
| 10702 | |
| 10703 | EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer()); |
| 10704 | |
| 10705 | float min_page_scale = 1.f, max_page_scale = 4.f; |
| 10706 | float page_scale_factor = 1.f; |
| 10707 | |
| 10708 | // The scroll deltas should have the page scale factor applied. |
| 10709 | { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 10710 | host_impl_->active_tree()->PushPageScaleFromMainThread( |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10711 | page_scale_factor, min_page_scale, max_page_scale); |
danakj | 5ad246cd | 2015-09-12 01:04:50 | [diff] [blame] | 10712 | host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 10713 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10714 | |
| 10715 | float page_scale_delta = 2.f; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 10716 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 10717 | InputHandler::TOUCHSCREEN); |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10718 | host_impl_->PinchGestureBegin(); |
| 10719 | host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); |
| 10720 | host_impl_->PinchGestureEnd(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 10721 | host_impl_->ScrollEnd(EndState().get()); |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10722 | |
| 10723 | gfx::Vector2dF scroll_delta(0, 5); |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10724 | EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 10725 | host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 10726 | InputHandler::WHEEL) |
| 10727 | .thread); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 10728 | EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->CurrentScrollOffset()); |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10729 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 10730 | host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 10731 | host_impl_->ScrollEnd(EndState().get()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 10732 | EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 2.5), |
| 10733 | scroll_layer->CurrentScrollOffset()); |
lanwei | d17d074 | 2014-12-01 18:58:52 | [diff] [blame] | 10734 | } |
| 10735 | } |
| 10736 | |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10737 | class LayerTreeHostImplCountingLostSurfaces : public LayerTreeHostImplTest { |
| 10738 | public: |
| 10739 | LayerTreeHostImplCountingLostSurfaces() : num_lost_surfaces_(0) {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 10740 | void DidLoseOutputSurfaceOnImplThread() override { num_lost_surfaces_++; } |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10741 | |
| 10742 | protected: |
| 10743 | int num_lost_surfaces_; |
| 10744 | }; |
| 10745 | |
| 10746 | TEST_F(LayerTreeHostImplCountingLostSurfaces, TwiceLostSurface) { |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10747 | // Really we just need at least one client notification each time |
| 10748 | // we go from having a valid output surface to not having a valid output |
| 10749 | // surface. |
| 10750 | EXPECT_EQ(0, num_lost_surfaces_); |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10751 | host_impl_->DidLoseOutputSurface(); |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10752 | EXPECT_EQ(1, num_lost_surfaces_); |
| 10753 | host_impl_->DidLoseOutputSurface(); |
dneto | b71e30c | 2014-08-25 23:27:20 | [diff] [blame] | 10754 | EXPECT_LE(1, num_lost_surfaces_); |
[email protected] | 0e0b7fd9 | 2014-08-08 22:53:11 | [diff] [blame] | 10755 | } |
| 10756 | |
danakj | 61902b8 | 2015-10-30 00:30:26 | [diff] [blame] | 10757 | size_t CountRenderPassesWithId(const RenderPassList& list, RenderPassId id) { |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10758 | return std::count_if( |
| 10759 | list.begin(), list.end(), |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10760 | [id](const std::unique_ptr<RenderPass>& p) { return p->id == id; }); |
danakj | 61902b8 | 2015-10-30 00:30:26 | [diff] [blame] | 10761 | } |
| 10762 | |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10763 | TEST_F(LayerTreeHostImplTest, RemoveUnreferencedRenderPass) { |
| 10764 | LayerTreeHostImpl::FrameData frame; |
| 10765 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10766 | RenderPass* pass3 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10767 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10768 | RenderPass* pass2 = 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* pass1 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10771 | |
| 10772 | pass1->SetNew(RenderPassId(1, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10773 | pass2->SetNew(RenderPassId(2, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10774 | pass3->SetNew(RenderPassId(3, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10775 | |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10776 | // Add a quad to each pass so they aren't empty. |
| 10777 | SolidColorDrawQuad* color_quad; |
| 10778 | color_quad = pass1->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 10779 | color_quad->material = DrawQuad::SOLID_COLOR; |
| 10780 | color_quad = pass2->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 10781 | color_quad->material = DrawQuad::SOLID_COLOR; |
| 10782 | color_quad = pass3->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 10783 | color_quad->material = DrawQuad::SOLID_COLOR; |
| 10784 | |
| 10785 | // pass3 is referenced by pass2. |
| 10786 | RenderPassDrawQuad* rpdq = |
| 10787 | pass2->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 10788 | rpdq->material = DrawQuad::RENDER_PASS; |
| 10789 | rpdq->render_pass_id = pass3->id; |
| 10790 | |
| 10791 | // But pass2 is not referenced by pass1. So pass2 and pass3 should be culled. |
| 10792 | FakeLayerTreeHostImpl::RemoveRenderPasses(&frame); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10793 | EXPECT_EQ(1u, frame.render_passes.size()); |
danakj | 61902b8 | 2015-10-30 00:30:26 | [diff] [blame] | 10794 | EXPECT_EQ(1u, |
| 10795 | CountRenderPassesWithId(frame.render_passes, RenderPassId(1, 0))); |
| 10796 | EXPECT_EQ(0u, |
| 10797 | CountRenderPassesWithId(frame.render_passes, RenderPassId(2, 0))); |
| 10798 | EXPECT_EQ(0u, |
| 10799 | CountRenderPassesWithId(frame.render_passes, RenderPassId(3, 0))); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10800 | EXPECT_EQ(RenderPassId(1, 0), frame.render_passes[0]->id); |
| 10801 | } |
| 10802 | |
| 10803 | TEST_F(LayerTreeHostImplTest, RemoveEmptyRenderPass) { |
| 10804 | LayerTreeHostImpl::FrameData frame; |
| 10805 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10806 | RenderPass* pass3 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10807 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10808 | RenderPass* pass2 = 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* pass1 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10811 | |
| 10812 | pass1->SetNew(RenderPassId(1, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10813 | pass2->SetNew(RenderPassId(2, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10814 | pass3->SetNew(RenderPassId(3, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10815 | |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10816 | // pass1 is not empty, but pass2 and pass3 are. |
| 10817 | SolidColorDrawQuad* color_quad; |
| 10818 | color_quad = pass1->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 10819 | color_quad->material = DrawQuad::SOLID_COLOR; |
| 10820 | |
| 10821 | // pass3 is referenced by pass2. |
| 10822 | RenderPassDrawQuad* rpdq = |
| 10823 | pass2->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 10824 | rpdq->material = DrawQuad::RENDER_PASS; |
| 10825 | rpdq->render_pass_id = pass3->id; |
| 10826 | |
| 10827 | // pass2 is referenced by pass1. |
| 10828 | rpdq = pass1->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 10829 | rpdq->material = DrawQuad::RENDER_PASS; |
| 10830 | rpdq->render_pass_id = pass2->id; |
| 10831 | |
| 10832 | // Since pass3 is empty it should be removed. Then pass2 is empty too, and |
| 10833 | // should be removed. |
| 10834 | FakeLayerTreeHostImpl::RemoveRenderPasses(&frame); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10835 | EXPECT_EQ(1u, frame.render_passes.size()); |
danakj | 61902b8 | 2015-10-30 00:30:26 | [diff] [blame] | 10836 | EXPECT_EQ(1u, |
| 10837 | CountRenderPassesWithId(frame.render_passes, RenderPassId(1, 0))); |
| 10838 | EXPECT_EQ(0u, |
| 10839 | CountRenderPassesWithId(frame.render_passes, RenderPassId(2, 0))); |
| 10840 | EXPECT_EQ(0u, |
| 10841 | CountRenderPassesWithId(frame.render_passes, RenderPassId(3, 0))); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10842 | EXPECT_EQ(RenderPassId(1, 0), frame.render_passes[0]->id); |
| 10843 | // The RenderPassDrawQuad should be removed from pass1. |
| 10844 | EXPECT_EQ(1u, pass1->quad_list.size()); |
| 10845 | EXPECT_EQ(DrawQuad::SOLID_COLOR, pass1->quad_list.ElementAt(0)->material); |
| 10846 | } |
| 10847 | |
| 10848 | TEST_F(LayerTreeHostImplTest, DoNotRemoveEmptyRootRenderPass) { |
| 10849 | LayerTreeHostImpl::FrameData frame; |
| 10850 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10851 | RenderPass* pass3 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10852 | frame.render_passes.push_back(RenderPass::Create()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 10853 | RenderPass* pass2 = 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* pass1 = frame.render_passes.back().get(); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10856 | |
| 10857 | pass1->SetNew(RenderPassId(1, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10858 | pass2->SetNew(RenderPassId(2, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10859 | pass3->SetNew(RenderPassId(3, 0), gfx::Rect(), gfx::Rect(), gfx::Transform()); |
| 10860 | |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10861 | // pass3 is referenced by pass2. |
| 10862 | RenderPassDrawQuad* rpdq = |
| 10863 | pass2->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 10864 | rpdq->material = DrawQuad::RENDER_PASS; |
| 10865 | rpdq->render_pass_id = pass3->id; |
| 10866 | |
| 10867 | // pass2 is referenced by pass1. |
| 10868 | rpdq = pass1->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 10869 | rpdq->material = DrawQuad::RENDER_PASS; |
| 10870 | rpdq->render_pass_id = pass2->id; |
| 10871 | |
| 10872 | // Since pass3 is empty it should be removed. Then pass2 is empty too, and |
| 10873 | // should be removed. Then pass1 is empty too, but it's the root so it should |
| 10874 | // not be removed. |
| 10875 | FakeLayerTreeHostImpl::RemoveRenderPasses(&frame); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10876 | EXPECT_EQ(1u, frame.render_passes.size()); |
danakj | 61902b8 | 2015-10-30 00:30:26 | [diff] [blame] | 10877 | EXPECT_EQ(1u, |
| 10878 | CountRenderPassesWithId(frame.render_passes, RenderPassId(1, 0))); |
| 10879 | EXPECT_EQ(0u, |
| 10880 | CountRenderPassesWithId(frame.render_passes, RenderPassId(2, 0))); |
| 10881 | EXPECT_EQ(0u, |
| 10882 | CountRenderPassesWithId(frame.render_passes, RenderPassId(3, 0))); |
danakj | 112d3a10 | 2015-04-14 18:24:49 | [diff] [blame] | 10883 | EXPECT_EQ(RenderPassId(1, 0), frame.render_passes[0]->id); |
| 10884 | // The RenderPassDrawQuad should be removed from pass1. |
| 10885 | EXPECT_EQ(0u, pass1->quad_list.size()); |
| 10886 | } |
| 10887 | |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10888 | class FakeVideoFrameController : public VideoFrameController { |
| 10889 | public: |
| 10890 | void OnBeginFrame(const BeginFrameArgs& args) override { |
| 10891 | begin_frame_args_ = args; |
dalecurtis | e8024c4 | 2015-05-29 21:22:35 | [diff] [blame] | 10892 | did_draw_frame_ = false; |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10893 | } |
| 10894 | |
dalecurtis | e8024c4 | 2015-05-29 21:22:35 | [diff] [blame] | 10895 | void DidDrawFrame() override { did_draw_frame_ = true; } |
| 10896 | |
| 10897 | const BeginFrameArgs& begin_frame_args() const { return begin_frame_args_; } |
| 10898 | |
| 10899 | bool did_draw_frame() const { return did_draw_frame_; } |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10900 | |
| 10901 | private: |
| 10902 | BeginFrameArgs begin_frame_args_; |
dalecurtis | e8024c4 | 2015-05-29 21:22:35 | [diff] [blame] | 10903 | bool did_draw_frame_ = false; |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10904 | }; |
| 10905 | |
| 10906 | TEST_F(LayerTreeHostImplTest, AddVideoFrameControllerInsideFrame) { |
| 10907 | BeginFrameArgs begin_frame_args = |
| 10908 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10909 | FakeVideoFrameController controller; |
| 10910 | |
| 10911 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10912 | EXPECT_FALSE(controller.begin_frame_args().IsValid()); |
| 10913 | host_impl_->AddVideoFrameController(&controller); |
| 10914 | EXPECT_TRUE(controller.begin_frame_args().IsValid()); |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 10915 | host_impl_->DidFinishImplFrame(); |
dalecurtis | e8024c4 | 2015-05-29 21:22:35 | [diff] [blame] | 10916 | |
| 10917 | EXPECT_FALSE(controller.did_draw_frame()); |
| 10918 | LayerTreeHostImpl::FrameData frame; |
| 10919 | host_impl_->DidDrawAllLayers(frame); |
| 10920 | EXPECT_TRUE(controller.did_draw_frame()); |
| 10921 | |
| 10922 | controller.OnBeginFrame(begin_frame_args); |
| 10923 | EXPECT_FALSE(controller.did_draw_frame()); |
| 10924 | host_impl_->RemoveVideoFrameController(&controller); |
| 10925 | host_impl_->DidDrawAllLayers(frame); |
| 10926 | EXPECT_FALSE(controller.did_draw_frame()); |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10927 | } |
| 10928 | |
| 10929 | TEST_F(LayerTreeHostImplTest, AddVideoFrameControllerOutsideFrame) { |
| 10930 | BeginFrameArgs begin_frame_args = |
| 10931 | CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10932 | FakeVideoFrameController controller; |
| 10933 | |
| 10934 | host_impl_->WillBeginImplFrame(begin_frame_args); |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 10935 | host_impl_->DidFinishImplFrame(); |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10936 | |
| 10937 | EXPECT_FALSE(controller.begin_frame_args().IsValid()); |
| 10938 | host_impl_->AddVideoFrameController(&controller); |
| 10939 | EXPECT_FALSE(controller.begin_frame_args().IsValid()); |
| 10940 | |
| 10941 | begin_frame_args = CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 10942 | EXPECT_FALSE(controller.begin_frame_args().IsValid()); |
| 10943 | host_impl_->WillBeginImplFrame(begin_frame_args); |
| 10944 | EXPECT_TRUE(controller.begin_frame_args().IsValid()); |
dalecurtis | e8024c4 | 2015-05-29 21:22:35 | [diff] [blame] | 10945 | |
| 10946 | EXPECT_FALSE(controller.did_draw_frame()); |
| 10947 | LayerTreeHostImpl::FrameData frame; |
| 10948 | host_impl_->DidDrawAllLayers(frame); |
| 10949 | EXPECT_TRUE(controller.did_draw_frame()); |
| 10950 | |
| 10951 | controller.OnBeginFrame(begin_frame_args); |
| 10952 | EXPECT_FALSE(controller.did_draw_frame()); |
| 10953 | host_impl_->RemoveVideoFrameController(&controller); |
| 10954 | host_impl_->DidDrawAllLayers(frame); |
| 10955 | EXPECT_FALSE(controller.did_draw_frame()); |
sunnyps | c052ba99 | 2015-05-05 00:42:29 | [diff] [blame] | 10956 | } |
| 10957 | |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10958 | TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusModes) { |
| 10959 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10960 | |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 10961 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10962 | host_impl_->SetContentIsSuitableForGpuRasterization(true); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 10963 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10964 | EXPECT_EQ(GpuRasterizationStatus::ON, host_impl_->gpu_rasterization_status()); |
| 10965 | EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 10966 | |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 10967 | host_impl_->SetHasGpuRasterizationTrigger(false); |
| 10968 | host_impl_->SetContentIsSuitableForGpuRasterization(true); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 10969 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10970 | EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT, |
| 10971 | host_impl_->gpu_rasterization_status()); |
| 10972 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10973 | |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 10974 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10975 | host_impl_->SetContentIsSuitableForGpuRasterization(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 10976 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10977 | EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, |
| 10978 | host_impl_->gpu_rasterization_status()); |
| 10979 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 10980 | EXPECT_FALSE(host_impl_->use_msaa()); |
| 10981 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 10982 | std::unique_ptr<TestWebGraphicsContext3D> context_with_msaa = |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10983 | TestWebGraphicsContext3D::Create(); |
| 10984 | context_with_msaa->SetMaxSamples(8); |
| 10985 | |
| 10986 | LayerTreeSettings msaaSettings = GpuRasterizationEnabledSettings(); |
| 10987 | msaaSettings.gpu_rasterization_msaa_sample_count = 4; |
| 10988 | EXPECT_TRUE(CreateHostImpl( |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 10989 | msaaSettings, |
| 10990 | FakeOutputSurface::CreateDelegating3d(std::move(context_with_msaa)))); |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 10991 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 10992 | host_impl_->SetContentIsSuitableForGpuRasterization(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 10993 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 10994 | EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT, |
| 10995 | host_impl_->gpu_rasterization_status()); |
| 10996 | EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 10997 | EXPECT_TRUE(host_impl_->use_msaa()); |
| 10998 | |
| 10999 | LayerTreeSettings settings = DefaultSettings(); |
| 11000 | settings.gpu_rasterization_enabled = false; |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 11001 | EXPECT_TRUE( |
| 11002 | CreateHostImpl(settings, FakeOutputSurface::CreateDelegating3d())); |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 11003 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 11004 | host_impl_->SetContentIsSuitableForGpuRasterization(true); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 11005 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 11006 | EXPECT_EQ(GpuRasterizationStatus::OFF_DEVICE, |
| 11007 | host_impl_->gpu_rasterization_status()); |
| 11008 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 11009 | |
| 11010 | settings.gpu_rasterization_forced = true; |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 11011 | EXPECT_TRUE( |
| 11012 | CreateHostImpl(settings, FakeOutputSurface::CreateDelegating3d())); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 11013 | |
senorblanco | 9c04acb | 2015-05-15 19:41:32 | [diff] [blame] | 11014 | host_impl_->SetHasGpuRasterizationTrigger(false); |
| 11015 | host_impl_->SetContentIsSuitableForGpuRasterization(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 11016 | host_impl_->CommitComplete(); |
senorblanco | fb88a4e | 2015-05-08 17:28:41 | [diff] [blame] | 11017 | EXPECT_EQ(GpuRasterizationStatus::ON_FORCED, |
| 11018 | host_impl_->gpu_rasterization_status()); |
| 11019 | EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 11020 | } |
| 11021 | |
ericrk | d72af43d | 2016-03-18 21:44:31 | [diff] [blame] | 11022 | class MsaaIsSlowLayerTreeHostImplTest : public LayerTreeHostImplTest { |
| 11023 | public: |
| 11024 | void CreateHostImplWithMsaaIsSlow(bool msaa_is_slow) { |
| 11025 | LayerTreeSettings settings = DefaultSettings(); |
| 11026 | settings.gpu_rasterization_enabled = true; |
| 11027 | settings.gpu_rasterization_msaa_sample_count = 4; |
| 11028 | auto context_provider = TestContextProvider::Create(); |
| 11029 | context_provider->UnboundTestContext3d()->SetMaxSamples(4); |
| 11030 | context_provider->UnboundTestContext3d()->set_msaa_is_slow(msaa_is_slow); |
| 11031 | auto msaa_is_normal_output_surface = |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 11032 | FakeOutputSurface::CreateDelegating3d(context_provider); |
ericrk | d72af43d | 2016-03-18 21:44:31 | [diff] [blame] | 11033 | EXPECT_TRUE( |
| 11034 | CreateHostImpl(settings, std::move(msaa_is_normal_output_surface))); |
| 11035 | } |
| 11036 | }; |
| 11037 | |
| 11038 | TEST_F(MsaaIsSlowLayerTreeHostImplTest, GpuRasterizationStatusMsaaIsSlow) { |
| 11039 | // Ensure that without the msaa_is_slow cap we raster unsuitable content with |
| 11040 | // msaa. |
| 11041 | CreateHostImplWithMsaaIsSlow(false); |
| 11042 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 11043 | host_impl_->SetContentIsSuitableForGpuRasterization(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 11044 | host_impl_->CommitComplete(); |
ericrk | d72af43d | 2016-03-18 21:44:31 | [diff] [blame] | 11045 | EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT, |
| 11046 | host_impl_->gpu_rasterization_status()); |
| 11047 | EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 11048 | |
| 11049 | // Ensure that with the msaa_is_slow cap we don't raster unsuitable content |
| 11050 | // with msaa. |
| 11051 | CreateHostImplWithMsaaIsSlow(true); |
| 11052 | host_impl_->SetHasGpuRasterizationTrigger(true); |
| 11053 | host_impl_->SetContentIsSuitableForGpuRasterization(false); |
danakj | 1a86f6d6 | 2016-08-17 20:10:40 | [diff] [blame] | 11054 | host_impl_->CommitComplete(); |
ericrk | d72af43d | 2016-03-18 21:44:31 | [diff] [blame] | 11055 | EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, |
| 11056 | host_impl_->gpu_rasterization_status()); |
| 11057 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 11058 | } |
| 11059 | |
ericrk | 17ec17f | 2015-05-19 19:50:51 | [diff] [blame] | 11060 | // A mock output surface which lets us detect calls to ForceReclaimResources. |
| 11061 | class MockReclaimResourcesOutputSurface : public FakeOutputSurface { |
| 11062 | public: |
danakj | c070bf55 | 2016-08-10 22:41:55 | [diff] [blame] | 11063 | MockReclaimResourcesOutputSurface() |
| 11064 | : FakeOutputSurface(TestContextProvider::Create(), |
| 11065 | TestContextProvider::CreateWorker(), |
| 11066 | true) {} |
ericrk | 17ec17f | 2015-05-19 19:50:51 | [diff] [blame] | 11067 | |
| 11068 | MOCK_METHOD0(ForceReclaimResources, void()); |
ericrk | 17ec17f | 2015-05-19 19:50:51 | [diff] [blame] | 11069 | }; |
| 11070 | |
| 11071 | // Display::Draw (and the planned Display Scheduler) currently rely on resources |
| 11072 | // being reclaimed to block drawing between BeginCommit / Swap. This test |
| 11073 | // ensures that BeginCommit triggers ForceReclaimResources. See |
| 11074 | // crbug.com/489515. |
| 11075 | TEST_F(LayerTreeHostImplTest, BeginCommitReclaimsResources) { |
danakj | c070bf55 | 2016-08-10 22:41:55 | [diff] [blame] | 11076 | auto output_surface = base::MakeUnique<MockReclaimResourcesOutputSurface>(); |
ericrk | 17ec17f | 2015-05-19 19:50:51 | [diff] [blame] | 11077 | // Hold an unowned pointer to the output surface to use for mock expectations. |
| 11078 | MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); |
| 11079 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 11080 | CreateHostImpl(DefaultSettings(), std::move(output_surface)); |
ericrk | 17ec17f | 2015-05-19 19:50:51 | [diff] [blame] | 11081 | EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); |
| 11082 | host_impl_->BeginCommit(); |
| 11083 | } |
| 11084 | |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11085 | TEST_F(LayerTreeHostImplTest, UpdatePageScaleFactorOnActiveTree) { |
| 11086 | // Check page scale factor update in property trees when an update is made |
| 11087 | // on the active tree. |
| 11088 | host_impl_->CreatePendingTree(); |
| 11089 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 3.f); |
| 11090 | CreateScrollAndContentsLayers(host_impl_->pending_tree(), |
| 11091 | gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11092 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11093 | host_impl_->ActivateSyncTree(); |
| 11094 | DrawFrame(); |
| 11095 | |
| 11096 | host_impl_->CreatePendingTree(); |
| 11097 | host_impl_->active_tree()->SetPageScaleOnActiveTree(2.f); |
| 11098 | LayerImpl* page_scale_layer = host_impl_->active_tree()->PageScaleLayer(); |
| 11099 | |
| 11100 | TransformNode* active_tree_node = |
| 11101 | host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 11102 | page_scale_layer->transform_tree_index()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 11103 | // SetPageScaleOnActiveTree also updates the factors in property trees. |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 11104 | EXPECT_EQ(active_tree_node->post_local_scale_factor, 2.f); |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11105 | EXPECT_EQ(host_impl_->active_tree()->current_page_scale_factor(), 2.f); |
| 11106 | |
| 11107 | TransformNode* pending_tree_node = |
| 11108 | host_impl_->pending_tree()->property_trees()->transform_tree.Node( |
| 11109 | page_scale_layer->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 11110 | EXPECT_EQ(pending_tree_node->post_local_scale_factor, 1.f); |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11111 | EXPECT_EQ(host_impl_->pending_tree()->current_page_scale_factor(), 2.f); |
| 11112 | |
| 11113 | host_impl_->pending_tree()->UpdateDrawProperties(false); |
| 11114 | pending_tree_node = |
| 11115 | host_impl_->pending_tree()->property_trees()->transform_tree.Node( |
| 11116 | page_scale_layer->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 11117 | EXPECT_EQ(pending_tree_node->post_local_scale_factor, 2.f); |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11118 | |
| 11119 | host_impl_->ActivateSyncTree(); |
| 11120 | host_impl_->active_tree()->UpdateDrawProperties(false); |
| 11121 | active_tree_node = |
| 11122 | host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 11123 | page_scale_layer->transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 11124 | EXPECT_EQ(active_tree_node->post_local_scale_factor, 2.f); |
jaydasika | 0c1fd60 | 2015-10-07 17:59:52 | [diff] [blame] | 11125 | } |
| 11126 | |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11127 | TEST_F(LayerTreeHostImplTest, SubLayerScaleForNodeInSubtreeOfPageScaleLayer) { |
| 11128 | // Checks that the sublayer scale of a transform node in the subtree of the |
| 11129 | // page scale layer is updated without a property tree rebuild. |
| 11130 | host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 3.f); |
| 11131 | CreateScrollAndContentsLayers(host_impl_->active_tree(), gfx::Size(100, 100)); |
| 11132 | LayerImpl* page_scale_layer = host_impl_->active_tree()->PageScaleLayer(); |
jaydasika | 89f7b5a | 2016-06-22 02:08:39 | [diff] [blame] | 11133 | page_scale_layer->test_properties()->AddChild( |
| 11134 | LayerImpl::Create(host_impl_->active_tree(), 100)); |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11135 | |
| 11136 | LayerImpl* in_subtree_of_page_scale_layer = |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 11137 | host_impl_->active_tree()->LayerById(100); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 11138 | in_subtree_of_page_scale_layer->test_properties()->force_render_surface = |
| 11139 | true; |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11140 | host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 11141 | |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11142 | DrawFrame(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11143 | |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11144 | TransformNode* node = |
| 11145 | host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 11146 | in_subtree_of_page_scale_layer->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 11147 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11148 | |
| 11149 | host_impl_->active_tree()->SetPageScaleOnActiveTree(2.f); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11150 | |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11151 | DrawFrame(); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11152 | |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 11153 | in_subtree_of_page_scale_layer = host_impl_->active_tree()->LayerById(100); |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11154 | node = host_impl_->active_tree()->property_trees()->transform_tree.Node( |
| 11155 | in_subtree_of_page_scale_layer->transform_tree_index()); |
jaydasika | 6be76160 | 2016-07-18 20:11:43 | [diff] [blame] | 11156 | EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); |
jaydasika | fbb9f43a | 2015-10-22 20:44:08 | [diff] [blame] | 11157 | } |
| 11158 | |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11159 | TEST_F(LayerTreeHostImplTest, JitterTest) { |
| 11160 | host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 11161 | |
| 11162 | host_impl_->CreatePendingTree(); |
| 11163 | CreateScrollAndContentsLayers(host_impl_->pending_tree(), |
| 11164 | gfx::Size(100, 100)); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11165 | host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11166 | |
| 11167 | host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11168 | const int scroll = 5; |
| 11169 | int accumulated_scroll = 0; |
| 11170 | for (int i = 0; i < host_impl_->pending_tree()->kFixedPointHitsThreshold + 1; |
| 11171 | ++i) { |
| 11172 | host_impl_->ActivateSyncTree(); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 11173 | host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 11174 | InputHandler::TOUCHSCREEN); |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 11175 | host_impl_->ScrollBy( |
| 11176 | UpdateState(gfx::Point(), gfx::Vector2dF(0, scroll)).get()); |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11177 | accumulated_scroll += scroll; |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 11178 | host_impl_->ScrollEnd(EndState().get()); |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11179 | host_impl_->active_tree()->UpdateDrawProperties(false); |
| 11180 | |
| 11181 | host_impl_->CreatePendingTree(); |
| 11182 | host_impl_->pending_tree()->set_source_frame_number(i + 1); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 11183 | LayerImpl* content_layer = host_impl_->pending_tree() |
| 11184 | ->OuterViewportScrollLayer() |
| 11185 | ->test_properties() |
| 11186 | ->children[0]; |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11187 | // The scroll done on the active tree is undone on the pending tree. |
| 11188 | gfx::Transform translate; |
| 11189 | translate.Translate(0, accumulated_scroll); |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 11190 | content_layer->test_properties()->transform = translate; |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11191 | |
| 11192 | LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
| 11193 | pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 11194 | LayerImpl* last_scrolled_layer = pending_tree->LayerById( |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11195 | host_impl_->active_tree()->LastScrolledLayerId()); |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 11196 | |
| 11197 | // When building property trees from impl side, the builder uses the scroll |
| 11198 | // offset of layer_impl to initialize the scroll offset in scroll tree: |
| 11199 | // scroll_tree.synced_scroll_offset.PushFromMainThread( |
| 11200 | // layer->CurrentScrollOffset()). |
| 11201 | // However, layer_impl does not store scroll_offset, so it is using scroll |
| 11202 | // tree's scroll offset to initialize itself. Usually this approach works |
| 11203 | // because this is a simple assignment. However if scroll_offset's pending |
| 11204 | // delta is not zero, the delta would be counted twice. |
| 11205 | // This hacking here is to restore the damaged scroll offset. |
| 11206 | gfx::ScrollOffset pending_base = |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 11207 | pending_tree->property_trees() |
| 11208 | ->scroll_tree.GetScrollOffsetBaseForTesting( |
| 11209 | last_scrolled_layer->id()); |
danakj | 74af409e | 2016-07-01 00:41:48 | [diff] [blame] | 11210 | pending_tree->BuildPropertyTreesForTesting(); |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 11211 | pending_tree->property_trees() |
| 11212 | ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
| 11213 | last_scrolled_layer->id(), pending_base); |
jaydasika | 69dc941 | 2016-06-25 00:34:57 | [diff] [blame] | 11214 | pending_tree->LayerById(content_layer->id())->SetNeedsPushProperties(); |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 11215 | |
| 11216 | pending_tree->set_needs_update_draw_properties(); |
| 11217 | pending_tree->UpdateDrawProperties(false); |
jaydasika | eaa8d085 | 2016-03-29 23:55:39 | [diff] [blame] | 11218 | float jitter = LayerTreeHostCommon::CalculateLayerJitter(content_layer); |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 11219 | // There should not be any jitter measured till we hit the fixed point hits |
| 11220 | // threshold. |
| 11221 | float expected_jitter = |
| 11222 | (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; |
| 11223 | EXPECT_EQ(jitter, expected_jitter); |
| 11224 | } |
| 11225 | } |
| 11226 | |
ericrk | 563e1a015 | 2016-05-02 18:54:06 | [diff] [blame] | 11227 | // Checks that if we lose a GPU raster enabled OutputSurface and replace it |
| 11228 | // with a software OutputSurface, LayerTreeHostImpl correctly re-computes GPU |
| 11229 | // rasterization status. |
| 11230 | TEST_F(LayerTreeHostImplTest, RecomputeGpuRasterOnOutputSurfaceChange) { |
danakj | ee6547a2 | 2016-07-01 20:41:50 | [diff] [blame] | 11231 | host_impl_->ReleaseOutputSurface(); |
| 11232 | host_impl_ = nullptr; |
| 11233 | |
ericrk | 563e1a015 | 2016-05-02 18:54:06 | [diff] [blame] | 11234 | LayerTreeSettings settings = DefaultSettings(); |
| 11235 | settings.gpu_rasterization_forced = true; |
| 11236 | |
| 11237 | host_impl_ = LayerTreeHostImpl::Create( |
| 11238 | settings, this, &task_runner_provider_, &stats_instrumentation_, |
| 11239 | &shared_bitmap_manager_, &gpu_memory_buffer_manager_, &task_graph_runner_, |
loyso | ab32ee7 | 2016-06-08 03:33:18 | [diff] [blame] | 11240 | AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); |
ericrk | 563e1a015 | 2016-05-02 18:54:06 | [diff] [blame] | 11241 | host_impl_->SetVisible(true); |
| 11242 | |
| 11243 | // InitializeRenderer with a gpu-raster enabled output surface. |
| 11244 | auto gpu_raster_output_surface = |
danakj | f33ceec | 2016-07-20 20:04:45 | [diff] [blame] | 11245 | FakeOutputSurface::CreateDelegating3d(TestWebGraphicsContext3D::Create()); |
ericrk | 563e1a015 | 2016-05-02 18:54:06 | [diff] [blame] | 11246 | host_impl_->InitializeRenderer(gpu_raster_output_surface.get()); |
| 11247 | EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
| 11248 | |
| 11249 | // Re-initialize with a software output surface. |
danakj | 6021ec3 | 2016-07-22 22:16:08 | [diff] [blame] | 11250 | output_surface_ = FakeOutputSurface::CreateDelegatingSoftware(); |
ericrk | 563e1a015 | 2016-05-02 18:54:06 | [diff] [blame] | 11251 | host_impl_->InitializeRenderer(output_surface_.get()); |
| 11252 | EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
| 11253 | } |
| 11254 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 11255 | } // namespace |
| 11256 | } // namespace cc |