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

Side by Side Diff: cc/layer_tree_host_impl.cc

Issue 11443004: Maintain global lists of animation controllers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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 "cc/animation_registrar.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 && !AnimationRegistrar::GetActiveCont rollers(AnimationRegistrar::CompositorThread).empty());
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 gfx::Vector2dF maxScroll = gfx::Rect(contentBounds).bottom_right() - gfx::Re ctF(viewBounds).bottom_right(); 1112 gfx::Vector2dF maxScroll = gfx::Rect(contentBounds).bottom_right() - gfx::Re ctF(viewBounds).bottom_right();
1140 maxScroll.Scale(1 / m_deviceScaleFactor); 1113 maxScroll.Scale(1 / m_deviceScaleFactor);
1141 1114
1142 // The viewport may be larger than the contents in some cases, such as 1115 // The viewport may be larger than the contents in some cases, such as
1143 // having a vertical scrollbar but no horizontal overflow. 1116 // having a vertical scrollbar but no horizontal overflow.
1144 maxScroll.ClampToMin(gfx::Vector2dF()); 1117 maxScroll.ClampToMin(gfx::Vector2dF());
1145 1118
1146 m_rootScrollLayerImpl->setMaxScrollOffset(gfx::ToFlooredVector2d(maxScroll)) ; 1119 m_rootScrollLayerImpl->setMaxScrollOffset(gfx::ToFlooredVector2d(maxScroll)) ;
1147 } 1120 }
1148 1121
1122 bool LayerTreeHostImpl::needsAnimateLayers() const
1123 {
1124 return !AnimationRegistrar::GetActiveControllers(AnimationRegistrar::Composi torThread).empty();
1125 }
1126
1149 void LayerTreeHostImpl::setNeedsRedraw() 1127 void LayerTreeHostImpl::setNeedsRedraw()
1150 { 1128 {
1151 m_client->setNeedsRedrawOnImplThread(); 1129 m_client->setNeedsRedrawOnImplThread();
1152 } 1130 }
1153 1131
1154 bool LayerTreeHostImpl::ensureRenderSurfaceLayerList() 1132 bool LayerTreeHostImpl::ensureRenderSurfaceLayerList()
1155 { 1133 {
1156 if (!m_rootLayerImpl) 1134 if (!m_rootLayerImpl)
1157 return false; 1135 return false;
1158 if (!m_renderer) 1136 if (!m_renderer)
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 m_client->setNeedsRedrawOnImplThread(); 1502 m_client->setNeedsRedrawOnImplThread();
1525 1503
1526 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { 1504 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) {
1527 m_pageScaleAnimation.reset(); 1505 m_pageScaleAnimation.reset();
1528 m_client->setNeedsCommitOnImplThread(); 1506 m_client->setNeedsCommitOnImplThread();
1529 } 1507 }
1530 } 1508 }
1531 1509
1532 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime) 1510 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime)
1533 { 1511 {
1534 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers || !m_r ootLayerImpl) 1512 if (!m_settings.acceleratedAnimationEnabled || AnimationRegistrar::GetActive Controllers(AnimationRegistrar::CompositorThread).empty() || !m_rootLayerImpl)
1535 return; 1513 return;
1536 1514
1537 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); 1515 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers");
1538 1516
1517 double monotonicSeconds = (monotonicTime - base::TimeTicks()).InSecondsF();
1518
1539 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 1519 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
1540 1520 AnimationControllerSet copy = AnimationRegistrar::GetActiveControllers(Anima tionRegistrar::CompositorThread);
1541 bool didAnimate = false; 1521 for (AnimationControllerSet::iterator iter = copy.begin(); iter != copy.end( ); ++iter)
1542 animateLayersRecursive(m_rootLayerImpl.get(), monotonicTime, wallClockTime, events.get(), didAnimate, m_needsAnimateLayers); 1522 (*iter)->animate(monotonicSeconds, events.get());
1543 1523
1544 if (!events->empty()) 1524 if (!events->empty())
1545 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal lClockTime); 1525 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal lClockTime);
1546 1526
1547 if (didAnimate) 1527 m_client->setNeedsRedrawOnImplThread();
1548 m_client->setNeedsRedrawOnImplThread(); 1528 setBackgroundTickingEnabled(!m_visible && !AnimationRegistrar::GetActiveCont rollers(AnimationRegistrar::CompositorThread).empty());
1549
1550 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers);
1551 } 1529 }
1552 1530
1553 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const 1531 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const
1554 { 1532 {
1555 return base::TimeDelta::FromSeconds(1); 1533 return base::TimeDelta::FromSeconds(1);
1556 } 1534 }
1557 1535
1558 void LayerTreeHostImpl::sendDidLoseContextRecursive(LayerImpl* current) 1536 void LayerTreeHostImpl::sendDidLoseContextRecursive(LayerImpl* current)
1559 { 1537 {
1560 DCHECK(current); 1538 DCHECK(current);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController(); 1609 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController();
1632 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); 1610 double monotonicTime = (time - base::TimeTicks()).InSecondsF();
1633 if (scrollbarController && scrollbarController->animate(monotonicTime)) 1611 if (scrollbarController && scrollbarController->animate(monotonicTime))
1634 m_client->setNeedsRedrawOnImplThread(); 1612 m_client->setNeedsRedrawOnImplThread();
1635 1613
1636 for (size_t i = 0; i < layer->children().size(); ++i) 1614 for (size_t i = 0; i < layer->children().size(); ++i)
1637 animateScrollbarsRecursive(layer->children()[i], time); 1615 animateScrollbarsRecursive(layer->children()[i], time);
1638 } 1616 }
1639 1617
1640 } // namespace cc 1618 } // namespace cc
OLDNEW
« cc/animation_registrar.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