OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "blimp/client/compositor/blimp_compositor.h" | 5 #include "blimp/client/compositor/blimp_compositor.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 | 65 |
66 BlimpCompositor::~BlimpCompositor() { | 66 BlimpCompositor::~BlimpCompositor() { |
67 render_widget_processor_.RemoveDelegate(kDummyTabId); | 67 render_widget_processor_.RemoveDelegate(kDummyTabId); |
68 SetVisible(false); | 68 SetVisible(false); |
69 | 69 |
70 // Destroy |host_| first, as it has a reference to the |settings_| and runs | 70 // Destroy |host_| first, as it has a reference to the |settings_| and runs |
71 // tasks on |compositor_thread_|. | 71 // tasks on |compositor_thread_|. |
72 host_.reset(); | 72 host_.reset(); |
73 settings_.reset(); | 73 settings_.reset(); |
| 74 |
| 75 // We must destroy |host_| before the |input_manager_|. |
| 76 input_manager_.reset(); |
| 77 |
74 if (compositor_thread_) | 78 if (compositor_thread_) |
75 compositor_thread_->Stop(); | 79 compositor_thread_->Stop(); |
76 } | 80 } |
77 | 81 |
78 void BlimpCompositor::SetVisible(bool visible) { | 82 void BlimpCompositor::SetVisible(bool visible) { |
79 // For testing. Remove once we bind to the network layer. | 83 // For testing. Remove once we bind to the network layer. |
80 if (!host_) | 84 if (!host_) |
81 CreateLayerTreeHost(nullptr); | 85 CreateLayerTreeHost(nullptr); |
82 | 86 |
83 host_should_be_visible_ = visible; | 87 host_should_be_visible_ = visible; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 void BlimpCompositor::ReleaseAcceleratedWidget() { | 128 void BlimpCompositor::ReleaseAcceleratedWidget() { |
125 if (window_ == gfx::kNullAcceleratedWidget) | 129 if (window_ == gfx::kNullAcceleratedWidget) |
126 return; | 130 return; |
127 | 131 |
128 // Hide the compositor and drop the output surface if necessary. | 132 // Hide the compositor and drop the output surface if necessary. |
129 SetVisible(false); | 133 SetVisible(false); |
130 | 134 |
131 window_ = gfx::kNullAcceleratedWidget; | 135 window_ = gfx::kNullAcceleratedWidget; |
132 } | 136 } |
133 | 137 |
| 138 bool BlimpCompositor::OnTouchEvent(const ui::MotionEvent& motion_event) { |
| 139 if (input_manager_) |
| 140 return input_manager_->OnTouchEvent(motion_event); |
| 141 return false; |
| 142 } |
| 143 |
134 void BlimpCompositor::WillBeginMainFrame() {} | 144 void BlimpCompositor::WillBeginMainFrame() {} |
135 | 145 |
136 void BlimpCompositor::DidBeginMainFrame() {} | 146 void BlimpCompositor::DidBeginMainFrame() {} |
137 | 147 |
138 void BlimpCompositor::BeginMainFrame(const cc::BeginFrameArgs& args) {} | 148 void BlimpCompositor::BeginMainFrame(const cc::BeginFrameArgs& args) {} |
139 | 149 |
140 void BlimpCompositor::BeginMainFrameNotExpectedSoon() {} | 150 void BlimpCompositor::BeginMainFrameNotExpectedSoon() {} |
141 | 151 |
142 void BlimpCompositor::UpdateLayerTreeHost() {} | 152 void BlimpCompositor::UpdateLayerTreeHost() {} |
143 | 153 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 192 } |
183 | 193 |
184 void BlimpCompositor::OnRenderWidgetInitialized() { | 194 void BlimpCompositor::OnRenderWidgetInitialized() { |
185 // Tear down the output surface connection with the old LayerTreeHost | 195 // Tear down the output surface connection with the old LayerTreeHost |
186 // instance. | 196 // instance. |
187 SetVisible(false); | 197 SetVisible(false); |
188 | 198 |
189 // Destroy the old LayerTreeHost state. | 199 // Destroy the old LayerTreeHost state. |
190 host_.reset(); | 200 host_.reset(); |
191 | 201 |
| 202 // Destroy the old input manager state. |
| 203 // It is important to destroy the LayerTreeHost before destroying the input |
| 204 // manager as it has a reference to the cc::InputHandlerClient owned by the |
| 205 // BlimpInputManager. |
| 206 input_manager_.reset(); |
| 207 |
192 // Reset other state. | 208 // Reset other state. |
193 output_surface_request_pending_ = false; | 209 output_surface_request_pending_ = false; |
194 | 210 |
195 // Make sure we don't have a receiver at this point. | 211 // Make sure we don't have a receiver at this point. |
196 DCHECK(!remote_proto_channel_receiver_); | 212 DCHECK(!remote_proto_channel_receiver_); |
197 } | 213 } |
198 | 214 |
199 void BlimpCompositor::OnCompositorMessageReceived( | 215 void BlimpCompositor::OnCompositorMessageReceived( |
200 scoped_ptr<cc::proto::CompositorMessage> message) { | 216 scoped_ptr<cc::proto::CompositorMessage> message) { |
201 // TODO(dtrainor, khushalsagar): Look into the CompositorMessage. If it is | 217 // TODO(dtrainor, khushalsagar): Look into the CompositorMessage. If it is |
202 // initialize or shutdown, create or destroy |host_|. | 218 // initialize or shutdown, create or destroy |host_|. |
203 | 219 |
204 // We should have a receiver if we're getting compositor messages that aren't | 220 // We should have a receiver if we're getting compositor messages that aren't |
205 // initialize. | 221 // initialize. |
206 DCHECK(remote_proto_channel_receiver_); | 222 DCHECK(remote_proto_channel_receiver_); |
207 remote_proto_channel_receiver_->OnProtoReceived(std::move(message)); | 223 remote_proto_channel_receiver_->OnProtoReceived(std::move(message)); |
208 } | 224 } |
209 | 225 |
210 void BlimpCompositor::GenerateLayerTreeSettings( | 226 void BlimpCompositor::GenerateLayerTreeSettings( |
211 cc::LayerTreeSettings* settings) { | 227 cc::LayerTreeSettings* settings) { |
212 PopulateCommonLayerTreeSettings(settings); | 228 PopulateCommonLayerTreeSettings(settings); |
213 } | 229 } |
214 | 230 |
| 231 void BlimpCompositor::SendWebInputEvent( |
| 232 const blink::WebInputEvent& input_event) { |
| 233 render_widget_processor_.SendInputEvent(kDummyTabId, input_event); |
| 234 } |
| 235 |
215 void BlimpCompositor::CreateLayerTreeHost( | 236 void BlimpCompositor::CreateLayerTreeHost( |
216 scoped_ptr<cc::proto::CompositorMessage> message) { | 237 scoped_ptr<cc::proto::CompositorMessage> message) { |
217 if (!settings_) { | 238 if (!settings_) { |
218 settings_.reset(new cc::LayerTreeSettings); | 239 settings_.reset(new cc::LayerTreeSettings); |
219 GenerateLayerTreeSettings(settings_.get()); | 240 GenerateLayerTreeSettings(settings_.get()); |
220 } | 241 } |
221 | 242 |
222 // Create the LayerTreeHost | 243 // Create the LayerTreeHost |
223 cc::LayerTreeHost::InitParams params; | 244 cc::LayerTreeHost::InitParams params; |
224 params.client = this; | 245 params.client = this; |
(...skipping 12 matching lines...) Expand all Loading... |
237 host_->SetVisible(true); | 258 host_->SetVisible(true); |
238 | 259 |
239 host_->SetViewportSize(viewport_size_); | 260 host_->SetViewportSize(viewport_size_); |
240 host_->SetDeviceScaleFactor(device_scale_factor_); | 261 host_->SetDeviceScaleFactor(device_scale_factor_); |
241 | 262 |
242 // For testing, set the dummy Layer. | 263 // For testing, set the dummy Layer. |
243 scoped_refptr<cc::Layer> root( | 264 scoped_refptr<cc::Layer> root( |
244 cc::Layer::Create(BlimpCompositor::LayerSettings())); | 265 cc::Layer::Create(BlimpCompositor::LayerSettings())); |
245 host_->SetRootLayer(root); | 266 host_->SetRootLayer(root); |
246 g_dummy_layer_driver.Pointer()->SetParentLayer(root); | 267 g_dummy_layer_driver.Pointer()->SetParentLayer(root); |
| 268 |
| 269 // TODO(khushalsagar): Create this after successful initialization of the |
| 270 // remote client compositor when implemented. |
| 271 DCHECK(!input_manager_); |
| 272 input_manager_ = |
| 273 BlimpInputManager::Create(this, |
| 274 base::ThreadTaskRunnerHandle::Get(), |
| 275 GetCompositorTaskRunner(), |
| 276 host_->GetInputHandler()); |
247 } | 277 } |
248 | 278 |
249 scoped_refptr<base::SingleThreadTaskRunner> | 279 scoped_refptr<base::SingleThreadTaskRunner> |
250 BlimpCompositor::GetCompositorTaskRunner() { | 280 BlimpCompositor::GetCompositorTaskRunner() { |
251 if (compositor_thread_) | 281 if (compositor_thread_) |
252 return compositor_thread_->task_runner(); | 282 return compositor_thread_->task_runner(); |
253 | 283 |
254 base::Thread::Options thread_options; | 284 base::Thread::Options thread_options; |
255 #if defined(OS_ANDROID) | 285 #if defined(OS_ANDROID) |
256 thread_options.priority = base::ThreadPriority::DISPLAY; | 286 thread_options.priority = base::ThreadPriority::DISPLAY; |
(...skipping 29 matching lines...) Expand all Loading... |
286 output_surface_request_pending_ = false; | 316 output_surface_request_pending_ = false; |
287 } | 317 } |
288 | 318 |
289 cc::LayerSettings BlimpCompositor::LayerSettings() { | 319 cc::LayerSettings BlimpCompositor::LayerSettings() { |
290 cc::LayerSettings settings; | 320 cc::LayerSettings settings; |
291 settings.use_compositor_animation_timelines = true; | 321 settings.use_compositor_animation_timelines = true; |
292 return settings; | 322 return settings; |
293 } | 323 } |
294 | 324 |
295 } // namespace blimp | 325 } // namespace blimp |
OLD | NEW |