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_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" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 #include "cc/quad_culler.h" | 30 #include "cc/quad_culler.h" |
| 31 #include "cc/render_pass_draw_quad.h" | 31 #include "cc/render_pass_draw_quad.h" |
| 32 #include "cc/rendering_stats.h" | 32 #include "cc/rendering_stats.h" |
| 33 #include "cc/scrollbar_animation_controller.h" | 33 #include "cc/scrollbar_animation_controller.h" |
| 34 #include "cc/scrollbar_layer_impl.h" | 34 #include "cc/scrollbar_layer_impl.h" |
| 35 #include "cc/shared_quad_state.h" | 35 #include "cc/shared_quad_state.h" |
| 36 #include "cc/single_thread_proxy.h" | 36 #include "cc/single_thread_proxy.h" |
| 37 #include "cc/software_renderer.h" | 37 #include "cc/software_renderer.h" |
| 38 #include "cc/solid_color_draw_quad.h" | 38 #include "cc/solid_color_draw_quad.h" |
| 39 #include "cc/texture_uploader.h" | 39 #include "cc/texture_uploader.h" |
| 40 #include "cc/top_controls_manager.h" | |
| 40 #include "cc/util.h" | 41 #include "cc/util.h" |
| 41 #include "ui/gfx/size_conversions.h" | 42 #include "ui/gfx/size_conversions.h" |
| 42 #include "ui/gfx/vector2d_conversions.h" | 43 #include "ui/gfx/vector2d_conversions.h" |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| 45 | 46 |
| 46 void didVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) | 47 void didVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) |
| 47 { | 48 { |
| 48 if (visible) { | 49 if (visible) { |
| 49 TRACE_EVENT_ASYNC_BEGIN1("webkit", "LayerTreeHostImpl::setVisible", id, "LayerTreeHostImpl", id); | 50 TRACE_EVENT_ASYNC_BEGIN1("webkit", "LayerTreeHostImpl::setVisible", id, "LayerTreeHostImpl", id); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 , m_cumulativeNumLayersDrawn(0) | 229 , m_cumulativeNumLayersDrawn(0) |
| 229 , m_cumulativeNumMissingTiles(0) | 230 , m_cumulativeNumMissingTiles(0) |
| 230 , m_lastSentMemoryVisibleBytes(0) | 231 , m_lastSentMemoryVisibleBytes(0) |
| 231 , m_lastSentMemoryVisibleAndNearbyBytes(0) | 232 , m_lastSentMemoryVisibleAndNearbyBytes(0) |
| 232 , m_lastSentMemoryUseBytes(0) | 233 , m_lastSentMemoryUseBytes(0) |
| 233 , m_animationRegistrar(AnimationRegistrar::create()) | 234 , m_animationRegistrar(AnimationRegistrar::create()) |
| 234 { | 235 { |
| 235 DCHECK(m_proxy->isImplThread()); | 236 DCHECK(m_proxy->isImplThread()); |
| 236 didVisibilityChange(this, m_visible); | 237 didVisibilityChange(this, m_visible); |
| 237 | 238 |
| 239 if (settings.calculateTopControlsPosition) | |
| 240 m_topControlsManager = TopControlsManager::Create(this, settings.topCont rolsHeightPx); | |
| 241 | |
| 238 // LTHI always has an active tree. | 242 // LTHI always has an active tree. |
| 239 m_activeTree = LayerTreeImpl::create(this); | 243 m_activeTree = LayerTreeImpl::create(this); |
| 240 } | 244 } |
| 241 | 245 |
| 242 LayerTreeHostImpl::~LayerTreeHostImpl() | 246 LayerTreeHostImpl::~LayerTreeHostImpl() |
| 243 { | 247 { |
| 244 DCHECK(m_proxy->isImplThread()); | 248 DCHECK(m_proxy->isImplThread()); |
| 245 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); | 249 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); |
| 246 | 250 |
| 247 if (rootLayer()) { | 251 if (rootLayer()) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 OutputSurface* LayerTreeHostImpl::outputSurface() const | 315 OutputSurface* LayerTreeHostImpl::outputSurface() const |
| 312 { | 316 { |
| 313 return m_outputSurface.get(); | 317 return m_outputSurface.get(); |
| 314 } | 318 } |
| 315 | 319 |
| 316 void LayerTreeHostImpl::animate(base::TimeTicks monotonicTime, base::Time wallCl ockTime) | 320 void LayerTreeHostImpl::animate(base::TimeTicks monotonicTime, base::Time wallCl ockTime) |
| 317 { | 321 { |
| 318 animatePageScale(monotonicTime); | 322 animatePageScale(monotonicTime); |
| 319 animateLayers(monotonicTime, wallClockTime); | 323 animateLayers(monotonicTime, wallClockTime); |
| 320 animateScrollbars(monotonicTime); | 324 animateScrollbars(monotonicTime); |
| 325 if (m_topControlsManager) | |
| 326 m_topControlsManager->Animate(monotonicTime); | |
| 321 } | 327 } |
| 322 | 328 |
| 323 void LayerTreeHostImpl::manageTiles() | 329 void LayerTreeHostImpl::manageTiles() |
| 324 { | 330 { |
| 325 DCHECK(m_tileManager); | 331 DCHECK(m_tileManager); |
| 326 m_tileManager->ManageTiles(); | 332 m_tileManager->ManageTiles(); |
| 327 | 333 |
| 328 size_t memoryRequiredBytes; | 334 size_t memoryRequiredBytes; |
| 329 size_t memoryNiceToHaveBytes; | 335 size_t memoryNiceToHaveBytes; |
| 330 size_t memoryUsedBytes; | 336 size_t memoryUsedBytes; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 if (!needsUpdateDrawProperties()) | 417 if (!needsUpdateDrawProperties()) |
| 412 return; | 418 return; |
| 413 | 419 |
| 414 if (!m_renderer) { // For maxTextureSize. | 420 if (!m_renderer) { // For maxTextureSize. |
| 415 // This will get set if renderer gets initialized. | 421 // This will get set if renderer gets initialized. |
| 416 m_needsUpdateDrawProperties = false; | 422 m_needsUpdateDrawProperties = false; |
| 417 return; | 423 return; |
| 418 } | 424 } |
| 419 | 425 |
| 420 activeTree()->UpdateDrawProperties(); | 426 activeTree()->UpdateDrawProperties(); |
| 427 if (m_topControlsManager) | |
| 428 m_topControlsManager->UpdateDrawPositions(); | |
|
enne (OOO)
2013/01/08 06:23:05
How is this supposed to work? You update the activ
Ted C
2013/01/08 18:17:33
Why wouldn't the transforms be up to date? The la
enne (OOO)
2013/01/08 18:23:50
Because the implTransform on a layer is an input t
Ted C
2013/01/08 18:32:42
Ah ha...that certainly wasn't my intention. When
| |
| 421 if (pendingTree()) | 429 if (pendingTree()) |
| 422 pendingTree()->UpdateDrawProperties(); | 430 pendingTree()->UpdateDrawProperties(); |
| 423 | 431 |
| 424 m_needsUpdateDrawProperties = false; | 432 m_needsUpdateDrawProperties = false; |
| 425 } | 433 } |
| 426 | 434 |
| 427 void LayerTreeHostImpl::FrameData::appendRenderPass(scoped_ptr<RenderPass> rende rPass) | 435 void LayerTreeHostImpl::FrameData::appendRenderPass(scoped_ptr<RenderPass> rende rPass) |
| 428 { | 436 { |
| 429 renderPassesById[renderPass->id] = renderPass.get(); | 437 renderPassesById[renderPass->id] = renderPass.get(); |
| 430 renderPasses.append(renderPass.Pass()); | 438 renderPasses.append(renderPass.Pass()); |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 metadata.root_scroll_offset = rootScrollLayer()->scrollOffset() + rootScroll Layer()->scrollDelta(); | 873 metadata.root_scroll_offset = rootScrollLayer()->scrollOffset() + rootScroll Layer()->scrollDelta(); |
| 866 metadata.page_scale_factor = m_pinchZoomViewport.totalPageScaleFactor(); | 874 metadata.page_scale_factor = m_pinchZoomViewport.totalPageScaleFactor(); |
| 867 metadata.viewport_size = m_pinchZoomViewport.bounds().size(); | 875 metadata.viewport_size = m_pinchZoomViewport.bounds().size(); |
| 868 metadata.root_layer_size = rootScrollLayer()->bounds(); | 876 metadata.root_layer_size = rootScrollLayer()->bounds(); |
| 869 metadata.min_page_scale_factor = m_pinchZoomViewport.minPageScaleFactor(); | 877 metadata.min_page_scale_factor = m_pinchZoomViewport.minPageScaleFactor(); |
| 870 metadata.max_page_scale_factor = m_pinchZoomViewport.maxPageScaleFactor(); | 878 metadata.max_page_scale_factor = m_pinchZoomViewport.maxPageScaleFactor(); |
| 871 if (!m_settings.pageScalePinchZoomEnabled) { | 879 if (!m_settings.pageScalePinchZoomEnabled) { |
| 872 metadata.root_scroll_offset.Scale(1 / m_pinchZoomViewport.pageScaleFacto r()); | 880 metadata.root_scroll_offset.Scale(1 / m_pinchZoomViewport.pageScaleFacto r()); |
| 873 metadata.root_layer_size.Scale(1 / m_pinchZoomViewport.pageScaleFactor() ); | 881 metadata.root_layer_size.Scale(1 / m_pinchZoomViewport.pageScaleFactor() ); |
| 874 } | 882 } |
| 883 if (m_topControlsManager) { | |
| 884 metadata.location_bar_offset = gfx::Vector2dF(0.f, m_topControlsManager- >controls_top_offset()); | |
| 885 metadata.content_offset = gfx::Vector2dF(0.f, m_topControlsManager->cont ent_top_offset()); | |
| 886 } | |
| 875 | 887 |
| 876 return metadata; | 888 return metadata; |
| 877 } | 889 } |
| 878 | 890 |
| 879 void LayerTreeHostImpl::drawLayers(FrameData& frame) | 891 void LayerTreeHostImpl::drawLayers(FrameData& frame) |
| 880 { | 892 { |
| 881 TRACE_EVENT0("cc", "LayerTreeHostImpl::drawLayers"); | 893 TRACE_EVENT0("cc", "LayerTreeHostImpl::drawLayers"); |
| 882 DCHECK(canDraw()); | 894 DCHECK(canDraw()); |
| 883 DCHECK(!frame.renderPasses.isEmpty()); | 895 DCHECK(!frame.renderPasses.isEmpty()); |
| 884 | 896 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 991 | 1003 |
| 992 if (layerImpl->scrollable()) | 1004 if (layerImpl->scrollable()) |
| 993 return layerImpl; | 1005 return layerImpl; |
| 994 | 1006 |
| 995 if (layerImpl->drawsContent() && layerImpl->parent() && layerImpl->parent()- >scrollable()) | 1007 if (layerImpl->drawsContent() && layerImpl->parent() && layerImpl->parent()- >scrollable()) |
| 996 return layerImpl->parent(); | 1008 return layerImpl->parent(); |
| 997 | 1009 |
| 998 return 0; | 1010 return 0; |
| 999 } | 1011 } |
| 1000 | 1012 |
| 1013 LayerTreeImpl* LayerTreeHostImpl::activeTree() | |
| 1014 { | |
| 1015 return m_activeTree.get(); | |
| 1016 } | |
| 1017 | |
| 1001 void LayerTreeHostImpl::createPendingTree() | 1018 void LayerTreeHostImpl::createPendingTree() |
| 1002 { | 1019 { |
| 1003 CHECK(!m_pendingTree); | 1020 CHECK(!m_pendingTree); |
| 1004 m_pendingTree = LayerTreeImpl::create(this); | 1021 m_pendingTree = LayerTreeImpl::create(this); |
| 1005 m_client->onCanDrawStateChanged(canDraw()); | 1022 m_client->onCanDrawStateChanged(canDraw()); |
| 1006 m_client->onHasPendingTreeStateChanged(pendingTree()); | 1023 m_client->onHasPendingTreeStateChanged(pendingTree()); |
| 1007 } | 1024 } |
| 1008 | 1025 |
| 1009 void LayerTreeHostImpl::activatePendingTreeIfNeeded() | 1026 void LayerTreeHostImpl::activatePendingTreeIfNeeded() |
| 1010 { | 1027 { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1181 updateMaxScrollOffset(); | 1198 updateMaxScrollOffset(); |
| 1182 } | 1199 } |
| 1183 | 1200 |
| 1184 void LayerTreeHostImpl::updateMaxScrollOffset() | 1201 void LayerTreeHostImpl::updateMaxScrollOffset() |
| 1185 { | 1202 { |
| 1186 activeTree()->UpdateMaxScrollOffset(); | 1203 activeTree()->UpdateMaxScrollOffset(); |
| 1187 if (pendingTree()) | 1204 if (pendingTree()) |
| 1188 pendingTree()->UpdateMaxScrollOffset(); | 1205 pendingTree()->UpdateMaxScrollOffset(); |
| 1189 } | 1206 } |
| 1190 | 1207 |
| 1208 void LayerTreeHostImpl::setNeedsUpdateDrawProperties() | |
| 1209 { | |
| 1210 m_needsUpdateDrawProperties = true; | |
| 1211 } | |
| 1212 | |
| 1191 void LayerTreeHostImpl::setNeedsRedraw() | 1213 void LayerTreeHostImpl::setNeedsRedraw() |
| 1192 { | 1214 { |
| 1193 m_client->setNeedsRedrawOnImplThread(); | 1215 m_client->setNeedsRedrawOnImplThread(); |
| 1194 } | 1216 } |
| 1195 | 1217 |
| 1196 bool LayerTreeHostImpl::ensureRenderSurfaceLayerList() | 1218 bool LayerTreeHostImpl::ensureRenderSurfaceLayerList() |
| 1197 { | 1219 { |
| 1198 updateDrawProperties(); | 1220 updateDrawProperties(); |
| 1199 return activeTree()->RenderSurfaceLayerList().size(); | 1221 return activeTree()->RenderSurfaceLayerList().size(); |
| 1200 } | 1222 } |
| 1201 | 1223 |
| 1202 InputHandlerClient::ScrollStatus LayerTreeHostImpl::scrollBegin(gfx::Point viewp ortPoint, InputHandlerClient::ScrollInputType type) | 1224 InputHandlerClient::ScrollStatus LayerTreeHostImpl::scrollBegin(gfx::Point viewp ortPoint, InputHandlerClient::ScrollInputType type) |
| 1203 { | 1225 { |
| 1204 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBegin"); | 1226 TRACE_EVENT0("cc", "LayerTreeHostImpl::scrollBegin"); |
| 1205 | 1227 |
| 1228 if (m_topControlsManager) | |
| 1229 m_topControlsManager->ScrollBegin(); | |
| 1230 | |
| 1206 DCHECK(!currentlyScrollingLayer()); | 1231 DCHECK(!currentlyScrollingLayer()); |
| 1207 clearCurrentlyScrollingLayer(); | 1232 clearCurrentlyScrollingLayer(); |
| 1208 | 1233 |
| 1209 if (!ensureRenderSurfaceLayerList()) | 1234 if (!ensureRenderSurfaceLayerList()) |
| 1210 return ScrollIgnored; | 1235 return ScrollIgnored; |
| 1211 | 1236 |
| 1212 gfx::PointF deviceViewportPoint = gfx::ScalePoint(viewportPoint, m_deviceSca leFactor); | 1237 gfx::PointF deviceViewportPoint = gfx::ScalePoint(viewportPoint, m_deviceSca leFactor); |
| 1213 | 1238 |
| 1214 // First find out which layer was hit from the saved list of visible layers | 1239 // First find out which layer was hit from the saved list of visible layers |
| 1215 // in the most recent frame. | 1240 // in the most recent frame. |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1328 bool didScroll = false; | 1353 bool didScroll = false; |
| 1329 | 1354 |
| 1330 for (LayerImpl* layerImpl = currentlyScrollingLayer(); layerImpl; layerImpl = layerImpl->parent()) { | 1355 for (LayerImpl* layerImpl = currentlyScrollingLayer(); layerImpl; layerImpl = layerImpl->parent()) { |
| 1331 if (!layerImpl->scrollable()) | 1356 if (!layerImpl->scrollable()) |
| 1332 continue; | 1357 continue; |
| 1333 | 1358 |
| 1334 PinchZoomViewport* viewport = NULL; | 1359 PinchZoomViewport* viewport = NULL; |
| 1335 if (m_settings.pageScalePinchZoomEnabled && layerImpl == rootScrollLayer ()) | 1360 if (m_settings.pageScalePinchZoomEnabled && layerImpl == rootScrollLayer ()) |
| 1336 viewport = &m_pinchZoomViewport; | 1361 viewport = &m_pinchZoomViewport; |
| 1337 gfx::Vector2dF appliedDelta; | 1362 gfx::Vector2dF appliedDelta; |
| 1363 if (m_topControlsManager && layerImpl == rootScrollLayer()) | |
| 1364 pendingDelta = m_topControlsManager->ScrollBy(pendingDelta); | |
| 1365 | |
| 1338 if (m_scrollDeltaIsInViewportSpace) { | 1366 if (m_scrollDeltaIsInViewportSpace) { |
| 1339 float scaleFromViewportToScreenSpace = m_deviceScaleFactor; | 1367 float scaleFromViewportToScreenSpace = m_deviceScaleFactor; |
| 1340 appliedDelta = scrollLayerWithViewportSpaceDelta(viewport, *layerImp l, scaleFromViewportToScreenSpace, viewportPoint, pendingDelta); | 1368 appliedDelta = scrollLayerWithViewportSpaceDelta(viewport, *layerImp l, scaleFromViewportToScreenSpace, viewportPoint, pendingDelta); |
| 1341 } else | 1369 } else |
| 1342 appliedDelta = scrollLayerWithLocalDelta(*layerImpl, pendingDelta); | 1370 appliedDelta = scrollLayerWithLocalDelta(*layerImpl, pendingDelta); |
| 1343 | 1371 |
| 1344 // If the layer wasn't able to move, try the next one in the hierarchy. | 1372 // If the layer wasn't able to move, try the next one in the hierarchy. |
| 1345 float moveThresholdSquared = 0.1f * 0.1f; | 1373 float moveThresholdSquared = 0.1f * 0.1f; |
| 1346 if (appliedDelta.LengthSquared() < moveThresholdSquared) | 1374 if (appliedDelta.LengthSquared() < moveThresholdSquared) |
| 1347 continue; | 1375 continue; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1372 return didScroll; | 1400 return didScroll; |
| 1373 } | 1401 } |
| 1374 | 1402 |
| 1375 void LayerTreeHostImpl::clearCurrentlyScrollingLayer() | 1403 void LayerTreeHostImpl::clearCurrentlyScrollingLayer() |
| 1376 { | 1404 { |
| 1377 m_activeTree->ClearCurrentlyScrollingLayer(); | 1405 m_activeTree->ClearCurrentlyScrollingLayer(); |
| 1378 } | 1406 } |
| 1379 | 1407 |
| 1380 void LayerTreeHostImpl::scrollEnd() | 1408 void LayerTreeHostImpl::scrollEnd() |
| 1381 { | 1409 { |
| 1410 if (m_topControlsManager) | |
| 1411 m_topControlsManager->ScrollEnd(); | |
| 1382 clearCurrentlyScrollingLayer(); | 1412 clearCurrentlyScrollingLayer(); |
| 1383 } | 1413 } |
| 1384 | 1414 |
| 1385 void LayerTreeHostImpl::pinchGestureBegin() | 1415 void LayerTreeHostImpl::pinchGestureBegin() |
| 1386 { | 1416 { |
| 1387 m_pinchGestureActive = true; | 1417 m_pinchGestureActive = true; |
| 1388 m_previousPinchAnchor = gfx::Point(); | 1418 m_previousPinchAnchor = gfx::Point(); |
| 1389 | 1419 |
| 1390 if (rootScrollLayer() && rootScrollLayer()->scrollbarAnimationController()) | 1420 if (rootScrollLayer() && rootScrollLayer()->scrollbarAnimationController()) |
| 1391 rootScrollLayer()->scrollbarAnimationController()->didPinchGestureBegin( ); | 1421 rootScrollLayer()->scrollbarAnimationController()->didPinchGestureBegin( ); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1703 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController(); | 1733 ScrollbarAnimationController* scrollbarController = layer->scrollbarAnimatio nController(); |
| 1704 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); | 1734 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
| 1705 if (scrollbarController && scrollbarController->animate(monotonicTime)) | 1735 if (scrollbarController && scrollbarController->animate(monotonicTime)) |
| 1706 m_client->setNeedsRedrawOnImplThread(); | 1736 m_client->setNeedsRedrawOnImplThread(); |
| 1707 | 1737 |
| 1708 for (size_t i = 0; i < layer->children().size(); ++i) | 1738 for (size_t i = 0; i < layer->children().size(); ++i) |
| 1709 animateScrollbarsRecursive(layer->children()[i], time); | 1739 animateScrollbarsRecursive(layer->children()[i], time); |
| 1710 } | 1740 } |
| 1711 | 1741 |
| 1712 } // namespace cc | 1742 } // namespace cc |
| OLD | NEW |