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

Side by Side Diff: cc/layer_tree_host_impl.cc

Issue 11348256: Use an auxiliary list of animation controllers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unit tests pass! Created 8 years 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 | Annotate | Revision Log
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/layer_tree_host_impl.h" 5 #include "cc/layer_tree_host_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/stl_util.h"
11 #include "cc/append_quads_data.h" 12 #include "cc/append_quads_data.h"
12 #include "cc/damage_tracker.h" 13 #include "cc/damage_tracker.h"
13 #include "cc/debug_rect_history.h" 14 #include "cc/debug_rect_history.h"
14 #include "cc/delay_based_time_source.h" 15 #include "cc/delay_based_time_source.h"
15 #include "cc/font_atlas.h" 16 #include "cc/font_atlas.h"
16 #include "cc/frame_rate_counter.h" 17 #include "cc/frame_rate_counter.h"
17 #include "cc/gl_renderer.h" 18 #include "cc/gl_renderer.h"
18 #include "cc/heads_up_display_layer_impl.h" 19 #include "cc/heads_up_display_layer_impl.h"
19 #include "cc/layer_iterator.h" 20 #include "cc/layer_iterator.h"
20 #include "cc/layer_tree_host.h" 21 #include "cc/layer_tree_host.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 , m_settings(settings) 214 , m_settings(settings)
214 , m_deviceScaleFactor(1) 215 , m_deviceScaleFactor(1)
215 , m_visible(true) 216 , m_visible(true)
216 , m_contentsTexturesPurged(false) 217 , m_contentsTexturesPurged(false)
217 , m_managedMemoryPolicy(PrioritizedResourceManager::defaultMemoryAllocationL imit(), 218 , m_managedMemoryPolicy(PrioritizedResourceManager::defaultMemoryAllocationL imit(),
218 PriorityCalculator::allowEverythingCutoff(), 219 PriorityCalculator::allowEverythingCutoff(),
219 0, 220 0,
220 PriorityCalculator::allowNothingCutoff()) 221 PriorityCalculator::allowNothingCutoff())
221 , m_backgroundColor(0) 222 , m_backgroundColor(0)
222 , m_hasTransparentBackground(false) 223 , m_hasTransparentBackground(false)
223 , m_needsAnimateLayers(false)
224 , m_pinchGestureActive(false) 224 , m_pinchGestureActive(false)
225 , m_fpsCounter(FrameRateCounter::create(m_proxy->hasImplThread())) 225 , m_fpsCounter(FrameRateCounter::create(m_proxy->hasImplThread()))
226 , m_debugRectHistory(DebugRectHistory::create()) 226 , m_debugRectHistory(DebugRectHistory::create())
227 , m_numImplThreadScrolls(0) 227 , m_numImplThreadScrolls(0)
228 , m_numMainThreadScrolls(0) 228 , m_numMainThreadScrolls(0)
229 , m_cumulativeNumLayersInLayerTree(0) 229 , m_cumulativeNumLayersInLayerTree(0)
230 { 230 {
231 DCHECK(m_proxy->isImplThread()); 231 DCHECK(m_proxy->isImplThread());
232 didVisibilityChange(this, m_visible); 232 didVisibilityChange(this, m_visible);
233 } 233 }
234 234
235 LayerTreeHostImpl::~LayerTreeHostImpl() 235 LayerTreeHostImpl::~LayerTreeHostImpl()
236 { 236 {
237 DCHECK(m_proxy->isImplThread()); 237 DCHECK(m_proxy->isImplThread());
238 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); 238 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()");
239 239
240 if (m_rootLayerImpl) 240 if (m_rootLayerImpl) {
241 clearRenderSurfaces(); 241 clearRenderSurfaces();
242 m_rootLayerImpl.release();
243 }
242 } 244 }
243 245
244 void LayerTreeHostImpl::beginCommit() 246 void LayerTreeHostImpl::beginCommit()
245 { 247 {
246 } 248 }
247 249
248 void LayerTreeHostImpl::commitComplete() 250 void LayerTreeHostImpl::commitComplete()
249 { 251 {
250 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); 252 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete");
251 // Recompute max scroll position; must be after layer content bounds are 253 // Recompute max scroll position; must be after layer content bounds are
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 if (drawFrame) 580 if (drawFrame)
579 occlusionTracker.overdrawMetrics().recordMetrics(this); 581 occlusionTracker.overdrawMetrics().recordMetrics(this);
580 582
581 removeRenderPasses(CullRenderPassesWithNoQuads(), frame); 583 removeRenderPasses(CullRenderPassesWithNoQuads(), frame);
582 m_renderer->decideRenderPassAllocationsForFrame(frame.renderPasses); 584 m_renderer->decideRenderPassAllocationsForFrame(frame.renderPasses);
583 removeRenderPasses(CullRenderPassesWithCachedTextures(*m_renderer), frame); 585 removeRenderPasses(CullRenderPassesWithCachedTextures(*m_renderer), frame);
584 586
585 return drawFrame; 587 return drawFrame;
586 } 588 }
587 589
588 void LayerTreeHostImpl::animateLayersRecursive(LayerImpl* current, base::TimeTic ks monotonicTime, base::Time wallClockTime, AnimationEventsVector* events, bool& didAnimate, bool& needsAnimateLayers)
589 {
590 bool subtreeNeedsAnimateLayers = false;
591
592 LayerAnimationController* currentController = current->layerAnimationControl ler();
593
594 bool hadActiveAnimation = currentController->hasActiveAnimation();
595 double monotonicTimeSeconds = (monotonicTime - base::TimeTicks()).InSecondsF ();
596 currentController->animate(monotonicTimeSeconds, events);
597 bool startedAnimation = events->size() > 0;
598
599 // We animated if we either ticked a running animation, or started a new ani mation.
600 if (hadActiveAnimation || startedAnimation)
601 didAnimate = true;
602
603 // If the current controller still has an active animation, we must continue animating layers.
604 if (currentController->hasActiveAnimation())
605 subtreeNeedsAnimateLayers = true;
606
607 for (size_t i = 0; i < current->children().size(); ++i) {
608 bool childNeedsAnimateLayers = false;
609 animateLayersRecursive(current->children()[i], monotonicTime, wallClockT ime, events, didAnimate, childNeedsAnimateLayers);
610 if (childNeedsAnimateLayers)
611 subtreeNeedsAnimateLayers = true;
612 }
613
614 needsAnimateLayers = subtreeNeedsAnimateLayers;
615 }
616
617 void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled) 590 void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled)
618 { 591 {
619 // Lazily create the timeSource adapter so that we can vary the interval for testing. 592 // Lazily create the timeSource adapter so that we can vary the interval for testing.
620 if (!m_timeSourceClientAdapter) 593 if (!m_timeSourceClientAdapter)
621 m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(t his, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->curr entThread())); 594 m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(t his, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->curr entThread()));
622 595
623 m_timeSourceClientAdapter->setActive(enabled); 596 m_timeSourceClientAdapter->setActive(enabled);
624 } 597 }
625 598
626 gfx::Size LayerTreeHostImpl::contentSize() const 599 gfx::Size LayerTreeHostImpl::contentSize() const
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 return; 947 return;
975 m_visible = visible; 948 m_visible = visible;
976 didVisibilityChange(this, m_visible); 949 didVisibilityChange(this, m_visible);
977 enforceManagedMemoryPolicy(m_managedMemoryPolicy); 950 enforceManagedMemoryPolicy(m_managedMemoryPolicy);
978 951
979 if (!m_renderer) 952 if (!m_renderer)
980 return; 953 return;
981 954
982 m_renderer->setVisible(visible); 955 m_renderer->setVisible(visible);
983 956
984 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers); 957 setBackgroundTickingEnabled(!m_visible && !m_activeAnimationControllers.empt y());
985 } 958 }
986 959
987 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<GraphicsContext> context) 960 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<GraphicsContext> context)
988 { 961 {
989 // Since we will create a new resource provider, we cannot continue to use 962 // Since we will create a new resource provider, we cannot continue to use
990 // the old resources (i.e. renderSurfaces and texture IDs). Clear them 963 // the old resources (i.e. renderSurfaces and texture IDs). Clear them
991 // before we destroy the old resource provider. 964 // before we destroy the old resource provider.
992 if (m_rootLayerImpl) { 965 if (m_rootLayerImpl) {
993 clearRenderSurfaces(); 966 clearRenderSurfaces();
994 sendDidLoseContextRecursive(m_rootLayerImpl.get()); 967 sendDidLoseContextRecursive(m_rootLayerImpl.get());
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 m_client->setNeedsRedrawOnImplThread(); 1498 m_client->setNeedsRedrawOnImplThread();
1526 1499
1527 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { 1500 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) {
1528 m_pageScaleAnimation.reset(); 1501 m_pageScaleAnimation.reset();
1529 m_client->setNeedsCommitOnImplThread(); 1502 m_client->setNeedsCommitOnImplThread();
1530 } 1503 }
1531 } 1504 }
1532 1505
1533 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime) 1506 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime)
1534 { 1507 {
1535 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers || !m_r ootLayerImpl) 1508 if (!m_settings.acceleratedAnimationEnabled || m_activeAnimationControllers. empty() || !m_rootLayerImpl)
1536 return; 1509 return;
1537 1510
1538 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); 1511 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers");
1539 1512
1513 double monotonicSeconds = (monotonicTime - base::TimeTicks()).InSecondsF();
1514
1540 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 1515 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
1541 1516 AnimationControllerSet copy = m_activeAnimationControllers;
1542 bool didAnimate = false; 1517 for (AnimationControllerSet::iterator iter = copy.begin(); iter != copy.end( ); ++iter)
1543 animateLayersRecursive(m_rootLayerImpl.get(), monotonicTime, wallClockTime, events.get(), didAnimate, m_needsAnimateLayers); 1518 (*iter)->animate(monotonicSeconds, events.get());
1544 1519
1545 if (!events->empty()) 1520 if (!events->empty())
1546 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal lClockTime); 1521 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal lClockTime);
1547 1522
1548 if (didAnimate) 1523 m_client->setNeedsRedrawOnImplThread();
1549 m_client->setNeedsRedrawOnImplThread(); 1524 setBackgroundTickingEnabled(!m_visible && !m_activeAnimationControllers.empt y());
1550
1551 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers);
1552 } 1525 }
1553 1526
1554 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const 1527 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const
1555 { 1528 {
1556 return base::TimeDelta::FromSeconds(1); 1529 return base::TimeDelta::FromSeconds(1);
1557 } 1530 }
1558 1531
1559 void LayerTreeHostImpl::sendDidLoseContextRecursive(LayerImpl* current) 1532 void LayerTreeHostImpl::sendDidLoseContextRecursive(LayerImpl* current)
1560 { 1533 {
1561 DCHECK(current); 1534 DCHECK(current);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 1601
1629 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController(); 1602 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController();
1630 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); 1603 double monotonicTime = (time - base::TimeTicks()).InSecondsF();
1631 if (scrollbarController && scrollbarController->animate(monotonicTime)) 1604 if (scrollbarController && scrollbarController->animate(monotonicTime))
1632 m_client->setNeedsRedrawOnImplThread(); 1605 m_client->setNeedsRedrawOnImplThread();
1633 1606
1634 for (size_t i = 0; i < layer->children().size(); ++i) 1607 for (size_t i = 0; i < layer->children().size(); ++i)
1635 animateScrollbarsRecursive(layer->children()[i], time); 1608 animateScrollbarsRecursive(layer->children()[i], time);
1636 } 1609 }
1637 1610
1611
1612 void LayerTreeHostImpl::Register(LayerAnimationController* controller) {
1613 m_activeAnimationControllers.insert(controller);
1614 }
1615
1616 void LayerTreeHostImpl::Unregister(LayerAnimationController* controller) {
1617 if (ContainsKey(m_activeAnimationControllers, controller))
1618 m_activeAnimationControllers.erase(controller);
1619 }
1620
1638 } // namespace cc 1621 } // namespace cc
OLDNEW
« cc/layer_tree_host.h ('K') | « cc/layer_tree_host_impl.h ('k') | cc/proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698