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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); | 325 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); |
| 322 hostImpl->setDebugState(m_debugState); | 326 hostImpl->setDebugState(m_debugState); |
| 323 | 327 |
| 324 DCHECK(!syncTree->ViewportSizeInvalid()); | 328 DCHECK(!syncTree->ViewportSizeInvalid()); |
| 325 | 329 |
| 326 if (newImplTreeHasNoEvictedResources) { | 330 if (newImplTreeHasNoEvictedResources) { |
| 327 if (syncTree->ContentsTexturesPurged()) | 331 if (syncTree->ContentsTexturesPurged()) |
| 328 syncTree->ResetContentsTexturesPurged(); | 332 syncTree->ResetContentsTexturesPurged(); |
| 329 } | 333 } |
| 330 | 334 |
| 335 syncTree->SetPinchZoomHorizontalLayerId( | |
| 336 m_pinchZoomScrollbarHorizontal ? m_pinchZoomScrollbarHorizontal->id() : 0); | |
|
jamesr
2013/02/26 20:48:46
we use -1 as an invalid id most of the time
wjmaclean
2013/03/01 15:30:32
Fixed.
| |
| 337 syncTree->SetPinchZoomVerticalLayerId( | |
| 338 m_pinchZoomScrollbarVertical ? m_pinchZoomScrollbarVertical->id() : 0); | |
| 339 | |
| 331 if (!m_settings.implSidePainting) { | 340 if (!m_settings.implSidePainting) { |
| 332 // If we're not in impl-side painting, the tree is immediately | 341 // If we're not in impl-side painting, the tree is immediately |
| 333 // considered active. | 342 // considered active. |
| 334 syncTree->DidBecomeActive(); | 343 syncTree->DidBecomeActive(); |
| 335 } | 344 } |
| 336 | 345 |
| 337 if (m_debugState.continuousPainting) | 346 if (m_debugState.continuousPainting) |
| 338 hostImpl->savePaintTime(m_renderingStats.totalPaintTime, commitNumber()) ; | 347 hostImpl->savePaintTime(m_renderingStats.totalPaintTime, commitNumber()) ; |
| 339 | 348 |
| 340 m_commitNumber++; | 349 m_commitNumber++; |
| 341 } | 350 } |
| 342 | 351 |
| 352 void LayerTreeHost::setPinchZoomScrollbarPropertiesIfNeeded() | |
| 353 { | |
| 354 if (!m_pinchZoomScrollbarHorizontal || !m_pinchZoomScrollbarVertical) | |
| 355 return; | |
| 356 | |
| 357 gfx::Size size = layoutViewportSize(); | |
| 358 int trackWidth = PinchZoomScrollbar::kTrackWidth; | |
| 359 Layer* rootScrollLayer = this->rootScrollLayer(); | |
|
jamesr
2013/02/26 20:48:46
I can't find any uses of this local in this functi
wjmaclean
2013/03/01 15:30:32
Ooops, deleted this, but must have inadvertently r
| |
| 360 | |
| 361 m_pinchZoomScrollbarHorizontal->setBounds(gfx::Size(size.width() - trackWidt h, trackWidth)); | |
| 362 m_pinchZoomScrollbarHorizontal->setPosition(gfx::PointF(0, size.height() - t rackWidth)); | |
| 363 m_pinchZoomScrollbarHorizontal->setIsDrawable(true); | |
| 364 m_pinchZoomScrollbarHorizontal->setOpacity(0.5); | |
| 365 m_pinchZoomScrollbarHorizontal->setNeedsDisplay(); | |
|
jamesr
2013/02/26 20:48:46
Most of these properties are the same every time,
wjmaclean
2013/03/01 15:30:32
Fixed.
| |
| 366 | |
| 367 m_pinchZoomScrollbarVertical->setBounds(gfx::Size(10, size.height() - 10)); | |
|
jamesr
2013/02/26 20:48:46
What are these "10"s for? Are they supposed to be
wjmaclean
2013/03/01 15:30:32
Fixed.
Trackwidth. I had them set correctly for h
| |
| 368 m_pinchZoomScrollbarVertical->setPosition(gfx::PointF(size.width() - 10, 0)) ; | |
| 369 m_pinchZoomScrollbarVertical->setIsDrawable(true); | |
| 370 m_pinchZoomScrollbarVertical->setOpacity(0.5); | |
| 371 m_pinchZoomScrollbarVertical->setNeedsDisplay(); | |
| 372 } | |
| 373 | |
| 374 static ScrollbarLayer* findScrollLayerScrollbar(Layer* layer, int targetScrollLa yerId) | |
| 375 { | |
| 376 if (layer->toScrollbarLayer()) { | |
| 377 int scrollLayerId = layer->toScrollbarLayer()->scrollLayerId(); | |
| 378 if (scrollLayerId == targetScrollLayerId) | |
| 379 return layer->toScrollbarLayer(); | |
| 380 } | |
| 381 | |
| 382 const Layer::LayerList& children = layer->children(); | |
| 383 for (size_t childIndex = 0; childIndex < children.size(); ++childIndex) { | |
| 384 ScrollbarLayer* result = | |
| 385 findScrollLayerScrollbar(children[childIndex].get(), targetScrollLay erId); | |
| 386 if (result) | |
| 387 return result; | |
| 388 } | |
| 389 | |
| 390 return 0; | |
| 391 } | |
| 392 | |
| 393 bool LayerTreeHost::rootScrollLayerUsesOverlayScrollbars() const | |
|
jamesr
2013/02/26 20:48:46
This function doesn't seem helpful. The decision
wjmaclean
2013/03/01 15:30:32
Done.
| |
| 394 { | |
| 395 // Use OS-specific defaults for the case where no rootLayer scrollbar is fou nd. | |
| 396 #if defined(OS_ANDROID) | |
| 397 bool usesOverlay = true; | |
| 398 #else | |
| 399 bool usesOverlay = false; | |
| 400 #endif | |
| 401 | |
| 402 Layer* rootScrollLayer = this->rootScrollLayer(); | |
| 403 if (!rootScrollLayer) | |
| 404 return usesOverlay; | |
| 405 | |
| 406 ScrollbarLayer* rootScrollLayerScrollbar = findScrollLayerScrollbar(m_rootLa yer.get(), rootScrollLayer->id()); | |
| 407 | |
| 408 if (rootScrollLayerScrollbar) | |
| 409 return rootScrollLayerScrollbar->isOverlay(); | |
| 410 else | |
| 411 return usesOverlay; | |
| 412 } | |
| 413 | |
| 343 void LayerTreeHost::willCommit() | 414 void LayerTreeHost::willCommit() |
| 344 { | 415 { |
| 345 m_client->willCommit(); | 416 m_client->willCommit(); |
| 346 | 417 |
| 347 if (m_debugState.showHudInfo()) { | 418 if (m_debugState.showHudInfo()) { |
| 348 if (!m_hudLayer) | 419 if (!m_hudLayer) |
| 349 m_hudLayer = HeadsUpDisplayLayer::create(); | 420 m_hudLayer = HeadsUpDisplayLayer::create(); |
| 350 | 421 |
| 351 if (m_rootLayer && !m_hudLayer->parent()) | 422 if (m_rootLayer && !m_hudLayer->parent()) |
| 352 m_rootLayer->addChild(m_hudLayer); | 423 m_rootLayer->addChild(m_hudLayer); |
| 353 } else if (m_hudLayer) { | 424 } else if (m_hudLayer) { |
| 354 m_hudLayer->removeFromParent(); | 425 m_hudLayer->removeFromParent(); |
| 355 m_hudLayer = 0; | 426 m_hudLayer = 0; |
| 356 } | 427 } |
| 428 | |
| 429 // Setup pinch-zoom scrollbars if required. | |
| 430 if (rootScrollLayer() && !rootScrollLayerUsesOverlayScrollbars()) { | |
|
jamesr
2013/02/26 20:48:46
This should check a setting to determine whether t
wjmaclean
2013/03/01 15:30:32
Done.
| |
| 431 bool needsPropertiesUpdated = false; | |
| 432 | |
| 433 if (!m_pinchZoomScrollbarHorizontal) { | |
|
jamesr
2013/02/26 20:48:46
This is way too much code to add to ::willCommit()
wjmaclean
2013/03/01 15:30:32
Done.
| |
| 434 m_pinchZoomScrollbarHorizontal = ScrollbarLayer::create( | |
| 435 make_scoped_ptr( | |
| 436 new PinchZoomScrollbar( | |
| 437 WebKit::WebScrollbar::Horizontal, this)).PassAs<WebKit:: WebScrollbar>(), | |
| 438 make_scoped_ptr(new PinchZoomScrollbarPainter).PassAs<ScrollbarT hemePainter>(), | |
| 439 make_scoped_ptr(new WebKit::PinchZoomScrollbarGeometry).PassAs<W ebKit::WebScrollbarThemeGeometry>(), | |
| 440 0); | |
| 441 needsPropertiesUpdated = true; | |
| 442 } | |
| 443 | |
| 444 DCHECK(m_pinchZoomScrollbarHorizontal); | |
| 445 if (!m_pinchZoomScrollbarHorizontal->parent()) | |
| 446 m_rootLayer->addChild(m_pinchZoomScrollbarHorizontal); | |
| 447 | |
| 448 if (!m_pinchZoomScrollbarVertical) { | |
| 449 m_pinchZoomScrollbarVertical = ScrollbarLayer::create( | |
| 450 make_scoped_ptr( | |
| 451 new PinchZoomScrollbar( | |
| 452 WebKit::WebScrollbar::Vertical, this)).PassAs<WebKit::We bScrollbar>(), | |
| 453 make_scoped_ptr(new PinchZoomScrollbarPainter).PassAs<ScrollbarT hemePainter>(), | |
| 454 make_scoped_ptr(new WebKit::PinchZoomScrollbarGeometry).PassAs<W ebKit::WebScrollbarThemeGeometry>(), | |
| 455 0); | |
| 456 needsPropertiesUpdated = true; | |
| 457 } | |
| 458 | |
| 459 DCHECK(m_pinchZoomScrollbarVertical); | |
| 460 if (!m_pinchZoomScrollbarVertical->parent()) | |
| 461 m_rootLayer->addChild(m_pinchZoomScrollbarVertical); | |
| 462 | |
| 463 if (needsPropertiesUpdated) | |
| 464 setPinchZoomScrollbarPropertiesIfNeeded(); | |
| 465 } | |
| 357 } | 466 } |
| 358 | 467 |
| 359 void LayerTreeHost::commitComplete() | 468 void LayerTreeHost::commitComplete() |
| 360 { | 469 { |
| 361 m_client->didCommit(); | 470 m_client->didCommit(); |
| 362 } | 471 } |
| 363 | 472 |
| 364 scoped_ptr<OutputSurface> LayerTreeHost::createOutputSurface() | 473 scoped_ptr<OutputSurface> LayerTreeHost::createOutputSurface() |
| 365 { | 474 { |
| 366 return m_client->createOutputSurface(); | 475 return m_client->createOutputSurface(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 } | 602 } |
| 494 | 603 |
| 495 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g fx::Size& deviceViewportSize) | 604 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g fx::Size& deviceViewportSize) |
| 496 { | 605 { |
| 497 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de viceViewportSize) | 606 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de viceViewportSize) |
| 498 return; | 607 return; |
| 499 | 608 |
| 500 m_layoutViewportSize = layoutViewportSize; | 609 m_layoutViewportSize = layoutViewportSize; |
| 501 m_deviceViewportSize = deviceViewportSize; | 610 m_deviceViewportSize = deviceViewportSize; |
| 502 | 611 |
| 612 setPinchZoomScrollbarPropertiesIfNeeded(); | |
| 503 setNeedsCommit(); | 613 setNeedsCommit(); |
| 504 } | 614 } |
| 505 | 615 |
| 506 void LayerTreeHost::setPageScaleFactorAndLimits(float pageScaleFactor, float min PageScaleFactor, float maxPageScaleFactor) | 616 void LayerTreeHost::setPageScaleFactorAndLimits(float pageScaleFactor, float min PageScaleFactor, float maxPageScaleFactor) |
| 507 { | 617 { |
| 508 if (pageScaleFactor == m_pageScaleFactor && minPageScaleFactor == m_minPageS caleFactor && maxPageScaleFactor == m_maxPageScaleFactor) | 618 if (pageScaleFactor == m_pageScaleFactor && minPageScaleFactor == m_minPageS caleFactor && maxPageScaleFactor == m_maxPageScaleFactor) |
| 509 return; | 619 return; |
| 510 | 620 |
| 511 m_pageScaleFactor = pageScaleFactor; | 621 m_pageScaleFactor = pageScaleFactor; |
| 512 m_minPageScaleFactor = minPageScaleFactor; | 622 m_minPageScaleFactor = minPageScaleFactor; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 | 696 |
| 587 for (size_t i = 0; i < layer->children().size(); ++i) { | 697 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 588 Layer* found = findFirstScrollableLayer(layer->children()[i].get()); | 698 Layer* found = findFirstScrollableLayer(layer->children()[i].get()); |
| 589 if (found) | 699 if (found) |
| 590 return found; | 700 return found; |
| 591 } | 701 } |
| 592 | 702 |
| 593 return 0; | 703 return 0; |
| 594 } | 704 } |
| 595 | 705 |
| 706 Layer* LayerTreeHost::rootScrollLayer() const | |
|
jamesr
2013/02/26 20:48:46
I think this function can completely go away
wjmaclean
2013/03/01 15:30:32
It's still used by PinchZoomScrollbar.
| |
| 707 { | |
| 708 return findFirstScrollableLayer(m_rootLayer.get()); | |
| 709 } | |
| 710 | |
| 596 void LayerTreeHost::updateLayers(Layer* rootLayer, ResourceUpdateQueue& queue) | 711 void LayerTreeHost::updateLayers(Layer* rootLayer, ResourceUpdateQueue& queue) |
| 597 { | 712 { |
| 598 TRACE_EVENT0("cc", "LayerTreeHost::updateLayers"); | 713 TRACE_EVENT0("cc", "LayerTreeHost::updateLayers"); |
| 599 | 714 |
| 600 LayerList updateList; | 715 LayerList updateList; |
| 601 | 716 |
| 602 { | 717 { |
| 603 Layer* rootScroll = findFirstScrollableLayer(rootLayer); | 718 Layer* rootScroll = findFirstScrollableLayer(rootLayer); |
| 604 if (rootScroll) | 719 if (rootScroll) |
| 605 rootScroll->setImplTransform(m_implTransform); | 720 rootScroll->setImplTransform(m_implTransform); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) | 1009 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) |
| 895 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); | 1010 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); |
| 896 } | 1011 } |
| 897 | 1012 |
| 898 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() | 1013 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() |
| 899 { | 1014 { |
| 900 return m_proxy->capturePicture(); | 1015 return m_proxy->capturePicture(); |
| 901 } | 1016 } |
| 902 | 1017 |
| 903 } // namespace cc | 1018 } // namespace cc |
| OLD | NEW |