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" |
11 #include "base/posix/eintr_wrapper.h" | 11 #include "base/posix/eintr_wrapper.h" |
12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "base/threading/worker_pool.h" | 14 #include "base/threading/worker_pool.h" |
15 #include "ui/display/types/display_snapshot.h" | 15 #include "ui/display/types/display_snapshot.h" |
16 #include "ui/events/ozone/device/device_event.h" | 16 #include "ui/events/ozone/device/device_event.h" |
17 #include "ui/events/ozone/device/device_manager.h" | 17 #include "ui/events/ozone/device/device_manager.h" |
18 #include "ui/ozone/common/display_util.h" | 18 #include "ui/ozone/common/display_util.h" |
19 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" | 19 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" |
20 #include "ui/ozone/platform/drm/common/drm_util.h" | 20 #include "ui/ozone/platform/drm/common/drm_util.h" |
21 #include "ui/ozone/platform/drm/host/drm_device_handle.h" | 21 #include "ui/ozone/platform/drm/host/drm_device_handle.h" |
22 #include "ui/ozone/platform/drm/host/drm_display_host.h" | 22 #include "ui/ozone/platform/drm/host/drm_display_host.h" |
23 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" | 23 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" |
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 #include "base/command_line.h" | |
27 #include "ui/ozone/public/ozone_switches.h" | |
28 | |
26 namespace ui { | 29 namespace ui { |
27 | 30 |
28 namespace { | 31 namespace { |
29 | 32 |
30 typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)> | 33 typedef base::Callback<void(const base::FilePath&, scoped_ptr<DrmDeviceHandle>)> |
31 OnOpenDeviceReplyCallback; | 34 OnOpenDeviceReplyCallback; |
32 | 35 |
33 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; | 36 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; |
34 const char kVgemDevDriCardPath[] = "/dev/dri/"; | 37 const char kVgemDevDriCardPath[] = "/dev/dri/"; |
35 const char kVgemSysCardPath[] = "/sys/bus/platform/devices/vgem/drm/"; | 38 const char kVgemSysCardPath[] = "/sys/bus/platform/devices/vgem/drm/"; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 // synchronously since the GPU process will need it to initialize the | 125 // synchronously since the GPU process will need it to initialize the |
123 // graphics state. | 126 // graphics state. |
124 base::ThreadRestrictions::ScopedAllowIO allow_io; | 127 base::ThreadRestrictions::ScopedAllowIO allow_io; |
125 primary_drm_device_handle_.reset(new DrmDeviceHandle()); | 128 primary_drm_device_handle_.reset(new DrmDeviceHandle()); |
126 if (!primary_drm_device_handle_->Initialize(primary_graphics_card_path_)) { | 129 if (!primary_drm_device_handle_->Initialize(primary_graphics_card_path_)) { |
127 LOG(FATAL) << "Failed to open primary graphics card"; | 130 LOG(FATAL) << "Failed to open primary graphics card"; |
128 return; | 131 return; |
129 } | 132 } |
130 drm_devices_.insert(primary_graphics_card_path_); | 133 drm_devices_.insert(primary_graphics_card_path_); |
131 | 134 |
135 int duped_handle = HANDLE_EINTR(dup(primary_drm_device_handle_->GetFD())); | |
136 if (duped_handle < 0) | |
137 LOG(FATAL) << "Failed to dup primary graphics card for renderer"; | |
138 primary_drm_device_file_.reset(duped_handle); | |
139 | |
132 vgem_card_path_ = GetVgemCardPath(); | 140 vgem_card_path_ = GetVgemCardPath(); |
133 if (!vgem_card_path_.empty()) { | 141 if (!vgem_card_path_.empty()) { |
134 int fd = HANDLE_EINTR( | 142 int fd = HANDLE_EINTR( |
135 open(vgem_card_path_.value().c_str(), O_RDWR | O_CLOEXEC)); | 143 open(vgem_card_path_.value().c_str(), O_RDWR | O_CLOEXEC)); |
136 if (fd < 0) { | 144 if (fd < 0) { |
137 PLOG(ERROR) << "Failed to open vgem: " << vgem_card_path_.value(); | 145 PLOG(ERROR) << "Failed to open vgem: " << vgem_card_path_.value(); |
138 } | 146 } |
139 vgem_card_device_file_.reset(fd); | 147 vgem_card_device_file_.reset(fd); |
140 } | 148 } |
141 } | 149 } |
142 | 150 |
143 device_manager_->AddObserver(this); | 151 device_manager_->AddObserver(this); |
144 proxy_->RegisterHandler(this); | 152 proxy_->RegisterHandler(this); |
145 | 153 |
146 ScopedVector<HardwareDisplayControllerInfo> display_infos = | 154 ScopedVector<HardwareDisplayControllerInfo> display_infos = |
147 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); | 155 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); |
148 has_dummy_display_ = !display_infos.empty(); | 156 has_dummy_display_ = !display_infos.empty(); |
149 for (size_t i = 0; i < display_infos.size(); ++i) { | 157 for (size_t i = 0; i < display_infos.size(); ++i) { |
150 displays_.push_back(new DrmDisplayHost( | 158 displays_.push_back(new DrmDisplayHost( |
151 proxy_, CreateDisplaySnapshotParams(display_infos[i], | 159 proxy_, CreateDisplaySnapshotParams(display_infos[i], |
152 primary_drm_device_handle_->fd(), i, | 160 primary_drm_device_handle_->fd(), i, |
153 gfx::Point()), | 161 gfx::Point()), |
154 true /* is_dummy */)); | 162 true /* is_dummy */)); |
155 } | 163 } |
156 } | 164 } |
157 | 165 |
158 base::FileDescriptor DrmDisplayHostManager::DupVgemFd() { | 166 base::FileDescriptor DrmDisplayHostManager::DupVgemFd() { |
159 if (vgem_card_path_.empty()) | 167 int device_fd = vgem_card_device_file_.get(); |
168 base::FilePath* device_path = &vgem_card_path_; | |
169 | |
170 bool enable_intel_drm = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
171 switches::kOzoneUseIntelDrm); | |
172 if (enable_intel_drm) { | |
173 device_fd = primary_drm_device_file_.get(); | |
dshwang
2015/06/29 17:42:07
When --ozone-use-intel-drm, "/dev/dri/card0" is se
| |
174 device_path = &primary_graphics_card_path_; | |
175 } | |
176 | |
177 if (device_path->empty()) | |
160 return base::FileDescriptor(); | 178 return base::FileDescriptor(); |
161 | 179 |
162 int duped_handle = -1; | 180 int duped_handle = -1; |
163 { | 181 { |
164 base::ThreadRestrictions::ScopedAllowIO allow_io; | 182 base::ThreadRestrictions::ScopedAllowIO allow_io; |
165 duped_handle = HANDLE_EINTR(dup(vgem_card_device_file_.get())); | 183 duped_handle = HANDLE_EINTR(dup(device_fd)); |
166 } | 184 } |
167 if (duped_handle < 0) { | 185 if (duped_handle < 0) { |
168 PLOG(ERROR) << "dup() failed."; | 186 PLOG(ERROR) << "dup() failed."; |
169 return base::FileDescriptor(); | 187 return base::FileDescriptor(); |
170 } | 188 } |
171 | 189 |
172 return base::FileDescriptor(duped_handle, true); | 190 return base::FileDescriptor(duped_handle, true); |
173 } | 191 } |
174 | 192 |
175 DrmDisplayHostManager::~DrmDisplayHostManager() { | 193 DrmDisplayHostManager::~DrmDisplayHostManager() { |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 | 509 |
492 callback.Run(snapshots); | 510 callback.Run(snapshots); |
493 } | 511 } |
494 | 512 |
495 void DrmDisplayHostManager::NotifyDisplayDelegate() const { | 513 void DrmDisplayHostManager::NotifyDisplayDelegate() const { |
496 if (delegate_) | 514 if (delegate_) |
497 delegate_->OnConfigurationChanged(); | 515 delegate_->OnConfigurationChanged(); |
498 } | 516 } |
499 | 517 |
500 } // namespace ui | 518 } // namespace ui |
OLD | NEW |