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