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