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" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "cc/animation_registrar.h" | 13 #include "cc/animation_registrar.h" |
| 14 #include "cc/heads_up_display_layer.h" | 14 #include "cc/heads_up_display_layer.h" |
| 15 #include "cc/heads_up_display_layer_impl.h" | 15 #include "cc/heads_up_display_layer_impl.h" |
| 16 #include "cc/layer.h" | 16 #include "cc/layer.h" |
| 17 #include "cc/layer_animation_controller.h" | 17 #include "cc/layer_animation_controller.h" |
| 18 #include "cc/layer_iterator.h" | 18 #include "cc/layer_iterator.h" |
| 19 #include "cc/layer_tree_host_client.h" | 19 #include "cc/layer_tree_host_client.h" |
| 20 #include "cc/layer_tree_host_common.h" | 20 #include "cc/layer_tree_host_common.h" |
| 21 #include "cc/layer_tree_host_impl.h" | 21 #include "cc/layer_tree_host_impl.h" |
| 22 #include "cc/layer_tree_impl.h" | 22 #include "cc/layer_tree_impl.h" |
| 23 #include "cc/math_util.h" | 23 #include "cc/math_util.h" |
| 24 #include "cc/occlusion_tracker.h" | 24 #include "cc/occlusion_tracker.h" |
| 25 #include "cc/overdraw_metrics.h" | 25 #include "cc/overdraw_metrics.h" |
| 26 #include "cc/pinch_zoom_scrollbar.h" | |
| 27 #include "cc/pinch_zoom_scrollbar_geometry.h" | |
| 28 #include "cc/pinch_zoom_scrollbar_painter.h" | |
| 26 #include "cc/prioritized_resource_manager.h" | 29 #include "cc/prioritized_resource_manager.h" |
| 30 #include "cc/scrollbar_layer.h" | |
| 27 #include "cc/single_thread_proxy.h" | 31 #include "cc/single_thread_proxy.h" |
| 28 #include "cc/switches.h" | 32 #include "cc/switches.h" |
| 29 #include "cc/thread.h" | 33 #include "cc/thread.h" |
| 30 #include "cc/thread_proxy.h" | 34 #include "cc/thread_proxy.h" |
| 31 #include "cc/top_controls_manager.h" | 35 #include "cc/top_controls_manager.h" |
| 32 #include "cc/tree_synchronizer.h" | 36 #include "cc/tree_synchronizer.h" |
| 33 | 37 |
| 34 namespace { | 38 namespace { |
| 35 static int numLayerTreeInstances; | 39 static int numLayerTreeInstances; |
| 36 } | 40 } |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); | 323 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); |
| 320 hostImpl->setDebugState(m_debugState); | 324 hostImpl->setDebugState(m_debugState); |
| 321 | 325 |
| 322 DCHECK(!syncTree->ViewportSizeInvalid()); | 326 DCHECK(!syncTree->ViewportSizeInvalid()); |
| 323 | 327 |
| 324 if (newImplTreeHasNoEvictedResources) { | 328 if (newImplTreeHasNoEvictedResources) { |
| 325 if (syncTree->ContentsTexturesPurged()) | 329 if (syncTree->ContentsTexturesPurged()) |
| 326 syncTree->ResetContentsTexturesPurged(); | 330 syncTree->ResetContentsTexturesPurged(); |
| 327 } | 331 } |
| 328 | 332 |
| 333 syncTree->SetPinchZoomHorizontalLayerId( | |
| 334 m_pinchZoomScrollbarHorizontal ? m_pinchZoomScrollbarHorizontal->id() : -1); | |
| 335 syncTree->SetPinchZoomVerticalLayerId( | |
| 336 m_pinchZoomScrollbarVertical ? m_pinchZoomScrollbarVertical->id() : -1); | |
| 337 | |
| 329 if (!m_settings.implSidePainting) { | 338 if (!m_settings.implSidePainting) { |
| 330 // If we're not in impl-side painting, the tree is immediately | 339 // If we're not in impl-side painting, the tree is immediately |
| 331 // considered active. | 340 // considered active. |
| 332 syncTree->DidBecomeActive(); | 341 syncTree->DidBecomeActive(); |
| 333 } | 342 } |
| 334 | 343 |
| 335 if (m_debugState.continuousPainting) | 344 if (m_debugState.continuousPainting) |
| 336 hostImpl->savePaintTime(m_renderingStats.totalPaintTime, commitNumber()) ; | 345 hostImpl->savePaintTime(m_renderingStats.totalPaintTime, commitNumber()) ; |
| 337 | 346 |
| 338 m_commitNumber++; | 347 m_commitNumber++; |
| 339 } | 348 } |
| 340 | 349 |
| 350 void LayerTreeHost::setPinchZoomScrollbarsBoundsAndPosition() | |
| 351 { | |
| 352 if (!m_pinchZoomScrollbarHorizontal || !m_pinchZoomScrollbarVertical) | |
| 353 return; | |
| 354 | |
| 355 gfx::Size size = layoutViewportSize(); | |
| 356 int trackWidth = PinchZoomScrollbarGeometry::kTrackWidth; | |
| 357 | |
| 358 m_pinchZoomScrollbarHorizontal->setBounds(gfx::Size(size.width() - trackWidt h, trackWidth)); | |
| 359 m_pinchZoomScrollbarHorizontal->setPosition(gfx::PointF(0, size.height() - t rackWidth)); | |
| 360 m_pinchZoomScrollbarHorizontal->setNeedsDisplay(); | |
|
enne (OOO)
2013/03/06 19:32:58
setBounds should take care of this if anything cha
wjmaclean
2013/03/06 22:36:53
Removed.
| |
| 361 | |
| 362 m_pinchZoomScrollbarVertical->setBounds(gfx::Size(trackWidth, size.height() - trackWidth)); | |
| 363 m_pinchZoomScrollbarVertical->setPosition(gfx::PointF(size.width() - trackWi dth, 0)); | |
| 364 m_pinchZoomScrollbarVertical->setNeedsDisplay(); | |
| 365 } | |
| 366 | |
| 367 static scoped_refptr<ScrollbarLayer> CreatePinchZoomScrollbar( | |
| 368 WebKit::WebScrollbar::Orientation orientation, LayerTreeHost* owner) | |
| 369 { | |
| 370 scoped_refptr<ScrollbarLayer> scrollbarLayer = ScrollbarLayer::create( | |
| 371 make_scoped_ptr( | |
| 372 new PinchZoomScrollbar(orientation, owner)).PassAs<WebKit::WebScroll bar>(), | |
| 373 scoped_ptr<ScrollbarThemePainter>(new PinchZoomScrollbarPainter).Pass(), | |
| 374 scoped_ptr<WebKit::WebScrollbarThemeGeometry>( | |
| 375 new PinchZoomScrollbarGeometry).Pass(), | |
| 376 -1); | |
| 377 scrollbarLayer->setIsDrawable(true); | |
| 378 scrollbarLayer->setOpacity(0); | |
| 379 return scrollbarLayer; | |
| 380 } | |
| 381 | |
| 382 void LayerTreeHost::createAndAddPinchZoomScrollbars() | |
| 383 { | |
| 384 bool needsPropertiesUpdated = false; | |
| 385 | |
| 386 if (!m_pinchZoomScrollbarHorizontal) { | |
|
enne (OOO)
2013/03/06 19:32:58
It's always the case that you have both pinch zoom
wjmaclean
2013/03/06 22:36:53
If nothing is wrong, then yes, we have both or nei
| |
| 387 m_pinchZoomScrollbarHorizontal = CreatePinchZoomScrollbar(WebKit::WebScr ollbar::Horizontal, this); | |
| 388 needsPropertiesUpdated = true; | |
| 389 } | |
| 390 | |
| 391 if (!m_pinchZoomScrollbarVertical) { | |
| 392 m_pinchZoomScrollbarVertical = CreatePinchZoomScrollbar( WebKit::WebScro llbar::Vertical, this); | |
| 393 needsPropertiesUpdated = true; | |
| 394 } | |
| 395 | |
| 396 DCHECK(m_pinchZoomScrollbarHorizontal && m_pinchZoomScrollbarVertical); | |
| 397 | |
| 398 if (!m_pinchZoomScrollbarHorizontal->parent()) | |
| 399 m_rootLayer->addChild(m_pinchZoomScrollbarHorizontal); | |
| 400 | |
| 401 if (!m_pinchZoomScrollbarVertical->parent()) | |
| 402 m_rootLayer->addChild(m_pinchZoomScrollbarVertical); | |
| 403 | |
| 404 if (needsPropertiesUpdated) | |
| 405 setPinchZoomScrollbarsBoundsAndPosition(); | |
| 406 } | |
| 407 | |
| 341 void LayerTreeHost::willCommit() | 408 void LayerTreeHost::willCommit() |
| 342 { | 409 { |
| 343 m_client->willCommit(); | 410 m_client->willCommit(); |
| 344 } | 411 } |
| 345 | 412 |
| 346 void LayerTreeHost::updateHudLayer() | 413 void LayerTreeHost::updateHudLayer() |
| 347 { | 414 { |
| 348 if (m_debugState.showHudInfo()) { | 415 if (m_debugState.showHudInfo()) { |
| 349 if (!m_hudLayer) | 416 if (!m_hudLayer) |
| 350 m_hudLayer = HeadsUpDisplayLayer::create(); | 417 m_hudLayer = HeadsUpDisplayLayer::create(); |
| 351 | 418 |
| 352 if (m_rootLayer && !m_hudLayer->parent()) | 419 if (m_rootLayer && !m_hudLayer->parent()) |
| 353 m_rootLayer->addChild(m_hudLayer); | 420 m_rootLayer->addChild(m_hudLayer); |
| 354 } else if (m_hudLayer) { | 421 } else if (m_hudLayer) { |
| 355 m_hudLayer->removeFromParent(); | 422 m_hudLayer->removeFromParent(); |
| 356 m_hudLayer = 0; | 423 m_hudLayer = 0; |
| 357 } | 424 } |
| 425 | |
| 426 // Setup pinch-zoom scrollbars if required. | |
|
enne (OOO)
2013/03/06 19:32:58
This comment doesn't really add anything.
wjmaclean
2013/03/06 22:36:53
Done.
It used to mean more before the last re-fac
| |
| 427 if (m_settings.usePinchZoomScrollbars) | |
| 428 createAndAddPinchZoomScrollbars(); | |
| 358 } | 429 } |
| 359 | 430 |
| 360 void LayerTreeHost::commitComplete() | 431 void LayerTreeHost::commitComplete() |
| 361 { | 432 { |
| 362 m_client->didCommit(); | 433 m_client->didCommit(); |
| 363 } | 434 } |
| 364 | 435 |
| 365 scoped_ptr<OutputSurface> LayerTreeHost::createOutputSurface() | 436 scoped_ptr<OutputSurface> LayerTreeHost::createOutputSurface() |
| 366 { | 437 { |
| 367 return m_client->createOutputSurface(); | 438 return m_client->createOutputSurface(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 } | 565 } |
| 495 | 566 |
| 496 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g fx::Size& deviceViewportSize) | 567 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g fx::Size& deviceViewportSize) |
| 497 { | 568 { |
| 498 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de viceViewportSize) | 569 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de viceViewportSize) |
| 499 return; | 570 return; |
| 500 | 571 |
| 501 m_layoutViewportSize = layoutViewportSize; | 572 m_layoutViewportSize = layoutViewportSize; |
| 502 m_deviceViewportSize = deviceViewportSize; | 573 m_deviceViewportSize = deviceViewportSize; |
| 503 | 574 |
| 575 setPinchZoomScrollbarsBoundsAndPosition(); | |
| 504 setNeedsCommit(); | 576 setNeedsCommit(); |
| 505 } | 577 } |
| 506 | 578 |
| 507 void LayerTreeHost::setPageScaleFactorAndLimits(float pageScaleFactor, float min PageScaleFactor, float maxPageScaleFactor) | 579 void LayerTreeHost::setPageScaleFactorAndLimits(float pageScaleFactor, float min PageScaleFactor, float maxPageScaleFactor) |
| 508 { | 580 { |
| 509 if (pageScaleFactor == m_pageScaleFactor && minPageScaleFactor == m_minPageS caleFactor && maxPageScaleFactor == m_maxPageScaleFactor) | 581 if (pageScaleFactor == m_pageScaleFactor && minPageScaleFactor == m_minPageS caleFactor && maxPageScaleFactor == m_maxPageScaleFactor) |
| 510 return; | 582 return; |
| 511 | 583 |
| 512 m_pageScaleFactor = pageScaleFactor; | 584 m_pageScaleFactor = pageScaleFactor; |
| 513 m_minPageScaleFactor = minPageScaleFactor; | 585 m_minPageScaleFactor = minPageScaleFactor; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 | 659 |
| 588 for (size_t i = 0; i < layer->children().size(); ++i) { | 660 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 589 Layer* found = findFirstScrollableLayer(layer->children()[i].get()); | 661 Layer* found = findFirstScrollableLayer(layer->children()[i].get()); |
| 590 if (found) | 662 if (found) |
| 591 return found; | 663 return found; |
| 592 } | 664 } |
| 593 | 665 |
| 594 return 0; | 666 return 0; |
| 595 } | 667 } |
| 596 | 668 |
| 669 Layer* LayerTreeHost::rootScrollLayer() const | |
| 670 { | |
| 671 return findFirstScrollableLayer(m_rootLayer.get()); | |
| 672 } | |
| 673 | |
| 597 void LayerTreeHost::updateLayers(Layer* rootLayer, ResourceUpdateQueue& queue) | 674 void LayerTreeHost::updateLayers(Layer* rootLayer, ResourceUpdateQueue& queue) |
| 598 { | 675 { |
| 599 TRACE_EVENT0("cc", "LayerTreeHost::updateLayers"); | 676 TRACE_EVENT0("cc", "LayerTreeHost::updateLayers"); |
| 600 | 677 |
| 601 LayerList updateList; | 678 LayerList updateList; |
| 602 | 679 |
| 603 { | 680 { |
| 604 Layer* rootScroll = findFirstScrollableLayer(rootLayer); | 681 Layer* rootScroll = findFirstScrollableLayer(rootLayer); |
| 605 if (rootScroll) | 682 if (rootScroll) |
| 606 rootScroll->setImplTransform(m_implTransform); | 683 rootScroll->setImplTransform(m_implTransform); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 } | 957 } |
| 881 } | 958 } |
| 882 | 959 |
| 883 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve nts, Layer* layer, base::Time wallClockTime) | 960 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve nts, Layer* layer, base::Time wallClockTime) |
| 884 { | 961 { |
| 885 if (!layer) | 962 if (!layer) |
| 886 return; | 963 return; |
| 887 | 964 |
| 888 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { | 965 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { |
| 889 if (layer->id() == events[eventIndex].layerId) { | 966 if (layer->id() == events[eventIndex].layerId) { |
| 890 if (events[eventIndex].type == AnimationEvent::Started) | 967 switch (events[eventIndex].type) { |
| 968 case AnimationEvent::Started : | |
| 891 layer->notifyAnimationStarted(events[eventIndex], wallClockTime. ToDoubleT()); | 969 layer->notifyAnimationStarted(events[eventIndex], wallClockTime. ToDoubleT()); |
| 892 else | 970 break; |
| 971 case AnimationEvent::Finished : | |
| 893 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); | 972 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); |
| 973 break; | |
| 974 | |
| 975 case AnimationEvent::PropertyUpdate : | |
| 976 layer->notifyAnimationPropertyUpdate(events[eventIndex]); | |
| 977 break; | |
| 978 | |
| 979 default: | |
| 980 NOTREACHED(); | |
| 981 } | |
| 894 } | 982 } |
| 895 } | 983 } |
| 896 | 984 |
| 897 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) | 985 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) |
| 898 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); | 986 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); |
| 899 } | 987 } |
| 900 | 988 |
| 901 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() | 989 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() |
| 902 { | 990 { |
| 903 return m_proxy->capturePicture(); | 991 return m_proxy->capturePicture(); |
| 904 } | 992 } |
| 905 | 993 |
| 906 } // namespace cc | 994 } // namespace cc |
| OLD | NEW |