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 namespace ui { | 16 namespace ui { |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
20 const char kDefaultGraphicsCardPattern[] = "/dev/dri/card%d"; | |
21 | |
18 bool IsCrtcInUse(uint32_t crtc, | 22 bool IsCrtcInUse(uint32_t crtc, |
19 const ScopedVector<HardwareDisplayControllerInfo>& displays) { | 23 const ScopedVector<HardwareDisplayControllerInfo>& displays) { |
20 for (size_t i = 0; i < displays.size(); ++i) { | 24 for (size_t i = 0; i < displays.size(); ++i) { |
21 if (crtc == displays[i]->crtc()->crtc_id) | 25 if (crtc == displays[i]->crtc()->crtc_id) |
22 return true; | 26 return true; |
23 } | 27 } |
24 | 28 |
25 return false; | 29 return false; |
26 } | 30 } |
27 | 31 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 fd, | 132 fd, |
129 map_request.offset); | 133 map_request.offset); |
130 if (*pixels == MAP_FAILED) { | 134 if (*pixels == MAP_FAILED) { |
131 VLOG(2) << "Cannot mmap dumb buffer (" << errno << ") " << strerror(errno); | 135 VLOG(2) << "Cannot mmap dumb buffer (" << errno << ") " << strerror(errno); |
132 return false; | 136 return false; |
133 } | 137 } |
134 | 138 |
135 return true; | 139 return true; |
136 } | 140 } |
137 | 141 |
142 int OpenFirstDisplayCard() { | |
143 struct drm_mode_card_res res; | |
144 for (int i = 0; /* end on first card# that does not exist */; i++) { | |
145 std::string card_path = base::StringPrintf(kDefaultGraphicsCardPattern, i); | |
146 | |
147 if (access(card_path.c_str(), F_OK) != 0) | |
148 break; | |
149 | |
150 int fd = open(card_path.c_str(), O_RDWR | O_CLOEXEC); | |
151 if (fd < 0) | |
152 continue; | |
153 | |
154 memset(&res, 0, sizeof(struct drm_mode_card_res)); | |
155 int ret = drmIoctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res); | |
marcheu
2015/02/13 04:34:42
I'm going to nitpick. In some cases, we can have a
Zach Reizner
2015/02/13 18:45:15
I agree.
| |
156 if (ret == 0) { | |
157 return fd; | |
158 } | |
159 | |
160 close(fd); | |
161 } | |
162 | |
163 return -1; | |
164 } | |
165 | |
138 } // namespace ui | 166 } // namespace ui |
OLD | NEW |