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/common/drm_util.h" | 5 #include "ui/ozone/platform/drm/common/drm_util.h" |
6 | 6 |
7 #include <drm_fourcc.h> | 7 #include <drm_fourcc.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
11 #include <xf86drmMode.h> | 11 #include <xf86drmMode.h> |
| 12 #include <utility> |
12 | 13 |
13 #include "ui/display/util/edid_parser.h" | 14 #include "ui/display/util/edid_parser.h" |
14 | 15 |
15 #if !defined(DRM_MODE_CONNECTOR_DSI) | 16 #if !defined(DRM_MODE_CONNECTOR_DSI) |
16 #define DRM_MODE_CONNECTOR_DSI 16 | 17 #define DRM_MODE_CONNECTOR_DSI 16 |
17 #endif | 18 #endif |
18 | 19 |
19 namespace ui { | 20 namespace ui { |
20 | 21 |
21 namespace { | 22 namespace { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 int GetDrmProperty(int fd, | 102 int GetDrmProperty(int fd, |
102 drmModeConnector* connector, | 103 drmModeConnector* connector, |
103 const std::string& name, | 104 const std::string& name, |
104 ScopedDrmPropertyPtr* property) { | 105 ScopedDrmPropertyPtr* property) { |
105 for (int i = 0; i < connector->count_props; ++i) { | 106 for (int i = 0; i < connector->count_props; ++i) { |
106 ScopedDrmPropertyPtr tmp(drmModeGetProperty(fd, connector->props[i])); | 107 ScopedDrmPropertyPtr tmp(drmModeGetProperty(fd, connector->props[i])); |
107 if (!tmp) | 108 if (!tmp) |
108 continue; | 109 continue; |
109 | 110 |
110 if (name == tmp->name) { | 111 if (name == tmp->name) { |
111 *property = tmp.Pass(); | 112 *property = std::move(tmp); |
112 return i; | 113 return i; |
113 } | 114 } |
114 } | 115 } |
115 | 116 |
116 return -1; | 117 return -1; |
117 } | 118 } |
118 | 119 |
119 std::string GetNameForEnumValue(drmModePropertyRes* property, uint32_t value) { | 120 std::string GetNameForEnumValue(drmModePropertyRes* property, uint32_t value) { |
120 for (int i = 0; i < property->count_enums; ++i) | 121 for (int i = 0; i < property->count_enums; ++i) |
121 if (property->enums[i].value == value) | 122 if (property->enums[i].value == value) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 DCHECK_LT(display_index, 16); | 156 DCHECK_LT(display_index, 16); |
156 return ((device_index << 4) + display_index) & 0xFF; | 157 return ((device_index << 4) + display_index) & 0xFF; |
157 } | 158 } |
158 | 159 |
159 } // namespace | 160 } // namespace |
160 | 161 |
161 HardwareDisplayControllerInfo::HardwareDisplayControllerInfo( | 162 HardwareDisplayControllerInfo::HardwareDisplayControllerInfo( |
162 ScopedDrmConnectorPtr connector, | 163 ScopedDrmConnectorPtr connector, |
163 ScopedDrmCrtcPtr crtc, | 164 ScopedDrmCrtcPtr crtc, |
164 size_t index) | 165 size_t index) |
165 : connector_(connector.Pass()), crtc_(crtc.Pass()), index_(index) {} | 166 : connector_(std::move(connector)), crtc_(std::move(crtc)), index_(index) {} |
166 | 167 |
167 HardwareDisplayControllerInfo::~HardwareDisplayControllerInfo() { | 168 HardwareDisplayControllerInfo::~HardwareDisplayControllerInfo() { |
168 } | 169 } |
169 | 170 |
170 ScopedVector<HardwareDisplayControllerInfo> GetAvailableDisplayControllerInfos( | 171 ScopedVector<HardwareDisplayControllerInfo> GetAvailableDisplayControllerInfos( |
171 int fd) { | 172 int fd) { |
172 ScopedDrmResourcesPtr resources(drmModeGetResources(fd)); | 173 ScopedDrmResourcesPtr resources(drmModeGetResources(fd)); |
173 DCHECK(resources) << "Failed to get DRM resources"; | 174 DCHECK(resources) << "Failed to get DRM resources"; |
174 ScopedVector<HardwareDisplayControllerInfo> displays; | 175 ScopedVector<HardwareDisplayControllerInfo> displays; |
175 | 176 |
176 for (int i = 0; i < resources->count_connectors; ++i) { | 177 for (int i = 0; i < resources->count_connectors; ++i) { |
177 ScopedDrmConnectorPtr connector( | 178 ScopedDrmConnectorPtr connector( |
178 drmModeGetConnector(fd, resources->connectors[i])); | 179 drmModeGetConnector(fd, resources->connectors[i])); |
179 | 180 |
180 if (!connector || connector->connection != DRM_MODE_CONNECTED || | 181 if (!connector || connector->connection != DRM_MODE_CONNECTED || |
181 connector->count_modes == 0) | 182 connector->count_modes == 0) |
182 continue; | 183 continue; |
183 | 184 |
184 uint32_t crtc_id = GetCrtc(fd, connector.get(), resources.get(), displays); | 185 uint32_t crtc_id = GetCrtc(fd, connector.get(), resources.get(), displays); |
185 if (!crtc_id) | 186 if (!crtc_id) |
186 continue; | 187 continue; |
187 | 188 |
188 ScopedDrmCrtcPtr crtc(drmModeGetCrtc(fd, crtc_id)); | 189 ScopedDrmCrtcPtr crtc(drmModeGetCrtc(fd, crtc_id)); |
189 displays.push_back( | 190 displays.push_back(new HardwareDisplayControllerInfo(std::move(connector), |
190 new HardwareDisplayControllerInfo(connector.Pass(), crtc.Pass(), i)); | 191 std::move(crtc), i)); |
191 } | 192 } |
192 | 193 |
193 return displays.Pass(); | 194 return displays; |
194 } | 195 } |
195 | 196 |
196 bool SameMode(const drmModeModeInfo& lhs, const drmModeModeInfo& rhs) { | 197 bool SameMode(const drmModeModeInfo& lhs, const drmModeModeInfo& rhs) { |
197 return lhs.clock == rhs.clock && lhs.hdisplay == rhs.hdisplay && | 198 return lhs.clock == rhs.clock && lhs.hdisplay == rhs.hdisplay && |
198 lhs.vdisplay == rhs.vdisplay && lhs.vrefresh == rhs.vrefresh && | 199 lhs.vdisplay == rhs.vdisplay && lhs.vrefresh == rhs.vrefresh && |
199 lhs.hsync_start == rhs.hsync_start && lhs.hsync_end == rhs.hsync_end && | 200 lhs.hsync_start == rhs.hsync_start && lhs.hsync_end == rhs.hsync_end && |
200 lhs.htotal == rhs.htotal && lhs.hskew == rhs.hskew && | 201 lhs.htotal == rhs.htotal && lhs.hskew == rhs.hskew && |
201 lhs.vsync_start == rhs.vsync_start && lhs.vsync_end == rhs.vsync_end && | 202 lhs.vsync_start == rhs.vsync_start && lhs.vsync_end == rhs.vsync_end && |
202 lhs.vtotal == rhs.vtotal && lhs.vscan == rhs.vscan && | 203 lhs.vtotal == rhs.vtotal && lhs.vscan == rhs.vscan && |
203 lhs.flags == rhs.flags && strcmp(lhs.name, rhs.name) == 0; | 204 lhs.flags == rhs.flags && strcmp(lhs.name, rhs.name) == 0; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 case DRM_FORMAT_XRGB8888: | 293 case DRM_FORMAT_XRGB8888: |
293 return gfx::BufferFormat::BGRX_8888; | 294 return gfx::BufferFormat::BGRX_8888; |
294 case DRM_FORMAT_UYVY: | 295 case DRM_FORMAT_UYVY: |
295 return gfx::BufferFormat::UYVY_422; | 296 return gfx::BufferFormat::UYVY_422; |
296 default: | 297 default: |
297 NOTREACHED(); | 298 NOTREACHED(); |
298 return gfx::BufferFormat::BGRA_8888; | 299 return gfx::BufferFormat::BGRA_8888; |
299 } | 300 } |
300 } | 301 } |
301 } // namespace ui | 302 } // namespace ui |
OLD | NEW |