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::InitializeUILayerSettings() { |
| 147 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 148 if (command_line->HasSwitch(switches::kUIEnableCompositorAnimationTimelines)) |
| 149 g_ui_layer_settings.Get().use_compositor_animation_timelines = true; |
| 150 } |
| 151 |
136 const Compositor* Layer::GetCompositor() const { | 152 const Compositor* Layer::GetCompositor() const { |
137 return GetRoot(this)->compositor_; | 153 return GetRoot(this)->compositor_; |
138 } | 154 } |
139 | 155 |
140 float Layer::opacity() const { | 156 float Layer::opacity() const { |
141 return cc_layer_->opacity(); | 157 return cc_layer_->opacity(); |
142 } | 158 } |
143 | 159 |
144 void Layer::SetCompositor(Compositor* compositor) { | 160 void Layer::SetCompositor(Compositor* compositor) { |
145 // This function must only be called to set the compositor on the root layer, | 161 // 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); | 531 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
516 cc_layer_->SetHideLayerAndSubtree(!visible_); | 532 cc_layer_->SetHideLayerAndSubtree(!visible_); |
517 | 533 |
518 SetLayerFilters(); | 534 SetLayerFilters(); |
519 SetLayerBackgroundFilters(); | 535 SetLayerBackgroundFilters(); |
520 } | 536 } |
521 | 537 |
522 void Layer::SwitchCCLayerForTest() { | 538 void Layer::SwitchCCLayerForTest() { |
523 scoped_refptr<cc::Layer> new_layer; | 539 scoped_refptr<cc::Layer> new_layer; |
524 if (Layer::UsingPictureLayer()) | 540 if (Layer::UsingPictureLayer()) |
525 new_layer = cc::PictureLayer::Create(this); | 541 new_layer = cc::PictureLayer::Create(UILayerSettings(), this); |
526 else | 542 else |
527 new_layer = cc::ContentLayer::Create(this); | 543 new_layer = cc::ContentLayer::Create(UILayerSettings(), this); |
528 SwitchToLayer(new_layer); | 544 SwitchToLayer(new_layer); |
529 content_layer_ = new_layer; | 545 content_layer_ = new_layer; |
530 } | 546 } |
531 | 547 |
532 void Layer::SetTextureMailbox( | 548 void Layer::SetTextureMailbox( |
533 const cc::TextureMailbox& mailbox, | 549 const cc::TextureMailbox& mailbox, |
534 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 550 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
535 gfx::Size texture_size_in_dip) { | 551 gfx::Size texture_size_in_dip) { |
536 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); | 552 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); |
537 DCHECK(mailbox.IsValid()); | 553 DCHECK(mailbox.IsValid()); |
538 DCHECK(release_callback); | 554 DCHECK(release_callback); |
539 if (!texture_layer_.get()) { | 555 if (!texture_layer_.get()) { |
540 scoped_refptr<cc::TextureLayer> new_layer = | 556 scoped_refptr<cc::TextureLayer> new_layer = |
541 cc::TextureLayer::CreateForMailbox(this); | 557 cc::TextureLayer::CreateForMailbox(UILayerSettings(), this); |
542 new_layer->SetFlipped(true); | 558 new_layer->SetFlipped(true); |
543 SwitchToLayer(new_layer); | 559 SwitchToLayer(new_layer); |
544 texture_layer_ = new_layer; | 560 texture_layer_ = new_layer; |
545 // Reset the frame_size_in_dip_ so that SetTextureSize() will not early out, | 561 // 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_|. | 562 // the frame_size_in_dip_ was for a previous (different) |texture_layer_|. |
547 frame_size_in_dip_ = gfx::Size(); | 563 frame_size_in_dip_ = gfx::Size(); |
548 } | 564 } |
549 if (mailbox_release_callback_) | 565 if (mailbox_release_callback_) |
550 mailbox_release_callback_->Run(0, false); | 566 mailbox_release_callback_->Run(0, false); |
551 mailbox_release_callback_ = release_callback.Pass(); | 567 mailbox_release_callback_ = release_callback.Pass(); |
(...skipping 18 matching lines...) Expand all Loading... |
570 bool Layer::TextureFlipped() const { | 586 bool Layer::TextureFlipped() const { |
571 DCHECK(texture_layer_.get()); | 587 DCHECK(texture_layer_.get()); |
572 return texture_layer_->flipped(); | 588 return texture_layer_->flipped(); |
573 } | 589 } |
574 | 590 |
575 void Layer::SetShowDelegatedContent(cc::DelegatedFrameProvider* frame_provider, | 591 void Layer::SetShowDelegatedContent(cc::DelegatedFrameProvider* frame_provider, |
576 gfx::Size frame_size_in_dip) { | 592 gfx::Size frame_size_in_dip) { |
577 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); | 593 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); |
578 | 594 |
579 scoped_refptr<cc::DelegatedRendererLayer> new_layer = | 595 scoped_refptr<cc::DelegatedRendererLayer> new_layer = |
580 cc::DelegatedRendererLayer::Create(frame_provider); | 596 cc::DelegatedRendererLayer::Create(UILayerSettings(), frame_provider); |
581 SwitchToLayer(new_layer); | 597 SwitchToLayer(new_layer); |
582 delegated_renderer_layer_ = new_layer; | 598 delegated_renderer_layer_ = new_layer; |
583 | 599 |
584 frame_size_in_dip_ = frame_size_in_dip; | 600 frame_size_in_dip_ = frame_size_in_dip; |
585 RecomputeDrawsContentAndUVRect(); | 601 RecomputeDrawsContentAndUVRect(); |
586 } | 602 } |
587 | 603 |
588 void Layer::SetShowSurface( | 604 void Layer::SetShowSurface( |
589 cc::SurfaceId surface_id, | 605 cc::SurfaceId surface_id, |
590 const cc::SurfaceLayer::SatisfyCallback& satisfy_callback, | 606 const cc::SurfaceLayer::SatisfyCallback& satisfy_callback, |
591 const cc::SurfaceLayer::RequireCallback& require_callback, | 607 const cc::SurfaceLayer::RequireCallback& require_callback, |
592 gfx::Size surface_size, | 608 gfx::Size surface_size, |
593 float scale, | 609 float scale, |
594 gfx::Size frame_size_in_dip) { | 610 gfx::Size frame_size_in_dip) { |
595 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); | 611 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); |
596 | 612 |
597 scoped_refptr<cc::SurfaceLayer> new_layer = | 613 scoped_refptr<cc::SurfaceLayer> new_layer = cc::SurfaceLayer::Create( |
598 cc::SurfaceLayer::Create(satisfy_callback, require_callback); | 614 UILayerSettings(), satisfy_callback, require_callback); |
599 new_layer->SetSurfaceId(surface_id, scale, surface_size); | 615 new_layer->SetSurfaceId(surface_id, scale, surface_size); |
600 SwitchToLayer(new_layer); | 616 SwitchToLayer(new_layer); |
601 surface_layer_ = new_layer; | 617 surface_layer_ = new_layer; |
602 | 618 |
603 frame_size_in_dip_ = frame_size_in_dip; | 619 frame_size_in_dip_ = frame_size_in_dip; |
604 RecomputeDrawsContentAndUVRect(); | 620 RecomputeDrawsContentAndUVRect(); |
605 } | 621 } |
606 | 622 |
607 void Layer::SetShowSolidColorContent() { | 623 void Layer::SetShowSolidColorContent() { |
608 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 624 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
609 | 625 |
610 if (solid_color_layer_.get()) | 626 if (solid_color_layer_.get()) |
611 return; | 627 return; |
612 | 628 |
613 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); | 629 scoped_refptr<cc::SolidColorLayer> new_layer = |
| 630 cc::SolidColorLayer::Create(UILayerSettings()); |
614 SwitchToLayer(new_layer); | 631 SwitchToLayer(new_layer); |
615 solid_color_layer_ = new_layer; | 632 solid_color_layer_ = new_layer; |
616 | 633 |
617 mailbox_ = cc::TextureMailbox(); | 634 mailbox_ = cc::TextureMailbox(); |
618 if (mailbox_release_callback_) { | 635 if (mailbox_release_callback_) { |
619 mailbox_release_callback_->Run(0, false); | 636 mailbox_release_callback_->Run(0, false); |
620 mailbox_release_callback_.reset(); | 637 mailbox_release_callback_.reset(); |
621 } | 638 } |
622 RecomputeDrawsContentAndUVRect(); | 639 RecomputeDrawsContentAndUVRect(); |
623 } | 640 } |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 cc_layer_->AddAnimation(pending_threaded_animations_.take(it)); | 1039 cc_layer_->AddAnimation(pending_threaded_animations_.take(it)); |
1023 | 1040 |
1024 pending_threaded_animations_.clear(); | 1041 pending_threaded_animations_.clear(); |
1025 | 1042 |
1026 for (size_t i = 0; i < children_.size(); ++i) | 1043 for (size_t i = 0; i < children_.size(); ++i) |
1027 children_[i]->SendPendingThreadedAnimations(); | 1044 children_[i]->SendPendingThreadedAnimations(); |
1028 } | 1045 } |
1029 | 1046 |
1030 void Layer::CreateCcLayer() { | 1047 void Layer::CreateCcLayer() { |
1031 if (type_ == LAYER_SOLID_COLOR) { | 1048 if (type_ == LAYER_SOLID_COLOR) { |
1032 solid_color_layer_ = cc::SolidColorLayer::Create(); | 1049 solid_color_layer_ = cc::SolidColorLayer::Create(UILayerSettings()); |
1033 cc_layer_ = solid_color_layer_.get(); | 1050 cc_layer_ = solid_color_layer_.get(); |
1034 } else if (type_ == LAYER_NINE_PATCH) { | 1051 } else if (type_ == LAYER_NINE_PATCH) { |
1035 nine_patch_layer_ = cc::NinePatchLayer::Create(); | 1052 nine_patch_layer_ = cc::NinePatchLayer::Create(UILayerSettings()); |
1036 cc_layer_ = nine_patch_layer_.get(); | 1053 cc_layer_ = nine_patch_layer_.get(); |
1037 } else { | 1054 } else { |
1038 if (Layer::UsingPictureLayer()) | 1055 if (Layer::UsingPictureLayer()) |
1039 content_layer_ = cc::PictureLayer::Create(this); | 1056 content_layer_ = cc::PictureLayer::Create(UILayerSettings(), this); |
1040 else | 1057 else |
1041 content_layer_ = cc::ContentLayer::Create(this); | 1058 content_layer_ = cc::ContentLayer::Create(UILayerSettings(), this); |
1042 cc_layer_ = content_layer_.get(); | 1059 cc_layer_ = content_layer_.get(); |
1043 } | 1060 } |
1044 cc_layer_->SetTransformOrigin(gfx::Point3F()); | 1061 cc_layer_->SetTransformOrigin(gfx::Point3F()); |
1045 cc_layer_->SetContentsOpaque(true); | 1062 cc_layer_->SetContentsOpaque(true); |
1046 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); | 1063 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); |
1047 cc_layer_->AddLayerAnimationEventObserver(this); | 1064 cc_layer_->AddLayerAnimationEventObserver(this); |
1048 cc_layer_->SetLayerClient(this); | 1065 cc_layer_->SetLayerClient(this); |
1049 RecomputePosition(); | 1066 RecomputePosition(); |
1050 } | 1067 } |
1051 | 1068 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 children_.end(), | 1112 children_.end(), |
1096 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), | 1113 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), |
1097 collection)); | 1114 collection)); |
1098 } | 1115 } |
1099 | 1116 |
1100 bool Layer::IsAnimating() const { | 1117 bool Layer::IsAnimating() const { |
1101 return animator_.get() && animator_->is_animating(); | 1118 return animator_.get() && animator_->is_animating(); |
1102 } | 1119 } |
1103 | 1120 |
1104 } // namespace ui | 1121 } // namespace ui |
OLD | NEW |