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 <stdint.h> | 7 #include <stdint.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <sys/mman.h> | 9 #include <sys/mman.h> |
10 #include <xf86drmMode.h> | 10 #include <xf86drmMode.h> |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 if (name == tmp->name) { | 110 if (name == tmp->name) { |
111 *property = tmp.Pass(); | 111 *property = tmp.Pass(); |
112 return i; | 112 return i; |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 return -1; | 116 return -1; |
117 } | 117 } |
118 | 118 |
119 std::string GetNameForEnumValue(drmModePropertyRes* property, uint32_t value) { | |
120 for (int i = 0; i < property->count_enums; ++i) | |
121 if (property->enums[i].value == value) | |
122 return property->enums[i].name; | |
123 | |
124 return std::string(); | |
125 } | |
126 | |
127 ScopedDrmPropertyBlobPtr GetDrmPropertyBlob(int fd, | 119 ScopedDrmPropertyBlobPtr GetDrmPropertyBlob(int fd, |
128 drmModeConnector* connector, | 120 drmModeConnector* connector, |
129 const std::string& name) { | 121 const std::string& name) { |
130 ScopedDrmPropertyPtr property; | 122 ScopedDrmPropertyPtr property; |
131 int index = GetDrmProperty(fd, connector, name, &property); | 123 int index = GetDrmProperty(fd, connector, name, &property); |
132 if (index < 0) | 124 if (index < 0) |
133 return nullptr; | 125 return nullptr; |
134 | 126 |
135 if (property->flags & DRM_MODE_PROP_BLOB) { | 127 if (property->flags & DRM_MODE_PROP_BLOB) { |
136 return ScopedDrmPropertyBlobPtr( | 128 return ScopedDrmPropertyBlobPtr( |
137 drmModeGetPropertyBlob(fd, connector->prop_values[index])); | 129 drmModeGetPropertyBlob(fd, connector->prop_values[index])); |
138 } | 130 } |
139 | 131 |
140 return nullptr; | 132 return nullptr; |
141 } | 133 } |
142 | 134 |
143 bool IsAspectPreserving(int fd, drmModeConnector* connector) { | |
144 ScopedDrmPropertyPtr property; | |
145 int index = GetDrmProperty(fd, connector, "scaling mode", &property); | |
146 if (index < 0) | |
147 return false; | |
148 | |
149 return (GetNameForEnumValue(property.get(), connector->prop_values[index]) == | |
150 "Full aspect"); | |
151 } | |
152 | |
153 } // namespace | 135 } // namespace |
154 | 136 |
155 HardwareDisplayControllerInfo::HardwareDisplayControllerInfo( | 137 HardwareDisplayControllerInfo::HardwareDisplayControllerInfo( |
156 ScopedDrmConnectorPtr connector, | 138 ScopedDrmConnectorPtr connector, |
157 ScopedDrmCrtcPtr crtc) | 139 ScopedDrmCrtcPtr crtc) |
158 : connector_(connector.Pass()), crtc_(crtc.Pass()) { | 140 : connector_(connector.Pass()), crtc_(crtc.Pass()) { |
159 } | 141 } |
160 | 142 |
161 HardwareDisplayControllerInfo::~HardwareDisplayControllerInfo() { | 143 HardwareDisplayControllerInfo::~HardwareDisplayControllerInfo() { |
162 } | 144 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 HardwareDisplayControllerInfo* info, | 192 HardwareDisplayControllerInfo* info, |
211 int fd, | 193 int fd, |
212 size_t display_index, | 194 size_t display_index, |
213 const gfx::Point& origin) { | 195 const gfx::Point& origin) { |
214 DisplaySnapshot_Params params; | 196 DisplaySnapshot_Params params; |
215 params.display_id = display_index; | 197 params.display_id = display_index; |
216 params.origin = origin; | 198 params.origin = origin; |
217 params.physical_size = | 199 params.physical_size = |
218 gfx::Size(info->connector()->mmWidth, info->connector()->mmHeight); | 200 gfx::Size(info->connector()->mmWidth, info->connector()->mmHeight); |
219 params.type = GetDisplayType(info->connector()); | 201 params.type = GetDisplayType(info->connector()); |
220 params.is_aspect_preserving_scaling = | |
221 IsAspectPreserving(fd, info->connector()); | |
222 | 202 |
223 ScopedDrmPropertyBlobPtr edid_blob( | 203 ScopedDrmPropertyBlobPtr edid_blob( |
224 GetDrmPropertyBlob(fd, info->connector(), "EDID")); | 204 GetDrmPropertyBlob(fd, info->connector(), "EDID")); |
225 | 205 |
226 if (edid_blob) { | 206 if (edid_blob) { |
227 std::vector<uint8_t> edid( | 207 std::vector<uint8_t> edid( |
228 static_cast<uint8_t*>(edid_blob->data), | 208 static_cast<uint8_t*>(edid_blob->data), |
229 static_cast<uint8_t*>(edid_blob->data) + edid_blob->length); | 209 static_cast<uint8_t*>(edid_blob->data) + edid_blob->length); |
230 | 210 |
231 if (!GetDisplayIdFromEDID(edid, display_index, ¶ms.display_id, | 211 if (!GetDisplayIdFromEDID(edid, display_index, ¶ms.display_id, |
232 ¶ms.product_id)) | 212 ¶ms.product_id)) |
233 params.display_id = display_index; | 213 params.display_id = display_index; |
234 | |
235 ParseOutputDeviceData(edid, nullptr, nullptr, ¶ms.display_name, nullptr, | |
236 nullptr); | |
237 ParseOutputOverscanFlag(edid, ¶ms.has_overscan); | |
238 } else { | 214 } else { |
239 VLOG(1) << "Failed to get EDID blob for connector " | 215 VLOG(1) << "Failed to get EDID blob for connector " |
240 << info->connector()->connector_id; | 216 << info->connector()->connector_id; |
241 } | 217 } |
242 | 218 |
243 for (int i = 0; i < info->connector()->count_modes; ++i) { | 219 for (int i = 0; i < info->connector()->count_modes; ++i) { |
244 const drmModeModeInfo& mode = info->connector()->modes[i]; | 220 const drmModeModeInfo& mode = info->connector()->modes[i]; |
245 params.modes.push_back(CreateDisplayModeParams(mode)); | 221 params.modes.push_back(CreateDisplayModeParams(mode)); |
246 | 222 |
247 if (info->crtc()->mode_valid && SameMode(info->crtc()->mode, mode)) { | 223 if (info->crtc()->mode_valid && SameMode(info->crtc()->mode, mode)) { |
(...skipping 11 matching lines...) Expand all Loading... |
259 // since it should be the best mode. | 235 // since it should be the best mode. |
260 if (!params.has_native_mode && !params.modes.empty()) { | 236 if (!params.has_native_mode && !params.modes.empty()) { |
261 params.has_native_mode = true; | 237 params.has_native_mode = true; |
262 params.native_mode = params.modes.front(); | 238 params.native_mode = params.modes.front(); |
263 } | 239 } |
264 | 240 |
265 return params; | 241 return params; |
266 } | 242 } |
267 | 243 |
268 } // namespace ui | 244 } // namespace ui |
OLD | NEW |