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