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