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/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/compositor_frame_metadata.h" | 14 #include "cc/compositor_frame_metadata.h" |
14 #include "cc/damage_tracker.h" | 15 #include "cc/damage_tracker.h" |
15 #include "cc/debug_rect_history.h" | 16 #include "cc/debug_rect_history.h" |
16 #include "cc/delay_based_time_source.h" | 17 #include "cc/delay_based_time_source.h" |
17 #include "cc/delegating_renderer.h" | 18 #include "cc/delegating_renderer.h" |
18 #include "cc/frame_rate_counter.h" | 19 #include "cc/frame_rate_counter.h" |
19 #include "cc/gl_renderer.h" | 20 #include "cc/gl_renderer.h" |
20 #include "cc/heads_up_display_layer_impl.h" | 21 #include "cc/heads_up_display_layer_impl.h" |
21 #include "cc/layer_iterator.h" | 22 #include "cc/layer_iterator.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_needsUpdateDrawProperties(false) | 224 , m_needsUpdateDrawProperties(false) |
225 , m_pinchGestureActive(false) | 225 , m_pinchGestureActive(false) |
226 , m_fpsCounter(FrameRateCounter::create(m_proxy->hasImplThread())) | 226 , m_fpsCounter(FrameRateCounter::create(m_proxy->hasImplThread())) |
227 , m_debugRectHistory(DebugRectHistory::create()) | 227 , m_debugRectHistory(DebugRectHistory::create()) |
228 , m_numImplThreadScrolls(0) | 228 , m_numImplThreadScrolls(0) |
229 , m_numMainThreadScrolls(0) | 229 , m_numMainThreadScrolls(0) |
230 , m_cumulativeNumLayersDrawn(0) | 230 , m_cumulativeNumLayersDrawn(0) |
231 , m_cumulativeNumMissingTiles(0) | 231 , m_cumulativeNumMissingTiles(0) |
232 , m_lastSentMemoryVisibleBytes(0) | 232 , m_lastSentMemoryVisibleBytes(0) |
233 , m_lastSentMemoryVisibleAndNearbyBytes(0) | 233 , m_lastSentMemoryVisibleAndNearbyBytes(0) |
234 , m_lastSentMemoryUseBytes(0) | 234 , m_lastSentMemoryUseBytes(0) |
| 235 , m_animationRegistrar(AnimationRegistrar::create()) |
235 { | 236 { |
236 DCHECK(m_proxy->isImplThread()); | 237 DCHECK(m_proxy->isImplThread()); |
237 didVisibilityChange(this, m_visible); | 238 didVisibilityChange(this, m_visible); |
238 | 239 |
239 // TODO(nduca): For now, assume we have an active tree. This will be removed | 240 // TODO(nduca): For now, assume we have an active tree. This will be removed |
240 // in future patches. | 241 // in future patches. |
241 m_activeTree = LayerTreeImpl::create(this); | 242 m_activeTree = LayerTreeImpl::create(this); |
242 } | 243 } |
243 | 244 |
244 LayerTreeHostImpl::~LayerTreeHostImpl() | 245 LayerTreeHostImpl::~LayerTreeHostImpl() |
245 { | 246 { |
246 DCHECK(m_proxy->isImplThread()); | 247 DCHECK(m_proxy->isImplThread()); |
247 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); | 248 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); |
248 | 249 |
249 if (rootLayer()) | 250 if (rootLayer()) { |
250 clearRenderSurfaces(); | 251 clearRenderSurfaces(); |
| 252 // The layer trees must be destroyed before the layer tree host. We've |
| 253 // made a contract with our animation controllers that the registrar |
| 254 // will outlive them, and we must make good. |
| 255 m_activeTree.reset(); |
| 256 m_pendingTree.reset(); |
| 257 } |
251 } | 258 } |
252 | 259 |
253 void LayerTreeHostImpl::beginCommit() | 260 void LayerTreeHostImpl::beginCommit() |
254 { | 261 { |
255 } | 262 } |
256 | 263 |
257 void LayerTreeHostImpl::commitComplete() | 264 void LayerTreeHostImpl::commitComplete() |
258 { | 265 { |
259 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); | 266 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); |
260 | 267 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 if (drawFrame) | 612 if (drawFrame) |
606 occlusionTracker.overdrawMetrics().recordMetrics(this); | 613 occlusionTracker.overdrawMetrics().recordMetrics(this); |
607 | 614 |
608 removeRenderPasses(CullRenderPassesWithNoQuads(), frame); | 615 removeRenderPasses(CullRenderPassesWithNoQuads(), frame); |
609 m_renderer->decideRenderPassAllocationsForFrame(frame.renderPasses); | 616 m_renderer->decideRenderPassAllocationsForFrame(frame.renderPasses); |
610 removeRenderPasses(CullRenderPassesWithCachedTextures(*m_renderer), frame); | 617 removeRenderPasses(CullRenderPassesWithCachedTextures(*m_renderer), frame); |
611 | 618 |
612 return drawFrame; | 619 return drawFrame; |
613 } | 620 } |
614 | 621 |
615 void LayerTreeHostImpl::animateLayersRecursive(LayerImpl* current, base::TimeTic
ks monotonicTime, base::Time wallClockTime, AnimationEventsVector* events, bool&
didAnimate, bool& needsAnimateLayers) | |
616 { | |
617 bool subtreeNeedsAnimateLayers = false; | |
618 | |
619 LayerAnimationController* currentController = current->layerAnimationControl
ler(); | |
620 | |
621 bool hadActiveAnimation = currentController->hasActiveAnimation(); | |
622 double monotonicTimeSeconds = (monotonicTime - base::TimeTicks()).InSecondsF
(); | |
623 currentController->animate(monotonicTimeSeconds, events); | |
624 bool startedAnimation = events->size() > 0; | |
625 | |
626 // We animated if we either ticked a running animation, or started a new ani
mation. | |
627 if (hadActiveAnimation || startedAnimation) | |
628 didAnimate = true; | |
629 | |
630 // If the current controller still has an active animation, we must continue
animating layers. | |
631 if (currentController->hasActiveAnimation()) | |
632 subtreeNeedsAnimateLayers = true; | |
633 | |
634 for (size_t i = 0; i < current->children().size(); ++i) { | |
635 bool childNeedsAnimateLayers = false; | |
636 animateLayersRecursive(current->children()[i], monotonicTime, wallClockT
ime, events, didAnimate, childNeedsAnimateLayers); | |
637 if (childNeedsAnimateLayers) | |
638 subtreeNeedsAnimateLayers = true; | |
639 } | |
640 | |
641 needsAnimateLayers = subtreeNeedsAnimateLayers; | |
642 } | |
643 | |
644 void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled) | 622 void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled) |
645 { | 623 { |
646 // Lazily create the timeSource adapter so that we can vary the interval for
testing. | 624 // Lazily create the timeSource adapter so that we can vary the interval for
testing. |
647 if (!m_timeSourceClientAdapter) | 625 if (!m_timeSourceClientAdapter) |
648 m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(t
his, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->curr
entThread())); | 626 m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(t
his, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->curr
entThread())); |
649 | 627 |
650 m_timeSourceClientAdapter->setActive(enabled); | 628 m_timeSourceClientAdapter->setActive(enabled); |
651 } | 629 } |
652 | 630 |
653 gfx::Size LayerTreeHostImpl::contentSize() const | 631 gfx::Size LayerTreeHostImpl::contentSize() const |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 return; | 1016 return; |
1039 m_visible = visible; | 1017 m_visible = visible; |
1040 didVisibilityChange(this, m_visible); | 1018 didVisibilityChange(this, m_visible); |
1041 enforceManagedMemoryPolicy(m_managedMemoryPolicy); | 1019 enforceManagedMemoryPolicy(m_managedMemoryPolicy); |
1042 | 1020 |
1043 if (!m_renderer) | 1021 if (!m_renderer) |
1044 return; | 1022 return; |
1045 | 1023 |
1046 m_renderer->setVisible(visible); | 1024 m_renderer->setVisible(visible); |
1047 | 1025 |
1048 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers); | 1026 setBackgroundTickingEnabled(!m_visible && !m_animationRegistrar->active_anim
ation_controllers().empty()); |
1049 } | 1027 } |
1050 | 1028 |
1051 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<OutputSurface> outputSurfa
ce) | 1029 bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<OutputSurface> outputSurfa
ce) |
1052 { | 1030 { |
1053 // Since we will create a new resource provider, we cannot continue to use | 1031 // Since we will create a new resource provider, we cannot continue to use |
1054 // the old resources (i.e. renderSurfaces and texture IDs). Clear them | 1032 // the old resources (i.e. renderSurfaces and texture IDs). Clear them |
1055 // before we destroy the old resource provider. | 1033 // before we destroy the old resource provider. |
1056 if (rootLayer()) { | 1034 if (rootLayer()) { |
1057 clearRenderSurfaces(); | 1035 clearRenderSurfaces(); |
1058 sendDidLoseOutputSurfaceRecursive(rootLayer()); | 1036 sendDidLoseOutputSurfaceRecursive(rootLayer()); |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 setNeedsUpdateDrawProperties(); | 1558 setNeedsUpdateDrawProperties(); |
1581 | 1559 |
1582 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { | 1560 if (m_pageScaleAnimation->isAnimationCompleteAtTime(monotonicTime)) { |
1583 m_pageScaleAnimation.reset(); | 1561 m_pageScaleAnimation.reset(); |
1584 m_client->setNeedsCommitOnImplThread(); | 1562 m_client->setNeedsCommitOnImplThread(); |
1585 } | 1563 } |
1586 } | 1564 } |
1587 | 1565 |
1588 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time
wallClockTime) | 1566 void LayerTreeHostImpl::animateLayers(base::TimeTicks monotonicTime, base::Time
wallClockTime) |
1589 { | 1567 { |
1590 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers || !roo
tLayer()) | 1568 if (!m_settings.acceleratedAnimationEnabled || m_animationRegistrar->active_
animation_controllers().empty() || !rootLayer()) |
1591 return; | 1569 return; |
1592 | 1570 |
1593 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); | 1571 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); |
1594 | 1572 |
| 1573 double monotonicSeconds = (monotonicTime - base::TimeTicks()).InSecondsF(); |
| 1574 |
1595 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); | 1575 scoped_ptr<AnimationEventsVector> events(make_scoped_ptr(new AnimationEvents
Vector)); |
1596 | 1576 AnimationRegistrar::AnimationControllerMap copy = m_animationRegistrar->acti
ve_animation_controllers(); |
1597 bool didAnimate = false; | 1577 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(
); iter != copy.end(); ++iter) |
1598 animateLayersRecursive(rootLayer(), monotonicTime, wallClockTime, events.get
(), didAnimate, m_needsAnimateLayers); | 1578 (*iter).second->animate(monotonicSeconds, events.get()); |
1599 | 1579 |
1600 if (!events->empty()) | 1580 if (!events->empty()) |
1601 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal
lClockTime); | 1581 m_client->postAnimationEventsToMainThreadOnImplThread(events.Pass(), wal
lClockTime); |
1602 | 1582 |
1603 if (didAnimate) { | 1583 m_client->setNeedsRedrawOnImplThread(); |
1604 m_client->setNeedsRedrawOnImplThread(); | 1584 setNeedsUpdateDrawProperties(); |
1605 setNeedsUpdateDrawProperties(); | 1585 setBackgroundTickingEnabled(!m_visible && !m_animationRegistrar->active_anim
ation_controllers().empty()); |
1606 } | |
1607 | |
1608 setBackgroundTickingEnabled(!m_visible && m_needsAnimateLayers); | |
1609 } | 1586 } |
1610 | 1587 |
1611 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const | 1588 base::TimeDelta LayerTreeHostImpl::lowFrequencyAnimationInterval() const |
1612 { | 1589 { |
1613 return base::TimeDelta::FromSeconds(1); | 1590 return base::TimeDelta::FromSeconds(1); |
1614 } | 1591 } |
1615 | 1592 |
1616 void LayerTreeHostImpl::sendDidLoseOutputSurfaceRecursive(LayerImpl* current) | 1593 void LayerTreeHostImpl::sendDidLoseOutputSurfaceRecursive(LayerImpl* current) |
1617 { | 1594 { |
1618 DCHECK(current); | 1595 DCHECK(current); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1730 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio
nController(); | 1707 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio
nController(); |
1731 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); | 1708 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
1732 if (scrollbarController && scrollbarController->animate(monotonicTime)) | 1709 if (scrollbarController && scrollbarController->animate(monotonicTime)) |
1733 m_client->setNeedsRedrawOnImplThread(); | 1710 m_client->setNeedsRedrawOnImplThread(); |
1734 | 1711 |
1735 for (size_t i = 0; i < layer->children().size(); ++i) | 1712 for (size_t i = 0; i < layer->children().size(); ++i) |
1736 animateScrollbarsRecursive(layer->children()[i], time); | 1713 animateScrollbarsRecursive(layer->children()[i], time); |
1737 } | 1714 } |
1738 | 1715 |
1739 } // namespace cc | 1716 } // namespace cc |
OLD | NEW |