| 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 "ui/ozone/platform/drm/host/drm_display_host_manager.h" | 5 #include "ui/ozone/platform/drm/host/drm_display_host_manager.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <xf86drm.h> | 8 #include <xf86drm.h> |
| 9 | 9 |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 216 |
| 217 relinquish_display_control_callback_ = callback; | 217 relinquish_display_control_callback_ = callback; |
| 218 display_control_change_pending_ = true; | 218 display_control_change_pending_ = true; |
| 219 | 219 |
| 220 if (!proxy_->RelinquishDisplayControl()) | 220 if (!proxy_->RelinquishDisplayControl()) |
| 221 OnRelinquishDisplayControl(false); | 221 OnRelinquishDisplayControl(false); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void DrmDisplayHostManager::UpdateDisplays( | 224 void DrmDisplayHostManager::UpdateDisplays( |
| 225 const GetDisplaysCallback& callback) { | 225 const GetDisplaysCallback& callback) { |
| 226 DCHECK(get_displays_callback_.is_null()); |
| 226 get_displays_callback_ = callback; | 227 get_displays_callback_ = callback; |
| 227 if (!proxy_->RefreshNativeDisplays()) { | 228 if (!proxy_->RefreshNativeDisplays()) { |
| 228 get_displays_callback_.Reset(); | 229 get_displays_callback_.Reset(); |
| 229 RunUpdateDisplaysCallback(callback); | 230 RunUpdateDisplaysCallback(callback); |
| 230 } | 231 } |
| 231 } | 232 } |
| 232 | 233 |
| 233 void DrmDisplayHostManager::OnDeviceEvent(const DeviceEvent& event) { | 234 void DrmDisplayHostManager::OnDeviceEvent(const DeviceEvent& event) { |
| 234 if (event.device_type() != DeviceEvent::DISPLAY) | 235 if (event.device_type() != DeviceEvent::DISPLAY) |
| 235 return; | 236 return; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 ProcessEvent(); | 301 ProcessEvent(); |
| 301 } | 302 } |
| 302 | 303 |
| 303 void DrmDisplayHostManager::OnRemoveGraphicsDevice(const base::FilePath& path) { | 304 void DrmDisplayHostManager::OnRemoveGraphicsDevice(const base::FilePath& path) { |
| 304 proxy_->RemoveGraphicsDevice(path); | 305 proxy_->RemoveGraphicsDevice(path); |
| 305 NotifyDisplayDelegate(); | 306 NotifyDisplayDelegate(); |
| 306 task_pending_ = false; | 307 task_pending_ = false; |
| 307 ProcessEvent(); | 308 ProcessEvent(); |
| 308 } | 309 } |
| 309 | 310 |
| 310 void DrmDisplayHostManager::OnChannelEstablished(int host_id) { | 311 void DrmDisplayHostManager::OnChannelEstablished() { |
| 311 // If in the middle of a configuration, just respond with the old list of | 312 // If in the middle of a configuration - don't respond here. |
| 312 // displays. This is fine, since after the DRM resources are initialized and | 313 // Chromium does so, but that causes a problem: |
| 313 // IPC-ed to the GPU NotifyDisplayDelegate() is called to let the display | 314 // NotifyDisplayDelegate, below, triggers a new update display request which |
| 314 // delegate know that the display configuration changed and it needs to | 315 // is |
| 315 // update it again. | 316 // fulfilled by the results from the first request. That result is empty |
| 316 if (!get_displays_callback_.is_null()) { | 317 // because |
| 317 base::ThreadTaskRunnerHandle::Get()->PostTask( | 318 // we haven't added a drm device yet). |
| 318 FROM_HERE, | 319 // The second update display request generates non empty results, |
| 319 base::Bind(&DrmDisplayHostManager::RunUpdateDisplaysCallback, | 320 // but those won't be forwarded to the observer because there is no longer |
| 320 weak_ptr_factory_.GetWeakPtr(), get_displays_callback_)); | 321 // an outstanding request. |
| 321 get_displays_callback_.Reset(); | |
| 322 } | |
| 323 | 322 |
| 324 // Signal that we're taking DRM master since we're going through the | 323 // Signal that we're taking DRM master since we're going through the |
| 325 // initialization process again and we'll take all the available resources. | 324 // initialization process again and we'll take all the available resources. |
| 326 if (!take_display_control_callback_.is_null()) | 325 if (!take_display_control_callback_.is_null()) |
| 327 OnTakeDisplayControl(true); | 326 OnTakeDisplayControl(true); |
| 328 | 327 |
| 329 if (!relinquish_display_control_callback_.is_null()) | 328 if (!relinquish_display_control_callback_.is_null()) |
| 330 OnRelinquishDisplayControl(false); | 329 OnRelinquishDisplayControl(false); |
| 331 | 330 |
| 332 drm_devices_.clear(); | 331 drm_devices_.clear(); |
| 333 drm_devices_.insert(primary_graphics_card_path_); | 332 drm_devices_.insert(primary_graphics_card_path_); |
| 334 scoped_ptr<DrmDeviceHandle> handle = primary_drm_device_handle_.Pass(); | 333 scoped_ptr<DrmDeviceHandle> handle = primary_drm_device_handle_.Pass(); |
| 335 if (!handle) { | 334 if (!handle) { |
| 336 handle.reset(new DrmDeviceHandle()); | 335 handle.reset(new DrmDeviceHandle()); |
| 337 if (!handle->Initialize(primary_graphics_card_path_)) | 336 if (!handle->Initialize(primary_graphics_card_path_)) |
| 338 LOG(FATAL) << "Failed to open primary graphics card"; | 337 LOG(FATAL) << "Failed to open primary graphics card"; |
| 339 } | 338 } |
| 340 | 339 |
| 341 // Send the primary device first since this is used to initialize graphics | 340 // Send the primary device first since this is used to initialize graphics |
| 342 // state. | 341 // state. |
| 343 proxy_->AddGraphicsDevice(primary_graphics_card_path_, | 342 proxy_->AddGraphicsDevice(primary_graphics_card_path_, |
| 344 base::FileDescriptor(handle->PassFD())); | 343 base::FileDescriptor(handle->PassFD())); |
| 345 | 344 |
| 346 device_manager_->ScanDevices(this); | 345 device_manager_->ScanDevices(this); |
| 347 NotifyDisplayDelegate(); | 346 NotifyDisplayDelegate(); |
| 348 } | 347 } |
| 349 | 348 |
| 350 void DrmDisplayHostManager::OnChannelDestroyed(int host_id) { | 349 void DrmDisplayHostManager::OnChannelDestroyed() { |
| 351 // Do nothing. | 350 // Do nothing. |
| 352 } | 351 } |
| 353 | 352 |
| 354 void DrmDisplayHostManager::OnUpdateNativeDisplays( | 353 void DrmDisplayHostManager::OnUpdateNativeDisplays( |
| 355 const std::vector<DisplaySnapshot_Params>& params) { | 354 const std::vector<DisplaySnapshot_Params>& params) { |
| 356 ScopedVector<DrmDisplayHost> old_displays(displays_.Pass()); | 355 ScopedVector<DrmDisplayHost> old_displays(displays_.Pass()); |
| 357 for (size_t i = 0; i < params.size(); ++i) { | 356 for (size_t i = 0; i < params.size(); ++i) { |
| 358 auto it = std::find_if(old_displays.begin(), old_displays.end(), | 357 auto it = std::find_if(old_displays.begin(), old_displays.end(), |
| 359 FindDrmDisplayHostById(params[i].display_id)); | 358 FindDrmDisplayHostById(params[i].display_id)); |
| 360 if (it == old_displays.end()) { | 359 if (it == old_displays.end()) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 451 |
| 453 callback.Run(snapshots); | 452 callback.Run(snapshots); |
| 454 } | 453 } |
| 455 | 454 |
| 456 void DrmDisplayHostManager::NotifyDisplayDelegate() const { | 455 void DrmDisplayHostManager::NotifyDisplayDelegate() const { |
| 457 if (delegate_) | 456 if (delegate_) |
| 458 delegate_->OnConfigurationChanged(); | 457 delegate_->OnConfigurationChanged(); |
| 459 } | 458 } |
| 460 | 459 |
| 461 } // namespace ui | 460 } // namespace ui |
| OLD | NEW |