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/dri/native_display_delegate_dri.h" | 5 #include "ui/ozone/platform/dri/native_display_delegate_dri.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_descriptor_posix.h" |
| 10 #include "base/files/file.h" |
9 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
10 #include "ui/display/types/native_display_observer.h" | 12 #include "ui/display/types/native_display_observer.h" |
11 #include "ui/events/ozone/device/device_event.h" | 13 #include "ui/events/ozone/device/device_event.h" |
12 #include "ui/ozone/common/display_util.h" | 14 #include "ui/ozone/common/display_util.h" |
13 #include "ui/ozone/platform/dri/display_mode_dri.h" | 15 #include "ui/ozone/platform/dri/display_mode_dri.h" |
14 #include "ui/ozone/platform/dri/display_snapshot_dri.h" | 16 #include "ui/ozone/platform/dri/display_snapshot_dri.h" |
15 #include "ui/ozone/platform/dri/dri_util.h" | 17 #include "ui/ozone/platform/dri/dri_util.h" |
16 #include "ui/ozone/platform/dri/dri_wrapper.h" | 18 #include "ui/ozone/platform/dri/dri_wrapper.h" |
| 19 #include "ui/ozone/platform/dri/drm_device_generator.h" |
17 #include "ui/ozone/platform/dri/screen_manager.h" | 20 #include "ui/ozone/platform/dri/screen_manager.h" |
18 #include "ui/ozone/public/ozone_switches.h" | 21 #include "ui/ozone/public/ozone_switches.h" |
19 | 22 |
20 namespace ui { | 23 namespace ui { |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 const char kContentProtection[] = "Content Protection"; | 27 const char kContentProtection[] = "Content Protection"; |
25 | 28 |
26 struct ContentProtectionMapping { | 29 struct ContentProtectionMapping { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 return drm_ == other->drm() && connector_ == other->connector() && | 70 return drm_ == other->drm() && connector_ == other->connector() && |
68 crtc_ == other->crtc(); | 71 crtc_ == other->crtc(); |
69 } | 72 } |
70 | 73 |
71 private: | 74 private: |
72 scoped_refptr<DriWrapper> drm_; | 75 scoped_refptr<DriWrapper> drm_; |
73 uint32_t crtc_; | 76 uint32_t crtc_; |
74 uint32_t connector_; | 77 uint32_t connector_; |
75 }; | 78 }; |
76 | 79 |
| 80 class FindByDevicePath { |
| 81 public: |
| 82 explicit FindByDevicePath(const base::FilePath& path) : path_(path) {} |
| 83 |
| 84 bool operator()(const scoped_refptr<DriWrapper>& device) { |
| 85 return device->device_path() == path_; |
| 86 } |
| 87 |
| 88 private: |
| 89 base::FilePath path_; |
| 90 }; |
| 91 |
77 } // namespace | 92 } // namespace |
78 | 93 |
79 NativeDisplayDelegateDri::NativeDisplayDelegateDri( | 94 NativeDisplayDelegateDri::NativeDisplayDelegateDri( |
80 ScreenManager* screen_manager, | 95 ScreenManager* screen_manager, |
81 const scoped_refptr<DriWrapper>& primary_device) | 96 const scoped_refptr<DriWrapper>& primary_device, |
82 : screen_manager_(screen_manager) { | 97 scoped_ptr<DrmDeviceGenerator> drm_device_generator) |
| 98 : screen_manager_(screen_manager), |
| 99 drm_device_generator_(drm_device_generator.Pass()) { |
83 devices_.push_back(primary_device); | 100 devices_.push_back(primary_device); |
84 } | 101 } |
85 | 102 |
86 NativeDisplayDelegateDri::~NativeDisplayDelegateDri() { | 103 NativeDisplayDelegateDri::~NativeDisplayDelegateDri() { |
87 } | 104 } |
88 | 105 |
89 void NativeDisplayDelegateDri::ForceDPMSOn() { | 106 void NativeDisplayDelegateDri::ForceDPMSOn() { |
90 for (size_t i = 0; i < cached_displays_.size(); ++i) { | 107 for (size_t i = 0; i < cached_displays_.size(); ++i) { |
91 DisplaySnapshotDri* dri_output = cached_displays_[i]; | 108 DisplaySnapshotDri* dri_output = cached_displays_[i]; |
92 if (dri_output->dpms_property()) | 109 if (dri_output->dpms_property()) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 bool NativeDisplayDelegateDri::RelinquishDisplayControl() { | 205 bool NativeDisplayDelegateDri::RelinquishDisplayControl() { |
189 for (const auto& drm : devices_) { | 206 for (const auto& drm : devices_) { |
190 if (!drm->DropMaster()) { | 207 if (!drm->DropMaster()) { |
191 LOG(ERROR) << "Failed to relinquish control of the display"; | 208 LOG(ERROR) << "Failed to relinquish control of the display"; |
192 return false; | 209 return false; |
193 } | 210 } |
194 } | 211 } |
195 return true; | 212 return true; |
196 } | 213 } |
197 | 214 |
198 void NativeDisplayDelegateDri::AddGraphicsDevice(const base::FilePath& path) { | 215 void NativeDisplayDelegateDri::AddGraphicsDevice( |
199 NOTIMPLEMENTED(); | 216 const base::FilePath& path, |
| 217 const base::FileDescriptor& fd) { |
| 218 base::File file(fd.fd); |
| 219 auto it = |
| 220 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); |
| 221 if (it != devices_.end()) { |
| 222 LOG(WARNING) << "Got request to add existing device '" << path.value() |
| 223 << "'"; |
| 224 return; |
| 225 } |
| 226 |
| 227 scoped_refptr<DriWrapper> device = |
| 228 drm_device_generator_->CreateDevice(path, file.Pass()); |
| 229 devices_.push_back(device); |
| 230 if (io_task_runner_) |
| 231 device->InitializeTaskRunner(io_task_runner_); |
200 } | 232 } |
201 | 233 |
202 void NativeDisplayDelegateDri::RemoveGraphicsDevice( | 234 void NativeDisplayDelegateDri::RemoveGraphicsDevice( |
203 const base::FilePath& path) { | 235 const base::FilePath& path) { |
204 NOTIMPLEMENTED(); | 236 auto it = |
| 237 std::find_if(devices_.begin(), devices_.end(), FindByDevicePath(path)); |
| 238 if (it == devices_.end()) { |
| 239 LOG(ERROR) << "Got request to remove non-existent device '" << path.value() |
| 240 << "'"; |
| 241 return; |
| 242 } |
| 243 |
| 244 devices_.erase(it); |
205 } | 245 } |
206 | 246 |
207 DisplaySnapshotDri* NativeDisplayDelegateDri::FindDisplaySnapshot(int64_t id) { | 247 DisplaySnapshotDri* NativeDisplayDelegateDri::FindDisplaySnapshot(int64_t id) { |
208 for (size_t i = 0; i < cached_displays_.size(); ++i) | 248 for (size_t i = 0; i < cached_displays_.size(); ++i) |
209 if (cached_displays_[i]->display_id() == id) | 249 if (cached_displays_[i]->display_id() == id) |
210 return cached_displays_[i]; | 250 return cached_displays_[i]; |
211 | 251 |
212 return NULL; | 252 return NULL; |
213 } | 253 } |
214 | 254 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 408 |
369 if (it == old_displays.end()) { | 409 if (it == old_displays.end()) { |
370 screen_manager_->AddDisplayController(new_displays[i]->drm(), | 410 screen_manager_->AddDisplayController(new_displays[i]->drm(), |
371 new_displays[i]->crtc(), | 411 new_displays[i]->crtc(), |
372 new_displays[i]->connector()); | 412 new_displays[i]->connector()); |
373 } | 413 } |
374 } | 414 } |
375 } | 415 } |
376 | 416 |
377 } // namespace ui | 417 } // namespace ui |
OLD | NEW |