Chromium Code Reviews| 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.h" | 5 #include "cc/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 return scoped_ptr<LayerTreeHost>(); | 68 return scoped_ptr<LayerTreeHost>(); |
| 69 return layerTreeHost.Pass(); | 69 return layerTreeHost.Pass(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting s& settings) | 72 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting s& settings) |
| 73 : m_animating(false) | 73 : m_animating(false) |
| 74 , m_needsFullTreeSync(true) | 74 , m_needsFullTreeSync(true) |
| 75 , m_needsFilterContext(false) | 75 , m_needsFilterContext(false) |
| 76 , m_client(client) | 76 , m_client(client) |
| 77 , m_commitNumber(0) | 77 , m_commitNumber(0) |
| 78 , m_renderingStats() | 78 , m_renderingStatsRecorder(RenderingStatsRecorder::create()) |
| 79 , m_rendererInitialized(false) | 79 , m_rendererInitialized(false) |
| 80 , m_outputSurfaceLost(false) | 80 , m_outputSurfaceLost(false) |
| 81 , m_numFailedRecreateAttempts(0) | 81 , m_numFailedRecreateAttempts(0) |
| 82 , m_settings(settings) | 82 , m_settings(settings) |
| 83 , m_debugState(settings.initialDebugState) | 83 , m_debugState(settings.initialDebugState) |
| 84 , m_deviceScaleFactor(1) | 84 , m_deviceScaleFactor(1) |
| 85 , m_visible(true) | 85 , m_visible(true) |
| 86 , m_pageScaleFactor(1) | 86 , m_pageScaleFactor(1) |
| 87 , m_minPageScaleFactor(1) | 87 , m_minPageScaleFactor(1) |
| 88 , m_maxPageScaleFactor(1) | 88 , m_maxPageScaleFactor(1) |
| 89 , m_triggerIdleUpdates(true) | 89 , m_triggerIdleUpdates(true) |
| 90 , m_backgroundColor(SK_ColorWHITE) | 90 , m_backgroundColor(SK_ColorWHITE) |
| 91 , m_hasTransparentBackground(false) | 91 , m_hasTransparentBackground(false) |
| 92 , m_partialTextureUpdateRequests(0) | 92 , m_partialTextureUpdateRequests(0) |
| 93 { | 93 { |
| 94 if (m_settings.acceleratedAnimationEnabled) | 94 if (m_settings.acceleratedAnimationEnabled) |
| 95 m_animationRegistrar = AnimationRegistrar::create(); | 95 m_animationRegistrar = AnimationRegistrar::create(); |
| 96 numLayerTreeInstances++; | 96 numLayerTreeInstances++; |
| 97 m_renderingStatsRecorder->set_record_rendering_stats(m_debugState.recordRend eringStats()); | |
| 97 } | 98 } |
| 98 | 99 |
| 99 bool LayerTreeHost::initialize(scoped_ptr<Thread> implThread) | 100 bool LayerTreeHost::initialize(scoped_ptr<Thread> implThread) |
| 100 { | 101 { |
| 101 if (implThread) | 102 if (implThread) |
| 102 return initializeProxy(ThreadProxy::create(this, implThread.Pass())); | 103 return initializeProxy(ThreadProxy::create(this, implThread.Pass())); |
| 103 else | 104 else |
| 104 return initializeProxy(SingleThreadProxy::Create(this)); | 105 return initializeProxy(SingleThreadProxy::Create(this)); |
| 105 } | 106 } |
| 106 | 107 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 m_client->didBeginFrame(); | 223 m_client->didBeginFrame(); |
| 223 } | 224 } |
| 224 | 225 |
| 225 void LayerTreeHost::updateAnimations(base::TimeTicks frameBeginTime) | 226 void LayerTreeHost::updateAnimations(base::TimeTicks frameBeginTime) |
| 226 { | 227 { |
| 227 m_animating = true; | 228 m_animating = true; |
| 228 m_client->animate((frameBeginTime - base::TimeTicks()).InSecondsF()); | 229 m_client->animate((frameBeginTime - base::TimeTicks()).InSecondsF()); |
| 229 animateLayers(frameBeginTime); | 230 animateLayers(frameBeginTime); |
| 230 m_animating = false; | 231 m_animating = false; |
| 231 | 232 |
| 232 m_renderingStats.numAnimationFrames++; | 233 m_renderingStatsRecorder->IncrementAnimationFrameCount(); |
| 233 } | 234 } |
| 234 | 235 |
| 235 void LayerTreeHost::didStopFlinging() | 236 void LayerTreeHost::didStopFlinging() |
| 236 { | 237 { |
| 237 m_proxy->MainThreadHasStoppedFlinging(); | 238 m_proxy->MainThreadHasStoppedFlinging(); |
| 238 } | 239 } |
| 239 | 240 |
| 240 void LayerTreeHost::layout() | 241 void LayerTreeHost::layout() |
| 241 { | 242 { |
| 242 m_client->layout(); | 243 m_client->layout(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 syncTree->ResetContentsTexturesPurged(); | 328 syncTree->ResetContentsTexturesPurged(); |
| 328 } | 329 } |
| 329 | 330 |
| 330 if (!m_settings.implSidePainting) { | 331 if (!m_settings.implSidePainting) { |
| 331 // If we're not in impl-side painting, the tree is immediately | 332 // If we're not in impl-side painting, the tree is immediately |
| 332 // considered active. | 333 // considered active. |
| 333 syncTree->DidBecomeActive(); | 334 syncTree->DidBecomeActive(); |
| 334 } | 335 } |
| 335 | 336 |
| 336 if (m_debugState.continuousPainting) | 337 if (m_debugState.continuousPainting) |
| 337 hostImpl->savePaintTime(m_renderingStats.totalPaintTime, commitNumber()) ; | 338 hostImpl->savePaintTime(m_renderingStatsRecorder->GetRenderingStats().to talPaintTime, commitNumber()); |
| 338 | 339 |
| 339 m_commitNumber++; | 340 m_commitNumber++; |
| 340 } | 341 } |
| 341 | 342 |
| 342 void LayerTreeHost::willCommit() | 343 void LayerTreeHost::willCommit() |
| 343 { | 344 { |
| 344 m_client->willCommit(); | 345 m_client->willCommit(); |
| 345 } | 346 } |
| 346 | 347 |
| 347 void LayerTreeHost::updateHudLayer() | 348 void LayerTreeHost::updateHudLayer() |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 369 } | 370 } |
| 370 | 371 |
| 371 scoped_ptr<InputHandler> LayerTreeHost::createInputHandler() | 372 scoped_ptr<InputHandler> LayerTreeHost::createInputHandler() |
| 372 { | 373 { |
| 373 return m_client->createInputHandler(); | 374 return m_client->createInputHandler(); |
| 374 } | 375 } |
| 375 | 376 |
| 376 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::createLayerTreeHostImpl(LayerTreeHo stImplClient* client) | 377 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::createLayerTreeHostImpl(LayerTreeHo stImplClient* client) |
| 377 { | 378 { |
| 378 DCHECK(m_proxy->IsImplThread()); | 379 DCHECK(m_proxy->IsImplThread()); |
| 379 scoped_ptr<LayerTreeHostImpl> hostImpl(LayerTreeHostImpl::create(m_settings, client, m_proxy.get())); | 380 scoped_ptr<LayerTreeHostImpl> hostImpl(LayerTreeHostImpl::create(m_settings, client, m_proxy.get(), m_renderingStatsRecorder.get())); |
| 380 if (m_settings.calculateTopControlsPosition && hostImpl->topControlsManager( )) | 381 if (m_settings.calculateTopControlsPosition && hostImpl->topControlsManager( )) |
| 381 m_topControlsManagerWeakPtr = hostImpl->topControlsManager()->AsWeakPtr( ); | 382 m_topControlsManagerWeakPtr = hostImpl->topControlsManager()->AsWeakPtr( ); |
| 382 return hostImpl.Pass(); | 383 return hostImpl.Pass(); |
| 383 } | 384 } |
| 384 | 385 |
| 385 void LayerTreeHost::didLoseOutputSurface() | 386 void LayerTreeHost::didLoseOutputSurface() |
| 386 { | 387 { |
| 387 TRACE_EVENT0("cc", "LayerTreeHost::didLoseOutputSurface"); | 388 TRACE_EVENT0("cc", "LayerTreeHost::didLoseOutputSurface"); |
| 388 DCHECK(m_proxy->IsMainThread()); | 389 DCHECK(m_proxy->IsMainThread()); |
| 389 m_outputSurfaceLost = true; | 390 m_outputSurfaceLost = true; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 411 m_proxy->SetDeferCommits(deferCommits); | 412 m_proxy->SetDeferCommits(deferCommits); |
| 412 } | 413 } |
| 413 | 414 |
| 414 void LayerTreeHost::didDeferCommit() | 415 void LayerTreeHost::didDeferCommit() |
| 415 { | 416 { |
| 416 } | 417 } |
| 417 | 418 |
| 418 void LayerTreeHost::renderingStats(RenderingStats* stats) const | 419 void LayerTreeHost::renderingStats(RenderingStats* stats) const |
| 419 { | 420 { |
| 420 CHECK(m_debugState.recordRenderingStats()); | 421 CHECK(m_debugState.recordRenderingStats()); |
| 421 *stats = m_renderingStats; | 422 *stats = m_renderingStatsRecorder->GetRenderingStats(); |
| 422 m_proxy->GetRenderingStats(stats); | 423 } |
| 424 | |
| 425 RenderingStatsRecorder* LayerTreeHost::renderingStatsRecorder() const | |
|
danakj
2013/03/13 17:25:41
rename rendering_stats_recorder()
egraether
2013/03/14 18:58:07
Done.
| |
| 426 { | |
| 427 return m_renderingStatsRecorder.get(); | |
|
danakj
2013/03/13 17:25:41
move this function to the header
egraether
2013/03/14 18:58:07
Done.
| |
| 423 } | 428 } |
| 424 | 429 |
| 425 const RendererCapabilities& LayerTreeHost::rendererCapabilities() const | 430 const RendererCapabilities& LayerTreeHost::rendererCapabilities() const |
| 426 { | 431 { |
| 427 return m_proxy->GetRendererCapabilities(); | 432 return m_proxy->GetRendererCapabilities(); |
| 428 } | 433 } |
| 429 | 434 |
| 430 void LayerTreeHost::setNeedsAnimate() | 435 void LayerTreeHost::setNeedsAnimate() |
| 431 { | 436 { |
| 432 DCHECK(m_proxy->HasImplThread()); | 437 DCHECK(m_proxy->HasImplThread()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 } | 489 } |
| 485 | 490 |
| 486 void LayerTreeHost::setDebugState(const LayerTreeDebugState& debugState) | 491 void LayerTreeHost::setDebugState(const LayerTreeDebugState& debugState) |
| 487 { | 492 { |
| 488 LayerTreeDebugState newDebugState = LayerTreeDebugState::unite(m_settings.in itialDebugState, debugState); | 493 LayerTreeDebugState newDebugState = LayerTreeDebugState::unite(m_settings.in itialDebugState, debugState); |
| 489 | 494 |
| 490 if (LayerTreeDebugState::equal(m_debugState, newDebugState)) | 495 if (LayerTreeDebugState::equal(m_debugState, newDebugState)) |
| 491 return; | 496 return; |
| 492 | 497 |
| 493 m_debugState = newDebugState; | 498 m_debugState = newDebugState; |
| 499 m_renderingStatsRecorder->set_record_rendering_stats(m_debugState.recordRend eringStats()); | |
| 494 setNeedsCommit(); | 500 setNeedsCommit(); |
| 495 } | 501 } |
| 496 | 502 |
| 497 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g fx::Size& deviceViewportSize) | 503 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g fx::Size& deviceViewportSize) |
| 498 { | 504 { |
| 499 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de viceViewportSize) | 505 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de viceViewportSize) |
| 500 return; | 506 return; |
| 501 | 507 |
| 502 m_layoutViewportSize = layoutViewportSize; | 508 m_layoutViewportSize = layoutViewportSize; |
| 503 m_deviceViewportSize = deviceViewportSize; | 509 m_deviceViewportSize = deviceViewportSize; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 continue; | 701 continue; |
| 696 | 702 |
| 697 if (bytes > maxBackgroundTextureBytes) | 703 if (bytes > maxBackgroundTextureBytes) |
| 698 maxBackgroundTextureBytes = bytes; | 704 maxBackgroundTextureBytes = bytes; |
| 699 if (!readbackBytes) | 705 if (!readbackBytes) |
| 700 readbackBytes = Resource::MemorySizeBytes(m_deviceViewportSize, GL_R GBA); | 706 readbackBytes = Resource::MemorySizeBytes(m_deviceViewportSize, GL_R GBA); |
| 701 } | 707 } |
| 702 return readbackBytes + maxBackgroundTextureBytes + contentsTextureBytes; | 708 return readbackBytes + maxBackgroundTextureBytes + contentsTextureBytes; |
| 703 } | 709 } |
| 704 | 710 |
| 705 bool LayerTreeHost::paintMasksForRenderSurface(Layer* renderSurfaceLayer, Resour ceUpdateQueue& queue) | 711 bool LayerTreeHost::paintMasksForRenderSurface(Layer* renderSurfaceLayer, Resour ceUpdateQueue& queue, RenderingStats* stats) |
| 706 { | 712 { |
| 707 // Note: Masks and replicas only exist for layers that own render surfaces. If we reach this point | 713 // Note: Masks and replicas only exist for layers that own render surfaces. If we reach this point |
| 708 // in code, we already know that at least something will be drawn into this render surface, so the | 714 // in code, we already know that at least something will be drawn into this render surface, so the |
| 709 // mask and replica should be painted. | 715 // mask and replica should be painted. |
| 710 | 716 |
| 711 RenderingStats* stats = m_debugState.recordRenderingStats() ? &m_renderingSt ats : NULL; | |
| 712 | |
| 713 bool needMoreUpdates = false; | 717 bool needMoreUpdates = false; |
| 714 Layer* maskLayer = renderSurfaceLayer->mask_layer(); | 718 Layer* maskLayer = renderSurfaceLayer->mask_layer(); |
| 715 if (maskLayer) { | 719 if (maskLayer) { |
| 716 maskLayer->Update(&queue, 0, stats); | 720 maskLayer->Update(&queue, 0, stats); |
| 717 needMoreUpdates |= maskLayer->NeedMoreUpdates(); | 721 needMoreUpdates |= maskLayer->NeedMoreUpdates(); |
| 718 } | 722 } |
| 719 | 723 |
| 720 Layer* replicaMaskLayer = renderSurfaceLayer->replica_layer() ? renderSurfac eLayer->replica_layer()->mask_layer() : 0; | 724 Layer* replicaMaskLayer = renderSurfaceLayer->replica_layer() ? renderSurfac eLayer->replica_layer()->mask_layer() : 0; |
| 721 if (replicaMaskLayer) { | 725 if (replicaMaskLayer) { |
| 722 replicaMaskLayer->Update(&queue, 0, stats); | 726 replicaMaskLayer->Update(&queue, 0, stats); |
| 723 needMoreUpdates |= replicaMaskLayer->NeedMoreUpdates(); | 727 needMoreUpdates |= replicaMaskLayer->NeedMoreUpdates(); |
| 724 } | 728 } |
| 725 return needMoreUpdates; | 729 return needMoreUpdates; |
| 726 } | 730 } |
| 727 | 731 |
| 728 bool LayerTreeHost::paintLayerContents(const LayerList& renderSurfaceLayerList, ResourceUpdateQueue& queue) | 732 bool LayerTreeHost::paintLayerContents(const LayerList& renderSurfaceLayerList, ResourceUpdateQueue& queue) |
| 729 { | 733 { |
| 730 // Use FrontToBack to allow for testing occlusion and performing culling dur ing the tree walk. | 734 // Use FrontToBack to allow for testing occlusion and performing culling dur ing the tree walk. |
| 731 typedef LayerIterator<Layer, LayerList, RenderSurface, LayerIteratorActions: :FrontToBack> LayerIteratorType; | 735 typedef LayerIterator<Layer, LayerList, RenderSurface, LayerIteratorActions: :FrontToBack> LayerIteratorType; |
| 732 | 736 |
| 733 bool needMoreUpdates = false; | 737 bool needMoreUpdates = false; |
| 734 bool recordMetricsForFrame = m_settings.showOverdrawInTracing && base::debug ::TraceLog::GetInstance() && base::debug::TraceLog::GetInstance()->IsEnabled(); | 738 bool recordMetricsForFrame = m_settings.showOverdrawInTracing && base::debug ::TraceLog::GetInstance() && base::debug::TraceLog::GetInstance()->IsEnabled(); |
| 735 OcclusionTracker occlusionTracker(m_rootLayer->render_surface()->content_rec t(), recordMetricsForFrame); | 739 OcclusionTracker occlusionTracker(m_rootLayer->render_surface()->content_rec t(), recordMetricsForFrame); |
| 736 occlusionTracker.set_minimum_tracking_size(m_settings.minimumOcclusionTracki ngSize); | 740 occlusionTracker.set_minimum_tracking_size(m_settings.minimumOcclusionTracki ngSize); |
| 737 | 741 |
| 738 prioritizeTextures(renderSurfaceLayerList, occlusionTracker.OverdrawMetrics( )); | 742 prioritizeTextures(renderSurfaceLayerList, occlusionTracker.OverdrawMetrics( )); |
| 739 | 743 |
| 740 RenderingStats* stats = m_debugState.recordRenderingStats() ? &m_renderingSt ats : NULL; | 744 // TODO: Switch Layer::update() to use RenderingStatsRecorder |
|
danakj
2013/03/13 17:25:41
stick you ldap in brackets after the TODO - ie TOD
egraether
2013/03/14 18:58:07
Done.
| |
| 745 RenderingStats stats; | |
| 746 RenderingStats* statsPtr = m_debugState.recordRenderingStats() ? &stats : NU LL; | |
| 741 | 747 |
| 742 LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList); | 748 LayerIteratorType end = LayerIteratorType::end(&renderSurfaceLayerList); |
| 743 for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList ); it != end; ++it) { | 749 for (LayerIteratorType it = LayerIteratorType::begin(&renderSurfaceLayerList ); it != end; ++it) { |
| 744 occlusionTracker.EnterLayer(it); | 750 occlusionTracker.EnterLayer(it); |
| 745 | 751 |
| 746 if (it.representsTargetRenderSurface()) { | 752 if (it.representsTargetRenderSurface()) { |
| 747 DCHECK(it->render_surface()->draw_opacity() || it->render_surface()- >draw_opacity_is_animating()); | 753 DCHECK(it->render_surface()->draw_opacity() || it->render_surface()- >draw_opacity_is_animating()); |
| 748 needMoreUpdates |= paintMasksForRenderSurface(*it, queue); | 754 needMoreUpdates |= paintMasksForRenderSurface(*it, queue, statsPtr); |
| 749 } else if (it.representsItself()) { | 755 } else if (it.representsItself()) { |
| 750 DCHECK(!it->bounds().IsEmpty()); | 756 DCHECK(!it->bounds().IsEmpty()); |
| 751 it->Update(&queue, &occlusionTracker, stats); | 757 it->Update(&queue, &occlusionTracker, statsPtr); |
| 752 needMoreUpdates |= it->NeedMoreUpdates(); | 758 needMoreUpdates |= it->NeedMoreUpdates(); |
| 753 } | 759 } |
| 754 | 760 |
| 755 occlusionTracker.LeaveLayer(it); | 761 occlusionTracker.LeaveLayer(it); |
| 756 } | 762 } |
| 757 | 763 |
| 764 m_renderingStatsRecorder->AddStats(stats); | |
| 765 | |
| 758 occlusionTracker.OverdrawMetrics().RecordMetrics(this); | 766 occlusionTracker.OverdrawMetrics().RecordMetrics(this); |
| 759 | 767 |
| 760 return needMoreUpdates; | 768 return needMoreUpdates; |
| 761 } | 769 } |
| 762 | 770 |
| 763 void LayerTreeHost::applyScrollAndScale(const ScrollAndScaleSet& info) | 771 void LayerTreeHost::applyScrollAndScale(const ScrollAndScaleSet& info) |
| 764 { | 772 { |
| 765 if (!m_rootLayer) | 773 if (!m_rootLayer) |
| 766 return; | 774 return; |
| 767 | 775 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 910 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) | 918 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) |
| 911 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); | 919 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); |
| 912 } | 920 } |
| 913 | 921 |
| 914 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() | 922 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() |
| 915 { | 923 { |
| 916 return m_proxy->CapturePicture(); | 924 return m_proxy->CapturePicture(); |
| 917 } | 925 } |
| 918 | 926 |
| 919 } // namespace cc | 927 } // namespace cc |
| OLD | NEW |