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 s_num_layer_tree_instances; | 39 static int s_num_layer_tree_instances; |
36 } | 40 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 host_impl->SetDeviceScaleFactor(device_scale_factor_); | 325 host_impl->SetDeviceScaleFactor(device_scale_factor_); |
322 host_impl->SetDebugState(debug_state_); | 326 host_impl->SetDebugState(debug_state_); |
323 | 327 |
324 DCHECK(!sync_tree->ViewportSizeInvalid()); | 328 DCHECK(!sync_tree->ViewportSizeInvalid()); |
325 | 329 |
326 if (new_impl_tree_has_no_evicted_resources) { | 330 if (new_impl_tree_has_no_evicted_resources) { |
327 if (sync_tree->ContentsTexturesPurged()) | 331 if (sync_tree->ContentsTexturesPurged()) |
328 sync_tree->ResetContentsTexturesPurged(); | 332 sync_tree->ResetContentsTexturesPurged(); |
329 } | 333 } |
330 | 334 |
| 335 sync_tree->SetPinchZoomHorizontalLayerId( |
| 336 pinch_zoom_scrollbar_horizontal_ ? |
| 337 pinch_zoom_scrollbar_horizontal_->id() : Layer::INVALID_ID); |
| 338 |
| 339 sync_tree->SetPinchZoomVerticalLayerId( |
| 340 pinch_zoom_scrollbar_vertical_ ? |
| 341 pinch_zoom_scrollbar_vertical_->id() : Layer::INVALID_ID); |
| 342 |
331 if (!settings_.implSidePainting) { | 343 if (!settings_.implSidePainting) { |
332 // If we're not in impl-side painting, the tree is immediately | 344 // If we're not in impl-side painting, the tree is immediately |
333 // considered active. | 345 // considered active. |
334 sync_tree->DidBecomeActive(); | 346 sync_tree->DidBecomeActive(); |
335 } | 347 } |
336 | 348 |
337 if (debug_state_.continuousPainting) | 349 if (debug_state_.continuousPainting) |
338 host_impl->SavePaintTime(rendering_stats_.totalPaintTime, commit_number()); | 350 host_impl->SavePaintTime(rendering_stats_.totalPaintTime, commit_number()); |
339 | 351 |
340 commit_number_++; | 352 commit_number_++; |
341 } | 353 } |
342 | 354 |
| 355 void LayerTreeHost::SetPinchZoomScrollbarsBoundsAndPosition() |
| 356 { |
| 357 if (!pinch_zoom_scrollbar_horizontal_ || !pinch_zoom_scrollbar_vertical_) |
| 358 return; |
| 359 |
| 360 gfx::Size size = layout_viewport_size(); |
| 361 int track_width = PinchZoomScrollbarGeometry::kTrackWidth; |
| 362 |
| 363 pinch_zoom_scrollbar_horizontal_->SetBounds( |
| 364 gfx::Size(size.width() - track_width, track_width)); |
| 365 pinch_zoom_scrollbar_horizontal_->SetPosition( |
| 366 gfx::PointF(0, size.height() - track_width)); |
| 367 |
| 368 pinch_zoom_scrollbar_vertical_->SetBounds( |
| 369 gfx::Size(track_width, size.height() - track_width)); |
| 370 pinch_zoom_scrollbar_vertical_->SetPosition( |
| 371 gfx::PointF(size.width() - track_width, 0)); |
| 372 } |
| 373 |
| 374 static scoped_refptr<ScrollbarLayer> CreatePinchZoomScrollbar( |
| 375 WebKit::WebScrollbar::Orientation orientation, LayerTreeHost* owner) |
| 376 { |
| 377 scoped_refptr<ScrollbarLayer> scrollbar_layer = ScrollbarLayer::Create( |
| 378 make_scoped_ptr( |
| 379 new PinchZoomScrollbar(orientation, owner)) |
| 380 .PassAs<WebKit::WebScrollbar>(), |
| 381 scoped_ptr<ScrollbarThemePainter>(new PinchZoomScrollbarPainter).Pass(), |
| 382 scoped_ptr<WebKit::WebScrollbarThemeGeometry>( |
| 383 new PinchZoomScrollbarGeometry).Pass(), |
| 384 Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID); |
| 385 scrollbar_layer->SetIsDrawable(true); |
| 386 scrollbar_layer->SetOpacity(0.f); |
| 387 return scrollbar_layer; |
| 388 } |
| 389 |
| 390 void LayerTreeHost::CreateAndAddPinchZoomScrollbars() |
| 391 { |
| 392 bool needs_properties_updated = false; |
| 393 |
| 394 if (!pinch_zoom_scrollbar_horizontal_ || !pinch_zoom_scrollbar_vertical_) { |
| 395 pinch_zoom_scrollbar_horizontal_ = |
| 396 CreatePinchZoomScrollbar(WebKit::WebScrollbar::Horizontal, this); |
| 397 pinch_zoom_scrollbar_vertical_ = |
| 398 CreatePinchZoomScrollbar( WebKit::WebScrollbar::Vertical, this); |
| 399 needs_properties_updated = true; |
| 400 } |
| 401 |
| 402 DCHECK(pinch_zoom_scrollbar_horizontal_ && pinch_zoom_scrollbar_vertical_); |
| 403 |
| 404 if (!pinch_zoom_scrollbar_horizontal_->parent()) |
| 405 root_layer_->AddChild(pinch_zoom_scrollbar_horizontal_); |
| 406 |
| 407 if (!pinch_zoom_scrollbar_vertical_->parent()) |
| 408 root_layer_->AddChild(pinch_zoom_scrollbar_vertical_); |
| 409 |
| 410 if (needs_properties_updated) |
| 411 SetPinchZoomScrollbarsBoundsAndPosition(); |
| 412 } |
| 413 |
343 void LayerTreeHost::WillCommit() { | 414 void LayerTreeHost::WillCommit() { |
344 client_->willCommit(); | 415 client_->willCommit(); |
| 416 |
| 417 if (settings().usePinchZoomScrollbars) |
| 418 CreateAndAddPinchZoomScrollbars(); |
345 } | 419 } |
346 | 420 |
347 void LayerTreeHost::UpdateHudLayer() { | 421 void LayerTreeHost::UpdateHudLayer() { |
348 if (debug_state_.showHudInfo()) { | 422 if (debug_state_.showHudInfo()) { |
349 if (!hud_layer_) | 423 if (!hud_layer_) |
350 hud_layer_ = HeadsUpDisplayLayer::Create(); | 424 hud_layer_ = HeadsUpDisplayLayer::Create(); |
351 | 425 |
352 if (root_layer_ && !hud_layer_->parent()) | 426 if (root_layer_ && !hud_layer_->parent()) |
353 root_layer_->AddChild(hud_layer_); | 427 root_layer_->AddChild(hud_layer_); |
354 } else if (hud_layer_) { | 428 } else if (hud_layer_) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 | 537 |
464 if (root_layer_) | 538 if (root_layer_) |
465 root_layer_->SetLayerTreeHost(NULL); | 539 root_layer_->SetLayerTreeHost(NULL); |
466 root_layer_ = root_layer; | 540 root_layer_ = root_layer; |
467 if (root_layer_) | 541 if (root_layer_) |
468 root_layer_->SetLayerTreeHost(this); | 542 root_layer_->SetLayerTreeHost(this); |
469 | 543 |
470 if (hud_layer_) | 544 if (hud_layer_) |
471 hud_layer_->RemoveFromParent(); | 545 hud_layer_->RemoveFromParent(); |
472 | 546 |
| 547 if (pinch_zoom_scrollbar_horizontal_) |
| 548 pinch_zoom_scrollbar_horizontal_->RemoveFromParent(); |
| 549 |
| 550 if (pinch_zoom_scrollbar_vertical_) |
| 551 pinch_zoom_scrollbar_vertical_->RemoveFromParent(); |
| 552 |
473 SetNeedsFullTreeSync(); | 553 SetNeedsFullTreeSync(); |
474 } | 554 } |
475 | 555 |
476 void LayerTreeHost::SetDebugState(const LayerTreeDebugState& debug_state) { | 556 void LayerTreeHost::SetDebugState(const LayerTreeDebugState& debug_state) { |
477 LayerTreeDebugState new_debug_state = | 557 LayerTreeDebugState new_debug_state = |
478 LayerTreeDebugState::unite(settings_.initialDebugState, debug_state); | 558 LayerTreeDebugState::unite(settings_.initialDebugState, debug_state); |
479 | 559 |
480 if (LayerTreeDebugState::equal(debug_state_, new_debug_state)) | 560 if (LayerTreeDebugState::equal(debug_state_, new_debug_state)) |
481 return; | 561 return; |
482 | 562 |
483 debug_state_ = new_debug_state; | 563 debug_state_ = new_debug_state; |
484 SetNeedsCommit(); | 564 SetNeedsCommit(); |
485 } | 565 } |
486 | 566 |
487 void LayerTreeHost::SetViewportSize(gfx::Size layout_viewport_size, | 567 void LayerTreeHost::SetViewportSize(gfx::Size layout_viewport_size, |
488 gfx::Size device_viewport_size) { | 568 gfx::Size device_viewport_size) { |
489 if (layout_viewport_size == layout_viewport_size_ && | 569 if (layout_viewport_size == layout_viewport_size_ && |
490 device_viewport_size == device_viewport_size_) | 570 device_viewport_size == device_viewport_size_) |
491 return; | 571 return; |
492 | 572 |
493 layout_viewport_size_ = layout_viewport_size; | 573 layout_viewport_size_ = layout_viewport_size; |
494 device_viewport_size_ = device_viewport_size; | 574 device_viewport_size_ = device_viewport_size; |
495 | 575 |
| 576 SetPinchZoomScrollbarsBoundsAndPosition(); |
496 SetNeedsCommit(); | 577 SetNeedsCommit(); |
497 } | 578 } |
498 | 579 |
499 void LayerTreeHost::SetPageScaleFactorAndLimits(float page_scale_factor, | 580 void LayerTreeHost::SetPageScaleFactorAndLimits(float page_scale_factor, |
500 float min_page_scale_factor, | 581 float min_page_scale_factor, |
501 float max_page_scale_factor) { | 582 float max_page_scale_factor) { |
502 if (page_scale_factor == page_scale_factor_ && | 583 if (page_scale_factor == page_scale_factor_ && |
503 min_page_scale_factor == min_page_scale_factor_ && | 584 min_page_scale_factor == min_page_scale_factor_ && |
504 max_page_scale_factor == max_page_scale_factor_) | 585 max_page_scale_factor == max_page_scale_factor_) |
505 return; | 586 return; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 | 658 |
578 for (size_t i = 0; i < layer->children().size(); ++i) { | 659 for (size_t i = 0; i < layer->children().size(); ++i) { |
579 Layer* found = FindFirstScrollableLayer(layer->children()[i].get()); | 660 Layer* found = FindFirstScrollableLayer(layer->children()[i].get()); |
580 if (found) | 661 if (found) |
581 return found; | 662 return found; |
582 } | 663 } |
583 | 664 |
584 return NULL; | 665 return NULL; |
585 } | 666 } |
586 | 667 |
| 668 const Layer* LayerTreeHost::RootScrollLayer() const { |
| 669 return FindFirstScrollableLayer(root_layer_.get()); |
| 670 } |
| 671 |
587 void LayerTreeHost::UpdateLayers(Layer* root_layer, | 672 void LayerTreeHost::UpdateLayers(Layer* root_layer, |
588 ResourceUpdateQueue* queue) { | 673 ResourceUpdateQueue* queue) { |
589 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers"); | 674 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers"); |
590 | 675 |
591 LayerList update_list; { | 676 LayerList update_list; { |
592 Layer* root_scroll = FindFirstScrollableLayer(root_layer); | 677 Layer* root_scroll = FindFirstScrollableLayer(root_layer); |
593 if (root_scroll) | 678 if (root_scroll) |
594 root_scroll->SetImplTransform(impl_transform_); | 679 root_scroll->SetImplTransform(impl_transform_); |
595 | 680 |
596 UpdateHudLayer(); | 681 UpdateHudLayer(); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 SetAnimationEventsRecursive(events, | 1024 SetAnimationEventsRecursive(events, |
940 layer->children()[child_index].get(), | 1025 layer->children()[child_index].get(), |
941 wall_clock_time); | 1026 wall_clock_time); |
942 } | 1027 } |
943 | 1028 |
944 skia::RefPtr<SkPicture> LayerTreeHost::CapturePicture() { | 1029 skia::RefPtr<SkPicture> LayerTreeHost::CapturePicture() { |
945 return proxy_->CapturePicture(); | 1030 return proxy_->CapturePicture(); |
946 } | 1031 } |
947 | 1032 |
948 } // namespace cc | 1033 } // namespace cc |
OLD | NEW |