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

Side by Side Diff: cc/layer_tree_host_impl.cc

Issue 11491003: Revert 171714 - Use an auxiliary list of animation controllers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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
« no previous file with comments | « cc/layer_tree_host_impl.h ('k') | cc/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 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"
13 #include "cc/append_quads_data.h" 12 #include "cc/append_quads_data.h"
14 #include "cc/damage_tracker.h" 13 #include "cc/damage_tracker.h"
15 #include "cc/debug_rect_history.h" 14 #include "cc/debug_rect_history.h"
16 #include "cc/delay_based_time_source.h" 15 #include "cc/delay_based_time_source.h"
17 #include "cc/delegating_renderer.h" 16 #include "cc/delegating_renderer.h"
18 #include "cc/frame_rate_counter.h" 17 #include "cc/frame_rate_counter.h"
19 #include "cc/gl_renderer.h" 18 #include "cc/gl_renderer.h"
20 #include "cc/heads_up_display_layer_impl.h" 19 #include "cc/heads_up_display_layer_impl.h"
21 #include "cc/layer_iterator.h" 20 #include "cc/layer_iterator.h"
22 #include "cc/layer_tree_host.h" 21 #include "cc/layer_tree_host.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 , m_debugState(settings.initialDebugState) 211 , m_debugState(settings.initialDebugState)
213 , m_deviceScaleFactor(1) 212 , m_deviceScaleFactor(1)
214 , m_visible(true) 213 , m_visible(true)
215 , m_contentsTexturesPurged(false) 214 , m_contentsTexturesPurged(false)
216 , m_managedMemoryPolicy(PrioritizedResourceManager::defaultMemoryAllocationL imit(), 215 , m_managedMemoryPolicy(PrioritizedResourceManager::defaultMemoryAllocationL imit(),
217 PriorityCalculator::allowEverythingCutoff(), 216 PriorityCalculator::allowEverythingCutoff(),
218 0, 217 0,
219 PriorityCalculator::allowNothingCutoff()) 218 PriorityCalculator::allowNothingCutoff())
220 , m_backgroundColor(0) 219 , m_backgroundColor(0)
221 , m_hasTransparentBackground(false) 220 , m_hasTransparentBackground(false)
221 , m_needsAnimateLayers(false)
222 , m_pinchGestureActive(false) 222 , m_pinchGestureActive(false)
223 , m_fpsCounter(FrameRateCounter::create(m_proxy->hasImplThread())) 223 , m_fpsCounter(FrameRateCounter::create(m_proxy->hasImplThread()))
224 , m_debugRectHistory(DebugRectHistory::create()) 224 , m_debugRectHistory(DebugRectHistory::create())
225 , m_numImplThreadScrolls(0) 225 , m_numImplThreadScrolls(0)
226 , m_numMainThreadScrolls(0) 226 , m_numMainThreadScrolls(0)
227 , m_cumulativeNumLayersDrawn(0) 227 , m_cumulativeNumLayersDrawn(0)
228 , m_cumulativeNumMissingTiles(0) 228 , m_cumulativeNumMissingTiles(0)
229 , m_lastSentMemoryVisibleBytes(0) 229 , m_lastSentMemoryVisibleBytes(0)
230 , m_lastSentMemoryVisibleAndNearbyBytes(0) 230 , m_lastSentMemoryVisibleAndNearbyBytes(0)
231 , m_lastSentMemoryUseBytes(0) 231 , m_lastSentMemoryUseBytes(0)
232 { 232 {
233 DCHECK(m_proxy->isImplThread()); 233 DCHECK(m_proxy->isImplThread());
234 didVisibilityChange(this, m_visible); 234 didVisibilityChange(this, m_visible);
235 235
236 // TODO(nduca): For now, assume we have an active tree. This will be removed 236 // TODO(nduca): For now, assume we have an active tree. This will be removed
237 // in future patches. 237 // in future patches.
238 m_activeTree = LayerTreeImpl::create(this); 238 m_activeTree = LayerTreeImpl::create(this);
239 } 239 }
240 240
241 LayerTreeHostImpl::~LayerTreeHostImpl() 241 LayerTreeHostImpl::~LayerTreeHostImpl()
242 { 242 {
243 DCHECK(m_proxy->isImplThread()); 243 DCHECK(m_proxy->isImplThread());
244 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); 244 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()");
245 245
246 if (rootLayer()) { 246 if (rootLayer())
247 clearRenderSurfaces(); 247 clearRenderSurfaces();
248 // The layer trees must be destroyed before the layer tree host. We've
249 // made a contract with our animation controllers that the registrar
250 // will outlive them, and we must make good.
251 m_activeTree.reset();
252 }
253 } 248 }
254 249
255 void LayerTreeHostImpl::beginCommit() 250 void LayerTreeHostImpl::beginCommit()
256 { 251 {
257 } 252 }
258 253
259 void LayerTreeHostImpl::commitComplete() 254 void LayerTreeHostImpl::commitComplete()
260 { 255 {
261 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); 256 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete");
262 // Recompute max scroll position; must be after layer content bounds are 257 // Recompute max scroll position; must be after layer content bounds are
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 if (drawFrame) 585 if (drawFrame)
591 occlusionTracker.overdrawMetrics().recordMetrics(this); 586 occlusionTracker.overdrawMetrics().recordMetrics(this);
592 587
593 removeRenderPasses(CullRenderPassesWithNoQuads(), frame); 588 removeRenderPasses(CullRenderPassesWithNoQuads(), frame);
594 m_renderer->decideRenderPassAllocationsForFrame(frame.renderPasses); 589 m_renderer->decideRenderPassAllocationsForFrame(frame.renderPasses);
595 removeRenderPasses(CullRenderPassesWithCachedTextures(*m_renderer), frame); 590 removeRenderPasses(CullRenderPassesWithCachedTextures(*m_renderer), frame);
596 591
597 return drawFrame; 592 return drawFrame;
598 } 593 }
599 594
595 void LayerTreeHostImpl::animateLayersRecursive(LayerImpl* current, base::TimeTic ks monotonicTime, base::Time wallClockTime, AnimationEventsVector* events, bool& didAnimate, bool& needsAnimateLayers)
596 {
597 bool subtreeNeedsAnimateLayers = false;
598
599 LayerAnimationController* currentController = current->layerAnimationControl ler();
600
601 bool hadActiveAnimation = currentController->hasActiveAnimation();
602 double monotonicTimeSeconds = (monotonicTime - base::TimeTicks()).InSecondsF ();
603 currentController->animate(monotonicTimeSeconds, events);
604 bool startedAnimation = events->size() > 0;
605
606 // We animated if we either ticked a running animation, or started a new ani mation.
607 if (hadActiveAnimation || startedAnimation)
608 didAnimate = true;
609
610 // If the current controller still has an active animation, we must continue animating layers.
611 if (currentController->hasActiveAnimation())
612 subtreeNeedsAnimateLayers = true;
613
614 for (size_t i = 0; i < current->children().size(); ++i) {
615 bool childNeedsAnimateLayers = false;
616 animateLayersRecursive(current->children()[i], monotonicTime, wallClockT ime, events, didAnimate, childNeedsAnimateLayers);
617 if (childNeedsAnimateLayers)
618 subtreeNeedsAnimateLayers = true;
619 }
620
621 needsAnimateLayers = subtreeNeedsAnimateLayers;
622 }
623
600 void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled) 624 void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled)
601 { 625 {
602 // Lazily create the timeSource adapter so that we can vary the interval for testing. 626 // Lazily create the timeSource adapter so that we can vary the interval for testing.
603 if (!m_timeSourceClientAdapter) 627 if (!m_timeSourceClientAdapter)
604 m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(t his, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->curr entThread())); 628 m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(t his, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->curr entThread()));
605 629
606 m_timeSourceClientAdapter->setActive(enabled); 630 m_timeSourceClientAdapter->setActive(enabled);
607 } 631 }
608 632
609 gfx::Size LayerTreeHostImpl::contentSize() const 633 gfx::Size LayerTreeHostImpl::contentSize() const
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 return; 970 return;
947 m_visible = visible; 971 m_visible = visible;
948 didVisibilityChange(this, m_visible); 972 didVisibilityChange(this, m_visible);
949 enforceManagedMemoryPolicy(m_managedMemoryPolicy); 973 enforceManagedMemoryPolicy(m_managedMemoryPolicy);
950 974
951 if (!m_renderer) 975 if (!m_renderer)
952 return; 976 return;
953 977
954 m_renderer->setVisible(visible); 978 m_renderer->setVisible(visible);
955 979
956 setBackgroundTickingEnabled(!m_visible && !m_activeAnimationControllers.empt y()); 980 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers);
957 } 981 }
958 982
959 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<OutputSurface> outputSurfa ce) 983 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<OutputSurface> outputSurfa ce)
960 { 984 {
961 // Since we will create a new resource provider, we cannot continue to use 985 // Since we will create a new resource provider, we cannot continue to use
962 // the old resources (i.e. renderSurfaces and texture IDs). Clear them 986 // the old resources (i.e. renderSurfaces and texture IDs). Clear them
963 // before we destroy the old resource provider. 987 // before we destroy the old resource provider.
964 if (rootLayer()) { 988 if (rootLayer()) {
965 clearRenderSurfaces(); 989 clearRenderSurfaces();
966 sendDidLoseOutputSurfaceRecursive(rootLayer()); 990 sendDidLoseOutputSurfaceRecursive(rootLayer());
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 m_client->setNeedsRedrawOnImplThread(); 1525 m_client->setNeedsRedrawOnImplThread();
1502 1526
1503 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { 1527 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) {
1504 m_pageScaleAnimation.reset(); 1528 m_pageScaleAnimation.reset();
1505 m_client->setNeedsCommitOnImplThread(); 1529 m_client->setNeedsCommitOnImplThread();
1506 } 1530 }
1507 } 1531 }
1508 1532
1509 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime) 1533 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time wallClockTime)
1510 { 1534 {
1511 if (!m_settings.acceleratedAnimationEnabled || m_activeAnimationControllers. empty() || !rootLayer()) 1535 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers || !roo tLayer())
1512 return; 1536 return;
1513 1537
1514 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); 1538 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers");
1515 1539
1516 double monotonicSeconds = (monotonicTime - base::TimeTicks()).InSecondsF(); 1540 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector));
1517 1541
1518 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents Vector)); 1542 bool didAnimate = false;
1519 AnimationControllerSet copy = m_activeAnimationControllers; 1543 animateLayersRecursive(rootLayer(), monotonicTime, wallClockTime, events.get (), didAnimate, m_needsAnimateLayers);
1520 for (AnimationControllerSet::iterator iter = copy.begin(); iter != copy.end( ); ++iter)
1521 (*iter)->animate(monotonicSeconds, events.get());
1522 1544
1523 if (!events->empty()) 1545 if (!events->empty())
1524 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal lClockTime); 1546 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal lClockTime);
1525 1547
1526 m_client->setNeedsRedrawOnImplThread(); 1548 if (didAnimate)
1527 setBackgroundTickingEnabled(!m_visible && !m_activeAnimationControllers.empt y()); 1549 m_client->setNeedsRedrawOnImplThread();
1550
1551 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers);
1528 } 1552 }
1529 1553
1530 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const 1554 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const
1531 { 1555 {
1532 return base::TimeDelta::FromSeconds(1); 1556 return base::TimeDelta::FromSeconds(1);
1533 } 1557 }
1534 1558
1535 void LayerTreeHostImpl::sendDidLoseOutputSurfaceRecursive(LayerImpl* current) 1559 void LayerTreeHostImpl::sendDidLoseOutputSurfaceRecursive(LayerImpl* current)
1536 { 1560 {
1537 DCHECK(current); 1561 DCHECK(current);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 1671
1648 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController(); 1672 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController();
1649 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); 1673 double monotonicTime = (time - base::TimeTicks()).InSecondsF();
1650 if (scrollbarController && scrollbarController->animate(monotonicTime)) 1674 if (scrollbarController && scrollbarController->animate(monotonicTime))
1651 m_client->setNeedsRedrawOnImplThread(); 1675 m_client->setNeedsRedrawOnImplThread();
1652 1676
1653 for (size_t i = 0; i < layer->children().size(); ++i) 1677 for (size_t i = 0; i < layer->children().size(); ++i)
1654 animateScrollbarsRecursive(layer->children()[i], time); 1678 animateScrollbarsRecursive(layer->children()[i], time);
1655 } 1679 }
1656 1680
1657 void LayerTreeHostImpl::DidActivateAnimationController(LayerAnimationController* controller) {
1658 m_activeAnimationControllers.insert(controller);
1659 }
1660
1661 void LayerTreeHostImpl::DidDeactivateAnimationController(LayerAnimationControlle r* controller) {
1662 if (ContainsKey(m_activeAnimationControllers, controller))
1663 m_activeAnimationControllers.erase(controller);
1664 }
1665
1666 void LayerTreeHostImpl::RegisterAnimationController(LayerAnimationController* co ntroller) {
1667 #if !defined(NDEBUG)
1668 m_allAnimationControllers.insert(controller);
1669 #endif
1670 }
1671
1672 void LayerTreeHostImpl::UnregisterAnimationController(LayerAnimationController* controller) {
1673 #if !defined(NDEBUG)
1674 if (ContainsKey(m_allAnimationControllers, controller))
1675 m_allAnimationControllers.erase(controller);
1676 #endif
1677 DidDeactivateAnimationController(controller);
1678 }
1679
1680 } // namespace cc 1681 } // namespace cc
OLDNEW
« no previous file with comments | « 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