Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Side by Side Diff: cc/trees/layer_tree_host_impl.cc

Issue 1010663002: CC Animations: Redirect all compositor animation requests to AnimationHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@introduce
Patch Set: Add ported unittests. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 10
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 paint_time_counter_(PaintTimeCounter::Create()), 211 paint_time_counter_(PaintTimeCounter::Create()),
212 memory_history_(MemoryHistory::Create()), 212 memory_history_(MemoryHistory::Create()),
213 debug_rect_history_(DebugRectHistory::Create()), 213 debug_rect_history_(DebugRectHistory::Create()),
214 texture_mailbox_deleter_(new TextureMailboxDeleter( 214 texture_mailbox_deleter_(new TextureMailboxDeleter(
215 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() 215 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner()
216 : proxy_->MainThreadTaskRunner())), 216 : proxy_->MainThreadTaskRunner())),
217 max_memory_needed_bytes_(0), 217 max_memory_needed_bytes_(0),
218 device_scale_factor_(1.f), 218 device_scale_factor_(1.f),
219 resourceless_software_draw_(false), 219 resourceless_software_draw_(false),
220 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()), 220 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()),
221 animation_registrar_(AnimationRegistrar::Create()),
222 rendering_stats_instrumentation_(rendering_stats_instrumentation), 221 rendering_stats_instrumentation_(rendering_stats_instrumentation),
223 micro_benchmark_controller_(this), 222 micro_benchmark_controller_(this),
224 shared_bitmap_manager_(shared_bitmap_manager), 223 shared_bitmap_manager_(shared_bitmap_manager),
225 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), 224 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
226 task_graph_runner_(task_graph_runner), 225 task_graph_runner_(task_graph_runner),
227 id_(id), 226 id_(id),
228 requires_high_res_to_draw_(false), 227 requires_high_res_to_draw_(false),
229 is_likely_to_require_a_draw_(false), 228 is_likely_to_require_a_draw_(false),
230 frame_timing_tracker_(FrameTimingTracker::Create()) { 229 frame_timing_tracker_(FrameTimingTracker::Create()) {
231 if (settings.use_compositor_animation_timelines) { 230 if (settings.use_compositor_animation_timelines) {
232 animation_host_ = AnimationHost::Create(true); 231 animation_host_ = AnimationHost::Create(true);
233 animation_host_->SetLayerTreeMutatorsClient(this); 232 animation_host_->SetLayerTreeMutatorsClient(this);
233 animation_host_->SetSupportsScrollAnimations(
234 proxy_->SupportsImplScrolling());
235 } else {
236 animation_registrar_ = AnimationRegistrar::Create();
237 animation_registrar_->set_supports_scroll_animations(
238 proxy_->SupportsImplScrolling());
234 } 239 }
235 240
236 DCHECK(proxy_->IsImplThread()); 241 DCHECK(proxy_->IsImplThread());
237 DidVisibilityChange(this, visible_); 242 DidVisibilityChange(this, visible_);
238 animation_registrar_->set_supports_scroll_animations(
239 proxy_->SupportsImplScrolling());
240 243
241 SetDebugState(settings.initial_debug_state); 244 SetDebugState(settings.initial_debug_state);
242 245
243 // LTHI always has an active tree. 246 // LTHI always has an active tree.
244 active_tree_ = 247 active_tree_ =
245 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), 248 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(),
246 new SyncedTopControls, new SyncedElasticOverscroll); 249 new SyncedTopControls, new SyncedElasticOverscroll);
247 250
248 viewport_ = Viewport::Create(this); 251 viewport_ = Viewport::Create(this);
249 252
(...skipping 23 matching lines...) Expand all
273 // made a contract with our animation controllers that the registrar 276 // made a contract with our animation controllers that the registrar
274 // will outlive them, and we must make good. 277 // will outlive them, and we must make good.
275 if (recycle_tree_) 278 if (recycle_tree_)
276 recycle_tree_->Shutdown(); 279 recycle_tree_->Shutdown();
277 if (pending_tree_) 280 if (pending_tree_)
278 pending_tree_->Shutdown(); 281 pending_tree_->Shutdown();
279 active_tree_->Shutdown(); 282 active_tree_->Shutdown();
280 recycle_tree_ = nullptr; 283 recycle_tree_ = nullptr;
281 pending_tree_ = nullptr; 284 pending_tree_ = nullptr;
282 active_tree_ = nullptr; 285 active_tree_ = nullptr;
286
287 if (animation_host_) {
288 animation_host_->ClearTimelines();
289 animation_host_->SetLayerTreeMutatorsClient(nullptr);
290 }
291
283 DestroyTileManager(); 292 DestroyTileManager();
284 } 293 }
285 294
286 void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { 295 void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) {
287 // If the begin frame data was handled, then scroll and scale set was applied 296 // If the begin frame data was handled, then scroll and scale set was applied
288 // by the main thread, so the active tree needs to be updated as if these sent 297 // by the main thread, so the active tree needs to be updated as if these sent
289 // values were applied and committed. 298 // values were applied and committed.
290 if (CommitEarlyOutHandledCommit(reason)) { 299 if (CommitEarlyOutHandledCommit(reason)) {
291 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); 300 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit();
292 active_tree_->ResetContentsTexturesPurged(); 301 active_tree_->ResetContentsTexturesPurged();
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 // contents of its texture are updated as the last thing before the frame is 1565 // contents of its texture are updated as the last thing before the frame is
1557 // drawn. 1566 // drawn.
1558 if (active_tree_->hud_layer()) { 1567 if (active_tree_->hud_layer()) {
1559 TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture"); 1568 TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture");
1560 active_tree_->hud_layer()->UpdateHudTexture(draw_mode, 1569 active_tree_->hud_layer()->UpdateHudTexture(draw_mode,
1561 resource_provider_.get()); 1570 resource_provider_.get());
1562 } 1571 }
1563 1572
1564 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) { 1573 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) {
1565 bool disable_picture_quad_image_filtering = 1574 bool disable_picture_quad_image_filtering =
1566 IsActivelyScrolling() || animation_registrar_->needs_animate_layers(); 1575 IsActivelyScrolling() ||
1576 (animation_host_ ? animation_host_->NeedsAnimateLayers()
1577 : animation_registrar_->needs_animate_layers());
1567 1578
1568 scoped_ptr<SoftwareRenderer> temp_software_renderer = 1579 scoped_ptr<SoftwareRenderer> temp_software_renderer =
1569 SoftwareRenderer::Create(this, &settings_.renderer_settings, 1580 SoftwareRenderer::Create(this, &settings_.renderer_settings,
1570 output_surface_.get(), NULL); 1581 output_surface_.get(), NULL);
1571 temp_software_renderer->DrawFrame(&frame->render_passes, 1582 temp_software_renderer->DrawFrame(&frame->render_passes,
1572 device_scale_factor_, 1583 device_scale_factor_,
1573 DeviceViewport(), 1584 DeviceViewport(),
1574 DeviceClip(), 1585 DeviceClip(),
1575 disable_picture_quad_image_filtering); 1586 disable_picture_quad_image_filtering);
1576 } else { 1587 } else {
(...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after
3029 for (auto& it : controllers_copy) 3040 for (auto& it : controllers_copy)
3030 it->Animate(monotonic_time); 3041 it->Animate(monotonic_time);
3031 3042
3032 SetNeedsAnimate(); 3043 SetNeedsAnimate();
3033 } 3044 }
3034 3045
3035 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { 3046 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) {
3036 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) 3047 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer())
3037 return; 3048 return;
3038 3049
3039 if (animation_registrar_->AnimateLayers(monotonic_time)) 3050 if (animation_host_) {
3040 SetNeedsAnimate(); 3051 if (animation_host_->AnimateLayers(monotonic_time))
3052 SetNeedsAnimate();
3053 } else {
3054 if (animation_registrar_->AnimateLayers(monotonic_time))
3055 SetNeedsAnimate();
3056 }
3041 } 3057 }
3042 3058
3043 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { 3059 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) {
3044 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) 3060 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer())
3045 return; 3061 return;
3046 3062
3047 scoped_ptr<AnimationEventsVector> events = 3063 bool has_active_animations = false;
3048 animation_registrar_->CreateEvents(); 3064 scoped_ptr<AnimationEventsVector> events;
3049 const bool has_active_animations = animation_registrar_->UpdateAnimationState( 3065
3050 start_ready_animations, events.get()); 3066 if (animation_host_) {
3067 events = animation_host_->CreateEvents();
3068 has_active_animations = animation_host_->UpdateAnimationState(
3069 start_ready_animations, events.get());
3070 } else {
3071 events = animation_registrar_->CreateEvents();
3072 has_active_animations = animation_registrar_->UpdateAnimationState(
3073 start_ready_animations, events.get());
3074 }
3051 3075
3052 if (!events->empty()) 3076 if (!events->empty())
3053 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); 3077 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass());
3054 3078
3055 if (has_active_animations) 3079 if (has_active_animations)
3056 SetNeedsAnimate(); 3080 SetNeedsAnimate();
3057 } 3081 }
3058 3082
3059 void LayerTreeHostImpl::ActivateAnimations() { 3083 void LayerTreeHostImpl::ActivateAnimations() {
3060 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) 3084 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer())
3061 return; 3085 return;
3062 3086
3063 if (animation_registrar_->ActivateAnimations()) 3087 if (animation_host_) {
3064 SetNeedsAnimate(); 3088 if (animation_host_->ActivateAnimations())
3089 SetNeedsAnimate();
3090 } else {
3091 if (animation_registrar_->ActivateAnimations())
3092 SetNeedsAnimate();
3093 }
3065 } 3094 }
3066 3095
3067 std::string LayerTreeHostImpl::LayerTreeAsJson() const { 3096 std::string LayerTreeHostImpl::LayerTreeAsJson() const {
3068 std::string str; 3097 std::string str;
3069 if (active_tree_->root_layer()) { 3098 if (active_tree_->root_layer()) {
3070 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); 3099 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson());
3071 base::JSONWriter::WriteWithOptions( 3100 base::JSONWriter::WriteWithOptions(
3072 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); 3101 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str);
3073 } 3102 }
3074 return str; 3103 return str;
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
3489 const gfx::ScrollOffset& scroll_offset) { 3518 const gfx::ScrollOffset& scroll_offset) {
3490 if (affects_active_tree) { 3519 if (affects_active_tree) {
3491 SetTreeLayerScrollOffsetMutated(layer_id, active_tree(), scroll_offset); 3520 SetTreeLayerScrollOffsetMutated(layer_id, active_tree(), scroll_offset);
3492 } else { 3521 } else {
3493 SetTreeLayerScrollOffsetMutated(layer_id, pending_tree(), scroll_offset); 3522 SetTreeLayerScrollOffsetMutated(layer_id, pending_tree(), scroll_offset);
3494 SetTreeLayerScrollOffsetMutated(layer_id, recycle_tree(), scroll_offset); 3523 SetTreeLayerScrollOffsetMutated(layer_id, recycle_tree(), scroll_offset);
3495 } 3524 }
3496 } 3525 }
3497 3526
3498 } // namespace cc 3527 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698