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

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: Added registration/unregistration 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/frame_rate_counter.h" 16 #include "cc/frame_rate_counter.h"
16 #include "cc/gl_renderer.h" 17 #include "cc/gl_renderer.h"
17 #include "cc/heads_up_display_layer_impl.h" 18 #include "cc/heads_up_display_layer_impl.h"
18 #include "cc/layer_iterator.h" 19 #include "cc/layer_iterator.h"
19 #include "cc/layer_tree_host.h" 20 #include "cc/layer_tree_host.h"
20 #include "cc/layer_tree_host_common.h" 21 #include "cc/layer_tree_host_common.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 , m_debugState(settings.initialDebugState) 214 , m_debugState(settings.initialDebugState)
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_cumulativeNumLayersDrawn(0) 229 , m_cumulativeNumLayersDrawn(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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 return; 946 return;
974 m_visible = visible; 947 m_visible = visible;
975 didVisibilityChange(this, m_visible); 948 didVisibilityChange(this, m_visible);
976 enforceManagedMemoryPolicy(m_managedMemoryPolicy); 949 enforceManagedMemoryPolicy(m_managedMemoryPolicy);
977 950
978 if (!m_renderer) 951 if (!m_renderer)
979 return; 952 return;
980 953
981 m_renderer->setVisible(visible); 954 m_renderer->setVisible(visible);
982 955
983 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers); 956 setBackgroundTickingEnabled(!m_visible && !m_activeAnimationControllers.empt y());
984 } 957 }
985 958
986 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<GraphicsContext> context) 959 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<GraphicsContext> context)
987 { 960 {
988 // Since we will create a new resource provider, we cannot continue to use 961 // Since we will create a new resource provider, we cannot continue to use
989 // the old resources (i.e. renderSurfaces and texture IDs). Clear them 962 // the old resources (i.e. renderSurfaces and texture IDs). Clear them
990 // before we destroy the old resource provider. 963 // before we destroy the old resource provider.
991 if (m_rootLayerImpl) { 964 if (m_rootLayerImpl) {
992 clearRenderSurfaces(); 965 clearRenderSurfaces();
993 sendDidLoseContextRecursive(m_rootLayerImpl.get()); 966 sendDidLoseContextRecursive(m_rootLayerImpl.get());
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 m_client->setNeedsRedrawOnImplThread(); 1497 m_client->setNeedsRedrawOnImplThread();
1525 1498
1526 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { 1499 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) {
1527 m_pageScaleAnimation.reset(); 1500 m_pageScaleAnimation.reset();
1528 m_client->setNeedsCommitOnImplThread(); 1501 m_client->setNeedsCommitOnImplThread();
1529 } 1502 }
1530 } 1503 }
1531 1504
1532 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime) 1505 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime)
1533 { 1506 {
1534 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers || !m_r ootLayerImpl) 1507 if (!m_settings.acceleratedAnimationEnabled || m_activeAnimationControllers. empty() || !m_rootLayerImpl)
1535 return; 1508 return;
1536 1509
1537 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); 1510 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers");
1538 1511
1512 double monotonicSeconds = (monotonicTime - base::TimeTicks()).InSecondsF();
1513
1539 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 1514 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
1540 1515 AnimationControllerSet copy = m_activeAnimationControllers;
1541 bool didAnimate = false; 1516 for (AnimationControllerSet::iterator iter = copy.begin(); iter != copy.end( ); ++iter)
1542 animateLayersRecursive(m_rootLayerImpl.get(), monotonicTime, wallClockTime, events.get(), didAnimate, m_needsAnimateLayers); 1517 (*iter)->animate(monotonicSeconds, events.get());
1543 1518
1544 if (!events->empty()) 1519 if (!events->empty())
1545 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal lClockTime); 1520 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal lClockTime);
1546 1521
1547 if (didAnimate) 1522 m_client->setNeedsRedrawOnImplThread();
1548 m_client->setNeedsRedrawOnImplThread(); 1523 setBackgroundTickingEnabled(!m_visible && !m_activeAnimationControllers.empt y());
1549
1550 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers);
1551 } 1524 }
1552 1525
1553 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const 1526 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const
1554 { 1527 {
1555 return base::TimeDelta::FromSeconds(1); 1528 return base::TimeDelta::FromSeconds(1);
1556 } 1529 }
1557 1530
1558 void LayerTreeHostImpl::sendDidLoseContextRecursive(LayerImpl* current) 1531 void LayerTreeHostImpl::sendDidLoseContextRecursive(LayerImpl* current)
1559 { 1532 {
1560 DCHECK(current); 1533 DCHECK(current);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 1603
1631 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController(); 1604 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController();
1632 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); 1605 double monotonicTime = (time - base::TimeTicks()).InSecondsF();
1633 if (scrollbarController && scrollbarController->animate(monotonicTime)) 1606 if (scrollbarController && scrollbarController->animate(monotonicTime))
1634 m_client->setNeedsRedrawOnImplThread(); 1607 m_client->setNeedsRedrawOnImplThread();
1635 1608
1636 for (size_t i = 0; i < layer->children().size(); ++i) 1609 for (size_t i = 0; i < layer->children().size(); ++i)
1637 animateScrollbarsRecursive(layer->children()[i], time); 1610 animateScrollbarsRecursive(layer->children()[i], time);
1638 } 1611 }
1639 1612
1613
1614 void LayerTreeHostImpl::ActivateAnimationController(LayerAnimationController* co ntroller) {
1615 m_activeAnimationControllers.insert(controller);
1616 }
1617
1618 void LayerTreeHostImpl::DeactivateAnimationController(LayerAnimationController* controller) {
1619 if (ContainsKey(m_activeAnimationControllers, controller))
1620 m_activeAnimationControllers.erase(controller);
1621 }
1622
1623 void LayerTreeHostImpl::RegisterAnimationController(LayerAnimationController* co ntroller) {
1624 #if !defined(NDEBUG)
1625 m_allAnimationControllers.insert(controller);
1626 #endif
1627 }
1628
1629 void LayerTreeHostImpl::UnregisterAnimationController(LayerAnimationController* controller) {
1630 #if !defined(NDEBUG)
1631 if (ContainsKey(m_allAnimationControllers, controller))
1632 m_allAnimationControllers.erase(controller);
1633 #endif
1634 DeactivateAnimationController(controller);
1635 }
1636
1640 } // namespace cc 1637 } // 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