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