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