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