OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/layers/surface_layer.h" | 5 #include "cc/layers/surface_layer.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 | 92 |
93 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl( | 93 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl( |
94 LayerTreeImpl* tree_impl) { | 94 LayerTreeImpl* tree_impl) { |
95 return SurfaceLayerImpl::Create(tree_impl, id()); | 95 return SurfaceLayerImpl::Create(tree_impl, id()); |
96 } | 96 } |
97 | 97 |
98 bool SurfaceLayer::HasDrawableContent() const { | 98 bool SurfaceLayer::HasDrawableContent() const { |
99 return primary_surface_info_.is_valid() && Layer::HasDrawableContent(); | 99 return primary_surface_info_.is_valid() && Layer::HasDrawableContent(); |
100 } | 100 } |
101 | 101 |
102 const SurfaceId* SurfaceLayer::GetSurfaceId(LayerTreeHost* new_host) { | |
103 LayerTreeHost* old_host = layer_tree_host(); | |
104 DCHECK(!old_host || !new_host || | |
105 old_host->GetSettings().enable_surface_synchronization == | |
106 new_host->GetSettings().enable_surface_synchronization); | |
107 | |
108 bool enable_surface_synchronization; | |
109 if (old_host) { | |
110 enable_surface_synchronization = | |
111 old_host->GetSettings().enable_surface_synchronization; | |
112 } else { | |
113 DCHECK(new_host); | |
114 enable_surface_synchronization = | |
115 new_host->GetSettings().enable_surface_synchronization; | |
116 } | |
117 | |
118 if (enable_surface_synchronization) { | |
119 if (fallback_surface_info_.is_valid()) | |
120 return &fallback_surface_info_.id(); | |
121 } else { | |
122 return &primary_surface_info_.id(); | |
123 } | |
124 return nullptr; | |
jaydasika
2017/05/23 00:25:14
Not sure if this is correct / there is a simpler w
| |
125 } | |
126 | |
102 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { | 127 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { |
103 if (layer_tree_host() == host) { | 128 if (layer_tree_host() == host) { |
104 Layer::SetLayerTreeHost(host); | |
105 return; | 129 return; |
106 } | 130 } |
131 const SurfaceId* surface_id = GetSurfaceId(host); | |
132 | |
133 if (layer_tree_host() && surface_id) { | |
134 layer_tree_host()->RemoveSurfaceLayerId(*surface_id); | |
135 } | |
136 | |
107 RemoveReference(std::move(primary_reference_returner_)); | 137 RemoveReference(std::move(primary_reference_returner_)); |
108 RemoveReference(std::move(fallback_reference_returner_)); | 138 RemoveReference(std::move(fallback_reference_returner_)); |
109 Layer::SetLayerTreeHost(host); | 139 Layer::SetLayerTreeHost(host); |
110 if (layer_tree_host()) { | 140 if (layer_tree_host()) { |
111 if (primary_surface_info_.is_valid()) { | 141 if (primary_surface_info_.is_valid()) { |
112 primary_reference_returner_ = ref_factory_->CreateReference( | 142 primary_reference_returner_ = ref_factory_->CreateReference( |
113 layer_tree_host(), primary_surface_info_.id()); | 143 layer_tree_host(), primary_surface_info_.id()); |
114 } | 144 } |
115 if (fallback_surface_info_.is_valid()) { | 145 if (fallback_surface_info_.is_valid()) { |
116 fallback_reference_returner_ = ref_factory_->CreateReference( | 146 fallback_reference_returner_ = ref_factory_->CreateReference( |
117 layer_tree_host(), fallback_surface_info_.id()); | 147 layer_tree_host(), fallback_surface_info_.id()); |
118 } | 148 } |
149 if (surface_id) | |
150 layer_tree_host()->AddSurfaceLayerId(*surface_id); | |
119 } | 151 } |
120 } | 152 } |
121 | 153 |
122 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { | 154 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { |
123 Layer::PushPropertiesTo(layer); | 155 Layer::PushPropertiesTo(layer); |
124 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); | 156 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); |
125 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); | 157 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); |
126 layer_impl->SetPrimarySurfaceInfo(primary_surface_info_); | 158 layer_impl->SetPrimarySurfaceInfo(primary_surface_info_); |
127 layer_impl->SetFallbackSurfaceInfo(fallback_surface_info_); | 159 layer_impl->SetFallbackSurfaceInfo(fallback_surface_info_); |
128 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); | 160 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); |
129 } | 161 } |
130 | 162 |
131 void SurfaceLayer::RemoveReference(base::Closure reference_returner) { | 163 void SurfaceLayer::RemoveReference(base::Closure reference_returner) { |
132 if (!reference_returner) | 164 if (!reference_returner) |
133 return; | 165 return; |
134 auto swap_promise = base::MakeUnique<SatisfySwapPromise>( | 166 auto swap_promise = base::MakeUnique<SatisfySwapPromise>( |
135 std::move(reference_returner), | 167 std::move(reference_returner), |
136 layer_tree_host()->GetTaskRunnerProvider()->MainThreadTaskRunner()); | 168 layer_tree_host()->GetTaskRunnerProvider()->MainThreadTaskRunner()); |
137 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( | 169 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( |
138 std::move(swap_promise)); | 170 std::move(swap_promise)); |
139 } | 171 } |
140 | 172 |
141 } // namespace cc | 173 } // namespace cc |
OLD | NEW |