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