OLD | NEW |
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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 , m_debugState(settings.initialDebugState) | 209 , m_debugState(settings.initialDebugState) |
209 , m_deviceScaleFactor(1) | 210 , m_deviceScaleFactor(1) |
210 , m_visible(true) | 211 , m_visible(true) |
211 , m_contentsTexturesPurged(false) | 212 , m_contentsTexturesPurged(false) |
212 , m_managedMemoryPolicy(PrioritizedResourceManager::defaultMemoryAllocationL
imit(), | 213 , m_managedMemoryPolicy(PrioritizedResourceManager::defaultMemoryAllocationL
imit(), |
213 PriorityCalculator::allowEverythingCutoff(), | 214 PriorityCalculator::allowEverythingCutoff(), |
214 0, | 215 0, |
215 PriorityCalculator::allowNothingCutoff()) | 216 PriorityCalculator::allowNothingCutoff()) |
216 , m_backgroundColor(0) | 217 , m_backgroundColor(0) |
217 , m_hasTransparentBackground(false) | 218 , m_hasTransparentBackground(false) |
218 , m_needsAnimateLayers(false) | |
219 , m_pinchGestureActive(false) | 219 , m_pinchGestureActive(false) |
220 , m_fpsCounter(FrameRateCounter::create(m_proxy->hasImplThread())) | 220 , m_fpsCounter(FrameRateCounter::create(m_proxy->hasImplThread())) |
221 , m_debugRectHistory(DebugRectHistory::create()) | 221 , m_debugRectHistory(DebugRectHistory::create()) |
222 , m_numImplThreadScrolls(0) | 222 , m_numImplThreadScrolls(0) |
223 , m_numMainThreadScrolls(0) | 223 , m_numMainThreadScrolls(0) |
224 , m_cumulativeNumLayersDrawn(0) | 224 , m_cumulativeNumLayersDrawn(0) |
225 { | 225 { |
226 DCHECK(m_proxy->isImplThread()); | 226 DCHECK(m_proxy->isImplThread()); |
227 didVisibilityChange(this, m_visible); | 227 didVisibilityChange(this, m_visible); |
228 | 228 |
229 // TODO(nduca): For now, assume we have an active tree. This will be removed | 229 // TODO(nduca): For now, assume we have an active tree. This will be removed |
230 // in future patches. | 230 // in future patches. |
231 m_activeTree = LayerTreeImpl::create(this); | 231 m_activeTree = LayerTreeImpl::create(this); |
232 } | 232 } |
233 | 233 |
234 LayerTreeHostImpl::~LayerTreeHostImpl() | 234 LayerTreeHostImpl::~LayerTreeHostImpl() |
235 { | 235 { |
236 DCHECK(m_proxy->isImplThread()); | 236 DCHECK(m_proxy->isImplThread()); |
237 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); | 237 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); |
238 | 238 |
239 if (rootLayer()) | 239 if (rootLayer()) { |
240 clearRenderSurfaces(); | 240 clearRenderSurfaces(); |
| 241 // The layer trees must be destroyed before the layer tree host. We've |
| 242 // made a contract with our animation controllers that the registrar |
| 243 // will outlive them, and we must make good. |
| 244 m_activeTree.reset(); |
| 245 } |
241 } | 246 } |
242 | 247 |
243 void LayerTreeHostImpl::beginCommit() | 248 void LayerTreeHostImpl::beginCommit() |
244 { | 249 { |
245 } | 250 } |
246 | 251 |
247 void LayerTreeHostImpl::commitComplete() | 252 void LayerTreeHostImpl::commitComplete() |
248 { | 253 { |
249 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); | 254 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); |
250 // Recompute max scroll position; must be after layer content bounds are | 255 // Recompute max scroll position; must be after layer content bounds are |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 if (drawFrame) | 582 if (drawFrame) |
578 occlusionTracker.overdrawMetrics().recordMetrics(this); | 583 occlusionTracker.overdrawMetrics().recordMetrics(this); |
579 | 584 |
580 removeRenderPasses(CullRenderPassesWithNoQuads(), frame); | 585 removeRenderPasses(CullRenderPassesWithNoQuads(), frame); |
581 m_renderer->decideRenderPassAllocationsForFrame(frame.renderPasses); | 586 m_renderer->decideRenderPassAllocationsForFrame(frame.renderPasses); |
582 removeRenderPasses(CullRenderPassesWithCachedTextures(*m_renderer), frame); | 587 removeRenderPasses(CullRenderPassesWithCachedTextures(*m_renderer), frame); |
583 | 588 |
584 return drawFrame; | 589 return drawFrame; |
585 } | 590 } |
586 | 591 |
587 void LayerTreeHostImpl::animateLayersRecursive(LayerImpl* current, base::TimeTic
ks monotonicTime, base::Time wallClockTime, AnimationEventsVector* events, bool&
didAnimate, bool& needsAnimateLayers) | |
588 { | |
589 bool subtreeNeedsAnimateLayers = false; | |
590 | |
591 LayerAnimationController* currentController = current->layerAnimationControl
ler(); | |
592 | |
593 bool hadActiveAnimation = currentController->hasActiveAnimation(); | |
594 double monotonicTimeSeconds = (monotonicTime - base::TimeTicks()).InSecondsF
(); | |
595 currentController->animate(monotonicTimeSeconds, events); | |
596 bool startedAnimation = events->size() > 0; | |
597 | |
598 // We animated if we either ticked a running animation, or started a new ani
mation. | |
599 if (hadActiveAnimation || startedAnimation) | |
600 didAnimate = true; | |
601 | |
602 // If the current controller still has an active animation, we must continue
animating layers. | |
603 if (currentController->hasActiveAnimation()) | |
604 subtreeNeedsAnimateLayers = true; | |
605 | |
606 for (size_t i = 0; i < current->children().size(); ++i) { | |
607 bool childNeedsAnimateLayers = false; | |
608 animateLayersRecursive(current->children()[i], monotonicTime, wallClockT
ime, events, didAnimate, childNeedsAnimateLayers); | |
609 if (childNeedsAnimateLayers) | |
610 subtreeNeedsAnimateLayers = true; | |
611 } | |
612 | |
613 needsAnimateLayers = subtreeNeedsAnimateLayers; | |
614 } | |
615 | |
616 void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled) | 592 void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled) |
617 { | 593 { |
618 // Lazily create the timeSource adapter so that we can vary the interval for
testing. | 594 // Lazily create the timeSource adapter so that we can vary the interval for
testing. |
619 if (!m_timeSourceClientAdapter) | 595 if (!m_timeSourceClientAdapter) |
620 m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(t
his, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->curr
entThread())); | 596 m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(t
his, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->curr
entThread())); |
621 | 597 |
622 m_timeSourceClientAdapter->setActive(enabled); | 598 m_timeSourceClientAdapter->setActive(enabled); |
623 } | 599 } |
624 | 600 |
625 gfx::Size LayerTreeHostImpl::contentSize() const | 601 gfx::Size LayerTreeHostImpl::contentSize() const |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 return; | 924 return; |
949 m_visible = visible; | 925 m_visible = visible; |
950 didVisibilityChange(this, m_visible); | 926 didVisibilityChange(this, m_visible); |
951 enforceManagedMemoryPolicy(m_managedMemoryPolicy); | 927 enforceManagedMemoryPolicy(m_managedMemoryPolicy); |
952 | 928 |
953 if (!m_renderer) | 929 if (!m_renderer) |
954 return; | 930 return; |
955 | 931 |
956 m_renderer->setVisible(visible); | 932 m_renderer->setVisible(visible); |
957 | 933 |
958 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers); | 934 setBackgroundTickingEnabled(!m_visible && !m_activeAnimationControllers.empt
y()); |
959 } | 935 } |
960 | 936 |
961 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<OutputSurface> outputSurfa
ce) | 937 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<OutputSurface> outputSurfa
ce) |
962 { | 938 { |
963 // Since we will create a new resource provider, we cannot continue to use | 939 // Since we will create a new resource provider, we cannot continue to use |
964 // the old resources (i.e. renderSurfaces and texture IDs). Clear them | 940 // the old resources (i.e. renderSurfaces and texture IDs). Clear them |
965 // before we destroy the old resource provider. | 941 // before we destroy the old resource provider. |
966 if (rootLayer()) { | 942 if (rootLayer()) { |
967 clearRenderSurfaces(); | 943 clearRenderSurfaces(); |
968 sendDidLoseOutputSurfaceRecursive(rootLayer()); | 944 sendDidLoseOutputSurfaceRecursive(rootLayer()); |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 m_client->setNeedsRedrawOnImplThread(); | 1477 m_client->setNeedsRedrawOnImplThread(); |
1502 | 1478 |
1503 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { | 1479 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { |
1504 m_pageScaleAnimation.reset(); | 1480 m_pageScaleAnimation.reset(); |
1505 m_client->setNeedsCommitOnImplThread(); | 1481 m_client->setNeedsCommitOnImplThread(); |
1506 } | 1482 } |
1507 } | 1483 } |
1508 | 1484 |
1509 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time
wallClockTime) | 1485 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time
wallClockTime) |
1510 { | 1486 { |
1511 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers || !roo
tLayer()) | 1487 if (!m_settings.acceleratedAnimationEnabled || m_activeAnimationControllers.
empty() || !rootLayer()) |
1512 return; | 1488 return; |
1513 | 1489 |
1514 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); | 1490 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); |
1515 | 1491 |
| 1492 double monotonicSeconds = (monotonicTime - base::TimeTicks()).InSecondsF(); |
| 1493 |
1516 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 1494 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
1517 | 1495 AnimationControllerSet copy = m_activeAnimationControllers; |
1518 bool didAnimate = false; | 1496 for (AnimationControllerSet::iterator iter = copy.begin(); iter != copy.end(
); ++iter) |
1519 animateLayersRecursive(rootLayer(), monotonicTime, wallClockTime, events.get
(), didAnimate, m_needsAnimateLayers); | 1497 (*iter)->animate(monotonicSeconds, events.get()); |
1520 | 1498 |
1521 if (!events->empty()) | 1499 if (!events->empty()) |
1522 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal
lClockTime); | 1500 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal
lClockTime); |
1523 | 1501 |
1524 if (didAnimate) | 1502 m_client->setNeedsRedrawOnImplThread(); |
1525 m_client->setNeedsRedrawOnImplThread(); | 1503 setBackgroundTickingEnabled(!m_visible && !m_activeAnimationControllers.empt
y()); |
1526 | |
1527 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers); | |
1528 } | 1504 } |
1529 | 1505 |
1530 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const | 1506 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const |
1531 { | 1507 { |
1532 return base::TimeDelta::FromSeconds(1); | 1508 return base::TimeDelta::FromSeconds(1); |
1533 } | 1509 } |
1534 | 1510 |
1535 void LayerTreeHostImpl::sendDidLoseOutputSurfaceRecursive(LayerImpl* current) | 1511 void LayerTreeHostImpl::sendDidLoseOutputSurfaceRecursive(LayerImpl* current) |
1536 { | 1512 { |
1537 DCHECK(current); | 1513 DCHECK(current); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1607 | 1583 |
1608 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio
nController(); | 1584 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio
nController(); |
1609 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); | 1585 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
1610 if (scrollbarController && scrollbarController->animate(monotonicTime)) | 1586 if (scrollbarController && scrollbarController->animate(monotonicTime)) |
1611 m_client->setNeedsRedrawOnImplThread(); | 1587 m_client->setNeedsRedrawOnImplThread(); |
1612 | 1588 |
1613 for (size_t i = 0; i < layer->children().size(); ++i) | 1589 for (size_t i = 0; i < layer->children().size(); ++i) |
1614 animateScrollbarsRecursive(layer->children()[i], time); | 1590 animateScrollbarsRecursive(layer->children()[i], time); |
1615 } | 1591 } |
1616 | 1592 |
| 1593 void LayerTreeHostImpl::DidActivateAnimationController(LayerAnimationController*
controller) { |
| 1594 m_activeAnimationControllers.insert(controller); |
| 1595 } |
| 1596 |
| 1597 void LayerTreeHostImpl::DidDeactivateAnimationController(LayerAnimationControlle
r* controller) { |
| 1598 if (ContainsKey(m_activeAnimationControllers, controller)) |
| 1599 m_activeAnimationControllers.erase(controller); |
| 1600 } |
| 1601 |
| 1602 void LayerTreeHostImpl::RegisterAnimationController(LayerAnimationController* co
ntroller) { |
| 1603 #if !defined(NDEBUG) |
| 1604 m_allAnimationControllers.insert(controller); |
| 1605 #endif |
| 1606 } |
| 1607 |
| 1608 void LayerTreeHostImpl::UnregisterAnimationController(LayerAnimationController*
controller) { |
| 1609 #if !defined(NDEBUG) |
| 1610 if (ContainsKey(m_allAnimationControllers, controller)) |
| 1611 m_allAnimationControllers.erase(controller); |
| 1612 #endif |
| 1613 DidDeactivateAnimationController(controller); |
| 1614 } |
| 1615 |
1617 } // namespace cc | 1616 } // namespace cc |
OLD | NEW |