blob: f97eea0f51f09f4ade0b5dc3043f1523d1bb9620 [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>
8
[email protected]ad5d1422012-10-19 13:40:299#include "base/basictypes.h"
[email protected]4a23c374c2012-12-08 08:38:5510#include "base/json/json_writer.h"
[email protected]f5864912013-02-01 03:18:1411#include "base/metrics/histogram.h"
[email protected]de4afb5e2012-12-20 00:11:3412#include "base/stl_util.h"
[email protected]8e61d4b2013-06-10 22:11:4813#include "base/strings/stringprintf.h"
[email protected]95e4e1a02013-03-18 07:09:0914#include "cc/animation/scrollbar_animation_controller.h"
[email protected]85d136f782013-04-26 22:04:4015#include "cc/animation/timing_function.h"
[email protected]681ccff2013-03-18 06:13:5216#include "cc/base/math_util.h"
17#include "cc/base/util.h"
[email protected]6e84de22013-03-18 06:54:2718#include "cc/debug/debug_rect_history.h"
19#include "cc/debug/frame_rate_counter.h"
20#include "cc/debug/overdraw_metrics.h"
21#include "cc/debug/paint_time_counter.h"
[email protected]372bad5f2013-03-21 16:38:4322#include "cc/debug/rendering_stats_instrumentation.h"
[email protected]f6742f52013-05-08 23:52:2223#include "cc/debug/traced_value.h"
[email protected]3052b10f2013-03-18 07:41:2124#include "cc/input/page_scale_animation.h"
25#include "cc/input/top_controls_manager.h"
[email protected]cc3cfaa2013-03-18 09:05:5226#include "cc/layers/append_quads_data.h"
27#include "cc/layers/heads_up_display_layer_impl.h"
[email protected]50761e92013-03-29 20:51:2828#include "cc/layers/layer_impl.h"
[email protected]cc3cfaa2013-03-18 09:05:5229#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2830#include "cc/layers/render_surface_impl.h"
[email protected]cc3cfaa2013-03-18 09:05:5231#include "cc/layers/scrollbar_layer_impl.h"
[email protected]7f0d825f2013-03-18 07:24:3032#include "cc/output/compositor_frame_metadata.h"
[email protected]30fe19ff2013-07-04 00:54:4533#include "cc/output/copy_output_request.h"
[email protected]7f0d825f2013-03-18 07:24:3034#include "cc/output/delegating_renderer.h"
35#include "cc/output/gl_renderer.h"
36#include "cc/output/software_renderer.h"
[email protected]89e82672013-03-18 07:50:5637#include "cc/quads/render_pass_draw_quad.h"
38#include "cc/quads/shared_quad_state.h"
39#include "cc/quads/solid_color_draw_quad.h"
[email protected]e12dd0e2013-03-18 08:24:4040#include "cc/resources/memory_history.h"
41#include "cc/resources/picture_layer_tiling.h"
42#include "cc/resources/prioritized_resource_manager.h"
[email protected]be4655a2013-03-18 08:36:3143#include "cc/scheduler/delay_based_time_source.h"
44#include "cc/scheduler/texture_uploader.h"
[email protected]556fd292013-03-18 08:03:0445#include "cc/trees/damage_tracker.h"
46#include "cc/trees/layer_tree_host.h"
47#include "cc/trees/layer_tree_host_common.h"
48#include "cc/trees/layer_tree_impl.h"
49#include "cc/trees/quad_culler.h"
50#include "cc/trees/single_thread_proxy.h"
51#include "cc/trees/tree_synchronizer.h"
[email protected]d455d552012-11-02 00:19:0652#include "ui/gfx/size_conversions.h"
[email protected]c9c1ebe2012-11-05 20:46:1353#include "ui/gfx/vector2d_conversions.h"
[email protected]94f206c12012-08-25 00:09:1454
[email protected]94f206c12012-08-25 00:09:1455namespace {
56
[email protected]c1bb5af2013-03-13 19:06:2757void DidVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) {
58 if (visible) {
59 TRACE_EVENT_ASYNC_BEGIN1("webkit",
60 "LayerTreeHostImpl::SetVisible",
61 id,
62 "LayerTreeHostImpl",
63 id);
64 return;
65 }
[email protected]94f206c12012-08-25 00:09:1466
[email protected]c1bb5af2013-03-13 19:06:2767 TRACE_EVENT_ASYNC_END0("webkit", "LayerTreeHostImpl::SetVisible", id);
[email protected]94f206c12012-08-25 00:09:1468}
69
[email protected]c1bb5af2013-03-13 19:06:2770} // namespace
[email protected]94f206c12012-08-25 00:09:1471
[email protected]9c88e562012-09-14 22:21:3072namespace cc {
[email protected]94f206c12012-08-25 00:09:1473
[email protected]96baf3e2012-10-22 23:09:5574class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient {
[email protected]c1bb5af2013-03-13 19:06:2775 public:
76 static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> Create(
77 LayerTreeHostImpl* layer_tree_host_impl,
78 scoped_refptr<DelayBasedTimeSource> time_source) {
79 return make_scoped_ptr(
80 new LayerTreeHostImplTimeSourceAdapter(layer_tree_host_impl,
81 time_source));
82 }
83 virtual ~LayerTreeHostImplTimeSourceAdapter() {
[email protected]6d0e69d2013-03-20 14:53:2684 time_source_->SetClient(NULL);
85 time_source_->SetActive(false);
[email protected]c1bb5af2013-03-13 19:06:2786 }
87
[email protected]6d0e69d2013-03-20 14:53:2688 virtual void OnTimerTick() OVERRIDE {
[email protected]c1bb5af2013-03-13 19:06:2789 // In single threaded mode we attempt to simulate changing the current
90 // thread by maintaining a fake thread id. When we switch from one
91 // thread to another, we construct DebugScopedSetXXXThread objects that
92 // update the thread id. This lets DCHECKS that ensure we're on the
93 // right thread to work correctly in single threaded mode. The problem
94 // here is that the timer tasks are run via the message loop, and when
95 // they run, we've had no chance to construct a DebugScopedSetXXXThread
96 // object. The result is that we report that we're running on the main
97 // thread. In multi-threaded mode, this timer is run on the compositor
98 // thread, so to keep this consistent in single-threaded mode, we'll
99 // construct a DebugScopedSetImplThread object. There is no need to do
100 // this in multi-threaded mode since the real thread id's will be
101 // correct. In fact, setting fake thread id's interferes with the real
102 // thread id's and causes breakage.
103 scoped_ptr<DebugScopedSetImplThread> set_impl_thread;
104 if (!layer_tree_host_impl_->proxy()->HasImplThread()) {
105 set_impl_thread.reset(
106 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy()));
[email protected]94f206c12012-08-25 00:09:14107 }
108
[email protected]94bf75c2013-06-12 13:20:04109 // TODO(enne): This should probably happen post-animate.
110 if (layer_tree_host_impl_->pending_tree()) {
111 layer_tree_host_impl_->ActivatePendingTreeIfNeeded();
112
113 if (layer_tree_host_impl_->pending_tree()) {
114 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties();
115 layer_tree_host_impl_->ManageTiles();
116 }
117 }
118
[email protected]fb7425a2013-04-22 16:28:55119 layer_tree_host_impl_->Animate(
120 layer_tree_host_impl_->CurrentFrameTimeTicks(),
121 layer_tree_host_impl_->CurrentFrameTime());
[email protected]3d9f7432013-04-06 00:35:18122 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true);
123 bool start_ready_animations = true;
124 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
[email protected]8347d692013-05-17 23:22:38125 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
[email protected]c1bb5af2013-03-13 19:06:27126 }
[email protected]373974232013-01-10 22:20:50127
[email protected]c1bb5af2013-03-13 19:06:27128 void SetActive(bool active) {
[email protected]6d0e69d2013-03-20 14:53:26129 if (active != time_source_->Active())
130 time_source_->SetActive(active);
[email protected]c1bb5af2013-03-13 19:06:27131 }
[email protected]94f206c12012-08-25 00:09:14132
[email protected]c1bb5af2013-03-13 19:06:27133 private:
134 LayerTreeHostImplTimeSourceAdapter(
135 LayerTreeHostImpl* layer_tree_host_impl,
136 scoped_refptr<DelayBasedTimeSource> time_source)
137 : layer_tree_host_impl_(layer_tree_host_impl),
138 time_source_(time_source) {
[email protected]6d0e69d2013-03-20 14:53:26139 time_source_->SetClient(this);
[email protected]c1bb5af2013-03-13 19:06:27140 }
[email protected]94f206c12012-08-25 00:09:14141
[email protected]c1bb5af2013-03-13 19:06:27142 LayerTreeHostImpl* layer_tree_host_impl_;
143 scoped_refptr<DelayBasedTimeSource> time_source_;
[email protected]94f206c12012-08-25 00:09:14144
[email protected]c1bb5af2013-03-13 19:06:27145 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImplTimeSourceAdapter);
[email protected]94f206c12012-08-25 00:09:14146};
147
[email protected]96baf3e2012-10-22 23:09:55148LayerTreeHostImpl::FrameData::FrameData()
[email protected]e0341352013-04-06 05:01:20149 : contains_incomplete_tile(false), has_no_damage(false) {}
[email protected]c1bb5af2013-03-13 19:06:27150
151LayerTreeHostImpl::FrameData::~FrameData() {}
152
153scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create(
154 const LayerTreeSettings& settings,
155 LayerTreeHostImplClient* client,
[email protected]372bad5f2013-03-21 16:38:43156 Proxy* proxy,
157 RenderingStatsInstrumentation* rendering_stats_instrumentation) {
158 return make_scoped_ptr(
159 new LayerTreeHostImpl(settings,
160 client,
161 proxy,
162 rendering_stats_instrumentation));
[email protected]493067512012-09-19 23:34:10163}
164
[email protected]372bad5f2013-03-21 16:38:43165LayerTreeHostImpl::LayerTreeHostImpl(
166 const LayerTreeSettings& settings,
167 LayerTreeHostImplClient* client,
168 Proxy* proxy,
169 RenderingStatsInstrumentation* rendering_stats_instrumentation)
[email protected]c1bb5af2013-03-13 19:06:27170 : client_(client),
171 proxy_(proxy),
[email protected]200a9c062013-05-20 04:34:37172 input_handler_client_(NULL),
[email protected]c1bb5af2013-03-13 19:06:27173 did_lock_scrolling_layer_(false),
174 should_bubble_scrolls_(false),
175 wheel_scrolling_(false),
[email protected]a23451e2013-06-07 20:58:26176 manage_tiles_needed_(false),
[email protected]1960a712013-04-30 17:06:47177 root_layer_scroll_offset_delegate_(NULL),
[email protected]c1bb5af2013-03-13 19:06:27178 settings_(settings),
[email protected]c1bb5af2013-03-13 19:06:27179 visible_(true),
180 managed_memory_policy_(
[email protected]b56c1302013-03-20 21:17:34181 PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
[email protected]c1bb5af2013-03-13 19:06:27182 ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING,
183 0,
184 ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING),
185 pinch_gesture_active_(false),
[email protected]9e3594522013-03-18 00:57:36186 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())),
[email protected]7497316a2013-03-15 12:42:29187 paint_time_counter_(PaintTimeCounter::Create()),
[email protected]c1bb5af2013-03-13 19:06:27188 memory_history_(MemoryHistory::Create()),
[email protected]d35992782013-03-14 14:54:02189 debug_rect_history_(DebugRectHistory::Create()),
[email protected]d7626ffd2013-03-29 00:17:42190 max_memory_needed_bytes_(0),
[email protected]c1bb5af2013-03-13 19:06:27191 last_sent_memory_visible_bytes_(0),
192 last_sent_memory_visible_and_nearby_bytes_(0),
193 last_sent_memory_use_bytes_(0),
[email protected]50644642013-06-20 13:58:55194 zero_budget_(false),
[email protected]f224cc92013-06-06 23:23:32195 device_scale_factor_(1.f),
196 overdraw_bottom_height_(0.f),
[email protected]372bad5f2013-03-21 16:38:43197 animation_registrar_(AnimationRegistrar::Create()),
[email protected]39643fb2013-07-09 17:28:19198 rendering_stats_instrumentation_(rendering_stats_instrumentation),
[email protected]8bb6cfa2013-07-23 00:11:19199 need_to_update_visible_tiles_before_draw_(false) {
[email protected]c1bb5af2013-03-13 19:06:27200 DCHECK(proxy_->IsImplThread());
201 DidVisibilityChange(this, visible_);
202
[email protected]8e0176d2013-03-21 03:14:52203 SetDebugState(settings.initial_debug_state);
[email protected]c1bb5af2013-03-13 19:06:27204
[email protected]8e0176d2013-03-21 03:14:52205 if (settings.calculate_top_controls_position) {
[email protected]c1bb5af2013-03-13 19:06:27206 top_controls_manager_ =
207 TopControlsManager::Create(this,
[email protected]8e0176d2013-03-21 03:14:52208 settings.top_controls_height,
209 settings.top_controls_show_threshold,
210 settings.top_controls_hide_threshold);
[email protected]c1bb5af2013-03-13 19:06:27211 }
212
[email protected]8e0176d2013-03-21 03:14:52213 SetDebugState(settings.initial_debug_state);
[email protected]c1bb5af2013-03-13 19:06:27214
215 // LTHI always has an active tree.
216 active_tree_ = LayerTreeImpl::create(this);
[email protected]9197dbcb2013-05-15 20:28:51217 TRACE_EVENT_OBJECT_CREATED_WITH_ID(
218 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", this);
[email protected]493067512012-09-19 23:34:10219}
220
[email protected]c1bb5af2013-03-13 19:06:27221LayerTreeHostImpl::~LayerTreeHostImpl() {
222 DCHECK(proxy_->IsImplThread());
223 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()");
[email protected]9197dbcb2013-05-15 20:28:51224 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
225 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", this);
[email protected]c1bb5af2013-03-13 19:06:27226
[email protected]200a9c062013-05-20 04:34:37227 if (input_handler_client_) {
228 input_handler_client_->WillShutdown();
229 input_handler_client_ = NULL;
230 }
231
[email protected]75deb742013-06-24 20:19:18232 // The layer trees must be destroyed before the layer tree host. We've
233 // made a contract with our animation controllers that the registrar
234 // will outlive them, and we must make good.
235 recycle_tree_.reset();
236 pending_tree_.reset();
237 active_tree_.reset();
[email protected]94f206c12012-08-25 00:09:14238}
239
[email protected]c1bb5af2013-03-13 19:06:27240void LayerTreeHostImpl::BeginCommit() {}
[email protected]3b31c6ac2012-12-06 21:27:29241
[email protected]c1bb5af2013-03-13 19:06:27242void LayerTreeHostImpl::CommitComplete() {
243 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete");
[email protected]131a0c22013-02-12 18:31:08244
[email protected]c1bb5af2013-03-13 19:06:27245 // Impl-side painting needs an update immediately post-commit to have the
246 // opportunity to create tilings. Other paths can call UpdateDrawProperties
247 // more lazily when needed prior to drawing.
[email protected]8e0176d2013-03-21 03:14:52248 if (settings_.impl_side_painting) {
[email protected]c1bb5af2013-03-13 19:06:27249 pending_tree_->set_needs_update_draw_properties();
[email protected]7d19dc342013-05-02 22:02:04250 pending_tree_->UpdateDrawProperties();
[email protected]a23451e2013-06-07 20:58:26251 // Start working on newly created tiles immediately if needed.
252 ManageTiles();
[email protected]c1bb5af2013-03-13 19:06:27253 } else {
254 active_tree_->set_needs_update_draw_properties();
255 }
[email protected]3ba4cae2013-01-16 03:58:38256
[email protected]c1bb5af2013-03-13 19:06:27257 client_->SendManagedMemoryStats();
[email protected]94f206c12012-08-25 00:09:14258}
259
[email protected]c1bb5af2013-03-13 19:06:27260bool LayerTreeHostImpl::CanDraw() {
261 // Note: If you are changing this function or any other function that might
262 // affect the result of CanDraw, make sure to call
263 // client_->OnCanDrawStateChanged in the proper places and update the
264 // NotifyIfCanDrawChanged test.
[email protected]94f206c12012-08-25 00:09:14265
[email protected]c1bb5af2013-03-13 19:06:27266 if (!active_tree_->root_layer()) {
[email protected]c76faea2013-03-26 07:42:42267 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw no root layer",
268 TRACE_EVENT_SCOPE_THREAD);
[email protected]2f1acc262012-11-16 21:42:22269 return false;
[email protected]c1bb5af2013-03-13 19:06:27270 }
271 if (device_viewport_size_.IsEmpty()) {
[email protected]c76faea2013-03-26 07:42:42272 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw empty viewport",
273 TRACE_EVENT_SCOPE_THREAD);
[email protected]c1bb5af2013-03-13 19:06:27274 return false;
275 }
276 if (active_tree_->ViewportSizeInvalid()) {
277 TRACE_EVENT_INSTANT0(
[email protected]c76faea2013-03-26 07:42:42278 "cc", "LayerTreeHostImpl::CanDraw viewport size recently changed",
279 TRACE_EVENT_SCOPE_THREAD);
[email protected]c1bb5af2013-03-13 19:06:27280 return false;
281 }
282 if (!renderer_) {
[email protected]c76faea2013-03-26 07:42:42283 TRACE_EVENT_INSTANT0("cc", "LayerTreeHostImpl::CanDraw no renderer",
284 TRACE_EVENT_SCOPE_THREAD);
[email protected]c1bb5af2013-03-13 19:06:27285 return false;
286 }
287 if (active_tree_->ContentsTexturesPurged()) {
288 TRACE_EVENT_INSTANT0(
[email protected]c76faea2013-03-26 07:42:42289 "cc", "LayerTreeHostImpl::CanDraw contents textures purged",
290 TRACE_EVENT_SCOPE_THREAD);
[email protected]c1bb5af2013-03-13 19:06:27291 return false;
292 }
293 return true;
[email protected]2f1acc262012-11-16 21:42:22294}
295
[email protected]c1bb5af2013-03-13 19:06:27296void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time,
297 base::Time wall_clock_time) {
[email protected]200a9c062013-05-20 04:34:37298 if (input_handler_client_)
299 input_handler_client_->Animate(monotonic_time);
[email protected]c1bb5af2013-03-13 19:06:27300 AnimatePageScale(monotonic_time);
301 AnimateLayers(monotonic_time, wall_clock_time);
302 AnimateScrollbars(monotonic_time);
[email protected]ffb2720f2013-03-15 19:18:37303 AnimateTopControls(monotonic_time);
[email protected]94f206c12012-08-25 00:09:14304}
305
[email protected]c1bb5af2013-03-13 19:06:27306void LayerTreeHostImpl::ManageTiles() {
[email protected]a23451e2013-06-07 20:58:26307 if (!tile_manager_)
308 return;
309 if (!manage_tiles_needed_)
310 return;
311 manage_tiles_needed_ = false;
[email protected]c1bb5af2013-03-13 19:06:27312 tile_manager_->ManageTiles();
313
314 size_t memory_required_bytes;
315 size_t memory_nice_to_have_bytes;
316 size_t memory_used_bytes;
317 tile_manager_->GetMemoryStats(&memory_required_bytes,
318 &memory_nice_to_have_bytes,
319 &memory_used_bytes);
320 SendManagedMemoryStats(memory_required_bytes,
321 memory_nice_to_have_bytes,
322 memory_used_bytes);
[email protected]f57bbc02012-11-21 07:02:15323}
324
[email protected]c1bb5af2013-03-13 19:06:27325void LayerTreeHostImpl::StartPageScaleAnimation(gfx::Vector2d target_offset,
326 bool anchor_point,
327 float page_scale,
328 base::TimeTicks start_time,
329 base::TimeDelta duration) {
330 if (!RootScrollLayer())
331 return;
332
333 gfx::Vector2dF scroll_total =
[email protected]1960a712013-04-30 17:06:47334 RootScrollLayer()->scroll_offset() + RootScrollLayer()->ScrollDelta();
[email protected]c1bb5af2013-03-13 19:06:27335 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize();
[email protected]6fc4ee002013-03-26 23:39:51336 gfx::SizeF viewport_size = VisibleViewportSize();
[email protected]c1bb5af2013-03-13 19:06:27337
338 double start_time_seconds = (start_time - base::TimeTicks()).InSecondsF();
[email protected]85d136f782013-04-26 22:04:40339
340 // Easing constants experimentally determined.
341 scoped_ptr<TimingFunction> timing_function =
342 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>();
343
[email protected]c1bb5af2013-03-13 19:06:27344 page_scale_animation_ =
345 PageScaleAnimation::Create(scroll_total,
346 active_tree_->total_page_scale_factor(),
347 viewport_size,
348 scaled_scrollable_size,
[email protected]85d136f782013-04-26 22:04:40349 start_time_seconds,
350 timing_function.Pass());
[email protected]c1bb5af2013-03-13 19:06:27351
352 if (anchor_point) {
353 gfx::Vector2dF anchor(target_offset);
354 page_scale_animation_->ZoomWithAnchor(anchor,
355 page_scale,
356 duration.InSecondsF());
357 } else {
358 gfx::Vector2dF scaled_target_offset = target_offset;
359 page_scale_animation_->ZoomTo(scaled_target_offset,
360 page_scale,
361 duration.InSecondsF());
362 }
363
364 client_->SetNeedsRedrawOnImplThread();
365 client_->SetNeedsCommitOnImplThread();
366 client_->RenewTreePriority();
[email protected]f57bbc02012-11-21 07:02:15367}
368
[email protected]c1bb5af2013-03-13 19:06:27369void LayerTreeHostImpl::ScheduleAnimation() {
370 client_->SetNeedsRedrawOnImplThread();
[email protected]f57bbc02012-11-21 07:02:15371}
372
[email protected]c1bb5af2013-03-13 19:06:27373bool LayerTreeHostImpl::HaveTouchEventHandlersAt(gfx::Point viewport_point) {
374 if (!EnsureRenderSurfaceLayerList())
375 return false;
[email protected]f57bbc02012-11-21 07:02:15376
[email protected]c1bb5af2013-03-13 19:06:27377 gfx::PointF device_viewport_point =
378 gfx::ScalePoint(viewport_point, device_scale_factor_);
[email protected]f57bbc02012-11-21 07:02:15379
[email protected]c1bb5af2013-03-13 19:06:27380 // First find out which layer was hit from the saved list of visible layers
381 // in the most recent frame.
[email protected]6ba914122013-03-22 16:26:39382 LayerImpl* layer_impl = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
[email protected]c1bb5af2013-03-13 19:06:27383 device_viewport_point,
384 active_tree_->RenderSurfaceLayerList());
[email protected]f57bbc02012-11-21 07:02:15385
[email protected]c1bb5af2013-03-13 19:06:27386 // Walk up the hierarchy and look for a layer with a touch event handler
387 // region that the given point hits.
388 for (; layer_impl; layer_impl = layer_impl->parent()) {
[email protected]6ba914122013-03-22 16:26:39389 if (LayerTreeHostCommon::LayerHasTouchEventHandlersAt(device_viewport_point,
[email protected]c1bb5af2013-03-13 19:06:27390 layer_impl))
391 return true;
392 }
[email protected]f57bbc02012-11-21 07:02:15393
[email protected]c1bb5af2013-03-13 19:06:27394 return false;
395}
396
[email protected]b76329d2013-06-11 04:15:08397void LayerTreeHostImpl::SetLatencyInfoForInputEvent(
398 const ui::LatencyInfo& latency_info) {
399 active_tree()->SetLatencyInfo(latency_info);
400}
401
[email protected]c1bb5af2013-03-13 19:06:27402void LayerTreeHostImpl::TrackDamageForAllSurfaces(
403 LayerImpl* root_draw_layer,
[email protected]50761e92013-03-29 20:51:28404 const LayerImplList& render_surface_layer_list) {
[email protected]c1bb5af2013-03-13 19:06:27405 // For now, we use damage tracking to compute a global scissor. To do this, we
406 // must compute all damage tracking before drawing anything, so that we know
407 // the root damage rect. The root damage rect is then used to scissor each
408 // surface.
409
410 for (int surface_index = render_surface_layer_list.size() - 1;
[email protected]bf691c22013-03-26 21:15:06411 surface_index >= 0;
[email protected]c1bb5af2013-03-13 19:06:27412 --surface_index) {
413 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index];
414 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
415 DCHECK(render_surface);
416 render_surface->damage_tracker()->UpdateDamageTrackingState(
417 render_surface->layer_list(),
418 render_surface_layer->id(),
419 render_surface->SurfacePropertyChangedOnlyFromDescendant(),
420 render_surface->content_rect(),
421 render_surface_layer->mask_layer(),
422 render_surface_layer->filters(),
423 render_surface_layer->filter().get());
424 }
425}
426
427void LayerTreeHostImpl::FrameData::AppendRenderPass(
428 scoped_ptr<RenderPass> render_pass) {
429 render_passes_by_id[render_pass->id] = render_pass.get();
430 render_passes.push_back(render_pass.Pass());
431}
432
[email protected]ffbb2212013-06-02 23:47:59433static DrawMode GetDrawMode(OutputSurface* output_surface) {
434 if (output_surface->ForcedDrawToSoftwareDevice()) {
435 return DRAW_MODE_RESOURCELESS_SOFTWARE;
436 } else if (output_surface->context3d()) {
437 return DRAW_MODE_HARDWARE;
438 } else {
439 DCHECK(output_surface->software_device());
440 return DRAW_MODE_SOFTWARE;
441 }
442}
443
[email protected]c1bb5af2013-03-13 19:06:27444static void AppendQuadsForLayer(RenderPass* target_render_pass,
445 LayerImpl* layer,
446 const OcclusionTrackerImpl& occlusion_tracker,
447 AppendQuadsData* append_quads_data) {
448 bool for_surface = false;
[email protected]c7e95b42013-03-18 01:13:49449 QuadCuller quad_culler(&target_render_pass->quad_list,
450 &target_render_pass->shared_quad_state_list,
[email protected]c1bb5af2013-03-13 19:06:27451 layer,
452 occlusion_tracker,
453 layer->ShowDebugBorders(),
454 for_surface);
455 layer->AppendQuads(&quad_culler, append_quads_data);
456}
457
458static void AppendQuadsForRenderSurfaceLayer(
459 RenderPass* target_render_pass,
460 LayerImpl* layer,
461 const RenderPass* contributing_render_pass,
462 const OcclusionTrackerImpl& occlusion_tracker,
463 AppendQuadsData* append_quads_data) {
464 bool for_surface = true;
[email protected]c7e95b42013-03-18 01:13:49465 QuadCuller quad_culler(&target_render_pass->quad_list,
466 &target_render_pass->shared_quad_state_list,
[email protected]c1bb5af2013-03-13 19:06:27467 layer,
468 occlusion_tracker,
469 layer->ShowDebugBorders(),
470 for_surface);
471
472 bool is_replica = false;
473 layer->render_surface()->AppendQuads(&quad_culler,
474 append_quads_data,
475 is_replica,
476 contributing_render_pass->id);
477
478 // Add replica after the surface so that it appears below the surface.
479 if (layer->has_replica()) {
480 is_replica = true;
481 layer->render_surface()->AppendQuads(&quad_culler,
482 append_quads_data,
483 is_replica,
484 contributing_render_pass->id);
485 }
486}
487
488static void AppendQuadsToFillScreen(
489 RenderPass* target_render_pass,
490 LayerImpl* root_layer,
491 SkColor screen_background_color,
492 const OcclusionTrackerImpl& occlusion_tracker) {
493 if (!root_layer || !SkColorGetA(screen_background_color))
494 return;
495
496 Region fill_region = occlusion_tracker.ComputeVisibleRegionInScreen();
497 if (fill_region.IsEmpty())
498 return;
499
500 bool for_surface = false;
[email protected]c7e95b42013-03-18 01:13:49501 QuadCuller quad_culler(&target_render_pass->quad_list,
502 &target_render_pass->shared_quad_state_list,
[email protected]c1bb5af2013-03-13 19:06:27503 root_layer,
504 occlusion_tracker,
505 root_layer->ShowDebugBorders(),
506 for_surface);
507
508 // Manually create the quad state for the gutter quads, as the root layer
509 // doesn't have any bounds and so can't generate this itself.
510 // TODO(danakj): Make the gutter quads generated by the solid color layer
511 // (make it smarter about generating quads to fill unoccluded areas).
512
513 gfx::Rect root_target_rect = root_layer->render_surface()->content_rect();
514 float opacity = 1.f;
515 SharedQuadState* shared_quad_state =
[email protected]c7e95b42013-03-18 01:13:49516 quad_culler.UseSharedQuadState(SharedQuadState::Create());
[email protected]c1bb5af2013-03-13 19:06:27517 shared_quad_state->SetAll(root_layer->draw_transform(),
518 root_target_rect.size(),
519 root_target_rect,
520 root_target_rect,
[email protected]dc462d782012-11-21 21:43:01521 false,
[email protected]f57bbc02012-11-21 07:02:15522 opacity);
523
[email protected]c1bb5af2013-03-13 19:06:27524 AppendQuadsData append_quads_data;
[email protected]bda41962013-01-07 18:46:17525
[email protected]c1bb5af2013-03-13 19:06:27526 gfx::Transform transform_to_layer_space(gfx::Transform::kSkipInitialization);
527 bool did_invert = root_layer->screen_space_transform().GetInverse(
528 &transform_to_layer_space);
529 DCHECK(did_invert);
530 for (Region::Iterator fill_rects(fill_region);
531 fill_rects.has_rect();
532 fill_rects.next()) {
533 // The root layer transform is composed of translations and scales only,
534 // no perspective, so mapping is sufficient (as opposed to projecting).
535 gfx::Rect layer_rect =
[email protected]fa816c62013-03-18 04:24:21536 MathUtil::MapClippedRect(transform_to_layer_space, fill_rects.rect());
[email protected]c1bb5af2013-03-13 19:06:27537 // Skip the quad culler and just append the quads directly to avoid
538 // occlusion checks.
539 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
[email protected]10a30b12013-05-02 16:42:11540 quad->SetNew(shared_quad_state, layer_rect, screen_background_color, false);
[email protected]c7e95b42013-03-18 01:13:49541 quad_culler.Append(quad.PassAs<DrawQuad>(), &append_quads_data);
[email protected]c1bb5af2013-03-13 19:06:27542 }
[email protected]467b3612012-08-28 07:41:16543}
544
[email protected]c1bb5af2013-03-13 19:06:27545bool LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) {
546 DCHECK(frame->render_passes.empty());
[email protected]94f206c12012-08-25 00:09:14547
[email protected]c1bb5af2013-03-13 19:06:27548 if (!CanDraw() || !active_tree_->root_layer())
549 return false;
[email protected]2d692992012-12-19 01:19:32550
[email protected]c1bb5af2013-03-13 19:06:27551 TrackDamageForAllSurfaces(active_tree_->root_layer(),
552 *frame->render_surface_layer_list);
[email protected]94f206c12012-08-25 00:09:14553
[email protected]e0341352013-04-06 05:01:20554 // If the root render surface has no visible damage, then don't generate a
555 // frame at all.
556 RenderSurfaceImpl* root_surface =
557 active_tree_->root_layer()->render_surface();
558 bool root_surface_has_no_visible_damage =
559 !root_surface->damage_tracker()->current_damage_rect().Intersects(
560 root_surface->content_rect());
561 bool root_surface_has_contributing_layers =
562 !root_surface->layer_list().empty();
563 if (root_surface_has_contributing_layers &&
564 root_surface_has_no_visible_damage) {
565 TRACE_EVENT0("cc",
566 "LayerTreeHostImpl::CalculateRenderPasses::EmptyDamageRect");
567 frame->has_no_damage = true;
[email protected]30fe19ff2013-07-04 00:54:45568 // A copy request should cause damage, so we should not have any copy
569 // requests in this case.
570 DCHECK_EQ(0u, active_tree_->LayersWithCopyOutputRequest().size());
[email protected]e0341352013-04-06 05:01:20571 return true;
572 }
573
[email protected]c1bb5af2013-03-13 19:06:27574 TRACE_EVENT1("cc",
575 "LayerTreeHostImpl::CalculateRenderPasses",
576 "render_surface_layer_list.size()",
[email protected]bf691c22013-03-26 21:15:06577 static_cast<uint64>(frame->render_surface_layer_list->size()));
[email protected]94f206c12012-08-25 00:09:14578
[email protected]c1bb5af2013-03-13 19:06:27579 // Create the render passes in dependency order.
580 for (int surface_index = frame->render_surface_layer_list->size() - 1;
[email protected]bf691c22013-03-26 21:15:06581 surface_index >= 0;
[email protected]c1bb5af2013-03-13 19:06:27582 --surface_index) {
583 LayerImpl* render_surface_layer =
584 (*frame->render_surface_layer_list)[surface_index];
[email protected]30fe19ff2013-07-04 00:54:45585 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
586
587 bool should_draw_into_render_pass =
588 render_surface_layer->parent() == NULL ||
589 render_surface->contributes_to_drawn_surface() ||
590 render_surface_layer->HasCopyRequest();
591 if (should_draw_into_render_pass)
592 render_surface_layer->render_surface()->AppendRenderPasses(frame);
[email protected]c1bb5af2013-03-13 19:06:27593 }
[email protected]94f206c12012-08-25 00:09:14594
[email protected]c1bb5af2013-03-13 19:06:27595 bool record_metrics_for_frame =
[email protected]8e0176d2013-03-21 03:14:52596 settings_.show_overdraw_in_tracing &&
[email protected]c1bb5af2013-03-13 19:06:27597 base::debug::TraceLog::GetInstance() &&
598 base::debug::TraceLog::GetInstance()->IsEnabled();
599 OcclusionTrackerImpl occlusion_tracker(
600 active_tree_->root_layer()->render_surface()->content_rect(),
601 record_metrics_for_frame);
602 occlusion_tracker.set_minimum_tracking_size(
[email protected]8e0176d2013-03-21 03:14:52603 settings_.minimum_occlusion_tracking_size);
[email protected]94f206c12012-08-25 00:09:14604
[email protected]846f455b2013-03-18 19:07:41605 if (debug_state_.show_occluding_rects) {
[email protected]c1bb5af2013-03-13 19:06:27606 occlusion_tracker.set_occluding_screen_space_rects_container(
607 &frame->occluding_screen_space_rects);
608 }
[email protected]846f455b2013-03-18 19:07:41609 if (debug_state_.show_non_occluding_rects) {
[email protected]c1bb5af2013-03-13 19:06:27610 occlusion_tracker.set_non_occluding_screen_space_rects_container(
611 &frame->non_occluding_screen_space_rects);
612 }
[email protected]94f206c12012-08-25 00:09:14613
[email protected]c1bb5af2013-03-13 19:06:27614 // Add quads to the Render passes in FrontToBack order to allow for testing
615 // occlusion and performing culling during the tree walk.
616 typedef LayerIterator<LayerImpl,
[email protected]50761e92013-03-29 20:51:28617 LayerImplList,
[email protected]c1bb5af2013-03-13 19:06:27618 RenderSurfaceImpl,
619 LayerIteratorActions::FrontToBack> LayerIteratorType;
[email protected]94f206c12012-08-25 00:09:14620
[email protected]c1bb5af2013-03-13 19:06:27621 // Typically when we are missing a texture and use a checkerboard quad, we
622 // still draw the frame. However when the layer being checkerboarded is moving
623 // due to an impl-animation, we drop the frame to avoid flashing due to the
624 // texture suddenly appearing in the future.
625 bool draw_frame = true;
[email protected]18a70192013-04-26 16:18:25626 // When we have a copy request for a layer, we need to draw no matter
627 // what, as the layer may disappear after this frame.
628 bool have_copy_request = false;
[email protected]94f206c12012-08-25 00:09:14629
[email protected]372bad5f2013-03-21 16:38:43630 int layers_drawn = 0;
631
[email protected]ffbb2212013-06-02 23:47:59632 const DrawMode draw_mode = GetDrawMode(output_surface_.get());
633
[email protected]c1bb5af2013-03-13 19:06:27634 LayerIteratorType end =
[email protected]71dfcc72013-03-20 21:30:09635 LayerIteratorType::End(frame->render_surface_layer_list);
[email protected]c1bb5af2013-03-13 19:06:27636 for (LayerIteratorType it =
[email protected]71dfcc72013-03-20 21:30:09637 LayerIteratorType::Begin(frame->render_surface_layer_list);
[email protected]c1bb5af2013-03-13 19:06:27638 it != end;
639 ++it) {
640 RenderPass::Id target_render_pass_id =
[email protected]71dfcc72013-03-20 21:30:09641 it.target_render_surface_layer()->render_surface()->RenderPassId();
[email protected]c1bb5af2013-03-13 19:06:27642 RenderPass* target_render_pass =
643 frame->render_passes_by_id[target_render_pass_id];
[email protected]94f206c12012-08-25 00:09:14644
[email protected]0e5f7142013-05-24 06:45:36645 bool prevent_occlusion = it.target_render_surface_layer()->HasCopyRequest();
[email protected]2ea5e6c2013-04-26 21:52:23646 occlusion_tracker.EnterLayer(it, prevent_occlusion);
[email protected]94f206c12012-08-25 00:09:14647
[email protected]30fe19ff2013-07-04 00:54:45648 AppendQuadsData append_quads_data(target_render_pass_id);
[email protected]89228202012-08-29 03:20:30649
[email protected]18a70192013-04-26 16:18:25650 if (it.represents_target_render_surface()) {
[email protected]0e5f7142013-05-24 06:45:36651 if (it->HasCopyRequest()) {
[email protected]18a70192013-04-26 16:18:25652 have_copy_request = true;
[email protected]d4d017e2013-06-20 21:46:11653 it->TakeCopyRequestsAndTransformToTarget(
654 &target_render_pass->copy_requests);
[email protected]18a70192013-04-26 16:18:25655 }
[email protected]30fe19ff2013-07-04 00:54:45656 } else if (it.represents_contributing_render_surface() &&
657 it->render_surface()->contributes_to_drawn_surface()) {
[email protected]c1bb5af2013-03-13 19:06:27658 RenderPass::Id contributing_render_pass_id =
659 it->render_surface()->RenderPassId();
660 RenderPass* contributing_render_pass =
661 frame->render_passes_by_id[contributing_render_pass_id];
662 AppendQuadsForRenderSurfaceLayer(target_render_pass,
663 *it,
664 contributing_render_pass,
665 occlusion_tracker,
666 &append_quads_data);
[email protected]e1e768f2013-03-26 08:48:09667 } else if (it.represents_itself() &&
668 !it->visible_content_rect().IsEmpty()) {
[email protected]c1bb5af2013-03-13 19:06:27669 bool has_occlusion_from_outside_target_surface;
670 bool impl_draw_transform_is_unknown = false;
671 if (occlusion_tracker.Occluded(
672 it->render_target(),
673 it->visible_content_rect(),
674 it->draw_transform(),
675 impl_draw_transform_is_unknown,
676 it->is_clipped(),
677 it->clip_rect(),
678 &has_occlusion_from_outside_target_surface)) {
[email protected]e1e768f2013-03-26 08:48:09679 append_quads_data.had_occlusion_from_outside_target_surface |=
[email protected]c1bb5af2013-03-13 19:06:27680 has_occlusion_from_outside_target_surface;
[email protected]ffbb2212013-06-02 23:47:59681 } else if (it->WillDraw(draw_mode, resource_provider_.get())) {
[email protected]c1bb5af2013-03-13 19:06:27682 DCHECK_EQ(active_tree_, it->layer_tree_impl());
[email protected]ffbb2212013-06-02 23:47:59683
[email protected]c1bb5af2013-03-13 19:06:27684 frame->will_draw_layers.push_back(*it);
[email protected]7d929c02012-09-20 17:26:57685
[email protected]c1bb5af2013-03-13 19:06:27686 if (it->HasContributingDelegatedRenderPasses()) {
687 RenderPass::Id contributing_render_pass_id =
688 it->FirstContributingRenderPassId();
689 while (frame->render_passes_by_id.find(contributing_render_pass_id) !=
690 frame->render_passes_by_id.end()) {
691 RenderPass* render_pass =
692 frame->render_passes_by_id[contributing_render_pass_id];
[email protected]f5864912013-02-01 03:18:14693
[email protected]c1bb5af2013-03-13 19:06:27694 AppendQuadsData append_quads_data(render_pass->id);
695 AppendQuadsForLayer(render_pass,
696 *it,
697 occlusion_tracker,
698 &append_quads_data);
[email protected]7d929c02012-09-20 17:26:57699
[email protected]c1bb5af2013-03-13 19:06:27700 contributing_render_pass_id =
701 it->NextContributingRenderPassId(contributing_render_pass_id);
702 }
[email protected]94f206c12012-08-25 00:09:14703 }
704
[email protected]c1bb5af2013-03-13 19:06:27705 AppendQuadsForLayer(target_render_pass,
706 *it,
707 occlusion_tracker,
708 &append_quads_data);
709 }
[email protected]89228202012-08-29 03:20:30710
[email protected]372bad5f2013-03-21 16:38:43711 ++layers_drawn;
[email protected]94f206c12012-08-25 00:09:14712 }
713
[email protected]e1e768f2013-03-26 08:48:09714 if (append_quads_data.had_occlusion_from_outside_target_surface)
[email protected]c1bb5af2013-03-13 19:06:27715 target_render_pass->has_occlusion_from_outside_target_surface = true;
716
[email protected]e1e768f2013-03-26 08:48:09717 if (append_quads_data.num_missing_tiles) {
[email protected]372bad5f2013-03-21 16:38:43718 rendering_stats_instrumentation_->AddMissingTiles(
[email protected]e1e768f2013-03-26 08:48:09719 append_quads_data.num_missing_tiles);
[email protected]c1bb5af2013-03-13 19:06:27720 bool layer_has_animating_transform =
721 it->screen_space_transform_is_animating() ||
722 it->draw_transform_is_animating();
723 if (layer_has_animating_transform)
724 draw_frame = false;
725 }
726
[email protected]e1e768f2013-03-26 08:48:09727 if (append_quads_data.had_incomplete_tile)
[email protected]c1bb5af2013-03-13 19:06:27728 frame->contains_incomplete_tile = true;
729
730 occlusion_tracker.LeaveLayer(it);
731 }
732
[email protected]18a70192013-04-26 16:18:25733 if (have_copy_request)
734 draw_frame = true;
735
[email protected]372bad5f2013-03-21 16:38:43736 rendering_stats_instrumentation_->AddLayersDrawn(layers_drawn);
737
[email protected]1d993172012-10-18 18:15:04738#ifndef NDEBUG
[email protected]c1bb5af2013-03-13 19:06:27739 for (size_t i = 0; i < frame->render_passes.size(); ++i) {
740 for (size_t j = 0; j < frame->render_passes[i]->quad_list.size(); ++j)
741 DCHECK(frame->render_passes[i]->quad_list[j]->shared_quad_state);
742 DCHECK(frame->render_passes_by_id.find(frame->render_passes[i]->id)
743 != frame->render_passes_by_id.end());
744 }
[email protected]94f206c12012-08-25 00:09:14745#endif
[email protected]c1bb5af2013-03-13 19:06:27746 DCHECK(frame->render_passes.back()->output_rect.origin().IsOrigin());
[email protected]94f206c12012-08-25 00:09:14747
[email protected]c1bb5af2013-03-13 19:06:27748 if (!active_tree_->has_transparent_background()) {
749 frame->render_passes.back()->has_transparent_background = false;
750 AppendQuadsToFillScreen(frame->render_passes.back(),
751 active_tree_->root_layer(),
752 active_tree_->background_color(),
753 occlusion_tracker);
754 }
[email protected]94f206c12012-08-25 00:09:14755
[email protected]c1bb5af2013-03-13 19:06:27756 if (draw_frame)
757 occlusion_tracker.overdraw_metrics()->RecordMetrics(this);
[email protected]18a70192013-04-26 16:18:25758 else
759 DCHECK(!have_copy_request);
[email protected]94f206c12012-08-25 00:09:14760
[email protected]c1bb5af2013-03-13 19:06:27761 RemoveRenderPasses(CullRenderPassesWithNoQuads(), frame);
[email protected]b09c1942013-05-10 00:06:37762 if (!output_surface_->ForcedDrawToSoftwareDevice())
763 renderer_->DecideRenderPassAllocationsForFrame(frame->render_passes);
[email protected]d15d9622013-06-21 02:49:15764 RemoveRenderPasses(CullRenderPassesWithCachedTextures(renderer_.get()),
765 frame);
[email protected]94f206c12012-08-25 00:09:14766
[email protected]30fe19ff2013-07-04 00:54:45767 // Any copy requests left in the tree are not going to get serviced, and
768 // should be aborted.
769 ScopedPtrVector<CopyOutputRequest> requests_to_abort;
770 while (!active_tree_->LayersWithCopyOutputRequest().empty()) {
771 LayerImpl* layer = active_tree_->LayersWithCopyOutputRequest().back();
772 layer->TakeCopyRequestsAndTransformToTarget(&requests_to_abort);
773 }
774 for (size_t i = 0; i < requests_to_abort.size(); ++i)
775 requests_to_abort[i]->SendEmptyResult();
776
[email protected]e0341352013-04-06 05:01:20777 // If we're making a frame to draw, it better have at least one render pass.
778 DCHECK(!frame->render_passes.empty());
[email protected]c1bb5af2013-03-13 19:06:27779 return draw_frame;
[email protected]94f206c12012-08-25 00:09:14780}
781
[email protected]200a9c062013-05-20 04:34:37782void LayerTreeHostImpl::MainThreadHasStoppedFlinging() {
783 if (input_handler_client_)
784 input_handler_client_->MainThreadHasStoppedFlinging();
785}
786
[email protected]3d9f7432013-04-06 00:35:18787void LayerTreeHostImpl::UpdateBackgroundAnimateTicking(
788 bool should_background_tick) {
[email protected]810d40b72013-06-20 18:26:15789 DCHECK(proxy_->IsImplThread());
790
[email protected]3d9f7432013-04-06 00:35:18791 bool enabled = should_background_tick &&
792 !animation_registrar_->active_animation_controllers().empty();
793
[email protected]c1bb5af2013-03-13 19:06:27794 // Lazily create the time_source adapter so that we can vary the interval for
795 // testing.
796 if (!time_source_client_adapter_) {
797 time_source_client_adapter_ = LayerTreeHostImplTimeSourceAdapter::Create(
798 this,
[email protected]810d40b72013-06-20 18:26:15799 DelayBasedTimeSource::Create(
800 LowFrequencyAnimationInterval(),
801 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner()
802 : proxy_->MainThreadTaskRunner()));
[email protected]c1bb5af2013-03-13 19:06:27803 }
[email protected]94f206c12012-08-25 00:09:14804
[email protected]c1bb5af2013-03-13 19:06:27805 time_source_client_adapter_->SetActive(enabled);
[email protected]94f206c12012-08-25 00:09:14806}
807
[email protected]b9d4a362013-04-23 05:36:27808void LayerTreeHostImpl::SetViewportDamage(gfx::Rect damage_rect) {
[email protected]878705be2013-04-15 22:44:02809 viewport_damage_rect_.Union(damage_rect);
810}
811
[email protected]c1bb5af2013-03-13 19:06:27812static inline RenderPass* FindRenderPassById(
813 RenderPass::Id render_pass_id,
814 const LayerTreeHostImpl::FrameData& frame) {
815 RenderPassIdHashMap::const_iterator it =
816 frame.render_passes_by_id.find(render_pass_id);
817 return it != frame.render_passes_by_id.end() ? it->second : NULL;
[email protected]94f206c12012-08-25 00:09:14818}
819
[email protected]c1bb5af2013-03-13 19:06:27820static void RemoveRenderPassesRecursive(RenderPass::Id remove_render_pass_id,
821 LayerTreeHostImpl::FrameData* frame) {
822 RenderPass* remove_render_pass =
823 FindRenderPassById(remove_render_pass_id, *frame);
824 // The pass was already removed by another quad - probably the original, and
825 // we are the replica.
826 if (!remove_render_pass)
827 return;
828 RenderPassList& render_passes = frame->render_passes;
829 RenderPassList::iterator to_remove = std::find(render_passes.begin(),
830 render_passes.end(),
831 remove_render_pass);
[email protected]94f206c12012-08-25 00:09:14832
[email protected]c1bb5af2013-03-13 19:06:27833 DCHECK(to_remove != render_passes.end());
[email protected]94f206c12012-08-25 00:09:14834
[email protected]c1bb5af2013-03-13 19:06:27835 scoped_ptr<RenderPass> removed_pass = render_passes.take(to_remove);
836 frame->render_passes.erase(to_remove);
837 frame->render_passes_by_id.erase(remove_render_pass_id);
[email protected]94f206c12012-08-25 00:09:14838
[email protected]c1bb5af2013-03-13 19:06:27839 // Now follow up for all RenderPass quads and remove their RenderPasses
840 // recursively.
841 const QuadList& quad_list = removed_pass->quad_list;
[email protected]ed511b8d2013-03-25 03:29:29842 QuadList::ConstBackToFrontIterator quad_list_iterator =
843 quad_list.BackToFrontBegin();
844 for (; quad_list_iterator != quad_list.BackToFrontEnd();
[email protected]c1bb5af2013-03-13 19:06:27845 ++quad_list_iterator) {
846 DrawQuad* current_quad = (*quad_list_iterator);
847 if (current_quad->material != DrawQuad::RENDER_PASS)
848 continue;
[email protected]94f206c12012-08-25 00:09:14849
[email protected]c1bb5af2013-03-13 19:06:27850 RenderPass::Id next_remove_render_pass_id =
851 RenderPassDrawQuad::MaterialCast(current_quad)->render_pass_id;
852 RemoveRenderPassesRecursive(next_remove_render_pass_id, frame);
853 }
[email protected]94f206c12012-08-25 00:09:14854}
855
[email protected]c1bb5af2013-03-13 19:06:27856bool LayerTreeHostImpl::CullRenderPassesWithCachedTextures::
857 ShouldRemoveRenderPass(const RenderPassDrawQuad& quad,
858 const FrameData& frame) const {
[email protected]fbe89f72013-05-21 07:24:24859 DCHECK(renderer_);
[email protected]c1bb5af2013-03-13 19:06:27860 bool quad_has_damage = !quad.contents_changed_since_last_frame.IsEmpty();
861 bool quad_has_cached_resource =
[email protected]bf691c22013-03-26 21:15:06862 renderer_->HaveCachedResourcesForRenderPassId(quad.render_pass_id);
[email protected]c1bb5af2013-03-13 19:06:27863 if (quad_has_damage) {
864 TRACE_EVENT0("cc", "CullRenderPassesWithCachedTextures have damage");
865 return false;
866 } else if (!quad_has_cached_resource) {
867 TRACE_EVENT0("cc", "CullRenderPassesWithCachedTextures have no texture");
868 return false;
869 }
870 TRACE_EVENT0("cc", "CullRenderPassesWithCachedTextures dropped!");
871 return true;
[email protected]94f206c12012-08-25 00:09:14872}
873
[email protected]c1bb5af2013-03-13 19:06:27874bool LayerTreeHostImpl::CullRenderPassesWithNoQuads::ShouldRemoveRenderPass(
875 const RenderPassDrawQuad& quad, const FrameData& frame) const {
876 const RenderPass* render_pass =
877 FindRenderPassById(quad.render_pass_id, frame);
878 if (!render_pass)
879 return false;
[email protected]94f206c12012-08-25 00:09:14880
[email protected]c1bb5af2013-03-13 19:06:27881 // If any quad or RenderPass draws into this RenderPass, then keep it.
882 const QuadList& quad_list = render_pass->quad_list;
[email protected]ed511b8d2013-03-25 03:29:29883 for (QuadList::ConstBackToFrontIterator quad_list_iterator =
884 quad_list.BackToFrontBegin();
885 quad_list_iterator != quad_list.BackToFrontEnd();
[email protected]c1bb5af2013-03-13 19:06:27886 ++quad_list_iterator) {
887 DrawQuad* current_quad = *quad_list_iterator;
[email protected]94f206c12012-08-25 00:09:14888
[email protected]c1bb5af2013-03-13 19:06:27889 if (current_quad->material != DrawQuad::RENDER_PASS)
890 return false;
[email protected]94f206c12012-08-25 00:09:14891
[email protected]c1bb5af2013-03-13 19:06:27892 const RenderPass* contributing_pass = FindRenderPassById(
893 RenderPassDrawQuad::MaterialCast(current_quad)->render_pass_id, frame);
894 if (contributing_pass)
895 return false;
896 }
897 return true;
[email protected]94f206c12012-08-25 00:09:14898}
899
900// Defined for linking tests.
[email protected]c1bb5af2013-03-13 19:06:27901template CC_EXPORT void LayerTreeHostImpl::RemoveRenderPasses<
902 LayerTreeHostImpl::CullRenderPassesWithCachedTextures>(
903 CullRenderPassesWithCachedTextures culler, FrameData* frame);
904template CC_EXPORT void LayerTreeHostImpl::RemoveRenderPasses<
905 LayerTreeHostImpl::CullRenderPassesWithNoQuads>(
906 CullRenderPassesWithNoQuads culler, FrameData*);
[email protected]94f206c12012-08-25 00:09:14907
908// static
[email protected]c1bb5af2013-03-13 19:06:27909template <typename RenderPassCuller>
910void LayerTreeHostImpl::RemoveRenderPasses(RenderPassCuller culler,
911 FrameData* frame) {
912 for (size_t it = culler.RenderPassListBegin(frame->render_passes);
913 it != culler.RenderPassListEnd(frame->render_passes);
914 it = culler.RenderPassListNext(it)) {
915 const RenderPass* current_pass = frame->render_passes[it];
916 const QuadList& quad_list = current_pass->quad_list;
[email protected]ed511b8d2013-03-25 03:29:29917 QuadList::ConstBackToFrontIterator quad_list_iterator =
918 quad_list.BackToFrontBegin();
[email protected]94f206c12012-08-25 00:09:14919
[email protected]ed511b8d2013-03-25 03:29:29920 for (; quad_list_iterator != quad_list.BackToFrontEnd();
[email protected]c1bb5af2013-03-13 19:06:27921 ++quad_list_iterator) {
922 DrawQuad* current_quad = *quad_list_iterator;
[email protected]94f206c12012-08-25 00:09:14923
[email protected]c1bb5af2013-03-13 19:06:27924 if (current_quad->material != DrawQuad::RENDER_PASS)
925 continue;
[email protected]94f206c12012-08-25 00:09:14926
[email protected]c1bb5af2013-03-13 19:06:27927 const RenderPassDrawQuad* render_pass_quad =
928 RenderPassDrawQuad::MaterialCast(current_quad);
929 if (!culler.ShouldRemoveRenderPass(*render_pass_quad, *frame))
930 continue;
[email protected]94f206c12012-08-25 00:09:14931
[email protected]c1bb5af2013-03-13 19:06:27932 // We are changing the vector in the middle of iteration. Because we
933 // delete render passes that draw into the current pass, we are
934 // guaranteed that any data from the iterator to the end will not
935 // change. So, capture the iterator position from the end of the
936 // list, and restore it after the change.
937 size_t position_from_end = frame->render_passes.size() - it;
938 RemoveRenderPassesRecursive(render_pass_quad->render_pass_id, frame);
939 it = frame->render_passes.size() - position_from_end;
940 DCHECK_GE(frame->render_passes.size(), position_from_end);
[email protected]94f206c12012-08-25 00:09:14941 }
[email protected]c1bb5af2013-03-13 19:06:27942 }
[email protected]94f206c12012-08-25 00:09:14943}
944
[email protected]e0341352013-04-06 05:01:20945bool LayerTreeHostImpl::PrepareToDraw(FrameData* frame,
946 gfx::Rect device_viewport_damage_rect) {
[email protected]7a52f43e2013-07-10 01:58:47947 TRACE_EVENT1("cc",
948 "LayerTreeHostImpl::PrepareToDraw",
949 "SourceFrameNumber",
950 active_tree_->source_frame_number());
[email protected]94f206c12012-08-25 00:09:14951
[email protected]8bb6cfa2013-07-23 00:11:19952 if (need_to_update_visible_tiles_before_draw_) {
[email protected]39643fb2013-07-09 17:28:19953 DCHECK(tile_manager_);
[email protected]8bb6cfa2013-07-23 00:11:19954 if (tile_manager_->UpdateVisibleTiles())
955 DidInitializeVisibleTile();
[email protected]39643fb2013-07-09 17:28:19956 }
957
[email protected]7d19dc342013-05-02 22:02:04958 active_tree_->UpdateDrawProperties();
[email protected]2e7ca422012-12-20 02:57:27959
[email protected]c1bb5af2013-03-13 19:06:27960 frame->render_surface_layer_list = &active_tree_->RenderSurfaceLayerList();
961 frame->render_passes.clear();
962 frame->render_passes_by_id.clear();
963 frame->will_draw_layers.clear();
[email protected]e0341352013-04-06 05:01:20964 frame->contains_incomplete_tile = false;
965 frame->has_no_damage = false;
966
967 if (active_tree_->root_layer()) {
[email protected]878705be2013-04-15 22:44:02968 device_viewport_damage_rect.Union(viewport_damage_rect_);
969 viewport_damage_rect_ = gfx::Rect();
[email protected]e0341352013-04-06 05:01:20970
971 active_tree_->root_layer()->render_surface()->damage_tracker()->
972 AddDamageNextUpdate(device_viewport_damage_rect);
973 }
[email protected]94f206c12012-08-25 00:09:14974
[email protected]c1bb5af2013-03-13 19:06:27975 if (!CalculateRenderPasses(frame))
976 return false;
[email protected]94f206c12012-08-25 00:09:14977
[email protected]c1bb5af2013-03-13 19:06:27978 // If we return true, then we expect DrawLayers() to be called before this
979 // function is called again.
980 return true;
[email protected]94f206c12012-08-25 00:09:14981}
982
[email protected]0309ba5e02013-06-26 04:11:08983void LayerTreeHostImpl::EvictTexturesForTesting() {
984 EnforceManagedMemoryPolicy(ManagedMemoryPolicy(0));
985}
986
[email protected]c1bb5af2013-03-13 19:06:27987void LayerTreeHostImpl::EnforceManagedMemoryPolicy(
988 const ManagedMemoryPolicy& policy) {
[email protected]206a3922013-05-17 06:34:12989
[email protected]c1bb5af2013-03-13 19:06:27990 bool evicted_resources = client_->ReduceContentsTextureMemoryOnImplThread(
[email protected]46b8acc2013-03-19 22:38:35991 visible_ ? policy.bytes_limit_when_visible
992 : policy.bytes_limit_when_not_visible,
993 ManagedMemoryPolicy::PriorityCutoffToValue(
994 visible_ ? policy.priority_cutoff_when_visible
995 : policy.priority_cutoff_when_not_visible));
[email protected]c1bb5af2013-03-13 19:06:27996 if (evicted_resources) {
997 active_tree_->SetContentsTexturesPurged();
998 if (pending_tree_)
999 pending_tree_->SetContentsTexturesPurged();
1000 client_->SetNeedsCommitOnImplThread();
1001 client_->OnCanDrawStateChanged(CanDraw());
1002 client_->RenewTreePriority();
1003 }
1004 client_->SendManagedMemoryStats();
[email protected]8947cbe2012-11-28 05:27:431005
[email protected]8be1a9bf2013-05-01 03:45:191006 UpdateTileManagerMemoryPolicy(policy);
1007}
1008
1009void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy(
1010 const ManagedMemoryPolicy& policy) {
1011 if (!tile_manager_)
1012 return;
1013
1014 GlobalStateThatImpactsTilePriority new_state(tile_manager_->GlobalState());
1015 new_state.memory_limit_in_bytes = visible_ ?
1016 policy.bytes_limit_when_visible :
1017 policy.bytes_limit_when_not_visible;
1018 // TODO(reveman): We should avoid keeping around unused resources if
1019 // possible. crbug.com/224475
1020 new_state.unused_memory_limit_in_bytes = static_cast<size_t>(
1021 (static_cast<int64>(new_state.memory_limit_in_bytes) *
1022 settings_.max_unused_resource_memory_percentage) / 100);
1023 new_state.memory_limit_policy =
1024 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy(
1025 visible_ ?
1026 policy.priority_cutoff_when_visible :
1027 policy.priority_cutoff_when_not_visible);
1028 tile_manager_->SetGlobalState(new_state);
[email protected]a23451e2013-06-07 20:58:261029 manage_tiles_needed_ = true;
[email protected]94f206c12012-08-25 00:09:141030}
1031
[email protected]c1bb5af2013-03-13 19:06:271032bool LayerTreeHostImpl::HasImplThread() const {
1033 return proxy_->HasImplThread();
[email protected]61de5812012-11-08 07:03:441034}
1035
[email protected]86126792013-03-16 20:07:541036void LayerTreeHostImpl::DidInitializeVisibleTile() {
1037 // TODO(reveman): Determine tiles that changed and only damage
1038 // what's necessary.
1039 SetFullRootLayerDamage();
[email protected]c1bb5af2013-03-13 19:06:271040 if (client_)
[email protected]86126792013-03-16 20:07:541041 client_->DidInitializeVisibleTileOnImplThread();
[email protected]74d9063c2013-01-18 03:14:471042}
1043
[email protected]94bf75c2013-06-12 13:20:041044void LayerTreeHostImpl::NotifyReadyToActivate() {
[email protected]39643fb2013-07-09 17:28:191045 if (pending_tree_) {
[email protected]8bb6cfa2013-07-23 00:11:191046 need_to_update_visible_tiles_before_draw_ = true;
[email protected]94bf75c2013-06-12 13:20:041047 ActivatePendingTree();
[email protected]39643fb2013-07-09 17:28:191048 }
[email protected]94bf75c2013-06-12 13:20:041049}
1050
[email protected]c1bb5af2013-03-13 19:06:271051bool LayerTreeHostImpl::ShouldClearRootRenderPass() const {
[email protected]8e0176d2013-03-21 03:14:521052 return settings_.should_clear_root_render_pass;
[email protected]f35e2322012-12-15 21:45:521053}
1054
[email protected]fd32d122013-06-29 13:11:041055void LayerTreeHostImpl::SetMemoryPolicy(
1056 const ManagedMemoryPolicy& policy,
1057 bool discard_backbuffer_when_not_visible) {
1058 if (policy.bytes_limit_when_visible) {
1059 // Just ignore the memory manager when it says to set the limit to zero
1060 // bytes. This will happen when the memory manager thinks that the renderer
1061 // is not visible (which the renderer knows better).
1062 SetManagedMemoryPolicy(policy);
1063 }
1064 renderer_->SetDiscardBackBufferWhenNotVisible(
1065 discard_backbuffer_when_not_visible);
1066}
1067
[email protected]5f07afc2013-07-19 05:17:181068void LayerTreeHostImpl::SetTreeActivationCallback(
1069 const base::Closure& callback) {
1070 DCHECK(proxy_->IsImplThread());
1071 DCHECK(settings_.impl_side_painting || callback.is_null());
[email protected]2022c672013-07-23 19:55:261072 tree_activation_callback_ = callback;
[email protected]5f07afc2013-07-19 05:17:181073}
1074
[email protected]c1bb5af2013-03-13 19:06:271075void LayerTreeHostImpl::SetManagedMemoryPolicy(
1076 const ManagedMemoryPolicy& policy) {
1077 if (managed_memory_policy_ == policy)
1078 return;
[email protected]61de5812012-11-08 07:03:441079
[email protected]50644642013-06-20 13:58:551080 if (zero_budget_)
1081 DCHECK_EQ(0u, policy.bytes_limit_when_visible);
1082
[email protected]d7626ffd2013-03-29 00:17:421083 // If there is already enough memory to draw everything imaginable and the
1084 // new memory limit does not change this, then do not re-commit. Don't bother
1085 // skipping commits if this is not visible (commits don't happen when not
1086 // visible, there will almost always be a commit when this becomes visible).
1087 bool needs_commit = true;
1088 if (visible() &&
1089 policy.bytes_limit_when_visible >=
1090 max_memory_needed_bytes_ &&
1091 managed_memory_policy_.bytes_limit_when_visible >=
1092 max_memory_needed_bytes_ &&
1093 policy.priority_cutoff_when_visible ==
1094 managed_memory_policy_.priority_cutoff_when_visible) {
1095 needs_commit = false;
1096 }
1097
[email protected]c1bb5af2013-03-13 19:06:271098 managed_memory_policy_ = policy;
1099 if (!proxy_->HasImplThread()) {
[email protected]d7626ffd2013-03-29 00:17:421100 // In single-thread mode, this can be called on the main thread by
1101 // GLRenderer::OnMemoryAllocationChanged.
[email protected]c1bb5af2013-03-13 19:06:271102 DebugScopedSetImplThread impl_thread(proxy_);
[email protected]206a3922013-05-17 06:34:121103 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy());
[email protected]c1bb5af2013-03-13 19:06:271104 } else {
1105 DCHECK(proxy_->IsImplThread());
[email protected]206a3922013-05-17 06:34:121106 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy());
[email protected]c1bb5af2013-03-13 19:06:271107 }
[email protected]d7626ffd2013-03-29 00:17:421108
1109 if (needs_commit)
1110 client_->SetNeedsCommitOnImplThread();
[email protected]94f206c12012-08-25 00:09:141111}
1112
[email protected]f224cc92013-06-06 23:23:321113void LayerTreeHostImpl::SetExternalDrawConstraints(
1114 const gfx::Transform& transform,
1115 gfx::Rect viewport) {
1116 external_transform_ = transform;
1117 external_viewport_ = viewport;
1118}
1119
[email protected]1cd9f5552013-04-26 04:22:031120void LayerTreeHostImpl::SetNeedsRedrawRect(gfx::Rect damage_rect) {
1121 client_->SetNeedsRedrawRectOnImplThread(damage_rect);
1122}
1123
[email protected]df3c24c92013-06-19 03:54:351124void LayerTreeHostImpl::BeginFrame(const BeginFrameArgs& args) {
1125 client_->BeginFrameOnImplThread(args);
[email protected]7ed47512013-03-26 22:28:451126}
1127
[email protected]36e5ff12013-06-11 12:19:291128void LayerTreeHostImpl::OnSwapBuffersComplete(
1129 const CompositorFrameAck* ack) {
[email protected]c1bb5af2013-03-13 19:06:271130 // TODO(piman): We may need to do some validation on this ack before
1131 // processing it.
[email protected]36e5ff12013-06-11 12:19:291132 if (ack && renderer_)
1133 renderer_->ReceiveSwapBuffersAck(*ack);
[email protected]bb1e2822013-04-17 22:06:011134
[email protected]36e5ff12013-06-11 12:19:291135 client_->OnSwapBuffersCompleteOnImplThread();
[email protected]a46f32932012-12-07 21:43:161136}
1137
[email protected]c1bb5af2013-03-13 19:06:271138void LayerTreeHostImpl::OnCanDrawStateChangedForTree() {
1139 client_->OnCanDrawStateChanged(CanDraw());
[email protected]3b31c6ac2012-12-06 21:27:291140}
1141
[email protected]c1bb5af2013-03-13 19:06:271142CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const {
1143 CompositorFrameMetadata metadata;
1144 metadata.device_scale_factor = device_scale_factor_;
1145 metadata.page_scale_factor = active_tree_->total_page_scale_factor();
1146 metadata.viewport_size = active_tree_->ScrollableViewportSize();
1147 metadata.root_layer_size = active_tree_->ScrollableSize();
1148 metadata.min_page_scale_factor = active_tree_->min_page_scale_factor();
1149 metadata.max_page_scale_factor = active_tree_->max_page_scale_factor();
[email protected]6a50af12013-06-14 08:47:501150 metadata.latency_info = active_tree_->GetLatencyInfo();
[email protected]c1bb5af2013-03-13 19:06:271151 if (top_controls_manager_) {
1152 metadata.location_bar_offset =
1153 gfx::Vector2dF(0.f, top_controls_manager_->controls_top_offset());
1154 metadata.location_bar_content_translation =
1155 gfx::Vector2dF(0.f, top_controls_manager_->content_top_offset());
[email protected]5a54b2822013-03-26 10:00:011156 metadata.overdraw_bottom_height = overdraw_bottom_height_;
[email protected]c1bb5af2013-03-13 19:06:271157 }
[email protected]bf189f62012-12-18 03:42:111158
[email protected]c1bb5af2013-03-13 19:06:271159 if (!RootScrollLayer())
[email protected]bf189f62012-12-18 03:42:111160 return metadata;
[email protected]c1bb5af2013-03-13 19:06:271161
[email protected]ffb2720f2013-03-15 19:18:371162 metadata.root_scroll_offset = RootScrollLayer()->TotalScrollOffset();
[email protected]c1bb5af2013-03-13 19:06:271163
1164 return metadata;
[email protected]bf189f62012-12-18 03:42:111165}
1166
[email protected]73673592013-04-03 22:14:321167bool LayerTreeHostImpl::AllowPartialSwap() const {
1168 // We don't track damage on the HUD layer (it interacts with damage tracking
1169 // visualizations), so disable partial swaps to make the HUD layer display
1170 // properly.
1171 return !debug_state_.ShowHudRects();
1172}
1173
[email protected]6f50b8fa2013-07-01 19:51:491174static void LayerTreeHostImplDidBeginTracingCallback(LayerImpl* layer) {
1175 layer->DidBeginTracing();
1176}
[email protected]37349bc2013-06-04 01:31:521177
[email protected]f0c2a242013-03-15 19:34:521178void LayerTreeHostImpl::DrawLayers(FrameData* frame,
1179 base::TimeTicks frame_begin_time) {
[email protected]c1bb5af2013-03-13 19:06:271180 TRACE_EVENT0("cc", "LayerTreeHostImpl::DrawLayers");
1181 DCHECK(CanDraw());
[email protected]e0341352013-04-06 05:01:201182
[email protected]3519b872013-07-30 07:17:501183 if (frame->has_no_damage) {
1184 TRACE_EVENT0("cc", "EarlyOut_NoDamage");
[email protected]e0341352013-04-06 05:01:201185 return;
[email protected]3519b872013-07-30 07:17:501186 }
[email protected]e0341352013-04-06 05:01:201187
[email protected]c1bb5af2013-03-13 19:06:271188 DCHECK(!frame->render_passes.empty());
[email protected]94f206c12012-08-25 00:09:141189
[email protected]9e3594522013-03-18 00:57:361190 fps_counter_->SaveTimeStamp(frame_begin_time);
[email protected]94f206c12012-08-25 00:09:141191
[email protected]372bad5f2013-03-21 16:38:431192 rendering_stats_instrumentation_->SetScreenFrameCount(
1193 fps_counter_->current_frame_number());
1194 rendering_stats_instrumentation_->SetDroppedFrameCount(
1195 fps_counter_->dropped_frame_count());
1196
[email protected]c1bb5af2013-03-13 19:06:271197 if (tile_manager_) {
1198 memory_history_->SaveEntry(
1199 tile_manager_->memory_stats_from_last_assign());
1200 }
[email protected]1191d9d2013-02-02 06:00:331201
[email protected]846f455b2013-03-18 19:07:411202 if (debug_state_.ShowHudRects()) {
[email protected]d35992782013-03-14 14:54:021203 debug_rect_history_->SaveDebugRectsForCurrentFrame(
[email protected]c1bb5af2013-03-13 19:06:271204 active_tree_->root_layer(),
1205 *frame->render_surface_layer_list,
1206 frame->occluding_screen_space_rects,
1207 frame->non_occluding_screen_space_rects,
1208 debug_state_);
1209 }
[email protected]94f206c12012-08-25 00:09:141210
[email protected]a848c102013-03-26 08:59:091211 if (!settings_.impl_side_painting && debug_state_.continuous_painting) {
1212 const RenderingStats& stats =
1213 rendering_stats_instrumentation_->GetRenderingStats();
1214 paint_time_counter_->SavePaintTime(stats.total_paint_time);
1215 }
1216
[email protected]37349bc2013-06-04 01:31:521217 bool is_new_trace;
1218 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace);
1219 if (is_new_trace) {
[email protected]6f50b8fa2013-07-01 19:51:491220 if (pending_tree_) {
1221 LayerTreeHostCommon::CallFunctionForSubtree(
1222 pending_tree_->root_layer(),
1223 base::Bind(&LayerTreeHostImplDidBeginTracingCallback));
1224 }
1225 LayerTreeHostCommon::CallFunctionForSubtree(
1226 active_tree_->root_layer(),
1227 base::Bind(&LayerTreeHostImplDidBeginTracingCallback));
[email protected]37349bc2013-06-04 01:31:521228 }
1229
[email protected]9197dbcb2013-05-15 20:28:511230 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
1231 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", this,
1232 TracedValue::FromValue(AsValue().release()));
[email protected]131a0c22013-02-12 18:31:081233
[email protected]c1bb5af2013-03-13 19:06:271234 // Because the contents of the HUD depend on everything else in the frame, the
1235 // contents of its texture are updated as the last thing before the frame is
1236 // drawn.
1237 if (active_tree_->hud_layer())
[email protected]264dc0332013-03-17 21:00:541238 active_tree_->hud_layer()->UpdateHudTexture(resource_provider_.get());
[email protected]94f206c12012-08-25 00:09:141239
[email protected]b09c1942013-05-10 00:06:371240 if (output_surface_->ForcedDrawToSoftwareDevice()) {
1241 scoped_ptr<SoftwareRenderer> temp_software_renderer =
1242 SoftwareRenderer::Create(this, output_surface_.get(), NULL);
1243 temp_software_renderer->DrawFrame(&frame->render_passes);
1244 } else {
1245 renderer_->DrawFrame(&frame->render_passes);
1246 }
[email protected]c1bb5af2013-03-13 19:06:271247 // The render passes should be consumed by the renderer.
1248 DCHECK(frame->render_passes.empty());
1249 frame->render_passes_by_id.clear();
[email protected]94f206c12012-08-25 00:09:141250
[email protected]c1bb5af2013-03-13 19:06:271251 // The next frame should start by assuming nothing has changed, and changes
1252 // are noted as they occur.
[email protected]264dc0332013-03-17 21:00:541253 for (size_t i = 0; i < frame->render_surface_layer_list->size(); i++) {
[email protected]c1bb5af2013-03-13 19:06:271254 (*frame->render_surface_layer_list)[i]->render_surface()->damage_tracker()->
1255 DidDrawDamagedArea();
1256 }
1257 active_tree_->root_layer()->ResetAllChangeTrackingForSubtree();
[email protected]94f206c12012-08-25 00:09:141258}
1259
[email protected]c1bb5af2013-03-13 19:06:271260void LayerTreeHostImpl::DidDrawAllLayers(const FrameData& frame) {
1261 for (size_t i = 0; i < frame.will_draw_layers.size(); ++i)
1262 frame.will_draw_layers[i]->DidDraw(resource_provider_.get());
[email protected]b914e102012-10-02 08:11:521263
[email protected]c1bb5af2013-03-13 19:06:271264 // Once all layers have been drawn, pending texture uploads should no
1265 // longer block future uploads.
[email protected]d15d9622013-06-21 02:49:151266 resource_provider_->MarkPendingUploadsAsNonBlocking();
[email protected]94f206c12012-08-25 00:09:141267}
1268
[email protected]c1bb5af2013-03-13 19:06:271269void LayerTreeHostImpl::FinishAllRendering() {
1270 if (renderer_)
1271 renderer_->Finish();
[email protected]94f206c12012-08-25 00:09:141272}
1273
[email protected]c1bb5af2013-03-13 19:06:271274bool LayerTreeHostImpl::IsContextLost() {
1275 DCHECK(proxy_->IsImplThread());
1276 return renderer_ && renderer_->IsContextLost();
[email protected]94f206c12012-08-25 00:09:141277}
1278
[email protected]c1bb5af2013-03-13 19:06:271279const RendererCapabilities& LayerTreeHostImpl::GetRendererCapabilities() const {
1280 return renderer_->Capabilities();
[email protected]94f206c12012-08-25 00:09:141281}
1282
[email protected]e0341352013-04-06 05:01:201283bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) {
1284 if (frame.has_no_damage)
1285 return false;
[email protected]36e5ff12013-06-11 12:19:291286 renderer_->SwapBuffers();
[email protected]c5c506382013-04-30 04:42:161287 active_tree_->ClearLatencyInfo();
1288 return true;
[email protected]94f206c12012-08-25 00:09:141289}
1290
[email protected]c8cbae72013-05-23 10:45:031291void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) {
[email protected]7ed47512013-03-26 22:28:451292 if (output_surface_)
[email protected]c8cbae72013-05-23 10:45:031293 output_surface_->SetNeedsBeginFrame(enable);
[email protected]7ed47512013-03-26 22:28:451294}
1295
[email protected]94c40e6292013-05-24 22:01:501296float LayerTreeHostImpl::DeviceScaleFactor() const {
1297 return device_scale_factor_;
1298}
1299
[email protected]ffb2720f2013-03-15 19:18:371300gfx::SizeF LayerTreeHostImpl::VisibleViewportSize() const {
1301 gfx::SizeF dip_size =
[email protected]f224cc92013-06-06 23:23:321302 gfx::ScaleSize(device_viewport_size(), 1.f / device_scale_factor());
[email protected]ffb2720f2013-03-15 19:18:371303
[email protected]ed511b8d2013-03-25 03:29:291304 float top_offset =
[email protected]ffb2720f2013-03-15 19:18:371305 top_controls_manager_ ? top_controls_manager_->content_top_offset() : 0.f;
[email protected]d9083762013-03-24 01:36:401306 return gfx::SizeF(dip_size.width(),
[email protected]ed511b8d2013-03-25 03:29:291307 dip_size.height() - top_offset - overdraw_bottom_height_);
[email protected]ffb2720f2013-03-15 19:18:371308}
1309
[email protected]c1bb5af2013-03-13 19:06:271310const LayerTreeSettings& LayerTreeHostImpl::Settings() const {
1311 return settings();
[email protected]493067512012-09-19 23:34:101312}
1313
[email protected]c1bb5af2013-03-13 19:06:271314void LayerTreeHostImpl::DidLoseOutputSurface() {
[email protected]bb1e2822013-04-17 22:06:011315 // TODO(jamesr): The renderer_ check is needed to make some of the
1316 // LayerTreeHostContextTest tests pass, but shouldn't be necessary (or
1317 // important) in production. We should adjust the test to not need this.
1318 if (renderer_)
1319 client_->DidLoseOutputSurfaceOnImplThread();
[email protected]94f206c12012-08-25 00:09:141320}
1321
[email protected]c1bb5af2013-03-13 19:06:271322void LayerTreeHostImpl::Readback(void* pixels,
1323 gfx::Rect rect_in_device_viewport) {
1324 DCHECK(renderer_);
1325 renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport);
[email protected]94f206c12012-08-25 00:09:141326}
1327
[email protected]59adb112013-04-09 04:48:441328bool LayerTreeHostImpl::HaveRootScrollLayer() const {
[email protected]3209161d2013-03-29 19:17:341329 return !!RootScrollLayer();
[email protected]69b50ec2013-01-19 04:58:011330}
1331
[email protected]c1bb5af2013-03-13 19:06:271332LayerImpl* LayerTreeHostImpl::RootLayer() const {
1333 return active_tree_->root_layer();
[email protected]8bef40572012-12-11 21:38:081334}
1335
[email protected]c1bb5af2013-03-13 19:06:271336LayerImpl* LayerTreeHostImpl::RootScrollLayer() const {
1337 return active_tree_->RootScrollLayer();
[email protected]8bef40572012-12-11 21:38:081338}
1339
[email protected]c1bb5af2013-03-13 19:06:271340LayerImpl* LayerTreeHostImpl::CurrentlyScrollingLayer() const {
1341 return active_tree_->CurrentlyScrollingLayer();
[email protected]8bef40572012-12-11 21:38:081342}
1343
[email protected]94f206c12012-08-25 00:09:141344// Content layers can be either directly scrollable or contained in an outer
1345// scrolling layer which applies the scroll transform. Given a content layer,
1346// this function returns the associated scroll layer if any.
[email protected]c1bb5af2013-03-13 19:06:271347static LayerImpl* FindScrollLayerForContentLayer(LayerImpl* layer_impl) {
1348 if (!layer_impl)
[email protected]94f206c12012-08-25 00:09:141349 return 0;
[email protected]c1bb5af2013-03-13 19:06:271350
1351 if (layer_impl->scrollable())
1352 return layer_impl;
1353
1354 if (layer_impl->DrawsContent() &&
1355 layer_impl->parent() &&
1356 layer_impl->parent()->scrollable())
1357 return layer_impl->parent();
1358
1359 return 0;
[email protected]94f206c12012-08-25 00:09:141360}
1361
[email protected]c1bb5af2013-03-13 19:06:271362void LayerTreeHostImpl::CreatePendingTree() {
1363 CHECK(!pending_tree_);
1364 if (recycle_tree_)
1365 recycle_tree_.swap(pending_tree_);
1366 else
1367 pending_tree_ = LayerTreeImpl::create(this);
1368 client_->OnCanDrawStateChanged(CanDraw());
1369 client_->OnHasPendingTreeStateChanged(pending_tree_);
1370 TRACE_EVENT_ASYNC_BEGIN0("cc", "PendingTree", pending_tree_.get());
1371 TRACE_EVENT_ASYNC_STEP0("cc",
1372 "PendingTree", pending_tree_.get(), "waiting");
[email protected]2e7ca422012-12-20 02:57:271373}
1374
[email protected]8bb6cfa2013-07-23 00:11:191375void LayerTreeHostImpl::UpdateVisibleTiles() {
[email protected]c1bb5af2013-03-13 19:06:271376 DCHECK(!client_->IsInsideDraw()) <<
[email protected]8bb6cfa2013-07-23 00:11:191377 "Updating visible tiles within a draw may trigger "
[email protected]c1bb5af2013-03-13 19:06:271378 "spurious redraws.";
[email protected]8bb6cfa2013-07-23 00:11:191379 if (tile_manager_ && tile_manager_->UpdateVisibleTiles())
1380 DidInitializeVisibleTile();
[email protected]39643fb2013-07-09 17:28:191381
[email protected]8bb6cfa2013-07-23 00:11:191382 need_to_update_visible_tiles_before_draw_ = false;
[email protected]eabe5002013-01-12 22:07:481383}
1384
[email protected]94bf75c2013-06-12 13:20:041385void LayerTreeHostImpl::ActivatePendingTreeIfNeeded() {
1386 DCHECK(pending_tree_);
[email protected]fbe89f72013-05-21 07:24:241387 CHECK(settings_.impl_side_painting);
[email protected]2ae038b2013-01-28 12:52:091388
[email protected]94bf75c2013-06-12 13:20:041389 if (!pending_tree_)
1390 return;
1391
1392 // The tile manager is usually responsible for notifying activation.
1393 // If there is no tile manager, then we need to manually activate.
1394 if (!tile_manager_ || tile_manager_->AreTilesRequiredForActivationReady()) {
1395 ActivatePendingTree();
1396 return;
1397 }
[email protected]615c78a2013-01-24 23:44:161398
[email protected]b67a44e2013-07-12 19:15:101399 // Manage tiles in case state affecting tile priority has changed.
1400 ManageTiles();
1401
[email protected]f6742f52013-05-08 23:52:221402 TRACE_EVENT_ASYNC_STEP1(
[email protected]fcb846d2013-05-22 01:42:361403 "cc",
1404 "PendingTree", pending_tree_.get(), "activate",
1405 "state", TracedValue::FromValue(ActivationStateAsValue().release()));
[email protected]2e7ca422012-12-20 02:57:271406}
1407
[email protected]c1bb5af2013-03-13 19:06:271408void LayerTreeHostImpl::ActivatePendingTree() {
1409 CHECK(pending_tree_);
1410 TRACE_EVENT_ASYNC_END0("cc", "PendingTree", pending_tree_.get());
[email protected]1e0f8d62013-01-09 07:41:351411
[email protected]1960a712013-04-30 17:06:471412 active_tree_->SetRootLayerScrollOffsetDelegate(NULL);
[email protected]c1bb5af2013-03-13 19:06:271413 active_tree_->PushPersistedState(pending_tree_.get());
1414 if (pending_tree_->needs_full_tree_sync()) {
1415 active_tree_->SetRootLayer(
[email protected]b5651c22013-03-14 15:06:331416 TreeSynchronizer::SynchronizeTrees(pending_tree_->root_layer(),
[email protected]c1bb5af2013-03-13 19:06:271417 active_tree_->DetachLayerTree(),
1418 active_tree_.get()));
1419 }
[email protected]b5651c22013-03-14 15:06:331420 TreeSynchronizer::PushProperties(pending_tree_->root_layer(),
[email protected]c1bb5af2013-03-13 19:06:271421 active_tree_->root_layer());
1422 DCHECK(!recycle_tree_);
[email protected]48871fc2013-01-23 07:36:511423
[email protected]c1bb5af2013-03-13 19:06:271424 pending_tree_->PushPropertiesTo(active_tree_.get());
[email protected]48871fc2013-01-23 07:36:511425
[email protected]c1bb5af2013-03-13 19:06:271426 // Now that we've synced everything from the pending tree to the active
1427 // tree, rename the pending tree the recycle tree so we can reuse it on the
1428 // next sync.
1429 pending_tree_.swap(recycle_tree_);
[email protected]48871fc2013-01-23 07:36:511430
[email protected]1960a712013-04-30 17:06:471431 active_tree_->SetRootLayerScrollOffsetDelegate(
1432 root_layer_scroll_offset_delegate_);
[email protected]c1bb5af2013-03-13 19:06:271433 active_tree_->DidBecomeActive();
[email protected]37386f052013-01-13 00:42:221434
[email protected]c1bb5af2013-03-13 19:06:271435 // Reduce wasted memory now that unlinked resources are guaranteed not
1436 // to be used.
1437 client_->ReduceWastedContentsTextureMemoryOnImplThread();
[email protected]a0b84172013-02-04 08:13:411438
[email protected]c1bb5af2013-03-13 19:06:271439 client_->OnCanDrawStateChanged(CanDraw());
1440 client_->OnHasPendingTreeStateChanged(pending_tree_);
1441 client_->SetNeedsRedrawOnImplThread();
1442 client_->RenewTreePriority();
[email protected]652cf132013-02-15 21:53:241443
[email protected]a848c102013-03-26 08:59:091444 if (debug_state_.continuous_painting) {
1445 const RenderingStats& stats =
[email protected]372bad5f2013-03-21 16:38:431446 rendering_stats_instrumentation_->GetRenderingStats();
[email protected]a848c102013-03-26 08:59:091447 paint_time_counter_->SavePaintTime(
[email protected]41abb6d92013-04-26 16:38:501448 stats.total_paint_time + stats.total_record_time +
[email protected]a848c102013-03-26 08:59:091449 stats.total_rasterize_time_for_now_bins_on_pending_tree);
[email protected]c1bb5af2013-03-13 19:06:271450 }
[email protected]2a61ad52013-05-13 14:01:291451
1452 client_->DidActivatePendingTree();
[email protected]2022c672013-07-23 19:55:261453 if (!tree_activation_callback_.is_null())
1454 tree_activation_callback_.Run();
[email protected]2e7ca422012-12-20 02:57:271455}
1456
[email protected]c1bb5af2013-03-13 19:06:271457void LayerTreeHostImpl::SetVisible(bool visible) {
1458 DCHECK(proxy_->IsImplThread());
[email protected]94f206c12012-08-25 00:09:141459
[email protected]c1bb5af2013-03-13 19:06:271460 if (visible_ == visible)
1461 return;
1462 visible_ = visible;
1463 DidVisibilityChange(this, visible_);
[email protected]206a3922013-05-17 06:34:121464 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy());
[email protected]94f206c12012-08-25 00:09:141465
[email protected]c1bb5af2013-03-13 19:06:271466 if (!renderer_)
1467 return;
[email protected]94f206c12012-08-25 00:09:141468
[email protected]c1bb5af2013-03-13 19:06:271469 renderer_->SetVisible(visible);
[email protected]94f206c12012-08-25 00:09:141470}
1471
[email protected]206a3922013-05-17 06:34:121472ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const {
1473 if (!debug_state_.rasterize_only_visible_content)
1474 return managed_memory_policy_;
1475
1476 ManagedMemoryPolicy actual = managed_memory_policy_;
1477 actual.priority_cutoff_when_not_visible =
1478 ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING;
1479 actual.priority_cutoff_when_visible =
1480 ManagedMemoryPolicy::CUTOFF_ALLOW_REQUIRED_ONLY;
1481 return actual;
1482}
1483
[email protected]50644642013-06-20 13:58:551484void LayerTreeHostImpl::ReleaseTreeResources() {
1485 if (active_tree_->root_layer())
[email protected]50644642013-06-20 13:58:551486 SendReleaseResourcesRecursive(active_tree_->root_layer());
1487 if (pending_tree_ && pending_tree_->root_layer())
1488 SendReleaseResourcesRecursive(pending_tree_->root_layer());
1489 if (recycle_tree_ && recycle_tree_->root_layer())
1490 SendReleaseResourcesRecursive(recycle_tree_->root_layer());
1491}
1492
1493void LayerTreeHostImpl::CreateAndSetRenderer(
1494 OutputSurface* output_surface,
[email protected]50af3c22013-07-13 03:50:201495 ResourceProvider* resource_provider,
1496 bool skip_gl_renderer) {
[email protected]50644642013-06-20 13:58:551497 DCHECK(!renderer_);
1498 if (output_surface->capabilities().delegated_rendering) {
1499 renderer_ =
1500 DelegatingRenderer::Create(this, output_surface, resource_provider);
[email protected]50af3c22013-07-13 03:50:201501 } else if (output_surface->context3d() && !skip_gl_renderer) {
[email protected]50644642013-06-20 13:58:551502 renderer_ = GLRenderer::Create(this,
1503 output_surface,
1504 resource_provider,
1505 settings_.highp_threshold_min,
1506 settings_.force_direct_layer_drawing);
1507 } else if (output_surface->software_device()) {
1508 renderer_ =
1509 SoftwareRenderer::Create(this, output_surface, resource_provider);
1510 }
1511
[email protected]84975832013-06-29 00:24:111512 if (renderer_) {
[email protected]50644642013-06-20 13:58:551513 renderer_->SetVisible(visible_);
[email protected]84975832013-06-29 00:24:111514 SetFullRootLayerDamage();
1515 }
[email protected]50644642013-06-20 13:58:551516}
1517
[email protected]50af3c22013-07-13 03:50:201518void LayerTreeHostImpl::CreateAndSetTileManager(
1519 ResourceProvider* resource_provider,
1520 bool using_map_image) {
1521 DCHECK(settings_.impl_side_painting);
1522 DCHECK(resource_provider);
1523 tile_manager_ = TileManager::Create(this,
1524 resource_provider,
1525 settings_.num_raster_threads,
1526 rendering_stats_instrumentation_,
1527 using_map_image);
1528 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy());
[email protected]8bb6cfa2013-07-23 00:11:191529 need_to_update_visible_tiles_before_draw_ = false;
[email protected]50af3c22013-07-13 03:50:201530}
1531
[email protected]50644642013-06-20 13:58:551532void LayerTreeHostImpl::EnforceZeroBudget(bool zero_budget) {
1533 if (zero_budget_ == zero_budget)
1534 return;
1535
1536 zero_budget_ = zero_budget;
1537
1538 ManagedMemoryPolicy new_policy = managed_memory_policy_;
1539 if (zero_budget_) {
1540 new_policy.bytes_limit_when_visible = 0;
1541 } else {
1542 new_policy.bytes_limit_when_visible =
1543 PrioritizedResourceManager::DefaultMemoryAllocationLimit();
1544 }
1545 SetManagedMemoryPolicy(new_policy);
1546}
1547
[email protected]c1bb5af2013-03-13 19:06:271548bool LayerTreeHostImpl::InitializeRenderer(
1549 scoped_ptr<OutputSurface> output_surface) {
1550 // Since we will create a new resource provider, we cannot continue to use
1551 // the old resources (i.e. render_surfaces and texture IDs). Clear them
1552 // before we destroy the old resource provider.
[email protected]50644642013-06-20 13:58:551553 ReleaseTreeResources();
[email protected]7ba3ca72013-04-11 06:37:251554 if (resource_provider_)
1555 resource_provider_->DidLoseOutputSurface();
[email protected]45c4b1e2013-01-16 02:19:401556
[email protected]c1bb5af2013-03-13 19:06:271557 // Note: order is important here.
1558 renderer_.reset();
1559 tile_manager_.reset();
1560 resource_provider_.reset();
1561 output_surface_.reset();
[email protected]94f206c12012-08-25 00:09:141562
[email protected]c1bb5af2013-03-13 19:06:271563 if (!output_surface->BindToClient(this))
1564 return false;
[email protected]be3181652012-09-25 13:02:131565
[email protected]50644642013-06-20 13:58:551566 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create(
1567 output_surface.get(), settings_.highp_threshold_min);
1568 if (!resource_provider)
1569 return false;
[email protected]2b154b22013-06-07 09:03:271570
[email protected]50644642013-06-20 13:58:551571 if (output_surface->capabilities().deferred_gl_initialization)
1572 EnforceZeroBudget(true);
[email protected]be3181652012-09-25 13:02:131573
[email protected]50af3c22013-07-13 03:50:201574 bool skip_gl_renderer = false;
1575 CreateAndSetRenderer(
1576 output_surface.get(), resource_provider.get(), skip_gl_renderer);
[email protected]be3181652012-09-25 13:02:131577
[email protected]50644642013-06-20 13:58:551578 if (!renderer_)
1579 return false;
[email protected]6123930c2013-05-23 06:48:371580
[email protected]50644642013-06-20 13:58:551581 if (settings_.impl_side_painting) {
[email protected]50af3c22013-07-13 03:50:201582 CreateAndSetTileManager(resource_provider.get(),
1583 GetRendererCapabilities().using_map_image);
[email protected]fbe89f72013-05-21 07:24:241584 }
1585
[email protected]049fc7a2013-06-18 12:32:351586 // Setup BeginFrameEmulation if it's not supported natively
1587 if (!settings_.begin_frame_scheduling_enabled) {
1588 const base::TimeDelta display_refresh_interval =
1589 base::TimeDelta::FromMicroseconds(
1590 base::Time::kMicrosecondsPerSecond /
1591 settings_.refresh_rate);
1592
1593 output_surface->InitializeBeginFrameEmulation(
[email protected]810d40b72013-06-20 18:26:151594 proxy_->ImplThreadTaskRunner(),
[email protected]049fc7a2013-06-18 12:32:351595 settings_.throttle_frame_production,
1596 display_refresh_interval);
1597 }
1598
1599 int max_frames_pending =
1600 output_surface->capabilities().max_frames_pending;
1601 if (max_frames_pending <= 0)
[email protected]df3c24c92013-06-19 03:54:351602 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING;
[email protected]049fc7a2013-06-18 12:32:351603 output_surface->SetMaxFramesPending(max_frames_pending);
1604
[email protected]50644642013-06-20 13:58:551605 resource_provider_ = resource_provider.Pass();
[email protected]c1bb5af2013-03-13 19:06:271606 output_surface_ = output_surface.Pass();
[email protected]94f206c12012-08-25 00:09:141607
[email protected]c1bb5af2013-03-13 19:06:271608 client_->OnCanDrawStateChanged(CanDraw());
[email protected]8db2213c2012-09-05 22:08:211609
[email protected]c1bb5af2013-03-13 19:06:271610 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs
1611 // to be initialized to get max texture size.
1612 active_tree_->set_needs_update_draw_properties();
1613 if (pending_tree_)
1614 pending_tree_->set_needs_update_draw_properties();
[email protected]615c78a2013-01-24 23:44:161615
[email protected]c1bb5af2013-03-13 19:06:271616 return true;
[email protected]94f206c12012-08-25 00:09:141617}
1618
[email protected]2b154b22013-06-07 09:03:271619bool LayerTreeHostImpl::DeferredInitialize(
1620 scoped_refptr<ContextProvider> offscreen_context_provider) {
1621 DCHECK(output_surface_->capabilities().deferred_gl_initialization);
[email protected]50644642013-06-20 13:58:551622 DCHECK(settings_.impl_side_painting);
1623 DCHECK(settings_.solid_color_scrollbars);
[email protected]2b154b22013-06-07 09:03:271624 DCHECK(output_surface_->context3d());
1625
[email protected]50644642013-06-20 13:58:551626 ReleaseTreeResources();
1627 renderer_.reset();
[email protected]50af3c22013-07-13 03:50:201628 resource_provider_->InitializeGL();
1629 bool skip_gl_renderer = false;
1630 CreateAndSetRenderer(
1631 output_surface_.get(), resource_provider_.get(), skip_gl_renderer);
[email protected]2b154b22013-06-07 09:03:271632
[email protected]50644642013-06-20 13:58:551633 bool success = !!renderer_.get();
[email protected]2b154b22013-06-07 09:03:271634 client_->DidTryInitializeRendererOnImplThread(success,
1635 offscreen_context_provider);
[email protected]50644642013-06-20 13:58:551636 if (success) {
1637 EnforceZeroBudget(false);
1638 client_->SetNeedsCommitOnImplThread();
1639 }
[email protected]2b154b22013-06-07 09:03:271640 return success;
1641}
1642
[email protected]50af3c22013-07-13 03:50:201643void LayerTreeHostImpl::ReleaseGL() {
1644 DCHECK(output_surface_->capabilities().deferred_gl_initialization);
1645 DCHECK(settings_.impl_side_painting);
1646 DCHECK(settings_.solid_color_scrollbars);
1647 DCHECK(output_surface_->context3d());
1648
1649 ReleaseTreeResources();
1650 renderer_.reset();
1651 tile_manager_.reset();
1652 resource_provider_->InitializeSoftware();
1653
1654 bool skip_gl_renderer = true;
1655 CreateAndSetRenderer(
1656 output_surface_.get(), resource_provider_.get(), skip_gl_renderer);
1657 DCHECK(renderer_);
1658
1659 EnforceZeroBudget(true);
1660 CreateAndSetTileManager(resource_provider_.get(),
1661 GetRendererCapabilities().using_map_image);
1662 DCHECK(tile_manager_);
1663
1664 bool success = true;
1665 client_->DidTryInitializeRendererOnImplThread(
1666 success, scoped_refptr<ContextProvider>());
1667 client_->SetNeedsCommitOnImplThread();
1668}
1669
[email protected]18ce59702013-04-09 04:58:401670void LayerTreeHostImpl::SetViewportSize(gfx::Size device_viewport_size) {
1671 if (device_viewport_size == device_viewport_size_)
[email protected]c1bb5af2013-03-13 19:06:271672 return;
[email protected]94f206c12012-08-25 00:09:141673
[email protected]c1bb5af2013-03-13 19:06:271674 if (pending_tree_ && device_viewport_size_ != device_viewport_size)
1675 active_tree_->SetViewportSizeInvalid();
[email protected]318822852013-02-14 00:54:271676
[email protected]c1bb5af2013-03-13 19:06:271677 device_viewport_size_ = device_viewport_size;
[email protected]94f206c12012-08-25 00:09:141678
[email protected]c1bb5af2013-03-13 19:06:271679 UpdateMaxScrollOffset();
[email protected]94f206c12012-08-25 00:09:141680
[email protected]c1bb5af2013-03-13 19:06:271681 if (renderer_)
1682 renderer_->ViewportChanged();
[email protected]8db2213c2012-09-05 22:08:211683
[email protected]c1bb5af2013-03-13 19:06:271684 client_->OnCanDrawStateChanged(CanDraw());
[email protected]59adb112013-04-09 04:48:441685 SetFullRootLayerDamage();
[email protected]94f206c12012-08-25 00:09:141686}
1687
[email protected]d9083762013-03-24 01:36:401688void LayerTreeHostImpl::SetOverdrawBottomHeight(float overdraw_bottom_height) {
1689 if (overdraw_bottom_height == overdraw_bottom_height_)
1690 return;
1691 overdraw_bottom_height_ = overdraw_bottom_height;
1692
1693 UpdateMaxScrollOffset();
[email protected]59adb112013-04-09 04:48:441694 SetFullRootLayerDamage();
[email protected]d9083762013-03-24 01:36:401695}
1696
[email protected]c1bb5af2013-03-13 19:06:271697void LayerTreeHostImpl::SetDeviceScaleFactor(float device_scale_factor) {
1698 if (device_scale_factor == device_scale_factor_)
1699 return;
1700 device_scale_factor_ = device_scale_factor;
[email protected]c0dd24c2012-08-30 23:25:271701
[email protected]94c40e6292013-05-24 22:01:501702 if (renderer_)
1703 renderer_->ViewportChanged();
1704
[email protected]c1bb5af2013-03-13 19:06:271705 UpdateMaxScrollOffset();
[email protected]59adb112013-04-09 04:48:441706 SetFullRootLayerDamage();
[email protected]94f206c12012-08-25 00:09:141707}
1708
[email protected]f224cc92013-06-06 23:23:321709gfx::Rect LayerTreeHostImpl::DeviceViewport() const {
1710 if (external_viewport_.IsEmpty())
1711 return gfx::Rect(device_viewport_size_);
1712
1713 return external_viewport_;
1714}
1715
1716const gfx::Transform& LayerTreeHostImpl::DeviceTransform() const {
1717 return external_transform_;
1718}
1719
[email protected]c1bb5af2013-03-13 19:06:271720void LayerTreeHostImpl::UpdateMaxScrollOffset() {
1721 active_tree_->UpdateMaxScrollOffset();
[email protected]94f206c12012-08-25 00:09:141722}
1723
[email protected]59adb112013-04-09 04:48:441724void LayerTreeHostImpl::DidChangeTopControlsPosition() {
[email protected]c1bb5af2013-03-13 19:06:271725 client_->SetNeedsRedrawOnImplThread();
[email protected]59adb112013-04-09 04:48:441726 active_tree_->set_needs_update_draw_properties();
1727 SetFullRootLayerDamage();
[email protected]94f206c12012-08-25 00:09:141728}
1729
[email protected]c1bb5af2013-03-13 19:06:271730bool LayerTreeHostImpl::EnsureRenderSurfaceLayerList() {
[email protected]7d19dc342013-05-02 22:02:041731 active_tree_->UpdateDrawProperties();
[email protected]3209161d2013-03-29 19:17:341732 return !active_tree_->RenderSurfaceLayerList().empty();
[email protected]94f206c12012-08-25 00:09:141733}
1734
[email protected]200a9c062013-05-20 04:34:371735void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) {
1736 DCHECK(input_handler_client_ == NULL);
1737 input_handler_client_ = client;
1738}
1739
[email protected]5ff3c9782013-04-29 17:35:121740InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
1741 gfx::Point viewport_point, InputHandler::ScrollInputType type) {
[email protected]ed511b8d2013-03-25 03:29:291742 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin");
[email protected]94f206c12012-08-25 00:09:141743
[email protected]c1bb5af2013-03-13 19:06:271744 if (top_controls_manager_)
1745 top_controls_manager_->ScrollBegin();
[email protected]3ba4cae2013-01-16 03:58:381746
[email protected]c1bb5af2013-03-13 19:06:271747 DCHECK(!CurrentlyScrollingLayer());
1748 ClearCurrentlyScrollingLayer();
[email protected]94f206c12012-08-25 00:09:141749
[email protected]c1bb5af2013-03-13 19:06:271750 if (!EnsureRenderSurfaceLayerList())
[email protected]94f206c12012-08-25 00:09:141751 return ScrollIgnored;
[email protected]94f206c12012-08-25 00:09:141752
[email protected]c1bb5af2013-03-13 19:06:271753 gfx::PointF device_viewport_point = gfx::ScalePoint(viewport_point,
1754 device_scale_factor_);
[email protected]94f206c12012-08-25 00:09:141755
[email protected]c1bb5af2013-03-13 19:06:271756 // First find out which layer was hit from the saved list of visible layers
1757 // in the most recent frame.
[email protected]6ba914122013-03-22 16:26:391758 LayerImpl* layer_impl = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
[email protected]c1bb5af2013-03-13 19:06:271759 device_viewport_point, active_tree_->RenderSurfaceLayerList());
[email protected]31bfe272012-10-19 18:49:521760
[email protected]c1bb5af2013-03-13 19:06:271761 // Walk up the hierarchy and look for a scrollable layer.
1762 LayerImpl* potentially_scrolling_layer_impl = 0;
1763 for (; layer_impl; layer_impl = layer_impl->parent()) {
1764 // The content layer can also block attempts to scroll outside the main
1765 // thread.
1766 ScrollStatus status = layer_impl->TryScroll(device_viewport_point, type);
1767 if (status == ScrollOnMainThread) {
[email protected]372bad5f2013-03-21 16:38:431768 rendering_stats_instrumentation_->IncrementMainThreadScrolls();
[email protected]c1bb5af2013-03-13 19:06:271769 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true);
1770 return ScrollOnMainThread;
[email protected]94f206c12012-08-25 00:09:141771 }
1772
[email protected]c1bb5af2013-03-13 19:06:271773 LayerImpl* scroll_layer_impl = FindScrollLayerForContentLayer(layer_impl);
1774 if (!scroll_layer_impl)
1775 continue;
[email protected]94f206c12012-08-25 00:09:141776
[email protected]c1bb5af2013-03-13 19:06:271777 status = scroll_layer_impl->TryScroll(device_viewport_point, type);
[email protected]94f206c12012-08-25 00:09:141778
[email protected]c1bb5af2013-03-13 19:06:271779 // If any layer wants to divert the scroll event to the main thread, abort.
1780 if (status == ScrollOnMainThread) {
[email protected]372bad5f2013-03-21 16:38:431781 rendering_stats_instrumentation_->IncrementMainThreadScrolls();
[email protected]c1bb5af2013-03-13 19:06:271782 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", true);
1783 return ScrollOnMainThread;
[email protected]94f206c12012-08-25 00:09:141784 }
1785
[email protected]c1bb5af2013-03-13 19:06:271786 if (status == ScrollStarted && !potentially_scrolling_layer_impl)
1787 potentially_scrolling_layer_impl = scroll_layer_impl;
1788 }
1789
1790 // When hiding top controls is enabled and the controls are hidden or
1791 // overlaying the content, force scrolls to be enabled on the root layer to
1792 // allow bringing the top controls back into view.
1793 if (!potentially_scrolling_layer_impl && top_controls_manager_ &&
1794 top_controls_manager_->content_top_offset() !=
[email protected]8e0176d2013-03-21 03:14:521795 settings_.top_controls_height) {
[email protected]c1bb5af2013-03-13 19:06:271796 potentially_scrolling_layer_impl = RootScrollLayer();
1797 }
1798
1799 if (potentially_scrolling_layer_impl) {
[email protected]0fc818e2013-03-18 06:45:201800 active_tree_->SetCurrentlyScrollingLayer(
[email protected]c1bb5af2013-03-13 19:06:271801 potentially_scrolling_layer_impl);
1802 should_bubble_scrolls_ = (type != NonBubblingGesture);
1803 wheel_scrolling_ = (type == Wheel);
[email protected]372bad5f2013-03-21 16:38:431804 rendering_stats_instrumentation_->IncrementImplThreadScrolls();
[email protected]c1bb5af2013-03-13 19:06:271805 client_->RenewTreePriority();
1806 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false);
1807 return ScrollStarted;
1808 }
1809 return ScrollIgnored;
[email protected]94f206c12012-08-25 00:09:141810}
1811
[email protected]c1bb5af2013-03-13 19:06:271812gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta(
1813 LayerImpl* layer_impl,
1814 float scale_from_viewport_to_screen_space,
1815 gfx::PointF viewport_point,
1816 gfx::Vector2dF viewport_delta) {
1817 // Layers with non-invertible screen space transforms should not have passed
1818 // the scroll hit test in the first place.
1819 DCHECK(layer_impl->screen_space_transform().IsInvertible());
1820 gfx::Transform inverse_screen_space_transform(
1821 gfx::Transform::kSkipInitialization);
1822 bool did_invert = layer_impl->screen_space_transform().GetInverse(
1823 &inverse_screen_space_transform);
[email protected]ca2902e92013-03-28 01:45:351824 // TODO(shawnsingh): With the advent of impl-side crolling for non-root
1825 // layers, we may need to explicitly handle uninvertible transforms here.
[email protected]c1bb5af2013-03-13 19:06:271826 DCHECK(did_invert);
[email protected]94f206c12012-08-25 00:09:141827
[email protected]c1bb5af2013-03-13 19:06:271828 gfx::PointF screen_space_point =
1829 gfx::ScalePoint(viewport_point, scale_from_viewport_to_screen_space);
[email protected]94f206c12012-08-25 00:09:141830
[email protected]c1bb5af2013-03-13 19:06:271831 gfx::Vector2dF screen_space_delta = viewport_delta;
1832 screen_space_delta.Scale(scale_from_viewport_to_screen_space);
1833
1834 // First project the scroll start and end points to local layer space to find
1835 // the scroll delta in layer coordinates.
1836 bool start_clipped, end_clipped;
1837 gfx::PointF screen_space_end_point = screen_space_point + screen_space_delta;
1838 gfx::PointF local_start_point =
[email protected]fa816c62013-03-18 04:24:211839 MathUtil::ProjectPoint(inverse_screen_space_transform,
[email protected]c1bb5af2013-03-13 19:06:271840 screen_space_point,
[email protected]fa816c62013-03-18 04:24:211841 &start_clipped);
[email protected]c1bb5af2013-03-13 19:06:271842 gfx::PointF local_end_point =
[email protected]fa816c62013-03-18 04:24:211843 MathUtil::ProjectPoint(inverse_screen_space_transform,
[email protected]c1bb5af2013-03-13 19:06:271844 screen_space_end_point,
[email protected]fa816c62013-03-18 04:24:211845 &end_clipped);
[email protected]c1bb5af2013-03-13 19:06:271846
1847 // In general scroll point coordinates should not get clipped.
1848 DCHECK(!start_clipped);
1849 DCHECK(!end_clipped);
1850 if (start_clipped || end_clipped)
1851 return gfx::Vector2dF();
1852
1853 // local_start_point and local_end_point are in content space but we want to
1854 // move them to layer space for scrolling.
1855 float width_scale = 1.f / layer_impl->contents_scale_x();
1856 float height_scale = 1.f / layer_impl->contents_scale_y();
1857 local_start_point.Scale(width_scale, height_scale);
1858 local_end_point.Scale(width_scale, height_scale);
1859
1860 // Apply the scroll delta.
[email protected]1960a712013-04-30 17:06:471861 gfx::Vector2dF previous_delta = layer_impl->ScrollDelta();
[email protected]c1bb5af2013-03-13 19:06:271862 layer_impl->ScrollBy(local_end_point - local_start_point);
1863
1864 // Get the end point in the layer's content space so we can apply its
1865 // ScreenSpaceTransform.
1866 gfx::PointF actual_local_end_point = local_start_point +
[email protected]1960a712013-04-30 17:06:471867 layer_impl->ScrollDelta() -
[email protected]c1bb5af2013-03-13 19:06:271868 previous_delta;
1869 gfx::PointF actual_local_content_end_point =
1870 gfx::ScalePoint(actual_local_end_point,
1871 1.f / width_scale,
1872 1.f / height_scale);
1873
1874 // Calculate the applied scroll delta in viewport space coordinates.
1875 gfx::PointF actual_screen_space_end_point =
[email protected]fa816c62013-03-18 04:24:211876 MathUtil::MapPoint(layer_impl->screen_space_transform(),
[email protected]c1bb5af2013-03-13 19:06:271877 actual_local_content_end_point,
[email protected]fa816c62013-03-18 04:24:211878 &end_clipped);
[email protected]c1bb5af2013-03-13 19:06:271879 DCHECK(!end_clipped);
1880 if (end_clipped)
1881 return gfx::Vector2dF();
1882 gfx::PointF actual_viewport_end_point =
1883 gfx::ScalePoint(actual_screen_space_end_point,
1884 1.f / scale_from_viewport_to_screen_space);
1885 return actual_viewport_end_point - viewport_point;
[email protected]94f206c12012-08-25 00:09:141886}
1887
[email protected]c1bb5af2013-03-13 19:06:271888static gfx::Vector2dF ScrollLayerWithLocalDelta(LayerImpl* layer_impl,
1889 gfx::Vector2dF local_delta) {
[email protected]1960a712013-04-30 17:06:471890 gfx::Vector2dF previous_delta(layer_impl->ScrollDelta());
[email protected]c1bb5af2013-03-13 19:06:271891 layer_impl->ScrollBy(local_delta);
[email protected]1960a712013-04-30 17:06:471892 return layer_impl->ScrollDelta() - previous_delta;
[email protected]c1bb5af2013-03-13 19:06:271893}
1894
1895bool LayerTreeHostImpl::ScrollBy(gfx::Point viewport_point,
1896 gfx::Vector2dF scroll_delta) {
1897 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy");
1898 if (!CurrentlyScrollingLayer())
1899 return false;
1900
1901 gfx::Vector2dF pending_delta = scroll_delta;
[email protected]a2b5ded2013-05-20 21:32:531902 gfx::Vector2dF unused_root_delta;
[email protected]2bd503f2013-07-23 05:35:291903 bool did_scroll_x = false;
1904 bool did_scroll_y = false;
[email protected]60b4d252013-03-23 18:49:421905 bool consume_by_top_controls = top_controls_manager_ &&
1906 (CurrentlyScrollingLayer() == RootScrollLayer() || scroll_delta.y() < 0);
[email protected]a91e4f82013-03-15 06:58:061907
[email protected]c1bb5af2013-03-13 19:06:271908 for (LayerImpl* layer_impl = CurrentlyScrollingLayer();
1909 layer_impl;
1910 layer_impl = layer_impl->parent()) {
1911 if (!layer_impl->scrollable())
1912 continue;
1913
[email protected]a2b5ded2013-05-20 21:32:531914 if (layer_impl == RootScrollLayer()) {
1915 // Only allow bubble scrolling when the scroll is in the direction to make
1916 // the top controls visible.
1917 if (consume_by_top_controls && layer_impl == RootScrollLayer()) {
1918 pending_delta = top_controls_manager_->ScrollBy(pending_delta);
1919 UpdateMaxScrollOffset();
1920 }
1921 // Track root layer deltas for reporting overscroll.
1922 unused_root_delta = pending_delta;
[email protected]60b4d252013-03-23 18:49:421923 }
1924
[email protected]c1bb5af2013-03-13 19:06:271925 gfx::Vector2dF applied_delta;
[email protected]c1bb5af2013-03-13 19:06:271926 // Gesture events need to be transformed from viewport coordinates to local
1927 // layer coordinates so that the scrolling contents exactly follow the
1928 // user's finger. In contrast, wheel events represent a fixed amount of
1929 // scrolling so we can just apply them directly.
1930 if (!wheel_scrolling_) {
1931 float scale_from_viewport_to_screen_space = device_scale_factor_;
1932 applied_delta =
1933 ScrollLayerWithViewportSpaceDelta(layer_impl,
1934 scale_from_viewport_to_screen_space,
1935 viewport_point, pending_delta);
1936 } else {
1937 applied_delta = ScrollLayerWithLocalDelta(layer_impl, pending_delta);
[email protected]94f206c12012-08-25 00:09:141938 }
[email protected]94f206c12012-08-25 00:09:141939
[email protected]c1bb5af2013-03-13 19:06:271940 // If the layer wasn't able to move, try the next one in the hierarchy.
[email protected]2bd503f2013-07-23 05:35:291941 float move_threshold = 0.1f;
1942 bool did_move_layer_x = std::abs(applied_delta.x()) > move_threshold;
1943 bool did_move_layer_y = std::abs(applied_delta.y()) > move_threshold;
1944 did_scroll_x |= did_move_layer_x;
1945 did_scroll_y |= did_move_layer_y;
1946 if (!did_move_layer_x && !did_move_layer_y) {
[email protected]c1bb5af2013-03-13 19:06:271947 if (should_bubble_scrolls_ || !did_lock_scrolling_layer_)
1948 continue;
1949 else
1950 break;
[email protected]94f206c12012-08-25 00:09:141951 }
[email protected]a2b5ded2013-05-20 21:32:531952
1953 if (layer_impl == RootScrollLayer())
1954 unused_root_delta.Subtract(applied_delta);
1955
[email protected]c1bb5af2013-03-13 19:06:271956 did_lock_scrolling_layer_ = true;
1957 if (!should_bubble_scrolls_) {
[email protected]0fc818e2013-03-18 06:45:201958 active_tree_->SetCurrentlyScrollingLayer(layer_impl);
[email protected]c1bb5af2013-03-13 19:06:271959 break;
[email protected]94f206c12012-08-25 00:09:141960 }
[email protected]94f206c12012-08-25 00:09:141961
[email protected]c1bb5af2013-03-13 19:06:271962 // If the applied delta is within 45 degrees of the input delta, bail out to
1963 // make it easier to scroll just one layer in one direction without
1964 // affecting any of its parents.
1965 float angle_threshold = 45;
[email protected]fa816c62013-03-18 04:24:211966 if (MathUtil::SmallestAngleBetweenVectors(
[email protected]c1bb5af2013-03-13 19:06:271967 applied_delta, pending_delta) < angle_threshold) {
1968 pending_delta = gfx::Vector2d();
1969 break;
[email protected]4a23c374c2012-12-08 08:38:551970 }
[email protected]c1bb5af2013-03-13 19:06:271971
1972 // Allow further movement only on an axis perpendicular to the direction in
1973 // which the layer moved.
1974 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x());
[email protected]fa816c62013-03-18 04:24:211975 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis);
[email protected]c1bb5af2013-03-13 19:06:271976
[email protected]a2b5ded2013-05-20 21:32:531977 if (gfx::ToRoundedVector2d(pending_delta).IsZero())
[email protected]c1bb5af2013-03-13 19:06:271978 break;
1979 }
1980
[email protected]2bd503f2013-07-23 05:35:291981 bool did_scroll = did_scroll_x || did_scroll_y;
[email protected]c1bb5af2013-03-13 19:06:271982 if (did_scroll) {
1983 client_->SetNeedsCommitOnImplThread();
1984 client_->SetNeedsRedrawOnImplThread();
1985 client_->RenewTreePriority();
1986 }
[email protected]a2b5ded2013-05-20 21:32:531987
[email protected]2bd503f2013-07-23 05:35:291988 // Scrolling along an axis resets accumulated root overscroll for that axis.
1989 if (did_scroll_x)
1990 accumulated_root_overscroll_.set_x(0);
1991 if (did_scroll_y)
1992 accumulated_root_overscroll_.set_y(0);
1993
[email protected]a2b5ded2013-05-20 21:32:531994 accumulated_root_overscroll_ += unused_root_delta;
1995 bool did_overscroll = !gfx::ToRoundedVector2d(unused_root_delta).IsZero();
1996 if (did_overscroll && input_handler_client_) {
[email protected]bfb6e242013-07-17 23:15:111997 DidOverscrollParams params;
1998 params.accumulated_overscroll = accumulated_root_overscroll_;
1999 params.latest_overscroll_delta = unused_root_delta;
2000 params.current_fling_velocity = current_fling_velocity_;
2001 input_handler_client_->DidOverscroll(params);
[email protected]a2b5ded2013-05-20 21:32:532002 }
2003
[email protected]c1bb5af2013-03-13 19:06:272004 return did_scroll;
[email protected]4a23c374c2012-12-08 08:38:552005}
2006
[email protected]be782f52013-03-23 21:36:142007// This implements scrolling by page as described here:
2008// http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).aspx#_win32_The_Mouse_Wheel
2009// for events with WHEEL_PAGESCROLL set.
[email protected]c28df4c12013-05-22 17:36:492010bool LayerTreeHostImpl::ScrollVerticallyByPage(gfx::Point viewport_point,
2011 ScrollDirection direction) {
[email protected]be782f52013-03-23 21:36:142012 DCHECK(wheel_scrolling_);
2013
2014 for (LayerImpl* layer_impl = CurrentlyScrollingLayer();
2015 layer_impl;
2016 layer_impl = layer_impl->parent()) {
2017 if (!layer_impl->scrollable())
2018 continue;
2019
2020 if (!layer_impl->vertical_scrollbar_layer())
2021 continue;
2022
2023 float height = layer_impl->vertical_scrollbar_layer()->bounds().height();
2024
2025 // These magical values match WebKit and are designed to scroll nearly the
2026 // entire visible content height but leave a bit of overlap.
2027 float page = std::max(height * 0.875f, 1.f);
[email protected]c28df4c12013-05-22 17:36:492028 if (direction == SCROLL_BACKWARD)
[email protected]be782f52013-03-23 21:36:142029 page = -page;
2030
2031 gfx::Vector2dF delta = gfx::Vector2dF(0.f, page);
2032
2033 gfx::Vector2dF applied_delta = ScrollLayerWithLocalDelta(layer_impl, delta);
2034
2035 if (!applied_delta.IsZero()) {
[email protected]be782f52013-03-23 21:36:142036 client_->SetNeedsCommitOnImplThread();
2037 client_->SetNeedsRedrawOnImplThread();
2038 client_->RenewTreePriority();
2039 return true;
2040 }
2041
2042 active_tree_->SetCurrentlyScrollingLayer(layer_impl);
2043 }
2044
2045 return false;
2046}
2047
[email protected]1960a712013-04-30 17:06:472048void LayerTreeHostImpl::SetRootLayerScrollOffsetDelegate(
2049 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
2050 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
2051 active_tree_->SetRootLayerScrollOffsetDelegate(
2052 root_layer_scroll_offset_delegate_);
2053}
2054
2055void LayerTreeHostImpl::OnRootLayerDelegatedScrollOffsetChanged() {
2056 DCHECK(root_layer_scroll_offset_delegate_ != NULL);
2057 client_->SetNeedsCommitOnImplThread();
2058}
2059
[email protected]c1bb5af2013-03-13 19:06:272060void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() {
2061 active_tree_->ClearCurrentlyScrollingLayer();
2062 did_lock_scrolling_layer_ = false;
[email protected]a2b5ded2013-05-20 21:32:532063 accumulated_root_overscroll_ = gfx::Vector2dF();
[email protected]6e921bd2013-04-29 21:10:202064 current_fling_velocity_ = gfx::Vector2dF();
[email protected]94f206c12012-08-25 00:09:142065}
2066
[email protected]c1bb5af2013-03-13 19:06:272067void LayerTreeHostImpl::ScrollEnd() {
2068 if (top_controls_manager_)
2069 top_controls_manager_->ScrollEnd();
2070 ClearCurrentlyScrollingLayer();
[email protected]21c9dee72013-06-15 01:20:052071 StartScrollbarAnimation();
[email protected]94f206c12012-08-25 00:09:142072}
2073
[email protected]5ff3c9782013-04-29 17:35:122074InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() {
[email protected]7c45d8152013-04-23 18:27:212075 if (active_tree_->CurrentlyScrollingLayer())
2076 return ScrollStarted;
2077
2078 return ScrollIgnored;
2079}
2080
[email protected]6e921bd2013-04-29 21:10:202081void LayerTreeHostImpl::NotifyCurrentFlingVelocity(gfx::Vector2dF velocity) {
2082 current_fling_velocity_ = velocity;
2083}
2084
[email protected]c1bb5af2013-03-13 19:06:272085void LayerTreeHostImpl::PinchGestureBegin() {
2086 pinch_gesture_active_ = true;
2087 previous_pinch_anchor_ = gfx::Point();
2088 client_->RenewTreePriority();
[email protected]94f206c12012-08-25 00:09:142089}
2090
[email protected]c1bb5af2013-03-13 19:06:272091void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta,
2092 gfx::Point anchor) {
2093 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate");
[email protected]d3afa112012-12-08 06:24:282094
[email protected]c1bb5af2013-03-13 19:06:272095 if (!RootScrollLayer())
2096 return;
[email protected]d3afa112012-12-08 06:24:282097
[email protected]c1bb5af2013-03-13 19:06:272098 // Keep the center-of-pinch anchor specified by (x, y) in a stable
2099 // position over the course of the magnify.
2100 float page_scale_delta = active_tree_->page_scale_delta();
2101 gfx::PointF previous_scale_anchor =
2102 gfx::ScalePoint(anchor, 1.f / page_scale_delta);
2103 active_tree_->SetPageScaleDelta(page_scale_delta * magnify_delta);
2104 page_scale_delta = active_tree_->page_scale_delta();
2105 gfx::PointF new_scale_anchor =
2106 gfx::ScalePoint(anchor, 1.f / page_scale_delta);
2107 gfx::Vector2dF move = previous_scale_anchor - new_scale_anchor;
2108
2109 previous_pinch_anchor_ = anchor;
2110
2111 move.Scale(1 / active_tree_->page_scale_factor());
2112
2113 RootScrollLayer()->ScrollBy(move);
2114
[email protected]c1bb5af2013-03-13 19:06:272115 client_->SetNeedsCommitOnImplThread();
2116 client_->SetNeedsRedrawOnImplThread();
2117 client_->RenewTreePriority();
[email protected]d3afa112012-12-08 06:24:282118}
2119
[email protected]c1bb5af2013-03-13 19:06:272120void LayerTreeHostImpl::PinchGestureEnd() {
2121 pinch_gesture_active_ = false;
[email protected]c1bb5af2013-03-13 19:06:272122 client_->SetNeedsCommitOnImplThread();
[email protected]94f206c12012-08-25 00:09:142123}
2124
[email protected]c1bb5af2013-03-13 19:06:272125static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info,
2126 LayerImpl* layer_impl) {
2127 if (!layer_impl)
2128 return;
[email protected]94f206c12012-08-25 00:09:142129
[email protected]c1bb5af2013-03-13 19:06:272130 gfx::Vector2d scroll_delta =
[email protected]1960a712013-04-30 17:06:472131 gfx::ToFlooredVector2d(layer_impl->ScrollDelta());
[email protected]c1bb5af2013-03-13 19:06:272132 if (!scroll_delta.IsZero()) {
2133 LayerTreeHostCommon::ScrollUpdateInfo scroll;
[email protected]6ba914122013-03-22 16:26:392134 scroll.layer_id = layer_impl->id();
2135 scroll.scroll_delta = scroll_delta;
[email protected]c1bb5af2013-03-13 19:06:272136 scroll_info->scrolls.push_back(scroll);
2137 layer_impl->SetSentScrollDelta(scroll_delta);
2138 }
[email protected]94f206c12012-08-25 00:09:142139
[email protected]c1bb5af2013-03-13 19:06:272140 for (size_t i = 0; i < layer_impl->children().size(); ++i)
2141 CollectScrollDeltas(scroll_info, layer_impl->children()[i]);
[email protected]94f206c12012-08-25 00:09:142142}
2143
[email protected]c1bb5af2013-03-13 19:06:272144scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() {
2145 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet());
[email protected]362f1e8b2013-01-21 16:54:302146
[email protected]c1bb5af2013-03-13 19:06:272147 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer());
[email protected]6ba914122013-03-22 16:26:392148 scroll_info->page_scale_delta = active_tree_->page_scale_delta();
2149 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta);
[email protected]362f1e8b2013-01-21 16:54:302150
[email protected]c1bb5af2013-03-13 19:06:272151 return scroll_info.Pass();
[email protected]362f1e8b2013-01-21 16:54:302152}
2153
[email protected]c1bb5af2013-03-13 19:06:272154void LayerTreeHostImpl::SetFullRootLayerDamage() {
[email protected]878705be2013-04-15 22:44:022155 SetViewportDamage(gfx::Rect(device_viewport_size_));
[email protected]829ad972013-01-28 23:36:102156}
2157
[email protected]c1bb5af2013-03-13 19:06:272158void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks time) {
2159 if (!page_scale_animation_ || !RootScrollLayer())
2160 return;
2161
2162 double monotonic_time = (time - base::TimeTicks()).InSecondsF();
2163 gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() +
[email protected]1960a712013-04-30 17:06:472164 RootScrollLayer()->ScrollDelta();
[email protected]c1bb5af2013-03-13 19:06:272165
2166 active_tree_->SetPageScaleDelta(
2167 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) /
2168 active_tree_->page_scale_factor());
2169 gfx::Vector2dF next_scroll =
2170 page_scale_animation_->ScrollOffsetAtTime(monotonic_time);
2171
2172 RootScrollLayer()->ScrollBy(next_scroll - scroll_total);
2173 client_->SetNeedsRedrawOnImplThread();
2174
2175 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) {
2176 page_scale_animation_.reset();
2177 client_->SetNeedsCommitOnImplThread();
2178 client_->RenewTreePriority();
2179 }
[email protected]829ad972013-01-28 23:36:102180}
2181
[email protected]ffb2720f2013-03-15 19:18:372182void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) {
2183 if (!top_controls_manager_ || !RootScrollLayer())
2184 return;
2185 gfx::Vector2dF scroll = top_controls_manager_->Animate(time);
2186 UpdateMaxScrollOffset();
[email protected]5ef82622013-05-01 16:26:172187 if (RootScrollLayer()->TotalScrollOffset().y() == 0.f)
2188 return;
[email protected]ffb2720f2013-03-15 19:18:372189 RootScrollLayer()->ScrollBy(gfx::ScaleVector2d(
2190 scroll, 1.f / active_tree_->total_page_scale_factor()));
2191}
2192
[email protected]c1bb5af2013-03-13 19:06:272193void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time,
2194 base::Time wall_clock_time) {
[email protected]8e0176d2013-03-21 03:14:522195 if (!settings_.accelerated_animation_enabled ||
[email protected]c1bb5af2013-03-13 19:06:272196 animation_registrar_->active_animation_controllers().empty() ||
2197 !active_tree_->root_layer())
2198 return;
2199
2200 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers");
2201
2202 last_animation_time_ = wall_clock_time;
2203 double monotonic_seconds = (monotonic_time - base::TimeTicks()).InSecondsF();
2204
2205 AnimationRegistrar::AnimationControllerMap copy =
2206 animation_registrar_->active_animation_controllers();
2207 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin();
2208 iter != copy.end();
2209 ++iter)
2210 (*iter).second->Animate(monotonic_seconds);
2211
2212 client_->SetNeedsRedrawOnImplThread();
[email protected]131a0c22013-02-12 18:31:082213}
2214
[email protected]3d9f7432013-04-06 00:35:182215void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) {
[email protected]8e0176d2013-03-21 03:14:522216 if (!settings_.accelerated_animation_enabled ||
[email protected]c1bb5af2013-03-13 19:06:272217 animation_registrar_->active_animation_controllers().empty() ||
2218 !active_tree_->root_layer())
2219 return;
2220
2221 TRACE_EVENT0("cc", "LayerTreeHostImpl::UpdateAnimationState");
2222 scoped_ptr<AnimationEventsVector> events =
2223 make_scoped_ptr(new AnimationEventsVector);
2224 AnimationRegistrar::AnimationControllerMap copy =
2225 animation_registrar_->active_animation_controllers();
2226 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin();
2227 iter != copy.end();
2228 ++iter)
[email protected]3d9f7432013-04-06 00:35:182229 (*iter).second->UpdateState(start_ready_animations, events.get());
[email protected]c1bb5af2013-03-13 19:06:272230
2231 if (!events->empty()) {
2232 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass(),
2233 last_animation_time_);
2234 }
[email protected]131a0c22013-02-12 18:31:082235}
2236
[email protected]c1bb5af2013-03-13 19:06:272237base::TimeDelta LayerTreeHostImpl::LowFrequencyAnimationInterval() const {
2238 return base::TimeDelta::FromSeconds(1);
2239}
2240
[email protected]50644642013-06-20 13:58:552241void LayerTreeHostImpl::SendReleaseResourcesRecursive(LayerImpl* current) {
[email protected]ff1211d2013-06-07 01:58:352242 DCHECK(current);
[email protected]50644642013-06-20 13:58:552243 // TODO(boliu): Rename DidLoseOutputSurface to ReleaseResources.
[email protected]ff1211d2013-06-07 01:58:352244 current->DidLoseOutputSurface();
2245 if (current->mask_layer())
[email protected]50644642013-06-20 13:58:552246 SendReleaseResourcesRecursive(current->mask_layer());
[email protected]ff1211d2013-06-07 01:58:352247 if (current->replica_layer())
[email protected]50644642013-06-20 13:58:552248 SendReleaseResourcesRecursive(current->replica_layer());
[email protected]ff1211d2013-06-07 01:58:352249 for (size_t i = 0; i < current->children().size(); ++i)
[email protected]50644642013-06-20 13:58:552250 SendReleaseResourcesRecursive(current->children()[i]);
[email protected]ff1211d2013-06-07 01:58:352251}
2252
[email protected]c1bb5af2013-03-13 19:06:272253std::string LayerTreeHostImpl::LayerTreeAsJson() const {
2254 std::string str;
2255 if (active_tree_->root_layer()) {
2256 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson());
2257 base::JSONWriter::WriteWithOptions(
2258 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str);
2259 }
2260 return str;
2261}
2262
[email protected]c1bb5af2013-03-13 19:06:272263int LayerTreeHostImpl::SourceAnimationFrameNumber() const {
[email protected]9e3594522013-03-18 00:57:362264 return fps_counter_->current_frame_number();
[email protected]c1bb5af2013-03-13 19:06:272265}
2266
[email protected]c1bb5af2013-03-13 19:06:272267void LayerTreeHostImpl::SendManagedMemoryStats(
2268 size_t memory_visible_bytes,
2269 size_t memory_visible_and_nearby_bytes,
2270 size_t memory_use_bytes) {
2271 if (!renderer_)
2272 return;
2273
2274 // Round the numbers being sent up to the next 8MB, to throttle the rate
2275 // at which we spam the GPU process.
2276 static const size_t rounding_step = 8 * 1024 * 1024;
2277 memory_visible_bytes = RoundUp(memory_visible_bytes, rounding_step);
2278 memory_visible_and_nearby_bytes = RoundUp(memory_visible_and_nearby_bytes,
2279 rounding_step);
2280 memory_use_bytes = RoundUp(memory_use_bytes, rounding_step);
2281 if (last_sent_memory_visible_bytes_ == memory_visible_bytes &&
2282 last_sent_memory_visible_and_nearby_bytes_ ==
2283 memory_visible_and_nearby_bytes &&
2284 last_sent_memory_use_bytes_ == memory_use_bytes) {
2285 return;
2286 }
2287 last_sent_memory_visible_bytes_ = memory_visible_bytes;
2288 last_sent_memory_visible_and_nearby_bytes_ = memory_visible_and_nearby_bytes;
2289 last_sent_memory_use_bytes_ = memory_use_bytes;
2290
2291 renderer_->SendManagedMemoryStats(last_sent_memory_visible_bytes_,
2292 last_sent_memory_visible_and_nearby_bytes_,
2293 last_sent_memory_use_bytes_);
2294}
2295
2296void LayerTreeHostImpl::AnimateScrollbars(base::TimeTicks time) {
2297 AnimateScrollbarsRecursive(active_tree_->root_layer(), time);
2298}
2299
2300void LayerTreeHostImpl::AnimateScrollbarsRecursive(LayerImpl* layer,
2301 base::TimeTicks time) {
2302 if (!layer)
2303 return;
2304
2305 ScrollbarAnimationController* scrollbar_controller =
2306 layer->scrollbar_animation_controller();
[email protected]6bc09e82013-03-19 03:48:352307 if (scrollbar_controller && scrollbar_controller->Animate(time)) {
[email protected]0fc818e2013-03-18 06:45:202308 TRACE_EVENT_INSTANT0(
[email protected]c76faea2013-03-26 07:42:422309 "cc", "LayerTreeHostImpl::SetNeedsRedraw due to AnimateScrollbars",
2310 TRACE_EVENT_SCOPE_THREAD);
[email protected]c1bb5af2013-03-13 19:06:272311 client_->SetNeedsRedrawOnImplThread();
[email protected]0fc818e2013-03-18 06:45:202312 }
[email protected]c1bb5af2013-03-13 19:06:272313
2314 for (size_t i = 0; i < layer->children().size(); ++i)
2315 AnimateScrollbarsRecursive(layer->children()[i], time);
2316}
2317
[email protected]21c9dee72013-06-15 01:20:052318void LayerTreeHostImpl::StartScrollbarAnimation() {
[email protected]0fc818e2013-03-18 06:45:202319 TRACE_EVENT0("cc", "LayerTreeHostImpl::StartScrollbarAnimation");
[email protected]21c9dee72013-06-15 01:20:052320 StartScrollbarAnimationRecursive(RootLayer(), CurrentPhysicalTimeTicks());
[email protected]0fc818e2013-03-18 06:45:202321}
2322
2323void LayerTreeHostImpl::StartScrollbarAnimationRecursive(LayerImpl* layer,
2324 base::TimeTicks time) {
2325 if (!layer)
2326 return;
2327
2328 ScrollbarAnimationController* scrollbar_controller =
2329 layer->scrollbar_animation_controller();
[email protected]6bc09e82013-03-19 03:48:352330 if (scrollbar_controller && scrollbar_controller->IsAnimating()) {
2331 base::TimeDelta delay = scrollbar_controller->DelayBeforeStart(time);
[email protected]0fc818e2013-03-18 06:45:202332 if (delay > base::TimeDelta())
2333 client_->RequestScrollbarAnimationOnImplThread(delay);
[email protected]6bc09e82013-03-19 03:48:352334 else if (scrollbar_controller->Animate(time))
[email protected]0fc818e2013-03-18 06:45:202335 client_->SetNeedsRedrawOnImplThread();
2336 }
2337
2338 for (size_t i = 0; i < layer->children().size(); ++i)
2339 StartScrollbarAnimationRecursive(layer->children()[i], time);
2340}
2341
[email protected]c1bb5af2013-03-13 19:06:272342void LayerTreeHostImpl::SetTreePriority(TreePriority priority) {
2343 if (!tile_manager_)
2344 return;
2345
2346 GlobalStateThatImpactsTilePriority new_state(tile_manager_->GlobalState());
2347 if (new_state.tree_priority == priority)
2348 return;
2349
2350 new_state.tree_priority = priority;
2351 tile_manager_->SetGlobalState(new_state);
[email protected]a23451e2013-06-07 20:58:262352 manage_tiles_needed_ = true;
[email protected]c1bb5af2013-03-13 19:06:272353}
2354
[email protected]8347d692013-05-17 23:22:382355void LayerTreeHostImpl::ResetCurrentFrameTimeForNextFrame() {
[email protected]fb7425a2013-04-22 16:28:552356 current_frame_timeticks_ = base::TimeTicks();
2357 current_frame_time_ = base::Time();
[email protected]c1bb5af2013-03-13 19:06:272358}
2359
[email protected]21c9dee72013-06-15 01:20:052360void LayerTreeHostImpl::UpdateCurrentFrameTime(base::TimeTicks* ticks,
2361 base::Time* now) const {
[email protected]fb7425a2013-04-22 16:28:552362 if (ticks->is_null()) {
2363 DCHECK(now->is_null());
[email protected]21c9dee72013-06-15 01:20:052364 *ticks = CurrentPhysicalTimeTicks();
[email protected]fb7425a2013-04-22 16:28:552365 *now = base::Time::Now();
2366 }
2367}
2368
2369base::TimeTicks LayerTreeHostImpl::CurrentFrameTimeTicks() {
2370 UpdateCurrentFrameTime(&current_frame_timeticks_, &current_frame_time_);
2371 return current_frame_timeticks_;
2372}
2373
2374base::Time LayerTreeHostImpl::CurrentFrameTime() {
2375 UpdateCurrentFrameTime(&current_frame_timeticks_, &current_frame_time_);
[email protected]c1bb5af2013-03-13 19:06:272376 return current_frame_time_;
2377}
2378
[email protected]21c9dee72013-06-15 01:20:052379base::TimeTicks LayerTreeHostImpl::CurrentPhysicalTimeTicks() const {
2380 return base::TimeTicks::Now();
2381}
2382
[email protected]c1bb5af2013-03-13 19:06:272383scoped_ptr<base::Value> LayerTreeHostImpl::AsValue() const {
2384 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
[email protected]f6742f52013-05-08 23:52:222385 if (this->pending_tree_)
2386 state->Set("activation_state", ActivationStateAsValue().release());
[email protected]c1bb5af2013-03-13 19:06:272387 state->Set("device_viewport_size",
[email protected]fa816c62013-03-18 04:24:212388 MathUtil::AsValue(device_viewport_size_).release());
[email protected]c1bb5af2013-03-13 19:06:272389 if (tile_manager_)
2390 state->Set("tiles", tile_manager_->AllTilesAsValue().release());
2391 state->Set("active_tree", active_tree_->AsValue().release());
[email protected]f6742f52013-05-08 23:52:222392 if (pending_tree_)
2393 state->Set("pending_tree", pending_tree_->AsValue().release());
2394 return state.PassAs<base::Value>();
2395}
2396
2397scoped_ptr<base::Value> LayerTreeHostImpl::ActivationStateAsValue() const {
[email protected]f6742f52013-05-08 23:52:222398 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
2399 state->Set("lthi", TracedValue::CreateIDRef(this).release());
[email protected]15cc9922013-05-24 07:31:472400 if (tile_manager_)
2401 state->Set("tile_manager", tile_manager_->BasicStateAsValue().release());
[email protected]c1bb5af2013-03-13 19:06:272402 return state.PassAs<base::Value>();
[email protected]131a0c22013-02-12 18:31:082403}
2404
[email protected]6e7fdeb2013-07-09 14:28:382405void LayerTreeHostImpl::SetDebugState(
2406 const LayerTreeDebugState& new_debug_state) {
2407 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state))
2408 return;
2409 if (debug_state_.continuous_painting != new_debug_state.continuous_painting)
[email protected]c1bb5af2013-03-13 19:06:272410 paint_time_counter_->ClearHistory();
[email protected]652cf132013-02-15 21:53:242411
[email protected]6e7fdeb2013-07-09 14:28:382412 debug_state_ = new_debug_state;
2413 SetFullRootLayerDamage();
[email protected]d0d12192013-02-08 19:02:022414}
2415
[email protected]d3143c732012-10-05 19:17:592416} // namespace cc