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::NOTUSED_ID); |
| 378 scrollbarLayer->SetIsDrawable(true); |
| 379 scrollbarLayer->SetOpacity(0); |
| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 } | 561 } |
496 | 562 |
497 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g
fx::Size& deviceViewportSize) | 563 void LayerTreeHost::setViewportSize(const gfx::Size& layoutViewportSize, const g
fx::Size& deviceViewportSize) |
498 { | 564 { |
499 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de
viceViewportSize) | 565 if (layoutViewportSize == m_layoutViewportSize && deviceViewportSize == m_de
viceViewportSize) |
500 return; | 566 return; |
501 | 567 |
502 m_layoutViewportSize = layoutViewportSize; | 568 m_layoutViewportSize = layoutViewportSize; |
503 m_deviceViewportSize = deviceViewportSize; | 569 m_deviceViewportSize = deviceViewportSize; |
504 | 570 |
| 571 setPinchZoomScrollbarsBoundsAndPosition(); |
505 setNeedsCommit(); | 572 setNeedsCommit(); |
506 } | 573 } |
507 | 574 |
508 void LayerTreeHost::setPageScaleFactorAndLimits(float pageScaleFactor, float min
PageScaleFactor, float maxPageScaleFactor) | 575 void LayerTreeHost::setPageScaleFactorAndLimits(float pageScaleFactor, float min
PageScaleFactor, float maxPageScaleFactor) |
509 { | 576 { |
510 if (pageScaleFactor == m_pageScaleFactor && minPageScaleFactor == m_minPageS
caleFactor && maxPageScaleFactor == m_maxPageScaleFactor) | 577 if (pageScaleFactor == m_pageScaleFactor && minPageScaleFactor == m_minPageS
caleFactor && maxPageScaleFactor == m_maxPageScaleFactor) |
511 return; | 578 return; |
512 | 579 |
513 m_pageScaleFactor = pageScaleFactor; | 580 m_pageScaleFactor = pageScaleFactor; |
514 m_minPageScaleFactor = minPageScaleFactor; | 581 m_minPageScaleFactor = minPageScaleFactor; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 | 655 |
589 for (size_t i = 0; i < layer->children().size(); ++i) { | 656 for (size_t i = 0; i < layer->children().size(); ++i) { |
590 Layer* found = findFirstScrollableLayer(layer->children()[i].get()); | 657 Layer* found = findFirstScrollableLayer(layer->children()[i].get()); |
591 if (found) | 658 if (found) |
592 return found; | 659 return found; |
593 } | 660 } |
594 | 661 |
595 return 0; | 662 return 0; |
596 } | 663 } |
597 | 664 |
| 665 const Layer* LayerTreeHost::rootScrollLayer() const |
| 666 { |
| 667 return findFirstScrollableLayer(m_rootLayer.get()); |
| 668 } |
| 669 |
598 void LayerTreeHost::updateLayers(Layer* rootLayer, ResourceUpdateQueue& queue) | 670 void LayerTreeHost::updateLayers(Layer* rootLayer, ResourceUpdateQueue& queue) |
599 { | 671 { |
600 TRACE_EVENT0("cc", "LayerTreeHost::updateLayers"); | 672 TRACE_EVENT0("cc", "LayerTreeHost::updateLayers"); |
601 | 673 |
602 LayerList updateList; | 674 LayerList updateList; |
603 | 675 |
604 { | 676 { |
605 Layer* rootScroll = findFirstScrollableLayer(rootLayer); | 677 Layer* rootScroll = findFirstScrollableLayer(rootLayer); |
606 if (rootScroll) | 678 if (rootScroll) |
607 rootScroll->SetImplTransform(m_implTransform); | 679 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) | 982 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn
dex) |
911 setAnimationEventsRecursive(events, layer->children()[childIndex].get(),
wallClockTime); | 983 setAnimationEventsRecursive(events, layer->children()[childIndex].get(),
wallClockTime); |
912 } | 984 } |
913 | 985 |
914 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() | 986 skia::RefPtr<SkPicture> LayerTreeHost::capturePicture() |
915 { | 987 { |
916 return m_proxy->CapturePicture(); | 988 return m_proxy->CapturePicture(); |
917 } | 989 } |
918 | 990 |
919 } // namespace cc | 991 } // namespace cc |
OLD | NEW |