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

Side by Side Diff: cc/layer_tree_host_impl.cc

Issue 11598005: Ref count layer 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 "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/stl_util.h"
12 #include "cc/append_quads_data.h" 13 #include "cc/append_quads_data.h"
13 #include "cc/damage_tracker.h" 14 #include "cc/damage_tracker.h"
14 #include "cc/debug_rect_history.h" 15 #include "cc/debug_rect_history.h"
15 #include "cc/delay_based_time_source.h" 16 #include "cc/delay_based_time_source.h"
16 #include "cc/delegating_renderer.h" 17 #include "cc/delegating_renderer.h"
17 #include "cc/frame_rate_counter.h" 18 #include "cc/frame_rate_counter.h"
18 #include "cc/gl_renderer.h" 19 #include "cc/gl_renderer.h"
19 #include "cc/heads_up_display_layer_impl.h" 20 #include "cc/heads_up_display_layer_impl.h"
20 #include "cc/layer_iterator.h" 21 #include "cc/layer_iterator.h"
21 #include "cc/layer_tree_host.h" 22 #include "cc/layer_tree_host.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 , m_debugState(settings.initialDebugState) 213 , m_debugState(settings.initialDebugState)
213 , m_deviceScaleFactor(1) 214 , m_deviceScaleFactor(1)
214 , m_visible(true) 215 , m_visible(true)
215 , m_contentsTexturesPurged(false) 216 , m_contentsTexturesPurged(false)
216 , m_managedMemoryPolicy(PrioritizedResourceManager::defaultMemoryAllocationL imit(), 217 , m_managedMemoryPolicy(PrioritizedResourceManager::defaultMemoryAllocationL imit(),
217 PriorityCalculator::allowEverythingCutoff(), 218 PriorityCalculator::allowEverythingCutoff(),
218 0, 219 0,
219 PriorityCalculator::allowNothingCutoff()) 220 PriorityCalculator::allowNothingCutoff())
220 , m_backgroundColor(0) 221 , m_backgroundColor(0)
221 , m_hasTransparentBackground(false) 222 , m_hasTransparentBackground(false)
222 , m_needsAnimateLayers(false)
223 , m_needsUpdateDrawProperties(false) 223 , m_needsUpdateDrawProperties(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 , m_cumulativeNumMissingTiles(0) 230 , m_cumulativeNumMissingTiles(0)
231 , m_lastSentMemoryVisibleBytes(0) 231 , m_lastSentMemoryVisibleBytes(0)
232 , m_lastSentMemoryVisibleAndNearbyBytes(0) 232 , m_lastSentMemoryVisibleAndNearbyBytes(0)
233 , m_lastSentMemoryUseBytes(0) 233 , m_lastSentMemoryUseBytes(0)
234 { 234 {
235 DCHECK(m_proxy->isImplThread()); 235 DCHECK(m_proxy->isImplThread());
236 didVisibilityChange(this, m_visible); 236 didVisibilityChange(this, m_visible);
237 237
238 // TODO(nduca): For now, assume we have an active tree. This will be removed 238 // TODO(nduca): For now, assume we have an active tree. This will be removed
239 // in future patches. 239 // in future patches.
240 m_activeTree = LayerTreeImpl::create(this); 240 m_activeTree = LayerTreeImpl::create(this);
241 } 241 }
242 242
243 LayerTreeHostImpl::~LayerTreeHostImpl() 243 LayerTreeHostImpl::~LayerTreeHostImpl()
244 { 244 {
245 DCHECK(m_proxy->isImplThread()); 245 DCHECK(m_proxy->isImplThread());
246 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); 246 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()");
247 247
248 if (rootLayer()) 248 if (rootLayer()) {
249 clearRenderSurfaces(); 249 clearRenderSurfaces();
250 // The layer trees must be destroyed before the layer tree host. We've
251 // made a contract with our animation controllers that the registrar
252 // will outlive them, and we must make good.
253 m_activeTree.reset();
254 m_pendingTree.reset();
255 }
250 } 256 }
251 257
252 void LayerTreeHostImpl::beginCommit() 258 void LayerTreeHostImpl::beginCommit()
253 { 259 {
254 } 260 }
255 261
256 void LayerTreeHostImpl::commitComplete() 262 void LayerTreeHostImpl::commitComplete()
257 { 263 {
258 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); 264 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete");
259 265
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 if (drawFrame) 618 if (drawFrame)
613 occlusionTracker.overdrawMetrics().recordMetrics(this); 619 occlusionTracker.overdrawMetrics().recordMetrics(this);
614 620
615 removeRenderPasses(CullRenderPassesWithNoQuads(), frame); 621 removeRenderPasses(CullRenderPassesWithNoQuads(), frame);
616 m_renderer->decideRenderPassAllocationsForFrame(frame.renderPasses); 622 m_renderer->decideRenderPassAllocationsForFrame(frame.renderPasses);
617 removeRenderPasses(CullRenderPassesWithCachedTextures(*m_renderer), frame); 623 removeRenderPasses(CullRenderPassesWithCachedTextures(*m_renderer), frame);
618 624
619 return drawFrame; 625 return drawFrame;
620 } 626 }
621 627
622 void LayerTreeHostImpl::animateLayersRecursive(LayerImpl* current, base::TimeTic ks monotonicTime, base::Time wallClockTime, AnimationEventsVector* events, bool& didAnimate, bool& needsAnimateLayers)
623 {
624 bool subtreeNeedsAnimateLayers = false;
625
626 LayerAnimationController* currentController = current->layerAnimationControl ler();
627
628 bool hadActiveAnimation = currentController->hasActiveAnimation();
629 double monotonicTimeSeconds = (monotonicTime - base::TimeTicks()).InSecondsF ();
630 currentController->animate(monotonicTimeSeconds, events);
631 bool startedAnimation = events->size() > 0;
632
633 // We animated if we either ticked a running animation, or started a new ani mation.
634 if (hadActiveAnimation || startedAnimation)
635 didAnimate = true;
636
637 // If the current controller still has an active animation, we must continue animating layers.
638 if (currentController->hasActiveAnimation())
639 subtreeNeedsAnimateLayers = true;
640
641 for (size_t i = 0; i < current->children().size(); ++i) {
642 bool childNeedsAnimateLayers = false;
643 animateLayersRecursive(current->children()[i], monotonicTime, wallClockT ime, events, didAnimate, childNeedsAnimateLayers);
644 if (childNeedsAnimateLayers)
645 subtreeNeedsAnimateLayers = true;
646 }
647
648 needsAnimateLayers = subtreeNeedsAnimateLayers;
649 }
650
651 void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled) 628 void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled)
652 { 629 {
653 // Lazily create the timeSource adapter so that we can vary the interval for testing. 630 // Lazily create the timeSource adapter so that we can vary the interval for testing.
654 if (!m_timeSourceClientAdapter) 631 if (!m_timeSourceClientAdapter)
655 m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(t his, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->curr entThread())); 632 m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(t his, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->curr entThread()));
656 633
657 m_timeSourceClientAdapter->setActive(enabled); 634 m_timeSourceClientAdapter->setActive(enabled);
658 } 635 }
659 636
660 gfx::Size LayerTreeHostImpl::contentSize() const 637 gfx::Size LayerTreeHostImpl::contentSize() const
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 return; 1003 return;
1027 m_visible = visible; 1004 m_visible = visible;
1028 didVisibilityChange(this, m_visible); 1005 didVisibilityChange(this, m_visible);
1029 enforceManagedMemoryPolicy(m_managedMemoryPolicy); 1006 enforceManagedMemoryPolicy(m_managedMemoryPolicy);
1030 1007
1031 if (!m_renderer) 1008 if (!m_renderer)
1032 return; 1009 return;
1033 1010
1034 m_renderer->setVisible(visible); 1011 m_renderer->setVisible(visible);
1035 1012
1036 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers); 1013 setBackgroundTickingEnabled(!m_visible && !m_activeAnimationControllers.empt y());
1037 } 1014 }
1038 1015
1039 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<OutputSurface> outputSurfa ce) 1016 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<OutputSurface> outputSurfa ce)
1040 { 1017 {
1041 // Since we will create a new resource provider, we cannot continue to use 1018 // Since we will create a new resource provider, we cannot continue to use
1042 // the old resources (i.e. renderSurfaces and texture IDs). Clear them 1019 // the old resources (i.e. renderSurfaces and texture IDs). Clear them
1043 // before we destroy the old resource provider. 1020 // before we destroy the old resource provider.
1044 if (rootLayer()) { 1021 if (rootLayer()) {
1045 clearRenderSurfaces(); 1022 clearRenderSurfaces();
1046 sendDidLoseOutputSurfaceRecursive(rootLayer()); 1023 sendDidLoseOutputSurfaceRecursive(rootLayer());
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 setNeedsUpdateDrawProperties(); 1563 setNeedsUpdateDrawProperties();
1587 1564
1588 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { 1565 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) {
1589 m_pageScaleAnimation.reset(); 1566 m_pageScaleAnimation.reset();
1590 m_client->setNeedsCommitOnImplThread(); 1567 m_client->setNeedsCommitOnImplThread();
1591 } 1568 }
1592 } 1569 }
1593 1570
1594 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime) 1571 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime)
1595 { 1572 {
1596 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers || !roo tLayer()) 1573 if (!m_settings.acceleratedAnimationEnabled || m_activeAnimationControllers. empty() || !rootLayer())
1597 return; 1574 return;
1598 1575
1599 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); 1576 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers");
1600 1577
1578 double monotonicSeconds = (monotonicTime - base::TimeTicks()).InSecondsF();
1579
1601 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 1580 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
1602 1581 AnimationControllerMap copy = m_activeAnimationControllers;
1603 bool didAnimate = false; 1582 for (AnimationControllerMap::iterator iter = copy.begin(); iter != copy.end( ); ++iter)
1604 animateLayersRecursive(rootLayer(), monotonicTime, wallClockTime, events.get (), didAnimate, m_needsAnimateLayers); 1583 (*iter).second->animate(monotonicSeconds, events.get());
1605 1584
1606 if (!events->empty()) 1585 if (!events->empty())
1607 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal lClockTime); 1586 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal lClockTime);
1608 1587
1609 if (didAnimate) { 1588 m_client->setNeedsRedrawOnImplThread();
1610 m_client->setNeedsRedrawOnImplThread(); 1589 setNeedsUpdateDrawProperties();
1611 setNeedsUpdateDrawProperties(); 1590 setBackgroundTickingEnabled(!m_visible && !m_activeAnimationControllers.empt y());
1612 }
1613
1614 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers);
1615 } 1591 }
1616 1592
1617 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const 1593 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const
1618 { 1594 {
1619 return base::TimeDelta::FromSeconds(1); 1595 return base::TimeDelta::FromSeconds(1);
1620 } 1596 }
1621 1597
1622 void LayerTreeHostImpl::sendDidLoseOutputSurfaceRecursive(LayerImpl* current) 1598 void LayerTreeHostImpl::sendDidLoseOutputSurfaceRecursive(LayerImpl* current)
1623 { 1599 {
1624 DCHECK(current); 1600 DCHECK(current);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 1711
1736 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController(); 1712 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController();
1737 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); 1713 double monotonicTime = (time - base::TimeTicks()).InSecondsF();
1738 if (scrollbarController && scrollbarController->animate(monotonicTime)) 1714 if (scrollbarController && scrollbarController->animate(monotonicTime))
1739 m_client->setNeedsRedrawOnImplThread(); 1715 m_client->setNeedsRedrawOnImplThread();
1740 1716
1741 for (size_t i = 0; i < layer->children().size(); ++i) 1717 for (size_t i = 0; i < layer->children().size(); ++i)
1742 animateScrollbarsRecursive(layer->children()[i], time); 1718 animateScrollbarsRecursive(layer->children()[i], time);
1743 } 1719 }
1744 1720
1721 scoped_refptr<LayerAnimationController> LayerTreeHostImpl::GetAnimationControlle rForId(int id)
1722 {
1723 scoped_refptr<LayerAnimationController> toReturn;
1724 if (!ContainsKey(m_allAnimationControllers, id)) {
1725 toReturn = LayerAnimationController::create(id);
1726 toReturn->setAnimationRegistrar(this);
1727 m_allAnimationControllers[id] = toReturn.get();
1728 } else
1729 toReturn = m_allAnimationControllers[id];
1730 return toReturn;
1731 }
1732
1733 void LayerTreeHostImpl::DidActivateAnimationController(LayerAnimationController* controller) {
1734 m_activeAnimationControllers[controller->id()] = controller;
1735 }
1736
1737 void LayerTreeHostImpl::DidDeactivateAnimationController(LayerAnimationControlle r* controller) {
1738 if (ContainsKey(m_activeAnimationControllers, controller->id()))
1739 m_activeAnimationControllers.erase(controller->id());
1740 }
1741
1742 void LayerTreeHostImpl::RegisterAnimationController(LayerAnimationController* co ntroller) {
1743 m_allAnimationControllers[controller->id()] = controller;
1744 }
1745
1746 void LayerTreeHostImpl::UnregisterAnimationController(LayerAnimationController* controller) {
1747 if (ContainsKey(m_allAnimationControllers, controller->id()))
1748 m_allAnimationControllers.erase(controller->id());
1749 DidDeactivateAnimationController(controller);
1750 }
1751
1745 } // namespace cc 1752 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698