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

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

Issue 23593003: cc: Avoid updating animations in the background without an active tree (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix clang Created 7 years, 3 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.cc ('k') | cc/trees/single_thread_proxy.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "cc/animation/animation_curve.h" 7 #include "cc/animation/animation_curve.h"
8 #include "cc/animation/layer_animation_controller.h" 8 #include "cc/animation/layer_animation_controller.h"
9 #include "cc/animation/timing_function.h" 9 #include "cc/animation/timing_function.h"
10 #include "cc/layers/layer.h" 10 #include "cc/layers/layer.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 97 }
98 EndTest(); 98 EndTest();
99 } 99 }
100 100
101 virtual void AfterTest() OVERRIDE {} 101 virtual void AfterTest() OVERRIDE {}
102 102
103 private: 103 private:
104 int num_animates_; 104 int num_animates_;
105 }; 105 };
106 106
107 // Temporarily suppressed per crbug.com/280706. 107 MULTI_THREAD_TEST_F(
108 //MULTI_THREAD_TEST_F( 108 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback);
109 // LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback);
110 109
111 // Add a layer animation and confirm that 110 // Add a layer animation and confirm that
112 // LayerTreeHostImpl::updateAnimationState does get called and continues to 111 // LayerTreeHostImpl::updateAnimationState does get called and continues to
113 // get called. 112 // get called.
114 class LayerTreeHostAnimationTestAddAnimation 113 class LayerTreeHostAnimationTestAddAnimation
115 : public LayerTreeHostAnimationTest { 114 : public LayerTreeHostAnimationTest {
116 public: 115 public:
117 LayerTreeHostAnimationTestAddAnimation() 116 LayerTreeHostAnimationTestAddAnimation()
118 : num_animates_(0), 117 : num_animates_(0),
119 received_animation_started_notification_(false), 118 received_animation_started_notification_(false),
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 286
288 virtual void AfterTest() OVERRIDE {} 287 virtual void AfterTest() OVERRIDE {}
289 288
290 private: 289 private:
291 int num_animates_; 290 int num_animates_;
292 }; 291 };
293 292
294 SINGLE_AND_MULTI_THREAD_TEST_F( 293 SINGLE_AND_MULTI_THREAD_TEST_F(
295 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded); 294 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded);
296 295
296 // Ensures that animations do not tick when we are backgrounded and
297 // and the active tree's root layer is null.
298 class LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree
299 : public LayerTreeHostAnimationTest {
300 public:
301 virtual void BeginTest() OVERRIDE {
302 PostAddAnimationToMainThread(layer_tree_host()->root_layer());
303 }
304
305 virtual void NotifyAnimationFinished(double time) OVERRIDE {
306 // Replace animated commits with a null root layer commit.
307 layer_tree_host()->SetRootLayer(make_scoped_refptr<Layer>(NULL));
308 }
309
310 virtual void DidCommit() OVERRIDE {
311 // This alternates setting the root tree null and root tree with animation.
danakj 2013/08/29 17:22:17 "setting the root tree null" - i think you mean se
312 switch (layer_tree_host()->source_frame_number()) {
313 case 1:
314 // Wait for NotifyAnimationFinished to set the root layer to null.
315 break;
316 case 2:
317 SetupTree();
318 PostAddAnimationToMainThread(layer_tree_host()->root_layer());
danakj 2013/08/29 17:22:17 This is going to be racey, you're post-tasking the
319 break;
320 case 3:
321 // Wait for NotifyAnimationFinished to set the root layer to null.
322 break;
323 case 4:
324 EndTest();
325 break;
326 }
327 }
328
329 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
330 // At the start of every commit, block activations and make sure
331 // we are backgrounded.
332 host_impl->BlockNotifyReadyToActivateForTesting(true);
333 PostSetVisibleToMainThread(false);
334 }
335
336 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
337 if (host_impl->settings().impl_side_painting) {
338 // We block activation for several ticks to make sure that, even though
339 // there is a pending tree with animations, we still do not background
340 // tick if the active tree has a null root layer.
341 if (host_impl->pending_tree()->source_frame_number() < 4) {
342 base::MessageLoopProxy::current()->PostDelayedTask(
343 FROM_HERE,
344 base::Bind(
345 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree: :
danakj 2013/08/29 17:22:17 80 col. save the Bind() result in a callback befor
346 UnblockActivations,
347 base::Unretained(this),
348 host_impl),
349 4 * LowFrequencyAnimationInterval());
350 }
351 } else {
352 UnblockActivations(host_impl);
danakj 2013/08/29 17:22:17 if (!impl paint) do this and early out? maybe tha
353 }
354 }
355
356 virtual void UnblockActivations(LayerTreeHostImpl* host_impl) {
357 host_impl->BlockNotifyReadyToActivateForTesting(false);
358
359 // Initiate the next commit after a delay to give us a chance to background
360 // tick if the root layer isn't null.
361 base::MessageLoopProxy::current()->PostDelayedTask(
362 FROM_HERE,
363 base::Bind(
364 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree::
365 InitiateNextCommit,
366 base::Unretained(this)),
367 4 * LowFrequencyAnimationInterval());
368 }
369
370 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
371 // Verify that we are actually alternating null root layers.
372 switch (host_impl->active_tree()->source_frame_number()) {
373 case 1:
374 case 3:
375 EXPECT_FALSE(host_impl->active_tree()->root_layer());
376 break;
377 case 0:
378 case 2:
379 EXPECT_TRUE(host_impl->active_tree()->root_layer());
380 break;
381 }
382 }
383
384 virtual void InitiateNextCommit() {
danakj 2013/08/29 17:22:17 not virtual?
385 // The next commit is blocked until we become visible again.
386 PostSetVisibleToMainThread(true);
387 }
388
389 virtual void WillAnimateLayers(LayerTreeHostImpl* host_impl,
390 base::TimeTicks monotonic_time) OVERRIDE {
391 EXPECT_TRUE(host_impl->active_tree()->root_layer());
392 }
393
394 virtual void AfterTest() OVERRIDE {}
395 };
396
397 SINGLE_AND_MULTI_THREAD_TEST_F(
398 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree);
399
297 // Ensure that an animation's timing function is respected. 400 // Ensure that an animation's timing function is respected.
298 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction 401 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction
299 : public LayerTreeHostAnimationTest { 402 : public LayerTreeHostAnimationTest {
300 public: 403 public:
301 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} 404 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {}
302 405
303 virtual void SetupTree() OVERRIDE { 406 virtual void SetupTree() OVERRIDE {
304 LayerTreeHostAnimationTest::SetupTree(); 407 LayerTreeHostAnimationTest::SetupTree();
305 content_ = FakeContentLayer::Create(&client_); 408 content_ = FakeContentLayer::Create(&client_);
306 content_->SetBounds(gfx::Size(4, 4)); 409 content_->SetBounds(gfx::Size(4, 4));
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 int finished_times_; 901 int finished_times_;
799 FakeContentLayerClient client_; 902 FakeContentLayerClient client_;
800 scoped_refptr<FakeContentLayer> content_; 903 scoped_refptr<FakeContentLayer> content_;
801 }; 904 };
802 905
803 MULTI_THREAD_TEST_F( 906 MULTI_THREAD_TEST_F(
804 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); 907 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations);
805 908
806 } // namespace 909 } // namespace
807 } // namespace cc 910 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/single_thread_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698