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