| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/compositor/layer.h" | 5 #include "ui/compositor/layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "cc/base/scoped_ptr_algorithm.h" | 16 #include "cc/base/scoped_ptr_algorithm.h" |
| 17 #include "cc/layers/content_layer.h" | 17 #include "cc/layers/content_layer.h" |
| 18 #include "cc/layers/delegated_renderer_layer.h" | 18 #include "cc/layers/delegated_renderer_layer.h" |
| 19 #include "cc/layers/nine_patch_layer.h" | 19 #include "cc/layers/nine_patch_layer.h" |
| 20 #include "cc/layers/picture_layer.h" | 20 #include "cc/layers/picture_layer.h" |
| 21 #include "cc/layers/solid_color_layer.h" | 21 #include "cc/layers/solid_color_layer.h" |
| 22 #include "cc/layers/surface_layer.h" | 22 #include "cc/layers/surface_layer.h" |
| 23 #include "cc/layers/texture_layer.h" | 23 #include "cc/layers/texture_layer.h" |
| 24 #include "cc/output/copy_output_request.h" | 24 #include "cc/output/copy_output_request.h" |
| 25 #include "cc/output/delegated_frame_data.h" | 25 #include "cc/output/delegated_frame_data.h" |
| 26 #include "cc/output/filter_operation.h" | 26 #include "cc/output/filter_operation.h" |
| 27 #include "cc/output/filter_operations.h" | 27 #include "cc/output/filter_operations.h" |
| 28 #include "cc/resources/transferable_resource.h" | 28 #include "cc/resources/transferable_resource.h" |
| 29 #include "cc/trees/layer_tree_settings.h" |
| 29 #include "ui/compositor/compositor_switches.h" | 30 #include "ui/compositor/compositor_switches.h" |
| 30 #include "ui/compositor/dip_util.h" | 31 #include "ui/compositor/dip_util.h" |
| 31 #include "ui/compositor/layer_animator.h" | 32 #include "ui/compositor/layer_animator.h" |
| 32 #include "ui/compositor/paint_context.h" | 33 #include "ui/compositor/paint_context.h" |
| 33 #include "ui/gfx/animation/animation.h" | 34 #include "ui/gfx/animation/animation.h" |
| 34 #include "ui/gfx/canvas.h" | 35 #include "ui/gfx/canvas.h" |
| 35 #include "ui/gfx/display.h" | 36 #include "ui/gfx/display.h" |
| 36 #include "ui/gfx/geometry/point3_f.h" | 37 #include "ui/gfx/geometry/point3_f.h" |
| 37 #include "ui/gfx/geometry/point_conversions.h" | 38 #include "ui/gfx/geometry/point_conversions.h" |
| 38 #include "ui/gfx/geometry/size_conversions.h" | 39 #include "ui/gfx/geometry/size_conversions.h" |
| 39 #include "ui/gfx/interpolated_transform.h" | 40 #include "ui/gfx/interpolated_transform.h" |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 const ui::Layer* GetRoot(const ui::Layer* layer) { | 44 const ui::Layer* GetRoot(const ui::Layer* layer) { |
| 44 while (layer->parent()) | 45 while (layer->parent()) |
| 45 layer = layer->parent(); | 46 layer = layer->parent(); |
| 46 return layer; | 47 return layer; |
| 47 } | 48 } |
| 48 | 49 |
| 49 struct UIImplSidePaintingStatus { | 50 struct UIImplSidePaintingStatus { |
| 50 UIImplSidePaintingStatus() | 51 UIImplSidePaintingStatus() |
| 51 : enabled(ui::IsUIImplSidePaintingEnabled()) { | 52 : enabled(ui::IsUIImplSidePaintingEnabled()) { |
| 52 } | 53 } |
| 53 bool enabled; | 54 bool enabled; |
| 54 }; | 55 }; |
| 55 base::LazyInstance<UIImplSidePaintingStatus> g_ui_impl_side_painting_status = | 56 base::LazyInstance<UIImplSidePaintingStatus> g_ui_impl_side_painting_status = |
| 56 LAZY_INSTANCE_INITIALIZER; | 57 LAZY_INSTANCE_INITIALIZER; |
| 57 | 58 |
| 59 base::LazyInstance<cc::LayerSettings> g_ui_layer_settings = |
| 60 LAZY_INSTANCE_INITIALIZER; |
| 61 |
| 58 } // namespace | 62 } // namespace |
| 59 | 63 |
| 60 namespace ui { | 64 namespace ui { |
| 61 | 65 |
| 62 Layer::Layer() | 66 Layer::Layer() |
| 63 : type_(LAYER_TEXTURED), | 67 : type_(LAYER_TEXTURED), |
| 64 compositor_(NULL), | 68 compositor_(NULL), |
| 65 parent_(NULL), | 69 parent_(NULL), |
| 66 visible_(true), | 70 visible_(true), |
| 67 force_render_surface_(false), | 71 force_render_surface_(false), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 children_[i]->parent_ = NULL; | 130 children_[i]->parent_ = NULL; |
| 127 cc_layer_->RemoveLayerAnimationEventObserver(this); | 131 cc_layer_->RemoveLayerAnimationEventObserver(this); |
| 128 cc_layer_->RemoveFromParent(); | 132 cc_layer_->RemoveFromParent(); |
| 129 } | 133 } |
| 130 | 134 |
| 131 // static | 135 // static |
| 132 bool Layer::UsingPictureLayer() { | 136 bool Layer::UsingPictureLayer() { |
| 133 return g_ui_impl_side_painting_status.Get().enabled; | 137 return g_ui_impl_side_painting_status.Get().enabled; |
| 134 } | 138 } |
| 135 | 139 |
| 140 // static |
| 141 const cc::LayerSettings& Layer::UILayerSettings() { |
| 142 return g_ui_layer_settings.Get(); |
| 143 } |
| 144 |
| 145 // static |
| 146 void Layer::SetUILayerSettings(const cc::LayerSettings& settings) { |
| 147 g_ui_layer_settings.Get() = settings; |
| 148 } |
| 149 |
| 136 const Compositor* Layer::GetCompositor() const { | 150 const Compositor* Layer::GetCompositor() const { |
| 137 return GetRoot(this)->compositor_; | 151 return GetRoot(this)->compositor_; |
| 138 } | 152 } |
| 139 | 153 |
| 140 float Layer::opacity() const { | 154 float Layer::opacity() const { |
| 141 return cc_layer_->opacity(); | 155 return cc_layer_->opacity(); |
| 142 } | 156 } |
| 143 | 157 |
| 144 void Layer::SetCompositor(Compositor* compositor) { | 158 void Layer::SetCompositor(Compositor* compositor) { |
| 145 // This function must only be called to set the compositor on the root layer, | 159 // This function must only be called to set the compositor on the root layer, |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); | 529 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
| 516 cc_layer_->SetHideLayerAndSubtree(!visible_); | 530 cc_layer_->SetHideLayerAndSubtree(!visible_); |
| 517 | 531 |
| 518 SetLayerFilters(); | 532 SetLayerFilters(); |
| 519 SetLayerBackgroundFilters(); | 533 SetLayerBackgroundFilters(); |
| 520 } | 534 } |
| 521 | 535 |
| 522 void Layer::SwitchCCLayerForTest() { | 536 void Layer::SwitchCCLayerForTest() { |
| 523 scoped_refptr<cc::Layer> new_layer; | 537 scoped_refptr<cc::Layer> new_layer; |
| 524 if (Layer::UsingPictureLayer()) | 538 if (Layer::UsingPictureLayer()) |
| 525 new_layer = cc::PictureLayer::Create(this); | 539 new_layer = cc::PictureLayer::Create(UILayerSettings(), this); |
| 526 else | 540 else |
| 527 new_layer = cc::ContentLayer::Create(this); | 541 new_layer = cc::ContentLayer::Create(UILayerSettings(), this); |
| 528 SwitchToLayer(new_layer); | 542 SwitchToLayer(new_layer); |
| 529 content_layer_ = new_layer; | 543 content_layer_ = new_layer; |
| 530 } | 544 } |
| 531 | 545 |
| 532 void Layer::SetTextureMailbox( | 546 void Layer::SetTextureMailbox( |
| 533 const cc::TextureMailbox& mailbox, | 547 const cc::TextureMailbox& mailbox, |
| 534 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 548 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
| 535 gfx::Size texture_size_in_dip) { | 549 gfx::Size texture_size_in_dip) { |
| 536 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); | 550 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); |
| 537 DCHECK(mailbox.IsValid()); | 551 DCHECK(mailbox.IsValid()); |
| 538 DCHECK(release_callback); | 552 DCHECK(release_callback); |
| 539 if (!texture_layer_.get()) { | 553 if (!texture_layer_.get()) { |
| 540 scoped_refptr<cc::TextureLayer> new_layer = | 554 scoped_refptr<cc::TextureLayer> new_layer = |
| 541 cc::TextureLayer::CreateForMailbox(this); | 555 cc::TextureLayer::CreateForMailbox(UILayerSettings(), this); |
| 542 new_layer->SetFlipped(true); | 556 new_layer->SetFlipped(true); |
| 543 SwitchToLayer(new_layer); | 557 SwitchToLayer(new_layer); |
| 544 texture_layer_ = new_layer; | 558 texture_layer_ = new_layer; |
| 545 // Reset the frame_size_in_dip_ so that SetTextureSize() will not early out, | 559 // Reset the frame_size_in_dip_ so that SetTextureSize() will not early out, |
| 546 // the frame_size_in_dip_ was for a previous (different) |texture_layer_|. | 560 // the frame_size_in_dip_ was for a previous (different) |texture_layer_|. |
| 547 frame_size_in_dip_ = gfx::Size(); | 561 frame_size_in_dip_ = gfx::Size(); |
| 548 } | 562 } |
| 549 if (mailbox_release_callback_) | 563 if (mailbox_release_callback_) |
| 550 mailbox_release_callback_->Run(0, false); | 564 mailbox_release_callback_->Run(0, false); |
| 551 mailbox_release_callback_ = release_callback.Pass(); | 565 mailbox_release_callback_ = release_callback.Pass(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 570 bool Layer::TextureFlipped() const { | 584 bool Layer::TextureFlipped() const { |
| 571 DCHECK(texture_layer_.get()); | 585 DCHECK(texture_layer_.get()); |
| 572 return texture_layer_->flipped(); | 586 return texture_layer_->flipped(); |
| 573 } | 587 } |
| 574 | 588 |
| 575 void Layer::SetShowDelegatedContent(cc::DelegatedFrameProvider* frame_provider, | 589 void Layer::SetShowDelegatedContent(cc::DelegatedFrameProvider* frame_provider, |
| 576 gfx::Size frame_size_in_dip) { | 590 gfx::Size frame_size_in_dip) { |
| 577 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); | 591 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); |
| 578 | 592 |
| 579 scoped_refptr<cc::DelegatedRendererLayer> new_layer = | 593 scoped_refptr<cc::DelegatedRendererLayer> new_layer = |
| 580 cc::DelegatedRendererLayer::Create(frame_provider); | 594 cc::DelegatedRendererLayer::Create(UILayerSettings(), frame_provider); |
| 581 SwitchToLayer(new_layer); | 595 SwitchToLayer(new_layer); |
| 582 delegated_renderer_layer_ = new_layer; | 596 delegated_renderer_layer_ = new_layer; |
| 583 | 597 |
| 584 frame_size_in_dip_ = frame_size_in_dip; | 598 frame_size_in_dip_ = frame_size_in_dip; |
| 585 RecomputeDrawsContentAndUVRect(); | 599 RecomputeDrawsContentAndUVRect(); |
| 586 } | 600 } |
| 587 | 601 |
| 588 void Layer::SetShowSurface( | 602 void Layer::SetShowSurface( |
| 589 cc::SurfaceId surface_id, | 603 cc::SurfaceId surface_id, |
| 590 const cc::SurfaceLayer::SatisfyCallback& satisfy_callback, | 604 const cc::SurfaceLayer::SatisfyCallback& satisfy_callback, |
| 591 const cc::SurfaceLayer::RequireCallback& require_callback, | 605 const cc::SurfaceLayer::RequireCallback& require_callback, |
| 592 gfx::Size surface_size, | 606 gfx::Size surface_size, |
| 593 float scale, | 607 float scale, |
| 594 gfx::Size frame_size_in_dip) { | 608 gfx::Size frame_size_in_dip) { |
| 595 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); | 609 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); |
| 596 | 610 |
| 597 scoped_refptr<cc::SurfaceLayer> new_layer = | 611 scoped_refptr<cc::SurfaceLayer> new_layer = cc::SurfaceLayer::Create( |
| 598 cc::SurfaceLayer::Create(satisfy_callback, require_callback); | 612 UILayerSettings(), satisfy_callback, require_callback); |
| 599 new_layer->SetSurfaceId(surface_id, scale, surface_size); | 613 new_layer->SetSurfaceId(surface_id, scale, surface_size); |
| 600 SwitchToLayer(new_layer); | 614 SwitchToLayer(new_layer); |
| 601 surface_layer_ = new_layer; | 615 surface_layer_ = new_layer; |
| 602 | 616 |
| 603 frame_size_in_dip_ = frame_size_in_dip; | 617 frame_size_in_dip_ = frame_size_in_dip; |
| 604 RecomputeDrawsContentAndUVRect(); | 618 RecomputeDrawsContentAndUVRect(); |
| 605 } | 619 } |
| 606 | 620 |
| 607 void Layer::SetShowSolidColorContent() { | 621 void Layer::SetShowSolidColorContent() { |
| 608 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 622 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
| 609 | 623 |
| 610 if (solid_color_layer_.get()) | 624 if (solid_color_layer_.get()) |
| 611 return; | 625 return; |
| 612 | 626 |
| 613 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); | 627 scoped_refptr<cc::SolidColorLayer> new_layer = |
| 628 cc::SolidColorLayer::Create(UILayerSettings()); |
| 614 SwitchToLayer(new_layer); | 629 SwitchToLayer(new_layer); |
| 615 solid_color_layer_ = new_layer; | 630 solid_color_layer_ = new_layer; |
| 616 | 631 |
| 617 mailbox_ = cc::TextureMailbox(); | 632 mailbox_ = cc::TextureMailbox(); |
| 618 if (mailbox_release_callback_) { | 633 if (mailbox_release_callback_) { |
| 619 mailbox_release_callback_->Run(0, false); | 634 mailbox_release_callback_->Run(0, false); |
| 620 mailbox_release_callback_.reset(); | 635 mailbox_release_callback_.reset(); |
| 621 } | 636 } |
| 622 RecomputeDrawsContentAndUVRect(); | 637 RecomputeDrawsContentAndUVRect(); |
| 623 } | 638 } |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 cc_layer_->AddAnimation(pending_threaded_animations_.take(it)); | 1035 cc_layer_->AddAnimation(pending_threaded_animations_.take(it)); |
| 1021 | 1036 |
| 1022 pending_threaded_animations_.clear(); | 1037 pending_threaded_animations_.clear(); |
| 1023 | 1038 |
| 1024 for (size_t i = 0; i < children_.size(); ++i) | 1039 for (size_t i = 0; i < children_.size(); ++i) |
| 1025 children_[i]->SendPendingThreadedAnimations(); | 1040 children_[i]->SendPendingThreadedAnimations(); |
| 1026 } | 1041 } |
| 1027 | 1042 |
| 1028 void Layer::CreateCcLayer() { | 1043 void Layer::CreateCcLayer() { |
| 1029 if (type_ == LAYER_SOLID_COLOR) { | 1044 if (type_ == LAYER_SOLID_COLOR) { |
| 1030 solid_color_layer_ = cc::SolidColorLayer::Create(); | 1045 solid_color_layer_ = cc::SolidColorLayer::Create(UILayerSettings()); |
| 1031 cc_layer_ = solid_color_layer_.get(); | 1046 cc_layer_ = solid_color_layer_.get(); |
| 1032 } else if (type_ == LAYER_NINE_PATCH) { | 1047 } else if (type_ == LAYER_NINE_PATCH) { |
| 1033 nine_patch_layer_ = cc::NinePatchLayer::Create(); | 1048 nine_patch_layer_ = cc::NinePatchLayer::Create(UILayerSettings()); |
| 1034 cc_layer_ = nine_patch_layer_.get(); | 1049 cc_layer_ = nine_patch_layer_.get(); |
| 1035 } else { | 1050 } else { |
| 1036 if (Layer::UsingPictureLayer()) | 1051 if (Layer::UsingPictureLayer()) |
| 1037 content_layer_ = cc::PictureLayer::Create(this); | 1052 content_layer_ = cc::PictureLayer::Create(UILayerSettings(), this); |
| 1038 else | 1053 else |
| 1039 content_layer_ = cc::ContentLayer::Create(this); | 1054 content_layer_ = cc::ContentLayer::Create(UILayerSettings(), this); |
| 1040 cc_layer_ = content_layer_.get(); | 1055 cc_layer_ = content_layer_.get(); |
| 1041 } | 1056 } |
| 1042 cc_layer_->SetTransformOrigin(gfx::Point3F()); | 1057 cc_layer_->SetTransformOrigin(gfx::Point3F()); |
| 1043 cc_layer_->SetContentsOpaque(true); | 1058 cc_layer_->SetContentsOpaque(true); |
| 1044 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); | 1059 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
| 1045 cc_layer_->AddLayerAnimationEventObserver(this); | 1060 cc_layer_->AddLayerAnimationEventObserver(this); |
| 1046 cc_layer_->SetLayerClient(this); | 1061 cc_layer_->SetLayerClient(this); |
| 1047 RecomputePosition(); | 1062 RecomputePosition(); |
| 1048 } | 1063 } |
| 1049 | 1064 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 children_.end(), | 1108 children_.end(), |
| 1094 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), | 1109 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), |
| 1095 collection)); | 1110 collection)); |
| 1096 } | 1111 } |
| 1097 | 1112 |
| 1098 bool Layer::IsAnimating() const { | 1113 bool Layer::IsAnimating() const { |
| 1099 return animator_.get() && animator_->is_animating(); | 1114 return animator_.get() && animator_->is_animating(); |
| 1100 } | 1115 } |
| 1101 | 1116 |
| 1102 } // namespace ui | 1117 } // namespace ui |
| OLD | NEW |