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 "base/strings/stringprintf.h" |
5 #include "ui/ozone/platform/dri/dri_util.h" | 6 #include "ui/ozone/platform/dri/dri_util.h" |
6 | 7 |
7 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> |
8 #include <stdint.h> | 10 #include <stdint.h> |
9 #include <stdlib.h> | 11 #include <stdlib.h> |
10 #include <sys/mman.h> | 12 #include <sys/mman.h> |
11 #include <xf86drm.h> | 13 #include <xf86drm.h> |
12 #include <xf86drmMode.h> | 14 #include <xf86drmMode.h> |
13 | 15 |
14 #include "ui/ozone/platform/dri/dri_wrapper.h" | 16 #include "ui/ozone/platform/dri/dri_wrapper.h" |
15 #include "ui/ozone/platform/dri/screen_manager.h" | 17 #include "ui/ozone/platform/dri/screen_manager.h" |
16 | 18 |
17 namespace ui { | 19 namespace ui { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
| 23 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; |
| 24 |
21 bool IsCrtcInUse(uint32_t crtc, | 25 bool IsCrtcInUse(uint32_t crtc, |
22 const ScopedVector<HardwareDisplayControllerInfo>& displays) { | 26 const ScopedVector<HardwareDisplayControllerInfo>& displays) { |
23 for (size_t i = 0; i < displays.size(); ++i) { | 27 for (size_t i = 0; i < displays.size(); ++i) { |
24 if (crtc == displays[i]->crtc()->crtc_id) | 28 if (crtc == displays[i]->crtc()->crtc_id) |
25 return true; | 29 return true; |
26 } | 30 } |
27 | 31 |
28 return false; | 32 return false; |
29 } | 33 } |
30 | 34 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (screen_manager->ConfigureDisplayController( | 158 if (screen_manager->ConfigureDisplayController( |
155 drm, displays[0]->crtc()->crtc_id, | 159 drm, displays[0]->crtc()->crtc_id, |
156 displays[0]->connector()->connector_id, gfx::Point(), | 160 displays[0]->connector()->connector_id, gfx::Point(), |
157 displays[0]->connector()->modes[0])) { | 161 displays[0]->connector()->modes[0])) { |
158 if (dpms) | 162 if (dpms) |
159 drm->SetProperty(displays[0]->connector()->connector_id, dpms->prop_id, | 163 drm->SetProperty(displays[0]->connector()->connector_id, dpms->prop_id, |
160 DRM_MODE_DPMS_ON); | 164 DRM_MODE_DPMS_ON); |
161 } | 165 } |
162 } | 166 } |
163 | 167 |
| 168 base::FilePath GetFirstDisplayCardPath() { |
| 169 struct drm_mode_card_res res; |
| 170 for (int i = 0; /* end on first card# that does not exist */; i++) { |
| 171 std::string card_path = base::StringPrintf(kDefaultGraphicsCardPattern, i); |
| 172 |
| 173 if (access(card_path.c_str(), F_OK) != 0) |
| 174 break; |
| 175 |
| 176 int fd = open(card_path.c_str(), O_RDWR | O_CLOEXEC); |
| 177 if (fd < 0) |
| 178 continue; |
| 179 |
| 180 memset(&res, 0, sizeof(struct drm_mode_card_res)); |
| 181 int ret = drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res); |
| 182 close(fd); |
| 183 if (ret == 0 && res.count_crtcs > 0) { |
| 184 return base::FilePath(card_path); |
| 185 } |
| 186 } |
| 187 |
| 188 return base::FilePath(); |
| 189 } |
| 190 |
164 } // namespace ui | 191 } // namespace ui |
OLD | NEW |