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

Side by Side Diff: ui/compositor/layer.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 | « ui/compositor/compositor_switches.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/layer.h" 5 #include "ui/compositor/layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/trace_event/trace_event.h" 15 #include "base/trace_event/trace_event.h"
16 #include "cc/animation/animation_host.h"
16 #include "cc/animation/animation_id_provider.h" 17 #include "cc/animation/animation_id_provider.h"
17 #include "cc/animation/animation_player.h" 18 #include "cc/animation/animation_player.h"
18 #include "cc/animation/animation_timeline.h" 19 #include "cc/animation/animation_timeline.h"
19 #include "cc/base/scoped_ptr_algorithm.h" 20 #include "cc/base/scoped_ptr_algorithm.h"
20 #include "cc/layers/content_layer.h" 21 #include "cc/layers/content_layer.h"
21 #include "cc/layers/delegated_renderer_layer.h" 22 #include "cc/layers/delegated_renderer_layer.h"
22 #include "cc/layers/nine_patch_layer.h" 23 #include "cc/layers/nine_patch_layer.h"
23 #include "cc/layers/picture_layer.h" 24 #include "cc/layers/picture_layer.h"
24 #include "cc/layers/solid_color_layer.h" 25 #include "cc/layers/solid_color_layer.h"
25 #include "cc/layers/surface_layer.h" 26 #include "cc/layers/surface_layer.h"
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 991
991 float Layer::GetDeviceScaleFactor() const { 992 float Layer::GetDeviceScaleFactor() const {
992 return device_scale_factor_; 993 return device_scale_factor_;
993 } 994 }
994 995
995 void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) { 996 void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) {
996 DCHECK(cc_layer_); 997 DCHECK(cc_layer_);
997 // Until this layer has a compositor (and hence cc_layer_ has a 998 // Until this layer has a compositor (and hence cc_layer_ has a
998 // LayerTreeHost), addAnimation will fail. 999 // LayerTreeHost), addAnimation will fail.
999 if (GetCompositor()) { 1000 if (GetCompositor()) {
1000 animation_player_ ? animation_player_->AddAnimation(animation.Pass()) 1001 animation_player_->AddAnimation(animation.Pass());
1001 : (void)cc_layer_->AddAnimation(animation.Pass());
1002 } else { 1002 } else {
1003 pending_threaded_animations_.push_back(animation.Pass()); 1003 pending_threaded_animations_.push_back(animation.Pass());
1004 } 1004 }
1005 } 1005 }
1006 1006
1007 namespace{ 1007 namespace{
1008 1008
1009 struct HasAnimationId { 1009 struct HasAnimationId {
1010 HasAnimationId(int id): id_(id) { 1010 HasAnimationId(int id): id_(id) {
1011 } 1011 }
1012 1012
1013 bool operator()(cc::Animation* animation) const { 1013 bool operator()(cc::Animation* animation) const {
1014 return animation->id() == id_; 1014 return animation->id() == id_;
1015 } 1015 }
1016 1016
1017 private: 1017 private:
1018 int id_; 1018 int id_;
1019 }; 1019 };
1020 1020
1021 } 1021 }
1022 1022
1023 void Layer::RemoveThreadedAnimation(int animation_id) { 1023 void Layer::RemoveThreadedAnimation(int animation_id) {
1024 DCHECK(cc_layer_); 1024 DCHECK(cc_layer_);
1025 if (pending_threaded_animations_.size() == 0) { 1025 if (pending_threaded_animations_.size() == 0) {
1026 animation_player_ ? animation_player_->RemoveAnimation(animation_id) 1026 animation_player_->RemoveAnimation(animation_id);
1027 : cc_layer_->RemoveAnimation(animation_id);
1028 return; 1027 return;
1029 } 1028 }
1030 1029
1031 pending_threaded_animations_.erase( 1030 pending_threaded_animations_.erase(
1032 cc::remove_if(&pending_threaded_animations_, 1031 cc::remove_if(&pending_threaded_animations_,
1033 pending_threaded_animations_.begin(), 1032 pending_threaded_animations_.begin(),
1034 pending_threaded_animations_.end(), 1033 pending_threaded_animations_.end(),
1035 HasAnimationId(animation_id)), 1034 HasAnimationId(animation_id)),
1036 pending_threaded_animations_.end()); 1035 pending_threaded_animations_.end());
1037 } 1036 }
1038 1037
1039 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() { 1038 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() {
1040 Compositor* compositor = GetCompositor(); 1039 Compositor* compositor = GetCompositor();
1041 return compositor ? compositor->layer_animator_collection() : NULL; 1040 return compositor ? compositor->layer_animator_collection() : NULL;
1042 } 1041 }
1043 1042
1044 void Layer::SendPendingThreadedAnimations() { 1043 void Layer::SendPendingThreadedAnimations() {
1045 for (cc::ScopedPtrVector<cc::Animation>::iterator it = 1044 for (cc::ScopedPtrVector<cc::Animation>::iterator it =
1046 pending_threaded_animations_.begin(); 1045 pending_threaded_animations_.begin();
1047 it != pending_threaded_animations_.end(); ++it) { 1046 it != pending_threaded_animations_.end(); ++it) {
1048 animation_player_ 1047 animation_player_->AddAnimation(pending_threaded_animations_.take(it));
1049 ? animation_player_->AddAnimation(pending_threaded_animations_.take(it))
1050 : (void)cc_layer_->AddAnimation(pending_threaded_animations_.take(it));
1051 } 1048 }
1052 1049
1053 pending_threaded_animations_.clear(); 1050 pending_threaded_animations_.clear();
1054 1051
1055 for (size_t i = 0; i < children_.size(); ++i) 1052 for (size_t i = 0; i < children_.size(); ++i)
1056 children_[i]->SendPendingThreadedAnimations(); 1053 children_[i]->SendPendingThreadedAnimations();
1057 } 1054 }
1058 1055
1059 void Layer::CreateCcLayer() { 1056 void Layer::CreateCcLayer() {
1060 if (type_ == LAYER_SOLID_COLOR) { 1057 if (type_ == LAYER_SOLID_COLOR) {
(...skipping 12 matching lines...) Expand all
1073 cc_layer_->SetTransformOrigin(gfx::Point3F()); 1070 cc_layer_->SetTransformOrigin(gfx::Point3F());
1074 cc_layer_->SetContentsOpaque(true); 1071 cc_layer_->SetContentsOpaque(true);
1075 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); 1072 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN);
1076 cc_layer_->SetLayerClient(this); 1073 cc_layer_->SetLayerClient(this);
1077 RecomputePosition(); 1074 RecomputePosition();
1078 } 1075 }
1079 1076
1080 void Layer::AttachAnimationObserversAndLayer() { 1077 void Layer::AttachAnimationObserversAndLayer() {
1081 DCHECK(cc_layer_); 1078 DCHECK(cc_layer_);
1082 1079
1083 if (animation_player_) { 1080 animation_player_->AttachLayer(cc_layer_->id());
1084 animation_player_->AttachLayer(cc_layer_->id()); 1081 DCHECK(animation_player_->layer_animation_controller());
1085 DCHECK(animation_player_->layer_animation_controller()); 1082 animation_player_->layer_animation_controller()->AddEventObserver(this);
1086 animation_player_->layer_animation_controller()->AddEventObserver(this);
1087 } else {
1088 if (cc_layer_->layer_animation_controller())
1089 cc_layer_->AddLayerAnimationEventObserver(this);
1090 }
1091 1083
1092 for (size_t i = 0; i < children_.size(); ++i) 1084 for (size_t i = 0; i < children_.size(); ++i)
1093 children_[i]->AttachAnimationObserversAndLayer(); 1085 children_[i]->AttachAnimationObserversAndLayer();
1094 } 1086 }
1095 1087
1096 void Layer::DetachAnimationObserversAndLayer() { 1088 void Layer::DetachAnimationObserversAndLayer() {
1097 if (animation_player_) { 1089 if (animation_player_->layer_animation_controller()) {
1098 if (animation_player_->layer_animation_controller()) { 1090 animation_player_->layer_animation_controller()->RemoveEventObserver(this);
1099 animation_player_->layer_animation_controller()->RemoveEventObserver(this) ; 1091 animation_player_->DetachLayer();
1100 animation_player_->DetachLayer();
1101 }
1102 } else {
1103 if (cc_layer_->layer_animation_controller())
1104 cc_layer_->RemoveLayerAnimationEventObserver(this);
1105 } 1092 }
1106 1093
1107 for (size_t i = 0; i < children_.size(); ++i) 1094 for (size_t i = 0; i < children_.size(); ++i)
1108 children_[i]->DetachAnimationObserversAndLayer(); 1095 children_[i]->DetachAnimationObserversAndLayer();
1109 } 1096 }
1110 1097
1111 void Layer::CreateAnimationPlayers(Compositor* compositor) { 1098 void Layer::CreateAnimationPlayers(Compositor* compositor) {
1112 DCHECK(compositor); 1099 DCHECK(compositor);
1113 const cc::LayerTreeHost& host = compositor->GetLayerTreeHost();
1114 cc_layer_->RegisterForAnimations(host.animation_registrar(), host.settings());
1115 1100
1116 if (host.settings().use_compositor_animation_timelines) { 1101 animation_player_ =
1117 if (!animation_player_) { 1102 cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId());
1118 animation_player_ =
1119 cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId());
1120 }
1121 }
1122 1103
1123 for (size_t i = 0; i < children_.size(); ++i) 1104 for (size_t i = 0; i < children_.size(); ++i)
1124 children_[i]->CreateAnimationPlayers(compositor); 1105 children_[i]->CreateAnimationPlayers(compositor);
1125 } 1106 }
1126 1107
1127 void Layer::AttachAnimationPlayer(Compositor* compositor) { 1108 void Layer::AttachAnimationPlayer(Compositor* compositor) {
1128 DCHECK(compositor); 1109 DCHECK(compositor);
1129 1110
1130 if (animation_player_) 1111 compositor->GetAnimationTimeline()->AttachPlayer(animation_player_.get());
1131 compositor->GetAnimationTimeline()->AttachPlayer(animation_player_.get());
1132 1112
1133 for (size_t i = 0; i < children_.size(); ++i) 1113 for (size_t i = 0; i < children_.size(); ++i)
1134 children_[i]->AttachAnimationPlayer(compositor); 1114 children_[i]->AttachAnimationPlayer(compositor);
1135 } 1115 }
1136 1116
1137 void Layer::DetachAnimationPlayer() { 1117 void Layer::DetachAnimationPlayer() {
1138 Compositor* compositor = GetCompositor(); 1118 Compositor* compositor = GetCompositor();
1139 DCHECK(compositor); 1119 DCHECK(compositor);
1140 1120
1141 if (animation_player_) 1121 compositor->GetAnimationTimeline()->DetachPlayer(animation_player_.get());
1142 compositor->GetAnimationTimeline()->DetachPlayer(animation_player_.get());
1143 1122
1144 for (size_t i = 0; i < children_.size(); ++i) 1123 for (size_t i = 0; i < children_.size(); ++i)
1145 children_[i]->DetachAnimationPlayer(); 1124 children_[i]->DetachAnimationPlayer();
1146 } 1125 }
1147 1126
1148 gfx::Transform Layer::transform() const { 1127 gfx::Transform Layer::transform() const {
1149 return cc_layer_->transform(); 1128 return cc_layer_->transform();
1150 } 1129 }
1151 1130
1152 void Layer::RecomputeDrawsContentAndUVRect() { 1131 void Layer::RecomputeDrawsContentAndUVRect() {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 children_.end(), 1170 children_.end(),
1192 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), 1171 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection),
1193 collection)); 1172 collection));
1194 } 1173 }
1195 1174
1196 bool Layer::IsAnimating() const { 1175 bool Layer::IsAnimating() const {
1197 return animator_.get() && animator_->is_animating(); 1176 return animator_.get() && animator_->is_animating();
1198 } 1177 }
1199 1178
1200 } // namespace ui 1179 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/compositor_switches.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698