| 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 <stdio.h> | 8 #include <stdio.h> |
| 9 #include <xf86drm.h> | 9 #include <xf86drm.h> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" | 24 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h" |
| 25 | 25 |
| 26 namespace ui { | 26 namespace ui { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)> | 30 typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)> |
| 31 OnOpenDeviceReplyCallback; | 31 OnOpenDeviceReplyCallback; |
| 32 | 32 |
| 33 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; | 33 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; |
| 34 const char kVGEMCardPattern[] = "/sys/bus/platform/devices/vgem/drm/card%d"; |
| 34 | 35 |
| 35 const char* kDisplayActionString[] = { | 36 const char* kDisplayActionString[] = { |
| 36 "ADD", | 37 "ADD", |
| 37 "REMOVE", | 38 "REMOVE", |
| 38 "CHANGE", | 39 "CHANGE", |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 void OpenDeviceOnWorkerThread( | 42 void OpenDeviceOnWorkerThread( |
| 42 const base::FilePath& path, | 43 const base::FilePath& path, |
| 44 bool is_vgem, |
| 43 const scoped_refptr<base::TaskRunner>& reply_runner, | 45 const scoped_refptr<base::TaskRunner>& reply_runner, |
| 44 const OnOpenDeviceReplyCallback& callback) { | 46 const OnOpenDeviceReplyCallback& callback) { |
| 45 scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle()); | 47 scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle()); |
| 46 handle->Initialize(path); | 48 handle->Initialize(path, is_vgem); |
| 47 reply_runner->PostTask( | 49 reply_runner->PostTask( |
| 48 FROM_HERE, base::Bind(callback, path, base::Passed(handle.Pass()))); | 50 FROM_HERE, base::Bind(callback, path, base::Passed(handle.Pass()))); |
| 49 } | 51 } |
| 50 | 52 |
| 51 void CloseDeviceOnWorkerThread( | 53 void CloseDeviceOnWorkerThread( |
| 52 scoped_ptr<DrmDeviceHandle> handle, | 54 scoped_ptr<DrmDeviceHandle> handle, |
| 53 const scoped_refptr<base::TaskRunner>& reply_runner, | 55 const scoped_refptr<base::TaskRunner>& reply_runner, |
| 54 const base::Closure& callback) { | 56 const base::Closure& callback) { |
| 55 handle.reset(); | 57 handle.reset(); |
| 56 reply_runner->PostTask(FROM_HERE, callback); | 58 reply_runner->PostTask(FROM_HERE, callback); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 primary_graphics_card_path_(GetPrimaryDisplayCardPath()), | 107 primary_graphics_card_path_(GetPrimaryDisplayCardPath()), |
| 106 has_dummy_display_(false), | 108 has_dummy_display_(false), |
| 107 task_pending_(false), | 109 task_pending_(false), |
| 108 weak_ptr_factory_(this) { | 110 weak_ptr_factory_(this) { |
| 109 { | 111 { |
| 110 // First device needs to be treated specially. We need to open this | 112 // First device needs to be treated specially. We need to open this |
| 111 // synchronously since the GPU process will need it to initialize the | 113 // synchronously since the GPU process will need it to initialize the |
| 112 // graphics state. | 114 // graphics state. |
| 113 base::ThreadRestrictions::ScopedAllowIO allow_io; | 115 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 114 scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle()); | 116 scoped_ptr<DrmDeviceHandle> handle(new DrmDeviceHandle()); |
| 115 if (!handle->Initialize(primary_graphics_card_path_)) { | 117 if (!handle->Initialize(primary_graphics_card_path_, false)) { |
| 116 LOG(FATAL) << "Failed to open primary graphics card"; | 118 LOG(FATAL) << "Failed to open primary graphics card"; |
| 117 return; | 119 return; |
| 118 } | 120 } |
| 119 drm_devices_.add(primary_graphics_card_path_, handle.Pass()); | 121 drm_devices_.add(primary_graphics_card_path_, handle.Pass()); |
| 120 } | 122 } |
| 121 | 123 |
| 122 device_manager_->AddObserver(this); | 124 device_manager_->AddObserver(this); |
| 123 proxy_->RegisterHandler(this); | 125 proxy_->RegisterHandler(this); |
| 124 | 126 |
| 125 DisplaySnapshot_Params params; | 127 DisplaySnapshot_Params params; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 int64_t display_id, | 244 int64_t display_id, |
| 243 const std::vector<GammaRampRGBEntry>& lut) { | 245 const std::vector<GammaRampRGBEntry>& lut) { |
| 244 proxy_->Send(new OzoneGpuMsg_SetGammaRamp(display_id, lut)); | 246 proxy_->Send(new OzoneGpuMsg_SetGammaRamp(display_id, lut)); |
| 245 return true; | 247 return true; |
| 246 } | 248 } |
| 247 | 249 |
| 248 void DrmDisplayHostManager::OnDeviceEvent(const DeviceEvent& event) { | 250 void DrmDisplayHostManager::OnDeviceEvent(const DeviceEvent& event) { |
| 249 if (event.device_type() != DeviceEvent::DISPLAY) | 251 if (event.device_type() != DeviceEvent::DISPLAY) |
| 250 return; | 252 return; |
| 251 | 253 |
| 252 event_queue_.push(DisplayEvent(event.action_type(), event.path())); | 254 bool is_vgem = false; |
| 255 for (int i = 0; i < 16; i++) { |
| 256 struct stat vgem_stat; |
| 257 std::string vgem_path = base::StringPrintf(kVGEMCardPattern, i); |
| 258 if (stat(vgem_path.c_str(), &vgem_stat) == -1) |
| 259 continue; |
| 260 |
| 261 std::string card_path = base::StringPrintf(kDefaultGraphicsCardPattern, i); |
| 262 if (card_path == event.path().value()) |
| 263 is_vgem = true; |
| 264 break; |
| 265 } |
| 266 |
| 267 event_queue_.push(DisplayEvent(event.action_type(), event.path(), is_vgem)); |
| 253 ProcessEvent(); | 268 ProcessEvent(); |
| 254 } | 269 } |
| 255 | 270 |
| 256 void DrmDisplayHostManager::ProcessEvent() { | 271 void DrmDisplayHostManager::ProcessEvent() { |
| 257 while (!event_queue_.empty() && !task_pending_) { | 272 while (!event_queue_.empty() && !task_pending_) { |
| 258 DisplayEvent event = event_queue_.front(); | 273 DisplayEvent event = event_queue_.front(); |
| 259 event_queue_.pop(); | 274 event_queue_.pop(); |
| 260 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type] | 275 VLOG(1) << "Got display event " << kDisplayActionString[event.action_type] |
| 261 << " for " << event.path.value(); | 276 << " for " << event.path.value(); |
| 262 switch (event.action_type) { | 277 switch (event.action_type) { |
| 263 case DeviceEvent::ADD: | 278 case DeviceEvent::ADD: |
| 264 if (drm_devices_.find(event.path) == drm_devices_.end()) { | 279 if (drm_devices_.find(event.path) == drm_devices_.end()) { |
| 265 task_pending_ = base::WorkerPool::PostTask( | 280 task_pending_ = base::WorkerPool::PostTask( |
| 266 FROM_HERE, | 281 FROM_HERE, |
| 267 base::Bind(&OpenDeviceOnWorkerThread, event.path, | 282 base::Bind(&OpenDeviceOnWorkerThread, event.path, event.is_vgem, |
| 268 base::ThreadTaskRunnerHandle::Get(), | 283 base::ThreadTaskRunnerHandle::Get(), |
| 269 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice, | 284 base::Bind(&DrmDisplayHostManager::OnAddGraphicsDevice, |
| 270 weak_ptr_factory_.GetWeakPtr())), | 285 weak_ptr_factory_.GetWeakPtr())), |
| 271 false /* task_is_slow */); | 286 false /* task_is_slow */); |
| 272 } | 287 } |
| 273 break; | 288 break; |
| 274 case DeviceEvent::CHANGE: | 289 case DeviceEvent::CHANGE: |
| 275 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( | 290 task_pending_ = base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 276 FROM_HERE, | 291 FROM_HERE, |
| 277 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice, | 292 base::Bind(&DrmDisplayHostManager::OnUpdateGraphicsDevice, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 298 } | 313 } |
| 299 } | 314 } |
| 300 | 315 |
| 301 void DrmDisplayHostManager::OnAddGraphicsDevice( | 316 void DrmDisplayHostManager::OnAddGraphicsDevice( |
| 302 const base::FilePath& path, | 317 const base::FilePath& path, |
| 303 scoped_ptr<DrmDeviceHandle> handle) { | 318 scoped_ptr<DrmDeviceHandle> handle) { |
| 304 if (handle->IsValid()) { | 319 if (handle->IsValid()) { |
| 305 base::ScopedFD file = handle->Duplicate(); | 320 base::ScopedFD file = handle->Duplicate(); |
| 306 drm_devices_.add(path, handle.Pass()); | 321 drm_devices_.add(path, handle.Pass()); |
| 307 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( | 322 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
| 308 path, base::FileDescriptor(file.Pass()))); | 323 path, base::FileDescriptor(file.Pass()), handle->IsVgem())); |
| 309 NotifyDisplayDelegate(); | 324 NotifyDisplayDelegate(); |
| 310 } | 325 } |
| 311 | 326 |
| 312 task_pending_ = false; | 327 task_pending_ = false; |
| 313 ProcessEvent(); | 328 ProcessEvent(); |
| 314 } | 329 } |
| 315 | 330 |
| 316 void DrmDisplayHostManager::OnUpdateGraphicsDevice() { | 331 void DrmDisplayHostManager::OnUpdateGraphicsDevice() { |
| 317 NotifyDisplayDelegate(); | 332 NotifyDisplayDelegate(); |
| 318 task_pending_ = false; | 333 task_pending_ = false; |
| 319 ProcessEvent(); | 334 ProcessEvent(); |
| 320 } | 335 } |
| 321 | 336 |
| 322 void DrmDisplayHostManager::OnRemoveGraphicsDevice(const base::FilePath& path) { | 337 void DrmDisplayHostManager::OnRemoveGraphicsDevice(const base::FilePath& path) { |
| 323 proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(path)); | 338 proxy_->Send(new OzoneGpuMsg_RemoveGraphicsDevice(path)); |
| 324 NotifyDisplayDelegate(); | 339 NotifyDisplayDelegate(); |
| 325 task_pending_ = false; | 340 task_pending_ = false; |
| 326 ProcessEvent(); | 341 ProcessEvent(); |
| 327 } | 342 } |
| 328 | 343 |
| 329 void DrmDisplayHostManager::OnChannelEstablished( | 344 void DrmDisplayHostManager::OnChannelEstablished( |
| 330 int host_id, | 345 int host_id, |
| 331 scoped_refptr<base::SingleThreadTaskRunner> send_runner, | 346 scoped_refptr<base::SingleThreadTaskRunner> send_runner, |
| 332 const base::Callback<void(IPC::Message*)>& send_callback) { | 347 const base::Callback<void(IPC::Message*)>& send_callback) { |
| 333 auto it = drm_devices_.find(primary_graphics_card_path_); | 348 auto it = drm_devices_.find(primary_graphics_card_path_); |
| 334 DCHECK(it != drm_devices_.end()); | 349 DCHECK(it != drm_devices_.end()); |
| 335 // Send the primary device first since this is used to initialize graphics | 350 // Send the primary device first since this is used to initialize graphics |
| 336 // state. | 351 // state. |
| 337 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( | 352 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
| 338 it->first, base::FileDescriptor(it->second->Duplicate()))); | 353 it->first, base::FileDescriptor(it->second->Duplicate()), |
| 354 it->second->IsVgem())); |
| 339 | 355 |
| 340 for (auto pair : drm_devices_) { | 356 for (auto pair : drm_devices_) { |
| 341 if (pair.second->IsValid() && pair.first != primary_graphics_card_path_) { | 357 if (pair.second->IsValid() && pair.first != primary_graphics_card_path_) { |
| 342 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( | 358 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice( |
| 343 pair.first, base::FileDescriptor(pair.second->Duplicate()))); | 359 pair.first, base::FileDescriptor(pair.second->Duplicate()), |
| 360 it->second->IsVgem())); |
| 344 } | 361 } |
| 345 } | 362 } |
| 346 | 363 |
| 347 device_manager_->ScanDevices(this); | 364 device_manager_->ScanDevices(this); |
| 348 NotifyDisplayDelegate(); | 365 NotifyDisplayDelegate(); |
| 349 } | 366 } |
| 350 | 367 |
| 351 void DrmDisplayHostManager::OnChannelDestroyed(int host_id) { | 368 void DrmDisplayHostManager::OnChannelDestroyed(int host_id) { |
| 352 // If the channel got destroyed in the middle of a configuration then just | 369 // If the channel got destroyed in the middle of a configuration then just |
| 353 // respond with failure. | 370 // respond with failure. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 const GetDisplaysCallback& callback) const { | 448 const GetDisplaysCallback& callback) const { |
| 432 callback.Run(displays_.get()); | 449 callback.Run(displays_.get()); |
| 433 } | 450 } |
| 434 | 451 |
| 435 void DrmDisplayHostManager::NotifyDisplayDelegate() const { | 452 void DrmDisplayHostManager::NotifyDisplayDelegate() const { |
| 436 if (delegate_) | 453 if (delegate_) |
| 437 delegate_->OnConfigurationChanged(); | 454 delegate_->OnConfigurationChanged(); |
| 438 } | 455 } |
| 439 | 456 |
| 440 } // namespace ui | 457 } // namespace ui |
| OLD | NEW |