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

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

Issue 1130043003: [Sketch] CC Animations: Torpedo the old intrusive animation system. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@implscroll
Patch Set: Delete more (headers and animation_registrar_ leftover) Created 5 years, 7 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
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <set> 10 #include <set>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/containers/small_map.h" 14 #include "base/containers/small_map.h"
15 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/trace_event/trace_event_argument.h" 19 #include "base/trace_event/trace_event_argument.h"
20 #include "cc/animation/animation_host.h" 20 #include "cc/animation/animation_host.h"
21 #include "cc/animation/animation_id_provider.h"
22 #include "cc/animation/scroll_offset_animation_curve.h"
23 #include "cc/animation/scrollbar_animation_controller.h" 21 #include "cc/animation/scrollbar_animation_controller.h"
24 #include "cc/animation/timing_function.h" 22 #include "cc/animation/timing_function.h"
25 #include "cc/base/math_util.h" 23 #include "cc/base/math_util.h"
26 #include "cc/base/util.h" 24 #include "cc/base/util.h"
27 #include "cc/debug/benchmark_instrumentation.h" 25 #include "cc/debug/benchmark_instrumentation.h"
28 #include "cc/debug/debug_rect_history.h" 26 #include "cc/debug/debug_rect_history.h"
29 #include "cc/debug/devtools_instrumentation.h" 27 #include "cc/debug/devtools_instrumentation.h"
30 #include "cc/debug/frame_rate_counter.h" 28 #include "cc/debug/frame_rate_counter.h"
31 #include "cc/debug/frame_viewer_instrumentation.h" 29 #include "cc/debug/frame_viewer_instrumentation.h"
32 #include "cc/debug/paint_time_counter.h" 30 #include "cc/debug/paint_time_counter.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()), 220 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()),
223 rendering_stats_instrumentation_(rendering_stats_instrumentation), 221 rendering_stats_instrumentation_(rendering_stats_instrumentation),
224 micro_benchmark_controller_(this), 222 micro_benchmark_controller_(this),
225 shared_bitmap_manager_(shared_bitmap_manager), 223 shared_bitmap_manager_(shared_bitmap_manager),
226 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), 224 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
227 task_graph_runner_(task_graph_runner), 225 task_graph_runner_(task_graph_runner),
228 id_(id), 226 id_(id),
229 requires_high_res_to_draw_(false), 227 requires_high_res_to_draw_(false),
230 is_likely_to_require_a_draw_(false), 228 is_likely_to_require_a_draw_(false),
231 frame_timing_tracker_(FrameTimingTracker::Create()) { 229 frame_timing_tracker_(FrameTimingTracker::Create()) {
232 if (settings.use_compositor_animation_timelines) { 230 animation_host_ = AnimationHost::Create(true);
233 animation_host_ = AnimationHost::Create(true); 231 animation_host_->SetLayerTreeMutatorsClient(this);
234 animation_host_->SetLayerTreeMutatorsClient(this); 232 animation_host_->SetSupportsScrollAnimations(proxy_->SupportsImplScrolling());
235 animation_host_->SetSupportsScrollAnimations(
236 proxy_->SupportsImplScrolling());
237 } else {
238 animation_registrar_ = AnimationRegistrar::Create();
239 animation_registrar_->set_supports_scroll_animations(
240 proxy_->SupportsImplScrolling());
241 }
242 233
243 DCHECK(proxy_->IsImplThread()); 234 DCHECK(proxy_->IsImplThread());
244 DidVisibilityChange(this, visible_); 235 DidVisibilityChange(this, visible_);
245 236
246 SetDebugState(settings.initial_debug_state); 237 SetDebugState(settings.initial_debug_state);
247 238
248 // LTHI always has an active tree. 239 // LTHI always has an active tree.
249 active_tree_ = 240 active_tree_ =
250 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), 241 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(),
251 new SyncedTopControls, new SyncedElasticOverscroll); 242 new SyncedTopControls, new SyncedElasticOverscroll);
(...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 // contents of its texture are updated as the last thing before the frame is 1532 // contents of its texture are updated as the last thing before the frame is
1542 // drawn. 1533 // drawn.
1543 if (active_tree_->hud_layer()) { 1534 if (active_tree_->hud_layer()) {
1544 TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture"); 1535 TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture");
1545 active_tree_->hud_layer()->UpdateHudTexture(draw_mode, 1536 active_tree_->hud_layer()->UpdateHudTexture(draw_mode,
1546 resource_provider_.get()); 1537 resource_provider_.get());
1547 } 1538 }
1548 1539
1549 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) { 1540 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) {
1550 bool disable_picture_quad_image_filtering = 1541 bool disable_picture_quad_image_filtering =
1551 IsActivelyScrolling() || 1542 IsActivelyScrolling() || animation_host_->NeedsAnimateLayers();
1552 (animation_host_ ? animation_host_->NeedsAnimateLayers()
1553 : animation_registrar_->needs_animate_layers());
1554 1543
1555 scoped_ptr<SoftwareRenderer> temp_software_renderer = 1544 scoped_ptr<SoftwareRenderer> temp_software_renderer =
1556 SoftwareRenderer::Create(this, &settings_.renderer_settings, 1545 SoftwareRenderer::Create(this, &settings_.renderer_settings,
1557 output_surface_.get(), NULL); 1546 output_surface_.get(), NULL);
1558 temp_software_renderer->DrawFrame(&frame->render_passes, 1547 temp_software_renderer->DrawFrame(&frame->render_passes,
1559 device_scale_factor_, 1548 device_scale_factor_,
1560 DeviceViewport(), 1549 DeviceViewport(),
1561 DeviceClip(), 1550 DeviceClip(),
1562 disable_picture_quad_image_filtering); 1551 disable_picture_quad_image_filtering);
1563 } else { 1552 } else {
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
3019 for (auto& it : controllers_copy) 3008 for (auto& it : controllers_copy)
3020 it->Animate(monotonic_time); 3009 it->Animate(monotonic_time);
3021 3010
3022 SetNeedsAnimate(); 3011 SetNeedsAnimate();
3023 } 3012 }
3024 3013
3025 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { 3014 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) {
3026 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) 3015 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer())
3027 return; 3016 return;
3028 3017
3029 if (animation_host_) { 3018 if (animation_host_->AnimateLayers(monotonic_time))
3030 if (animation_host_->AnimateLayers(monotonic_time)) 3019 SetNeedsAnimate();
3031 SetNeedsAnimate();
3032 } else {
3033 if (animation_registrar_->AnimateLayers(monotonic_time))
3034 SetNeedsAnimate();
3035 }
3036 } 3020 }
3037 3021
3038 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { 3022 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) {
3039 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) 3023 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer())
3040 return; 3024 return;
3041 3025
3042 bool has_active_animations = false; 3026 bool has_active_animations = false;
3043 scoped_ptr<AnimationEventsVector> events; 3027 scoped_ptr<AnimationEventsVector> events;
3044 3028
3045 if (animation_host_) { 3029 events = animation_host_->CreateEvents();
3046 events = animation_host_->CreateEvents(); 3030 has_active_animations = animation_host_->UpdateAnimationState(
3047 has_active_animations = animation_host_->UpdateAnimationState( 3031 start_ready_animations, events.get());
3048 start_ready_animations, events.get());
3049 } else {
3050 events = animation_registrar_->CreateEvents();
3051 has_active_animations = animation_registrar_->UpdateAnimationState(
3052 start_ready_animations, events.get());
3053 }
3054 3032
3055 if (!events->empty()) 3033 if (!events->empty())
3056 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); 3034 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass());
3057 3035
3058 if (has_active_animations) 3036 if (has_active_animations)
3059 SetNeedsAnimate(); 3037 SetNeedsAnimate();
3060 } 3038 }
3061 3039
3062 void LayerTreeHostImpl::ActivateAnimations() { 3040 void LayerTreeHostImpl::ActivateAnimations() {
3063 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer()) 3041 if (!settings_.accelerated_animation_enabled || !active_tree_->root_layer())
3064 return; 3042 return;
3065 3043
3066 if (animation_host_) { 3044 if (animation_host_->ActivateAnimations())
3067 if (animation_host_->ActivateAnimations()) 3045 SetNeedsAnimate();
3068 SetNeedsAnimate();
3069 } else {
3070 if (animation_registrar_->ActivateAnimations())
3071 SetNeedsAnimate();
3072 }
3073 } 3046 }
3074 3047
3075 std::string LayerTreeHostImpl::LayerTreeAsJson() const { 3048 std::string LayerTreeHostImpl::LayerTreeAsJson() const {
3076 std::string str; 3049 std::string str;
3077 if (active_tree_->root_layer()) { 3050 if (active_tree_->root_layer()) {
3078 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); 3051 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson());
3079 base::JSONWriter::WriteWithOptions( 3052 base::JSONWriter::WriteWithOptions(
3080 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); 3053 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str);
3081 } 3054 }
3082 return str; 3055 return str;
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
3361 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfForwardingToMainThread() { 3334 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfForwardingToMainThread() {
3362 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); 3335 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin();
3363 for (; it != swap_promise_monitor_.end(); it++) 3336 for (; it != swap_promise_monitor_.end(); it++)
3364 (*it)->OnForwardScrollUpdateToMainThreadOnImpl(); 3337 (*it)->OnForwardScrollUpdateToMainThreadOnImpl();
3365 } 3338 }
3366 3339
3367 void LayerTreeHostImpl::ScrollAnimationCreate( 3340 void LayerTreeHostImpl::ScrollAnimationCreate(
3368 LayerImpl* layer_impl, 3341 LayerImpl* layer_impl,
3369 const gfx::ScrollOffset& target_offset, 3342 const gfx::ScrollOffset& target_offset,
3370 const gfx::ScrollOffset& current_offset) { 3343 const gfx::ScrollOffset& current_offset) {
3371 if (animation_host_) 3344 return animation_host_->ImplOnlyScrollAnimationCreate(
3372 return animation_host_->ImplOnlyScrollAnimationCreate( 3345 layer_impl->id(), target_offset, current_offset);
3373 layer_impl->id(), target_offset, current_offset);
3374
3375 scoped_ptr<ScrollOffsetAnimationCurve> curve =
3376 ScrollOffsetAnimationCurve::Create(target_offset,
3377 EaseInOutTimingFunction::Create());
3378 curve->SetInitialValue(current_offset);
3379
3380 scoped_ptr<Animation> animation = Animation::Create(
3381 curve.Pass(), AnimationIdProvider::NextAnimationId(),
3382 AnimationIdProvider::NextGroupId(), Animation::SCROLL_OFFSET);
3383 animation->set_is_impl_only(true);
3384
3385 layer_impl->layer_animation_controller()->AddAnimation(animation.Pass());
3386 } 3346 }
3387 3347
3388 bool LayerTreeHostImpl::ScrollAnimationUpdateTarget( 3348 bool LayerTreeHostImpl::ScrollAnimationUpdateTarget(
3389 LayerImpl* layer_impl, 3349 LayerImpl* layer_impl,
3390 const gfx::Vector2dF& scroll_delta) { 3350 const gfx::Vector2dF& scroll_delta) {
3391 if (animation_host_) 3351 return animation_host_->ImplOnlyScrollAnimationUpdateTarget(
3392 return animation_host_->ImplOnlyScrollAnimationUpdateTarget( 3352 layer_impl->id(), scroll_delta, layer_impl->MaxScrollOffset(),
3393 layer_impl->id(), scroll_delta, layer_impl->MaxScrollOffset(), 3353 CurrentBeginFrameArgs().frame_time);
3394 CurrentBeginFrameArgs().frame_time);
3395
3396 Animation* animation =
3397 layer_impl->layer_animation_controller()
3398 ? layer_impl->layer_animation_controller()->GetAnimation(
3399 Animation::SCROLL_OFFSET)
3400 : nullptr;
3401 if (!animation)
3402 return false;
3403
3404 ScrollOffsetAnimationCurve* curve =
3405 animation->curve()->ToScrollOffsetAnimationCurve();
3406
3407 gfx::ScrollOffset new_target =
3408 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta);
3409 new_target.SetToMax(gfx::ScrollOffset());
3410 new_target.SetToMin(layer_impl->MaxScrollOffset());
3411
3412 curve->UpdateTarget(
3413 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time)
3414 .InSecondsF(),
3415 new_target);
3416
3417 return true;
3418 } 3354 }
3419 3355
3420 bool LayerTreeHostImpl::IsLayerInActiveTree(int layer_id) const { 3356 bool LayerTreeHostImpl::IsLayerInActiveTree(int layer_id) const {
3421 return active_tree() ? active_tree()->LayerById(layer_id) != nullptr : false; 3357 return active_tree() ? active_tree()->LayerById(layer_id) != nullptr : false;
3422 } 3358 }
3423 3359
3424 bool LayerTreeHostImpl::IsLayerInPendingTree(int layer_id) const { 3360 bool LayerTreeHostImpl::IsLayerInPendingTree(int layer_id) const {
3425 if (pending_tree() && pending_tree()->LayerById(layer_id)) 3361 if (pending_tree() && pending_tree()->LayerById(layer_id))
3426 return true; 3362 return true;
3427 if (recycle_tree() && recycle_tree()->LayerById(layer_id)) 3363 if (recycle_tree() && recycle_tree()->LayerById(layer_id))
3428 return true; 3364 return true;
3429 3365
3430 return false; 3366 return false;
3431 } 3367 }
3432 3368
3433 void LayerTreeHostImpl::SetMutatorsNeedCommit() { 3369 void LayerTreeHostImpl::SetMutatorsNeedCommit() {
3434 SetNeedsCommit(); 3370 SetNeedsCommit();
3435 } 3371 }
3436 3372
3437 void LayerTreeHostImpl::SetTreeLayerFilterMutated( 3373 void LayerTreeHostImpl::SetTreeLayerFilterMutated(
3438 int layer_id, 3374 int layer_id,
3439 LayerTreeImpl* tree, 3375 LayerTreeImpl* tree,
3440 const FilterOperations& filters) { 3376 const FilterOperations& filters) {
3441 if (!tree) 3377 if (!tree)
3442 return; 3378 return;
3443 3379
3444 LayerAnimationValueObserver* layer = tree->LayerById(layer_id); 3380 LayerImpl* layer = tree->LayerById(layer_id);
3445 if (layer) 3381 if (layer)
3446 layer->OnFilterAnimated(filters); 3382 layer->OnFilterAnimated(filters);
3447 } 3383 }
3448 3384
3449 void LayerTreeHostImpl::SetTreeLayerOpacityMutated(int layer_id, 3385 void LayerTreeHostImpl::SetTreeLayerOpacityMutated(int layer_id,
3450 LayerTreeImpl* tree, 3386 LayerTreeImpl* tree,
3451 float opacity) { 3387 float opacity) {
3452 if (!tree) 3388 if (!tree)
3453 return; 3389 return;
3454 3390
3455 LayerAnimationValueObserver* layer = tree->LayerById(layer_id); 3391 LayerImpl* layer = tree->LayerById(layer_id);
3456 if (layer) 3392 if (layer)
3457 layer->OnOpacityAnimated(opacity); 3393 layer->OnOpacityAnimated(opacity);
3458 } 3394 }
3459 3395
3460 void LayerTreeHostImpl::SetTreeLayerTransformMutated( 3396 void LayerTreeHostImpl::SetTreeLayerTransformMutated(
3461 int layer_id, 3397 int layer_id,
3462 LayerTreeImpl* tree, 3398 LayerTreeImpl* tree,
3463 const gfx::Transform& transform) { 3399 const gfx::Transform& transform) {
3464 if (!tree) 3400 if (!tree)
3465 return; 3401 return;
3466 3402
3467 LayerAnimationValueObserver* layer = tree->LayerById(layer_id); 3403 LayerImpl* layer = tree->LayerById(layer_id);
3468 if (layer) 3404 if (layer)
3469 layer->OnTransformAnimated(transform); 3405 layer->OnTransformAnimated(transform);
3470 } 3406 }
3471 3407
3472 void LayerTreeHostImpl::SetTreeLayerScrollOffsetMutated( 3408 void LayerTreeHostImpl::SetTreeLayerScrollOffsetMutated(
3473 int layer_id, 3409 int layer_id,
3474 LayerTreeImpl* tree, 3410 LayerTreeImpl* tree,
3475 const gfx::ScrollOffset& scroll_offset) { 3411 const gfx::ScrollOffset& scroll_offset) {
3476 if (!tree) 3412 if (!tree)
3477 return; 3413 return;
3478 3414
3479 LayerAnimationValueObserver* layer = tree->LayerById(layer_id); 3415 LayerImpl* layer = tree->LayerById(layer_id);
3480 if (layer) 3416 if (layer)
3481 layer->OnScrollOffsetAnimated(scroll_offset); 3417 layer->OnScrollOffsetAnimated(scroll_offset);
3482 } 3418 }
3483 3419
3484 void LayerTreeHostImpl::SetLayerFilterMutated(int layer_id, 3420 void LayerTreeHostImpl::SetLayerFilterMutated(int layer_id,
3485 bool affects_active_tree, 3421 bool affects_active_tree,
3486 const FilterOperations& filters) { 3422 const FilterOperations& filters) {
3487 if (affects_active_tree) { 3423 if (affects_active_tree) {
3488 SetTreeLayerFilterMutated(layer_id, active_tree(), filters); 3424 SetTreeLayerFilterMutated(layer_id, active_tree(), filters);
3489 } else { 3425 } else {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3527 } 3463 }
3528 } 3464 }
3529 3465
3530 void LayerTreeHostImpl::ScrollOffsetAnimationFinished() { 3466 void LayerTreeHostImpl::ScrollOffsetAnimationFinished() {
3531 ScrollEnd(); 3467 ScrollEnd();
3532 } 3468 }
3533 3469
3534 gfx::ScrollOffset LayerTreeHostImpl::GetScrollOffsetForAnimation( 3470 gfx::ScrollOffset LayerTreeHostImpl::GetScrollOffsetForAnimation(
3535 int layer_id) const { 3471 int layer_id) const {
3536 if (active_tree()) { 3472 if (active_tree()) {
3537 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); 3473 LayerImpl* layer = active_tree()->LayerById(layer_id);
3538 if (layer) 3474 if (layer)
3539 return layer->ScrollOffsetForAnimation(); 3475 return layer->ScrollOffsetForAnimation();
3540 } 3476 }
3541 3477
3542 return gfx::ScrollOffset(); 3478 return gfx::ScrollOffset();
3543 } 3479 }
3544 3480
3545 } // namespace cc 3481 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698