blob: 4a01ed73e9fad1670f322870327f48452d933bea [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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]556fd292013-03-18 08:03:045#include "cc/trees/layer_tree_host_impl.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]ac7c7f52012-11-08 06:26:507#include <algorithm>
[email protected]b6eb8e332013-09-10 00:51:018#include <limits>
[email protected]ac7c7f52012-11-08 06:26:509
[email protected]ad5d1422012-10-19 13:40:2910#include "base/basictypes.h"
[email protected]34806722013-08-09 23:51:2111#include "base/containers/hash_tables.h"
[email protected]d12aa932014-08-01 13:10:3812#include "base/debug/trace_event_argument.h"
[email protected]4a23c374c2012-12-08 08:38:5513#include "base/json/json_writer.h"
[email protected]f5864912013-02-01 03:18:1414#include "base/metrics/histogram.h"
[email protected]de4afb5e2012-12-20 00:11:3415#include "base/stl_util.h"
[email protected]8e61d4b2013-06-10 22:11:4816#include "base/strings/stringprintf.h"
[email protected]749cbc62014-07-10 01:06:3517#include "cc/animation/animation_id_provider.h"
18#include "cc/animation/scroll_offset_animation_curve.h"
[email protected]95e4e1a02013-03-18 07:09:0919#include "cc/animation/scrollbar_animation_controller.h"
[email protected]85d136f782013-04-26 22:04:4020#include "cc/animation/timing_function.h"
[email protected]6be422b2013-12-08 06:47:3121#include "cc/base/latency_info_swap_promise_monitor.h"
[email protected]681ccff2013-03-18 06:13:5222#include "cc/base/math_util.h"
23#include "cc/base/util.h"
[email protected]adbe30f2013-10-11 21:12:3324#include "cc/debug/benchmark_instrumentation.h"
[email protected]6e84de22013-03-18 06:54:2725#include "cc/debug/debug_rect_history.h"
[email protected]dbe759a2013-12-02 19:23:0226#include "cc/debug/devtools_instrumentation.h"
[email protected]6e84de22013-03-18 06:54:2727#include "cc/debug/frame_rate_counter.h"
[email protected]6e84de22013-03-18 06:54:2728#include "cc/debug/paint_time_counter.h"
[email protected]372bad5f2013-03-21 16:38:4329#include "cc/debug/rendering_stats_instrumentation.h"
[email protected]f6742f52013-05-08 23:52:2230#include "cc/debug/traced_value.h"
[email protected]3052b10f2013-03-18 07:41:2131#include "cc/input/page_scale_animation.h"
32#include "cc/input/top_controls_manager.h"
[email protected]cc3cfaa2013-03-18 09:05:5233#include "cc/layers/append_quads_data.h"
34#include "cc/layers/heads_up_display_layer_impl.h"
[email protected]50761e92013-03-29 20:51:2835#include "cc/layers/layer_impl.h"
[email protected]cc3cfaa2013-03-18 09:05:5236#include "cc/layers/layer_iterator.h"
[email protected]3a83478b2013-08-22 20:55:1737#include "cc/layers/painted_scrollbar_layer_impl.h"
[email protected]50761e92013-03-29 20:51:2838#include "cc/layers/render_surface_impl.h"
[email protected]bf1cfd9a2013-09-26 05:43:0239#include "cc/layers/scrollbar_layer_impl_base.h"
[email protected]7f0d825f2013-03-18 07:24:3040#include "cc/output/compositor_frame_metadata.h"
[email protected]30fe19ff2013-07-04 00:54:4541#include "cc/output/copy_output_request.h"
[email protected]7f0d825f2013-03-18 07:24:3042#include "cc/output/delegating_renderer.h"
43#include "cc/output/gl_renderer.h"
44#include "cc/output/software_renderer.h"
[email protected]89e82672013-03-18 07:50:5645#include "cc/quads/render_pass_draw_quad.h"
46#include "cc/quads/shared_quad_state.h"
47#include "cc/quads/solid_color_draw_quad.h"
[email protected]9f4f6a32013-09-04 21:35:1248#include "cc/quads/texture_draw_quad.h"
reveman5ae838bb2014-09-24 23:30:1449#include "cc/resources/bitmap_raster_worker_pool.h"
[email protected]bf050582014-07-24 11:10:5850#include "cc/resources/eviction_tile_priority_queue.h"
[email protected]e1878b52014-07-01 09:21:1751#include "cc/resources/gpu_raster_worker_pool.h"
[email protected]e12dd0e2013-03-18 08:24:4052#include "cc/resources/memory_history.h"
reveman423e7da2014-09-23 16:57:4453#include "cc/resources/one_copy_raster_worker_pool.h"
[email protected]e12dd0e2013-03-18 08:24:4054#include "cc/resources/picture_layer_tiling.h"
[email protected]ec7541d2014-04-09 01:23:5355#include "cc/resources/pixel_buffer_raster_worker_pool.h"
[email protected]e12dd0e2013-03-18 08:24:4056#include "cc/resources/prioritized_resource_manager.h"
[email protected]bf050582014-07-24 11:10:5857#include "cc/resources/raster_tile_priority_queue.h"
[email protected]7beac1b52014-04-10 23:09:5658#include "cc/resources/raster_worker_pool.h"
[email protected]eece11e2014-04-12 03:07:1659#include "cc/resources/resource_pool.h"
[email protected]ea468c6c2013-09-10 08:25:1160#include "cc/resources/texture_mailbox_deleter.h"
[email protected]c9280762013-08-01 06:28:5761#include "cc/resources/ui_resource_bitmap.h"
reveman423e7da2014-09-23 16:57:4462#include "cc/resources/zero_copy_raster_worker_pool.h"
[email protected]be4655a2013-03-18 08:36:3163#include "cc/scheduler/delay_based_time_source.h"
[email protected]556fd292013-03-18 08:03:0464#include "cc/trees/damage_tracker.h"
65#include "cc/trees/layer_tree_host.h"
66#include "cc/trees/layer_tree_host_common.h"
67#include "cc/trees/layer_tree_impl.h"
[email protected]34ba1ffb2014-03-05 06:55:0368#include "cc/trees/occlusion_tracker.h"
[email protected]556fd292013-03-18 08:03:0469#include "cc/trees/single_thread_proxy.h"
70#include "cc/trees/tree_synchronizer.h"
[email protected]110fcc0e2014-07-16 15:52:4771#include "gpu/command_buffer/client/gles2_interface.h"
[email protected]8d7aa012013-11-23 21:19:1272#include "gpu/GLES2/gl2extchromium.h"
[email protected]de2cf8c2013-10-25 19:46:4673#include "ui/gfx/frame_time.h"
[email protected]bd5324592014-07-31 09:09:3374#include "ui/gfx/geometry/rect_conversions.h"
heejin.r.chungd28506ba2014-10-23 16:36:2075#include "ui/gfx/geometry/size_conversions.h"
76#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]94f206c12012-08-25 00:09:1477
reveman5ae838bb2014-09-24 23:30:1478namespace cc {
[email protected]94f206c12012-08-25 00:09:1479namespace {
80
bokanef971462014-10-13 22:58:3281// Small helper class that saves the current viewport location as the user sees
82// it and resets to the same location.
83class ViewportAnchor {
84 public:
85 ViewportAnchor(LayerImpl* inner_scroll, LayerImpl* outer_scroll)
86 : inner_(inner_scroll),
87 outer_(outer_scroll) {
88 viewport_in_content_coordinates_ = inner_->TotalScrollOffset();
89
90 if (outer_)
91 viewport_in_content_coordinates_ += outer_->TotalScrollOffset();
92 }
93
94 void ResetViewportToAnchoredPosition() {
95 DCHECK(outer_);
96
97 inner_->ClampScrollToMaxScrollOffset();
98 outer_->ClampScrollToMaxScrollOffset();
99
100 gfx::ScrollOffset viewport_location = inner_->TotalScrollOffset() +
101 outer_->TotalScrollOffset();
102
103 gfx::Vector2dF delta =
104 viewport_in_content_coordinates_.DeltaFrom(viewport_location);
105
106 delta = outer_->ScrollBy(delta);
107 inner_->ScrollBy(delta);
108 }
109
110 private:
111 LayerImpl* inner_;
112 LayerImpl* outer_;
113 gfx::ScrollOffset viewport_in_content_coordinates_;
114};
115
116
reveman5ae838bb2014-09-24 23:30:14117void DidVisibilityChange(LayerTreeHostImpl* id, bool visible) {
[email protected]c1bb5af2013-03-13 19:06:27118 if (visible) {
119 TRACE_EVENT_ASYNC_BEGIN1("webkit",
120 "LayerTreeHostImpl::SetVisible",
121 id,
122 "LayerTreeHostImpl",
123 id);
124 return;
125 }
[email protected]94f206c12012-08-25 00:09:14126
[email protected]c1bb5af2013-03-13 19:06:27127 TRACE_EVENT_ASYNC_END0("webkit", "LayerTreeHostImpl::SetVisible", id);
[email protected]94f206c12012-08-25 00:09:14128}
129
reveman5ae838bb2014-09-24 23:30:14130size_t GetMaxTransferBufferUsageBytes(
131 const ContextProvider::Capabilities& context_capabilities,
132 double refresh_rate) {
[email protected]b4664142013-11-08 00:50:31133 // We want to make sure the default transfer buffer size is equal to the
134 // amount of data that can be uploaded by the compositor to avoid stalling
135 // the pipeline.
136 // For reference Chromebook Pixel can upload 1MB in about 0.5ms.
137 const size_t kMaxBytesUploadedPerMs = 1024 * 1024 * 2;
danakje6a236bc2014-09-02 21:27:17138
139 // We need to upload at least enough work to keep the GPU process busy until
140 // the next time it can handle a request to start more uploads from the
141 // compositor. We assume that it will pick up any sent upload requests within
142 // the time of a vsync, since the browser will want to swap a frame within
143 // that time interval, and then uploads should have a chance to be processed.
144 size_t ms_per_frame = std::floor(1000.0 / refresh_rate);
145 size_t max_transfer_buffer_usage_bytes =
146 ms_per_frame * kMaxBytesUploadedPerMs;
147
148 // The context may request a lower limit based on the device capabilities.
reveman5ae838bb2014-09-24 23:30:14149 return std::min(context_capabilities.max_transfer_buffer_usage_bytes,
150 max_transfer_buffer_usage_bytes);
[email protected]b4664142013-11-08 00:50:31151}
152
reveman5ae838bb2014-09-24 23:30:14153unsigned GetMapImageTextureTarget(
154 const ContextProvider::Capabilities& context_capabilities) {
155 if (context_capabilities.gpu.egl_image_external)
[email protected]8d7aa012013-11-23 21:19:12156 return GL_TEXTURE_EXTERNAL_OES;
reveman5ae838bb2014-09-24 23:30:14157 if (context_capabilities.gpu.texture_rectangle)
[email protected]8d7aa012013-11-23 21:19:12158 return GL_TEXTURE_RECTANGLE_ARB;
[email protected]8d7aa012013-11-23 21:19:12159
160 return GL_TEXTURE_2D;
161}
162
revemanc84602a02014-09-24 15:41:25163size_t GetMaxStagingResourceCount() {
164 // Upper bound for number of staging resource to allow.
165 return 32;
166}
167
[email protected]c1bb5af2013-03-13 19:06:27168} // namespace
[email protected]94f206c12012-08-25 00:09:14169
[email protected]96baf3e2012-10-22 23:09:55170class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient {
[email protected]c1bb5af2013-03-13 19:06:27171 public:
172 static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> Create(
173 LayerTreeHostImpl* layer_tree_host_impl,
174 scoped_refptr<DelayBasedTimeSource> time_source) {
175 return make_scoped_ptr(
176 new LayerTreeHostImplTimeSourceAdapter(layer_tree_host_impl,
177 time_source));
178 }
dcheng716bedf2014-10-21 09:51:08179 ~LayerTreeHostImplTimeSourceAdapter() override {
[email protected]6d0e69d2013-03-20 14:53:26180 time_source_->SetClient(NULL);
181 time_source_->SetActive(false);
[email protected]c1bb5af2013-03-13 19:06:27182 }
183
dcheng716bedf2014-10-21 09:51:08184 void OnTimerTick() override {
[email protected]c1bb5af2013-03-13 19:06:27185 // In single threaded mode we attempt to simulate changing the current
186 // thread by maintaining a fake thread id. When we switch from one
187 // thread to another, we construct DebugScopedSetXXXThread objects that
188 // update the thread id. This lets DCHECKS that ensure we're on the
189 // right thread to work correctly in single threaded mode. The problem
190 // here is that the timer tasks are run via the message loop, and when
191 // they run, we've had no chance to construct a DebugScopedSetXXXThread
192 // object. The result is that we report that we're running on the main
193 // thread. In multi-threaded mode, this timer is run on the compositor
194 // thread, so to keep this consistent in single-threaded mode, we'll
195 // construct a DebugScopedSetImplThread object. There is no need to do
196 // this in multi-threaded mode since the real thread id's will be
197 // correct. In fact, setting fake thread id's interferes with the real
198 // thread id's and causes breakage.
199 scoped_ptr<DebugScopedSetImplThread> set_impl_thread;
200 if (!layer_tree_host_impl_->proxy()->HasImplThread()) {
201 set_impl_thread.reset(
202 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy()));
[email protected]94f206c12012-08-25 00:09:14203 }
204
[email protected]fb7425a2013-04-22 16:28:55205 layer_tree_host_impl_->Animate(
[email protected]04c5900d2014-08-18 13:38:36206 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time);
[email protected]3d9f7432013-04-06 00:35:18207 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true);
208 bool start_ready_animations = true;
209 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
[email protected]8f7f298822014-06-13 00:23:32210
211 if (layer_tree_host_impl_->pending_tree()) {
212 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties();
213 layer_tree_host_impl_->ManageTiles();
214 }
215
[email protected]04c5900d2014-08-18 13:38:36216 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame();
[email protected]c1bb5af2013-03-13 19:06:27217 }
[email protected]373974232013-01-10 22:20:50218
[email protected]c1bb5af2013-03-13 19:06:27219 void SetActive(bool active) {
[email protected]6d0e69d2013-03-20 14:53:26220 if (active != time_source_->Active())
221 time_source_->SetActive(active);
[email protected]c1bb5af2013-03-13 19:06:27222 }
[email protected]94f206c12012-08-25 00:09:14223
[email protected]d9fce6722013-08-30 01:10:01224 bool Active() const { return time_source_->Active(); }
225
[email protected]c1bb5af2013-03-13 19:06:27226 private:
227 LayerTreeHostImplTimeSourceAdapter(
228 LayerTreeHostImpl* layer_tree_host_impl,
229 scoped_refptr<DelayBasedTimeSource> time_source)
230 : layer_tree_host_impl_(layer_tree_host_impl),
231 time_source_(time_source) {
[email protected]6d0e69d2013-03-20 14:53:26232 time_source_->SetClient(this);
[email protected]c1bb5af2013-03-13 19:06:27233 }
[email protected]94f206c12012-08-25 00:09:14234
[email protected]c1bb5af2013-03-13 19:06:27235 LayerTreeHostImpl* layer_tree_host_impl_;
236 scoped_refptr<DelayBasedTimeSource> time_source_;
[email protected]94f206c12012-08-25 00:09:14237
[email protected]c1bb5af2013-03-13 19:06:27238 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImplTimeSourceAdapter);
[email protected]94f206c12012-08-25 00:09:14239};
240
[email protected]96baf3e2012-10-22 23:09:55241LayerTreeHostImpl::FrameData::FrameData()
[email protected]e0341352013-04-06 05:01:20242 : contains_incomplete_tile(false), has_no_damage(false) {}
[email protected]c1bb5af2013-03-13 19:06:27243
244LayerTreeHostImpl::FrameData::~FrameData() {}
245
246scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create(
247 const LayerTreeSettings& settings,
248 LayerTreeHostImplClient* client,
[email protected]372bad5f2013-03-21 16:38:43249 Proxy* proxy,
[email protected]a7f35682013-10-22 23:05:57250 RenderingStatsInstrumentation* rendering_stats_instrumentation,
reveman22dd9292014-10-13 20:52:05251 SharedBitmapManager* shared_bitmap_manager,
252 GpuMemoryBufferManager* gpu_memory_buffer_manager,
[email protected]dbe759a2013-12-02 19:23:02253 int id) {
reveman22dd9292014-10-13 20:52:05254 return make_scoped_ptr(new LayerTreeHostImpl(settings,
255 client,
256 proxy,
257 rendering_stats_instrumentation,
258 shared_bitmap_manager,
259 gpu_memory_buffer_manager,
260 id));
[email protected]493067512012-09-19 23:34:10261}
262
[email protected]372bad5f2013-03-21 16:38:43263LayerTreeHostImpl::LayerTreeHostImpl(
264 const LayerTreeSettings& settings,
265 LayerTreeHostImplClient* client,
266 Proxy* proxy,
[email protected]a7f35682013-10-22 23:05:57267 RenderingStatsInstrumentation* rendering_stats_instrumentation,
reveman22dd9292014-10-13 20:52:05268 SharedBitmapManager* shared_bitmap_manager,
269 GpuMemoryBufferManager* gpu_memory_buffer_manager,
[email protected]dbe759a2013-12-02 19:23:02270 int id)
mithroc34fc0b12014-09-30 09:10:41271 : BeginFrameSourceMixIn(),
272 client_(client),
[email protected]c1bb5af2013-03-13 19:06:27273 proxy_(proxy),
[email protected]13525d62014-05-20 21:22:04274 use_gpu_rasterization_(false),
[email protected]200a9c062013-05-20 04:34:37275 input_handler_client_(NULL),
[email protected]c1bb5af2013-03-13 19:06:27276 did_lock_scrolling_layer_(false),
277 should_bubble_scrolls_(false),
278 wheel_scrolling_(false),
[email protected]f161ca9e2014-04-01 13:57:01279 scroll_affects_scroll_handler_(false),
[email protected]f620b0e72013-10-01 21:38:24280 scroll_layer_id_when_mouse_over_scrollbar_(0),
[email protected]c48536a52013-09-14 00:02:08281 tile_priorities_dirty_(false),
[email protected]1960a712013-04-30 17:06:47282 root_layer_scroll_offset_delegate_(NULL),
[email protected]c1bb5af2013-03-13 19:06:27283 settings_(settings),
[email protected]c1bb5af2013-03-13 19:06:27284 visible_(true),
[email protected]3f2ff112013-08-03 02:41:07285 cached_managed_memory_policy_(
[email protected]b56c1302013-03-20 21:17:34286 PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
[email protected]f44d5552013-10-29 04:56:29287 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
[email protected]3f2ff112013-08-03 02:41:07288 ManagedMemoryPolicy::kDefaultNumResourcesLimit),
[email protected]c1bb5af2013-03-13 19:06:27289 pinch_gesture_active_(false),
[email protected]2fa342b82013-09-24 03:19:13290 pinch_gesture_end_should_clear_scrolling_layer_(false),
[email protected]9e3594522013-03-18 00:57:36291 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())),
[email protected]7497316a2013-03-15 12:42:29292 paint_time_counter_(PaintTimeCounter::Create()),
[email protected]c1bb5af2013-03-13 19:06:27293 memory_history_(MemoryHistory::Create()),
[email protected]d35992782013-03-14 14:54:02294 debug_rect_history_(DebugRectHistory::Create()),
[email protected]dd909b1f2014-03-18 00:19:52295 texture_mailbox_deleter_(new TextureMailboxDeleter(
296 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner()
297 : proxy_->MainThreadTaskRunner())),
[email protected]d7626ffd2013-03-29 00:17:42298 max_memory_needed_bytes_(0),
[email protected]50644642013-06-20 13:58:55299 zero_budget_(false),
[email protected]f224cc92013-06-06 23:23:32300 device_scale_factor_(1.f),
[email protected]9f4f6a32013-09-04 21:35:12301 overhang_ui_resource_id_(0),
[email protected]c05dfbb2014-07-10 22:49:04302 resourceless_software_draw_(false),
[email protected]c92195e2014-05-07 18:18:49303 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()),
[email protected]372bad5f2013-03-21 16:38:43304 animation_registrar_(AnimationRegistrar::Create()),
[email protected]39643fb2013-07-09 17:28:19305 rendering_stats_instrumentation_(rendering_stats_instrumentation),
[email protected]5e5648a2013-11-18 00:39:33306 micro_benchmark_controller_(this),
[email protected]a7f35682013-10-22 23:05:57307 need_to_update_visible_tiles_before_draw_(false),
reveman22dd9292014-10-13 20:52:05308 shared_bitmap_manager_(shared_bitmap_manager),
309 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
vmpstr61ed94a12014-10-09 04:49:30310 id_(id),
311 requires_high_res_to_draw_(false) {
[email protected]c1bb5af2013-03-13 19:06:27312 DCHECK(proxy_->IsImplThread());
313 DidVisibilityChange(this, visible_);
[email protected]5d8bec72014-07-03 03:03:11314 animation_registrar_->set_supports_scroll_animations(
315 proxy_->SupportsImplScrolling());
[email protected]c1bb5af2013-03-13 19:06:27316
[email protected]8e0176d2013-03-21 03:14:52317 SetDebugState(settings.initial_debug_state);
[email protected]c1bb5af2013-03-13 19:06:27318
bokan55b2f152014-09-15 14:47:59319 // LTHI always has an active tree.
320 active_tree_ = LayerTreeImpl::create(this);
321 TRACE_EVENT_OBJECT_CREATED_WITH_ID(
322 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_);
323
[email protected]8e0176d2013-03-21 03:14:52324 if (settings.calculate_top_controls_position) {
[email protected]c1bb5af2013-03-13 19:06:27325 top_controls_manager_ =
326 TopControlsManager::Create(this,
[email protected]8e0176d2013-03-21 03:14:52327 settings.top_controls_height,
328 settings.top_controls_show_threshold,
329 settings.top_controls_hide_threshold);
bokan0da0ba8b2014-09-25 19:17:26330
331 // TODO(bokan): This is a quick fix. The browser should lock the top
332 // controls to shown on creation but this appears not to work. Tracked
333 // in crbug.com/417680.
334 // Initialize with top controls showing.
335 SetControlsTopOffset(0.f);
[email protected]c1bb5af2013-03-13 19:06:27336 }
[email protected]493067512012-09-19 23:34:10337}
338
[email protected]c1bb5af2013-03-13 19:06:27339LayerTreeHostImpl::~LayerTreeHostImpl() {
340 DCHECK(proxy_->IsImplThread());
341 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()");
[email protected]9197dbcb2013-05-15 20:28:51342 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
[email protected]a75441c2014-05-16 19:10:29343 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_);
[email protected]c1bb5af2013-03-13 19:06:27344
[email protected]200a9c062013-05-20 04:34:37345 if (input_handler_client_) {
346 input_handler_client_->WillShutdown();
347 input_handler_client_ = NULL;
348 }
349
[email protected]75deb742013-06-24 20:19:18350 // The layer trees must be destroyed before the layer tree host. We've
351 // made a contract with our animation controllers that the registrar
352 // will outlive them, and we must make good.
[email protected]df17af52014-02-06 02:20:40353 if (recycle_tree_)
354 recycle_tree_->Shutdown();
355 if (pending_tree_)
356 pending_tree_->Shutdown();
357 active_tree_->Shutdown();
danakjf446a072014-09-27 21:55:48358 recycle_tree_ = nullptr;
359 pending_tree_ = nullptr;
360 active_tree_ = nullptr;
[email protected]ced667b2014-05-22 21:49:53361 DestroyTileManager();
[email protected]94f206c12012-08-25 00:09:14362}
363
[email protected]097a0cbf2013-12-12 17:04:58364void LayerTreeHostImpl::BeginMainFrameAborted(bool did_handle) {
365 // If the begin frame data was handled, then scroll and scale set was applied
366 // by the main thread, so the active tree needs to be updated as if these sent
367 // values were applied and committed.
368 if (did_handle) {
369 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit();
370 active_tree_->ResetContentsTexturesPurged();
371 }
372}
373
[email protected]12a63da2014-06-13 06:06:22374void LayerTreeHostImpl::BeginCommit() {
375 TRACE_EVENT0("cc", "LayerTreeHostImpl::BeginCommit");
376
[email protected]fc20d142014-07-01 00:49:15377 if (UsePendingTreeForSync())
[email protected]12a63da2014-06-13 06:06:22378 CreatePendingTree();
379}
[email protected]3b31c6ac2012-12-06 21:27:29380
[email protected]c1bb5af2013-03-13 19:06:27381void LayerTreeHostImpl::CommitComplete() {
382 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete");
[email protected]131a0c22013-02-12 18:31:08383
[email protected]fc20d142014-07-01 00:49:15384 if (pending_tree_)
385 pending_tree_->ApplyScrollDeltasSinceBeginMainFrame();
386 sync_tree()->set_needs_update_draw_properties();
387
[email protected]8e0176d2013-03-21 03:14:52388 if (settings_.impl_side_painting) {
[email protected]58241dc2013-08-20 01:39:25389 // Impl-side painting needs an update immediately post-commit to have the
390 // opportunity to create tilings. Other paths can call UpdateDrawProperties
391 // more lazily when needed prior to drawing.
[email protected]fc20d142014-07-01 00:49:15392 sync_tree()->UpdateDrawProperties();
[email protected]a23451e2013-06-07 20:58:26393 // Start working on newly created tiles immediately if needed.
[email protected]fc20d142014-07-01 00:49:15394 if (tile_manager_ && tile_priorities_dirty_)
[email protected]4f48f6e2013-08-27 06:33:38395 ManageTiles();
[email protected]fc20d142014-07-01 00:49:15396 else
397 NotifyReadyToActivate();
[email protected]c1bb5af2013-03-13 19:06:27398 } else {
[email protected]12a63da2014-06-13 06:06:22399 // If we're not in impl-side painting, the tree is immediately considered
400 // active.
[email protected]fc20d142014-07-01 00:49:15401 ActivateSyncTree();
[email protected]c1bb5af2013-03-13 19:06:27402 }
[email protected]3ba4cae2013-01-16 03:58:38403
[email protected]5e5648a2013-11-18 00:39:33404 micro_benchmark_controller_.DidCompleteCommit();
[email protected]94f206c12012-08-25 00:09:14405}
406
[email protected]6133cc232013-07-30 18:47:07407bool LayerTreeHostImpl::CanDraw() const {
[email protected]c1bb5af2013-03-13 19:06:27408 // Note: If you are changing this function or any other function that might
409 // affect the result of CanDraw, make sure to call
410 // client_->OnCanDrawStateChanged in the proper places and update the
411 // NotifyIfCanDrawChanged test.
[email protected]94f206c12012-08-25 00:09:14412
[email protected]6133cc232013-07-30 18:47:07413 if (!renderer_) {
414 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw no renderer",
415 TRACE_EVENT_SCOPE_THREAD);
416 return false;
417 }
418
419 // Must have an OutputSurface if |renderer_| is not NULL.
420 DCHECK(output_surface_);
421
422 // TODO(boliu): Make draws without root_layer work and move this below
423 // draw_and_swap_full_viewport_every_frame check. Tracked in crbug.com/264967.
[email protected]c1bb5af2013-03-13 19:06:27424 if (!active_tree_->root_layer()) {
[email protected]c76faea2013-03-26 07:42:42425 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw no root layer",
426 TRACE_EVENT_SCOPE_THREAD);
[email protected]2f1acc262012-11-16 21:42:22427 return false;
[email protected]c1bb5af2013-03-13 19:06:27428 }
[email protected]6133cc232013-07-30 18:47:07429
430 if (output_surface_->capabilities().draw_and_swap_full_viewport_every_frame)
431 return true;
432
[email protected]54af03522013-09-05 00:43:28433 if (DrawViewportSize().IsEmpty()) {
[email protected]c76faea2013-03-26 07:42:42434 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw empty viewport",
435 TRACE_EVENT_SCOPE_THREAD);
[email protected]c1bb5af2013-03-13 19:06:27436 return false;
437 }
438 if (active_tree_->ViewportSizeInvalid()) {
439 TRACE_EVENT_INSTANT0(
[email protected]c76faea2013-03-26 07:42:42440 "cc", "LayerTreeHostImpl::CanDraw viewport size recently changed",
441 TRACE_EVENT_SCOPE_THREAD);
[email protected]c1bb5af2013-03-13 19:06:27442 return false;
443 }
[email protected]c1bb5af2013-03-13 19:06:27444 if (active_tree_->ContentsTexturesPurged()) {
445 TRACE_EVENT_INSTANT0(
[email protected]c76faea2013-03-26 07:42:42446 "cc", "LayerTreeHostImpl::CanDraw contents textures purged",
447 TRACE_EVENT_SCOPE_THREAD);
[email protected]c1bb5af2013-03-13 19:06:27448 return false;
449 }
[email protected]127bdc1a2013-09-11 01:44:48450 if (EvictedUIResourcesExist()) {
451 TRACE_EVENT_INSTANT0(
452 "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated",
453 TRACE_EVENT_SCOPE_THREAD);
454 return false;
455 }
[email protected]c1bb5af2013-03-13 19:06:27456 return true;
[email protected]2f1acc262012-11-16 21:42:22457}
458
[email protected]27152642014-03-11 20:42:00459void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) {
[email protected]200a9c062013-05-20 04:34:37460 if (input_handler_client_)
461 input_handler_client_->Animate(monotonic_time);
[email protected]c1bb5af2013-03-13 19:06:27462 AnimatePageScale(monotonic_time);
[email protected]27152642014-03-11 20:42:00463 AnimateLayers(monotonic_time);
[email protected]c1bb5af2013-03-13 19:06:27464 AnimateScrollbars(monotonic_time);
[email protected]ffb2720f2013-03-15 19:18:37465 AnimateTopControls(monotonic_time);
[email protected]94f206c12012-08-25 00:09:14466}
467
[email protected]c1bb5af2013-03-13 19:06:27468void LayerTreeHostImpl::ManageTiles() {
[email protected]a23451e2013-06-07 20:58:26469 if (!tile_manager_)
470 return;
[email protected]c48536a52013-09-14 00:02:08471 if (!tile_priorities_dirty_)
[email protected]a23451e2013-06-07 20:58:26472 return;
[email protected]54af03522013-09-05 00:43:28473
[email protected]c48536a52013-09-14 00:02:08474 tile_priorities_dirty_ = false;
[email protected]1bcced22013-09-24 13:51:19475 tile_manager_->ManageTiles(global_tile_state_);
[email protected]c1bb5af2013-03-13 19:06:27476
[email protected]99cc6b42014-01-17 00:12:57477 client_->DidManageTiles();
[email protected]f57bbc02012-11-21 07:02:15478}
479
[email protected]edcc1a12014-05-06 01:26:39480bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt(
481 const gfx::Point& viewport_point,
482 InputHandler::ScrollInputType type) {
483 if (!CurrentlyScrollingLayer())
484 return false;
485
[email protected]edcc1a12014-05-06 01:26:39486 gfx::PointF device_viewport_point =
487 gfx::ScalePoint(viewport_point, device_scale_factor_);
488
[email protected]28336d52014-05-12 19:07:28489 LayerImpl* layer_impl =
490 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
[email protected]edcc1a12014-05-06 01:26:39491
492 bool scroll_on_main_thread = false;
493 LayerImpl* scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint(
494 device_viewport_point, type, layer_impl, &scroll_on_main_thread, NULL);
495 return CurrentlyScrollingLayer() == scrolling_layer_impl;
496}
497
[email protected]47a723f2014-03-05 12:42:49498bool LayerTreeHostImpl::HaveTouchEventHandlersAt(
499 const gfx::Point& viewport_point) {
[email protected]f57bbc02012-11-21 07:02:15500
[email protected]c1bb5af2013-03-13 19:06:27501 gfx::PointF device_viewport_point =
502 gfx::ScalePoint(viewport_point, device_scale_factor_);
[email protected]f57bbc02012-11-21 07:02:15503
[email protected]c974d5d2013-10-24 01:02:48504 LayerImpl* layer_impl =
[email protected]28336d52014-05-12 19:07:28505 active_tree_->FindLayerThatIsHitByPointInTouchHandlerRegion(
506 device_viewport_point);
507
[email protected]c974d5d2013-10-24 01:02:48508 return layer_impl != NULL;
[email protected]c1bb5af2013-03-13 19:06:27509}
510
[email protected]6be422b2013-12-08 06:47:31511scoped_ptr<SwapPromiseMonitor>
512LayerTreeHostImpl::CreateLatencyInfoSwapPromiseMonitor(
513 ui::LatencyInfo* latency) {
danakjf446a072014-09-27 21:55:48514 return make_scoped_ptr(
[email protected]6be422b2013-12-08 06:47:31515 new LatencyInfoSwapPromiseMonitor(latency, NULL, this));
[email protected]b76329d2013-06-11 04:15:08516}
517
[email protected]dab0a422014-08-13 16:09:46518void LayerTreeHostImpl::QueueSwapPromiseForMainThreadScrollUpdate(
519 scoped_ptr<SwapPromise> swap_promise) {
520 swap_promises_for_main_thread_scroll_update_.push_back(swap_promise.Pass());
521}
522
[email protected]c1bb5af2013-03-13 19:06:27523void LayerTreeHostImpl::TrackDamageForAllSurfaces(
524 LayerImpl* root_draw_layer,
[email protected]50761e92013-03-29 20:51:28525 const LayerImplList& render_surface_layer_list) {
[email protected]c1bb5af2013-03-13 19:06:27526 // For now, we use damage tracking to compute a global scissor. To do this, we
527 // must compute all damage tracking before drawing anything, so that we know
528 // the root damage rect. The root damage rect is then used to scissor each
529 // surface.
530
531 for (int surface_index = render_surface_layer_list.size() - 1;
[email protected]bf691c22013-03-26 21:15:06532 surface_index >= 0;
[email protected]c1bb5af2013-03-13 19:06:27533 --surface_index) {
534 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index];
535 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
536 DCHECK(render_surface);
537 render_surface->damage_tracker()->UpdateDamageTrackingState(
538 render_surface->layer_list(),
539 render_surface_layer->id(),
540 render_surface->SurfacePropertyChangedOnlyFromDescendant(),
541 render_surface->content_rect(),
542 render_surface_layer->mask_layer(),
[email protected]1dc7943e2013-09-26 04:41:48543 render_surface_layer->filters());
[email protected]c1bb5af2013-03-13 19:06:27544 }
545}
546
[email protected]d12aa932014-08-01 13:10:38547void LayerTreeHostImpl::FrameData::AsValueInto(
548 base::debug::TracedValue* value) const {
[email protected]34806722013-08-09 23:51:21549 value->SetBoolean("contains_incomplete_tile", contains_incomplete_tile);
550 value->SetBoolean("has_no_damage", has_no_damage);
551
552 // Quad data can be quite large, so only dump render passes if we select
553 // cc.debug.quads.
554 bool quads_enabled;
555 TRACE_EVENT_CATEGORY_GROUP_ENABLED(
556 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"), &quads_enabled);
557 if (quads_enabled) {
[email protected]d12aa932014-08-01 13:10:38558 value->BeginArray("render_passes");
559 for (size_t i = 0; i < render_passes.size(); ++i) {
560 value->BeginDictionary();
561 render_passes[i]->AsValueInto(value);
562 value->EndDictionary();
563 }
564 value->EndArray();
[email protected]34806722013-08-09 23:51:21565 }
[email protected]34806722013-08-09 23:51:21566}
567
[email protected]c1bb5af2013-03-13 19:06:27568void LayerTreeHostImpl::FrameData::AppendRenderPass(
569 scoped_ptr<RenderPass> render_pass) {
570 render_passes_by_id[render_pass->id] = render_pass.get();
571 render_passes.push_back(render_pass.Pass());
572}
573
[email protected]c05dfbb2014-07-10 22:49:04574DrawMode LayerTreeHostImpl::GetDrawMode() const {
575 if (resourceless_software_draw_) {
[email protected]ffbb2212013-06-02 23:47:59576 return DRAW_MODE_RESOURCELESS_SOFTWARE;
[email protected]c05dfbb2014-07-10 22:49:04577 } else if (output_surface_->context_provider()) {
[email protected]ffbb2212013-06-02 23:47:59578 return DRAW_MODE_HARDWARE;
579 } else {
[email protected]c05dfbb2014-07-10 22:49:04580 DCHECK_EQ(!output_surface_->software_device(),
581 output_surface_->capabilities().delegated_rendering &&
582 !output_surface_->capabilities().deferred_gl_initialization)
583 << output_surface_->capabilities().delegated_rendering << " "
584 << output_surface_->capabilities().deferred_gl_initialization;
[email protected]ffbb2212013-06-02 23:47:59585 return DRAW_MODE_SOFTWARE;
586 }
587}
588
[email protected]34ba1ffb2014-03-05 06:55:03589static void AppendQuadsForLayer(
590 RenderPass* target_render_pass,
591 LayerImpl* layer,
592 const OcclusionTracker<LayerImpl>& occlusion_tracker,
593 AppendQuadsData* append_quads_data) {
vmpstr11b77b432014-10-07 20:11:40594 layer->AppendQuads(
595 target_render_pass,
596 occlusion_tracker.GetCurrentOcclusionForLayer(layer->draw_transform()),
597 append_quads_data);
[email protected]c1bb5af2013-03-13 19:06:27598}
599
600static void AppendQuadsForRenderSurfaceLayer(
601 RenderPass* target_render_pass,
602 LayerImpl* layer,
603 const RenderPass* contributing_render_pass,
[email protected]34ba1ffb2014-03-05 06:55:03604 const OcclusionTracker<LayerImpl>& occlusion_tracker,
[email protected]c1bb5af2013-03-13 19:06:27605 AppendQuadsData* append_quads_data) {
[email protected]c1bb5af2013-03-13 19:06:27606 bool is_replica = false;
[email protected]c6707fd2014-06-23 05:50:36607 layer->render_surface()->AppendQuads(target_render_pass,
608 occlusion_tracker,
[email protected]c1bb5af2013-03-13 19:06:27609 append_quads_data,
610 is_replica,
611 contributing_render_pass->id);
612
613 // Add replica after the surface so that it appears below the surface.
614 if (layer->has_replica()) {
615 is_replica = true;
[email protected]c6707fd2014-06-23 05:50:36616 layer->render_surface()->AppendQuads(target_render_pass,
617 occlusion_tracker,
[email protected]c1bb5af2013-03-13 19:06:27618 append_quads_data,
619 is_replica,
620 contributing_render_pass->id);
621 }
622}
623
624static void AppendQuadsToFillScreen(
[email protected]3744e27b2013-11-06 21:44:08625 ResourceProvider::ResourceId overhang_resource_id,
[email protected]cde98022014-01-16 19:59:20626 const gfx::SizeF& overhang_resource_scaled_size,
[email protected]0023fc72014-01-10 20:05:06627 const gfx::Rect& root_scroll_layer_rect,
[email protected]c1bb5af2013-03-13 19:06:27628 RenderPass* target_render_pass,
629 LayerImpl* root_layer,
630 SkColor screen_background_color,
[email protected]34ba1ffb2014-03-05 06:55:03631 const OcclusionTracker<LayerImpl>& occlusion_tracker) {
[email protected]c1bb5af2013-03-13 19:06:27632 if (!root_layer || !SkColorGetA(screen_background_color))
633 return;
634
635 Region fill_region = occlusion_tracker.ComputeVisibleRegionInScreen();
636 if (fill_region.IsEmpty())
637 return;
638
[email protected]3744e27b2013-11-06 21:44:08639 // Divide the fill region into the part to be filled with the overhang
640 // resource and the part to be filled with the background color.
641 Region screen_background_color_region = fill_region;
642 Region overhang_region;
643 if (overhang_resource_id) {
644 overhang_region = fill_region;
645 overhang_region.Subtract(root_scroll_layer_rect);
646 screen_background_color_region.Intersect(root_scroll_layer_rect);
647 }
648
[email protected]c1bb5af2013-03-13 19:06:27649 // Manually create the quad state for the gutter quads, as the root layer
650 // doesn't have any bounds and so can't generate this itself.
651 // TODO(danakj): Make the gutter quads generated by the solid color layer
652 // (make it smarter about generating quads to fill unoccluded areas).
653
654 gfx::Rect root_target_rect = root_layer->render_surface()->content_rect();
655 float opacity = 1.f;
[email protected]a9d4d4f2014-06-19 06:49:28656 int sorting_context_id = 0;
[email protected]c6707fd2014-06-23 05:50:36657 SharedQuadState* shared_quad_state =
658 target_render_pass->CreateAndAppendSharedQuadState();
[email protected]7785e1002014-02-20 21:04:32659 shared_quad_state->SetAll(gfx::Transform(),
[email protected]c1bb5af2013-03-13 19:06:27660 root_target_rect.size(),
661 root_target_rect,
662 root_target_rect,
[email protected]dc462d782012-11-21 21:43:01663 false,
[email protected]7bbeaf4e2013-11-26 10:27:22664 opacity,
[email protected]a9d4d4f2014-06-19 06:49:28665 SkXfermode::kSrcOver_Mode,
666 sorting_context_id);
[email protected]f57bbc02012-11-21 07:02:15667
[email protected]3744e27b2013-11-06 21:44:08668 for (Region::Iterator fill_rects(screen_background_color_region);
[email protected]c1bb5af2013-03-13 19:06:27669 fill_rects.has_rect();
670 fill_rects.next()) {
[email protected]7785e1002014-02-20 21:04:32671 gfx::Rect screen_space_rect = fill_rects.rect();
[email protected]9bf06c72014-03-07 18:16:24672 gfx::Rect visible_screen_space_rect = screen_space_rect;
[email protected]3744e27b2013-11-06 21:44:08673 // Skip the quad culler and just append the quads directly to avoid
674 // occlusion checks.
[email protected]f7030c32014-07-03 18:54:34675 SolidColorDrawQuad* quad =
676 target_render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
[email protected]9bf06c72014-03-07 18:16:24677 quad->SetNew(shared_quad_state,
678 screen_space_rect,
679 visible_screen_space_rect,
680 screen_background_color,
681 false);
[email protected]3744e27b2013-11-06 21:44:08682 }
683 for (Region::Iterator fill_rects(overhang_region);
684 fill_rects.has_rect();
685 fill_rects.next()) {
686 DCHECK(overhang_resource_id);
[email protected]7785e1002014-02-20 21:04:32687 gfx::Rect screen_space_rect = fill_rects.rect();
[email protected]9bf06c72014-03-07 18:16:24688 gfx::Rect opaque_screen_space_rect = screen_space_rect;
689 gfx::Rect visible_screen_space_rect = screen_space_rect;
[email protected]f7030c32014-07-03 18:54:34690 TextureDrawQuad* tex_quad =
691 target_render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
[email protected]3744e27b2013-11-06 21:44:08692 const float vertex_opacity[4] = {1.f, 1.f, 1.f, 1.f};
693 tex_quad->SetNew(
694 shared_quad_state,
[email protected]7785e1002014-02-20 21:04:32695 screen_space_rect,
[email protected]9bf06c72014-03-07 18:16:24696 opaque_screen_space_rect,
697 visible_screen_space_rect,
[email protected]3744e27b2013-11-06 21:44:08698 overhang_resource_id,
699 false,
[email protected]7785e1002014-02-20 21:04:32700 gfx::PointF(
701 screen_space_rect.x() / overhang_resource_scaled_size.width(),
702 screen_space_rect.y() / overhang_resource_scaled_size.height()),
703 gfx::PointF(
704 screen_space_rect.right() / overhang_resource_scaled_size.width(),
705 screen_space_rect.bottom() /
706 overhang_resource_scaled_size.height()),
[email protected]3744e27b2013-11-06 21:44:08707 screen_background_color,
708 vertex_opacity,
709 false);
[email protected]c1bb5af2013-03-13 19:06:27710 }
[email protected]467b3612012-08-28 07:41:16711}
712
[email protected]30d82142014-05-12 04:26:02713DrawResult LayerTreeHostImpl::CalculateRenderPasses(
[email protected]7ddfe7e82014-01-30 07:22:11714 FrameData* frame) {
[email protected]c1bb5af2013-03-13 19:06:27715 DCHECK(frame->render_passes.empty());
[email protected]7ddfe7e82014-01-30 07:22:11716 DCHECK(CanDraw());
717 DCHECK(active_tree_->root_layer());
[email protected]2d692992012-12-19 01:19:32718
[email protected]c1bb5af2013-03-13 19:06:27719 TrackDamageForAllSurfaces(active_tree_->root_layer(),
720 *frame->render_surface_layer_list);
[email protected]94f206c12012-08-25 00:09:14721
[email protected]e0341352013-04-06 05:01:20722 // If the root render surface has no visible damage, then don't generate a
723 // frame at all.
724 RenderSurfaceImpl* root_surface =
725 active_tree_->root_layer()->render_surface();
726 bool root_surface_has_no_visible_damage =
727 !root_surface->damage_tracker()->current_damage_rect().Intersects(
728 root_surface->content_rect());
729 bool root_surface_has_contributing_layers =
730 !root_surface->layer_list().empty();
[email protected]5fda7f32014-03-12 20:44:29731 bool hud_wants_to_draw_ = active_tree_->hud_layer() &&
732 active_tree_->hud_layer()->IsAnimatingHUDContents();
[email protected]e0341352013-04-06 05:01:20733 if (root_surface_has_contributing_layers &&
[email protected]37c339be2014-02-06 09:44:23734 root_surface_has_no_visible_damage &&
[email protected]5fda7f32014-03-12 20:44:29735 active_tree_->LayersWithCopyOutputRequest().empty() &&
736 !hud_wants_to_draw_) {
[email protected]e0341352013-04-06 05:01:20737 TRACE_EVENT0("cc",
738 "LayerTreeHostImpl::CalculateRenderPasses::EmptyDamageRect");
739 frame->has_no_damage = true;
[email protected]6133cc232013-07-30 18:47:07740 DCHECK(!output_surface_->capabilities()
741 .draw_and_swap_full_viewport_every_frame);
[email protected]30d82142014-05-12 04:26:02742 return DRAW_SUCCESS;
[email protected]e0341352013-04-06 05:01:20743 }
744
[email protected]c1bb5af2013-03-13 19:06:27745 TRACE_EVENT1("cc",
746 "LayerTreeHostImpl::CalculateRenderPasses",
747 "render_surface_layer_list.size()",
[email protected]bf691c22013-03-26 21:15:06748 static_cast<uint64>(frame->render_surface_layer_list->size()));
[email protected]94f206c12012-08-25 00:09:14749
[email protected]c1bb5af2013-03-13 19:06:27750 // Create the render passes in dependency order.
751 for (int surface_index = frame->render_surface_layer_list->size() - 1;
[email protected]bf691c22013-03-26 21:15:06752 surface_index >= 0;
[email protected]c1bb5af2013-03-13 19:06:27753 --surface_index) {
754 LayerImpl* render_surface_layer =
755 (*frame->render_surface_layer_list)[surface_index];
[email protected]30fe19ff2013-07-04 00:54:45756 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
757
758 bool should_draw_into_render_pass =
759 render_surface_layer->parent() == NULL ||
760 render_surface->contributes_to_drawn_surface() ||
761 render_surface_layer->HasCopyRequest();
762 if (should_draw_into_render_pass)
763 render_surface_layer->render_surface()->AppendRenderPasses(frame);
[email protected]c1bb5af2013-03-13 19:06:27764 }
[email protected]94f206c12012-08-25 00:09:14765
[email protected]f636ce82014-03-10 22:33:08766 // When we are displaying the HUD, change the root damage rect to cover the
767 // entire root surface. This will disable partial-swap/scissor optimizations
768 // that would prevent the HUD from updating, since the HUD does not cause
769 // damage itself, to prevent it from messing with damage visualizations. Since
770 // damage visualizations are done off the LayerImpls and RenderSurfaceImpls,
771 // changing the RenderPass does not affect them.
772 if (active_tree_->hud_layer()) {
773 RenderPass* root_pass = frame->render_passes.back();
774 root_pass->damage_rect = root_pass->output_rect;
775 }
776
[email protected]34ba1ffb2014-03-05 06:55:03777 OcclusionTracker<LayerImpl> occlusion_tracker(
[email protected]97c6a7342014-03-12 20:36:43778 active_tree_->root_layer()->render_surface()->content_rect());
[email protected]c1bb5af2013-03-13 19:06:27779 occlusion_tracker.set_minimum_tracking_size(
[email protected]8e0176d2013-03-21 03:14:52780 settings_.minimum_occlusion_tracking_size);
[email protected]94f206c12012-08-25 00:09:14781
[email protected]846f455b2013-03-18 19:07:41782 if (debug_state_.show_occluding_rects) {
[email protected]c1bb5af2013-03-13 19:06:27783 occlusion_tracker.set_occluding_screen_space_rects_container(
784 &frame->occluding_screen_space_rects);
785 }
[email protected]846f455b2013-03-18 19:07:41786 if (debug_state_.show_non_occluding_rects) {
[email protected]c1bb5af2013-03-13 19:06:27787 occlusion_tracker.set_non_occluding_screen_space_rects_container(
788 &frame->non_occluding_screen_space_rects);
789 }
[email protected]94f206c12012-08-25 00:09:14790
[email protected]ba1b33e2014-02-28 16:44:51791 // Add quads to the Render passes in front-to-back order to allow for testing
[email protected]c1bb5af2013-03-13 19:06:27792 // occlusion and performing culling during the tree walk.
[email protected]ba1b33e2014-02-28 16:44:51793 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]94f206c12012-08-25 00:09:14794
[email protected]c1bb5af2013-03-13 19:06:27795 // Typically when we are missing a texture and use a checkerboard quad, we
796 // still draw the frame. However when the layer being checkerboarded is moving
797 // due to an impl-animation, we drop the frame to avoid flashing due to the
798 // texture suddenly appearing in the future.
[email protected]30d82142014-05-12 04:26:02799 DrawResult draw_result = DRAW_SUCCESS;
[email protected]18a70192013-04-26 16:18:25800 // When we have a copy request for a layer, we need to draw no matter
801 // what, as the layer may disappear after this frame.
802 bool have_copy_request = false;
[email protected]94f206c12012-08-25 00:09:14803
[email protected]372bad5f2013-03-21 16:38:43804 int layers_drawn = 0;
805
[email protected]c05dfbb2014-07-10 22:49:04806 const DrawMode draw_mode = GetDrawMode();
[email protected]ffbb2212013-06-02 23:47:59807
[email protected]76ca89b2014-07-14 20:32:05808 int num_missing_tiles = 0;
809 int num_incomplete_tiles = 0;
810
[email protected]c1bb5af2013-03-13 19:06:27811 LayerIteratorType end =
[email protected]71dfcc72013-03-20 21:30:09812 LayerIteratorType::End(frame->render_surface_layer_list);
[email protected]c1bb5af2013-03-13 19:06:27813 for (LayerIteratorType it =
[email protected]71dfcc72013-03-20 21:30:09814 LayerIteratorType::Begin(frame->render_surface_layer_list);
[email protected]c1bb5af2013-03-13 19:06:27815 it != end;
816 ++it) {
[email protected]0cd7d6f72014-08-22 14:50:51817 RenderPassId target_render_pass_id =
818 it.target_render_surface_layer()->render_surface()->GetRenderPassId();
[email protected]c1bb5af2013-03-13 19:06:27819 RenderPass* target_render_pass =
820 frame->render_passes_by_id[target_render_pass_id];
[email protected]94f206c12012-08-25 00:09:14821
[email protected]e47b0a0a2013-11-18 23:26:22822 occlusion_tracker.EnterLayer(it);
[email protected]94f206c12012-08-25 00:09:14823
[email protected]30fe19ff2013-07-04 00:54:45824 AppendQuadsData append_quads_data(target_render_pass_id);
[email protected]89228202012-08-29 03:20:30825
[email protected]18a70192013-04-26 16:18:25826 if (it.represents_target_render_surface()) {
[email protected]0e5f7142013-05-24 06:45:36827 if (it->HasCopyRequest()) {
[email protected]18a70192013-04-26 16:18:25828 have_copy_request = true;
[email protected]d4d017e2013-06-20 21:46:11829 it->TakeCopyRequestsAndTransformToTarget(
830 &target_render_pass->copy_requests);
[email protected]18a70192013-04-26 16:18:25831 }
[email protected]30fe19ff2013-07-04 00:54:45832 } else if (it.represents_contributing_render_surface() &&
833 it->render_surface()->contributes_to_drawn_surface()) {
[email protected]0cd7d6f72014-08-22 14:50:51834 RenderPassId contributing_render_pass_id =
835 it->render_surface()->GetRenderPassId();
[email protected]c1bb5af2013-03-13 19:06:27836 RenderPass* contributing_render_pass =
837 frame->render_passes_by_id[contributing_render_pass_id];
838 AppendQuadsForRenderSurfaceLayer(target_render_pass,
839 *it,
840 contributing_render_pass,
841 occlusion_tracker,
842 &append_quads_data);
[email protected]8d964342014-05-15 18:22:27843 } else if (it.represents_itself() &&
[email protected]e1e768f2013-03-26 08:48:09844 !it->visible_content_rect().IsEmpty()) {
vmpstr01a5bf352014-09-17 22:57:31845 bool occluded =
846 occlusion_tracker.GetCurrentOcclusionForLayer(it->draw_transform())
847 .IsOccluded(it->visible_content_rect());
[email protected]fbc293322013-10-01 05:07:15848 if (!occluded && it->WillDraw(draw_mode, resource_provider_.get())) {
[email protected]c1bb5af2013-03-13 19:06:27849 DCHECK_EQ(active_tree_, it->layer_tree_impl());
[email protected]ffbb2212013-06-02 23:47:59850
[email protected]c1bb5af2013-03-13 19:06:27851 frame->will_draw_layers.push_back(*it);
[email protected]7d929c02012-09-20 17:26:57852
[email protected]c1bb5af2013-03-13 19:06:27853 if (it->HasContributingDelegatedRenderPasses()) {
[email protected]0cd7d6f72014-08-22 14:50:51854 RenderPassId contributing_render_pass_id =
[email protected]c1bb5af2013-03-13 19:06:27855 it->FirstContributingRenderPassId();
856 while (frame->render_passes_by_id.find(contributing_render_pass_id) !=
857 frame->render_passes_by_id.end()) {
858 RenderPass* render_pass =
859 frame->render_passes_by_id[contributing_render_pass_id];
[email protected]f5864912013-02-01 03:18:14860
[email protected]c1bb5af2013-03-13 19:06:27861 AppendQuadsData append_quads_data(render_pass->id);
862 AppendQuadsForLayer(render_pass,
863 *it,
864 occlusion_tracker,
865 &append_quads_data);
[email protected]7d929c02012-09-20 17:26:57866
[email protected]c1bb5af2013-03-13 19:06:27867 contributing_render_pass_id =
868 it->NextContributingRenderPassId(contributing_render_pass_id);
869 }
[email protected]94f206c12012-08-25 00:09:14870 }
871
[email protected]c1bb5af2013-03-13 19:06:27872 AppendQuadsForLayer(target_render_pass,
873 *it,
874 occlusion_tracker,
875 &append_quads_data);
876 }
[email protected]89228202012-08-29 03:20:30877
[email protected]372bad5f2013-03-21 16:38:43878 ++layers_drawn;
[email protected]94f206c12012-08-25 00:09:14879 }
880
[email protected]2bc19e532014-04-30 05:29:22881 rendering_stats_instrumentation_->AddVisibleContentArea(
882 append_quads_data.visible_content_area);
883 rendering_stats_instrumentation_->AddApproximatedVisibleContentArea(
884 append_quads_data.approximated_visible_content_area);
885
[email protected]76ca89b2014-07-14 20:32:05886 num_missing_tiles += append_quads_data.num_missing_tiles;
887 num_incomplete_tiles += append_quads_data.num_incomplete_tiles;
888
[email protected]e1e768f2013-03-26 08:48:09889 if (append_quads_data.num_missing_tiles) {
[email protected]c1bb5af2013-03-13 19:06:27890 bool layer_has_animating_transform =
891 it->screen_space_transform_is_animating() ||
892 it->draw_transform_is_animating();
[email protected]30d82142014-05-12 04:26:02893 if (layer_has_animating_transform)
894 draw_result = DRAW_ABORTED_CHECKERBOARD_ANIMATIONS;
[email protected]c1bb5af2013-03-13 19:06:27895 }
896
[email protected]76ca89b2014-07-14 20:32:05897 if (append_quads_data.num_incomplete_tiles ||
898 append_quads_data.num_missing_tiles) {
[email protected]c1bb5af2013-03-13 19:06:27899 frame->contains_incomplete_tile = true;
vmpstr61ed94a12014-10-09 04:49:30900 if (RequiresHighResToDraw())
[email protected]30d82142014-05-12 04:26:02901 draw_result = DRAW_ABORTED_MISSING_HIGH_RES_CONTENT;
[email protected]3d609bb2014-02-01 01:10:23902 }
[email protected]c1bb5af2013-03-13 19:06:27903
904 occlusion_tracker.LeaveLayer(it);
905 }
906
[email protected]6133cc232013-07-30 18:47:07907 if (have_copy_request ||
908 output_surface_->capabilities().draw_and_swap_full_viewport_every_frame)
[email protected]30d82142014-05-12 04:26:02909 draw_result = DRAW_SUCCESS;
[email protected]18a70192013-04-26 16:18:25910
[email protected]767f38d72014-03-18 21:26:41911#if DCHECK_IS_ON
weiliangc7eb7ee62014-10-07 00:04:40912 for (auto* render_pass : frame->render_passes) {
913 for (auto& quad : render_pass->quad_list)
914 DCHECK(quad.shared_quad_state);
915 DCHECK(frame->render_passes_by_id.find(render_pass->id) !=
916 frame->render_passes_by_id.end());
[email protected]c1bb5af2013-03-13 19:06:27917 }
[email protected]94f206c12012-08-25 00:09:14918#endif
[email protected]c1bb5af2013-03-13 19:06:27919 DCHECK(frame->render_passes.back()->output_rect.origin().IsOrigin());
[email protected]94f206c12012-08-25 00:09:14920
[email protected]c1bb5af2013-03-13 19:06:27921 if (!active_tree_->has_transparent_background()) {
922 frame->render_passes.back()->has_transparent_background = false;
[email protected]3744e27b2013-11-06 21:44:08923 AppendQuadsToFillScreen(
924 ResourceIdForUIResource(overhang_ui_resource_id_),
925 gfx::ScaleSize(overhang_ui_resource_size_, device_scale_factor_),
926 active_tree_->RootScrollLayerDeviceViewportBounds(),
927 frame->render_passes.back(),
928 active_tree_->root_layer(),
929 active_tree_->background_color(),
930 occlusion_tracker);
[email protected]c1bb5af2013-03-13 19:06:27931 }
[email protected]94f206c12012-08-25 00:09:14932
[email protected]c1bb5af2013-03-13 19:06:27933 RemoveRenderPasses(CullRenderPassesWithNoQuads(), frame);
[email protected]45948712013-09-27 02:46:48934 renderer_->DecideRenderPassAllocationsForFrame(frame->render_passes);
[email protected]94f206c12012-08-25 00:09:14935
[email protected]30fe19ff2013-07-04 00:54:45936 // Any copy requests left in the tree are not going to get serviced, and
937 // should be aborted.
[email protected]19334ac2013-12-12 23:59:11938 ScopedPtrVector<CopyOutputRequest> requests_to_abort;
939 while (!active_tree_->LayersWithCopyOutputRequest().empty()) {
940 LayerImpl* layer = active_tree_->LayersWithCopyOutputRequest().back();
941 layer->TakeCopyRequestsAndTransformToTarget(&requests_to_abort);
[email protected]30fe19ff2013-07-04 00:54:45942 }
[email protected]19334ac2013-12-12 23:59:11943 for (size_t i = 0; i < requests_to_abort.size(); ++i)
944 requests_to_abort[i]->SendEmptyResult();
[email protected]30fe19ff2013-07-04 00:54:45945
[email protected]e0341352013-04-06 05:01:20946 // If we're making a frame to draw, it better have at least one render pass.
947 DCHECK(!frame->render_passes.empty());
[email protected]45948712013-09-27 02:46:48948
[email protected]759dc9f2014-07-23 19:18:51949 if (active_tree_->has_ever_been_drawn()) {
[email protected]76ca89b2014-07-14 20:32:05950 UMA_HISTOGRAM_COUNTS_100(
951 "Compositing.RenderPass.AppendQuadData.NumMissingTiles",
952 num_missing_tiles);
953 UMA_HISTOGRAM_COUNTS_100(
954 "Compositing.RenderPass.AppendQuadData.NumIncompleteTiles",
955 num_incomplete_tiles);
956 }
957
[email protected]45948712013-09-27 02:46:48958 // Should only have one render pass in resourceless software mode.
[email protected]c05dfbb2014-07-10 22:49:04959 DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE ||
960 frame->render_passes.size() == 1u)
961 << frame->render_passes.size();
[email protected]45948712013-09-27 02:46:48962
[email protected]7ddfe7e82014-01-30 07:22:11963 return draw_result;
[email protected]94f206c12012-08-25 00:09:14964}
965
[email protected]200a9c062013-05-20 04:34:37966void LayerTreeHostImpl::MainThreadHasStoppedFlinging() {
967 if (input_handler_client_)
968 input_handler_client_->MainThreadHasStoppedFlinging();
969}
970
[email protected]3d9f7432013-04-06 00:35:18971void LayerTreeHostImpl::UpdateBackgroundAnimateTicking(
972 bool should_background_tick) {
[email protected]810d40b72013-06-20 18:26:15973 DCHECK(proxy_->IsImplThread());
[email protected]d9fce6722013-08-30 01:10:01974 if (should_background_tick)
975 DCHECK(active_tree_->root_layer());
[email protected]810d40b72013-06-20 18:26:15976
[email protected]cd77bb62014-03-27 05:16:36977 bool enabled = should_background_tick && needs_animate_layers();
[email protected]3d9f7432013-04-06 00:35:18978
[email protected]c1bb5af2013-03-13 19:06:27979 // Lazily create the time_source adapter so that we can vary the interval for
980 // testing.
981 if (!time_source_client_adapter_) {
982 time_source_client_adapter_ = LayerTreeHostImplTimeSourceAdapter::Create(
983 this,
[email protected]810d40b72013-06-20 18:26:15984 DelayBasedTimeSource::Create(
985 LowFrequencyAnimationInterval(),
986 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner()
987 : proxy_->MainThreadTaskRunner()));
[email protected]c1bb5af2013-03-13 19:06:27988 }
[email protected]94f206c12012-08-25 00:09:14989
[email protected]c1bb5af2013-03-13 19:06:27990 time_source_client_adapter_->SetActive(enabled);
[email protected]94f206c12012-08-25 00:09:14991}
992
[email protected]b8384e22013-12-03 02:20:48993void LayerTreeHostImpl::DidAnimateScrollOffset() {
994 client_->SetNeedsCommitOnImplThread();
995 client_->RenewTreePriority();
996}
997
[email protected]0023fc72014-01-10 20:05:06998void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) {
[email protected]878705be2013-04-15 22:44:02999 viewport_damage_rect_.Union(damage_rect);
1000}
1001
[email protected]c1bb5af2013-03-13 19:06:271002static inline RenderPass* FindRenderPassById(
[email protected]0cd7d6f72014-08-22 14:50:511003 RenderPassId render_pass_id,
[email protected]c1bb5af2013-03-13 19:06:271004 const LayerTreeHostImpl::FrameData& frame) {
1005 RenderPassIdHashMap::const_iterator it =
1006 frame.render_passes_by_id.find(render_pass_id);
1007 return it != frame.render_passes_by_id.end() ? it->second : NULL;
[email protected]94f206c12012-08-25 00:09:141008}
1009
[email protected]0cd7d6f72014-08-22 14:50:511010static void RemoveRenderPassesRecursive(RenderPassId remove_render_pass_id,
[email protected]c1bb5af2013-03-13 19:06:271011 LayerTreeHostImpl::FrameData* frame) {
1012 RenderPass* remove_render_pass =
1013 FindRenderPassById(remove_render_pass_id, *frame);
1014 // The pass was already removed by another quad - probably the original, and
1015 // we are the replica.
1016 if (!remove_render_pass)
1017 return;
1018 RenderPassList& render_passes = frame->render_passes;
1019 RenderPassList::iterator to_remove = std::find(render_passes.begin(),
1020 render_passes.end(),
1021 remove_render_pass);
[email protected]94f206c12012-08-25 00:09:141022
[email protected]c1bb5af2013-03-13 19:06:271023 DCHECK(to_remove != render_passes.end());
[email protected]94f206c12012-08-25 00:09:141024
[email protected]c1bb5af2013-03-13 19:06:271025 scoped_ptr<RenderPass> removed_pass = render_passes.take(to_remove);
1026 frame->render_passes.erase(to_remove);
1027 frame->render_passes_by_id.erase(remove_render_pass_id);
[email protected]94f206c12012-08-25 00:09:141028
[email protected]c1bb5af2013-03-13 19:06:271029 // Now follow up for all RenderPass quads and remove their RenderPasses
1030 // recursively.
1031 const QuadList& quad_list = removed_pass->quad_list;
[email protected]ed511b8d2013-03-25 03:29:291032 QuadList::ConstBackToFrontIterator quad_list_iterator =
1033 quad_list.BackToFrontBegin();
1034 for (; quad_list_iterator != quad_list.BackToFrontEnd();
[email protected]c1bb5af2013-03-13 19:06:271035 ++quad_list_iterator) {
weiliangc032e929d2014-09-26 01:55:011036 const DrawQuad* current_quad = &*quad_list_iterator;
[email protected]c1bb5af2013-03-13 19:06:271037 if (current_quad->material != DrawQuad::RENDER_PASS)
1038 continue;
[email protected]94f206c12012-08-25 00:09:141039
[email protected]0cd7d6f72014-08-22 14:50:511040 RenderPassId next_remove_render_pass_id =
[email protected]c1bb5af2013-03-13 19:06:271041 RenderPassDrawQuad::MaterialCast(current_quad)->render_pass_id;
1042 RemoveRenderPassesRecursive(next_remove_render_pass_id, frame);
1043 }
[email protected]94f206c12012-08-25 00:09:141044}
1045
[email protected]c1bb5af2013-03-13 19:06:271046bool LayerTreeHostImpl::CullRenderPassesWithNoQuads::ShouldRemoveRenderPass(
1047 const RenderPassDrawQuad& quad, const FrameData& frame) const {
1048 const RenderPass* render_pass =
1049 FindRenderPassById(quad.render_pass_id, frame);
1050 if (!render_pass)
1051 return false;
[email protected]94f206c12012-08-25 00:09:141052
[email protected]c1bb5af2013-03-13 19:06:271053 // If any quad or RenderPass draws into this RenderPass, then keep it.
1054 const QuadList& quad_list = render_pass->quad_list;
[email protected]ed511b8d2013-03-25 03:29:291055 for (QuadList::ConstBackToFrontIterator quad_list_iterator =
1056 quad_list.BackToFrontBegin();
1057 quad_list_iterator != quad_list.BackToFrontEnd();
[email protected]c1bb5af2013-03-13 19:06:271058 ++quad_list_iterator) {
weiliangc032e929d2014-09-26 01:55:011059 const DrawQuad* current_quad = &*quad_list_iterator;
[email protected]94f206c12012-08-25 00:09:141060
[email protected]c1bb5af2013-03-13 19:06:271061 if (current_quad->material != DrawQuad::RENDER_PASS)
1062 return false;
[email protected]94f206c12012-08-25 00:09:141063
[email protected]c1bb5af2013-03-13 19:06:271064 const RenderPass* contributing_pass = FindRenderPassById(
1065 RenderPassDrawQuad::MaterialCast(current_quad)->render_pass_id, frame);
1066 if (contributing_pass)
1067 return false;
1068 }
1069 return true;
[email protected]94f206c12012-08-25 00:09:141070}
1071
1072// Defined for linking tests.
[email protected]c1bb5af2013-03-13 19:06:271073template CC_EXPORT void LayerTreeHostImpl::RemoveRenderPasses<
[email protected]c1bb5af2013-03-13 19:06:271074 LayerTreeHostImpl::CullRenderPassesWithNoQuads>(
1075 CullRenderPassesWithNoQuads culler, FrameData*);
[email protected]94f206c12012-08-25 00:09:141076
1077// static
[email protected]c1bb5af2013-03-13 19:06:271078template <typename RenderPassCuller>
1079void LayerTreeHostImpl::RemoveRenderPasses(RenderPassCuller culler,
1080 FrameData* frame) {
1081 for (size_t it = culler.RenderPassListBegin(frame->render_passes);
1082 it != culler.RenderPassListEnd(frame->render_passes);
1083 it = culler.RenderPassListNext(it)) {
1084 const RenderPass* current_pass = frame->render_passes[it];
1085 const QuadList& quad_list = current_pass->quad_list;
[email protected]ed511b8d2013-03-25 03:29:291086 QuadList::ConstBackToFrontIterator quad_list_iterator =
1087 quad_list.BackToFrontBegin();
[email protected]94f206c12012-08-25 00:09:141088
[email protected]ed511b8d2013-03-25 03:29:291089 for (; quad_list_iterator != quad_list.BackToFrontEnd();
[email protected]c1bb5af2013-03-13 19:06:271090 ++quad_list_iterator) {
weiliangc032e929d2014-09-26 01:55:011091 const DrawQuad* current_quad = &*quad_list_iterator;
[email protected]94f206c12012-08-25 00:09:141092
[email protected]c1bb5af2013-03-13 19:06:271093 if (current_quad->material != DrawQuad::RENDER_PASS)
1094 continue;
[email protected]94f206c12012-08-25 00:09:141095
[email protected]c1bb5af2013-03-13 19:06:271096 const RenderPassDrawQuad* render_pass_quad =
1097 RenderPassDrawQuad::MaterialCast(current_quad);
1098 if (!culler.ShouldRemoveRenderPass(*render_pass_quad, *frame))
1099 continue;
[email protected]94f206c12012-08-25 00:09:141100
[email protected]c1bb5af2013-03-13 19:06:271101 // We are changing the vector in the middle of iteration. Because we
1102 // delete render passes that draw into the current pass, we are
1103 // guaranteed that any data from the iterator to the end will not
1104 // change. So, capture the iterator position from the end of the
1105 // list, and restore it after the change.
1106 size_t position_from_end = frame->render_passes.size() - it;
1107 RemoveRenderPassesRecursive(render_pass_quad->render_pass_id, frame);
1108 it = frame->render_passes.size() - position_from_end;
1109 DCHECK_GE(frame->render_passes.size(), position_from_end);
[email protected]94f206c12012-08-25 00:09:141110 }
[email protected]c1bb5af2013-03-13 19:06:271111 }
[email protected]94f206c12012-08-25 00:09:141112}
1113
[email protected]2aae96792014-05-15 23:10:501114DrawResult LayerTreeHostImpl::PrepareToDraw(FrameData* frame) {
[email protected]7a52f43e2013-07-10 01:58:471115 TRACE_EVENT1("cc",
1116 "LayerTreeHostImpl::PrepareToDraw",
1117 "SourceFrameNumber",
1118 active_tree_->source_frame_number());
[email protected]94f206c12012-08-25 00:09:141119
[email protected]425e5332013-09-21 04:10:031120 if (need_to_update_visible_tiles_before_draw_ &&
1121 tile_manager_ && tile_manager_->UpdateVisibleTiles()) {
1122 DidInitializeVisibleTile();
[email protected]39643fb2013-07-09 17:28:191123 }
[email protected]425e5332013-09-21 04:10:031124 need_to_update_visible_tiles_before_draw_ = true;
[email protected]39643fb2013-07-09 17:28:191125
[email protected]aebf4622014-07-14 16:57:591126 UMA_HISTOGRAM_CUSTOM_COUNTS(
1127 "Compositing.NumActiveLayers", active_tree_->NumLayers(), 1, 400, 20);
1128
[email protected]8f7f298822014-06-13 00:23:321129 bool ok = active_tree_->UpdateDrawProperties();
1130 DCHECK(ok) << "UpdateDrawProperties failed during draw";
[email protected]2e7ca422012-12-20 02:57:271131
[email protected]c1bb5af2013-03-13 19:06:271132 frame->render_surface_layer_list = &active_tree_->RenderSurfaceLayerList();
1133 frame->render_passes.clear();
1134 frame->render_passes_by_id.clear();
1135 frame->will_draw_layers.clear();
[email protected]e0341352013-04-06 05:01:201136 frame->contains_incomplete_tile = false;
1137 frame->has_no_damage = false;
1138
1139 if (active_tree_->root_layer()) {
[email protected]2aae96792014-05-15 23:10:501140 gfx::Rect device_viewport_damage_rect = viewport_damage_rect_;
[email protected]878705be2013-04-15 22:44:021141 viewport_damage_rect_ = gfx::Rect();
[email protected]e0341352013-04-06 05:01:201142
1143 active_tree_->root_layer()->render_surface()->damage_tracker()->
1144 AddDamageNextUpdate(device_viewport_damage_rect);
1145 }
[email protected]94f206c12012-08-25 00:09:141146
[email protected]30d82142014-05-12 04:26:021147 DrawResult draw_result = CalculateRenderPasses(frame);
1148 if (draw_result != DRAW_SUCCESS) {
[email protected]6133cc232013-07-30 18:47:071149 DCHECK(!output_surface_->capabilities()
1150 .draw_and_swap_full_viewport_every_frame);
[email protected]7ddfe7e82014-01-30 07:22:111151 return draw_result;
[email protected]6133cc232013-07-30 18:47:071152 }
[email protected]94f206c12012-08-25 00:09:141153
[email protected]7ddfe7e82014-01-30 07:22:111154 // If we return DRAW_SUCCESS, then we expect DrawLayers() to be called before
1155 // this function is called again.
1156 return draw_result;
[email protected]94f206c12012-08-25 00:09:141157}
1158
[email protected]0309ba5e02013-06-26 04:11:081159void LayerTreeHostImpl::EvictTexturesForTesting() {
1160 EnforceManagedMemoryPolicy(ManagedMemoryPolicy(0));
1161}
1162
[email protected]4f48f6e2013-08-27 06:33:381163void LayerTreeHostImpl::BlockNotifyReadyToActivateForTesting(bool block) {
1164 NOTREACHED();
1165}
1166
[email protected]425e5332013-09-21 04:10:031167void LayerTreeHostImpl::DidInitializeVisibleTileForTesting() {
[email protected]cfa7fd922014-04-29 11:50:031168 // Add arbitrary damage, to trigger prepare-to-draws.
1169 // Here, setting damage as viewport size, used only for testing.
1170 SetFullRootLayerDamage();
[email protected]425e5332013-09-21 04:10:031171 DidInitializeVisibleTile();
1172}
1173
[email protected]34bff2122014-05-16 04:09:341174void LayerTreeHostImpl::ResetTreesForTesting() {
1175 if (active_tree_)
1176 active_tree_->DetachLayerTree();
1177 active_tree_ = LayerTreeImpl::create(this);
1178 if (pending_tree_)
1179 pending_tree_->DetachLayerTree();
danakjf446a072014-09-27 21:55:481180 pending_tree_ = nullptr;
[email protected]34bff2122014-05-16 04:09:341181 if (recycle_tree_)
1182 recycle_tree_->DetachLayerTree();
danakjf446a072014-09-27 21:55:481183 recycle_tree_ = nullptr;
[email protected]34bff2122014-05-16 04:09:341184}
1185
vmpstr7fceb772014-08-26 18:51:521186void LayerTreeHostImpl::ResetRecycleTreeForTesting() {
1187 if (recycle_tree_)
1188 recycle_tree_->DetachLayerTree();
danakjf446a072014-09-27 21:55:481189 recycle_tree_ = nullptr;
vmpstr7fceb772014-08-26 18:51:521190}
1191
[email protected]c1bb5af2013-03-13 19:06:271192void LayerTreeHostImpl::EnforceManagedMemoryPolicy(
1193 const ManagedMemoryPolicy& policy) {
[email protected]206a3922013-05-17 06:34:121194
[email protected]c1bb5af2013-03-13 19:06:271195 bool evicted_resources = client_->ReduceContentsTextureMemoryOnImplThread(
[email protected]0b8ef2842013-11-01 09:53:351196 visible_ ? policy.bytes_limit_when_visible : 0,
[email protected]46b8acc2013-03-19 22:38:351197 ManagedMemoryPolicy::PriorityCutoffToValue(
1198 visible_ ? policy.priority_cutoff_when_visible
[email protected]0b8ef2842013-11-01 09:53:351199 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING));
[email protected]c1bb5af2013-03-13 19:06:271200 if (evicted_resources) {
1201 active_tree_->SetContentsTexturesPurged();
1202 if (pending_tree_)
1203 pending_tree_->SetContentsTexturesPurged();
1204 client_->SetNeedsCommitOnImplThread();
1205 client_->OnCanDrawStateChanged(CanDraw());
1206 client_->RenewTreePriority();
1207 }
[email protected]8947cbe2012-11-28 05:27:431208
[email protected]8be1a9bf2013-05-01 03:45:191209 UpdateTileManagerMemoryPolicy(policy);
1210}
1211
1212void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy(
1213 const ManagedMemoryPolicy& policy) {
1214 if (!tile_manager_)
1215 return;
1216
[email protected]25489c02014-02-13 23:18:411217 global_tile_state_.hard_memory_limit_in_bytes = 0;
1218 global_tile_state_.soft_memory_limit_in_bytes = 0;
1219 if (visible_ && policy.bytes_limit_when_visible > 0) {
1220 global_tile_state_.hard_memory_limit_in_bytes =
1221 policy.bytes_limit_when_visible;
1222 global_tile_state_.soft_memory_limit_in_bytes =
[email protected]831414e2014-02-22 02:27:371223 (static_cast<int64>(global_tile_state_.hard_memory_limit_in_bytes) *
1224 settings_.max_memory_for_prepaint_percentage) /
1225 100;
[email protected]25489c02014-02-13 23:18:411226 }
[email protected]1bcced22013-09-24 13:51:191227 global_tile_state_.memory_limit_policy =
[email protected]8be1a9bf2013-05-01 03:45:191228 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy(
1229 visible_ ?
1230 policy.priority_cutoff_when_visible :
[email protected]0b8ef2842013-11-01 09:53:351231 gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING);
[email protected]1bcced22013-09-24 13:51:191232 global_tile_state_.num_resources_limit = policy.num_resources_limit;
[email protected]c48536a52013-09-14 00:02:081233
[email protected]b7635e02014-04-28 07:08:431234 // TODO(reveman): We should avoid keeping around unused resources if
1235 // possible. crbug.com/224475
1236 // Unused limit is calculated from soft-limit, as hard-limit may
1237 // be very high and shouldn't typically be exceeded.
1238 size_t unused_memory_limit_in_bytes = static_cast<size_t>(
1239 (static_cast<int64>(global_tile_state_.soft_memory_limit_in_bytes) *
1240 settings_.max_unused_resource_memory_percentage) /
1241 100);
1242
[email protected]eece11e2014-04-12 03:07:161243 DCHECK(resource_pool_);
1244 resource_pool_->CheckBusyResources();
1245 // Soft limit is used for resource pool such that memory returns to soft
1246 // limit after going over.
1247 resource_pool_->SetResourceUsageLimits(
1248 global_tile_state_.soft_memory_limit_in_bytes,
[email protected]b7635e02014-04-28 07:08:431249 unused_memory_limit_in_bytes,
[email protected]eece11e2014-04-12 03:07:161250 global_tile_state_.num_resources_limit);
1251
revemanc84602a02014-09-24 15:41:251252 // Release all staging resources when invisible.
[email protected]2cccfef2014-05-01 06:05:161253 if (staging_resource_pool_) {
1254 staging_resource_pool_->CheckBusyResources();
1255 staging_resource_pool_->SetResourceUsageLimits(
revemanc84602a02014-09-24 15:41:251256 std::numeric_limits<size_t>::max(),
1257 std::numeric_limits<size_t>::max(),
1258 visible_ ? GetMaxStagingResourceCount() : 0);
[email protected]2cccfef2014-05-01 06:05:161259 }
1260
[email protected]c48536a52013-09-14 00:02:081261 DidModifyTilePriorities();
1262}
1263
1264void LayerTreeHostImpl::DidModifyTilePriorities() {
1265 DCHECK(settings_.impl_side_painting);
1266 // Mark priorities as dirty and schedule a ManageTiles().
1267 tile_priorities_dirty_ = true;
1268 client_->SetNeedsManageTilesOnImplThread();
[email protected]94f206c12012-08-25 00:09:141269}
1270
[email protected]86126792013-03-16 20:07:541271void LayerTreeHostImpl::DidInitializeVisibleTile() {
[email protected]425e5332013-09-21 04:10:031272 if (client_ && !client_->IsInsideDraw())
[email protected]86126792013-03-16 20:07:541273 client_->DidInitializeVisibleTileOnImplThread();
[email protected]74d9063c2013-01-18 03:14:471274}
1275
[email protected]bf050582014-07-24 11:10:581276void LayerTreeHostImpl::GetPictureLayerImplPairs(
1277 std::vector<PictureLayerImpl::Pair>* layer_pairs) const {
1278 DCHECK(layer_pairs->empty());
1279 for (std::vector<PictureLayerImpl*>::const_iterator it =
1280 picture_layers_.begin();
1281 it != picture_layers_.end();
1282 ++it) {
1283 PictureLayerImpl* layer = *it;
1284
1285 // TODO(vmpstr): Iterators and should handle this instead. crbug.com/381704
1286 if (!layer->HasValidTilePriorities())
1287 continue;
1288
1289 PictureLayerImpl* twin_layer = layer->GetTwinLayer();
1290
1291 // Ignore the twin layer when tile priorities are invalid.
1292 // TODO(vmpstr): Iterators should handle this instead. crbug.com/381704
1293 if (twin_layer && !twin_layer->HasValidTilePriorities())
1294 twin_layer = NULL;
1295
1296 // If the current tree is ACTIVE_TREE, then always generate a layer_pair.
1297 // If current tree is PENDING_TREE, then only generate a layer_pair if
1298 // there is no twin layer.
1299 if (layer->GetTree() == ACTIVE_TREE) {
1300 DCHECK(!twin_layer || twin_layer->GetTree() == PENDING_TREE);
1301 layer_pairs->push_back(PictureLayerImpl::Pair(layer, twin_layer));
1302 } else if (!twin_layer) {
1303 layer_pairs->push_back(PictureLayerImpl::Pair(NULL, layer));
1304 }
1305 }
1306}
1307
1308void LayerTreeHostImpl::BuildRasterQueue(RasterTilePriorityQueue* queue,
1309 TreePriority tree_priority) {
vmpstrd554d082014-10-15 18:11:251310 TRACE_EVENT0("cc", "LayerTreeHostImpl::BuildRasterQueue");
[email protected]bf050582014-07-24 11:10:581311 picture_layer_pairs_.clear();
1312 GetPictureLayerImplPairs(&picture_layer_pairs_);
1313 queue->Build(picture_layer_pairs_, tree_priority);
1314}
1315
1316void LayerTreeHostImpl::BuildEvictionQueue(EvictionTilePriorityQueue* queue,
1317 TreePriority tree_priority) {
vmpstrd554d082014-10-15 18:11:251318 TRACE_EVENT0("cc", "LayerTreeHostImpl::BuildEvictionQueue");
[email protected]bf050582014-07-24 11:10:581319 picture_layer_pairs_.clear();
1320 GetPictureLayerImplPairs(&picture_layer_pairs_);
1321 queue->Build(picture_layer_pairs_, tree_priority);
1322}
1323
1324const std::vector<PictureLayerImpl*>& LayerTreeHostImpl::GetPictureLayers()
1325 const {
[email protected]8aa39ecb2014-06-12 14:19:141326 return picture_layers_;
1327}
1328
[email protected]94bf75c2013-06-12 13:20:041329void LayerTreeHostImpl::NotifyReadyToActivate() {
[email protected]4f48f6e2013-08-27 06:33:381330 client_->NotifyReadyToActivate();
[email protected]94bf75c2013-06-12 13:20:041331}
1332
[email protected]8f802b22014-05-27 21:28:121333void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) {
1334 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged");
[email protected]cfa7fd922014-04-29 11:50:031335
[email protected]90af23b2014-04-30 07:00:341336 if (active_tree_) {
1337 LayerImpl* layer_impl =
1338 active_tree_->FindActiveTreeLayerById(tile->layer_id());
1339 if (layer_impl)
[email protected]8f802b22014-05-27 21:28:121340 layer_impl->NotifyTileStateChanged(tile);
[email protected]90af23b2014-04-30 07:00:341341 }
1342
1343 if (pending_tree_) {
1344 LayerImpl* layer_impl =
1345 pending_tree_->FindPendingTreeLayerById(tile->layer_id());
1346 if (layer_impl)
[email protected]8f802b22014-05-27 21:28:121347 layer_impl->NotifyTileStateChanged(tile);
[email protected]cfa7fd922014-04-29 11:50:031348 }
1349}
1350
[email protected]3f2ff112013-08-03 02:41:071351void LayerTreeHostImpl::SetMemoryPolicy(const ManagedMemoryPolicy& policy) {
1352 SetManagedMemoryPolicy(policy, zero_budget_);
1353}
1354
[email protected]5f07afc2013-07-19 05:17:181355void LayerTreeHostImpl::SetTreeActivationCallback(
1356 const base::Closure& callback) {
1357 DCHECK(proxy_->IsImplThread());
1358 DCHECK(settings_.impl_side_painting || callback.is_null());
[email protected]2022c672013-07-23 19:55:261359 tree_activation_callback_ = callback;
[email protected]5f07afc2013-07-19 05:17:181360}
1361
[email protected]c1bb5af2013-03-13 19:06:271362void LayerTreeHostImpl::SetManagedMemoryPolicy(
[email protected]3f2ff112013-08-03 02:41:071363 const ManagedMemoryPolicy& policy, bool zero_budget) {
1364 if (cached_managed_memory_policy_ == policy && zero_budget_ == zero_budget)
[email protected]c1bb5af2013-03-13 19:06:271365 return;
[email protected]61de5812012-11-08 07:03:441366
[email protected]3f2ff112013-08-03 02:41:071367 ManagedMemoryPolicy old_policy = ActualManagedMemoryPolicy();
1368
1369 cached_managed_memory_policy_ = policy;
1370 zero_budget_ = zero_budget;
1371 ManagedMemoryPolicy actual_policy = ActualManagedMemoryPolicy();
1372
1373 if (old_policy == actual_policy)
1374 return;
1375
1376 if (!proxy_->HasImplThread()) {
1377 // In single-thread mode, this can be called on the main thread by
1378 // GLRenderer::OnMemoryAllocationChanged.
1379 DebugScopedSetImplThread impl_thread(proxy_);
1380 EnforceManagedMemoryPolicy(actual_policy);
1381 } else {
1382 DCHECK(proxy_->IsImplThread());
1383 EnforceManagedMemoryPolicy(actual_policy);
1384 }
[email protected]50644642013-06-20 13:58:551385
[email protected]d7626ffd2013-03-29 00:17:421386 // If there is already enough memory to draw everything imaginable and the
1387 // new memory limit does not change this, then do not re-commit. Don't bother
1388 // skipping commits if this is not visible (commits don't happen when not
1389 // visible, there will almost always be a commit when this becomes visible).
1390 bool needs_commit = true;
1391 if (visible() &&
[email protected]3f2ff112013-08-03 02:41:071392 actual_policy.bytes_limit_when_visible >= max_memory_needed_bytes_ &&
1393 old_policy.bytes_limit_when_visible >= max_memory_needed_bytes_ &&
1394 actual_policy.priority_cutoff_when_visible ==
1395 old_policy.priority_cutoff_when_visible) {
[email protected]d7626ffd2013-03-29 00:17:421396 needs_commit = false;
1397 }
1398
[email protected]d7626ffd2013-03-29 00:17:421399 if (needs_commit)
1400 client_->SetNeedsCommitOnImplThread();
[email protected]94f206c12012-08-25 00:09:141401}
1402
[email protected]f224cc92013-06-06 23:23:321403void LayerTreeHostImpl::SetExternalDrawConstraints(
1404 const gfx::Transform& transform,
[email protected]0023fc72014-01-10 20:05:061405 const gfx::Rect& viewport,
1406 const gfx::Rect& clip,
[email protected]bd5324592014-07-31 09:09:331407 const gfx::Rect& viewport_rect_for_tile_priority,
1408 const gfx::Transform& transform_for_tile_priority,
[email protected]c05dfbb2014-07-10 22:49:041409 bool resourceless_software_draw) {
[email protected]bd5324592014-07-31 09:09:331410 gfx::Rect viewport_rect_for_tile_priority_in_view_space;
1411 if (!resourceless_software_draw) {
1412 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization);
1413 if (transform_for_tile_priority.GetInverse(&screen_to_view)) {
1414 // Convert from screen space to view space.
1415 viewport_rect_for_tile_priority_in_view_space =
1416 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
1417 screen_to_view, viewport_rect_for_tile_priority));
1418 }
1419 }
1420
[email protected]c05dfbb2014-07-10 22:49:041421 if (external_transform_ != transform || external_viewport_ != viewport ||
[email protected]bd5324592014-07-31 09:09:331422 resourceless_software_draw_ != resourceless_software_draw ||
1423 viewport_rect_for_tile_priority_ !=
1424 viewport_rect_for_tile_priority_in_view_space) {
[email protected]ea12b5502014-06-24 21:37:361425 active_tree_->set_needs_update_draw_properties();
1426 }
1427
[email protected]f224cc92013-06-06 23:23:321428 external_transform_ = transform;
1429 external_viewport_ = viewport;
[email protected]54af03522013-09-05 00:43:281430 external_clip_ = clip;
[email protected]bd5324592014-07-31 09:09:331431 viewport_rect_for_tile_priority_ =
1432 viewport_rect_for_tile_priority_in_view_space;
[email protected]c05dfbb2014-07-10 22:49:041433 resourceless_software_draw_ = resourceless_software_draw;
[email protected]f224cc92013-06-06 23:23:321434}
1435
[email protected]0023fc72014-01-10 20:05:061436void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) {
[email protected]6be422b2013-12-08 06:47:311437 if (damage_rect.IsEmpty())
1438 return;
1439 NotifySwapPromiseMonitorsOfSetNeedsRedraw();
[email protected]1cd9f5552013-04-26 04:22:031440 client_->SetNeedsRedrawRectOnImplThread(damage_rect);
1441}
1442
[email protected]97e9ccd62014-04-12 01:07:151443void LayerTreeHostImpl::BeginFrame(const BeginFrameArgs& args) {
mithroc34fc0b12014-09-30 09:10:411444 CallOnBeginFrame(args);
[email protected]7ed47512013-03-26 22:28:451445}
1446
[email protected]4d7e46a2013-11-08 05:33:401447void LayerTreeHostImpl::DidSwapBuffers() {
1448 client_->DidSwapBuffersOnImplThread();
1449}
1450
[email protected]c14902662014-04-18 05:06:111451void LayerTreeHostImpl::DidSwapBuffersComplete() {
1452 client_->DidSwapBuffersCompleteOnImplThread();
[email protected]a7335e0b2013-09-18 09:34:511453}
1454
1455void LayerTreeHostImpl::ReclaimResources(const CompositorFrameAck* ack) {
[email protected]c1bb5af2013-03-13 19:06:271456 // TODO(piman): We may need to do some validation on this ack before
1457 // processing it.
[email protected]a7335e0b2013-09-18 09:34:511458 if (renderer_)
[email protected]36e5ff12013-06-11 12:19:291459 renderer_->ReceiveSwapBuffersAck(*ack);
[email protected]43b552672014-04-05 00:38:571460
1461 // In OOM, we now might be able to release more resources that were held
1462 // because they were exported.
1463 if (tile_manager_) {
[email protected]eece11e2014-04-12 03:07:161464 DCHECK(resource_pool_);
[email protected]43b552672014-04-05 00:38:571465
[email protected]eece11e2014-04-12 03:07:161466 resource_pool_->CheckBusyResources();
1467 resource_pool_->ReduceResourceUsage();
[email protected]43b552672014-04-05 00:38:571468 }
[email protected]e97908d2014-04-09 12:48:041469 // If we're not visible, we likely released resources, so we want to
1470 // aggressively flush here to make sure those DeleteTextures make it to the
1471 // GPU process to free up the memory.
[email protected]110fcc0e2014-07-16 15:52:471472 if (output_surface_->context_provider() && !visible_) {
1473 output_surface_->context_provider()->ContextGL()->ShallowFlushCHROMIUM();
1474 }
[email protected]a46f32932012-12-07 21:43:161475}
1476
[email protected]c1bb5af2013-03-13 19:06:271477void LayerTreeHostImpl::OnCanDrawStateChangedForTree() {
1478 client_->OnCanDrawStateChanged(CanDraw());
[email protected]3b31c6ac2012-12-06 21:27:291479}
1480
[email protected]c1bb5af2013-03-13 19:06:271481CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const {
1482 CompositorFrameMetadata metadata;
1483 metadata.device_scale_factor = device_scale_factor_;
1484 metadata.page_scale_factor = active_tree_->total_page_scale_factor();
[email protected]f3f611f2014-07-09 04:05:321485 metadata.scrollable_viewport_size = active_tree_->ScrollableViewportSize();
[email protected]c1bb5af2013-03-13 19:06:271486 metadata.root_layer_size = active_tree_->ScrollableSize();
1487 metadata.min_page_scale_factor = active_tree_->min_page_scale_factor();
1488 metadata.max_page_scale_factor = active_tree_->max_page_scale_factor();
1489 if (top_controls_manager_) {
1490 metadata.location_bar_offset =
bokan88eae012014-09-09 20:40:421491 gfx::Vector2dF(0.f, top_controls_manager_->ControlsTopOffset());
[email protected]c1bb5af2013-03-13 19:06:271492 metadata.location_bar_content_translation =
bokan88eae012014-09-09 20:40:421493 gfx::Vector2dF(0.f, top_controls_manager_->ContentTopOffset());
[email protected]c1bb5af2013-03-13 19:06:271494 }
[email protected]bf189f62012-12-18 03:42:111495
[email protected]ebb179b2014-07-16 17:54:411496 active_tree_->GetViewportSelection(&metadata.selection_start,
1497 &metadata.selection_end);
[email protected]19aec372014-07-01 19:08:491498
[email protected]adeda572014-01-31 00:49:471499 if (!InnerViewportScrollLayer())
[email protected]bf189f62012-12-18 03:42:111500 return metadata;
[email protected]c1bb5af2013-03-13 19:06:271501
miletusf57925d2014-10-01 19:38:131502 // TODO(miletus) : Change the metadata to hold ScrollOffset.
1503 metadata.root_scroll_offset = gfx::ScrollOffsetToVector2dF(
1504 active_tree_->TotalScrollOffset());
[email protected]c1bb5af2013-03-13 19:06:271505
1506 return metadata;
[email protected]bf189f62012-12-18 03:42:111507}
1508
[email protected]6f50b8fa2013-07-01 19:51:491509static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) {
1510 layer->DidBeginTracing();
1511}
[email protected]37349bc2013-06-04 01:31:521512
[email protected]2e316b272014-07-19 05:01:201513void LayerTreeHostImpl::DrawLayers(FrameData* frame,
1514 base::TimeTicks frame_begin_time) {
[email protected]c1e6cc062013-08-24 03:35:351515 TRACE_EVENT0("cc", "LayerTreeHostImpl::DrawLayers");
[email protected]c1bb5af2013-03-13 19:06:271516 DCHECK(CanDraw());
[email protected]e0341352013-04-06 05:01:201517
[email protected]3519b872013-07-30 07:17:501518 if (frame->has_no_damage) {
[email protected]87b180cc2014-02-06 21:19:191519 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoDamage", TRACE_EVENT_SCOPE_THREAD);
[email protected]6133cc232013-07-30 18:47:071520 DCHECK(!output_surface_->capabilities()
1521 .draw_and_swap_full_viewport_every_frame);
[email protected]e0341352013-04-06 05:01:201522 return;
[email protected]3519b872013-07-30 07:17:501523 }
[email protected]e0341352013-04-06 05:01:201524
[email protected]c1bb5af2013-03-13 19:06:271525 DCHECK(!frame->render_passes.empty());
[email protected]94f206c12012-08-25 00:09:141526
[email protected]2e316b272014-07-19 05:01:201527 fps_counter_->SaveTimeStamp(frame_begin_time,
[email protected]213fcfc2013-08-24 14:59:271528 !output_surface_->context_provider());
jbauman477b5002014-10-06 18:14:241529 rendering_stats_instrumentation_->IncrementFrameCount(1);
[email protected]372bad5f2013-03-21 16:38:431530
[email protected]c1bb5af2013-03-13 19:06:271531 if (tile_manager_) {
1532 memory_history_->SaveEntry(
1533 tile_manager_->memory_stats_from_last_assign());
1534 }
[email protected]1191d9d2013-02-02 06:00:331535
[email protected]846f455b2013-03-18 19:07:411536 if (debug_state_.ShowHudRects()) {
[email protected]d35992782013-03-14 14:54:021537 debug_rect_history_->SaveDebugRectsForCurrentFrame(
[email protected]c1bb5af2013-03-13 19:06:271538 active_tree_->root_layer(),
[email protected]f636ce82014-03-10 22:33:081539 active_tree_->hud_layer(),
[email protected]c1bb5af2013-03-13 19:06:271540 *frame->render_surface_layer_list,
1541 frame->occluding_screen_space_rects,
1542 frame->non_occluding_screen_space_rects,
1543 debug_state_);
1544 }
[email protected]94f206c12012-08-25 00:09:141545
[email protected]a848c102013-03-26 08:59:091546 if (!settings_.impl_side_painting && debug_state_.continuous_painting) {
1547 const RenderingStats& stats =
1548 rendering_stats_instrumentation_->GetRenderingStats();
[email protected]a9dc0d0f2013-08-17 02:43:181549 paint_time_counter_->SavePaintTime(stats.main_stats.paint_time);
[email protected]a848c102013-03-26 08:59:091550 }
1551
[email protected]37349bc2013-06-04 01:31:521552 bool is_new_trace;
1553 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace);
1554 if (is_new_trace) {
[email protected]6f50b8fa2013-07-01 19:51:491555 if (pending_tree_) {
1556 LayerTreeHostCommon::CallFunctionForSubtree(
1557 pending_tree_->root_layer(),
1558 base::Bind(&LayerTreeHostImplDidBeginTracingCallback));
1559 }
1560 LayerTreeHostCommon::CallFunctionForSubtree(
1561 active_tree_->root_layer(),
1562 base::Bind(&LayerTreeHostImplDidBeginTracingCallback));
[email protected]37349bc2013-06-04 01:31:521563 }
1564
[email protected]5b8da122014-06-25 20:00:081565 {
1566 TRACE_EVENT0("cc", "DrawLayers.FrameViewerTracing");
1567 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
1568 TRACE_DISABLED_BY_DEFAULT("cc.debug") ","
1569 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads") ","
1570 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.layers"),
1571 "cc::LayerTreeHostImpl",
1572 id_,
[email protected]d12aa932014-08-01 13:10:381573 AsValueWithFrame(frame));
[email protected]5b8da122014-06-25 20:00:081574 }
[email protected]131a0c22013-02-12 18:31:081575
[email protected]c05dfbb2014-07-10 22:49:041576 const DrawMode draw_mode = GetDrawMode();
1577
[email protected]c1bb5af2013-03-13 19:06:271578 // Because the contents of the HUD depend on everything else in the frame, the
1579 // contents of its texture are updated as the last thing before the frame is
1580 // drawn.
[email protected]671f6672013-10-01 07:31:071581 if (active_tree_->hud_layer()) {
1582 TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture");
[email protected]c05dfbb2014-07-10 22:49:041583 active_tree_->hud_layer()->UpdateHudTexture(draw_mode,
1584 resource_provider_.get());
[email protected]671f6672013-10-01 07:31:071585 }
[email protected]94f206c12012-08-25 00:09:141586
[email protected]c05dfbb2014-07-10 22:49:041587 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) {
[email protected]251699b2013-10-09 00:21:261588 bool disable_picture_quad_image_filtering =
1589 IsCurrentlyScrolling() || needs_animate_layers();
[email protected]573e8e32013-09-09 17:24:321590
[email protected]b09c1942013-05-10 00:06:371591 scoped_ptr<SoftwareRenderer> temp_software_renderer =
[email protected]573e8e32013-09-09 17:24:321592 SoftwareRenderer::Create(this, &settings_, output_surface_.get(), NULL);
[email protected]59fee302013-12-10 17:53:301593 temp_software_renderer->DrawFrame(&frame->render_passes,
[email protected]59fee302013-12-10 17:53:301594 device_scale_factor_,
1595 DeviceViewport(),
1596 DeviceClip(),
[email protected]59fee302013-12-10 17:53:301597 disable_picture_quad_image_filtering);
[email protected]b09c1942013-05-10 00:06:371598 } else {
[email protected]b5174d712013-08-28 08:10:431599 renderer_->DrawFrame(&frame->render_passes,
[email protected]573e8e32013-09-09 17:24:321600 device_scale_factor_,
[email protected]59fee302013-12-10 17:53:301601 DeviceViewport(),
1602 DeviceClip(),
[email protected]251699b2013-10-09 00:21:261603 false);
[email protected]b09c1942013-05-10 00:06:371604 }
[email protected]c1bb5af2013-03-13 19:06:271605 // The render passes should be consumed by the renderer.
1606 DCHECK(frame->render_passes.empty());
1607 frame->render_passes_by_id.clear();
[email protected]94f206c12012-08-25 00:09:141608
[email protected]c1bb5af2013-03-13 19:06:271609 // The next frame should start by assuming nothing has changed, and changes
1610 // are noted as they occur.
[email protected]573e8e32013-09-09 17:24:321611 // TODO(boliu): If we did a temporary software renderer frame, propogate the
1612 // damage forward to the next frame.
[email protected]264dc0332013-03-17 21:00:541613 for (size_t i = 0; i < frame->render_surface_layer_list->size(); i++) {
[email protected]c1bb5af2013-03-13 19:06:271614 (*frame->render_surface_layer_list)[i]->render_surface()->damage_tracker()->
1615 DidDrawDamagedArea();
1616 }
1617 active_tree_->root_layer()->ResetAllChangeTrackingForSubtree();
[email protected]c1e6cc062013-08-24 03:35:351618
[email protected]759dc9f2014-07-23 19:18:511619 active_tree_->set_has_ever_been_drawn(true);
[email protected]d73094482014-02-13 21:28:281620 devtools_instrumentation::DidDrawFrame(id_);
[email protected]1bbed7a2014-07-08 02:54:001621 benchmark_instrumentation::IssueImplThreadRenderingStatsEvent(
[email protected]adbe30f2013-10-11 21:12:331622 rendering_stats_instrumentation_->impl_thread_rendering_stats());
[email protected]a9dc0d0f2013-08-17 02:43:181623 rendering_stats_instrumentation_->AccumulateAndClearImplThreadStats();
[email protected]94f206c12012-08-25 00:09:141624}
1625
[email protected]c1bb5af2013-03-13 19:06:271626void LayerTreeHostImpl::DidDrawAllLayers(const FrameData& frame) {
1627 for (size_t i = 0; i < frame.will_draw_layers.size(); ++i)
1628 frame.will_draw_layers[i]->DidDraw(resource_provider_.get());
[email protected]b914e102012-10-02 08:11:521629
[email protected]c1bb5af2013-03-13 19:06:271630 // Once all layers have been drawn, pending texture uploads should no
1631 // longer block future uploads.
[email protected]d15d9622013-06-21 02:49:151632 resource_provider_->MarkPendingUploadsAsNonBlocking();
[email protected]94f206c12012-08-25 00:09:141633}
1634
[email protected]c1bb5af2013-03-13 19:06:271635void LayerTreeHostImpl::FinishAllRendering() {
1636 if (renderer_)
1637 renderer_->Finish();
[email protected]94f206c12012-08-25 00:09:141638}
1639
[email protected]13525d62014-05-20 21:22:041640void LayerTreeHostImpl::SetUseGpuRasterization(bool use_gpu) {
1641 if (use_gpu == use_gpu_rasterization_)
1642 return;
1643
1644 use_gpu_rasterization_ = use_gpu;
1645 ReleaseTreeResources();
1646
[email protected]ced667b2014-05-22 21:49:531647 // Replace existing tile manager with another one that uses appropriate
1648 // rasterizer.
1649 if (tile_manager_) {
1650 DestroyTileManager();
1651 CreateAndSetTileManager();
1652 }
1653
[email protected]13525d62014-05-20 21:22:041654 // We have released tilings for both active and pending tree.
1655 // We would not have any content to draw until the pending tree is activated.
1656 // Prevent the active tree from drawing until activation.
vmpstr61ed94a12014-10-09 04:49:301657 SetRequiresHighResToDraw();
[email protected]13525d62014-05-20 21:22:041658}
1659
[email protected]7a8bcd262014-01-15 12:54:581660const RendererCapabilitiesImpl&
1661LayerTreeHostImpl::GetRendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:271662 return renderer_->Capabilities();
[email protected]94f206c12012-08-25 00:09:141663}
1664
[email protected]e0341352013-04-06 05:01:201665bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) {
vmpstr61ed94a12014-10-09 04:49:301666 ResetRequiresHighResToDraw();
[email protected]b69c1db2013-11-27 00:05:191667 if (frame.has_no_damage) {
1668 active_tree()->BreakSwapPromises(SwapPromise::SWAP_FAILS);
[email protected]e0341352013-04-06 05:01:201669 return false;
[email protected]b69c1db2013-11-27 00:05:191670 }
[email protected]4a28a612013-11-27 02:06:331671 CompositorFrameMetadata metadata = MakeCompositorFrameMetadata();
[email protected]d359203a2013-11-29 06:16:551672 active_tree()->FinishSwapPromises(&metadata);
[email protected]15ba6dea2014-04-02 01:44:131673 for (size_t i = 0; i < metadata.latency_info.size(); i++) {
1674 TRACE_EVENT_FLOW_STEP0(
1675 "input",
1676 "LatencyInfo.Flow",
1677 TRACE_ID_DONT_MANGLE(metadata.latency_info[i].trace_id),
1678 "SwapBuffers");
1679 }
[email protected]4a28a612013-11-27 02:06:331680 renderer_->SwapBuffers(metadata);
[email protected]c5c506382013-04-30 04:42:161681 return true;
[email protected]94f206c12012-08-25 00:09:141682}
1683
mithroc34fc0b12014-09-30 09:10:411684void LayerTreeHostImpl::OnNeedsBeginFramesChange(bool enable) {
[email protected]7ed47512013-03-26 22:28:451685 if (output_surface_)
[email protected]97e9ccd62014-04-12 01:07:151686 output_surface_->SetNeedsBeginFrame(enable);
[email protected]3dc0c772014-04-26 10:06:051687 else
1688 DCHECK(!enable);
[email protected]97e9ccd62014-04-12 01:07:151689}
1690
1691void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) {
1692 // Sample the frame time now. This time will be used for updating animations
1693 // when we draw.
[email protected]04c5900d2014-08-18 13:38:361694 UpdateCurrentBeginFrameArgs(args);
[email protected]c92195e2014-05-07 18:18:491695 // Cache the begin impl frame interval
1696 begin_impl_frame_interval_ = args.interval;
[email protected]7ed47512013-03-26 22:28:451697}
1698
bokanef971462014-10-13 22:58:321699void LayerTreeHostImpl::UpdateViewportContainerSizes() {
1700 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer();
1701 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer();
1702
1703 if (!inner_container || !top_controls_manager_)
[email protected]fef74fd2014-02-27 06:28:171704 return;
1705
bokanef971462014-10-13 22:58:321706 ViewportAnchor anchor(InnerViewportScrollLayer(),
1707 OuterViewportScrollLayer());
1708
1709 // Adjust the inner viewport by shrinking/expanding the container to account
1710 // for the change in top controls height since the last Resize from Blink.
1711 inner_container->SetBoundsDelta(
1712 gfx::Vector2dF(0, active_tree_->top_controls_layout_height() -
1713 active_tree_->total_top_controls_content_offset()));
1714
1715 if (!outer_container || outer_container->BoundsForScrolling().IsEmpty())
1716 return;
1717
1718 // Adjust the outer viewport container as well, since adjusting only the
1719 // inner may cause its bounds to exceed those of the outer, causing scroll
1720 // clamping. We adjust it so it maintains the same aspect ratio as the
1721 // inner viewport.
1722 float aspect_ratio = inner_container->BoundsForScrolling().width() /
1723 inner_container->BoundsForScrolling().height();
1724 float target_height = outer_container->BoundsForScrolling().width() /
1725 aspect_ratio;
1726 float current_outer_height = outer_container->BoundsForScrolling().height() -
1727 outer_container->bounds_delta().y();
1728 gfx::Vector2dF delta(0, target_height - current_outer_height);
1729
1730 outer_container->SetBoundsDelta(delta);
1731 active_tree_->InnerViewportScrollLayer()->SetBoundsDelta(delta);
1732
1733 anchor.ResetViewportToAnchoredPosition();
bokan88eae012014-09-09 20:40:421734}
1735
1736void LayerTreeHostImpl::SetTopControlsLayoutHeight(float height) {
1737 if (active_tree_->top_controls_layout_height() == height)
1738 return;
1739
1740 active_tree_->set_top_controls_layout_height(height);
bokanef971462014-10-13 22:58:321741 UpdateViewportContainerSizes();
bokan88eae012014-09-09 20:40:421742 SetFullRootLayerDamage();
[email protected]ffb2720f2013-03-15 19:18:371743}
1744
[email protected]c1bb5af2013-03-13 19:06:271745void LayerTreeHostImpl::DidLoseOutputSurface() {
[email protected]13044fe72013-12-02 20:52:191746 if (resource_provider_)
1747 resource_provider_->DidLoseOutputSurface();
dnetob71e30c2014-08-25 23:27:201748 client_->DidLoseOutputSurfaceOnImplThread();
[email protected]94f206c12012-08-25 00:09:141749}
1750
[email protected]59adb112013-04-09 04:48:441751bool LayerTreeHostImpl::HaveRootScrollLayer() const {
[email protected]adeda572014-01-31 00:49:471752 return !!InnerViewportScrollLayer();
[email protected]69b50ec2013-01-19 04:58:011753}
1754
[email protected]c1bb5af2013-03-13 19:06:271755LayerImpl* LayerTreeHostImpl::RootLayer() const {
1756 return active_tree_->root_layer();
[email protected]8bef40572012-12-11 21:38:081757}
1758
[email protected]adeda572014-01-31 00:49:471759LayerImpl* LayerTreeHostImpl::InnerViewportScrollLayer() const {
1760 return active_tree_->InnerViewportScrollLayer();
1761}
1762
1763LayerImpl* LayerTreeHostImpl::OuterViewportScrollLayer() const {
1764 return active_tree_->OuterViewportScrollLayer();
[email protected]8bef40572012-12-11 21:38:081765}
1766
[email protected]c1bb5af2013-03-13 19:06:271767LayerImpl* LayerTreeHostImpl::CurrentlyScrollingLayer() const {
1768 return active_tree_->CurrentlyScrollingLayer();
[email protected]8bef40572012-12-11 21:38:081769}
1770
[email protected]251699b2013-10-09 00:21:261771bool LayerTreeHostImpl::IsCurrentlyScrolling() const {
1772 return CurrentlyScrollingLayer() ||
[email protected]adeda572014-01-31 00:49:471773 (InnerViewportScrollLayer() &&
1774 InnerViewportScrollLayer()->IsExternalFlingActive()) ||
1775 (OuterViewportScrollLayer() &&
1776 OuterViewportScrollLayer()->IsExternalFlingActive());
[email protected]251699b2013-10-09 00:21:261777}
1778
[email protected]94f206c12012-08-25 00:09:141779// Content layers can be either directly scrollable or contained in an outer
1780// scrolling layer which applies the scroll transform. Given a content layer,
1781// this function returns the associated scroll layer if any.
[email protected]c1bb5af2013-03-13 19:06:271782static LayerImpl* FindScrollLayerForContentLayer(LayerImpl* layer_impl) {
1783 if (!layer_impl)
[email protected]bf1cfd9a2013-09-26 05:43:021784 return NULL;
[email protected]c1bb5af2013-03-13 19:06:271785
1786 if (layer_impl->scrollable())
1787 return layer_impl;
1788
1789 if (layer_impl->DrawsContent() &&
1790 layer_impl->parent() &&
1791 layer_impl->parent()->scrollable())
1792 return layer_impl->parent();
1793
[email protected]bf1cfd9a2013-09-26 05:43:021794 return NULL;
[email protected]94f206c12012-08-25 00:09:141795}
1796
[email protected]c1bb5af2013-03-13 19:06:271797void LayerTreeHostImpl::CreatePendingTree() {
1798 CHECK(!pending_tree_);
1799 if (recycle_tree_)
1800 recycle_tree_.swap(pending_tree_);
1801 else
1802 pending_tree_ = LayerTreeImpl::create(this);
[email protected]12a63da2014-06-13 06:06:221803
1804 // Update the delta from the active tree, which may have
1805 // adjusted its delta prior to the pending tree being created.
1806 DCHECK_EQ(1.f, pending_tree_->sent_page_scale_delta());
bokan88eae012014-09-09 20:40:421807 DCHECK_EQ(0.f, pending_tree_->sent_top_controls_delta());
[email protected]12a63da2014-06-13 06:06:221808 pending_tree_->SetPageScaleDelta(active_tree_->page_scale_delta() /
1809 active_tree_->sent_page_scale_delta());
bokan88eae012014-09-09 20:40:421810 pending_tree_->set_top_controls_delta(
1811 active_tree_->top_controls_delta() -
1812 active_tree_->sent_top_controls_delta());
[email protected]12a63da2014-06-13 06:06:221813
[email protected]c1bb5af2013-03-13 19:06:271814 client_->OnCanDrawStateChanged(CanDraw());
[email protected]186468f2013-10-24 02:44:111815 TRACE_EVENT_ASYNC_BEGIN0("cc", "PendingTree:waiting", pending_tree_.get());
[email protected]2e7ca422012-12-20 02:57:271816}
1817
[email protected]8bb6cfa2013-07-23 00:11:191818void LayerTreeHostImpl::UpdateVisibleTiles() {
[email protected]8bb6cfa2013-07-23 00:11:191819 if (tile_manager_ && tile_manager_->UpdateVisibleTiles())
1820 DidInitializeVisibleTile();
[email protected]8bb6cfa2013-07-23 00:11:191821 need_to_update_visible_tiles_before_draw_ = false;
[email protected]eabe5002013-01-12 22:07:481822}
1823
[email protected]fc20d142014-07-01 00:49:151824void LayerTreeHostImpl::ActivateSyncTree() {
[email protected]4f48f6e2013-08-27 06:33:381825 need_to_update_visible_tiles_before_draw_ = true;
1826
[email protected]fc20d142014-07-01 00:49:151827 if (pending_tree_) {
1828 TRACE_EVENT_ASYNC_END0("cc", "PendingTree:waiting", pending_tree_.get());
1829
1830 active_tree_->SetRootLayerScrollOffsetDelegate(NULL);
1831 active_tree_->PushPersistedState(pending_tree_.get());
1832 // Process any requests in the UI resource queue. The request queue is
1833 // given in LayerTreeHost::FinishCommitOnImplThread. This must take place
1834 // before the swap.
1835 pending_tree_->ProcessUIResourceRequestQueue();
1836
1837 if (pending_tree_->needs_full_tree_sync()) {
1838 active_tree_->SetRootLayer(
1839 TreeSynchronizer::SynchronizeTrees(pending_tree_->root_layer(),
1840 active_tree_->DetachLayerTree(),
1841 active_tree_.get()));
1842 }
1843 TreeSynchronizer::PushProperties(pending_tree_->root_layer(),
1844 active_tree_->root_layer());
1845 pending_tree_->PushPropertiesTo(active_tree_.get());
1846
1847 // Now that we've synced everything from the pending tree to the active
1848 // tree, rename the pending tree the recycle tree so we can reuse it on the
1849 // next sync.
1850 DCHECK(!recycle_tree_);
1851 pending_tree_.swap(recycle_tree_);
1852
1853 active_tree_->SetRootLayerScrollOffsetDelegate(
1854 root_layer_scroll_offset_delegate_);
bokan88eae012014-09-09 20:40:421855
1856 if (top_controls_manager_) {
1857 top_controls_manager_->SetControlsTopOffset(
bokan55b2f152014-09-15 14:47:591858 active_tree_->total_top_controls_content_offset() -
1859 top_controls_manager_->top_controls_height());
bokan88eae012014-09-09 20:40:421860 }
1861
bokanef971462014-10-13 22:58:321862 UpdateViewportContainerSizes();
[email protected]fc20d142014-07-01 00:49:151863 } else {
1864 active_tree_->ProcessUIResourceRequestQueue();
[email protected]c1bb5af2013-03-13 19:06:271865 }
[email protected]48871fc2013-01-23 07:36:511866
[email protected]7d1b07e2013-10-01 17:31:301867 active_tree_->DidBecomeActive();
[email protected]b33348f2014-04-30 18:17:341868 ActivateAnimations();
[email protected]fc20d142014-07-01 00:49:151869 if (settings_.impl_side_painting)
1870 client_->RenewTreePriority();
[email protected]37386f052013-01-13 00:42:221871
[email protected]c1bb5af2013-03-13 19:06:271872 client_->OnCanDrawStateChanged(CanDraw());
[email protected]fc20d142014-07-01 00:49:151873 client_->DidActivateSyncTree();
1874 if (!tree_activation_callback_.is_null())
1875 tree_activation_callback_.Run();
[email protected]652cf132013-02-15 21:53:241876
[email protected]a848c102013-03-26 08:59:091877 if (debug_state_.continuous_painting) {
1878 const RenderingStats& stats =
[email protected]372bad5f2013-03-21 16:38:431879 rendering_stats_instrumentation_->GetRenderingStats();
[email protected]922c6e1f2013-10-09 04:04:091880 paint_time_counter_->SavePaintTime(stats.main_stats.paint_time +
1881 stats.main_stats.record_time +
1882 stats.impl_stats.rasterize_time);
[email protected]c1bb5af2013-03-13 19:06:271883 }
[email protected]2a61ad52013-05-13 14:01:291884
[email protected]d9fce6722013-08-30 01:10:011885 if (time_source_client_adapter_ && time_source_client_adapter_->Active())
1886 DCHECK(active_tree_->root_layer());
bokan915bf352014-10-02 21:57:141887
aelias74c39352014-10-14 03:48:141888 scoped_ptr<PageScaleAnimation> page_scale_animation =
1889 active_tree_->TakePageScaleAnimation();
1890 if (page_scale_animation) {
1891 page_scale_animation_ = page_scale_animation.Pass();
bokan915bf352014-10-02 21:57:141892 SetNeedsAnimate();
1893 client_->SetNeedsCommitOnImplThread();
1894 client_->RenewTreePriority();
1895 }
[email protected]2e7ca422012-12-20 02:57:271896}
1897
[email protected]c1bb5af2013-03-13 19:06:271898void LayerTreeHostImpl::SetVisible(bool visible) {
1899 DCHECK(proxy_->IsImplThread());
[email protected]94f206c12012-08-25 00:09:141900
[email protected]c1bb5af2013-03-13 19:06:271901 if (visible_ == visible)
1902 return;
1903 visible_ = visible;
1904 DidVisibilityChange(this, visible_);
[email protected]206a3922013-05-17 06:34:121905 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy());
[email protected]94f206c12012-08-25 00:09:141906
[email protected]10608052014-05-13 21:30:031907 // If we just became visible, we have to ensure that we draw high res tiles,
1908 // to prevent checkerboard/low res flashes.
1909 if (visible_)
vmpstr61ed94a12014-10-09 04:49:301910 SetRequiresHighResToDraw();
[email protected]10608052014-05-13 21:30:031911 else
[email protected]127bdc1a2013-09-11 01:44:481912 EvictAllUIResources();
1913
[email protected]0fa42e02013-08-20 01:16:051914 // Evict tiles immediately if invisible since this tab may never get another
1915 // draw or timer tick.
1916 if (!visible_)
1917 ManageTiles();
1918
[email protected]c1bb5af2013-03-13 19:06:271919 if (!renderer_)
1920 return;
[email protected]94f206c12012-08-25 00:09:141921
[email protected]c1bb5af2013-03-13 19:06:271922 renderer_->SetVisible(visible);
[email protected]94f206c12012-08-25 00:09:141923}
1924
[email protected]43b8f982014-04-30 21:24:331925void LayerTreeHostImpl::SetNeedsAnimate() {
1926 NotifySwapPromiseMonitorsOfSetNeedsRedraw();
1927 client_->SetNeedsAnimateOnImplThread();
1928}
1929
[email protected]6be422b2013-12-08 06:47:311930void LayerTreeHostImpl::SetNeedsRedraw() {
1931 NotifySwapPromiseMonitorsOfSetNeedsRedraw();
1932 client_->SetNeedsRedrawOnImplThread();
1933}
1934
[email protected]206a3922013-05-17 06:34:121935ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const {
[email protected]3f2ff112013-08-03 02:41:071936 ManagedMemoryPolicy actual = cached_managed_memory_policy_;
[email protected]c92195e2014-05-07 18:18:491937 if (debug_state_.rasterize_only_visible_content) {
[email protected]3f2ff112013-08-03 02:41:071938 actual.priority_cutoff_when_visible =
[email protected]f44d5552013-10-29 04:56:291939 gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY;
[email protected]13525d62014-05-20 21:22:041940 } else if (use_gpu_rasterization()) {
[email protected]c92195e2014-05-07 18:18:491941 actual.priority_cutoff_when_visible =
1942 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE;
[email protected]3f2ff112013-08-03 02:41:071943 }
[email protected]206a3922013-05-17 06:34:121944
[email protected]3f2ff112013-08-03 02:41:071945 if (zero_budget_) {
1946 actual.bytes_limit_when_visible = 0;
[email protected]3f2ff112013-08-03 02:41:071947 }
1948
[email protected]206a3922013-05-17 06:34:121949 return actual;
1950}
1951
[email protected]3f2ff112013-08-03 02:41:071952size_t LayerTreeHostImpl::memory_allocation_limit_bytes() const {
1953 return ActualManagedMemoryPolicy().bytes_limit_when_visible;
1954}
1955
[email protected]990e050a2013-09-23 18:50:211956int LayerTreeHostImpl::memory_allocation_priority_cutoff() const {
1957 return ManagedMemoryPolicy::PriorityCutoffToValue(
1958 ActualManagedMemoryPolicy().priority_cutoff_when_visible);
1959}
1960
[email protected]50644642013-06-20 13:58:551961void LayerTreeHostImpl::ReleaseTreeResources() {
[email protected]aeef2f02014-05-10 12:15:481962 active_tree_->ReleaseResources();
1963 if (pending_tree_)
1964 pending_tree_->ReleaseResources();
1965 if (recycle_tree_)
1966 recycle_tree_->ReleaseResources();
[email protected]c9280762013-08-01 06:28:571967
[email protected]127bdc1a2013-09-11 01:44:481968 EvictAllUIResources();
[email protected]50644642013-06-20 13:58:551969}
1970
[email protected]ced667b2014-05-22 21:49:531971void LayerTreeHostImpl::CreateAndSetRenderer() {
[email protected]50644642013-06-20 13:58:551972 DCHECK(!renderer_);
[email protected]ced667b2014-05-22 21:49:531973 DCHECK(output_surface_);
1974 DCHECK(resource_provider_);
1975
1976 if (output_surface_->capabilities().delegated_rendering) {
[email protected]573e8e32013-09-09 17:24:321977 renderer_ = DelegatingRenderer::Create(
[email protected]ced667b2014-05-22 21:49:531978 this, &settings_, output_surface_.get(), resource_provider_.get());
1979 } else if (output_surface_->context_provider()) {
[email protected]50644642013-06-20 13:58:551980 renderer_ = GLRenderer::Create(this,
[email protected]573e8e32013-09-09 17:24:321981 &settings_,
[email protected]ced667b2014-05-22 21:49:531982 output_surface_.get(),
1983 resource_provider_.get(),
[email protected]ea468c6c2013-09-10 08:25:111984 texture_mailbox_deleter_.get(),
[email protected]2eeea2b32013-12-06 21:29:241985 settings_.highp_threshold_min);
[email protected]ced667b2014-05-22 21:49:531986 } else if (output_surface_->software_device()) {
[email protected]573e8e32013-09-09 17:24:321987 renderer_ = SoftwareRenderer::Create(
[email protected]ced667b2014-05-22 21:49:531988 this, &settings_, output_surface_.get(), resource_provider_.get());
[email protected]50644642013-06-20 13:58:551989 }
[email protected]0cfda302014-04-23 19:02:371990 DCHECK(renderer_);
[email protected]50644642013-06-20 13:58:551991
[email protected]0cfda302014-04-23 19:02:371992 renderer_->SetVisible(visible_);
1993 SetFullRootLayerDamage();
[email protected]b0a99ad22013-09-12 17:25:561994
[email protected]0cfda302014-04-23 19:02:371995 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be
1996 // initialized to get max texture size. Also, after releasing resources,
1997 // trees need another update to generate new ones.
1998 active_tree_->set_needs_update_draw_properties();
1999 if (pending_tree_)
2000 pending_tree_->set_needs_update_draw_properties();
2001 client_->UpdateRendererCapabilitiesOnImplThread();
[email protected]50644642013-06-20 13:58:552002}
2003
[email protected]ced667b2014-05-22 21:49:532004void LayerTreeHostImpl::CreateAndSetTileManager() {
2005 DCHECK(!tile_manager_);
[email protected]50af3c22013-07-13 03:50:202006 DCHECK(settings_.impl_side_painting);
[email protected]ced667b2014-05-22 21:49:532007 DCHECK(output_surface_);
2008 DCHECK(resource_provider_);
enne98f3a6c2014-10-09 20:09:442009 base::SingleThreadTaskRunner* task_runner =
2010 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner()
2011 : proxy_->MainThreadTaskRunner();
2012 DCHECK(task_runner);
[email protected]ec7541d2014-04-09 01:23:532013
[email protected]ced667b2014-05-22 21:49:532014 ContextProvider* context_provider = output_surface_->context_provider();
reveman5ae838bb2014-09-24 23:30:142015 if (!context_provider) {
2016 resource_pool_ =
2017 ResourcePool::Create(resource_provider_.get(),
2018 GL_TEXTURE_2D,
2019 resource_provider_->best_texture_format());
2020
2021 raster_worker_pool_ =
2022 BitmapRasterWorkerPool::Create(proxy_->ImplThreadTaskRunner(),
2023 RasterWorkerPool::GetTaskGraphRunner(),
2024 resource_provider_.get());
2025 } else if (use_gpu_rasterization_) {
[email protected]eece11e2014-04-12 03:07:162026 resource_pool_ =
[email protected]ced667b2014-05-22 21:49:532027 ResourcePool::Create(resource_provider_.get(),
2028 GL_TEXTURE_2D,
2029 resource_provider_->best_texture_format());
2030
hendrikw6a15e252014-10-22 02:46:242031 raster_worker_pool_ =
2032 GpuRasterWorkerPool::Create(task_runner,
2033 context_provider,
2034 resource_provider_.get(),
2035 settings_.use_distance_field_text);
reveman5ae838bb2014-09-24 23:30:142036 } else if (UseZeroCopyRasterizer()) {
2037 resource_pool_ = ResourcePool::Create(
2038 resource_provider_.get(),
2039 GetMapImageTextureTarget(context_provider->ContextCapabilities()),
2040 resource_provider_->best_texture_format());
2041
2042 raster_worker_pool_ =
2043 ZeroCopyRasterWorkerPool::Create(proxy_->ImplThreadTaskRunner(),
2044 RasterWorkerPool::GetTaskGraphRunner(),
2045 resource_provider_.get());
2046 } else if (UseOneCopyRasterizer()) {
[email protected]2cccfef2014-05-01 06:05:162047 // We need to create a staging resource pool when using copy rasterizer.
reveman5ae838bb2014-09-24 23:30:142048 staging_resource_pool_ = ResourcePool::Create(
2049 resource_provider_.get(),
2050 GetMapImageTextureTarget(context_provider->ContextCapabilities()),
2051 resource_provider_->best_texture_format());
[email protected]2cccfef2014-05-01 06:05:162052 resource_pool_ =
[email protected]ced667b2014-05-22 21:49:532053 ResourcePool::Create(resource_provider_.get(),
[email protected]2cccfef2014-05-01 06:05:162054 GL_TEXTURE_2D,
[email protected]ced667b2014-05-22 21:49:532055 resource_provider_->best_texture_format());
[email protected]2cccfef2014-05-01 06:05:162056
reveman423e7da2014-09-23 16:57:442057 raster_worker_pool_ =
enne98f3a6c2014-10-09 20:09:442058 OneCopyRasterWorkerPool::Create(task_runner,
reveman423e7da2014-09-23 16:57:442059 RasterWorkerPool::GetTaskGraphRunner(),
2060 context_provider,
2061 resource_provider_.get(),
2062 staging_resource_pool_.get());
reveman5ae838bb2014-09-24 23:30:142063 } else {
[email protected]ced667b2014-05-22 21:49:532064 resource_pool_ = ResourcePool::Create(
2065 resource_provider_.get(),
2066 GL_TEXTURE_2D,
2067 resource_provider_->memory_efficient_texture_format());
2068
[email protected]7beac1b52014-04-10 23:09:562069 raster_worker_pool_ = PixelBufferRasterWorkerPool::Create(
enne98f3a6c2014-10-09 20:09:442070 task_runner,
[email protected]7beac1b52014-04-10 23:09:562071 RasterWorkerPool::GetTaskGraphRunner(),
[email protected]110fcc0e2014-07-16 15:52:472072 context_provider,
[email protected]ced667b2014-05-22 21:49:532073 resource_provider_.get(),
reveman5ae838bb2014-09-24 23:30:142074 GetMaxTransferBufferUsageBytes(context_provider->ContextCapabilities(),
revemanc84602a02014-09-24 15:41:252075 settings_.refresh_rate));
[email protected]ec7541d2014-04-09 01:23:532076 }
[email protected]ced667b2014-05-22 21:49:532077
enne98f3a6c2014-10-09 20:09:442078 tile_manager_ = TileManager::Create(this,
2079 task_runner,
2080 resource_pool_.get(),
2081 raster_worker_pool_->AsRasterizer(),
enne06a2caf2014-10-23 20:34:262082 rendering_stats_instrumentation_,
2083 settings().scheduled_raster_task_limit);
[email protected]b6eb8e332013-09-10 00:51:012084
[email protected]50af3c22013-07-13 03:50:202085 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy());
[email protected]8bb6cfa2013-07-23 00:11:192086 need_to_update_visible_tiles_before_draw_ = false;
[email protected]50af3c22013-07-13 03:50:202087}
2088
[email protected]ced667b2014-05-22 21:49:532089void LayerTreeHostImpl::DestroyTileManager() {
danakjf446a072014-09-27 21:55:482090 tile_manager_ = nullptr;
2091 resource_pool_ = nullptr;
2092 staging_resource_pool_ = nullptr;
2093 raster_worker_pool_ = nullptr;
[email protected]ced667b2014-05-22 21:49:532094}
2095
[email protected]fc20d142014-07-01 00:49:152096bool LayerTreeHostImpl::UsePendingTreeForSync() const {
2097 // In impl-side painting, synchronize to the pending tree so that it has
2098 // time to raster before being displayed.
2099 return settings_.impl_side_painting;
2100}
2101
reveman423e7da2014-09-23 16:57:442102bool LayerTreeHostImpl::UseZeroCopyRasterizer() const {
reveman340109182014-09-30 15:36:452103 return settings_.use_zero_copy && GetRendererCapabilities().using_image;
[email protected]ced667b2014-05-22 21:49:532104}
2105
reveman423e7da2014-09-23 16:57:442106bool LayerTreeHostImpl::UseOneCopyRasterizer() const {
[email protected]ced667b2014-05-22 21:49:532107 // Sync query support is required by one-copy rasterizer.
reveman340109182014-09-30 15:36:452108 return settings_.use_one_copy && GetRendererCapabilities().using_image &&
[email protected]ced667b2014-05-22 21:49:532109 resource_provider_->use_sync_query();
2110}
2111
[email protected]50644642013-06-20 13:58:552112void LayerTreeHostImpl::EnforceZeroBudget(bool zero_budget) {
[email protected]3f2ff112013-08-03 02:41:072113 SetManagedMemoryPolicy(cached_managed_memory_policy_, zero_budget);
[email protected]50644642013-06-20 13:58:552114}
2115
[email protected]c1bb5af2013-03-13 19:06:272116bool LayerTreeHostImpl::InitializeRenderer(
2117 scoped_ptr<OutputSurface> output_surface) {
[email protected]06630f832014-05-29 23:15:142118 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer");
[email protected]ce2e8112013-11-28 07:44:362119
[email protected]c1bb5af2013-03-13 19:06:272120 // Since we will create a new resource provider, we cannot continue to use
2121 // the old resources (i.e. render_surfaces and texture IDs). Clear them
2122 // before we destroy the old resource provider.
[email protected]50644642013-06-20 13:58:552123 ReleaseTreeResources();
[email protected]45c4b1e2013-01-16 02:19:402124
[email protected]c1bb5af2013-03-13 19:06:272125 // Note: order is important here.
danakjf446a072014-09-27 21:55:482126 renderer_ = nullptr;
[email protected]ced667b2014-05-22 21:49:532127 DestroyTileManager();
danakjf446a072014-09-27 21:55:482128 resource_provider_ = nullptr;
2129 output_surface_ = nullptr;
[email protected]94f206c12012-08-25 00:09:142130
[email protected]c1bb5af2013-03-13 19:06:272131 if (!output_surface->BindToClient(this))
2132 return false;
[email protected]be3181652012-09-25 13:02:132133
[email protected]ced667b2014-05-22 21:49:532134 output_surface_ = output_surface.Pass();
2135 resource_provider_ =
2136 ResourceProvider::Create(output_surface_.get(),
[email protected]a7f35682013-10-22 23:05:572137 shared_bitmap_manager_,
reveman22dd9292014-10-13 20:52:052138 gpu_memory_buffer_manager_,
skyostil3976a3f2014-09-04 22:07:232139 proxy_->blocking_main_thread_task_runner(),
[email protected]a7f35682013-10-22 23:05:572140 settings_.highp_threshold_min,
[email protected]b796c34f2013-11-01 11:52:342141 settings_.use_rgba_4444_textures,
hendrikw6a15e252014-10-22 02:46:242142 settings_.texture_id_allocation_chunk_size);
[email protected]2b154b22013-06-07 09:03:272143
[email protected]ced667b2014-05-22 21:49:532144 if (output_surface_->capabilities().deferred_gl_initialization)
[email protected]50644642013-06-20 13:58:552145 EnforceZeroBudget(true);
[email protected]be3181652012-09-25 13:02:132146
[email protected]ced667b2014-05-22 21:49:532147 CreateAndSetRenderer();
[email protected]be3181652012-09-25 13:02:132148
[email protected]ced667b2014-05-22 21:49:532149 if (settings_.impl_side_painting)
2150 CreateAndSetTileManager();
[email protected]fbe89f72013-05-21 07:24:242151
[email protected]3dc0c772014-04-26 10:06:052152 // Initialize vsync parameters to sane values.
2153 const base::TimeDelta display_refresh_interval =
2154 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond /
2155 settings_.refresh_rate);
2156 CommitVSyncParameters(base::TimeTicks(), display_refresh_interval);
[email protected]049fc7a2013-06-18 12:32:352157
[email protected]3dc0c772014-04-26 10:06:052158 // TODO(brianderson): Don't use a hard-coded parent draw time.
2159 base::TimeDelta parent_draw_time =
[email protected]4851dd22014-06-17 16:06:292160 (!settings_.begin_frame_scheduling_enabled &&
2161 output_surface_->capabilities().adjust_deadline_for_parent)
[email protected]1d142de82014-06-11 12:48:232162 ? BeginFrameArgs::DefaultEstimatedParentDrawTime()
[email protected]3dc0c772014-04-26 10:06:052163 : base::TimeDelta();
2164 client_->SetEstimatedParentDrawTime(parent_draw_time);
[email protected]049fc7a2013-06-18 12:32:352165
[email protected]ced667b2014-05-22 21:49:532166 int max_frames_pending = output_surface_->capabilities().max_frames_pending;
[email protected]049fc7a2013-06-18 12:32:352167 if (max_frames_pending <= 0)
[email protected]df3c24c92013-06-19 03:54:352168 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING;
[email protected]c14902662014-04-18 05:06:112169 client_->SetMaxSwapsPendingOnImplThread(max_frames_pending);
[email protected]c1bb5af2013-03-13 19:06:272170 client_->OnCanDrawStateChanged(CanDraw());
[email protected]8db2213c2012-09-05 22:08:212171
sohan.jyoti9d1e4202014-09-23 21:02:332172 // There will not be anything to draw here, so set high res
2173 // to avoid checkerboards, typically when we are recovering
2174 // from lost context.
vmpstr61ed94a12014-10-09 04:49:302175 SetRequiresHighResToDraw();
sohan.jyoti9d1e4202014-09-23 21:02:332176
[email protected]c1bb5af2013-03-13 19:06:272177 return true;
[email protected]94f206c12012-08-25 00:09:142178}
2179
[email protected]3dc0c772014-04-26 10:06:052180void LayerTreeHostImpl::CommitVSyncParameters(base::TimeTicks timebase,
2181 base::TimeDelta interval) {
2182 client_->CommitVSyncParameters(timebase, interval);
2183}
2184
[email protected]3b2eb882014-04-24 19:48:562185void LayerTreeHostImpl::DeferredInitialize() {
[email protected]2b154b22013-06-07 09:03:272186 DCHECK(output_surface_->capabilities().deferred_gl_initialization);
[email protected]50644642013-06-20 13:58:552187 DCHECK(settings_.impl_side_painting);
[email protected]0634cdd42013-08-16 00:46:092188 DCHECK(output_surface_->context_provider());
[email protected]2b154b22013-06-07 09:03:272189
[email protected]50644642013-06-20 13:58:552190 ReleaseTreeResources();
danakjf446a072014-09-27 21:55:482191 renderer_ = nullptr;
[email protected]105a723202014-06-12 14:18:272192 DestroyTileManager();
[email protected]2b154b22013-06-07 09:03:272193
[email protected]0cfda302014-04-23 19:02:372194 resource_provider_->InitializeGL();
[email protected]d9ca99e2013-08-28 21:49:482195
[email protected]ced667b2014-05-22 21:49:532196 CreateAndSetRenderer();
[email protected]3b2eb882014-04-24 19:48:562197 EnforceZeroBudget(false);
[email protected]105a723202014-06-12 14:18:272198 CreateAndSetTileManager();
2199
[email protected]3b2eb882014-04-24 19:48:562200 client_->SetNeedsCommitOnImplThread();
[email protected]2b154b22013-06-07 09:03:272201}
2202
[email protected]50af3c22013-07-13 03:50:202203void LayerTreeHostImpl::ReleaseGL() {
2204 DCHECK(output_surface_->capabilities().deferred_gl_initialization);
2205 DCHECK(settings_.impl_side_painting);
[email protected]0634cdd42013-08-16 00:46:092206 DCHECK(output_surface_->context_provider());
[email protected]50af3c22013-07-13 03:50:202207
2208 ReleaseTreeResources();
danakjf446a072014-09-27 21:55:482209 renderer_ = nullptr;
[email protected]ced667b2014-05-22 21:49:532210 DestroyTileManager();
[email protected]105a723202014-06-12 14:18:272211
[email protected]50af3c22013-07-13 03:50:202212 resource_provider_->InitializeSoftware();
[email protected]41b53ac2014-05-22 03:22:192213 output_surface_->ReleaseContextProvider();
[email protected]50af3c22013-07-13 03:50:202214
[email protected]105a723202014-06-12 14:18:272215 CreateAndSetRenderer();
[email protected]50af3c22013-07-13 03:50:202216 EnforceZeroBudget(true);
[email protected]ced667b2014-05-22 21:49:532217 CreateAndSetTileManager();
[email protected]50af3c22013-07-13 03:50:202218
[email protected]50af3c22013-07-13 03:50:202219 client_->SetNeedsCommitOnImplThread();
2220}
2221
[email protected]64348ea2014-01-29 22:58:262222void LayerTreeHostImpl::SetViewportSize(const gfx::Size& device_viewport_size) {
[email protected]18ce59702013-04-09 04:58:402223 if (device_viewport_size == device_viewport_size_)
[email protected]c1bb5af2013-03-13 19:06:272224 return;
[email protected]94f206c12012-08-25 00:09:142225
[email protected]54af03522013-09-05 00:43:282226 if (pending_tree_)
[email protected]c1bb5af2013-03-13 19:06:272227 active_tree_->SetViewportSizeInvalid();
[email protected]318822852013-02-14 00:54:272228
[email protected]c1bb5af2013-03-13 19:06:272229 device_viewport_size_ = device_viewport_size;
[email protected]94f206c12012-08-25 00:09:142230
bokanef971462014-10-13 22:58:322231 UpdateViewportContainerSizes();
[email protected]c1bb5af2013-03-13 19:06:272232 client_->OnCanDrawStateChanged(CanDraw());
[email protected]59adb112013-04-09 04:48:442233 SetFullRootLayerDamage();
[email protected]a533d9b82014-07-11 20:29:242234 active_tree_->set_needs_update_draw_properties();
[email protected]94f206c12012-08-25 00:09:142235}
2236
[email protected]9f4f6a32013-09-04 21:35:122237void LayerTreeHostImpl::SetOverhangUIResource(
2238 UIResourceId overhang_ui_resource_id,
[email protected]64348ea2014-01-29 22:58:262239 const gfx::Size& overhang_ui_resource_size) {
[email protected]9f4f6a32013-09-04 21:35:122240 overhang_ui_resource_id_ = overhang_ui_resource_id;
2241 overhang_ui_resource_size_ = overhang_ui_resource_size;
2242}
2243
[email protected]c1bb5af2013-03-13 19:06:272244void LayerTreeHostImpl::SetDeviceScaleFactor(float device_scale_factor) {
2245 if (device_scale_factor == device_scale_factor_)
2246 return;
2247 device_scale_factor_ = device_scale_factor;
[email protected]c0dd24c2012-08-30 23:25:272248
[email protected]59adb112013-04-09 04:48:442249 SetFullRootLayerDamage();
[email protected]94f206c12012-08-25 00:09:142250}
2251
[email protected]bd5324592014-07-31 09:09:332252const gfx::Rect LayerTreeHostImpl::ViewportRectForTilePriority() const {
2253 if (viewport_rect_for_tile_priority_.IsEmpty())
2254 return DeviceViewport();
2255
2256 return viewport_rect_for_tile_priority_;
2257}
2258
[email protected]54af03522013-09-05 00:43:282259gfx::Size LayerTreeHostImpl::DrawViewportSize() const {
2260 return DeviceViewport().size();
2261}
2262
[email protected]f224cc92013-06-06 23:23:322263gfx::Rect LayerTreeHostImpl::DeviceViewport() const {
2264 if (external_viewport_.IsEmpty())
2265 return gfx::Rect(device_viewport_size_);
2266
2267 return external_viewport_;
2268}
2269
[email protected]54af03522013-09-05 00:43:282270gfx::Rect LayerTreeHostImpl::DeviceClip() const {
2271 if (external_clip_.IsEmpty())
2272 return DeviceViewport();
2273
2274 return external_clip_;
2275}
2276
2277const gfx::Transform& LayerTreeHostImpl::DrawTransform() const {
[email protected]f224cc92013-06-06 23:23:322278 return external_transform_;
2279}
2280
[email protected]59adb112013-04-09 04:48:442281void LayerTreeHostImpl::DidChangeTopControlsPosition() {
bokanef971462014-10-13 22:58:322282 UpdateViewportContainerSizes();
[email protected]4e4136d2013-11-29 02:22:442283 SetNeedsRedraw();
[email protected]43b8f982014-04-30 21:24:332284 SetNeedsAnimate();
[email protected]59adb112013-04-09 04:48:442285 active_tree_->set_needs_update_draw_properties();
2286 SetFullRootLayerDamage();
[email protected]94f206c12012-08-25 00:09:142287}
2288
bokan88eae012014-09-09 20:40:422289void LayerTreeHostImpl::SetControlsTopOffset(float offset) {
bokan55b2f152014-09-15 14:47:592290 float current_top_offset = active_tree_->top_controls_content_offset() -
2291 top_controls_manager_->top_controls_height();
2292 active_tree_->set_top_controls_delta(offset - current_top_offset);
bokan88eae012014-09-09 20:40:422293}
2294
2295float LayerTreeHostImpl::ControlsTopOffset() const {
bokan55b2f152014-09-15 14:47:592296 return active_tree_->total_top_controls_content_offset() -
2297 top_controls_manager_->top_controls_height();
bokan88eae012014-09-09 20:40:422298}
2299
[email protected]200a9c062013-05-20 04:34:372300void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) {
2301 DCHECK(input_handler_client_ == NULL);
2302 input_handler_client_ = client;
2303}
2304
[email protected]420fdf6e2013-08-26 20:36:382305static LayerImpl* NextScrollLayer(LayerImpl* layer) {
2306 if (LayerImpl* scroll_parent = layer->scroll_parent())
2307 return scroll_parent;
2308 return layer->parent();
2309}
2310
[email protected]f620b0e72013-10-01 21:38:242311LayerImpl* LayerTreeHostImpl::FindScrollLayerForDeviceViewportPoint(
[email protected]14bc5d682014-01-17 07:26:472312 const gfx::PointF& device_viewport_point,
2313 InputHandler::ScrollInputType type,
[email protected]f161ca9e2014-04-01 13:57:012314 LayerImpl* layer_impl,
2315 bool* scroll_on_main_thread,
[email protected]edcc1a12014-05-06 01:26:392316 bool* optional_has_ancestor_scroll_handler) const {
[email protected]bf1cfd9a2013-09-26 05:43:022317 DCHECK(scroll_on_main_thread);
[email protected]94f206c12012-08-25 00:09:142318
[email protected]c1bb5af2013-03-13 19:06:272319 // Walk up the hierarchy and look for a scrollable layer.
[email protected]8f7f298822014-06-13 00:23:322320 LayerImpl* potentially_scrolling_layer_impl = NULL;
[email protected]420fdf6e2013-08-26 20:36:382321 for (; layer_impl; layer_impl = NextScrollLayer(layer_impl)) {
[email protected]c1bb5af2013-03-13 19:06:272322 // The content layer can also block attempts to scroll outside the main
2323 // thread.
2324 ScrollStatus status = layer_impl->TryScroll(device_viewport_point, type);
2325 if (status == ScrollOnMainThread) {
[email protected]bf1cfd9a2013-09-26 05:43:022326 *scroll_on_main_thread = true;
2327 return NULL;
[email protected]94f206c12012-08-25 00:09:142328 }
2329
[email protected]c1bb5af2013-03-13 19:06:272330 LayerImpl* scroll_layer_impl = FindScrollLayerForContentLayer(layer_impl);
2331 if (!scroll_layer_impl)
2332 continue;
[email protected]94f206c12012-08-25 00:09:142333
[email protected]c1bb5af2013-03-13 19:06:272334 status = scroll_layer_impl->TryScroll(device_viewport_point, type);
[email protected]c1bb5af2013-03-13 19:06:272335 // If any layer wants to divert the scroll event to the main thread, abort.
2336 if (status == ScrollOnMainThread) {
[email protected]bf1cfd9a2013-09-26 05:43:022337 *scroll_on_main_thread = true;
2338 return NULL;
[email protected]94f206c12012-08-25 00:09:142339 }
2340
[email protected]edcc1a12014-05-06 01:26:392341 if (optional_has_ancestor_scroll_handler &&
[email protected]f161ca9e2014-04-01 13:57:012342 scroll_layer_impl->have_scroll_event_handlers())
[email protected]edcc1a12014-05-06 01:26:392343 *optional_has_ancestor_scroll_handler = true;
[email protected]f161ca9e2014-04-01 13:57:012344
[email protected]c1bb5af2013-03-13 19:06:272345 if (status == ScrollStarted && !potentially_scrolling_layer_impl)
2346 potentially_scrolling_layer_impl = scroll_layer_impl;
2347 }
2348
[email protected]edcc1a12014-05-06 01:26:392349 // Falling back to the root scroll layer ensures generation of root overscroll
2350 // notifications while preventing scroll updates from being unintentionally
2351 // forwarded to the main thread.
2352 if (!potentially_scrolling_layer_impl)
2353 potentially_scrolling_layer_impl = OuterViewportScrollLayer()
2354 ? OuterViewportScrollLayer()
2355 : InnerViewportScrollLayer();
2356
[email protected]bf1cfd9a2013-09-26 05:43:022357 return potentially_scrolling_layer_impl;
2358}
2359
[email protected]edcc1a12014-05-06 01:26:392360// Similar to LayerImpl::HasAncestor, but walks up the scroll parents.
[email protected]05ba53c2014-04-16 21:22:512361static bool HasScrollAncestor(LayerImpl* child, LayerImpl* scroll_ancestor) {
2362 DCHECK(scroll_ancestor);
2363 for (LayerImpl* ancestor = child; ancestor;
2364 ancestor = NextScrollLayer(ancestor)) {
2365 if (ancestor->scrollable())
2366 return ancestor == scroll_ancestor;
2367 }
2368 return false;
2369}
2370
[email protected]bf1cfd9a2013-09-26 05:43:022371InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
[email protected]47a723f2014-03-05 12:42:492372 const gfx::Point& viewport_point,
2373 InputHandler::ScrollInputType type) {
[email protected]bf1cfd9a2013-09-26 05:43:022374 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin");
2375
2376 if (top_controls_manager_)
2377 top_controls_manager_->ScrollBegin();
2378
2379 DCHECK(!CurrentlyScrollingLayer());
2380 ClearCurrentlyScrollingLayer();
2381
[email protected]f620b0e72013-10-01 21:38:242382 gfx::PointF device_viewport_point = gfx::ScalePoint(viewport_point,
2383 device_scale_factor_);
[email protected]28336d52014-05-12 19:07:282384 LayerImpl* layer_impl =
2385 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
[email protected]05ba53c2014-04-16 21:22:512386
2387 if (layer_impl) {
2388 LayerImpl* scroll_layer_impl =
[email protected]28336d52014-05-12 19:07:282389 active_tree_->FindFirstScrollingLayerThatIsHitByPoint(
2390 device_viewport_point);
[email protected]05ba53c2014-04-16 21:22:512391 if (scroll_layer_impl && !HasScrollAncestor(layer_impl, scroll_layer_impl))
2392 return ScrollUnknown;
2393 }
2394
[email protected]bf1cfd9a2013-09-26 05:43:022395 bool scroll_on_main_thread = false;
[email protected]edcc1a12014-05-06 01:26:392396 LayerImpl* scrolling_layer_impl =
[email protected]f161ca9e2014-04-01 13:57:012397 FindScrollLayerForDeviceViewportPoint(device_viewport_point,
2398 type,
2399 layer_impl,
2400 &scroll_on_main_thread,
2401 &scroll_affects_scroll_handler_);
[email protected]bf1cfd9a2013-09-26 05:43:022402
2403 if (scroll_on_main_thread) {
[email protected]bf1cfd9a2013-09-26 05:43:022404 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true);
2405 return ScrollOnMainThread;
2406 }
2407
[email protected]edcc1a12014-05-06 01:26:392408 if (scrolling_layer_impl) {
2409 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl);
[email protected]c1bb5af2013-03-13 19:06:272410 should_bubble_scrolls_ = (type != NonBubblingGesture);
2411 wheel_scrolling_ = (type == Wheel);
[email protected]c1bb5af2013-03-13 19:06:272412 client_->RenewTreePriority();
2413 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false);
2414 return ScrollStarted;
2415 }
2416 return ScrollIgnored;
[email protected]94f206c12012-08-25 00:09:142417}
2418
[email protected]749cbc62014-07-10 01:06:352419InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated(
2420 const gfx::Point& viewport_point,
2421 const gfx::Vector2dF& scroll_delta) {
[email protected]7a7d5be2014-07-18 22:37:262422 if (LayerImpl* layer_impl = CurrentlyScrollingLayer()) {
2423 Animation* animation =
2424 layer_impl->layer_animation_controller()->GetAnimation(
2425 Animation::ScrollOffset);
2426 if (!animation)
2427 return ScrollIgnored;
2428
2429 ScrollOffsetAnimationCurve* curve =
2430 animation->curve()->ToScrollOffsetAnimationCurve();
2431
miletusf57925d2014-10-01 19:38:132432 gfx::ScrollOffset new_target =
2433 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta);
2434 new_target.SetToMax(gfx::ScrollOffset());
[email protected]7a7d5be2014-07-18 22:37:262435 new_target.SetToMin(layer_impl->MaxScrollOffset());
2436
[email protected]04c5900d2014-08-18 13:38:362437 curve->UpdateTarget(animation->TrimTimeToCurrentIteration(
2438 CurrentBeginFrameArgs().frame_time),
2439 new_target);
[email protected]7a7d5be2014-07-18 22:37:262440
2441 return ScrollStarted;
[email protected]749cbc62014-07-10 01:06:352442 }
2443 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling
2444 // behavior as ScrollBy to determine which layer to animate, but we do not
2445 // do the Android-specific things in ScrollBy like showing top controls.
2446 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel);
2447 if (scroll_status == ScrollStarted) {
2448 gfx::Vector2dF pending_delta = scroll_delta;
2449 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl;
2450 layer_impl = layer_impl->parent()) {
2451 if (!layer_impl->scrollable())
2452 continue;
2453
miletusf57925d2014-10-01 19:38:132454 gfx::ScrollOffset current_offset = layer_impl->TotalScrollOffset();
2455 gfx::ScrollOffset target_offset =
2456 ScrollOffsetWithDelta(current_offset, pending_delta);
2457 target_offset.SetToMax(gfx::ScrollOffset());
[email protected]749cbc62014-07-10 01:06:352458 target_offset.SetToMin(layer_impl->MaxScrollOffset());
miletusf57925d2014-10-01 19:38:132459 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset);
[email protected]749cbc62014-07-10 01:06:352460
2461 const float kEpsilon = 0.1f;
2462 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon ||
2463 std::abs(actual_delta.y()) > kEpsilon);
2464
2465 if (!can_layer_scroll) {
2466 layer_impl->ScrollBy(actual_delta);
2467 pending_delta -= actual_delta;
2468 continue;
2469 }
2470
2471 active_tree_->SetCurrentlyScrollingLayer(layer_impl);
2472
2473 scoped_ptr<ScrollOffsetAnimationCurve> curve =
2474 ScrollOffsetAnimationCurve::Create(target_offset,
2475 EaseInOutTimingFunction::Create());
2476 curve->SetInitialValue(current_offset);
2477
2478 scoped_ptr<Animation> animation =
danakjf446a072014-09-27 21:55:482479 Animation::Create(curve.Pass(),
[email protected]749cbc62014-07-10 01:06:352480 AnimationIdProvider::NextAnimationId(),
2481 AnimationIdProvider::NextGroupId(),
2482 Animation::ScrollOffset);
2483 animation->set_is_impl_only(true);
2484
2485 layer_impl->layer_animation_controller()->AddAnimation(animation.Pass());
2486
2487 SetNeedsAnimate();
2488 return ScrollStarted;
2489 }
2490 }
2491 ScrollEnd();
2492 return scroll_status;
2493}
2494
[email protected]c1bb5af2013-03-13 19:06:272495gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta(
2496 LayerImpl* layer_impl,
2497 float scale_from_viewport_to_screen_space,
[email protected]14bc5d682014-01-17 07:26:472498 const gfx::PointF& viewport_point,
[email protected]3244c9132014-01-23 10:39:122499 const gfx::Vector2dF& viewport_delta) {
[email protected]c1bb5af2013-03-13 19:06:272500 // Layers with non-invertible screen space transforms should not have passed
2501 // the scroll hit test in the first place.
2502 DCHECK(layer_impl->screen_space_transform().IsInvertible());
2503 gfx::Transform inverse_screen_space_transform(
2504 gfx::Transform::kSkipInitialization);
2505 bool did_invert = layer_impl->screen_space_transform().GetInverse(
2506 &inverse_screen_space_transform);
[email protected]ca2902e92013-03-28 01:45:352507 // TODO(shawnsingh): With the advent of impl-side crolling for non-root
2508 // layers, we may need to explicitly handle uninvertible transforms here.
[email protected]c1bb5af2013-03-13 19:06:272509 DCHECK(did_invert);
[email protected]94f206c12012-08-25 00:09:142510
[email protected]c1bb5af2013-03-13 19:06:272511 gfx::PointF screen_space_point =
2512 gfx::ScalePoint(viewport_point, scale_from_viewport_to_screen_space);
[email protected]94f206c12012-08-25 00:09:142513
[email protected]c1bb5af2013-03-13 19:06:272514 gfx::Vector2dF screen_space_delta = viewport_delta;
2515 screen_space_delta.Scale(scale_from_viewport_to_screen_space);
2516
2517 // First project the scroll start and end points to local layer space to find
2518 // the scroll delta in layer coordinates.
2519 bool start_clipped, end_clipped;
2520 gfx::PointF screen_space_end_point = screen_space_point + screen_space_delta;
2521 gfx::PointF local_start_point =
[email protected]fa816c62013-03-18 04:24:212522 MathUtil::ProjectPoint(inverse_screen_space_transform,
[email protected]c1bb5af2013-03-13 19:06:272523 screen_space_point,
[email protected]fa816c62013-03-18 04:24:212524 &start_clipped);
[email protected]c1bb5af2013-03-13 19:06:272525 gfx::PointF local_end_point =
[email protected]fa816c62013-03-18 04:24:212526 MathUtil::ProjectPoint(inverse_screen_space_transform,
[email protected]c1bb5af2013-03-13 19:06:272527 screen_space_end_point,
[email protected]fa816c62013-03-18 04:24:212528 &end_clipped);
[email protected]c1bb5af2013-03-13 19:06:272529
2530 // In general scroll point coordinates should not get clipped.
2531 DCHECK(!start_clipped);
2532 DCHECK(!end_clipped);
2533 if (start_clipped || end_clipped)
2534 return gfx::Vector2dF();
2535
2536 // local_start_point and local_end_point are in content space but we want to
2537 // move them to layer space for scrolling.
2538 float width_scale = 1.f / layer_impl->contents_scale_x();
2539 float height_scale = 1.f / layer_impl->contents_scale_y();
2540 local_start_point.Scale(width_scale, height_scale);
2541 local_end_point.Scale(width_scale, height_scale);
2542
2543 // Apply the scroll delta.
[email protected]1960a712013-04-30 17:06:472544 gfx::Vector2dF previous_delta = layer_impl->ScrollDelta();
[email protected]c1bb5af2013-03-13 19:06:272545 layer_impl->ScrollBy(local_end_point - local_start_point);
2546
2547 // Get the end point in the layer's content space so we can apply its
2548 // ScreenSpaceTransform.
2549 gfx::PointF actual_local_end_point = local_start_point +
[email protected]1960a712013-04-30 17:06:472550 layer_impl->ScrollDelta() -
[email protected]c1bb5af2013-03-13 19:06:272551 previous_delta;
2552 gfx::PointF actual_local_content_end_point =
2553 gfx::ScalePoint(actual_local_end_point,
2554 1.f / width_scale,
2555 1.f / height_scale);
2556
2557 // Calculate the applied scroll delta in viewport space coordinates.
2558 gfx::PointF actual_screen_space_end_point =
[email protected]fa816c62013-03-18 04:24:212559 MathUtil::MapPoint(layer_impl->screen_space_transform(),
[email protected]c1bb5af2013-03-13 19:06:272560 actual_local_content_end_point,
[email protected]fa816c62013-03-18 04:24:212561 &end_clipped);
[email protected]c1bb5af2013-03-13 19:06:272562 DCHECK(!end_clipped);
2563 if (end_clipped)
2564 return gfx::Vector2dF();
2565 gfx::PointF actual_viewport_end_point =
2566 gfx::ScalePoint(actual_screen_space_end_point,
2567 1.f / scale_from_viewport_to_screen_space);
2568 return actual_viewport_end_point - viewport_point;
[email protected]94f206c12012-08-25 00:09:142569}
2570
[email protected]c1bb5af2013-03-13 19:06:272571static gfx::Vector2dF ScrollLayerWithLocalDelta(LayerImpl* layer_impl,
[email protected]3244c9132014-01-23 10:39:122572 const gfx::Vector2dF& local_delta) {
[email protected]1960a712013-04-30 17:06:472573 gfx::Vector2dF previous_delta(layer_impl->ScrollDelta());
[email protected]c1bb5af2013-03-13 19:06:272574 layer_impl->ScrollBy(local_delta);
[email protected]1960a712013-04-30 17:06:472575 return layer_impl->ScrollDelta() - previous_delta;
[email protected]c1bb5af2013-03-13 19:06:272576}
2577
bokanef971462014-10-13 22:58:322578bool LayerTreeHostImpl::ShouldTopControlsConsumeScroll(
2579 const gfx::Vector2dF& scroll_delta) const {
2580 DCHECK(CurrentlyScrollingLayer());
2581
2582 if (!top_controls_manager_)
2583 return false;
2584
2585 // Always consume if it's in the direction to show the top controls.
2586 if (scroll_delta.y() < 0)
2587 return true;
2588
2589 if (CurrentlyScrollingLayer() != InnerViewportScrollLayer() &&
2590 CurrentlyScrollingLayer() != OuterViewportScrollLayer())
2591 return false;
2592
2593 if (InnerViewportScrollLayer()->MaxScrollOffset().y() > 0)
2594 return true;
2595
2596 if (OuterViewportScrollLayer() &&
2597 OuterViewportScrollLayer()->MaxScrollOffset().y() > 0)
2598 return true;
2599
2600 return false;
2601}
2602
[email protected]47a723f2014-03-05 12:42:492603bool LayerTreeHostImpl::ScrollBy(const gfx::Point& viewport_point,
[email protected]3244c9132014-01-23 10:39:122604 const gfx::Vector2dF& scroll_delta) {
[email protected]c1bb5af2013-03-13 19:06:272605 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy");
2606 if (!CurrentlyScrollingLayer())
2607 return false;
2608
2609 gfx::Vector2dF pending_delta = scroll_delta;
[email protected]a2b5ded2013-05-20 21:32:532610 gfx::Vector2dF unused_root_delta;
[email protected]2bd503f2013-07-23 05:35:292611 bool did_scroll_x = false;
2612 bool did_scroll_y = false;
[email protected]f42cffb2014-03-08 18:03:252613 bool did_scroll_top_controls = false;
bokanef971462014-10-13 22:58:322614
2615 bool consume_by_top_controls = ShouldTopControlsConsumeScroll(scroll_delta);
[email protected]a91e4f82013-03-15 06:58:062616
[email protected]c1bb5af2013-03-13 19:06:272617 for (LayerImpl* layer_impl = CurrentlyScrollingLayer();
2618 layer_impl;
2619 layer_impl = layer_impl->parent()) {
2620 if (!layer_impl->scrollable())
2621 continue;
2622
bokanef971462014-10-13 22:58:322623 if (layer_impl == InnerViewportScrollLayer() ||
2624 layer_impl == OuterViewportScrollLayer()) {
[email protected]d948c112014-01-10 02:13:532625 if (consume_by_top_controls) {
bokanef971462014-10-13 22:58:322626 gfx::Vector2dF excess_delta =
2627 top_controls_manager_->ScrollBy(pending_delta);
2628 gfx::Vector2dF applied_delta = pending_delta - excess_delta;
[email protected]adeda572014-01-31 00:49:472629 pending_delta = excess_delta;
2630 // Force updating of vertical adjust values if needed.
bokanef971462014-10-13 22:58:322631 if (applied_delta.y() != 0)
[email protected]f42cffb2014-03-08 18:03:252632 did_scroll_top_controls = true;
[email protected]a2b5ded2013-05-20 21:32:532633 }
2634 // Track root layer deltas for reporting overscroll.
bokanef971462014-10-13 22:58:322635 if (layer_impl == InnerViewportScrollLayer())
2636 unused_root_delta = pending_delta;
[email protected]60b4d252013-03-23 18:49:422637 }
2638
[email protected]c1bb5af2013-03-13 19:06:272639 gfx::Vector2dF applied_delta;
[email protected]c1bb5af2013-03-13 19:06:272640 // Gesture events need to be transformed from viewport coordinates to local
2641 // layer coordinates so that the scrolling contents exactly follow the
2642 // user's finger. In contrast, wheel events represent a fixed amount of
2643 // scrolling so we can just apply them directly.
2644 if (!wheel_scrolling_) {
2645 float scale_from_viewport_to_screen_space = device_scale_factor_;
2646 applied_delta =
2647 ScrollLayerWithViewportSpaceDelta(layer_impl,
2648 scale_from_viewport_to_screen_space,
2649 viewport_point, pending_delta);
2650 } else {
2651 applied_delta = ScrollLayerWithLocalDelta(layer_impl, pending_delta);
[email protected]94f206c12012-08-25 00:09:142652 }
[email protected]94f206c12012-08-25 00:09:142653
[email protected]9328ede2014-04-04 07:45:522654 const float kEpsilon = 0.1f;
[email protected]5b8a865c2014-04-03 00:35:512655 if (layer_impl == InnerViewportScrollLayer()) {
2656 unused_root_delta.Subtract(applied_delta);
[email protected]9328ede2014-04-04 07:45:522657 if (std::abs(unused_root_delta.x()) < kEpsilon)
[email protected]5b8a865c2014-04-03 00:35:512658 unused_root_delta.set_x(0.0f);
[email protected]9328ede2014-04-04 07:45:522659 if (std::abs(unused_root_delta.y()) < kEpsilon)
[email protected]5b8a865c2014-04-03 00:35:512660 unused_root_delta.set_y(0.0f);
[email protected]e9eb23f2014-04-11 13:42:032661 // Disable overscroll on axes which is impossible to scroll.
2662 if (settings_.report_overscroll_only_for_scrollable_axes) {
aeliasaf915a882014-10-14 04:12:042663 if (std::abs(active_tree_->TotalMaxScrollOffset().x()) <= kEpsilon ||
2664 !layer_impl->user_scrollable_horizontal())
[email protected]e9eb23f2014-04-11 13:42:032665 unused_root_delta.set_x(0.0f);
aeliasaf915a882014-10-14 04:12:042666 if (std::abs(active_tree_->TotalMaxScrollOffset().y()) <= kEpsilon ||
2667 !layer_impl->user_scrollable_vertical())
[email protected]e9eb23f2014-04-11 13:42:032668 unused_root_delta.set_y(0.0f);
2669 }
[email protected]5b8a865c2014-04-03 00:35:512670 }
2671
[email protected]c1bb5af2013-03-13 19:06:272672 // If the layer wasn't able to move, try the next one in the hierarchy.
[email protected]9328ede2014-04-04 07:45:522673 bool did_move_layer_x = std::abs(applied_delta.x()) > kEpsilon;
2674 bool did_move_layer_y = std::abs(applied_delta.y()) > kEpsilon;
[email protected]2bd503f2013-07-23 05:35:292675 did_scroll_x |= did_move_layer_x;
2676 did_scroll_y |= did_move_layer_y;
2677 if (!did_move_layer_x && !did_move_layer_y) {
[email protected]09a6f2c2014-02-20 20:19:142678 // Scrolls should always bubble between the outer and inner viewports
2679 if (should_bubble_scrolls_ || !did_lock_scrolling_layer_ ||
2680 layer_impl == OuterViewportScrollLayer())
[email protected]c1bb5af2013-03-13 19:06:272681 continue;
[email protected]db102612013-12-20 22:04:122682 else
2683 break;
[email protected]94f206c12012-08-25 00:09:142684 }
[email protected]a2b5ded2013-05-20 21:32:532685
[email protected]c1bb5af2013-03-13 19:06:272686 did_lock_scrolling_layer_ = true;
2687 if (!should_bubble_scrolls_) {
[email protected]0fc818e2013-03-18 06:45:202688 active_tree_->SetCurrentlyScrollingLayer(layer_impl);
[email protected]c1bb5af2013-03-13 19:06:272689 break;
[email protected]94f206c12012-08-25 00:09:142690 }
[email protected]94f206c12012-08-25 00:09:142691
[email protected]c1bb5af2013-03-13 19:06:272692 // If the applied delta is within 45 degrees of the input delta, bail out to
2693 // make it easier to scroll just one layer in one direction without
2694 // affecting any of its parents.
2695 float angle_threshold = 45;
[email protected]fa816c62013-03-18 04:24:212696 if (MathUtil::SmallestAngleBetweenVectors(
[email protected]c1bb5af2013-03-13 19:06:272697 applied_delta, pending_delta) < angle_threshold) {
miletusf57925d2014-10-01 19:38:132698 pending_delta = gfx::Vector2dF();
[email protected]c1bb5af2013-03-13 19:06:272699 break;
[email protected]4a23c374c2012-12-08 08:38:552700 }
[email protected]c1bb5af2013-03-13 19:06:272701
2702 // Allow further movement only on an axis perpendicular to the direction in
2703 // which the layer moved.
2704 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x());
[email protected]fa816c62013-03-18 04:24:212705 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis);
[email protected]c1bb5af2013-03-13 19:06:272706
[email protected]a2b5ded2013-05-20 21:32:532707 if (gfx::ToRoundedVector2d(pending_delta).IsZero())
[email protected]c1bb5af2013-03-13 19:06:272708 break;
2709 }
2710
[email protected]f42cffb2014-03-08 18:03:252711 bool did_scroll_content = did_scroll_x || did_scroll_y;
2712 if (did_scroll_content) {
[email protected]dab0a422014-08-13 16:09:462713 // If we are scrolling with an active scroll handler, forward latency
2714 // tracking information to the main thread so the delay introduced by the
2715 // handler is accounted for.
2716 if (scroll_affects_scroll_handler())
2717 NotifySwapPromiseMonitorsOfForwardingToMainThread();
[email protected]c1bb5af2013-03-13 19:06:272718 client_->SetNeedsCommitOnImplThread();
[email protected]4e4136d2013-11-29 02:22:442719 SetNeedsRedraw();
[email protected]c1bb5af2013-03-13 19:06:272720 client_->RenewTreePriority();
2721 }
[email protected]a2b5ded2013-05-20 21:32:532722
[email protected]2bd503f2013-07-23 05:35:292723 // Scrolling along an axis resets accumulated root overscroll for that axis.
2724 if (did_scroll_x)
2725 accumulated_root_overscroll_.set_x(0);
2726 if (did_scroll_y)
2727 accumulated_root_overscroll_.set_y(0);
2728
[email protected]a2b5ded2013-05-20 21:32:532729 accumulated_root_overscroll_ += unused_root_delta;
[email protected]485a42dc2014-03-26 22:44:342730 bool did_overscroll = !unused_root_delta.IsZero();
[email protected]a2b5ded2013-05-20 21:32:532731 if (did_overscroll && input_handler_client_) {
[email protected]cffc3282014-08-15 23:38:242732 input_handler_client_->DidOverscroll(
2733 viewport_point, accumulated_root_overscroll_, unused_root_delta);
[email protected]a2b5ded2013-05-20 21:32:532734 }
2735
[email protected]f42cffb2014-03-08 18:03:252736 return did_scroll_content || did_scroll_top_controls;
[email protected]4a23c374c2012-12-08 08:38:552737}
2738
[email protected]be782f52013-03-23 21:36:142739// This implements scrolling by page as described here:
2740// http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).aspx#_win32_The_Mouse_Wheel
2741// for events with WHEEL_PAGESCROLL set.
[email protected]47a723f2014-03-05 12:42:492742bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point,
[email protected]c28df4c12013-05-22 17:36:492743 ScrollDirection direction) {
[email protected]be782f52013-03-23 21:36:142744 DCHECK(wheel_scrolling_);
2745
2746 for (LayerImpl* layer_impl = CurrentlyScrollingLayer();
2747 layer_impl;
2748 layer_impl = layer_impl->parent()) {
2749 if (!layer_impl->scrollable())
2750 continue;
2751
[email protected]adeda572014-01-31 00:49:472752 if (!layer_impl->HasScrollbar(VERTICAL))
[email protected]be782f52013-03-23 21:36:142753 continue;
2754
bokancccfde72014-10-08 15:15:222755 float height = layer_impl->clip_height();
[email protected]be782f52013-03-23 21:36:142756
2757 // These magical values match WebKit and are designed to scroll nearly the
2758 // entire visible content height but leave a bit of overlap.
2759 float page = std::max(height * 0.875f, 1.f);
[email protected]c28df4c12013-05-22 17:36:492760 if (direction == SCROLL_BACKWARD)
[email protected]be782f52013-03-23 21:36:142761 page = -page;
2762
2763 gfx::Vector2dF delta = gfx::Vector2dF(0.f, page);
2764
2765 gfx::Vector2dF applied_delta = ScrollLayerWithLocalDelta(layer_impl, delta);
2766
2767 if (!applied_delta.IsZero()) {
[email protected]be782f52013-03-23 21:36:142768 client_->SetNeedsCommitOnImplThread();
[email protected]4e4136d2013-11-29 02:22:442769 SetNeedsRedraw();
[email protected]be782f52013-03-23 21:36:142770 client_->RenewTreePriority();
2771 return true;
2772 }
2773
2774 active_tree_->SetCurrentlyScrollingLayer(layer_impl);
2775 }
2776
2777 return false;
2778}
2779
[email protected]1960a712013-04-30 17:06:472780void LayerTreeHostImpl::SetRootLayerScrollOffsetDelegate(
2781 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
2782 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
2783 active_tree_->SetRootLayerScrollOffsetDelegate(
2784 root_layer_scroll_offset_delegate_);
2785}
2786
2787void LayerTreeHostImpl::OnRootLayerDelegatedScrollOffsetChanged() {
boliu7d5dbab2014-10-10 20:05:472788 DCHECK(root_layer_scroll_offset_delegate_);
[email protected]1960a712013-04-30 17:06:472789 client_->SetNeedsCommitOnImplThread();
boliu7d5dbab2014-10-10 20:05:472790 SetNeedsRedraw();
2791 active_tree_->OnRootLayerDelegatedScrollOffsetChanged();
[email protected]b4a3d462014-06-17 09:17:082792 active_tree_->set_needs_update_draw_properties();
[email protected]1960a712013-04-30 17:06:472793}
2794
[email protected]c1bb5af2013-03-13 19:06:272795void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() {
2796 active_tree_->ClearCurrentlyScrollingLayer();
2797 did_lock_scrolling_layer_ = false;
[email protected]f161ca9e2014-04-01 13:57:012798 scroll_affects_scroll_handler_ = false;
[email protected]a2b5ded2013-05-20 21:32:532799 accumulated_root_overscroll_ = gfx::Vector2dF();
[email protected]94f206c12012-08-25 00:09:142800}
2801
[email protected]c1bb5af2013-03-13 19:06:272802void LayerTreeHostImpl::ScrollEnd() {
2803 if (top_controls_manager_)
2804 top_controls_manager_->ScrollEnd();
2805 ClearCurrentlyScrollingLayer();
[email protected]94f206c12012-08-25 00:09:142806}
2807
[email protected]5ff3c9782013-04-29 17:35:122808InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() {
[email protected]75147f52013-08-02 19:11:462809 if (!active_tree_->CurrentlyScrollingLayer())
2810 return ScrollIgnored;
[email protected]7c45d8152013-04-23 18:27:212811
[email protected]75147f52013-08-02 19:11:462812 if (settings_.ignore_root_layer_flings &&
[email protected]adeda572014-01-31 00:49:472813 (active_tree_->CurrentlyScrollingLayer() == InnerViewportScrollLayer() ||
2814 active_tree_->CurrentlyScrollingLayer() == OuterViewportScrollLayer())) {
[email protected]75147f52013-08-02 19:11:462815 ClearCurrentlyScrollingLayer();
2816 return ScrollIgnored;
2817 }
2818
[email protected]db102612013-12-20 22:04:122819 if (!wheel_scrolling_) {
2820 // Allow the fling to lock to the first layer that moves after the initial
2821 // fling |ScrollBy()| event.
2822 did_lock_scrolling_layer_ = false;
2823 should_bubble_scrolls_ = false;
2824 }
[email protected]df0c42342013-10-08 20:52:122825
[email protected]75147f52013-08-02 19:11:462826 return ScrollStarted;
[email protected]7c45d8152013-04-23 18:27:212827}
2828
[email protected]bf1cfd9a2013-09-26 05:43:022829float LayerTreeHostImpl::DeviceSpaceDistanceToLayer(
[email protected]14bc5d682014-01-17 07:26:472830 const gfx::PointF& device_viewport_point,
[email protected]bf1cfd9a2013-09-26 05:43:022831 LayerImpl* layer_impl) {
2832 if (!layer_impl)
2833 return std::numeric_limits<float>::max();
2834
2835 gfx::Rect layer_impl_bounds(
2836 layer_impl->content_bounds());
2837
2838 gfx::RectF device_viewport_layer_impl_bounds = MathUtil::MapClippedRect(
2839 layer_impl->screen_space_transform(),
2840 layer_impl_bounds);
2841
2842 return device_viewport_layer_impl_bounds.ManhattanDistanceToPoint(
2843 device_viewport_point);
2844}
2845
[email protected]47a723f2014-03-05 12:42:492846void LayerTreeHostImpl::MouseMoveAt(const gfx::Point& viewport_point) {
[email protected]f620b0e72013-10-01 21:38:242847 gfx::PointF device_viewport_point = gfx::ScalePoint(viewport_point,
2848 device_scale_factor_);
[email protected]28336d52014-05-12 19:07:282849 LayerImpl* layer_impl =
2850 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
[email protected]f620b0e72013-10-01 21:38:242851 if (HandleMouseOverScrollbar(layer_impl, device_viewport_point))
2852 return;
2853
2854 if (scroll_layer_id_when_mouse_over_scrollbar_) {
2855 LayerImpl* scroll_layer_impl = active_tree_->LayerById(
2856 scroll_layer_id_when_mouse_over_scrollbar_);
2857
[email protected]5cd9ac12014-02-05 21:48:532858 // The check for a null scroll_layer_impl below was added to see if it will
2859 // eliminate the crashes described in http://crbug.com/326635.
2860 // TODO(wjmaclean) Add a unit test if this fixes the crashes.
[email protected]f620b0e72013-10-01 21:38:242861 ScrollbarAnimationController* animation_controller =
[email protected]5cd9ac12014-02-05 21:48:532862 scroll_layer_impl ? scroll_layer_impl->scrollbar_animation_controller()
2863 : NULL;
[email protected]930ff43b2014-05-02 05:24:002864 if (animation_controller)
2865 animation_controller->DidMouseMoveOffScrollbar();
[email protected]f620b0e72013-10-01 21:38:242866 scroll_layer_id_when_mouse_over_scrollbar_ = 0;
2867 }
2868
[email protected]bf1cfd9a2013-09-26 05:43:022869 bool scroll_on_main_thread = false;
[email protected]f161ca9e2014-04-01 13:57:012870 LayerImpl* scroll_layer_impl =
2871 FindScrollLayerForDeviceViewportPoint(device_viewport_point,
2872 InputHandler::Gesture,
2873 layer_impl,
2874 &scroll_on_main_thread,
2875 NULL);
[email protected]bf1cfd9a2013-09-26 05:43:022876 if (scroll_on_main_thread || !scroll_layer_impl)
2877 return;
2878
2879 ScrollbarAnimationController* animation_controller =
2880 scroll_layer_impl->scrollbar_animation_controller();
2881 if (!animation_controller)
2882 return;
2883
[email protected]adeda572014-01-31 00:49:472884 // TODO(wjmaclean) Is it ok to choose distance from more than two scrollbars?
2885 float distance_to_scrollbar = std::numeric_limits<float>::max();
2886 for (LayerImpl::ScrollbarSet::iterator it =
2887 scroll_layer_impl->scrollbars()->begin();
2888 it != scroll_layer_impl->scrollbars()->end();
2889 ++it)
2890 distance_to_scrollbar =
2891 std::min(distance_to_scrollbar,
2892 DeviceSpaceDistanceToLayer(device_viewport_point, *it));
[email protected]bf1cfd9a2013-09-26 05:43:022893
[email protected]930ff43b2014-05-02 05:24:002894 animation_controller->DidMouseMoveNear(distance_to_scrollbar /
2895 device_scale_factor_);
[email protected]bf1cfd9a2013-09-26 05:43:022896}
2897
[email protected]f620b0e72013-10-01 21:38:242898bool LayerTreeHostImpl::HandleMouseOverScrollbar(LayerImpl* layer_impl,
[email protected]14bc5d682014-01-17 07:26:472899 const gfx::PointF& device_viewport_point) {
[email protected]f620b0e72013-10-01 21:38:242900 if (layer_impl && layer_impl->ToScrollbarLayer()) {
2901 int scroll_layer_id = layer_impl->ToScrollbarLayer()->ScrollLayerId();
2902 layer_impl = active_tree_->LayerById(scroll_layer_id);
2903 if (layer_impl && layer_impl->scrollbar_animation_controller()) {
2904 scroll_layer_id_when_mouse_over_scrollbar_ = scroll_layer_id;
[email protected]930ff43b2014-05-02 05:24:002905 layer_impl->scrollbar_animation_controller()->DidMouseMoveNear(0);
[email protected]f620b0e72013-10-01 21:38:242906 } else {
2907 scroll_layer_id_when_mouse_over_scrollbar_ = 0;
2908 }
2909
2910 return true;
2911 }
2912
2913 return false;
2914}
2915
[email protected]c1bb5af2013-03-13 19:06:272916void LayerTreeHostImpl::PinchGestureBegin() {
2917 pinch_gesture_active_ = true;
2918 previous_pinch_anchor_ = gfx::Point();
2919 client_->RenewTreePriority();
[email protected]2fa342b82013-09-24 03:19:132920 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer();
[email protected]adeda572014-01-31 00:49:472921 if (active_tree_->OuterViewportScrollLayer()) {
2922 active_tree_->SetCurrentlyScrollingLayer(
2923 active_tree_->OuterViewportScrollLayer());
2924 } else {
2925 active_tree_->SetCurrentlyScrollingLayer(
2926 active_tree_->InnerViewportScrollLayer());
2927 }
[email protected]a9bda5e2013-10-25 18:43:372928 if (top_controls_manager_)
2929 top_controls_manager_->PinchBegin();
[email protected]94f206c12012-08-25 00:09:142930}
2931
[email protected]c1bb5af2013-03-13 19:06:272932void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta,
[email protected]47a723f2014-03-05 12:42:492933 const gfx::Point& anchor) {
[email protected]b93480862014-02-20 13:07:032934 if (!InnerViewportScrollLayer())
2935 return;
[email protected]d3afa112012-12-08 06:24:282936
[email protected]b93480862014-02-20 13:07:032937 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate");
[email protected]d3afa112012-12-08 06:24:282938
[email protected]ec2322e2014-05-15 16:32:002939 // For a moment the scroll offset ends up being outside of the max range. This
2940 // confuses the delegate so we switch it off till after we're done processing
2941 // the pinch update.
2942 active_tree_->SetRootLayerScrollOffsetDelegate(NULL);
2943
[email protected]c1bb5af2013-03-13 19:06:272944 // Keep the center-of-pinch anchor specified by (x, y) in a stable
2945 // position over the course of the magnify.
2946 float page_scale_delta = active_tree_->page_scale_delta();
2947 gfx::PointF previous_scale_anchor =
2948 gfx::ScalePoint(anchor, 1.f / page_scale_delta);
2949 active_tree_->SetPageScaleDelta(page_scale_delta * magnify_delta);
2950 page_scale_delta = active_tree_->page_scale_delta();
2951 gfx::PointF new_scale_anchor =
2952 gfx::ScalePoint(anchor, 1.f / page_scale_delta);
2953 gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor;
2954
2955 previous_pinch_anchor_ = anchor;
2956
2957 move.Scale(1 / active_tree_->page_scale_factor());
[email protected]adeda572014-01-31 00:49:472958 // If clamping the inner viewport scroll offset causes a change, it should
2959 // be accounted for from the intended move.
2960 move -= InnerViewportScrollLayer()->ClampScrollToMaxScrollOffset();
[email protected]c1bb5af2013-03-13 19:06:272961
[email protected]adeda572014-01-31 00:49:472962 // We manually manage the bubbling behaviour here as it is different to that
2963 // implemented in LayerTreeHostImpl::ScrollBy(). Specifically:
2964 // 1) we want to explicit limit the bubbling to the outer/inner viewports,
2965 // 2) we don't want the directional limitations on the unused parts that
2966 // ScrollBy() implements, and
2967 // 3) pinching should not engage the top controls manager.
2968 gfx::Vector2dF unused = OuterViewportScrollLayer()
2969 ? OuterViewportScrollLayer()->ScrollBy(move)
2970 : move;
2971
2972 if (!unused.IsZero()) {
2973 InnerViewportScrollLayer()->ScrollBy(unused);
2974 InnerViewportScrollLayer()->ClampScrollToMaxScrollOffset();
2975 }
[email protected]c1bb5af2013-03-13 19:06:272976
[email protected]ec2322e2014-05-15 16:32:002977 active_tree_->SetRootLayerScrollOffsetDelegate(
2978 root_layer_scroll_offset_delegate_);
2979
[email protected]c1bb5af2013-03-13 19:06:272980 client_->SetNeedsCommitOnImplThread();
[email protected]4e4136d2013-11-29 02:22:442981 SetNeedsRedraw();
[email protected]c1bb5af2013-03-13 19:06:272982 client_->RenewTreePriority();
[email protected]d3afa112012-12-08 06:24:282983}
2984
[email protected]c1bb5af2013-03-13 19:06:272985void LayerTreeHostImpl::PinchGestureEnd() {
2986 pinch_gesture_active_ = false;
[email protected]2fa342b82013-09-24 03:19:132987 if (pinch_gesture_end_should_clear_scrolling_layer_) {
2988 pinch_gesture_end_should_clear_scrolling_layer_ = false;
2989 ClearCurrentlyScrollingLayer();
2990 }
[email protected]a9bda5e2013-10-25 18:43:372991 if (top_controls_manager_)
2992 top_controls_manager_->PinchEnd();
[email protected]c1bb5af2013-03-13 19:06:272993 client_->SetNeedsCommitOnImplThread();
[email protected]94f206c12012-08-25 00:09:142994}
2995
[email protected]c1bb5af2013-03-13 19:06:272996static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info,
2997 LayerImpl* layer_impl) {
aelias5d3e3b42014-10-14 03:51:022998 DCHECK(layer_impl);
[email protected]94f206c12012-08-25 00:09:142999
[email protected]c1bb5af2013-03-13 19:06:273000 gfx::Vector2d scroll_delta =
[email protected]1960a712013-04-30 17:06:473001 gfx::ToFlooredVector2d(layer_impl->ScrollDelta());
[email protected]c1bb5af2013-03-13 19:06:273002 if (!scroll_delta.IsZero()) {
3003 LayerTreeHostCommon::ScrollUpdateInfo scroll;
[email protected]6ba914122013-03-22 16:26:393004 scroll.layer_id = layer_impl->id();
3005 scroll.scroll_delta = scroll_delta;
[email protected]c1bb5af2013-03-13 19:06:273006 scroll_info->scrolls.push_back(scroll);
3007 layer_impl->SetSentScrollDelta(scroll_delta);
3008 }
[email protected]94f206c12012-08-25 00:09:143009
[email protected]c1bb5af2013-03-13 19:06:273010 for (size_t i = 0; i < layer_impl->children().size(); ++i)
3011 CollectScrollDeltas(scroll_info, layer_impl->children()[i]);
[email protected]94f206c12012-08-25 00:09:143012}
3013
[email protected]c1bb5af2013-03-13 19:06:273014scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() {
3015 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet());
[email protected]362f1e8b2013-01-21 16:54:303016
aelias5d3e3b42014-10-14 03:51:023017 if (active_tree_->root_layer()) {
3018 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer());
3019 scroll_info->page_scale_delta = active_tree_->page_scale_delta();
3020 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta);
3021 scroll_info->swap_promises.swap(
3022 swap_promises_for_main_thread_scroll_update_);
3023 scroll_info->top_controls_delta = active_tree()->top_controls_delta();
3024 active_tree_->set_sent_top_controls_delta(scroll_info->top_controls_delta);
3025 }
[email protected]362f1e8b2013-01-21 16:54:303026
[email protected]c1bb5af2013-03-13 19:06:273027 return scroll_info.Pass();
[email protected]362f1e8b2013-01-21 16:54:303028}
3029
[email protected]c1bb5af2013-03-13 19:06:273030void LayerTreeHostImpl::SetFullRootLayerDamage() {
[email protected]54af03522013-09-05 00:43:283031 SetViewportDamage(gfx::Rect(DrawViewportSize()));
[email protected]829ad972013-01-28 23:36:103032}
3033
bokan59379b092014-09-29 13:47:213034void LayerTreeHostImpl::ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta) {
3035 DCHECK(InnerViewportScrollLayer());
3036 LayerImpl* scroll_layer = InnerViewportScrollLayer();
3037
3038 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta);
3039 if (!unused_delta.IsZero() && OuterViewportScrollLayer())
3040 OuterViewportScrollLayer()->ScrollBy(unused_delta);
3041}
3042
[email protected]adeda572014-01-31 00:49:473043void LayerTreeHostImpl::ScrollViewportBy(gfx::Vector2dF scroll_delta) {
3044 DCHECK(InnerViewportScrollLayer());
3045 LayerImpl* scroll_layer = OuterViewportScrollLayer()
3046 ? OuterViewportScrollLayer()
3047 : InnerViewportScrollLayer();
3048
3049 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta);
3050
3051 if (!unused_delta.IsZero() && (scroll_layer == OuterViewportScrollLayer()))
3052 InnerViewportScrollLayer()->ScrollBy(unused_delta);
3053}
3054
[email protected]27152642014-03-11 20:42:003055void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) {
[email protected]adeda572014-01-31 00:49:473056 if (!page_scale_animation_)
[email protected]c1bb5af2013-03-13 19:06:273057 return;
3058
miletusf57925d2014-10-01 19:38:133059 gfx::ScrollOffset scroll_total = active_tree_->TotalScrollOffset();
[email protected]c1bb5af2013-03-13 19:06:273060
[email protected]34e1b512013-09-26 17:32:333061 if (!page_scale_animation_->IsAnimationStarted())
[email protected]ac22516a2014-05-15 17:31:363062 page_scale_animation_->StartAnimation(monotonic_time);
[email protected]34e1b512013-09-26 17:32:333063
[email protected]ac22516a2014-05-15 17:31:363064 active_tree_->SetPageScaleDelta(
3065 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) /
3066 active_tree_->page_scale_factor());
miletusf57925d2014-10-01 19:38:133067 gfx::ScrollOffset next_scroll = gfx::ScrollOffset(
3068 page_scale_animation_->ScrollOffsetAtTime(monotonic_time));
[email protected]c1bb5af2013-03-13 19:06:273069
miletusf57925d2014-10-01 19:38:133070 ScrollViewportInnerFirst(next_scroll.DeltaFrom(scroll_total));
[email protected]4e4136d2013-11-29 02:22:443071 SetNeedsRedraw();
[email protected]c1bb5af2013-03-13 19:06:273072
[email protected]ac22516a2014-05-15 17:31:363073 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) {
danakjf446a072014-09-27 21:55:483074 page_scale_animation_ = nullptr;
[email protected]c1bb5af2013-03-13 19:06:273075 client_->SetNeedsCommitOnImplThread();
3076 client_->RenewTreePriority();
[email protected]43b8f982014-04-30 21:24:333077 } else {
3078 SetNeedsAnimate();
[email protected]c1bb5af2013-03-13 19:06:273079 }
[email protected]829ad972013-01-28 23:36:103080}
3081
[email protected]ffb2720f2013-03-15 19:18:373082void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) {
[email protected]68d3fc12014-02-18 16:31:083083 if (!top_controls_manager_ || !top_controls_manager_->animation())
[email protected]ffb2720f2013-03-15 19:18:373084 return;
[email protected]ac3446d2014-08-13 08:51:203085
[email protected]ffb2720f2013-03-15 19:18:373086 gfx::Vector2dF scroll = top_controls_manager_->Animate(time);
[email protected]ac3446d2014-08-13 08:51:203087
3088 if (top_controls_manager_->animation())
3089 SetNeedsAnimate();
3090
[email protected]adeda572014-01-31 00:49:473091 if (active_tree_->TotalScrollOffset().y() == 0.f)
[email protected]5ef82622013-05-01 16:26:173092 return;
[email protected]ac3446d2014-08-13 08:51:203093
3094 if (scroll.IsZero())
3095 return;
3096
3097 ScrollViewportBy(gfx::ScaleVector2d(
3098 scroll, 1.f / active_tree_->total_page_scale_factor()));
3099 SetNeedsRedraw();
3100 client_->SetNeedsCommitOnImplThread();
3101 client_->RenewTreePriority();
[email protected]ffb2720f2013-03-15 19:18:373102}
3103
[email protected]27152642014-03-11 20:42:003104void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) {
[email protected]8e0176d2013-03-21 03:14:523105 if (!settings_.accelerated_animation_enabled ||
[email protected]cd77bb62014-03-27 05:16:363106 !needs_animate_layers() ||
[email protected]c1bb5af2013-03-13 19:06:273107 !active_tree_->root_layer())
3108 return;
3109
3110 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers");
[email protected]c1bb5af2013-03-13 19:06:273111 AnimationRegistrar::AnimationControllerMap copy =
3112 animation_registrar_->active_animation_controllers();
3113 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin();
3114 iter != copy.end();
3115 ++iter)
[email protected]ac22516a2014-05-15 17:31:363116 (*iter).second->Animate(monotonic_time);
[email protected]c1bb5af2013-03-13 19:06:273117
[email protected]43b8f982014-04-30 21:24:333118 SetNeedsAnimate();
[email protected]131a0c22013-02-12 18:31:083119}
3120
[email protected]3d9f7432013-04-06 00:35:183121void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) {
[email protected]8e0176d2013-03-21 03:14:523122 if (!settings_.accelerated_animation_enabled ||
[email protected]cd77bb62014-03-27 05:16:363123 !needs_animate_layers() ||
[email protected]c1bb5af2013-03-13 19:06:273124 !active_tree_->root_layer())
3125 return;
3126
3127 TRACE_EVENT0("cc", "LayerTreeHostImpl::UpdateAnimationState");
3128 scoped_ptr<AnimationEventsVector> events =
3129 make_scoped_ptr(new AnimationEventsVector);
3130 AnimationRegistrar::AnimationControllerMap copy =
3131 animation_registrar_->active_animation_controllers();
3132 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin();
3133 iter != copy.end();
3134 ++iter)
[email protected]3d9f7432013-04-06 00:35:183135 (*iter).second->UpdateState(start_ready_animations, events.get());
[email protected]c1bb5af2013-03-13 19:06:273136
3137 if (!events->empty()) {
[email protected]85b57502014-03-11 15:37:483138 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass());
[email protected]c1bb5af2013-03-13 19:06:273139 }
[email protected]43b8f982014-04-30 21:24:333140
3141 SetNeedsAnimate();
[email protected]131a0c22013-02-12 18:31:083142}
3143
[email protected]b33348f2014-04-30 18:17:343144void LayerTreeHostImpl::ActivateAnimations() {
3145 if (!settings_.accelerated_animation_enabled || !needs_animate_layers() ||
3146 !active_tree_->root_layer())
3147 return;
3148
3149 TRACE_EVENT0("cc", "LayerTreeHostImpl::ActivateAnimations");
3150 AnimationRegistrar::AnimationControllerMap copy =
3151 animation_registrar_->active_animation_controllers();
3152 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin();
3153 iter != copy.end();
3154 ++iter)
3155 (*iter).second->ActivateAnimations();
3156}
3157
[email protected]c1bb5af2013-03-13 19:06:273158base::TimeDelta LayerTreeHostImpl::LowFrequencyAnimationInterval() const {
3159 return base::TimeDelta::FromSeconds(1);
3160}
3161
[email protected]c1bb5af2013-03-13 19:06:273162std::string LayerTreeHostImpl::LayerTreeAsJson() const {
3163 std::string str;
3164 if (active_tree_->root_layer()) {
3165 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson());
3166 base::JSONWriter::WriteWithOptions(
3167 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str);
3168 }
3169 return str;
3170}
3171
[email protected]c1bb5af2013-03-13 19:06:273172int LayerTreeHostImpl::SourceAnimationFrameNumber() const {
[email protected]9e3594522013-03-18 00:57:363173 return fps_counter_->current_frame_number();
[email protected]c1bb5af2013-03-13 19:06:273174}
3175
[email protected]c1bb5af2013-03-13 19:06:273176void LayerTreeHostImpl::AnimateScrollbars(base::TimeTicks time) {
3177 AnimateScrollbarsRecursive(active_tree_->root_layer(), time);
3178}
3179
3180void LayerTreeHostImpl::AnimateScrollbarsRecursive(LayerImpl* layer,
3181 base::TimeTicks time) {
3182 if (!layer)
3183 return;
3184
3185 ScrollbarAnimationController* scrollbar_controller =
3186 layer->scrollbar_animation_controller();
[email protected]930ff43b2014-05-02 05:24:003187 if (scrollbar_controller)
3188 scrollbar_controller->Animate(time);
[email protected]c1bb5af2013-03-13 19:06:273189
3190 for (size_t i = 0; i < layer->children().size(); ++i)
3191 AnimateScrollbarsRecursive(layer->children()[i], time);
3192}
3193
[email protected]930ff43b2014-05-02 05:24:003194void LayerTreeHostImpl::PostDelayedScrollbarFade(
3195 const base::Closure& start_fade,
3196 base::TimeDelta delay) {
3197 client_->PostDelayedScrollbarFadeOnImplThread(start_fade, delay);
[email protected]0fc818e2013-03-18 06:45:203198}
3199
[email protected]930ff43b2014-05-02 05:24:003200void LayerTreeHostImpl::SetNeedsScrollbarAnimationFrame() {
3201 TRACE_EVENT_INSTANT0(
3202 "cc",
3203 "LayerTreeHostImpl::SetNeedsRedraw due to scrollbar fade",
3204 TRACE_EVENT_SCOPE_THREAD);
3205 SetNeedsAnimate();
[email protected]0fc818e2013-03-18 06:45:203206}
3207
[email protected]c1bb5af2013-03-13 19:06:273208void LayerTreeHostImpl::SetTreePriority(TreePriority priority) {
3209 if (!tile_manager_)
3210 return;
3211
[email protected]1bcced22013-09-24 13:51:193212 if (global_tile_state_.tree_priority == priority)
[email protected]c1bb5af2013-03-13 19:06:273213 return;
[email protected]1bcced22013-09-24 13:51:193214 global_tile_state_.tree_priority = priority;
[email protected]c48536a52013-09-14 00:02:083215 DidModifyTilePriorities();
[email protected]c1bb5af2013-03-13 19:06:273216}
3217
vmpstr56ace232014-10-09 20:16:283218TreePriority LayerTreeHostImpl::GetTreePriority() const {
3219 return global_tile_state_.tree_priority;
3220}
3221
[email protected]04c5900d2014-08-18 13:38:363222void LayerTreeHostImpl::UpdateCurrentBeginFrameArgs(
3223 const BeginFrameArgs& args) {
3224 DCHECK(!current_begin_frame_args_.IsValid());
3225 current_begin_frame_args_ = args;
3226 // TODO(skyostil): Stop overriding the frame time once the usage of frame
3227 // timing is unified.
3228 current_begin_frame_args_.frame_time = gfx::FrameTime::Now();
[email protected]1dc06162014-03-26 22:54:453229}
3230
[email protected]04c5900d2014-08-18 13:38:363231void LayerTreeHostImpl::ResetCurrentBeginFrameArgsForNextFrame() {
3232 current_begin_frame_args_ = BeginFrameArgs();
[email protected]c1bb5af2013-03-13 19:06:273233}
3234
[email protected]04c5900d2014-08-18 13:38:363235BeginFrameArgs LayerTreeHostImpl::CurrentBeginFrameArgs() const {
[email protected]1dc06162014-03-26 22:54:453236 // Try to use the current frame time to keep animations non-jittery. But if
3237 // we're not in a frame (because this is during an input event or a delayed
3238 // task), fall back to physical time. This should still be monotonic.
[email protected]04c5900d2014-08-18 13:38:363239 if (current_begin_frame_args_.IsValid())
3240 return current_begin_frame_args_;
3241 return BeginFrameArgs::Create(gfx::FrameTime::Now(),
3242 base::TimeTicks(),
3243 BeginFrameArgs::DefaultInterval());
[email protected]21c9dee72013-06-15 01:20:053244}
3245
mithroc34fc0b12014-09-30 09:10:413246void LayerTreeHostImpl::AsValueInto(base::debug::TracedValue* value) const {
3247 return AsValueWithFrameInto(NULL, value);
3248}
3249
[email protected]d12aa932014-08-01 13:10:383250scoped_refptr<base::debug::ConvertableToTraceFormat>
3251LayerTreeHostImpl::AsValue() const {
3252 return AsValueWithFrame(NULL);
[email protected]f6742f52013-05-08 23:52:223253}
3254
[email protected]d12aa932014-08-01 13:10:383255scoped_refptr<base::debug::ConvertableToTraceFormat>
3256LayerTreeHostImpl::AsValueWithFrame(FrameData* frame) const {
3257 scoped_refptr<base::debug::TracedValue> state =
3258 new base::debug::TracedValue();
3259 AsValueWithFrameInto(frame, state.get());
3260 return state;
3261}
3262
3263void LayerTreeHostImpl::AsValueWithFrameInto(
3264 FrameData* frame,
3265 base::debug::TracedValue* state) const {
3266 if (this->pending_tree_) {
3267 state->BeginDictionary("activation_state");
3268 ActivationStateAsValueInto(state);
3269 state->EndDictionary();
3270 }
3271 state->BeginDictionary("device_viewport_size");
3272 MathUtil::AddToTracedValue(device_viewport_size_, state);
3273 state->EndDictionary();
[email protected]0eded9ea2014-08-14 03:39:203274
vmpstrd7de03c2014-08-27 18:11:013275 std::set<const Tile*> tiles;
3276 active_tree_->GetAllTilesForTracing(&tiles);
3277 if (pending_tree_)
3278 pending_tree_->GetAllTilesForTracing(&tiles);
3279
3280 state->BeginArray("active_tiles");
3281 for (std::set<const Tile*>::const_iterator it = tiles.begin();
3282 it != tiles.end();
3283 ++it) {
3284 const Tile* tile = *it;
3285
3286 state->BeginDictionary();
3287 tile->AsValueInto(state);
3288 state->EndDictionary();
3289 }
3290 state->EndArray();
3291
3292 if (tile_manager_) {
[email protected]0eded9ea2014-08-14 03:39:203293 state->BeginDictionary("tile_manager_basic_state");
3294 tile_manager_->BasicStateAsValueInto(state);
3295 state->EndDictionary();
[email protected]d12aa932014-08-01 13:10:383296 }
3297 state->BeginDictionary("active_tree");
3298 active_tree_->AsValueInto(state);
3299 state->EndDictionary();
3300 if (pending_tree_) {
3301 state->BeginDictionary("pending_tree");
3302 pending_tree_->AsValueInto(state);
3303 state->EndDictionary();
3304 }
3305 if (frame) {
3306 state->BeginDictionary("frame");
3307 frame->AsValueInto(state);
3308 state->EndDictionary();
3309 }
3310}
3311
3312scoped_refptr<base::debug::ConvertableToTraceFormat>
3313LayerTreeHostImpl::ActivationStateAsValue() const {
3314 scoped_refptr<base::debug::TracedValue> state =
3315 new base::debug::TracedValue();
3316 ActivationStateAsValueInto(state.get());
3317 return state;
3318}
3319
3320void LayerTreeHostImpl::ActivationStateAsValueInto(
3321 base::debug::TracedValue* state) const {
3322 TracedValue::SetIDRef(this, state, "lthi");
3323 if (tile_manager_) {
3324 state->BeginDictionary("tile_manager");
3325 tile_manager_->BasicStateAsValueInto(state);
3326 state->EndDictionary();
3327 }
[email protected]131a0c22013-02-12 18:31:083328}
3329
[email protected]6e7fdeb2013-07-09 14:28:383330void LayerTreeHostImpl::SetDebugState(
3331 const LayerTreeDebugState& new_debug_state) {
3332 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state))
3333 return;
3334 if (debug_state_.continuous_painting != new_debug_state.continuous_painting)
[email protected]c1bb5af2013-03-13 19:06:273335 paint_time_counter_->ClearHistory();
[email protected]652cf132013-02-15 21:53:243336
[email protected]6e7fdeb2013-07-09 14:28:383337 debug_state_ = new_debug_state;
[email protected]5547b4fe2013-10-01 23:14:123338 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy());
[email protected]6e7fdeb2013-07-09 14:28:383339 SetFullRootLayerDamage();
[email protected]d0d12192013-02-08 19:02:023340}
3341
[email protected]741fba422013-09-20 03:34:143342void LayerTreeHostImpl::CreateUIResource(UIResourceId uid,
3343 const UIResourceBitmap& bitmap) {
[email protected]c9280762013-08-01 06:28:573344 DCHECK_GT(uid, 0);
[email protected]c9280762013-08-01 06:28:573345
[email protected]efa48412013-09-05 15:30:163346 GLint wrap_mode = 0;
[email protected]741fba422013-09-20 03:34:143347 switch (bitmap.GetWrapMode()) {
[email protected]efa48412013-09-05 15:30:163348 case UIResourceBitmap::CLAMP_TO_EDGE:
3349 wrap_mode = GL_CLAMP_TO_EDGE;
3350 break;
3351 case UIResourceBitmap::REPEAT:
3352 wrap_mode = GL_REPEAT;
3353 break;
3354 }
3355
[email protected]c9280762013-08-01 06:28:573356 // Allow for multiple creation requests with the same UIResourceId. The
3357 // previous resource is simply deleted.
3358 ResourceProvider::ResourceId id = ResourceIdForUIResource(uid);
3359 if (id)
3360 DeleteUIResource(uid);
[email protected]6be50ba82013-11-08 12:04:123361
3362 ResourceFormat format = resource_provider_->best_texture_format();
[email protected]9b05baa2014-08-14 00:43:313363 switch (bitmap.GetFormat()) {
3364 case UIResourceBitmap::RGBA8:
3365 break;
3366 case UIResourceBitmap::ALPHA_8:
3367 format = ALPHA_8;
3368 break;
3369 case UIResourceBitmap::ETC1:
3370 format = ETC1;
3371 break;
[email protected]cffc3282014-08-15 23:38:243372 }
[email protected]655041f2014-08-21 22:58:583373 id =
3374 resource_provider_->CreateResource(bitmap.GetSize(),
3375 wrap_mode,
3376 ResourceProvider::TextureHintImmutable,
3377 format);
[email protected]c9280762013-08-01 06:28:573378
[email protected]efbdb3a2013-10-04 00:35:133379 UIResourceData data;
3380 data.resource_id = id;
3381 data.size = bitmap.GetSize();
[email protected]709c9542013-10-26 01:43:513382 data.opaque = bitmap.GetOpaque();
[email protected]efbdb3a2013-10-04 00:35:133383
3384 ui_resource_map_[uid] = data;
[email protected]f6668c892013-09-26 10:05:033385
3386 AutoLockUIResourceBitmap bitmap_lock(bitmap);
[email protected]c9280762013-08-01 06:28:573387 resource_provider_->SetPixels(id,
[email protected]f6668c892013-09-26 10:05:033388 bitmap_lock.GetPixels(),
[email protected]741fba422013-09-20 03:34:143389 gfx::Rect(bitmap.GetSize()),
3390 gfx::Rect(bitmap.GetSize()),
[email protected]c9280762013-08-01 06:28:573391 gfx::Vector2d(0, 0));
[email protected]127bdc1a2013-09-11 01:44:483392 MarkUIResourceNotEvicted(uid);
[email protected]c9280762013-08-01 06:28:573393}
3394
3395void LayerTreeHostImpl::DeleteUIResource(UIResourceId uid) {
3396 ResourceProvider::ResourceId id = ResourceIdForUIResource(uid);
3397 if (id) {
3398 resource_provider_->DeleteResource(id);
3399 ui_resource_map_.erase(uid);
3400 }
[email protected]127bdc1a2013-09-11 01:44:483401 MarkUIResourceNotEvicted(uid);
[email protected]c9280762013-08-01 06:28:573402}
3403
[email protected]127bdc1a2013-09-11 01:44:483404void LayerTreeHostImpl::EvictAllUIResources() {
3405 if (ui_resource_map_.empty())
3406 return;
3407
[email protected]5f4dc4f2013-09-05 14:58:213408 for (UIResourceMap::const_iterator iter = ui_resource_map_.begin();
3409 iter != ui_resource_map_.end();
3410 ++iter) {
[email protected]127bdc1a2013-09-11 01:44:483411 evicted_ui_resources_.insert(iter->first);
[email protected]efbdb3a2013-10-04 00:35:133412 resource_provider_->DeleteResource(iter->second.resource_id);
[email protected]5f4dc4f2013-09-05 14:58:213413 }
3414 ui_resource_map_.clear();
[email protected]127bdc1a2013-09-11 01:44:483415
3416 client_->SetNeedsCommitOnImplThread();
3417 client_->OnCanDrawStateChanged(CanDraw());
3418 client_->RenewTreePriority();
[email protected]5f4dc4f2013-09-05 14:58:213419}
3420
[email protected]c9280762013-08-01 06:28:573421ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource(
3422 UIResourceId uid) const {
3423 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid);
3424 if (iter != ui_resource_map_.end())
[email protected]efbdb3a2013-10-04 00:35:133425 return iter->second.resource_id;
[email protected]c9280762013-08-01 06:28:573426 return 0;
3427}
3428
[email protected]709c9542013-10-26 01:43:513429bool LayerTreeHostImpl::IsUIResourceOpaque(UIResourceId uid) const {
3430 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid);
3431 DCHECK(iter != ui_resource_map_.end());
3432 return iter->second.opaque;
3433}
3434
[email protected]127bdc1a2013-09-11 01:44:483435bool LayerTreeHostImpl::EvictedUIResourcesExist() const {
3436 return !evicted_ui_resources_.empty();
3437}
3438
3439void LayerTreeHostImpl::MarkUIResourceNotEvicted(UIResourceId uid) {
3440 std::set<UIResourceId>::iterator found_in_evicted =
3441 evicted_ui_resources_.find(uid);
3442 if (found_in_evicted == evicted_ui_resources_.end())
3443 return;
3444 evicted_ui_resources_.erase(found_in_evicted);
3445 if (evicted_ui_resources_.empty())
3446 client_->OnCanDrawStateChanged(CanDraw());
3447}
3448
[email protected]5e5648a2013-11-18 00:39:333449void LayerTreeHostImpl::ScheduleMicroBenchmark(
3450 scoped_ptr<MicroBenchmarkImpl> benchmark) {
3451 micro_benchmark_controller_.ScheduleRun(benchmark.Pass());
3452}
3453
[email protected]6be422b2013-12-08 06:47:313454void LayerTreeHostImpl::InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor) {
3455 swap_promise_monitor_.insert(monitor);
3456}
3457
3458void LayerTreeHostImpl::RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor) {
3459 swap_promise_monitor_.erase(monitor);
3460}
3461
3462void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() {
3463 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin();
3464 for (; it != swap_promise_monitor_.end(); it++)
3465 (*it)->OnSetNeedsRedrawOnImpl();
3466}
3467
[email protected]dab0a422014-08-13 16:09:463468void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfForwardingToMainThread() {
3469 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin();
3470 for (; it != swap_promise_monitor_.end(); it++)
3471 (*it)->OnForwardScrollUpdateToMainThreadOnImpl();
3472}
3473
[email protected]8aa39ecb2014-06-12 14:19:143474void LayerTreeHostImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) {
3475 DCHECK(std::find(picture_layers_.begin(), picture_layers_.end(), layer) ==
3476 picture_layers_.end());
3477 picture_layers_.push_back(layer);
3478}
3479
3480void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
3481 std::vector<PictureLayerImpl*>::iterator it =
3482 std::find(picture_layers_.begin(), picture_layers_.end(), layer);
3483 DCHECK(it != picture_layers_.end());
3484 picture_layers_.erase(it);
3485}
3486
[email protected]d3143c732012-10-05 19:17:593487} // namespace cc