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

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

Issue 713783002: Revert of Moving background animation ticking from LayerTreeHostImpl into the Scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scheduler-timesource-refactor
Patch Set: Created 6 years, 1 month 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_host_unittest_animation.cc » ('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 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return GL_TEXTURE_2D; 166 return GL_TEXTURE_2D;
167 } 167 }
168 168
169 size_t GetMaxStagingResourceCount() { 169 size_t GetMaxStagingResourceCount() {
170 // Upper bound for number of staging resource to allow. 170 // Upper bound for number of staging resource to allow.
171 return 32; 171 return 32;
172 } 172 }
173 173
174 } // namespace 174 } // namespace
175 175
176 class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient {
177 public:
178 static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> Create(
179 LayerTreeHostImpl* layer_tree_host_impl,
180 scoped_refptr<DelayBasedTimeSource> time_source) {
181 return make_scoped_ptr(
182 new LayerTreeHostImplTimeSourceAdapter(layer_tree_host_impl,
183 time_source));
184 }
185 ~LayerTreeHostImplTimeSourceAdapter() override {
186 time_source_->SetClient(NULL);
187 time_source_->SetActive(false);
188 }
189
190 void OnTimerTick() override {
191 // In single threaded mode we attempt to simulate changing the current
192 // thread by maintaining a fake thread id. When we switch from one
193 // thread to another, we construct DebugScopedSetXXXThread objects that
194 // update the thread id. This lets DCHECKS that ensure we're on the
195 // right thread to work correctly in single threaded mode. The problem
196 // here is that the timer tasks are run via the message loop, and when
197 // they run, we've had no chance to construct a DebugScopedSetXXXThread
198 // object. The result is that we report that we're running on the main
199 // thread. In multi-threaded mode, this timer is run on the compositor
200 // thread, so to keep this consistent in single-threaded mode, we'll
201 // construct a DebugScopedSetImplThread object. There is no need to do
202 // this in multi-threaded mode since the real thread id's will be
203 // correct. In fact, setting fake thread id's interferes with the real
204 // thread id's and causes breakage.
205 scoped_ptr<DebugScopedSetImplThread> set_impl_thread;
206 if (!layer_tree_host_impl_->proxy()->HasImplThread()) {
207 set_impl_thread.reset(
208 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy()));
209 }
210
211 layer_tree_host_impl_->Animate(
212 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time);
213 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true);
214 bool start_ready_animations = true;
215 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
216
217 if (layer_tree_host_impl_->pending_tree()) {
218 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties();
219 layer_tree_host_impl_->ManageTiles();
220 }
221
222 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame();
223 }
224
225 void SetActive(bool active) {
226 if (active != time_source_->Active())
227 time_source_->SetActive(active);
228 }
229
230 bool Active() const { return time_source_->Active(); }
231
232 private:
233 LayerTreeHostImplTimeSourceAdapter(
234 LayerTreeHostImpl* layer_tree_host_impl,
235 scoped_refptr<DelayBasedTimeSource> time_source)
236 : layer_tree_host_impl_(layer_tree_host_impl),
237 time_source_(time_source) {
238 time_source_->SetClient(this);
239 }
240
241 LayerTreeHostImpl* layer_tree_host_impl_;
242 scoped_refptr<DelayBasedTimeSource> time_source_;
243
244 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImplTimeSourceAdapter);
245 };
246
176 LayerTreeHostImpl::FrameData::FrameData() 247 LayerTreeHostImpl::FrameData::FrameData()
177 : contains_incomplete_tile(false), has_no_damage(false) {} 248 : contains_incomplete_tile(false), has_no_damage(false) {}
178 249
179 LayerTreeHostImpl::FrameData::~FrameData() {} 250 LayerTreeHostImpl::FrameData::~FrameData() {}
180 251
181 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( 252 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create(
182 const LayerTreeSettings& settings, 253 const LayerTreeSettings& settings,
183 LayerTreeHostImplClient* client, 254 LayerTreeHostImplClient* client,
184 Proxy* proxy, 255 Proxy* proxy,
185 RenderingStatsInstrumentation* rendering_stats_instrumentation, 256 RenderingStatsInstrumentation* rendering_stats_instrumentation,
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 << frame->render_passes.size(); 967 << frame->render_passes.size();
897 968
898 return draw_result; 969 return draw_result;
899 } 970 }
900 971
901 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { 972 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() {
902 if (input_handler_client_) 973 if (input_handler_client_)
903 input_handler_client_->MainThreadHasStoppedFlinging(); 974 input_handler_client_->MainThreadHasStoppedFlinging();
904 } 975 }
905 976
977 void LayerTreeHostImpl::UpdateBackgroundAnimateTicking(
978 bool should_background_tick) {
979 DCHECK(proxy_->IsImplThread());
980 if (should_background_tick)
981 DCHECK(active_tree_->root_layer());
982
983 bool enabled = should_background_tick && needs_animate_layers();
984
985 // Lazily create the time_source adapter so that we can vary the interval for
986 // testing.
987 if (!time_source_client_adapter_) {
988 time_source_client_adapter_ = LayerTreeHostImplTimeSourceAdapter::Create(
989 this,
990 DelayBasedTimeSource::Create(
991 LowFrequencyAnimationInterval(),
992 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner()
993 : proxy_->MainThreadTaskRunner()));
994 }
995
996 time_source_client_adapter_->SetActive(enabled);
997 }
998
906 void LayerTreeHostImpl::DidAnimateScrollOffset() { 999 void LayerTreeHostImpl::DidAnimateScrollOffset() {
907 client_->SetNeedsCommitOnImplThread(); 1000 client_->SetNeedsCommitOnImplThread();
908 client_->RenewTreePriority(); 1001 client_->RenewTreePriority();
909 } 1002 }
910 1003
911 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { 1004 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) {
912 viewport_damage_rect_.Union(damage_rect); 1005 viewport_damage_rect_.Union(damage_rect);
913 } 1006 }
914 1007
915 static inline RenderPass* FindRenderPassById( 1008 static inline RenderPass* FindRenderPassById(
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 if (debug_state_.continuous_painting) { 1881 if (debug_state_.continuous_painting) {
1789 const RenderingStats& stats = 1882 const RenderingStats& stats =
1790 rendering_stats_instrumentation_->GetRenderingStats(); 1883 rendering_stats_instrumentation_->GetRenderingStats();
1791 // TODO(hendrikw): This requires a different metric when we commit directly 1884 // TODO(hendrikw): This requires a different metric when we commit directly
1792 // to the active tree. See crbug.com/429311. 1885 // to the active tree. See crbug.com/429311.
1793 paint_time_counter_->SavePaintTime( 1886 paint_time_counter_->SavePaintTime(
1794 stats.commit_to_activate_duration.GetLastTimeDelta() + 1887 stats.commit_to_activate_duration.GetLastTimeDelta() +
1795 stats.draw_duration.GetLastTimeDelta()); 1888 stats.draw_duration.GetLastTimeDelta());
1796 } 1889 }
1797 1890
1891 if (time_source_client_adapter_ && time_source_client_adapter_->Active())
1892 DCHECK(active_tree_->root_layer());
1893
1798 scoped_ptr<PageScaleAnimation> page_scale_animation = 1894 scoped_ptr<PageScaleAnimation> page_scale_animation =
1799 active_tree_->TakePageScaleAnimation(); 1895 active_tree_->TakePageScaleAnimation();
1800 if (page_scale_animation) { 1896 if (page_scale_animation) {
1801 page_scale_animation_ = page_scale_animation.Pass(); 1897 page_scale_animation_ = page_scale_animation.Pass();
1802 SetNeedsAnimate(); 1898 SetNeedsAnimate();
1803 client_->SetNeedsCommitOnImplThread(); 1899 client_->SetNeedsCommitOnImplThread();
1804 client_->RenewTreePriority(); 1900 client_->RenewTreePriority();
1805 } 1901 }
1806 } 1902 }
1807 1903
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after
3092 !active_tree_->root_layer()) 3188 !active_tree_->root_layer())
3093 return; 3189 return;
3094 3190
3095 TRACE_EVENT0("cc", "LayerTreeHostImpl::ActivateAnimations"); 3191 TRACE_EVENT0("cc", "LayerTreeHostImpl::ActivateAnimations");
3096 AnimationRegistrar::AnimationControllerMap copy = 3192 AnimationRegistrar::AnimationControllerMap copy =
3097 animation_registrar_->active_animation_controllers(); 3193 animation_registrar_->active_animation_controllers();
3098 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); 3194 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin();
3099 iter != copy.end(); 3195 iter != copy.end();
3100 ++iter) 3196 ++iter)
3101 (*iter).second->ActivateAnimations(); 3197 (*iter).second->ActivateAnimations();
3198 }
3102 3199
3103 SetNeedsAnimate(); 3200 base::TimeDelta LayerTreeHostImpl::LowFrequencyAnimationInterval() const {
3201 return base::TimeDelta::FromSeconds(1);
3104 } 3202 }
3105 3203
3106 std::string LayerTreeHostImpl::LayerTreeAsJson() const { 3204 std::string LayerTreeHostImpl::LayerTreeAsJson() const {
3107 std::string str; 3205 std::string str;
3108 if (active_tree_->root_layer()) { 3206 if (active_tree_->root_layer()) {
3109 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson()); 3207 scoped_ptr<base::Value> json(active_tree_->root_layer()->LayerTreeAsJson());
3110 base::JSONWriter::WriteWithOptions( 3208 base::JSONWriter::WriteWithOptions(
3111 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str); 3209 json.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &str);
3112 } 3210 }
3113 return str; 3211 return str;
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
3422 } 3520 }
3423 3521
3424 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { 3522 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
3425 std::vector<PictureLayerImpl*>::iterator it = 3523 std::vector<PictureLayerImpl*>::iterator it =
3426 std::find(picture_layers_.begin(), picture_layers_.end(), layer); 3524 std::find(picture_layers_.begin(), picture_layers_.end(), layer);
3427 DCHECK(it != picture_layers_.end()); 3525 DCHECK(it != picture_layers_.end());
3428 picture_layers_.erase(it); 3526 picture_layers_.erase(it);
3429 } 3527 }
3430 3528
3431 } // namespace cc 3529 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698