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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); | 324 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); |
321 hostImpl->setDebugState(m_debugState); | 325 hostImpl->setDebugState(m_debugState); |
322 | 326 |
323 DCHECK(!syncTree->ViewportSizeInvalid()); | 327 DCHECK(!syncTree->ViewportSizeInvalid()); |
324 | 328 |
325 if (newImplTreeHasNoEvictedResources) { | 329 if (newImplTreeHasNoEvictedResources) { |
326 if (syncTree->ContentsTexturesPurged()) | 330 if (syncTree->ContentsTexturesPurged()) |
327 syncTree->ResetContentsTexturesPurged(); | 331 syncTree->ResetContentsTexturesPurged(); |
328 } | 332 } |
329 | 333 |
| 334 syncTree->SetPinchZoomHorizontalLayerId( |
| 335 m_pinchZoomScrollbarHorizontal ? m_pinchZoomScrollbarHorizontal->id() : |
| 336 Layer::INVALID_ID); |
| 337 syncTree->SetPinchZoomVerticalLayerId( |
| 338 m_pinchZoomScrollbarVertical ? m_pinchZoomScrollbarVertical->id() : |
| 339 Layer::INVALID_ID); |
| 340 |
330 if (!m_settings.implSidePainting) { | 341 if (!m_settings.implSidePainting) { |
331 // If we're not in impl-side painting, the tree is immediately | 342 // If we're not in impl-side painting, the tree is immediately |
332 // considered active. | 343 // considered active. |
333 syncTree->DidBecomeActive(); | 344 syncTree->DidBecomeActive(); |
334 } | 345 } |
335 | 346 |
336 if (m_debugState.continuousPainting) | 347 if (m_debugState.continuousPainting) |
337 hostImpl->savePaintTime(m_renderingStats.totalPaintTime, commitNumber())
; | 348 hostImpl->savePaintTime(m_renderingStats.totalPaintTime, commitNumber())
; |
338 | 349 |
339 m_commitNumber++; | 350 m_commitNumber++; |
340 } | 351 } |
341 | 352 |
| 353 void LayerTreeHost::setPinchZoomScrollbarsBoundsAndPosition() |
| 354 { |
| 355 if (!m_pinchZoomScrollbarHorizontal || !m_pinchZoomScrollbarVertical) |
| 356 return; |
| 357 |
| 358 gfx::Size size = layoutViewportSize(); |
| 359 int trackWidth = PinchZoomScrollbarGeometry::kTrackWidth; |
| 360 |
| 361 m_pinchZoomScrollbarHorizontal->SetBounds(gfx::Size(size.width() - trackWidt
h, trackWidth)); |
| 362 m_pinchZoomScrollbarHorizontal->SetPosition(gfx::PointF(0, size.height() - t
rackWidth)); |
| 363 |
| 364 m_pinchZoomScrollbarVertical->SetBounds(gfx::Size(trackWidth, size.height()
- trackWidth)); |
| 365 m_pinchZoomScrollbarVertical->SetPosition(gfx::PointF(size.width() - trackWi
dth, 0)); |
| 366 } |
| 367 |
| 368 static scoped_refptr<ScrollbarLayer> CreatePinchZoomScrollbar( |
| 369 WebKit::WebScrollbar::Orientation orientation, LayerTreeHost* owner) |
| 370 { |
| 371 scoped_refptr<ScrollbarLayer> scrollbarLayer = ScrollbarLayer::Create( |
| 372 make_scoped_ptr( |
| 373 new PinchZoomScrollbar(orientation, owner)).PassAs<WebKit::WebScroll
bar>(), |
| 374 scoped_ptr<ScrollbarThemePainter>(new PinchZoomScrollbarPainter).Pass(), |
| 375 scoped_ptr<WebKit::WebScrollbarThemeGeometry>( |
| 376 new PinchZoomScrollbarGeometry).Pass(), |
| 377 Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID); |
| 378 scrollbarLayer->SetIsDrawable(true); |
| 379 scrollbarLayer->SetOpacity(0.f); |
| 380 return scrollbarLayer; |
| 381 } |
| 382 |
| 383 void LayerTreeHost::createAndAddPinchZoomScrollbars() |
| 384 { |
| 385 bool needsPropertiesUpdated = false; |
| 386 |
| 387 if (!m_pinchZoomScrollbarHorizontal || !m_pinchZoomScrollbarVertical) { |
| 388 m_pinchZoomScrollbarHorizontal = CreatePinchZoomScrollbar(WebKit::WebScr
ollbar::Horizontal, this); |
| 389 m_pinchZoomScrollbarVertical = CreatePinchZoomScrollbar( WebKit::WebScro
llbar::Vertical, this); |
| 390 needsPropertiesUpdated = true; |
| 391 } |
| 392 |
| 393 DCHECK(m_pinchZoomScrollbarHorizontal && m_pinchZoomScrollbarVertical); |
| 394 |
| 395 if (!m_pinchZoomScrollbarHorizontal->parent()) |
| 396 m_rootLayer->AddChild(m_pinchZoomScrollbarHorizontal); |
| 397 |
| 398 if (!m_pinchZoomScrollbarVertical->parent()) |
| 399 m_rootLayer->AddChild(m_pinchZoomScrollbarVertical); |
| 400 |
| 401 if (needsPropertiesUpdated) |
| 402 setPinchZoomScrollbarsBoundsAndPosition(); |
| 403 } |
| 404 |
342 void LayerTreeHost::willCommit() | 405 void LayerTreeHost::willCommit() |
343 { | 406 { |
344 m_client->willCommit(); | 407 m_client->willCommit(); |
| 408 |
| 409 if (m_settings.usePinchZoomScrollbars) |
| 410 createAndAddPinchZoomScrollbars(); |
345 } | 411 } |
346 | 412 |
347 void LayerTreeHost::updateHudLayer() | 413 void LayerTreeHost::updateHudLayer() |
348 { | 414 { |
349 if (m_debugState.showHudInfo()) { | 415 if (m_debugState.showHudInfo()) { |
350 if (!m_hudLayer) | 416 if (!m_hudLayer) |
351 m_hudLayer = HeadsUpDisplayLayer::Create(); | 417 m_hudLayer = HeadsUpDisplayLayer::Create(); |
352 | 418 |
353 if (m_rootLayer && !m_hudLayer->parent()) | 419 if (m_rootLayer && !m_hudLayer->parent()) |
354 m_rootLayer->AddChild(m_hudLayer); | 420 m_rootLayer->AddChild(m_hudLayer); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 539 |
474 if (m_rootLayer) | 540 if (m_rootLayer) |
475 m_rootLayer->SetLayerTreeHost(0); | 541 m_rootLayer->SetLayerTreeHost(0); |
476 m_rootLayer = rootLayer; | 542 m_rootLayer = rootLayer; |
477 if (m_rootLayer) | 543 if (m_rootLayer) |
478 m_rootLayer->SetLayerTreeHost(this); | 544 m_rootLayer->SetLayerTreeHost(this); |
479 | 545 |
480 if (m_hudLayer) | 546 if (m_hudLayer) |
481 m_hudLayer->RemoveFromParent(); | 547 m_hudLayer->RemoveFromParent(); |
482 | 548 |
| 549 if (m_pinchZoomScrollbarHorizontal) |
| 550 m_pinchZoomScrollbarHorizontal->RemoveFromParent(); |
| 551 |
| 552 if (m_pinchZoomScrollbarVertical) |
| 553 m_pinchZoomScrollbarVertical->RemoveFromParent(); |
| 554 |
483 setNeedsFullTreeSync(); | 555 setNeedsFullTreeSync(); |
484 } | 556 } |
485 | 557 |
486 void LayerTreeHost::setDebugState(const LayerTreeDebugState& debugState) | 558 void LayerTreeHost::setDebugState(const LayerTreeDebugState& debugState) |
487 { | 559 { |
488 LayerTreeDebugState newDebugState = LayerTreeDebugState::unite(m_settings.in
itialDebugState, debugState); | 560 LayerTreeDebugState newDebugState = LayerTreeDebugState::unite(m_settings.in
itialDebugState, debugState); |
489 | 561 |
490 if (LayerTreeDebugState::equal(m_debugState, newDebugState)) | 562 if (LayerTreeDebugState::equal(m_debugState, newDebugState)) |
491 return; | 563 return; |
492 | 564 |
493 m_debugState = newDebugState; | 565 m_debugState = newDebugState; |
494 setNeedsCommit(); | 566 setNeedsCommit(); |
495 } | 567 } |
496 | 568 |
497 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g
fx::Size& deviceViewportSize) | 569 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g
fx::Size& deviceViewportSize) |
498 { | 570 { |
499 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de
viceViewportSize) | 571 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de
viceViewportSize) |
500 return; | 572 return; |
501 | 573 |
502 m_layoutViewportSize = layoutViewportSize; | 574 m_layoutViewportSize = layoutViewportSize; |
503 m_deviceViewportSize = deviceViewportSize; | 575 m_deviceViewportSize = deviceViewportSize; |
504 | 576 |
| 577 setPinchZoomScrollbarsBoundsAndPosition(); |
505 setNeedsCommit(); | 578 setNeedsCommit(); |
506 } | 579 } |
507 | 580 |
508 void LayerTreeHost::setPageScaleFactorAndLimits(float pageScaleFactor, float min
PageScaleFactor, float maxPageScaleFactor) | 581 void LayerTreeHost::setPageScaleFactorAndLimits(float pageScaleFactor, float min
PageScaleFactor, float maxPageScaleFactor) |
509 { | 582 { |
510 if (pageScaleFactor == m_pageScaleFactor && minPageScaleFactor == m_minPageS
caleFactor && maxPageScaleFactor == m_maxPageScaleFactor) | 583 if (pageScaleFactor == m_pageScaleFactor && minPageScaleFactor == m_minPageS
caleFactor && maxPageScaleFactor == m_maxPageScaleFactor) |
511 return; | 584 return; |
512 | 585 |
513 m_pageScaleFactor = pageScaleFactor; | 586 m_pageScaleFactor = pageScaleFactor; |
514 m_minPageScaleFactor = minPageScaleFactor; | 587 m_minPageScaleFactor = minPageScaleFactor; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 | 661 |
589 for (size_t i = 0; i < layer->children().size(); ++i) { | 662 for (size_t i = 0; i < layer->children().size(); ++i) { |
590 Layer* found = findFirstScrollableLayer(layer->children()[i].get()); | 663 Layer* found = findFirstScrollableLayer(layer->children()[i].get()); |
591 if (found) | 664 if (found) |
592 return found; | 665 return found; |
593 } | 666 } |
594 | 667 |
595 return 0; | 668 return 0; |
596 } | 669 } |
597 | 670 |
| 671 const Layer* LayerTreeHost::rootScrollLayer() const |
| 672 { |
| 673 return findFirstScrollableLayer(m_rootLayer.get()); |
| 674 } |
| 675 |
598 void LayerTreeHost::updateLayers(Layer* rootLayer, ResourceUpdateQueue& queue) | 676 void LayerTreeHost::updateLayers(Layer* rootLayer, ResourceUpdateQueue& queue) |
599 { | 677 { |
600 TRACE_EVENT0("cc", "LayerTreeHost::updateLayers"); | 678 TRACE_EVENT0("cc", "LayerTreeHost::updateLayers"); |
601 | 679 |
602 LayerList updateList; | 680 LayerList updateList; |
603 | 681 |
604 { | 682 { |
605 Layer* rootScroll = findFirstScrollableLayer(rootLayer); | 683 Layer* rootScroll = findFirstScrollableLayer(rootLayer); |
606 if (rootScroll) | 684 if (rootScroll) |
607 rootScroll->SetImplTransform(m_implTransform); | 685 rootScroll->SetImplTransform(m_implTransform); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn
dex) | 988 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn
dex) |
911 setAnimationEventsRecursive(events, layer->children()[childIndex].get(),
wallClockTime); | 989 setAnimationEventsRecursive(events, layer->children()[childIndex].get(),
wallClockTime); |
912 } | 990 } |
913 | 991 |
914 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() | 992 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() |
915 { | 993 { |
916 return m_proxy->CapturePicture(); | 994 return m_proxy->CapturePicture(); |
917 } | 995 } |
918 | 996 |
919 } // namespace cc | 997 } // namespace cc |
OLD | NEW |