[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 | |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
[email protected] | ad5d142 | 2012-10-19 13:40:29 | [diff] [blame] | 9 | #include "base/basictypes.h" |
[email protected] | 4a23c374c | 2012-12-08 08:38:55 | [diff] [blame] | 10 | #include "base/json/json_writer.h" |
[email protected] | f586491 | 2013-02-01 03:18:14 | [diff] [blame] | 11 | #include "base/metrics/histogram.h" |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 12 | #include "base/stl_util.h" |
[email protected] | 8e61d4b | 2013-06-10 22:11:48 | [diff] [blame] | 13 | #include "base/strings/stringprintf.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 14 | #include "cc/animation/scrollbar_animation_controller.h" |
[email protected] | 85d136f78 | 2013-04-26 22:04:40 | [diff] [blame] | 15 | #include "cc/animation/timing_function.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 16 | #include "cc/base/math_util.h" |
| 17 | #include "cc/base/util.h" |
[email protected] | 6e84de2 | 2013-03-18 06:54:27 | [diff] [blame] | 18 | #include "cc/debug/debug_rect_history.h" |
| 19 | #include "cc/debug/frame_rate_counter.h" |
| 20 | #include "cc/debug/overdraw_metrics.h" |
| 21 | #include "cc/debug/paint_time_counter.h" |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 22 | #include "cc/debug/rendering_stats_instrumentation.h" |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 23 | #include "cc/debug/traced_value.h" |
[email protected] | 3052b10f | 2013-03-18 07:41:21 | [diff] [blame] | 24 | #include "cc/input/page_scale_animation.h" |
| 25 | #include "cc/input/top_controls_manager.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 26 | #include "cc/layers/append_quads_data.h" |
| 27 | #include "cc/layers/heads_up_display_layer_impl.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 28 | #include "cc/layers/layer_impl.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 29 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 30 | #include "cc/layers/render_surface_impl.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 31 | #include "cc/layers/scrollbar_layer_impl.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 32 | #include "cc/output/compositor_frame_metadata.h" |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 33 | #include "cc/output/copy_output_request.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 34 | #include "cc/output/delegating_renderer.h" |
| 35 | #include "cc/output/gl_renderer.h" |
| 36 | #include "cc/output/software_renderer.h" |
[email protected] | 89e8267 | 2013-03-18 07:50:56 | [diff] [blame] | 37 | #include "cc/quads/render_pass_draw_quad.h" |
| 38 | #include "cc/quads/shared_quad_state.h" |
| 39 | #include "cc/quads/solid_color_draw_quad.h" |
[email protected] | e12dd0e | 2013-03-18 08:24:40 | [diff] [blame] | 40 | #include "cc/resources/memory_history.h" |
| 41 | #include "cc/resources/picture_layer_tiling.h" |
| 42 | #include "cc/resources/prioritized_resource_manager.h" |
[email protected] | be4655a | 2013-03-18 08:36:31 | [diff] [blame] | 43 | #include "cc/scheduler/delay_based_time_source.h" |
| 44 | #include "cc/scheduler/texture_uploader.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 45 | #include "cc/trees/damage_tracker.h" |
| 46 | #include "cc/trees/layer_tree_host.h" |
| 47 | #include "cc/trees/layer_tree_host_common.h" |
| 48 | #include "cc/trees/layer_tree_impl.h" |
| 49 | #include "cc/trees/quad_culler.h" |
| 50 | #include "cc/trees/single_thread_proxy.h" |
| 51 | #include "cc/trees/tree_synchronizer.h" |
[email protected] | d455d55 | 2012-11-02 00:19:06 | [diff] [blame] | 52 | #include "ui/gfx/size_conversions.h" |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 53 | #include "ui/gfx/vector2d_conversions.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 54 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 55 | namespace { |
| 56 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 57 | void DidVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) { |
| 58 | if (visible) { |
| 59 | TRACE_EVENT_ASYNC_BEGIN1("webkit", |
| 60 | "LayerTreeHostImpl::SetVisible", |
| 61 | id, |
| 62 | "LayerTreeHostImpl", |
| 63 | id); |
| 64 | return; |
| 65 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 66 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 67 | TRACE_EVENT_ASYNC_END0("webkit", "LayerTreeHostImpl::SetVisible", id); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 68 | } |
| 69 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 70 | } // namespace |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 71 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 72 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 73 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 74 | class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 75 | public: |
| 76 | static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> Create( |
| 77 | LayerTreeHostImpl* layer_tree_host_impl, |
| 78 | scoped_refptr<DelayBasedTimeSource> time_source) { |
| 79 | return make_scoped_ptr( |
| 80 | new LayerTreeHostImplTimeSourceAdapter(layer_tree_host_impl, |
| 81 | time_source)); |
| 82 | } |
| 83 | virtual ~LayerTreeHostImplTimeSourceAdapter() { |
[email protected] | 6d0e69d | 2013-03-20 14:53:26 | [diff] [blame] | 84 | time_source_->SetClient(NULL); |
| 85 | time_source_->SetActive(false); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 86 | } |
| 87 | |
[email protected] | 6d0e69d | 2013-03-20 14:53:26 | [diff] [blame] | 88 | virtual void OnTimerTick() OVERRIDE { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 89 | // In single threaded mode we attempt to simulate changing the current |
| 90 | // thread by maintaining a fake thread id. When we switch from one |
| 91 | // thread to another, we construct DebugScopedSetXXXThread objects that |
| 92 | // update the thread id. This lets DCHECKS that ensure we're on the |
| 93 | // right thread to work correctly in single threaded mode. The problem |
| 94 | // here is that the timer tasks are run via the message loop, and when |
| 95 | // they run, we've had no chance to construct a DebugScopedSetXXXThread |
| 96 | // object. The result is that we report that we're running on the main |
| 97 | // thread. In multi-threaded mode, this timer is run on the compositor |
| 98 | // thread, so to keep this consistent in single-threaded mode, we'll |
| 99 | // construct a DebugScopedSetImplThread object. There is no need to do |
| 100 | // this in multi-threaded mode since the real thread id's will be |
| 101 | // correct. In fact, setting fake thread id's interferes with the real |
| 102 | // thread id's and causes breakage. |
| 103 | scoped_ptr<DebugScopedSetImplThread> set_impl_thread; |
| 104 | if (!layer_tree_host_impl_->proxy()->HasImplThread()) { |
| 105 | set_impl_thread.reset( |
| 106 | new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 107 | } |
| 108 | |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 109 | // TODO(enne): This should probably happen post-animate. |
| 110 | if (layer_tree_host_impl_->pending_tree()) { |
| 111 | layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); |
| 112 | |
| 113 | if (layer_tree_host_impl_->pending_tree()) { |
| 114 | layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); |
| 115 | layer_tree_host_impl_->ManageTiles(); |
| 116 | } |
| 117 | } |
| 118 | |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 119 | layer_tree_host_impl_->Animate( |
| 120 | layer_tree_host_impl_->CurrentFrameTimeTicks(), |
| 121 | layer_tree_host_impl_->CurrentFrameTime()); |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 122 | layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); |
| 123 | bool start_ready_animations = true; |
| 124 | layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
[email protected] | 8347d69 | 2013-05-17 23:22:38 | [diff] [blame] | 125 | layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 126 | } |
[email protected] | 37397423 | 2013-01-10 22:20:50 | [diff] [blame] | 127 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 128 | void SetActive(bool active) { |
[email protected] | 6d0e69d | 2013-03-20 14:53:26 | [diff] [blame] | 129 | if (active != time_source_->Active()) |
| 130 | time_source_->SetActive(active); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 131 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 132 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 133 | private: |
| 134 | LayerTreeHostImplTimeSourceAdapter( |
| 135 | LayerTreeHostImpl* layer_tree_host_impl, |
| 136 | scoped_refptr<DelayBasedTimeSource> time_source) |
| 137 | : layer_tree_host_impl_(layer_tree_host_impl), |
| 138 | time_source_(time_source) { |
[email protected] | 6d0e69d | 2013-03-20 14:53:26 | [diff] [blame] | 139 | time_source_->SetClient(this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 140 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 141 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 142 | LayerTreeHostImpl* layer_tree_host_impl_; |
| 143 | scoped_refptr<DelayBasedTimeSource> time_source_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 144 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 145 | DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImplTimeSourceAdapter); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 146 | }; |
| 147 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 148 | LayerTreeHostImpl::FrameData::FrameData() |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 149 | : contains_incomplete_tile(false), has_no_damage(false) {} |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 150 | |
| 151 | LayerTreeHostImpl::FrameData::~FrameData() {} |
| 152 | |
| 153 | scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( |
| 154 | const LayerTreeSettings& settings, |
| 155 | LayerTreeHostImplClient* client, |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 156 | Proxy* proxy, |
| 157 | RenderingStatsInstrumentation* rendering_stats_instrumentation) { |
| 158 | return make_scoped_ptr( |
| 159 | new LayerTreeHostImpl(settings, |
| 160 | client, |
| 161 | proxy, |
| 162 | rendering_stats_instrumentation)); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 163 | } |
| 164 | |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 165 | LayerTreeHostImpl::LayerTreeHostImpl( |
| 166 | const LayerTreeSettings& settings, |
| 167 | LayerTreeHostImplClient* client, |
| 168 | Proxy* proxy, |
| 169 | RenderingStatsInstrumentation* rendering_stats_instrumentation) |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 170 | : client_(client), |
| 171 | proxy_(proxy), |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 172 | input_handler_client_(NULL), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 173 | did_lock_scrolling_layer_(false), |
| 174 | should_bubble_scrolls_(false), |
| 175 | wheel_scrolling_(false), |
[email protected] | a23451e | 2013-06-07 20:58:26 | [diff] [blame] | 176 | manage_tiles_needed_(false), |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 177 | root_layer_scroll_offset_delegate_(NULL), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 178 | settings_(settings), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 179 | visible_(true), |
| 180 | managed_memory_policy_( |
[email protected] | b56c130 | 2013-03-20 21:17:34 | [diff] [blame] | 181 | PrioritizedResourceManager::DefaultMemoryAllocationLimit(), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 182 | ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING, |
| 183 | 0, |
| 184 | ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING), |
| 185 | pinch_gesture_active_(false), |
[email protected] | 9e359452 | 2013-03-18 00:57:36 | [diff] [blame] | 186 | fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())), |
[email protected] | 7497316a | 2013-03-15 12:42:29 | [diff] [blame] | 187 | paint_time_counter_(PaintTimeCounter::Create()), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 188 | memory_history_(MemoryHistory::Create()), |
[email protected] | d3599278 | 2013-03-14 14:54:02 | [diff] [blame] | 189 | debug_rect_history_(DebugRectHistory::Create()), |
[email protected] | d7626ffd | 2013-03-29 00:17:42 | [diff] [blame] | 190 | max_memory_needed_bytes_(0), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 191 | last_sent_memory_visible_bytes_(0), |
| 192 | last_sent_memory_visible_and_nearby_bytes_(0), |
| 193 | last_sent_memory_use_bytes_(0), |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 194 | zero_budget_(false), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 195 | device_scale_factor_(1.f), |
| 196 | overdraw_bottom_height_(0.f), |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 197 | animation_registrar_(AnimationRegistrar::Create()), |
[email protected] | 39643fb | 2013-07-09 17:28:19 | [diff] [blame] | 198 | rendering_stats_instrumentation_(rendering_stats_instrumentation), |
[email protected] | 8bb6cfa | 2013-07-23 00:11:19 | [diff] [blame] | 199 | need_to_update_visible_tiles_before_draw_(false) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 200 | DCHECK(proxy_->IsImplThread()); |
| 201 | DidVisibilityChange(this, visible_); |
| 202 | |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 203 | SetDebugState(settings.initial_debug_state); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 204 | |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 205 | if (settings.calculate_top_controls_position) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 206 | top_controls_manager_ = |
| 207 | TopControlsManager::Create(this, |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 208 | settings.top_controls_height, |
| 209 | settings.top_controls_show_threshold, |
| 210 | settings.top_controls_hide_threshold); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 211 | } |
| 212 | |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 213 | SetDebugState(settings.initial_debug_state); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 214 | |
| 215 | // LTHI always has an active tree. |
| 216 | active_tree_ = LayerTreeImpl::create(this); |
[email protected] | 9197dbcb | 2013-05-15 20:28:51 | [diff] [blame] | 217 | TRACE_EVENT_OBJECT_CREATED_WITH_ID( |
| 218 | TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", this); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 219 | } |
| 220 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 221 | LayerTreeHostImpl::~LayerTreeHostImpl() { |
| 222 | DCHECK(proxy_->IsImplThread()); |
| 223 | TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); |
[email protected] | 9197dbcb | 2013-05-15 20:28:51 | [diff] [blame] | 224 | TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
| 225 | TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", this); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 226 | |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 227 | if (input_handler_client_) { |
| 228 | input_handler_client_->WillShutdown(); |
| 229 | input_handler_client_ = NULL; |
| 230 | } |
| 231 | |
[email protected] | 75deb74 | 2013-06-24 20:19:18 | [diff] [blame] | 232 | // The layer trees must be destroyed before the layer tree host. We've |
| 233 | // made a contract with our animation controllers that the registrar |
| 234 | // will outlive them, and we must make good. |
| 235 | recycle_tree_.reset(); |
| 236 | pending_tree_.reset(); |
| 237 | active_tree_.reset(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 238 | } |
| 239 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 240 | void LayerTreeHostImpl::BeginCommit() {} |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 241 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 242 | void LayerTreeHostImpl::CommitComplete() { |
| 243 | TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); |
[email protected] | 131a0c2 | 2013-02-12 18:31:08 | [diff] [blame] | 244 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 245 | // Impl-side painting needs an update immediately post-commit to have the |
| 246 | // opportunity to create tilings. Other paths can call UpdateDrawProperties |
| 247 | // more lazily when needed prior to drawing. |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 248 | if (settings_.impl_side_painting) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 249 | pending_tree_->set_needs_update_draw_properties(); |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 250 | pending_tree_->UpdateDrawProperties(); |
[email protected] | a23451e | 2013-06-07 20:58:26 | [diff] [blame] | 251 | // Start working on newly created tiles immediately if needed. |
| 252 | ManageTiles(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 253 | } else { |
| 254 | active_tree_->set_needs_update_draw_properties(); |
| 255 | } |
[email protected] | 3ba4cae | 2013-01-16 03:58:38 | [diff] [blame] | 256 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 257 | client_->SendManagedMemoryStats(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 258 | } |
| 259 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 260 | bool LayerTreeHostImpl::CanDraw() { |
| 261 | // Note: If you are changing this function or any other function that might |
| 262 | // affect the result of CanDraw, make sure to call |
| 263 | // client_->OnCanDrawStateChanged in the proper places and update the |
| 264 | // NotifyIfCanDrawChanged test. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 265 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 266 | if (!active_tree_->root_layer()) { |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 267 | TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw no root layer", |
| 268 | TRACE_EVENT_SCOPE_THREAD); |
[email protected] | 2f1acc26 | 2012-11-16 21:42:22 | [diff] [blame] | 269 | return false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 270 | } |
| 271 | if (device_viewport_size_.IsEmpty()) { |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 272 | TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw empty viewport", |
| 273 | TRACE_EVENT_SCOPE_THREAD); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 274 | return false; |
| 275 | } |
| 276 | if (active_tree_->ViewportSizeInvalid()) { |
| 277 | TRACE_EVENT_INSTANT0( |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 278 | "cc", "LayerTreeHostImpl::CanDraw viewport size recently changed", |
| 279 | TRACE_EVENT_SCOPE_THREAD); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 280 | return false; |
| 281 | } |
| 282 | if (!renderer_) { |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 283 | TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw no renderer", |
| 284 | TRACE_EVENT_SCOPE_THREAD); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 285 | return false; |
| 286 | } |
| 287 | if (active_tree_->ContentsTexturesPurged()) { |
| 288 | TRACE_EVENT_INSTANT0( |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 289 | "cc", "LayerTreeHostImpl::CanDraw contents textures purged", |
| 290 | TRACE_EVENT_SCOPE_THREAD); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 291 | return false; |
| 292 | } |
| 293 | return true; |
[email protected] | 2f1acc26 | 2012-11-16 21:42:22 | [diff] [blame] | 294 | } |
| 295 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 296 | void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time, |
| 297 | base::Time wall_clock_time) { |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 298 | if (input_handler_client_) |
| 299 | input_handler_client_->Animate(monotonic_time); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 300 | AnimatePageScale(monotonic_time); |
| 301 | AnimateLayers(monotonic_time, wall_clock_time); |
| 302 | AnimateScrollbars(monotonic_time); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 303 | AnimateTopControls(monotonic_time); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 304 | } |
| 305 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 306 | void LayerTreeHostImpl::ManageTiles() { |
[email protected] | a23451e | 2013-06-07 20:58:26 | [diff] [blame] | 307 | if (!tile_manager_) |
| 308 | return; |
| 309 | if (!manage_tiles_needed_) |
| 310 | return; |
| 311 | manage_tiles_needed_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 312 | tile_manager_->ManageTiles(); |
| 313 | |
| 314 | size_t memory_required_bytes; |
| 315 | size_t memory_nice_to_have_bytes; |
| 316 | size_t memory_used_bytes; |
| 317 | tile_manager_->GetMemoryStats(&memory_required_bytes, |
| 318 | &memory_nice_to_have_bytes, |
| 319 | &memory_used_bytes); |
| 320 | SendManagedMemoryStats(memory_required_bytes, |
| 321 | memory_nice_to_have_bytes, |
| 322 | memory_used_bytes); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 323 | } |
| 324 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 325 | void LayerTreeHostImpl::StartPageScaleAnimation(gfx::Vector2d target_offset, |
| 326 | bool anchor_point, |
| 327 | float page_scale, |
| 328 | base::TimeTicks start_time, |
| 329 | base::TimeDelta duration) { |
| 330 | if (!RootScrollLayer()) |
| 331 | return; |
| 332 | |
| 333 | gfx::Vector2dF scroll_total = |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 334 | RootScrollLayer()->scroll_offset() + RootScrollLayer()->ScrollDelta(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 335 | gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); |
[email protected] | 6fc4ee00 | 2013-03-26 23:39:51 | [diff] [blame] | 336 | gfx::SizeF viewport_size = VisibleViewportSize(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 337 | |
| 338 | double start_time_seconds = (start_time - base::TimeTicks()).InSecondsF(); |
[email protected] | 85d136f78 | 2013-04-26 22:04:40 | [diff] [blame] | 339 | |
| 340 | // Easing constants experimentally determined. |
| 341 | scoped_ptr<TimingFunction> timing_function = |
| 342 | CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); |
| 343 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 344 | page_scale_animation_ = |
| 345 | PageScaleAnimation::Create(scroll_total, |
| 346 | active_tree_->total_page_scale_factor(), |
| 347 | viewport_size, |
| 348 | scaled_scrollable_size, |
[email protected] | 85d136f78 | 2013-04-26 22:04:40 | [diff] [blame] | 349 | start_time_seconds, |
| 350 | timing_function.Pass()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 351 | |
| 352 | if (anchor_point) { |
| 353 | gfx::Vector2dF anchor(target_offset); |
| 354 | page_scale_animation_->ZoomWithAnchor(anchor, |
| 355 | page_scale, |
| 356 | duration.InSecondsF()); |
| 357 | } else { |
| 358 | gfx::Vector2dF scaled_target_offset = target_offset; |
| 359 | page_scale_animation_->ZoomTo(scaled_target_offset, |
| 360 | page_scale, |
| 361 | duration.InSecondsF()); |
| 362 | } |
| 363 | |
| 364 | client_->SetNeedsRedrawOnImplThread(); |
| 365 | client_->SetNeedsCommitOnImplThread(); |
| 366 | client_->RenewTreePriority(); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 367 | } |
| 368 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 369 | void LayerTreeHostImpl::ScheduleAnimation() { |
| 370 | client_->SetNeedsRedrawOnImplThread(); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 371 | } |
| 372 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 373 | bool LayerTreeHostImpl::HaveTouchEventHandlersAt(gfx::Point viewport_point) { |
| 374 | if (!EnsureRenderSurfaceLayerList()) |
| 375 | return false; |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 376 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 377 | gfx::PointF device_viewport_point = |
| 378 | gfx::ScalePoint(viewport_point, device_scale_factor_); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 379 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 380 | // First find out which layer was hit from the saved list of visible layers |
| 381 | // in the most recent frame. |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 382 | LayerImpl* layer_impl = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 383 | device_viewport_point, |
| 384 | active_tree_->RenderSurfaceLayerList()); |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 385 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 386 | // Walk up the hierarchy and look for a layer with a touch event handler |
| 387 | // region that the given point hits. |
| 388 | for (; layer_impl; layer_impl = layer_impl->parent()) { |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 389 | if (LayerTreeHostCommon::LayerHasTouchEventHandlersAt(device_viewport_point, |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 390 | layer_impl)) |
| 391 | return true; |
| 392 | } |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 393 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 394 | return false; |
| 395 | } |
| 396 | |
[email protected] | b76329d | 2013-06-11 04:15:08 | [diff] [blame] | 397 | void LayerTreeHostImpl::SetLatencyInfoForInputEvent( |
| 398 | const ui::LatencyInfo& latency_info) { |
| 399 | active_tree()->SetLatencyInfo(latency_info); |
| 400 | } |
| 401 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 402 | void LayerTreeHostImpl::TrackDamageForAllSurfaces( |
| 403 | LayerImpl* root_draw_layer, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 404 | const LayerImplList& render_surface_layer_list) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 405 | // For now, we use damage tracking to compute a global scissor. To do this, we |
| 406 | // must compute all damage tracking before drawing anything, so that we know |
| 407 | // the root damage rect. The root damage rect is then used to scissor each |
| 408 | // surface. |
| 409 | |
| 410 | for (int surface_index = render_surface_layer_list.size() - 1; |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 411 | surface_index >= 0; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 412 | --surface_index) { |
| 413 | LayerImpl* render_surface_layer = render_surface_layer_list[surface_index]; |
| 414 | RenderSurfaceImpl* render_surface = render_surface_layer->render_surface(); |
| 415 | DCHECK(render_surface); |
| 416 | render_surface->damage_tracker()->UpdateDamageTrackingState( |
| 417 | render_surface->layer_list(), |
| 418 | render_surface_layer->id(), |
| 419 | render_surface->SurfacePropertyChangedOnlyFromDescendant(), |
| 420 | render_surface->content_rect(), |
| 421 | render_surface_layer->mask_layer(), |
| 422 | render_surface_layer->filters(), |
| 423 | render_surface_layer->filter().get()); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | void LayerTreeHostImpl::FrameData::AppendRenderPass( |
| 428 | scoped_ptr<RenderPass> render_pass) { |
| 429 | render_passes_by_id[render_pass->id] = render_pass.get(); |
| 430 | render_passes.push_back(render_pass.Pass()); |
| 431 | } |
| 432 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 433 | static DrawMode GetDrawMode(OutputSurface* output_surface) { |
| 434 | if (output_surface->ForcedDrawToSoftwareDevice()) { |
| 435 | return DRAW_MODE_RESOURCELESS_SOFTWARE; |
| 436 | } else if (output_surface->context3d()) { |
| 437 | return DRAW_MODE_HARDWARE; |
| 438 | } else { |
| 439 | DCHECK(output_surface->software_device()); |
| 440 | return DRAW_MODE_SOFTWARE; |
| 441 | } |
| 442 | } |
| 443 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 444 | static void AppendQuadsForLayer(RenderPass* target_render_pass, |
| 445 | LayerImpl* layer, |
| 446 | const OcclusionTrackerImpl& occlusion_tracker, |
| 447 | AppendQuadsData* append_quads_data) { |
| 448 | bool for_surface = false; |
[email protected] | c7e95b4 | 2013-03-18 01:13:49 | [diff] [blame] | 449 | QuadCuller quad_culler(&target_render_pass->quad_list, |
| 450 | &target_render_pass->shared_quad_state_list, |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 451 | layer, |
| 452 | occlusion_tracker, |
| 453 | layer->ShowDebugBorders(), |
| 454 | for_surface); |
| 455 | layer->AppendQuads(&quad_culler, append_quads_data); |
| 456 | } |
| 457 | |
| 458 | static void AppendQuadsForRenderSurfaceLayer( |
| 459 | RenderPass* target_render_pass, |
| 460 | LayerImpl* layer, |
| 461 | const RenderPass* contributing_render_pass, |
| 462 | const OcclusionTrackerImpl& occlusion_tracker, |
| 463 | AppendQuadsData* append_quads_data) { |
| 464 | bool for_surface = true; |
[email protected] | c7e95b4 | 2013-03-18 01:13:49 | [diff] [blame] | 465 | QuadCuller quad_culler(&target_render_pass->quad_list, |
| 466 | &target_render_pass->shared_quad_state_list, |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 467 | layer, |
| 468 | occlusion_tracker, |
| 469 | layer->ShowDebugBorders(), |
| 470 | for_surface); |
| 471 | |
| 472 | bool is_replica = false; |
| 473 | layer->render_surface()->AppendQuads(&quad_culler, |
| 474 | append_quads_data, |
| 475 | is_replica, |
| 476 | contributing_render_pass->id); |
| 477 | |
| 478 | // Add replica after the surface so that it appears below the surface. |
| 479 | if (layer->has_replica()) { |
| 480 | is_replica = true; |
| 481 | layer->render_surface()->AppendQuads(&quad_culler, |
| 482 | append_quads_data, |
| 483 | is_replica, |
| 484 | contributing_render_pass->id); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | static void AppendQuadsToFillScreen( |
| 489 | RenderPass* target_render_pass, |
| 490 | LayerImpl* root_layer, |
| 491 | SkColor screen_background_color, |
| 492 | const OcclusionTrackerImpl& occlusion_tracker) { |
| 493 | if (!root_layer || !SkColorGetA(screen_background_color)) |
| 494 | return; |
| 495 | |
| 496 | Region fill_region = occlusion_tracker.ComputeVisibleRegionInScreen(); |
| 497 | if (fill_region.IsEmpty()) |
| 498 | return; |
| 499 | |
| 500 | bool for_surface = false; |
[email protected] | c7e95b4 | 2013-03-18 01:13:49 | [diff] [blame] | 501 | QuadCuller quad_culler(&target_render_pass->quad_list, |
| 502 | &target_render_pass->shared_quad_state_list, |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 503 | root_layer, |
| 504 | occlusion_tracker, |
| 505 | root_layer->ShowDebugBorders(), |
| 506 | for_surface); |
| 507 | |
| 508 | // Manually create the quad state for the gutter quads, as the root layer |
| 509 | // doesn't have any bounds and so can't generate this itself. |
| 510 | // TODO(danakj): Make the gutter quads generated by the solid color layer |
| 511 | // (make it smarter about generating quads to fill unoccluded areas). |
| 512 | |
| 513 | gfx::Rect root_target_rect = root_layer->render_surface()->content_rect(); |
| 514 | float opacity = 1.f; |
| 515 | SharedQuadState* shared_quad_state = |
[email protected] | c7e95b4 | 2013-03-18 01:13:49 | [diff] [blame] | 516 | quad_culler.UseSharedQuadState(SharedQuadState::Create()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 517 | shared_quad_state->SetAll(root_layer->draw_transform(), |
| 518 | root_target_rect.size(), |
| 519 | root_target_rect, |
| 520 | root_target_rect, |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 521 | false, |
[email protected] | f57bbc0 | 2012-11-21 07:02:15 | [diff] [blame] | 522 | opacity); |
| 523 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 524 | AppendQuadsData append_quads_data; |
[email protected] | bda4196 | 2013-01-07 18:46:17 | [diff] [blame] | 525 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 526 | gfx::Transform transform_to_layer_space(gfx::Transform::kSkipInitialization); |
| 527 | bool did_invert = root_layer->screen_space_transform().GetInverse( |
| 528 | &transform_to_layer_space); |
| 529 | DCHECK(did_invert); |
| 530 | for (Region::Iterator fill_rects(fill_region); |
| 531 | fill_rects.has_rect(); |
| 532 | fill_rects.next()) { |
| 533 | // The root layer transform is composed of translations and scales only, |
| 534 | // no perspective, so mapping is sufficient (as opposed to projecting). |
| 535 | gfx::Rect layer_rect = |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 536 | MathUtil::MapClippedRect(transform_to_layer_space, fill_rects.rect()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 537 | // Skip the quad culler and just append the quads directly to avoid |
| 538 | // occlusion checks. |
| 539 | scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); |
[email protected] | 10a30b1 | 2013-05-02 16:42:11 | [diff] [blame] | 540 | quad->SetNew(shared_quad_state, layer_rect, screen_background_color, false); |
[email protected] | c7e95b4 | 2013-03-18 01:13:49 | [diff] [blame] | 541 | quad_culler.Append(quad.PassAs<DrawQuad>(), &append_quads_data); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 542 | } |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 543 | } |
| 544 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 545 | bool LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) { |
| 546 | DCHECK(frame->render_passes.empty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 547 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 548 | if (!CanDraw() || !active_tree_->root_layer()) |
| 549 | return false; |
[email protected] | 2d69299 | 2012-12-19 01:19:32 | [diff] [blame] | 550 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 551 | TrackDamageForAllSurfaces(active_tree_->root_layer(), |
| 552 | *frame->render_surface_layer_list); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 553 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 554 | // If the root render surface has no visible damage, then don't generate a |
| 555 | // frame at all. |
| 556 | RenderSurfaceImpl* root_surface = |
| 557 | active_tree_->root_layer()->render_surface(); |
| 558 | bool root_surface_has_no_visible_damage = |
| 559 | !root_surface->damage_tracker()->current_damage_rect().Intersects( |
| 560 | root_surface->content_rect()); |
| 561 | bool root_surface_has_contributing_layers = |
| 562 | !root_surface->layer_list().empty(); |
| 563 | if (root_surface_has_contributing_layers && |
| 564 | root_surface_has_no_visible_damage) { |
| 565 | TRACE_EVENT0("cc", |
| 566 | "LayerTreeHostImpl::CalculateRenderPasses::EmptyDamageRect"); |
| 567 | frame->has_no_damage = true; |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 568 | // A copy request should cause damage, so we should not have any copy |
| 569 | // requests in this case. |
| 570 | DCHECK_EQ(0u, active_tree_->LayersWithCopyOutputRequest().size()); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 571 | return true; |
| 572 | } |
| 573 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 574 | TRACE_EVENT1("cc", |
| 575 | "LayerTreeHostImpl::CalculateRenderPasses", |
| 576 | "render_surface_layer_list.size()", |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 577 | static_cast<uint64>(frame->render_surface_layer_list->size())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 578 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 579 | // Create the render passes in dependency order. |
| 580 | for (int surface_index = frame->render_surface_layer_list->size() - 1; |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 581 | surface_index >= 0; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 582 | --surface_index) { |
| 583 | LayerImpl* render_surface_layer = |
| 584 | (*frame->render_surface_layer_list)[surface_index]; |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 585 | RenderSurfaceImpl* render_surface = render_surface_layer->render_surface(); |
| 586 | |
| 587 | bool should_draw_into_render_pass = |
| 588 | render_surface_layer->parent() == NULL || |
| 589 | render_surface->contributes_to_drawn_surface() || |
| 590 | render_surface_layer->HasCopyRequest(); |
| 591 | if (should_draw_into_render_pass) |
| 592 | render_surface_layer->render_surface()->AppendRenderPasses(frame); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 593 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 594 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 595 | bool record_metrics_for_frame = |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 596 | settings_.show_overdraw_in_tracing && |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 597 | base::debug::TraceLog::GetInstance() && |
| 598 | base::debug::TraceLog::GetInstance()->IsEnabled(); |
| 599 | OcclusionTrackerImpl occlusion_tracker( |
| 600 | active_tree_->root_layer()->render_surface()->content_rect(), |
| 601 | record_metrics_for_frame); |
| 602 | occlusion_tracker.set_minimum_tracking_size( |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 603 | settings_.minimum_occlusion_tracking_size); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 604 | |
[email protected] | 846f455b | 2013-03-18 19:07:41 | [diff] [blame] | 605 | if (debug_state_.show_occluding_rects) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 606 | occlusion_tracker.set_occluding_screen_space_rects_container( |
| 607 | &frame->occluding_screen_space_rects); |
| 608 | } |
[email protected] | 846f455b | 2013-03-18 19:07:41 | [diff] [blame] | 609 | if (debug_state_.show_non_occluding_rects) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 610 | occlusion_tracker.set_non_occluding_screen_space_rects_container( |
| 611 | &frame->non_occluding_screen_space_rects); |
| 612 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 613 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 614 | // Add quads to the Render passes in FrontToBack order to allow for testing |
| 615 | // occlusion and performing culling during the tree walk. |
| 616 | typedef LayerIterator<LayerImpl, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 617 | LayerImplList, |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 618 | RenderSurfaceImpl, |
| 619 | LayerIteratorActions::FrontToBack> LayerIteratorType; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 620 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 621 | // Typically when we are missing a texture and use a checkerboard quad, we |
| 622 | // still draw the frame. However when the layer being checkerboarded is moving |
| 623 | // due to an impl-animation, we drop the frame to avoid flashing due to the |
| 624 | // texture suddenly appearing in the future. |
| 625 | bool draw_frame = true; |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 626 | // When we have a copy request for a layer, we need to draw no matter |
| 627 | // what, as the layer may disappear after this frame. |
| 628 | bool have_copy_request = false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 629 | |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 630 | int layers_drawn = 0; |
| 631 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 632 | const DrawMode draw_mode = GetDrawMode(output_surface_.get()); |
| 633 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 634 | LayerIteratorType end = |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 635 | LayerIteratorType::End(frame->render_surface_layer_list); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 636 | for (LayerIteratorType it = |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 637 | LayerIteratorType::Begin(frame->render_surface_layer_list); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 638 | it != end; |
| 639 | ++it) { |
| 640 | RenderPass::Id target_render_pass_id = |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 641 | it.target_render_surface_layer()->render_surface()->RenderPassId(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 642 | RenderPass* target_render_pass = |
| 643 | frame->render_passes_by_id[target_render_pass_id]; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 644 | |
[email protected] | 0e5f714 | 2013-05-24 06:45:36 | [diff] [blame] | 645 | bool prevent_occlusion = it.target_render_surface_layer()->HasCopyRequest(); |
[email protected] | 2ea5e6c | 2013-04-26 21:52:23 | [diff] [blame] | 646 | occlusion_tracker.EnterLayer(it, prevent_occlusion); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 647 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 648 | AppendQuadsData append_quads_data(target_render_pass_id); |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 649 | |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 650 | if (it.represents_target_render_surface()) { |
[email protected] | 0e5f714 | 2013-05-24 06:45:36 | [diff] [blame] | 651 | if (it->HasCopyRequest()) { |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 652 | have_copy_request = true; |
[email protected] | d4d017e | 2013-06-20 21:46:11 | [diff] [blame] | 653 | it->TakeCopyRequestsAndTransformToTarget( |
| 654 | &target_render_pass->copy_requests); |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 655 | } |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 656 | } else if (it.represents_contributing_render_surface() && |
| 657 | it->render_surface()->contributes_to_drawn_surface()) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 658 | RenderPass::Id contributing_render_pass_id = |
| 659 | it->render_surface()->RenderPassId(); |
| 660 | RenderPass* contributing_render_pass = |
| 661 | frame->render_passes_by_id[contributing_render_pass_id]; |
| 662 | AppendQuadsForRenderSurfaceLayer(target_render_pass, |
| 663 | *it, |
| 664 | contributing_render_pass, |
| 665 | occlusion_tracker, |
| 666 | &append_quads_data); |
[email protected] | e1e768f | 2013-03-26 08:48:09 | [diff] [blame] | 667 | } else if (it.represents_itself() && |
| 668 | !it->visible_content_rect().IsEmpty()) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 669 | bool has_occlusion_from_outside_target_surface; |
| 670 | bool impl_draw_transform_is_unknown = false; |
| 671 | if (occlusion_tracker.Occluded( |
| 672 | it->render_target(), |
| 673 | it->visible_content_rect(), |
| 674 | it->draw_transform(), |
| 675 | impl_draw_transform_is_unknown, |
| 676 | it->is_clipped(), |
| 677 | it->clip_rect(), |
| 678 | &has_occlusion_from_outside_target_surface)) { |
[email protected] | e1e768f | 2013-03-26 08:48:09 | [diff] [blame] | 679 | append_quads_data.had_occlusion_from_outside_target_surface |= |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 680 | has_occlusion_from_outside_target_surface; |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 681 | } else if (it->WillDraw(draw_mode, resource_provider_.get())) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 682 | DCHECK_EQ(active_tree_, it->layer_tree_impl()); |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 683 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 684 | frame->will_draw_layers.push_back(*it); |
[email protected] | 7d929c0 | 2012-09-20 17:26:57 | [diff] [blame] | 685 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 686 | if (it->HasContributingDelegatedRenderPasses()) { |
| 687 | RenderPass::Id contributing_render_pass_id = |
| 688 | it->FirstContributingRenderPassId(); |
| 689 | while (frame->render_passes_by_id.find(contributing_render_pass_id) != |
| 690 | frame->render_passes_by_id.end()) { |
| 691 | RenderPass* render_pass = |
| 692 | frame->render_passes_by_id[contributing_render_pass_id]; |
[email protected] | f586491 | 2013-02-01 03:18:14 | [diff] [blame] | 693 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 694 | AppendQuadsData append_quads_data(render_pass->id); |
| 695 | AppendQuadsForLayer(render_pass, |
| 696 | *it, |
| 697 | occlusion_tracker, |
| 698 | &append_quads_data); |
[email protected] | 7d929c0 | 2012-09-20 17:26:57 | [diff] [blame] | 699 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 700 | contributing_render_pass_id = |
| 701 | it->NextContributingRenderPassId(contributing_render_pass_id); |
| 702 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 703 | } |
| 704 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 705 | AppendQuadsForLayer(target_render_pass, |
| 706 | *it, |
| 707 | occlusion_tracker, |
| 708 | &append_quads_data); |
| 709 | } |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 710 | |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 711 | ++layers_drawn; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 712 | } |
| 713 | |
[email protected] | e1e768f | 2013-03-26 08:48:09 | [diff] [blame] | 714 | if (append_quads_data.had_occlusion_from_outside_target_surface) |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 715 | target_render_pass->has_occlusion_from_outside_target_surface = true; |
| 716 | |
[email protected] | e1e768f | 2013-03-26 08:48:09 | [diff] [blame] | 717 | if (append_quads_data.num_missing_tiles) { |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 718 | rendering_stats_instrumentation_->AddMissingTiles( |
[email protected] | e1e768f | 2013-03-26 08:48:09 | [diff] [blame] | 719 | append_quads_data.num_missing_tiles); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 720 | bool layer_has_animating_transform = |
| 721 | it->screen_space_transform_is_animating() || |
| 722 | it->draw_transform_is_animating(); |
| 723 | if (layer_has_animating_transform) |
| 724 | draw_frame = false; |
| 725 | } |
| 726 | |
[email protected] | e1e768f | 2013-03-26 08:48:09 | [diff] [blame] | 727 | if (append_quads_data.had_incomplete_tile) |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 728 | frame->contains_incomplete_tile = true; |
| 729 | |
| 730 | occlusion_tracker.LeaveLayer(it); |
| 731 | } |
| 732 | |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 733 | if (have_copy_request) |
| 734 | draw_frame = true; |
| 735 | |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 736 | rendering_stats_instrumentation_->AddLayersDrawn(layers_drawn); |
| 737 | |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 738 | #ifndef NDEBUG |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 739 | for (size_t i = 0; i < frame->render_passes.size(); ++i) { |
| 740 | for (size_t j = 0; j < frame->render_passes[i]->quad_list.size(); ++j) |
| 741 | DCHECK(frame->render_passes[i]->quad_list[j]->shared_quad_state); |
| 742 | DCHECK(frame->render_passes_by_id.find(frame->render_passes[i]->id) |
| 743 | != frame->render_passes_by_id.end()); |
| 744 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 745 | #endif |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 746 | DCHECK(frame->render_passes.back()->output_rect.origin().IsOrigin()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 747 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 748 | if (!active_tree_->has_transparent_background()) { |
| 749 | frame->render_passes.back()->has_transparent_background = false; |
| 750 | AppendQuadsToFillScreen(frame->render_passes.back(), |
| 751 | active_tree_->root_layer(), |
| 752 | active_tree_->background_color(), |
| 753 | occlusion_tracker); |
| 754 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 755 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 756 | if (draw_frame) |
| 757 | occlusion_tracker.overdraw_metrics()->RecordMetrics(this); |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 758 | else |
| 759 | DCHECK(!have_copy_request); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 760 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 761 | RemoveRenderPasses(CullRenderPassesWithNoQuads(), frame); |
[email protected] | b09c194 | 2013-05-10 00:06:37 | [diff] [blame] | 762 | if (!output_surface_->ForcedDrawToSoftwareDevice()) |
| 763 | renderer_->DecideRenderPassAllocationsForFrame(frame->render_passes); |
[email protected] | d15d962 | 2013-06-21 02:49:15 | [diff] [blame] | 764 | RemoveRenderPasses(CullRenderPassesWithCachedTextures(renderer_.get()), |
| 765 | frame); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 766 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 767 | // Any copy requests left in the tree are not going to get serviced, and |
| 768 | // should be aborted. |
| 769 | ScopedPtrVector<CopyOutputRequest> requests_to_abort; |
| 770 | while (!active_tree_->LayersWithCopyOutputRequest().empty()) { |
| 771 | LayerImpl* layer = active_tree_->LayersWithCopyOutputRequest().back(); |
| 772 | layer->TakeCopyRequestsAndTransformToTarget(&requests_to_abort); |
| 773 | } |
| 774 | for (size_t i = 0; i < requests_to_abort.size(); ++i) |
| 775 | requests_to_abort[i]->SendEmptyResult(); |
| 776 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 777 | // If we're making a frame to draw, it better have at least one render pass. |
| 778 | DCHECK(!frame->render_passes.empty()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 779 | return draw_frame; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 780 | } |
| 781 | |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 782 | void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { |
| 783 | if (input_handler_client_) |
| 784 | input_handler_client_->MainThreadHasStoppedFlinging(); |
| 785 | } |
| 786 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 787 | void LayerTreeHostImpl::UpdateBackgroundAnimateTicking( |
| 788 | bool should_background_tick) { |
[email protected] | 810d40b7 | 2013-06-20 18:26:15 | [diff] [blame] | 789 | DCHECK(proxy_->IsImplThread()); |
| 790 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 791 | bool enabled = should_background_tick && |
| 792 | !animation_registrar_->active_animation_controllers().empty(); |
| 793 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 794 | // Lazily create the time_source adapter so that we can vary the interval for |
| 795 | // testing. |
| 796 | if (!time_source_client_adapter_) { |
| 797 | time_source_client_adapter_ = LayerTreeHostImplTimeSourceAdapter::Create( |
| 798 | this, |
[email protected] | 810d40b7 | 2013-06-20 18:26:15 | [diff] [blame] | 799 | DelayBasedTimeSource::Create( |
| 800 | LowFrequencyAnimationInterval(), |
| 801 | proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() |
| 802 | : proxy_->MainThreadTaskRunner())); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 803 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 804 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 805 | time_source_client_adapter_->SetActive(enabled); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 806 | } |
| 807 | |
[email protected] | b9d4a36 | 2013-04-23 05:36:27 | [diff] [blame] | 808 | void LayerTreeHostImpl::SetViewportDamage(gfx::Rect damage_rect) { |
[email protected] | 878705be | 2013-04-15 22:44:02 | [diff] [blame] | 809 | viewport_damage_rect_.Union(damage_rect); |
| 810 | } |
| 811 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 812 | static inline RenderPass* FindRenderPassById( |
| 813 | RenderPass::Id render_pass_id, |
| 814 | const LayerTreeHostImpl::FrameData& frame) { |
| 815 | RenderPassIdHashMap::const_iterator it = |
| 816 | frame.render_passes_by_id.find(render_pass_id); |
| 817 | return it != frame.render_passes_by_id.end() ? it->second : NULL; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 818 | } |
| 819 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 820 | static void RemoveRenderPassesRecursive(RenderPass::Id remove_render_pass_id, |
| 821 | LayerTreeHostImpl::FrameData* frame) { |
| 822 | RenderPass* remove_render_pass = |
| 823 | FindRenderPassById(remove_render_pass_id, *frame); |
| 824 | // The pass was already removed by another quad - probably the original, and |
| 825 | // we are the replica. |
| 826 | if (!remove_render_pass) |
| 827 | return; |
| 828 | RenderPassList& render_passes = frame->render_passes; |
| 829 | RenderPassList::iterator to_remove = std::find(render_passes.begin(), |
| 830 | render_passes.end(), |
| 831 | remove_render_pass); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 832 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 833 | DCHECK(to_remove != render_passes.end()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 834 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 835 | scoped_ptr<RenderPass> removed_pass = render_passes.take(to_remove); |
| 836 | frame->render_passes.erase(to_remove); |
| 837 | frame->render_passes_by_id.erase(remove_render_pass_id); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 838 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 839 | // Now follow up for all RenderPass quads and remove their RenderPasses |
| 840 | // recursively. |
| 841 | const QuadList& quad_list = removed_pass->quad_list; |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 842 | QuadList::ConstBackToFrontIterator quad_list_iterator = |
| 843 | quad_list.BackToFrontBegin(); |
| 844 | for (; quad_list_iterator != quad_list.BackToFrontEnd(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 845 | ++quad_list_iterator) { |
| 846 | DrawQuad* current_quad = (*quad_list_iterator); |
| 847 | if (current_quad->material != DrawQuad::RENDER_PASS) |
| 848 | continue; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 849 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 850 | RenderPass::Id next_remove_render_pass_id = |
| 851 | RenderPassDrawQuad::MaterialCast(current_quad)->render_pass_id; |
| 852 | RemoveRenderPassesRecursive(next_remove_render_pass_id, frame); |
| 853 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 854 | } |
| 855 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 856 | bool LayerTreeHostImpl::CullRenderPassesWithCachedTextures:: |
| 857 | ShouldRemoveRenderPass(const RenderPassDrawQuad& quad, |
| 858 | const FrameData& frame) const { |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 859 | DCHECK(renderer_); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 860 | bool quad_has_damage = !quad.contents_changed_since_last_frame.IsEmpty(); |
| 861 | bool quad_has_cached_resource = |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 862 | renderer_->HaveCachedResourcesForRenderPassId(quad.render_pass_id); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 863 | if (quad_has_damage) { |
| 864 | TRACE_EVENT0("cc", "CullRenderPassesWithCachedTextures have damage"); |
| 865 | return false; |
| 866 | } else if (!quad_has_cached_resource) { |
| 867 | TRACE_EVENT0("cc", "CullRenderPassesWithCachedTextures have no texture"); |
| 868 | return false; |
| 869 | } |
| 870 | TRACE_EVENT0("cc", "CullRenderPassesWithCachedTextures dropped!"); |
| 871 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 872 | } |
| 873 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 874 | bool LayerTreeHostImpl::CullRenderPassesWithNoQuads::ShouldRemoveRenderPass( |
| 875 | const RenderPassDrawQuad& quad, const FrameData& frame) const { |
| 876 | const RenderPass* render_pass = |
| 877 | FindRenderPassById(quad.render_pass_id, frame); |
| 878 | if (!render_pass) |
| 879 | return false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 880 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 881 | // If any quad or RenderPass draws into this RenderPass, then keep it. |
| 882 | const QuadList& quad_list = render_pass->quad_list; |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 883 | for (QuadList::ConstBackToFrontIterator quad_list_iterator = |
| 884 | quad_list.BackToFrontBegin(); |
| 885 | quad_list_iterator != quad_list.BackToFrontEnd(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 886 | ++quad_list_iterator) { |
| 887 | DrawQuad* current_quad = *quad_list_iterator; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 888 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 889 | if (current_quad->material != DrawQuad::RENDER_PASS) |
| 890 | return false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 891 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 892 | const RenderPass* contributing_pass = FindRenderPassById( |
| 893 | RenderPassDrawQuad::MaterialCast(current_quad)->render_pass_id, frame); |
| 894 | if (contributing_pass) |
| 895 | return false; |
| 896 | } |
| 897 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | // Defined for linking tests. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 901 | template CC_EXPORT void LayerTreeHostImpl::RemoveRenderPasses< |
| 902 | LayerTreeHostImpl::CullRenderPassesWithCachedTextures>( |
| 903 | CullRenderPassesWithCachedTextures culler, FrameData* frame); |
| 904 | template CC_EXPORT void LayerTreeHostImpl::RemoveRenderPasses< |
| 905 | LayerTreeHostImpl::CullRenderPassesWithNoQuads>( |
| 906 | CullRenderPassesWithNoQuads culler, FrameData*); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 907 | |
| 908 | // static |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 909 | template <typename RenderPassCuller> |
| 910 | void LayerTreeHostImpl::RemoveRenderPasses(RenderPassCuller culler, |
| 911 | FrameData* frame) { |
| 912 | for (size_t it = culler.RenderPassListBegin(frame->render_passes); |
| 913 | it != culler.RenderPassListEnd(frame->render_passes); |
| 914 | it = culler.RenderPassListNext(it)) { |
| 915 | const RenderPass* current_pass = frame->render_passes[it]; |
| 916 | const QuadList& quad_list = current_pass->quad_list; |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 917 | QuadList::ConstBackToFrontIterator quad_list_iterator = |
| 918 | quad_list.BackToFrontBegin(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 919 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 920 | for (; quad_list_iterator != quad_list.BackToFrontEnd(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 921 | ++quad_list_iterator) { |
| 922 | DrawQuad* current_quad = *quad_list_iterator; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 923 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 924 | if (current_quad->material != DrawQuad::RENDER_PASS) |
| 925 | continue; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 926 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 927 | const RenderPassDrawQuad* render_pass_quad = |
| 928 | RenderPassDrawQuad::MaterialCast(current_quad); |
| 929 | if (!culler.ShouldRemoveRenderPass(*render_pass_quad, *frame)) |
| 930 | continue; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 931 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 932 | // We are changing the vector in the middle of iteration. Because we |
| 933 | // delete render passes that draw into the current pass, we are |
| 934 | // guaranteed that any data from the iterator to the end will not |
| 935 | // change. So, capture the iterator position from the end of the |
| 936 | // list, and restore it after the change. |
| 937 | size_t position_from_end = frame->render_passes.size() - it; |
| 938 | RemoveRenderPassesRecursive(render_pass_quad->render_pass_id, frame); |
| 939 | it = frame->render_passes.size() - position_from_end; |
| 940 | DCHECK_GE(frame->render_passes.size(), position_from_end); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 941 | } |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 942 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 943 | } |
| 944 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 945 | bool LayerTreeHostImpl::PrepareToDraw(FrameData* frame, |
| 946 | gfx::Rect device_viewport_damage_rect) { |
[email protected] | 7a52f43e | 2013-07-10 01:58:47 | [diff] [blame] | 947 | TRACE_EVENT1("cc", |
| 948 | "LayerTreeHostImpl::PrepareToDraw", |
| 949 | "SourceFrameNumber", |
| 950 | active_tree_->source_frame_number()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 951 | |
[email protected] | 8bb6cfa | 2013-07-23 00:11:19 | [diff] [blame] | 952 | if (need_to_update_visible_tiles_before_draw_) { |
[email protected] | 39643fb | 2013-07-09 17:28:19 | [diff] [blame] | 953 | DCHECK(tile_manager_); |
[email protected] | 8bb6cfa | 2013-07-23 00:11:19 | [diff] [blame] | 954 | if (tile_manager_->UpdateVisibleTiles()) |
| 955 | DidInitializeVisibleTile(); |
[email protected] | 39643fb | 2013-07-09 17:28:19 | [diff] [blame] | 956 | } |
| 957 | |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 958 | active_tree_->UpdateDrawProperties(); |
[email protected] | 2e7ca42 | 2012-12-20 02:57:27 | [diff] [blame] | 959 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 960 | frame->render_surface_layer_list = &active_tree_->RenderSurfaceLayerList(); |
| 961 | frame->render_passes.clear(); |
| 962 | frame->render_passes_by_id.clear(); |
| 963 | frame->will_draw_layers.clear(); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 964 | frame->contains_incomplete_tile = false; |
| 965 | frame->has_no_damage = false; |
| 966 | |
| 967 | if (active_tree_->root_layer()) { |
[email protected] | 878705be | 2013-04-15 22:44:02 | [diff] [blame] | 968 | device_viewport_damage_rect.Union(viewport_damage_rect_); |
| 969 | viewport_damage_rect_ = gfx::Rect(); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 970 | |
| 971 | active_tree_->root_layer()->render_surface()->damage_tracker()-> |
| 972 | AddDamageNextUpdate(device_viewport_damage_rect); |
| 973 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 974 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 975 | if (!CalculateRenderPasses(frame)) |
| 976 | return false; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 977 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 978 | // If we return true, then we expect DrawLayers() to be called before this |
| 979 | // function is called again. |
| 980 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 981 | } |
| 982 | |
[email protected] | 0309ba5e0 | 2013-06-26 04:11:08 | [diff] [blame] | 983 | void LayerTreeHostImpl::EvictTexturesForTesting() { |
| 984 | EnforceManagedMemoryPolicy(ManagedMemoryPolicy(0)); |
| 985 | } |
| 986 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 987 | void LayerTreeHostImpl::EnforceManagedMemoryPolicy( |
| 988 | const ManagedMemoryPolicy& policy) { |
[email protected] | 206a392 | 2013-05-17 06:34:12 | [diff] [blame] | 989 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 990 | bool evicted_resources = client_->ReduceContentsTextureMemoryOnImplThread( |
[email protected] | 46b8acc | 2013-03-19 22:38:35 | [diff] [blame] | 991 | visible_ ? policy.bytes_limit_when_visible |
| 992 | : policy.bytes_limit_when_not_visible, |
| 993 | ManagedMemoryPolicy::PriorityCutoffToValue( |
| 994 | visible_ ? policy.priority_cutoff_when_visible |
| 995 | : policy.priority_cutoff_when_not_visible)); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 996 | if (evicted_resources) { |
| 997 | active_tree_->SetContentsTexturesPurged(); |
| 998 | if (pending_tree_) |
| 999 | pending_tree_->SetContentsTexturesPurged(); |
| 1000 | client_->SetNeedsCommitOnImplThread(); |
| 1001 | client_->OnCanDrawStateChanged(CanDraw()); |
| 1002 | client_->RenewTreePriority(); |
| 1003 | } |
| 1004 | client_->SendManagedMemoryStats(); |
[email protected] | 8947cbe | 2012-11-28 05:27:43 | [diff] [blame] | 1005 | |
[email protected] | 8be1a9bf | 2013-05-01 03:45:19 | [diff] [blame] | 1006 | UpdateTileManagerMemoryPolicy(policy); |
| 1007 | } |
| 1008 | |
| 1009 | void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy( |
| 1010 | const ManagedMemoryPolicy& policy) { |
| 1011 | if (!tile_manager_) |
| 1012 | return; |
| 1013 | |
| 1014 | GlobalStateThatImpactsTilePriority new_state(tile_manager_->GlobalState()); |
| 1015 | new_state.memory_limit_in_bytes = visible_ ? |
| 1016 | policy.bytes_limit_when_visible : |
| 1017 | policy.bytes_limit_when_not_visible; |
| 1018 | // TODO(reveman): We should avoid keeping around unused resources if |
| 1019 | // possible. crbug.com/224475 |
| 1020 | new_state.unused_memory_limit_in_bytes = static_cast<size_t>( |
| 1021 | (static_cast<int64>(new_state.memory_limit_in_bytes) * |
| 1022 | settings_.max_unused_resource_memory_percentage) / 100); |
| 1023 | new_state.memory_limit_policy = |
| 1024 | ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( |
| 1025 | visible_ ? |
| 1026 | policy.priority_cutoff_when_visible : |
| 1027 | policy.priority_cutoff_when_not_visible); |
| 1028 | tile_manager_->SetGlobalState(new_state); |
[email protected] | a23451e | 2013-06-07 20:58:26 | [diff] [blame] | 1029 | manage_tiles_needed_ = true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1030 | } |
| 1031 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1032 | bool LayerTreeHostImpl::HasImplThread() const { |
| 1033 | return proxy_->HasImplThread(); |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 1034 | } |
| 1035 | |
[email protected] | 8612679 | 2013-03-16 20:07:54 | [diff] [blame] | 1036 | void LayerTreeHostImpl::DidInitializeVisibleTile() { |
| 1037 | // TODO(reveman): Determine tiles that changed and only damage |
| 1038 | // what's necessary. |
| 1039 | SetFullRootLayerDamage(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1040 | if (client_) |
[email protected] | 8612679 | 2013-03-16 20:07:54 | [diff] [blame] | 1041 | client_->DidInitializeVisibleTileOnImplThread(); |
[email protected] | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 1042 | } |
| 1043 | |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 1044 | void LayerTreeHostImpl::NotifyReadyToActivate() { |
[email protected] | 39643fb | 2013-07-09 17:28:19 | [diff] [blame] | 1045 | if (pending_tree_) { |
[email protected] | 8bb6cfa | 2013-07-23 00:11:19 | [diff] [blame] | 1046 | need_to_update_visible_tiles_before_draw_ = true; |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 1047 | ActivatePendingTree(); |
[email protected] | 39643fb | 2013-07-09 17:28:19 | [diff] [blame] | 1048 | } |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 1049 | } |
| 1050 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1051 | bool LayerTreeHostImpl::ShouldClearRootRenderPass() const { |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 1052 | return settings_.should_clear_root_render_pass; |
[email protected] | f35e232 | 2012-12-15 21:45:52 | [diff] [blame] | 1053 | } |
| 1054 | |
[email protected] | fd32d12 | 2013-06-29 13:11:04 | [diff] [blame] | 1055 | void LayerTreeHostImpl::SetMemoryPolicy( |
| 1056 | const ManagedMemoryPolicy& policy, |
| 1057 | bool discard_backbuffer_when_not_visible) { |
| 1058 | if (policy.bytes_limit_when_visible) { |
| 1059 | // Just ignore the memory manager when it says to set the limit to zero |
| 1060 | // bytes. This will happen when the memory manager thinks that the renderer |
| 1061 | // is not visible (which the renderer knows better). |
| 1062 | SetManagedMemoryPolicy(policy); |
| 1063 | } |
| 1064 | renderer_->SetDiscardBackBufferWhenNotVisible( |
| 1065 | discard_backbuffer_when_not_visible); |
| 1066 | } |
| 1067 | |
[email protected] | 5f07afc | 2013-07-19 05:17:18 | [diff] [blame] | 1068 | void LayerTreeHostImpl::SetTreeActivationCallback( |
| 1069 | const base::Closure& callback) { |
| 1070 | DCHECK(proxy_->IsImplThread()); |
| 1071 | DCHECK(settings_.impl_side_painting || callback.is_null()); |
[email protected] | 2022c67 | 2013-07-23 19:55:26 | [diff] [blame] | 1072 | tree_activation_callback_ = callback; |
[email protected] | 5f07afc | 2013-07-19 05:17:18 | [diff] [blame] | 1073 | } |
| 1074 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1075 | void LayerTreeHostImpl::SetManagedMemoryPolicy( |
| 1076 | const ManagedMemoryPolicy& policy) { |
| 1077 | if (managed_memory_policy_ == policy) |
| 1078 | return; |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 1079 | |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1080 | if (zero_budget_) |
| 1081 | DCHECK_EQ(0u, policy.bytes_limit_when_visible); |
| 1082 | |
[email protected] | d7626ffd | 2013-03-29 00:17:42 | [diff] [blame] | 1083 | // If there is already enough memory to draw everything imaginable and the |
| 1084 | // new memory limit does not change this, then do not re-commit. Don't bother |
| 1085 | // skipping commits if this is not visible (commits don't happen when not |
| 1086 | // visible, there will almost always be a commit when this becomes visible). |
| 1087 | bool needs_commit = true; |
| 1088 | if (visible() && |
| 1089 | policy.bytes_limit_when_visible >= |
| 1090 | max_memory_needed_bytes_ && |
| 1091 | managed_memory_policy_.bytes_limit_when_visible >= |
| 1092 | max_memory_needed_bytes_ && |
| 1093 | policy.priority_cutoff_when_visible == |
| 1094 | managed_memory_policy_.priority_cutoff_when_visible) { |
| 1095 | needs_commit = false; |
| 1096 | } |
| 1097 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1098 | managed_memory_policy_ = policy; |
| 1099 | if (!proxy_->HasImplThread()) { |
[email protected] | d7626ffd | 2013-03-29 00:17:42 | [diff] [blame] | 1100 | // In single-thread mode, this can be called on the main thread by |
| 1101 | // GLRenderer::OnMemoryAllocationChanged. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1102 | DebugScopedSetImplThread impl_thread(proxy_); |
[email protected] | 206a392 | 2013-05-17 06:34:12 | [diff] [blame] | 1103 | EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1104 | } else { |
| 1105 | DCHECK(proxy_->IsImplThread()); |
[email protected] | 206a392 | 2013-05-17 06:34:12 | [diff] [blame] | 1106 | EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1107 | } |
[email protected] | d7626ffd | 2013-03-29 00:17:42 | [diff] [blame] | 1108 | |
| 1109 | if (needs_commit) |
| 1110 | client_->SetNeedsCommitOnImplThread(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1111 | } |
| 1112 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1113 | void LayerTreeHostImpl::SetExternalDrawConstraints( |
| 1114 | const gfx::Transform& transform, |
| 1115 | gfx::Rect viewport) { |
| 1116 | external_transform_ = transform; |
| 1117 | external_viewport_ = viewport; |
| 1118 | } |
| 1119 | |
[email protected] | 1cd9f555 | 2013-04-26 04:22:03 | [diff] [blame] | 1120 | void LayerTreeHostImpl::SetNeedsRedrawRect(gfx::Rect damage_rect) { |
| 1121 | client_->SetNeedsRedrawRectOnImplThread(damage_rect); |
| 1122 | } |
| 1123 | |
[email protected] | df3c24c9 | 2013-06-19 03:54:35 | [diff] [blame] | 1124 | void LayerTreeHostImpl::BeginFrame(const BeginFrameArgs& args) { |
| 1125 | client_->BeginFrameOnImplThread(args); |
[email protected] | 7ed4751 | 2013-03-26 22:28:45 | [diff] [blame] | 1126 | } |
| 1127 | |
[email protected] | 36e5ff1 | 2013-06-11 12:19:29 | [diff] [blame] | 1128 | void LayerTreeHostImpl::OnSwapBuffersComplete( |
| 1129 | const CompositorFrameAck* ack) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1130 | // TODO(piman): We may need to do some validation on this ack before |
| 1131 | // processing it. |
[email protected] | 36e5ff1 | 2013-06-11 12:19:29 | [diff] [blame] | 1132 | if (ack && renderer_) |
| 1133 | renderer_->ReceiveSwapBuffersAck(*ack); |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 1134 | |
[email protected] | 36e5ff1 | 2013-06-11 12:19:29 | [diff] [blame] | 1135 | client_->OnSwapBuffersCompleteOnImplThread(); |
[email protected] | a46f3293 | 2012-12-07 21:43:16 | [diff] [blame] | 1136 | } |
| 1137 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1138 | void LayerTreeHostImpl::OnCanDrawStateChangedForTree() { |
| 1139 | client_->OnCanDrawStateChanged(CanDraw()); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 1140 | } |
| 1141 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1142 | CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { |
| 1143 | CompositorFrameMetadata metadata; |
| 1144 | metadata.device_scale_factor = device_scale_factor_; |
| 1145 | metadata.page_scale_factor = active_tree_->total_page_scale_factor(); |
| 1146 | metadata.viewport_size = active_tree_->ScrollableViewportSize(); |
| 1147 | metadata.root_layer_size = active_tree_->ScrollableSize(); |
| 1148 | metadata.min_page_scale_factor = active_tree_->min_page_scale_factor(); |
| 1149 | metadata.max_page_scale_factor = active_tree_->max_page_scale_factor(); |
[email protected] | 6a50af1 | 2013-06-14 08:47:50 | [diff] [blame] | 1150 | metadata.latency_info = active_tree_->GetLatencyInfo(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1151 | if (top_controls_manager_) { |
| 1152 | metadata.location_bar_offset = |
| 1153 | gfx::Vector2dF(0.f, top_controls_manager_->controls_top_offset()); |
| 1154 | metadata.location_bar_content_translation = |
| 1155 | gfx::Vector2dF(0.f, top_controls_manager_->content_top_offset()); |
[email protected] | 5a54b282 | 2013-03-26 10:00:01 | [diff] [blame] | 1156 | metadata.overdraw_bottom_height = overdraw_bottom_height_; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1157 | } |
[email protected] | bf189f6 | 2012-12-18 03:42:11 | [diff] [blame] | 1158 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1159 | if (!RootScrollLayer()) |
[email protected] | bf189f6 | 2012-12-18 03:42:11 | [diff] [blame] | 1160 | return metadata; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1161 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 1162 | metadata.root_scroll_offset = RootScrollLayer()->TotalScrollOffset(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1163 | |
| 1164 | return metadata; |
[email protected] | bf189f6 | 2012-12-18 03:42:11 | [diff] [blame] | 1165 | } |
| 1166 | |
[email protected] | 7367359 | 2013-04-03 22:14:32 | [diff] [blame] | 1167 | bool LayerTreeHostImpl::AllowPartialSwap() const { |
| 1168 | // We don't track damage on the HUD layer (it interacts with damage tracking |
| 1169 | // visualizations), so disable partial swaps to make the HUD layer display |
| 1170 | // properly. |
| 1171 | return !debug_state_.ShowHudRects(); |
| 1172 | } |
| 1173 | |
[email protected] | 6f50b8fa | 2013-07-01 19:51:49 | [diff] [blame] | 1174 | static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) { |
| 1175 | layer->DidBeginTracing(); |
| 1176 | } |
[email protected] | 37349bc | 2013-06-04 01:31:52 | [diff] [blame] | 1177 | |
[email protected] | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 1178 | void LayerTreeHostImpl::DrawLayers(FrameData* frame, |
| 1179 | base::TimeTicks frame_begin_time) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1180 | TRACE_EVENT0("cc", "LayerTreeHostImpl::DrawLayers"); |
| 1181 | DCHECK(CanDraw()); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 1182 | |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame^] | 1183 | if (frame->has_no_damage) { |
| 1184 | TRACE_EVENT0("cc", "EarlyOut_NoDamage"); |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 1185 | return; |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame^] | 1186 | } |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 1187 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1188 | DCHECK(!frame->render_passes.empty()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1189 | |
[email protected] | 9e359452 | 2013-03-18 00:57:36 | [diff] [blame] | 1190 | fps_counter_->SaveTimeStamp(frame_begin_time); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1191 | |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 1192 | rendering_stats_instrumentation_->SetScreenFrameCount( |
| 1193 | fps_counter_->current_frame_number()); |
| 1194 | rendering_stats_instrumentation_->SetDroppedFrameCount( |
| 1195 | fps_counter_->dropped_frame_count()); |
| 1196 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1197 | if (tile_manager_) { |
| 1198 | memory_history_->SaveEntry( |
| 1199 | tile_manager_->memory_stats_from_last_assign()); |
| 1200 | } |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 1201 | |
[email protected] | 846f455b | 2013-03-18 19:07:41 | [diff] [blame] | 1202 | if (debug_state_.ShowHudRects()) { |
[email protected] | d3599278 | 2013-03-14 14:54:02 | [diff] [blame] | 1203 | debug_rect_history_->SaveDebugRectsForCurrentFrame( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1204 | active_tree_->root_layer(), |
| 1205 | *frame->render_surface_layer_list, |
| 1206 | frame->occluding_screen_space_rects, |
| 1207 | frame->non_occluding_screen_space_rects, |
| 1208 | debug_state_); |
| 1209 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1210 | |
[email protected] | a848c10 | 2013-03-26 08:59:09 | [diff] [blame] | 1211 | if (!settings_.impl_side_painting && debug_state_.continuous_painting) { |
| 1212 | const RenderingStats& stats = |
| 1213 | rendering_stats_instrumentation_->GetRenderingStats(); |
| 1214 | paint_time_counter_->SavePaintTime(stats.total_paint_time); |
| 1215 | } |
| 1216 | |
[email protected] | 37349bc | 2013-06-04 01:31:52 | [diff] [blame] | 1217 | bool is_new_trace; |
| 1218 | TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); |
| 1219 | if (is_new_trace) { |
[email protected] | 6f50b8fa | 2013-07-01 19:51:49 | [diff] [blame] | 1220 | if (pending_tree_) { |
| 1221 | LayerTreeHostCommon::CallFunctionForSubtree( |
| 1222 | pending_tree_->root_layer(), |
| 1223 | base::Bind(&LayerTreeHostImplDidBeginTracingCallback)); |
| 1224 | } |
| 1225 | LayerTreeHostCommon::CallFunctionForSubtree( |
| 1226 | active_tree_->root_layer(), |
| 1227 | base::Bind(&LayerTreeHostImplDidBeginTracingCallback)); |
[email protected] | 37349bc | 2013-06-04 01:31:52 | [diff] [blame] | 1228 | } |
| 1229 | |
[email protected] | 9197dbcb | 2013-05-15 20:28:51 | [diff] [blame] | 1230 | TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
| 1231 | TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", this, |
| 1232 | TracedValue::FromValue(AsValue().release())); |
[email protected] | 131a0c2 | 2013-02-12 18:31:08 | [diff] [blame] | 1233 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1234 | // Because the contents of the HUD depend on everything else in the frame, the |
| 1235 | // contents of its texture are updated as the last thing before the frame is |
| 1236 | // drawn. |
| 1237 | if (active_tree_->hud_layer()) |
[email protected] | 264dc033 | 2013-03-17 21:00:54 | [diff] [blame] | 1238 | active_tree_->hud_layer()->UpdateHudTexture(resource_provider_.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1239 | |
[email protected] | b09c194 | 2013-05-10 00:06:37 | [diff] [blame] | 1240 | if (output_surface_->ForcedDrawToSoftwareDevice()) { |
| 1241 | scoped_ptr<SoftwareRenderer> temp_software_renderer = |
| 1242 | SoftwareRenderer::Create(this, output_surface_.get(), NULL); |
| 1243 | temp_software_renderer->DrawFrame(&frame->render_passes); |
| 1244 | } else { |
| 1245 | renderer_->DrawFrame(&frame->render_passes); |
| 1246 | } |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1247 | // The render passes should be consumed by the renderer. |
| 1248 | DCHECK(frame->render_passes.empty()); |
| 1249 | frame->render_passes_by_id.clear(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1250 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1251 | // The next frame should start by assuming nothing has changed, and changes |
| 1252 | // are noted as they occur. |
[email protected] | 264dc033 | 2013-03-17 21:00:54 | [diff] [blame] | 1253 | for (size_t i = 0; i < frame->render_surface_layer_list->size(); i++) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1254 | (*frame->render_surface_layer_list)[i]->render_surface()->damage_tracker()-> |
| 1255 | DidDrawDamagedArea(); |
| 1256 | } |
| 1257 | active_tree_->root_layer()->ResetAllChangeTrackingForSubtree(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1258 | } |
| 1259 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1260 | void LayerTreeHostImpl::DidDrawAllLayers(const FrameData& frame) { |
| 1261 | for (size_t i = 0; i < frame.will_draw_layers.size(); ++i) |
| 1262 | frame.will_draw_layers[i]->DidDraw(resource_provider_.get()); |
[email protected] | b914e10 | 2012-10-02 08:11:52 | [diff] [blame] | 1263 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1264 | // Once all layers have been drawn, pending texture uploads should no |
| 1265 | // longer block future uploads. |
[email protected] | d15d962 | 2013-06-21 02:49:15 | [diff] [blame] | 1266 | resource_provider_->MarkPendingUploadsAsNonBlocking(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1267 | } |
| 1268 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1269 | void LayerTreeHostImpl::FinishAllRendering() { |
| 1270 | if (renderer_) |
| 1271 | renderer_->Finish(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1272 | } |
| 1273 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1274 | bool LayerTreeHostImpl::IsContextLost() { |
| 1275 | DCHECK(proxy_->IsImplThread()); |
| 1276 | return renderer_ && renderer_->IsContextLost(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1277 | } |
| 1278 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1279 | const RendererCapabilities& LayerTreeHostImpl::GetRendererCapabilities() const { |
| 1280 | return renderer_->Capabilities(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1281 | } |
| 1282 | |
[email protected] | e034135 | 2013-04-06 05:01:20 | [diff] [blame] | 1283 | bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { |
| 1284 | if (frame.has_no_damage) |
| 1285 | return false; |
[email protected] | 36e5ff1 | 2013-06-11 12:19:29 | [diff] [blame] | 1286 | renderer_->SwapBuffers(); |
[email protected] | c5c50638 | 2013-04-30 04:42:16 | [diff] [blame] | 1287 | active_tree_->ClearLatencyInfo(); |
| 1288 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1289 | } |
| 1290 | |
[email protected] | c8cbae7 | 2013-05-23 10:45:03 | [diff] [blame] | 1291 | void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) { |
[email protected] | 7ed4751 | 2013-03-26 22:28:45 | [diff] [blame] | 1292 | if (output_surface_) |
[email protected] | c8cbae7 | 2013-05-23 10:45:03 | [diff] [blame] | 1293 | output_surface_->SetNeedsBeginFrame(enable); |
[email protected] | 7ed4751 | 2013-03-26 22:28:45 | [diff] [blame] | 1294 | } |
| 1295 | |
[email protected] | 94c40e629 | 2013-05-24 22:01:50 | [diff] [blame] | 1296 | float LayerTreeHostImpl::DeviceScaleFactor() const { |
| 1297 | return device_scale_factor_; |
| 1298 | } |
| 1299 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 1300 | gfx::SizeF LayerTreeHostImpl::VisibleViewportSize() const { |
| 1301 | gfx::SizeF dip_size = |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1302 | gfx::ScaleSize(device_viewport_size(), 1.f / device_scale_factor()); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 1303 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1304 | float top_offset = |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 1305 | top_controls_manager_ ? top_controls_manager_->content_top_offset() : 0.f; |
[email protected] | d908376 | 2013-03-24 01:36:40 | [diff] [blame] | 1306 | return gfx::SizeF(dip_size.width(), |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1307 | dip_size.height() - top_offset - overdraw_bottom_height_); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 1308 | } |
| 1309 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1310 | const LayerTreeSettings& LayerTreeHostImpl::Settings() const { |
| 1311 | return settings(); |
[email protected] | 49306751 | 2012-09-19 23:34:10 | [diff] [blame] | 1312 | } |
| 1313 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1314 | void LayerTreeHostImpl::DidLoseOutputSurface() { |
[email protected] | bb1e282 | 2013-04-17 22:06:01 | [diff] [blame] | 1315 | // TODO(jamesr): The renderer_ check is needed to make some of the |
| 1316 | // LayerTreeHostContextTest tests pass, but shouldn't be necessary (or |
| 1317 | // important) in production. We should adjust the test to not need this. |
| 1318 | if (renderer_) |
| 1319 | client_->DidLoseOutputSurfaceOnImplThread(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1320 | } |
| 1321 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1322 | void LayerTreeHostImpl::Readback(void* pixels, |
| 1323 | gfx::Rect rect_in_device_viewport) { |
| 1324 | DCHECK(renderer_); |
| 1325 | renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1326 | } |
| 1327 | |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 1328 | bool LayerTreeHostImpl::HaveRootScrollLayer() const { |
[email protected] | 3209161d | 2013-03-29 19:17:34 | [diff] [blame] | 1329 | return !!RootScrollLayer(); |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 1330 | } |
| 1331 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1332 | LayerImpl* LayerTreeHostImpl::RootLayer() const { |
| 1333 | return active_tree_->root_layer(); |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 1334 | } |
| 1335 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1336 | LayerImpl* LayerTreeHostImpl::RootScrollLayer() const { |
| 1337 | return active_tree_->RootScrollLayer(); |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 1338 | } |
| 1339 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1340 | LayerImpl* LayerTreeHostImpl::CurrentlyScrollingLayer() const { |
| 1341 | return active_tree_->CurrentlyScrollingLayer(); |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 1342 | } |
| 1343 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1344 | // Content layers can be either directly scrollable or contained in an outer |
| 1345 | // scrolling layer which applies the scroll transform. Given a content layer, |
| 1346 | // this function returns the associated scroll layer if any. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1347 | static LayerImpl* FindScrollLayerForContentLayer(LayerImpl* layer_impl) { |
| 1348 | if (!layer_impl) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1349 | return 0; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1350 | |
| 1351 | if (layer_impl->scrollable()) |
| 1352 | return layer_impl; |
| 1353 | |
| 1354 | if (layer_impl->DrawsContent() && |
| 1355 | layer_impl->parent() && |
| 1356 | layer_impl->parent()->scrollable()) |
| 1357 | return layer_impl->parent(); |
| 1358 | |
| 1359 | return 0; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1360 | } |
| 1361 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1362 | void LayerTreeHostImpl::CreatePendingTree() { |
| 1363 | CHECK(!pending_tree_); |
| 1364 | if (recycle_tree_) |
| 1365 | recycle_tree_.swap(pending_tree_); |
| 1366 | else |
| 1367 | pending_tree_ = LayerTreeImpl::create(this); |
| 1368 | client_->OnCanDrawStateChanged(CanDraw()); |
| 1369 | client_->OnHasPendingTreeStateChanged(pending_tree_); |
| 1370 | TRACE_EVENT_ASYNC_BEGIN0("cc", "PendingTree", pending_tree_.get()); |
| 1371 | TRACE_EVENT_ASYNC_STEP0("cc", |
| 1372 | "PendingTree", pending_tree_.get(), "waiting"); |
[email protected] | 2e7ca42 | 2012-12-20 02:57:27 | [diff] [blame] | 1373 | } |
| 1374 | |
[email protected] | 8bb6cfa | 2013-07-23 00:11:19 | [diff] [blame] | 1375 | void LayerTreeHostImpl::UpdateVisibleTiles() { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1376 | DCHECK(!client_->IsInsideDraw()) << |
[email protected] | 8bb6cfa | 2013-07-23 00:11:19 | [diff] [blame] | 1377 | "Updating visible tiles within a draw may trigger " |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1378 | "spurious redraws."; |
[email protected] | 8bb6cfa | 2013-07-23 00:11:19 | [diff] [blame] | 1379 | if (tile_manager_ && tile_manager_->UpdateVisibleTiles()) |
| 1380 | DidInitializeVisibleTile(); |
[email protected] | 39643fb | 2013-07-09 17:28:19 | [diff] [blame] | 1381 | |
[email protected] | 8bb6cfa | 2013-07-23 00:11:19 | [diff] [blame] | 1382 | need_to_update_visible_tiles_before_draw_ = false; |
[email protected] | eabe500 | 2013-01-12 22:07:48 | [diff] [blame] | 1383 | } |
| 1384 | |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 1385 | void LayerTreeHostImpl::ActivatePendingTreeIfNeeded() { |
| 1386 | DCHECK(pending_tree_); |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 1387 | CHECK(settings_.impl_side_painting); |
[email protected] | 2ae038b | 2013-01-28 12:52:09 | [diff] [blame] | 1388 | |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 1389 | if (!pending_tree_) |
| 1390 | return; |
| 1391 | |
| 1392 | // The tile manager is usually responsible for notifying activation. |
| 1393 | // If there is no tile manager, then we need to manually activate. |
| 1394 | if (!tile_manager_ || tile_manager_->AreTilesRequiredForActivationReady()) { |
| 1395 | ActivatePendingTree(); |
| 1396 | return; |
| 1397 | } |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 1398 | |
[email protected] | b67a44e | 2013-07-12 19:15:10 | [diff] [blame] | 1399 | // Manage tiles in case state affecting tile priority has changed. |
| 1400 | ManageTiles(); |
| 1401 | |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 1402 | TRACE_EVENT_ASYNC_STEP1( |
[email protected] | fcb846d | 2013-05-22 01:42:36 | [diff] [blame] | 1403 | "cc", |
| 1404 | "PendingTree", pending_tree_.get(), "activate", |
| 1405 | "state", TracedValue::FromValue(ActivationStateAsValue().release())); |
[email protected] | 2e7ca42 | 2012-12-20 02:57:27 | [diff] [blame] | 1406 | } |
| 1407 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1408 | void LayerTreeHostImpl::ActivatePendingTree() { |
| 1409 | CHECK(pending_tree_); |
| 1410 | TRACE_EVENT_ASYNC_END0("cc", "PendingTree", pending_tree_.get()); |
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 1411 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 1412 | active_tree_->SetRootLayerScrollOffsetDelegate(NULL); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1413 | active_tree_->PushPersistedState(pending_tree_.get()); |
| 1414 | if (pending_tree_->needs_full_tree_sync()) { |
| 1415 | active_tree_->SetRootLayer( |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 1416 | TreeSynchronizer::SynchronizeTrees(pending_tree_->root_layer(), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1417 | active_tree_->DetachLayerTree(), |
| 1418 | active_tree_.get())); |
| 1419 | } |
[email protected] | b5651c2 | 2013-03-14 15:06:33 | [diff] [blame] | 1420 | TreeSynchronizer::PushProperties(pending_tree_->root_layer(), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1421 | active_tree_->root_layer()); |
| 1422 | DCHECK(!recycle_tree_); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 1423 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1424 | pending_tree_->PushPropertiesTo(active_tree_.get()); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 1425 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1426 | // Now that we've synced everything from the pending tree to the active |
| 1427 | // tree, rename the pending tree the recycle tree so we can reuse it on the |
| 1428 | // next sync. |
| 1429 | pending_tree_.swap(recycle_tree_); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 1430 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 1431 | active_tree_->SetRootLayerScrollOffsetDelegate( |
| 1432 | root_layer_scroll_offset_delegate_); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1433 | active_tree_->DidBecomeActive(); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 1434 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1435 | // Reduce wasted memory now that unlinked resources are guaranteed not |
| 1436 | // to be used. |
| 1437 | client_->ReduceWastedContentsTextureMemoryOnImplThread(); |
[email protected] | a0b8417 | 2013-02-04 08:13:41 | [diff] [blame] | 1438 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1439 | client_->OnCanDrawStateChanged(CanDraw()); |
| 1440 | client_->OnHasPendingTreeStateChanged(pending_tree_); |
| 1441 | client_->SetNeedsRedrawOnImplThread(); |
| 1442 | client_->RenewTreePriority(); |
[email protected] | 652cf13 | 2013-02-15 21:53:24 | [diff] [blame] | 1443 | |
[email protected] | a848c10 | 2013-03-26 08:59:09 | [diff] [blame] | 1444 | if (debug_state_.continuous_painting) { |
| 1445 | const RenderingStats& stats = |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 1446 | rendering_stats_instrumentation_->GetRenderingStats(); |
[email protected] | a848c10 | 2013-03-26 08:59:09 | [diff] [blame] | 1447 | paint_time_counter_->SavePaintTime( |
[email protected] | 41abb6d9 | 2013-04-26 16:38:50 | [diff] [blame] | 1448 | stats.total_paint_time + stats.total_record_time + |
[email protected] | a848c10 | 2013-03-26 08:59:09 | [diff] [blame] | 1449 | stats.total_rasterize_time_for_now_bins_on_pending_tree); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1450 | } |
[email protected] | 2a61ad5 | 2013-05-13 14:01:29 | [diff] [blame] | 1451 | |
| 1452 | client_->DidActivatePendingTree(); |
[email protected] | 2022c67 | 2013-07-23 19:55:26 | [diff] [blame] | 1453 | if (!tree_activation_callback_.is_null()) |
| 1454 | tree_activation_callback_.Run(); |
[email protected] | 2e7ca42 | 2012-12-20 02:57:27 | [diff] [blame] | 1455 | } |
| 1456 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1457 | void LayerTreeHostImpl::SetVisible(bool visible) { |
| 1458 | DCHECK(proxy_->IsImplThread()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1459 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1460 | if (visible_ == visible) |
| 1461 | return; |
| 1462 | visible_ = visible; |
| 1463 | DidVisibilityChange(this, visible_); |
[email protected] | 206a392 | 2013-05-17 06:34:12 | [diff] [blame] | 1464 | EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1465 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1466 | if (!renderer_) |
| 1467 | return; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1468 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1469 | renderer_->SetVisible(visible); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1470 | } |
| 1471 | |
[email protected] | 206a392 | 2013-05-17 06:34:12 | [diff] [blame] | 1472 | ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const { |
| 1473 | if (!debug_state_.rasterize_only_visible_content) |
| 1474 | return managed_memory_policy_; |
| 1475 | |
| 1476 | ManagedMemoryPolicy actual = managed_memory_policy_; |
| 1477 | actual.priority_cutoff_when_not_visible = |
| 1478 | ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING; |
| 1479 | actual.priority_cutoff_when_visible = |
| 1480 | ManagedMemoryPolicy::CUTOFF_ALLOW_REQUIRED_ONLY; |
| 1481 | return actual; |
| 1482 | } |
| 1483 | |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1484 | void LayerTreeHostImpl::ReleaseTreeResources() { |
| 1485 | if (active_tree_->root_layer()) |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1486 | SendReleaseResourcesRecursive(active_tree_->root_layer()); |
| 1487 | if (pending_tree_ && pending_tree_->root_layer()) |
| 1488 | SendReleaseResourcesRecursive(pending_tree_->root_layer()); |
| 1489 | if (recycle_tree_ && recycle_tree_->root_layer()) |
| 1490 | SendReleaseResourcesRecursive(recycle_tree_->root_layer()); |
| 1491 | } |
| 1492 | |
| 1493 | void LayerTreeHostImpl::CreateAndSetRenderer( |
| 1494 | OutputSurface* output_surface, |
[email protected] | 50af3c2 | 2013-07-13 03:50:20 | [diff] [blame] | 1495 | ResourceProvider* resource_provider, |
| 1496 | bool skip_gl_renderer) { |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1497 | DCHECK(!renderer_); |
| 1498 | if (output_surface->capabilities().delegated_rendering) { |
| 1499 | renderer_ = |
| 1500 | DelegatingRenderer::Create(this, output_surface, resource_provider); |
[email protected] | 50af3c2 | 2013-07-13 03:50:20 | [diff] [blame] | 1501 | } else if (output_surface->context3d() && !skip_gl_renderer) { |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1502 | renderer_ = GLRenderer::Create(this, |
| 1503 | output_surface, |
| 1504 | resource_provider, |
| 1505 | settings_.highp_threshold_min, |
| 1506 | settings_.force_direct_layer_drawing); |
| 1507 | } else if (output_surface->software_device()) { |
| 1508 | renderer_ = |
| 1509 | SoftwareRenderer::Create(this, output_surface, resource_provider); |
| 1510 | } |
| 1511 | |
[email protected] | 8497583 | 2013-06-29 00:24:11 | [diff] [blame] | 1512 | if (renderer_) { |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1513 | renderer_->SetVisible(visible_); |
[email protected] | 8497583 | 2013-06-29 00:24:11 | [diff] [blame] | 1514 | SetFullRootLayerDamage(); |
| 1515 | } |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1516 | } |
| 1517 | |
[email protected] | 50af3c2 | 2013-07-13 03:50:20 | [diff] [blame] | 1518 | void LayerTreeHostImpl::CreateAndSetTileManager( |
| 1519 | ResourceProvider* resource_provider, |
| 1520 | bool using_map_image) { |
| 1521 | DCHECK(settings_.impl_side_painting); |
| 1522 | DCHECK(resource_provider); |
| 1523 | tile_manager_ = TileManager::Create(this, |
| 1524 | resource_provider, |
| 1525 | settings_.num_raster_threads, |
| 1526 | rendering_stats_instrumentation_, |
| 1527 | using_map_image); |
| 1528 | UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); |
[email protected] | 8bb6cfa | 2013-07-23 00:11:19 | [diff] [blame] | 1529 | need_to_update_visible_tiles_before_draw_ = false; |
[email protected] | 50af3c2 | 2013-07-13 03:50:20 | [diff] [blame] | 1530 | } |
| 1531 | |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1532 | void LayerTreeHostImpl::EnforceZeroBudget(bool zero_budget) { |
| 1533 | if (zero_budget_ == zero_budget) |
| 1534 | return; |
| 1535 | |
| 1536 | zero_budget_ = zero_budget; |
| 1537 | |
| 1538 | ManagedMemoryPolicy new_policy = managed_memory_policy_; |
| 1539 | if (zero_budget_) { |
| 1540 | new_policy.bytes_limit_when_visible = 0; |
| 1541 | } else { |
| 1542 | new_policy.bytes_limit_when_visible = |
| 1543 | PrioritizedResourceManager::DefaultMemoryAllocationLimit(); |
| 1544 | } |
| 1545 | SetManagedMemoryPolicy(new_policy); |
| 1546 | } |
| 1547 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1548 | bool LayerTreeHostImpl::InitializeRenderer( |
| 1549 | scoped_ptr<OutputSurface> output_surface) { |
| 1550 | // Since we will create a new resource provider, we cannot continue to use |
| 1551 | // the old resources (i.e. render_surfaces and texture IDs). Clear them |
| 1552 | // before we destroy the old resource provider. |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1553 | ReleaseTreeResources(); |
[email protected] | 7ba3ca7 | 2013-04-11 06:37:25 | [diff] [blame] | 1554 | if (resource_provider_) |
| 1555 | resource_provider_->DidLoseOutputSurface(); |
[email protected] | 45c4b1e | 2013-01-16 02:19:40 | [diff] [blame] | 1556 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1557 | // Note: order is important here. |
| 1558 | renderer_.reset(); |
| 1559 | tile_manager_.reset(); |
| 1560 | resource_provider_.reset(); |
| 1561 | output_surface_.reset(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1562 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1563 | if (!output_surface->BindToClient(this)) |
| 1564 | return false; |
[email protected] | be318165 | 2012-09-25 13:02:13 | [diff] [blame] | 1565 | |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1566 | scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create( |
| 1567 | output_surface.get(), settings_.highp_threshold_min); |
| 1568 | if (!resource_provider) |
| 1569 | return false; |
[email protected] | 2b154b2 | 2013-06-07 09:03:27 | [diff] [blame] | 1570 | |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1571 | if (output_surface->capabilities().deferred_gl_initialization) |
| 1572 | EnforceZeroBudget(true); |
[email protected] | be318165 | 2012-09-25 13:02:13 | [diff] [blame] | 1573 | |
[email protected] | 50af3c2 | 2013-07-13 03:50:20 | [diff] [blame] | 1574 | bool skip_gl_renderer = false; |
| 1575 | CreateAndSetRenderer( |
| 1576 | output_surface.get(), resource_provider.get(), skip_gl_renderer); |
[email protected] | be318165 | 2012-09-25 13:02:13 | [diff] [blame] | 1577 | |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1578 | if (!renderer_) |
| 1579 | return false; |
[email protected] | 6123930c | 2013-05-23 06:48:37 | [diff] [blame] | 1580 | |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1581 | if (settings_.impl_side_painting) { |
[email protected] | 50af3c2 | 2013-07-13 03:50:20 | [diff] [blame] | 1582 | CreateAndSetTileManager(resource_provider.get(), |
| 1583 | GetRendererCapabilities().using_map_image); |
[email protected] | fbe89f7 | 2013-05-21 07:24:24 | [diff] [blame] | 1584 | } |
| 1585 | |
[email protected] | 049fc7a | 2013-06-18 12:32:35 | [diff] [blame] | 1586 | // Setup BeginFrameEmulation if it's not supported natively |
| 1587 | if (!settings_.begin_frame_scheduling_enabled) { |
| 1588 | const base::TimeDelta display_refresh_interval = |
| 1589 | base::TimeDelta::FromMicroseconds( |
| 1590 | base::Time::kMicrosecondsPerSecond / |
| 1591 | settings_.refresh_rate); |
| 1592 | |
| 1593 | output_surface->InitializeBeginFrameEmulation( |
[email protected] | 810d40b7 | 2013-06-20 18:26:15 | [diff] [blame] | 1594 | proxy_->ImplThreadTaskRunner(), |
[email protected] | 049fc7a | 2013-06-18 12:32:35 | [diff] [blame] | 1595 | settings_.throttle_frame_production, |
| 1596 | display_refresh_interval); |
| 1597 | } |
| 1598 | |
| 1599 | int max_frames_pending = |
| 1600 | output_surface->capabilities().max_frames_pending; |
| 1601 | if (max_frames_pending <= 0) |
[email protected] | df3c24c9 | 2013-06-19 03:54:35 | [diff] [blame] | 1602 | max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; |
[email protected] | 049fc7a | 2013-06-18 12:32:35 | [diff] [blame] | 1603 | output_surface->SetMaxFramesPending(max_frames_pending); |
| 1604 | |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1605 | resource_provider_ = resource_provider.Pass(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1606 | output_surface_ = output_surface.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1607 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1608 | client_->OnCanDrawStateChanged(CanDraw()); |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 1609 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1610 | // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs |
| 1611 | // to be initialized to get max texture size. |
| 1612 | active_tree_->set_needs_update_draw_properties(); |
| 1613 | if (pending_tree_) |
| 1614 | pending_tree_->set_needs_update_draw_properties(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 1615 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1616 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1617 | } |
| 1618 | |
[email protected] | 2b154b2 | 2013-06-07 09:03:27 | [diff] [blame] | 1619 | bool LayerTreeHostImpl::DeferredInitialize( |
| 1620 | scoped_refptr<ContextProvider> offscreen_context_provider) { |
| 1621 | DCHECK(output_surface_->capabilities().deferred_gl_initialization); |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1622 | DCHECK(settings_.impl_side_painting); |
| 1623 | DCHECK(settings_.solid_color_scrollbars); |
[email protected] | 2b154b2 | 2013-06-07 09:03:27 | [diff] [blame] | 1624 | DCHECK(output_surface_->context3d()); |
| 1625 | |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1626 | ReleaseTreeResources(); |
| 1627 | renderer_.reset(); |
[email protected] | 50af3c2 | 2013-07-13 03:50:20 | [diff] [blame] | 1628 | resource_provider_->InitializeGL(); |
| 1629 | bool skip_gl_renderer = false; |
| 1630 | CreateAndSetRenderer( |
| 1631 | output_surface_.get(), resource_provider_.get(), skip_gl_renderer); |
[email protected] | 2b154b2 | 2013-06-07 09:03:27 | [diff] [blame] | 1632 | |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1633 | bool success = !!renderer_.get(); |
[email protected] | 2b154b2 | 2013-06-07 09:03:27 | [diff] [blame] | 1634 | client_->DidTryInitializeRendererOnImplThread(success, |
| 1635 | offscreen_context_provider); |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 1636 | if (success) { |
| 1637 | EnforceZeroBudget(false); |
| 1638 | client_->SetNeedsCommitOnImplThread(); |
| 1639 | } |
[email protected] | 2b154b2 | 2013-06-07 09:03:27 | [diff] [blame] | 1640 | return success; |
| 1641 | } |
| 1642 | |
[email protected] | 50af3c2 | 2013-07-13 03:50:20 | [diff] [blame] | 1643 | void LayerTreeHostImpl::ReleaseGL() { |
| 1644 | DCHECK(output_surface_->capabilities().deferred_gl_initialization); |
| 1645 | DCHECK(settings_.impl_side_painting); |
| 1646 | DCHECK(settings_.solid_color_scrollbars); |
| 1647 | DCHECK(output_surface_->context3d()); |
| 1648 | |
| 1649 | ReleaseTreeResources(); |
| 1650 | renderer_.reset(); |
| 1651 | tile_manager_.reset(); |
| 1652 | resource_provider_->InitializeSoftware(); |
| 1653 | |
| 1654 | bool skip_gl_renderer = true; |
| 1655 | CreateAndSetRenderer( |
| 1656 | output_surface_.get(), resource_provider_.get(), skip_gl_renderer); |
| 1657 | DCHECK(renderer_); |
| 1658 | |
| 1659 | EnforceZeroBudget(true); |
| 1660 | CreateAndSetTileManager(resource_provider_.get(), |
| 1661 | GetRendererCapabilities().using_map_image); |
| 1662 | DCHECK(tile_manager_); |
| 1663 | |
| 1664 | bool success = true; |
| 1665 | client_->DidTryInitializeRendererOnImplThread( |
| 1666 | success, scoped_refptr<ContextProvider>()); |
| 1667 | client_->SetNeedsCommitOnImplThread(); |
| 1668 | } |
| 1669 | |
[email protected] | 18ce5970 | 2013-04-09 04:58:40 | [diff] [blame] | 1670 | void LayerTreeHostImpl::SetViewportSize(gfx::Size device_viewport_size) { |
| 1671 | if (device_viewport_size == device_viewport_size_) |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1672 | return; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1673 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1674 | if (pending_tree_ && device_viewport_size_ != device_viewport_size) |
| 1675 | active_tree_->SetViewportSizeInvalid(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 1676 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1677 | device_viewport_size_ = device_viewport_size; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1678 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1679 | UpdateMaxScrollOffset(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1680 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1681 | if (renderer_) |
| 1682 | renderer_->ViewportChanged(); |
[email protected] | 8db2213c | 2012-09-05 22:08:21 | [diff] [blame] | 1683 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1684 | client_->OnCanDrawStateChanged(CanDraw()); |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 1685 | SetFullRootLayerDamage(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1686 | } |
| 1687 | |
[email protected] | d908376 | 2013-03-24 01:36:40 | [diff] [blame] | 1688 | void LayerTreeHostImpl::SetOverdrawBottomHeight(float overdraw_bottom_height) { |
| 1689 | if (overdraw_bottom_height == overdraw_bottom_height_) |
| 1690 | return; |
| 1691 | overdraw_bottom_height_ = overdraw_bottom_height; |
| 1692 | |
| 1693 | UpdateMaxScrollOffset(); |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 1694 | SetFullRootLayerDamage(); |
[email protected] | d908376 | 2013-03-24 01:36:40 | [diff] [blame] | 1695 | } |
| 1696 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1697 | void LayerTreeHostImpl::SetDeviceScaleFactor(float device_scale_factor) { |
| 1698 | if (device_scale_factor == device_scale_factor_) |
| 1699 | return; |
| 1700 | device_scale_factor_ = device_scale_factor; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 1701 | |
[email protected] | 94c40e629 | 2013-05-24 22:01:50 | [diff] [blame] | 1702 | if (renderer_) |
| 1703 | renderer_->ViewportChanged(); |
| 1704 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1705 | UpdateMaxScrollOffset(); |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 1706 | SetFullRootLayerDamage(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1707 | } |
| 1708 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1709 | gfx::Rect LayerTreeHostImpl::DeviceViewport() const { |
| 1710 | if (external_viewport_.IsEmpty()) |
| 1711 | return gfx::Rect(device_viewport_size_); |
| 1712 | |
| 1713 | return external_viewport_; |
| 1714 | } |
| 1715 | |
| 1716 | const gfx::Transform& LayerTreeHostImpl::DeviceTransform() const { |
| 1717 | return external_transform_; |
| 1718 | } |
| 1719 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1720 | void LayerTreeHostImpl::UpdateMaxScrollOffset() { |
| 1721 | active_tree_->UpdateMaxScrollOffset(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1722 | } |
| 1723 | |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 1724 | void LayerTreeHostImpl::DidChangeTopControlsPosition() { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1725 | client_->SetNeedsRedrawOnImplThread(); |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 1726 | active_tree_->set_needs_update_draw_properties(); |
| 1727 | SetFullRootLayerDamage(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1728 | } |
| 1729 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1730 | bool LayerTreeHostImpl::EnsureRenderSurfaceLayerList() { |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 1731 | active_tree_->UpdateDrawProperties(); |
[email protected] | 3209161d | 2013-03-29 19:17:34 | [diff] [blame] | 1732 | return !active_tree_->RenderSurfaceLayerList().empty(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1733 | } |
| 1734 | |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 1735 | void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) { |
| 1736 | DCHECK(input_handler_client_ == NULL); |
| 1737 | input_handler_client_ = client; |
| 1738 | } |
| 1739 | |
[email protected] | 5ff3c978 | 2013-04-29 17:35:12 | [diff] [blame] | 1740 | InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( |
| 1741 | gfx::Point viewport_point, InputHandler::ScrollInputType type) { |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 1742 | TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1743 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1744 | if (top_controls_manager_) |
| 1745 | top_controls_manager_->ScrollBegin(); |
[email protected] | 3ba4cae | 2013-01-16 03:58:38 | [diff] [blame] | 1746 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1747 | DCHECK(!CurrentlyScrollingLayer()); |
| 1748 | ClearCurrentlyScrollingLayer(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1749 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1750 | if (!EnsureRenderSurfaceLayerList()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1751 | return ScrollIgnored; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1752 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1753 | gfx::PointF device_viewport_point = gfx::ScalePoint(viewport_point, |
| 1754 | device_scale_factor_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1755 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1756 | // First find out which layer was hit from the saved list of visible layers |
| 1757 | // in the most recent frame. |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 1758 | LayerImpl* layer_impl = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1759 | device_viewport_point, active_tree_->RenderSurfaceLayerList()); |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 1760 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1761 | // Walk up the hierarchy and look for a scrollable layer. |
| 1762 | LayerImpl* potentially_scrolling_layer_impl = 0; |
| 1763 | for (; layer_impl; layer_impl = layer_impl->parent()) { |
| 1764 | // The content layer can also block attempts to scroll outside the main |
| 1765 | // thread. |
| 1766 | ScrollStatus status = layer_impl->TryScroll(device_viewport_point, type); |
| 1767 | if (status == ScrollOnMainThread) { |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 1768 | rendering_stats_instrumentation_->IncrementMainThreadScrolls(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1769 | UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true); |
| 1770 | return ScrollOnMainThread; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1771 | } |
| 1772 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1773 | LayerImpl* scroll_layer_impl = FindScrollLayerForContentLayer(layer_impl); |
| 1774 | if (!scroll_layer_impl) |
| 1775 | continue; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1776 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1777 | status = scroll_layer_impl->TryScroll(device_viewport_point, type); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1778 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1779 | // If any layer wants to divert the scroll event to the main thread, abort. |
| 1780 | if (status == ScrollOnMainThread) { |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 1781 | rendering_stats_instrumentation_->IncrementMainThreadScrolls(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1782 | UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true); |
| 1783 | return ScrollOnMainThread; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1784 | } |
| 1785 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1786 | if (status == ScrollStarted && !potentially_scrolling_layer_impl) |
| 1787 | potentially_scrolling_layer_impl = scroll_layer_impl; |
| 1788 | } |
| 1789 | |
| 1790 | // When hiding top controls is enabled and the controls are hidden or |
| 1791 | // overlaying the content, force scrolls to be enabled on the root layer to |
| 1792 | // allow bringing the top controls back into view. |
| 1793 | if (!potentially_scrolling_layer_impl && top_controls_manager_ && |
| 1794 | top_controls_manager_->content_top_offset() != |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 1795 | settings_.top_controls_height) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1796 | potentially_scrolling_layer_impl = RootScrollLayer(); |
| 1797 | } |
| 1798 | |
| 1799 | if (potentially_scrolling_layer_impl) { |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 1800 | active_tree_->SetCurrentlyScrollingLayer( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1801 | potentially_scrolling_layer_impl); |
| 1802 | should_bubble_scrolls_ = (type != NonBubblingGesture); |
| 1803 | wheel_scrolling_ = (type == Wheel); |
[email protected] | 372bad5f | 2013-03-21 16:38:43 | [diff] [blame] | 1804 | rendering_stats_instrumentation_->IncrementImplThreadScrolls(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1805 | client_->RenewTreePriority(); |
| 1806 | UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); |
| 1807 | return ScrollStarted; |
| 1808 | } |
| 1809 | return ScrollIgnored; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1810 | } |
| 1811 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1812 | gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta( |
| 1813 | LayerImpl* layer_impl, |
| 1814 | float scale_from_viewport_to_screen_space, |
| 1815 | gfx::PointF viewport_point, |
| 1816 | gfx::Vector2dF viewport_delta) { |
| 1817 | // Layers with non-invertible screen space transforms should not have passed |
| 1818 | // the scroll hit test in the first place. |
| 1819 | DCHECK(layer_impl->screen_space_transform().IsInvertible()); |
| 1820 | gfx::Transform inverse_screen_space_transform( |
| 1821 | gfx::Transform::kSkipInitialization); |
| 1822 | bool did_invert = layer_impl->screen_space_transform().GetInverse( |
| 1823 | &inverse_screen_space_transform); |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1824 | // TODO(shawnsingh): With the advent of impl-side crolling for non-root |
| 1825 | // layers, we may need to explicitly handle uninvertible transforms here. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1826 | DCHECK(did_invert); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1827 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1828 | gfx::PointF screen_space_point = |
| 1829 | gfx::ScalePoint(viewport_point, scale_from_viewport_to_screen_space); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1830 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1831 | gfx::Vector2dF screen_space_delta = viewport_delta; |
| 1832 | screen_space_delta.Scale(scale_from_viewport_to_screen_space); |
| 1833 | |
| 1834 | // First project the scroll start and end points to local layer space to find |
| 1835 | // the scroll delta in layer coordinates. |
| 1836 | bool start_clipped, end_clipped; |
| 1837 | gfx::PointF screen_space_end_point = screen_space_point + screen_space_delta; |
| 1838 | gfx::PointF local_start_point = |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 1839 | MathUtil::ProjectPoint(inverse_screen_space_transform, |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1840 | screen_space_point, |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 1841 | &start_clipped); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1842 | gfx::PointF local_end_point = |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 1843 | MathUtil::ProjectPoint(inverse_screen_space_transform, |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1844 | screen_space_end_point, |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 1845 | &end_clipped); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1846 | |
| 1847 | // In general scroll point coordinates should not get clipped. |
| 1848 | DCHECK(!start_clipped); |
| 1849 | DCHECK(!end_clipped); |
| 1850 | if (start_clipped || end_clipped) |
| 1851 | return gfx::Vector2dF(); |
| 1852 | |
| 1853 | // local_start_point and local_end_point are in content space but we want to |
| 1854 | // move them to layer space for scrolling. |
| 1855 | float width_scale = 1.f / layer_impl->contents_scale_x(); |
| 1856 | float height_scale = 1.f / layer_impl->contents_scale_y(); |
| 1857 | local_start_point.Scale(width_scale, height_scale); |
| 1858 | local_end_point.Scale(width_scale, height_scale); |
| 1859 | |
| 1860 | // Apply the scroll delta. |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 1861 | gfx::Vector2dF previous_delta = layer_impl->ScrollDelta(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1862 | layer_impl->ScrollBy(local_end_point - local_start_point); |
| 1863 | |
| 1864 | // Get the end point in the layer's content space so we can apply its |
| 1865 | // ScreenSpaceTransform. |
| 1866 | gfx::PointF actual_local_end_point = local_start_point + |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 1867 | layer_impl->ScrollDelta() - |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1868 | previous_delta; |
| 1869 | gfx::PointF actual_local_content_end_point = |
| 1870 | gfx::ScalePoint(actual_local_end_point, |
| 1871 | 1.f / width_scale, |
| 1872 | 1.f / height_scale); |
| 1873 | |
| 1874 | // Calculate the applied scroll delta in viewport space coordinates. |
| 1875 | gfx::PointF actual_screen_space_end_point = |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 1876 | MathUtil::MapPoint(layer_impl->screen_space_transform(), |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1877 | actual_local_content_end_point, |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 1878 | &end_clipped); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1879 | DCHECK(!end_clipped); |
| 1880 | if (end_clipped) |
| 1881 | return gfx::Vector2dF(); |
| 1882 | gfx::PointF actual_viewport_end_point = |
| 1883 | gfx::ScalePoint(actual_screen_space_end_point, |
| 1884 | 1.f / scale_from_viewport_to_screen_space); |
| 1885 | return actual_viewport_end_point - viewport_point; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1886 | } |
| 1887 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1888 | static gfx::Vector2dF ScrollLayerWithLocalDelta(LayerImpl* layer_impl, |
| 1889 | gfx::Vector2dF local_delta) { |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 1890 | gfx::Vector2dF previous_delta(layer_impl->ScrollDelta()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1891 | layer_impl->ScrollBy(local_delta); |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 1892 | return layer_impl->ScrollDelta() - previous_delta; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | bool LayerTreeHostImpl::ScrollBy(gfx::Point viewport_point, |
| 1896 | gfx::Vector2dF scroll_delta) { |
| 1897 | TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); |
| 1898 | if (!CurrentlyScrollingLayer()) |
| 1899 | return false; |
| 1900 | |
| 1901 | gfx::Vector2dF pending_delta = scroll_delta; |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 1902 | gfx::Vector2dF unused_root_delta; |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 1903 | bool did_scroll_x = false; |
| 1904 | bool did_scroll_y = false; |
[email protected] | 60b4d25 | 2013-03-23 18:49:42 | [diff] [blame] | 1905 | bool consume_by_top_controls = top_controls_manager_ && |
| 1906 | (CurrentlyScrollingLayer() == RootScrollLayer() || scroll_delta.y() < 0); |
[email protected] | a91e4f8 | 2013-03-15 06:58:06 | [diff] [blame] | 1907 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1908 | for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); |
| 1909 | layer_impl; |
| 1910 | layer_impl = layer_impl->parent()) { |
| 1911 | if (!layer_impl->scrollable()) |
| 1912 | continue; |
| 1913 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 1914 | if (layer_impl == RootScrollLayer()) { |
| 1915 | // Only allow bubble scrolling when the scroll is in the direction to make |
| 1916 | // the top controls visible. |
| 1917 | if (consume_by_top_controls && layer_impl == RootScrollLayer()) { |
| 1918 | pending_delta = top_controls_manager_->ScrollBy(pending_delta); |
| 1919 | UpdateMaxScrollOffset(); |
| 1920 | } |
| 1921 | // Track root layer deltas for reporting overscroll. |
| 1922 | unused_root_delta = pending_delta; |
[email protected] | 60b4d25 | 2013-03-23 18:49:42 | [diff] [blame] | 1923 | } |
| 1924 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1925 | gfx::Vector2dF applied_delta; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1926 | // Gesture events need to be transformed from viewport coordinates to local |
| 1927 | // layer coordinates so that the scrolling contents exactly follow the |
| 1928 | // user's finger. In contrast, wheel events represent a fixed amount of |
| 1929 | // scrolling so we can just apply them directly. |
| 1930 | if (!wheel_scrolling_) { |
| 1931 | float scale_from_viewport_to_screen_space = device_scale_factor_; |
| 1932 | applied_delta = |
| 1933 | ScrollLayerWithViewportSpaceDelta(layer_impl, |
| 1934 | scale_from_viewport_to_screen_space, |
| 1935 | viewport_point, pending_delta); |
| 1936 | } else { |
| 1937 | applied_delta = ScrollLayerWithLocalDelta(layer_impl, pending_delta); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1938 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1939 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1940 | // If the layer wasn't able to move, try the next one in the hierarchy. |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 1941 | float move_threshold = 0.1f; |
| 1942 | bool did_move_layer_x = std::abs(applied_delta.x()) > move_threshold; |
| 1943 | bool did_move_layer_y = std::abs(applied_delta.y()) > move_threshold; |
| 1944 | did_scroll_x |= did_move_layer_x; |
| 1945 | did_scroll_y |= did_move_layer_y; |
| 1946 | if (!did_move_layer_x && !did_move_layer_y) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1947 | if (should_bubble_scrolls_ || !did_lock_scrolling_layer_) |
| 1948 | continue; |
| 1949 | else |
| 1950 | break; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1951 | } |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 1952 | |
| 1953 | if (layer_impl == RootScrollLayer()) |
| 1954 | unused_root_delta.Subtract(applied_delta); |
| 1955 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1956 | did_lock_scrolling_layer_ = true; |
| 1957 | if (!should_bubble_scrolls_) { |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 1958 | active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1959 | break; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1960 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1961 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1962 | // If the applied delta is within 45 degrees of the input delta, bail out to |
| 1963 | // make it easier to scroll just one layer in one direction without |
| 1964 | // affecting any of its parents. |
| 1965 | float angle_threshold = 45; |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 1966 | if (MathUtil::SmallestAngleBetweenVectors( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1967 | applied_delta, pending_delta) < angle_threshold) { |
| 1968 | pending_delta = gfx::Vector2d(); |
| 1969 | break; |
[email protected] | 4a23c374c | 2012-12-08 08:38:55 | [diff] [blame] | 1970 | } |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1971 | |
| 1972 | // Allow further movement only on an axis perpendicular to the direction in |
| 1973 | // which the layer moved. |
| 1974 | gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x()); |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 1975 | pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1976 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 1977 | if (gfx::ToRoundedVector2d(pending_delta).IsZero()) |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1978 | break; |
| 1979 | } |
| 1980 | |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 1981 | bool did_scroll = did_scroll_x || did_scroll_y; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 1982 | if (did_scroll) { |
| 1983 | client_->SetNeedsCommitOnImplThread(); |
| 1984 | client_->SetNeedsRedrawOnImplThread(); |
| 1985 | client_->RenewTreePriority(); |
| 1986 | } |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 1987 | |
[email protected] | 2bd503f | 2013-07-23 05:35:29 | [diff] [blame] | 1988 | // Scrolling along an axis resets accumulated root overscroll for that axis. |
| 1989 | if (did_scroll_x) |
| 1990 | accumulated_root_overscroll_.set_x(0); |
| 1991 | if (did_scroll_y) |
| 1992 | accumulated_root_overscroll_.set_y(0); |
| 1993 | |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 1994 | accumulated_root_overscroll_ += unused_root_delta; |
| 1995 | bool did_overscroll = !gfx::ToRoundedVector2d(unused_root_delta).IsZero(); |
| 1996 | if (did_overscroll && input_handler_client_) { |
[email protected] | bfb6e24 | 2013-07-17 23:15:11 | [diff] [blame] | 1997 | DidOverscrollParams params; |
| 1998 | params.accumulated_overscroll = accumulated_root_overscroll_; |
| 1999 | params.latest_overscroll_delta = unused_root_delta; |
| 2000 | params.current_fling_velocity = current_fling_velocity_; |
| 2001 | input_handler_client_->DidOverscroll(params); |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 2002 | } |
| 2003 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2004 | return did_scroll; |
[email protected] | 4a23c374c | 2012-12-08 08:38:55 | [diff] [blame] | 2005 | } |
| 2006 | |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2007 | // This implements scrolling by page as described here: |
| 2008 | // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).aspx#_win32_The_Mouse_Wheel |
| 2009 | // for events with WHEEL_PAGESCROLL set. |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 2010 | bool LayerTreeHostImpl::ScrollVerticallyByPage(gfx::Point viewport_point, |
| 2011 | ScrollDirection direction) { |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2012 | DCHECK(wheel_scrolling_); |
| 2013 | |
| 2014 | for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); |
| 2015 | layer_impl; |
| 2016 | layer_impl = layer_impl->parent()) { |
| 2017 | if (!layer_impl->scrollable()) |
| 2018 | continue; |
| 2019 | |
| 2020 | if (!layer_impl->vertical_scrollbar_layer()) |
| 2021 | continue; |
| 2022 | |
| 2023 | float height = layer_impl->vertical_scrollbar_layer()->bounds().height(); |
| 2024 | |
| 2025 | // These magical values match WebKit and are designed to scroll nearly the |
| 2026 | // entire visible content height but leave a bit of overlap. |
| 2027 | float page = std::max(height * 0.875f, 1.f); |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 2028 | if (direction == SCROLL_BACKWARD) |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2029 | page = -page; |
| 2030 | |
| 2031 | gfx::Vector2dF delta = gfx::Vector2dF(0.f, page); |
| 2032 | |
| 2033 | gfx::Vector2dF applied_delta = ScrollLayerWithLocalDelta(layer_impl, delta); |
| 2034 | |
| 2035 | if (!applied_delta.IsZero()) { |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 2036 | client_->SetNeedsCommitOnImplThread(); |
| 2037 | client_->SetNeedsRedrawOnImplThread(); |
| 2038 | client_->RenewTreePriority(); |
| 2039 | return true; |
| 2040 | } |
| 2041 | |
| 2042 | active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
| 2043 | } |
| 2044 | |
| 2045 | return false; |
| 2046 | } |
| 2047 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 2048 | void LayerTreeHostImpl::SetRootLayerScrollOffsetDelegate( |
| 2049 | LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) { |
| 2050 | root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate; |
| 2051 | active_tree_->SetRootLayerScrollOffsetDelegate( |
| 2052 | root_layer_scroll_offset_delegate_); |
| 2053 | } |
| 2054 | |
| 2055 | void LayerTreeHostImpl::OnRootLayerDelegatedScrollOffsetChanged() { |
| 2056 | DCHECK(root_layer_scroll_offset_delegate_ != NULL); |
| 2057 | client_->SetNeedsCommitOnImplThread(); |
| 2058 | } |
| 2059 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2060 | void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() { |
| 2061 | active_tree_->ClearCurrentlyScrollingLayer(); |
| 2062 | did_lock_scrolling_layer_ = false; |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 2063 | accumulated_root_overscroll_ = gfx::Vector2dF(); |
[email protected] | 6e921bd | 2013-04-29 21:10:20 | [diff] [blame] | 2064 | current_fling_velocity_ = gfx::Vector2dF(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2065 | } |
| 2066 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2067 | void LayerTreeHostImpl::ScrollEnd() { |
| 2068 | if (top_controls_manager_) |
| 2069 | top_controls_manager_->ScrollEnd(); |
| 2070 | ClearCurrentlyScrollingLayer(); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2071 | StartScrollbarAnimation(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2072 | } |
| 2073 | |
[email protected] | 5ff3c978 | 2013-04-29 17:35:12 | [diff] [blame] | 2074 | InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 2075 | if (active_tree_->CurrentlyScrollingLayer()) |
| 2076 | return ScrollStarted; |
| 2077 | |
| 2078 | return ScrollIgnored; |
| 2079 | } |
| 2080 | |
[email protected] | 6e921bd | 2013-04-29 21:10:20 | [diff] [blame] | 2081 | void LayerTreeHostImpl::NotifyCurrentFlingVelocity(gfx::Vector2dF velocity) { |
| 2082 | current_fling_velocity_ = velocity; |
| 2083 | } |
| 2084 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2085 | void LayerTreeHostImpl::PinchGestureBegin() { |
| 2086 | pinch_gesture_active_ = true; |
| 2087 | previous_pinch_anchor_ = gfx::Point(); |
| 2088 | client_->RenewTreePriority(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2089 | } |
| 2090 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2091 | void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, |
| 2092 | gfx::Point anchor) { |
| 2093 | TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate"); |
[email protected] | d3afa11 | 2012-12-08 06:24:28 | [diff] [blame] | 2094 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2095 | if (!RootScrollLayer()) |
| 2096 | return; |
[email protected] | d3afa11 | 2012-12-08 06:24:28 | [diff] [blame] | 2097 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2098 | // Keep the center-of-pinch anchor specified by (x, y) in a stable |
| 2099 | // position over the course of the magnify. |
| 2100 | float page_scale_delta = active_tree_->page_scale_delta(); |
| 2101 | gfx::PointF previous_scale_anchor = |
| 2102 | gfx::ScalePoint(anchor, 1.f / page_scale_delta); |
| 2103 | active_tree_->SetPageScaleDelta(page_scale_delta * magnify_delta); |
| 2104 | page_scale_delta = active_tree_->page_scale_delta(); |
| 2105 | gfx::PointF new_scale_anchor = |
| 2106 | gfx::ScalePoint(anchor, 1.f / page_scale_delta); |
| 2107 | gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor; |
| 2108 | |
| 2109 | previous_pinch_anchor_ = anchor; |
| 2110 | |
| 2111 | move.Scale(1 / active_tree_->page_scale_factor()); |
| 2112 | |
| 2113 | RootScrollLayer()->ScrollBy(move); |
| 2114 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2115 | client_->SetNeedsCommitOnImplThread(); |
| 2116 | client_->SetNeedsRedrawOnImplThread(); |
| 2117 | client_->RenewTreePriority(); |
[email protected] | d3afa11 | 2012-12-08 06:24:28 | [diff] [blame] | 2118 | } |
| 2119 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2120 | void LayerTreeHostImpl::PinchGestureEnd() { |
| 2121 | pinch_gesture_active_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2122 | client_->SetNeedsCommitOnImplThread(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2123 | } |
| 2124 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2125 | static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, |
| 2126 | LayerImpl* layer_impl) { |
| 2127 | if (!layer_impl) |
| 2128 | return; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2129 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2130 | gfx::Vector2d scroll_delta = |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 2131 | gfx::ToFlooredVector2d(layer_impl->ScrollDelta()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2132 | if (!scroll_delta.IsZero()) { |
| 2133 | LayerTreeHostCommon::ScrollUpdateInfo scroll; |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 2134 | scroll.layer_id = layer_impl->id(); |
| 2135 | scroll.scroll_delta = scroll_delta; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2136 | scroll_info->scrolls.push_back(scroll); |
| 2137 | layer_impl->SetSentScrollDelta(scroll_delta); |
| 2138 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2139 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2140 | for (size_t i = 0; i < layer_impl->children().size(); ++i) |
| 2141 | CollectScrollDeltas(scroll_info, layer_impl->children()[i]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2142 | } |
| 2143 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2144 | scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() { |
| 2145 | scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); |
[email protected] | 362f1e8b | 2013-01-21 16:54:30 | [diff] [blame] | 2146 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2147 | CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 2148 | scroll_info->page_scale_delta = active_tree_->page_scale_delta(); |
| 2149 | active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta); |
[email protected] | 362f1e8b | 2013-01-21 16:54:30 | [diff] [blame] | 2150 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2151 | return scroll_info.Pass(); |
[email protected] | 362f1e8b | 2013-01-21 16:54:30 | [diff] [blame] | 2152 | } |
| 2153 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2154 | void LayerTreeHostImpl::SetFullRootLayerDamage() { |
[email protected] | 878705be | 2013-04-15 22:44:02 | [diff] [blame] | 2155 | SetViewportDamage(gfx::Rect(device_viewport_size_)); |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 2156 | } |
| 2157 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2158 | void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks time) { |
| 2159 | if (!page_scale_animation_ || !RootScrollLayer()) |
| 2160 | return; |
| 2161 | |
| 2162 | double monotonic_time = (time - base::TimeTicks()).InSecondsF(); |
| 2163 | gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() + |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 2164 | RootScrollLayer()->ScrollDelta(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2165 | |
| 2166 | active_tree_->SetPageScaleDelta( |
| 2167 | page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / |
| 2168 | active_tree_->page_scale_factor()); |
| 2169 | gfx::Vector2dF next_scroll = |
| 2170 | page_scale_animation_->ScrollOffsetAtTime(monotonic_time); |
| 2171 | |
| 2172 | RootScrollLayer()->ScrollBy(next_scroll - scroll_total); |
| 2173 | client_->SetNeedsRedrawOnImplThread(); |
| 2174 | |
| 2175 | if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { |
| 2176 | page_scale_animation_.reset(); |
| 2177 | client_->SetNeedsCommitOnImplThread(); |
| 2178 | client_->RenewTreePriority(); |
| 2179 | } |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 2180 | } |
| 2181 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 2182 | void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { |
| 2183 | if (!top_controls_manager_ || !RootScrollLayer()) |
| 2184 | return; |
| 2185 | gfx::Vector2dF scroll = top_controls_manager_->Animate(time); |
| 2186 | UpdateMaxScrollOffset(); |
[email protected] | 5ef8262 | 2013-05-01 16:26:17 | [diff] [blame] | 2187 | if (RootScrollLayer()->TotalScrollOffset().y() == 0.f) |
| 2188 | return; |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 2189 | RootScrollLayer()->ScrollBy(gfx::ScaleVector2d( |
| 2190 | scroll, 1.f / active_tree_->total_page_scale_factor())); |
| 2191 | } |
| 2192 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2193 | void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time, |
| 2194 | base::Time wall_clock_time) { |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 2195 | if (!settings_.accelerated_animation_enabled || |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2196 | animation_registrar_->active_animation_controllers().empty() || |
| 2197 | !active_tree_->root_layer()) |
| 2198 | return; |
| 2199 | |
| 2200 | TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers"); |
| 2201 | |
| 2202 | last_animation_time_ = wall_clock_time; |
| 2203 | double monotonic_seconds = (monotonic_time - base::TimeTicks()).InSecondsF(); |
| 2204 | |
| 2205 | AnimationRegistrar::AnimationControllerMap copy = |
| 2206 | animation_registrar_->active_animation_controllers(); |
| 2207 | for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); |
| 2208 | iter != copy.end(); |
| 2209 | ++iter) |
| 2210 | (*iter).second->Animate(monotonic_seconds); |
| 2211 | |
| 2212 | client_->SetNeedsRedrawOnImplThread(); |
[email protected] | 131a0c2 | 2013-02-12 18:31:08 | [diff] [blame] | 2213 | } |
| 2214 | |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 2215 | void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 2216 | if (!settings_.accelerated_animation_enabled || |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2217 | animation_registrar_->active_animation_controllers().empty() || |
| 2218 | !active_tree_->root_layer()) |
| 2219 | return; |
| 2220 | |
| 2221 | TRACE_EVENT0("cc", "LayerTreeHostImpl::UpdateAnimationState"); |
| 2222 | scoped_ptr<AnimationEventsVector> events = |
| 2223 | make_scoped_ptr(new AnimationEventsVector); |
| 2224 | AnimationRegistrar::AnimationControllerMap copy = |
| 2225 | animation_registrar_->active_animation_controllers(); |
| 2226 | for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); |
| 2227 | iter != copy.end(); |
| 2228 | ++iter) |
[email protected] | 3d9f743 | 2013-04-06 00:35:18 | [diff] [blame] | 2229 | (*iter).second->UpdateState(start_ready_animations, events.get()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2230 | |
| 2231 | if (!events->empty()) { |
| 2232 | client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass(), |
| 2233 | last_animation_time_); |
| 2234 | } |
[email protected] | 131a0c2 | 2013-02-12 18:31:08 | [diff] [blame] | 2235 | } |
| 2236 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2237 | base::TimeDelta LayerTreeHostImpl::LowFrequencyAnimationInterval() const { |
| 2238 | return base::TimeDelta::FromSeconds(1); |
| 2239 | } |
| 2240 | |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 2241 | void LayerTreeHostImpl::SendReleaseResourcesRecursive(LayerImpl* current) { |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 2242 | DCHECK(current); |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 2243 | // TODO(boliu): Rename DidLoseOutputSurface to ReleaseResources. |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 2244 | current->DidLoseOutputSurface(); |
| 2245 | if (current->mask_layer()) |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 2246 | SendReleaseResourcesRecursive(current->mask_layer()); |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 2247 | if (current->replica_layer()) |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 2248 | SendReleaseResourcesRecursive(current->replica_layer()); |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 2249 | for (size_t i = 0; i < current->children().size(); ++i) |
[email protected] | 5064464 | 2013-06-20 13:58:55 | [diff] [blame] | 2250 | SendReleaseResourcesRecursive(current->children()[i]); |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 2251 | } |
| 2252 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2253 | std::string LayerTreeHostImpl::LayerTreeAsJson() const { |
| 2254 | std::string str; |
| 2255 | if (active_tree_->root_layer()) { |
| 2256 | scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); |
| 2257 | base::JSONWriter::WriteWithOptions( |
| 2258 | json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); |
| 2259 | } |
| 2260 | return str; |
| 2261 | } |
| 2262 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2263 | int LayerTreeHostImpl::SourceAnimationFrameNumber() const { |
[email protected] | 9e359452 | 2013-03-18 00:57:36 | [diff] [blame] | 2264 | return fps_counter_->current_frame_number(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2265 | } |
| 2266 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2267 | void LayerTreeHostImpl::SendManagedMemoryStats( |
| 2268 | size_t memory_visible_bytes, |
| 2269 | size_t memory_visible_and_nearby_bytes, |
| 2270 | size_t memory_use_bytes) { |
| 2271 | if (!renderer_) |
| 2272 | return; |
| 2273 | |
| 2274 | // Round the numbers being sent up to the next 8MB, to throttle the rate |
| 2275 | // at which we spam the GPU process. |
| 2276 | static const size_t rounding_step = 8 * 1024 * 1024; |
| 2277 | memory_visible_bytes = RoundUp(memory_visible_bytes, rounding_step); |
| 2278 | memory_visible_and_nearby_bytes = RoundUp(memory_visible_and_nearby_bytes, |
| 2279 | rounding_step); |
| 2280 | memory_use_bytes = RoundUp(memory_use_bytes, rounding_step); |
| 2281 | if (last_sent_memory_visible_bytes_ == memory_visible_bytes && |
| 2282 | last_sent_memory_visible_and_nearby_bytes_ == |
| 2283 | memory_visible_and_nearby_bytes && |
| 2284 | last_sent_memory_use_bytes_ == memory_use_bytes) { |
| 2285 | return; |
| 2286 | } |
| 2287 | last_sent_memory_visible_bytes_ = memory_visible_bytes; |
| 2288 | last_sent_memory_visible_and_nearby_bytes_ = memory_visible_and_nearby_bytes; |
| 2289 | last_sent_memory_use_bytes_ = memory_use_bytes; |
| 2290 | |
| 2291 | renderer_->SendManagedMemoryStats(last_sent_memory_visible_bytes_, |
| 2292 | last_sent_memory_visible_and_nearby_bytes_, |
| 2293 | last_sent_memory_use_bytes_); |
| 2294 | } |
| 2295 | |
| 2296 | void LayerTreeHostImpl::AnimateScrollbars(base::TimeTicks time) { |
| 2297 | AnimateScrollbarsRecursive(active_tree_->root_layer(), time); |
| 2298 | } |
| 2299 | |
| 2300 | void LayerTreeHostImpl::AnimateScrollbarsRecursive(LayerImpl* layer, |
| 2301 | base::TimeTicks time) { |
| 2302 | if (!layer) |
| 2303 | return; |
| 2304 | |
| 2305 | ScrollbarAnimationController* scrollbar_controller = |
| 2306 | layer->scrollbar_animation_controller(); |
[email protected] | 6bc09e8 | 2013-03-19 03:48:35 | [diff] [blame] | 2307 | if (scrollbar_controller && scrollbar_controller->Animate(time)) { |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 2308 | TRACE_EVENT_INSTANT0( |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 2309 | "cc", "LayerTreeHostImpl::SetNeedsRedraw due to AnimateScrollbars", |
| 2310 | TRACE_EVENT_SCOPE_THREAD); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2311 | client_->SetNeedsRedrawOnImplThread(); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 2312 | } |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2313 | |
| 2314 | for (size_t i = 0; i < layer->children().size(); ++i) |
| 2315 | AnimateScrollbarsRecursive(layer->children()[i], time); |
| 2316 | } |
| 2317 | |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2318 | void LayerTreeHostImpl::StartScrollbarAnimation() { |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 2319 | TRACE_EVENT0("cc", "LayerTreeHostImpl::StartScrollbarAnimation"); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2320 | StartScrollbarAnimationRecursive(RootLayer(), CurrentPhysicalTimeTicks()); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | void LayerTreeHostImpl::StartScrollbarAnimationRecursive(LayerImpl* layer, |
| 2324 | base::TimeTicks time) { |
| 2325 | if (!layer) |
| 2326 | return; |
| 2327 | |
| 2328 | ScrollbarAnimationController* scrollbar_controller = |
| 2329 | layer->scrollbar_animation_controller(); |
[email protected] | 6bc09e8 | 2013-03-19 03:48:35 | [diff] [blame] | 2330 | if (scrollbar_controller && scrollbar_controller->IsAnimating()) { |
| 2331 | base::TimeDelta delay = scrollbar_controller->DelayBeforeStart(time); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 2332 | if (delay > base::TimeDelta()) |
| 2333 | client_->RequestScrollbarAnimationOnImplThread(delay); |
[email protected] | 6bc09e8 | 2013-03-19 03:48:35 | [diff] [blame] | 2334 | else if (scrollbar_controller->Animate(time)) |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 2335 | client_->SetNeedsRedrawOnImplThread(); |
| 2336 | } |
| 2337 | |
| 2338 | for (size_t i = 0; i < layer->children().size(); ++i) |
| 2339 | StartScrollbarAnimationRecursive(layer->children()[i], time); |
| 2340 | } |
| 2341 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2342 | void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { |
| 2343 | if (!tile_manager_) |
| 2344 | return; |
| 2345 | |
| 2346 | GlobalStateThatImpactsTilePriority new_state(tile_manager_->GlobalState()); |
| 2347 | if (new_state.tree_priority == priority) |
| 2348 | return; |
| 2349 | |
| 2350 | new_state.tree_priority = priority; |
| 2351 | tile_manager_->SetGlobalState(new_state); |
[email protected] | a23451e | 2013-06-07 20:58:26 | [diff] [blame] | 2352 | manage_tiles_needed_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2353 | } |
| 2354 | |
[email protected] | 8347d69 | 2013-05-17 23:22:38 | [diff] [blame] | 2355 | void LayerTreeHostImpl::ResetCurrentFrameTimeForNextFrame() { |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 2356 | current_frame_timeticks_ = base::TimeTicks(); |
| 2357 | current_frame_time_ = base::Time(); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2358 | } |
| 2359 | |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2360 | void LayerTreeHostImpl::UpdateCurrentFrameTime(base::TimeTicks* ticks, |
| 2361 | base::Time* now) const { |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 2362 | if (ticks->is_null()) { |
| 2363 | DCHECK(now->is_null()); |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2364 | *ticks = CurrentPhysicalTimeTicks(); |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 2365 | *now = base::Time::Now(); |
| 2366 | } |
| 2367 | } |
| 2368 | |
| 2369 | base::TimeTicks LayerTreeHostImpl::CurrentFrameTimeTicks() { |
| 2370 | UpdateCurrentFrameTime(¤t_frame_timeticks_, ¤t_frame_time_); |
| 2371 | return current_frame_timeticks_; |
| 2372 | } |
| 2373 | |
| 2374 | base::Time LayerTreeHostImpl::CurrentFrameTime() { |
| 2375 | UpdateCurrentFrameTime(¤t_frame_timeticks_, ¤t_frame_time_); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2376 | return current_frame_time_; |
| 2377 | } |
| 2378 | |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 2379 | base::TimeTicks LayerTreeHostImpl::CurrentPhysicalTimeTicks() const { |
| 2380 | return base::TimeTicks::Now(); |
| 2381 | } |
| 2382 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2383 | scoped_ptr<base::Value> LayerTreeHostImpl::AsValue() const { |
| 2384 | scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 2385 | if (this->pending_tree_) |
| 2386 | state->Set("activation_state", ActivationStateAsValue().release()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2387 | state->Set("device_viewport_size", |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 2388 | MathUtil::AsValue(device_viewport_size_).release()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2389 | if (tile_manager_) |
| 2390 | state->Set("tiles", tile_manager_->AllTilesAsValue().release()); |
| 2391 | state->Set("active_tree", active_tree_->AsValue().release()); |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 2392 | if (pending_tree_) |
| 2393 | state->Set("pending_tree", pending_tree_->AsValue().release()); |
| 2394 | return state.PassAs<base::Value>(); |
| 2395 | } |
| 2396 | |
| 2397 | scoped_ptr<base::Value> LayerTreeHostImpl::ActivationStateAsValue() const { |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 2398 | scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 2399 | state->Set("lthi", TracedValue::CreateIDRef(this).release()); |
[email protected] | 15cc992 | 2013-05-24 07:31:47 | [diff] [blame] | 2400 | if (tile_manager_) |
| 2401 | state->Set("tile_manager", tile_manager_->BasicStateAsValue().release()); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2402 | return state.PassAs<base::Value>(); |
[email protected] | 131a0c2 | 2013-02-12 18:31:08 | [diff] [blame] | 2403 | } |
| 2404 | |
[email protected] | 6e7fdeb | 2013-07-09 14:28:38 | [diff] [blame] | 2405 | void LayerTreeHostImpl::SetDebugState( |
| 2406 | const LayerTreeDebugState& new_debug_state) { |
| 2407 | if (LayerTreeDebugState::Equal(debug_state_, new_debug_state)) |
| 2408 | return; |
| 2409 | if (debug_state_.continuous_painting != new_debug_state.continuous_painting) |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 2410 | paint_time_counter_->ClearHistory(); |
[email protected] | 652cf13 | 2013-02-15 21:53:24 | [diff] [blame] | 2411 | |
[email protected] | 6e7fdeb | 2013-07-09 14:28:38 | [diff] [blame] | 2412 | debug_state_ = new_debug_state; |
| 2413 | SetFullRootLayerDamage(); |
[email protected] | d0d1219 | 2013-02-08 19:02:02 | [diff] [blame] | 2414 | } |
| 2415 | |
[email protected] | d3143c73 | 2012-10-05 19:17:59 | [diff] [blame] | 2416 | } // namespace cc |