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> |
11 | 11 |
12 #include "ui/display/util/edid_parser.h" | |
13 | |
14 #if !defined(DRM_MODE_CONNECTOR_DSI) | |
15 #define DRM_MODE_CONNECTOR_DSI 16 | |
16 #endif | |
17 | |
12 namespace ui { | 18 namespace ui { |
13 | 19 |
14 namespace { | 20 namespace { |
15 | 21 |
16 bool IsCrtcInUse(uint32_t crtc, | 22 bool IsCrtcInUse(uint32_t crtc, |
17 const ScopedVector<HardwareDisplayControllerInfo>& displays) { | 23 const ScopedVector<HardwareDisplayControllerInfo>& displays) { |
18 for (size_t i = 0; i < displays.size(); ++i) { | 24 for (size_t i = 0; i < displays.size(); ++i) { |
19 if (crtc == displays[i]->crtc()->crtc_id) | 25 if (crtc == displays[i]->crtc()->crtc_id) |
20 return true; | 26 return true; |
21 } | 27 } |
(...skipping 24 matching lines...) Expand all Loading... | |
46 IsCrtcInUse(resources->crtcs[j], displays)) | 52 IsCrtcInUse(resources->crtcs[j], displays)) |
47 continue; | 53 continue; |
48 | 54 |
49 return resources->crtcs[j]; | 55 return resources->crtcs[j]; |
50 } | 56 } |
51 } | 57 } |
52 | 58 |
53 return 0; | 59 return 0; |
54 } | 60 } |
55 | 61 |
62 float GetRefreshRate(const drmModeModeInfo& mode) { | |
spang
2015/05/12 16:58:53
Please describe why vrefresh is sometimes used and
dnicoara
2015/05/12 18:05:02
Done.
| |
63 if (!mode.htotal || !mode.vtotal) | |
64 return mode.vrefresh; | |
65 | |
66 float clock = mode.clock; | |
67 float htotal = mode.htotal; | |
68 float vtotal = mode.vtotal; | |
69 | |
70 return (clock * 1000.0f) / (htotal * vtotal); | |
71 } | |
72 | |
73 DisplayConnectionType GetDisplayType(drmModeConnector* connector) { | |
74 switch (connector->connector_type) { | |
75 case DRM_MODE_CONNECTOR_VGA: | |
76 return DISPLAY_CONNECTION_TYPE_VGA; | |
77 case DRM_MODE_CONNECTOR_DVII: | |
78 case DRM_MODE_CONNECTOR_DVID: | |
79 case DRM_MODE_CONNECTOR_DVIA: | |
80 return DISPLAY_CONNECTION_TYPE_DVI; | |
81 case DRM_MODE_CONNECTOR_LVDS: | |
82 case DRM_MODE_CONNECTOR_eDP: | |
83 case DRM_MODE_CONNECTOR_DSI: | |
84 return DISPLAY_CONNECTION_TYPE_INTERNAL; | |
85 case DRM_MODE_CONNECTOR_DisplayPort: | |
86 return DISPLAY_CONNECTION_TYPE_DISPLAYPORT; | |
87 case DRM_MODE_CONNECTOR_HDMIA: | |
88 case DRM_MODE_CONNECTOR_HDMIB: | |
89 return DISPLAY_CONNECTION_TYPE_HDMI; | |
90 default: | |
91 return DISPLAY_CONNECTION_TYPE_UNKNOWN; | |
92 } | |
93 } | |
94 | |
95 int GetDrmProperty(int fd, | |
96 drmModeConnector* connector, | |
97 const std::string& name, | |
98 ScopedDrmPropertyPtr* property) { | |
99 for (int i = 0; i < connector->count_props; ++i) { | |
100 ScopedDrmPropertyPtr tmp(drmModeGetProperty(fd, connector->props[i])); | |
101 if (!tmp) | |
102 continue; | |
103 | |
104 if (name == tmp->name) { | |
105 *property = tmp.Pass(); | |
106 return i; | |
107 } | |
108 } | |
109 | |
110 return -1; | |
111 } | |
112 | |
113 ScopedDrmPropertyBlobPtr GetDrmPropertyBlob(int fd, | |
114 drmModeConnector* connector, | |
115 const std::string& name) { | |
116 ScopedDrmPropertyPtr property; | |
117 int index = GetDrmProperty(fd, connector, name, &property); | |
118 if (index < 0) | |
119 return nullptr; | |
120 | |
121 if (property->flags & DRM_MODE_PROP_BLOB) { | |
122 return ScopedDrmPropertyBlobPtr( | |
123 drmModeGetPropertyBlob(fd, connector->prop_values[index])); | |
124 } | |
125 | |
126 return nullptr; | |
127 } | |
128 | |
129 bool IsAspectPreserving(int fd, drmModeConnector* connector) { | |
130 ScopedDrmPropertyPtr property; | |
131 int index = GetDrmProperty(fd, connector, "scaling mode", &property); | |
132 if (index < 0) | |
133 return false; | |
134 | |
135 for (int enums_i = 0; enums_i < property->count_enums; ++enums_i) { | |
136 if (property->enums[enums_i].value == connector->prop_values[index] && | |
137 strcmp(property->enums[enums_i].name, "Full aspect") == 0) | |
138 return true; | |
139 } | |
140 | |
141 return false; | |
142 } | |
143 | |
56 } // namespace | 144 } // namespace |
57 | 145 |
58 HardwareDisplayControllerInfo::HardwareDisplayControllerInfo( | 146 HardwareDisplayControllerInfo::HardwareDisplayControllerInfo( |
59 ScopedDrmConnectorPtr connector, | 147 ScopedDrmConnectorPtr connector, |
60 ScopedDrmCrtcPtr crtc) | 148 ScopedDrmCrtcPtr crtc) |
61 : connector_(connector.Pass()), crtc_(crtc.Pass()) { | 149 : connector_(connector.Pass()), crtc_(crtc.Pass()) { |
62 } | 150 } |
63 | 151 |
64 HardwareDisplayControllerInfo::~HardwareDisplayControllerInfo() { | 152 HardwareDisplayControllerInfo::~HardwareDisplayControllerInfo() { |
65 } | 153 } |
(...skipping 27 matching lines...) Expand all Loading... | |
93 bool SameMode(const drmModeModeInfo& lhs, const drmModeModeInfo& rhs) { | 181 bool SameMode(const drmModeModeInfo& lhs, const drmModeModeInfo& rhs) { |
94 return lhs.clock == rhs.clock && lhs.hdisplay == rhs.hdisplay && | 182 return lhs.clock == rhs.clock && lhs.hdisplay == rhs.hdisplay && |
95 lhs.vdisplay == rhs.vdisplay && lhs.vrefresh == rhs.vrefresh && | 183 lhs.vdisplay == rhs.vdisplay && lhs.vrefresh == rhs.vrefresh && |
96 lhs.hsync_start == rhs.hsync_start && lhs.hsync_end == rhs.hsync_end && | 184 lhs.hsync_start == rhs.hsync_start && lhs.hsync_end == rhs.hsync_end && |
97 lhs.htotal == rhs.htotal && lhs.hskew == rhs.hskew && | 185 lhs.htotal == rhs.htotal && lhs.hskew == rhs.hskew && |
98 lhs.vsync_start == rhs.vsync_start && lhs.vsync_end == rhs.vsync_end && | 186 lhs.vsync_start == rhs.vsync_start && lhs.vsync_end == rhs.vsync_end && |
99 lhs.vtotal == rhs.vtotal && lhs.vscan == rhs.vscan && | 187 lhs.vtotal == rhs.vtotal && lhs.vscan == rhs.vscan && |
100 lhs.flags == rhs.flags && strcmp(lhs.name, rhs.name) == 0; | 188 lhs.flags == rhs.flags && strcmp(lhs.name, rhs.name) == 0; |
101 } | 189 } |
102 | 190 |
191 DisplayMode_Params CreateDisplayModeParams(const drmModeModeInfo& mode) { | |
192 DisplayMode_Params params; | |
193 params.size = gfx::Size(mode.hdisplay, mode.vdisplay); | |
194 params.is_interlaced = mode.flags & DRM_MODE_FLAG_INTERLACE; | |
195 params.refresh_rate = GetRefreshRate(mode); | |
196 | |
197 return params; | |
198 } | |
199 | |
200 DisplaySnapshot_Params CreateDisplaySnapshotParams( | |
201 HardwareDisplayControllerInfo* info, | |
202 int fd, | |
203 size_t index) { | |
204 DisplaySnapshot_Params params; | |
205 params.display_id = index; | |
206 params.physical_size = | |
207 gfx::Size(info->connector()->mmWidth, info->connector()->mmHeight); | |
208 params.type = GetDisplayType(info->connector()); | |
209 params.is_aspect_preserving_scaling = | |
210 IsAspectPreserving(fd, info->connector()); | |
211 | |
212 ScopedDrmPropertyBlobPtr edid_blob( | |
213 GetDrmPropertyBlob(fd, info->connector(), "EDID")); | |
214 | |
215 if (edid_blob) { | |
216 std::vector<uint8_t> edid( | |
217 static_cast<uint8_t*>(edid_blob->data), | |
218 static_cast<uint8_t*>(edid_blob->data) + edid_blob->length); | |
219 | |
220 if (!GetDisplayIdFromEDID(edid, index, ¶ms.display_id)) | |
221 params.display_id = index; | |
222 | |
223 ParseOutputDeviceData(edid, nullptr, ¶ms.display_name, nullptr, | |
224 nullptr); | |
225 ParseOutputOverscanFlag(edid, ¶ms.has_overscan); | |
226 } else { | |
227 VLOG(1) << "Failed to get EDID blob for connector " | |
228 << info->connector()->connector_id; | |
229 } | |
230 | |
231 for (int i = 0; i < info->connector()->count_modes; ++i) { | |
232 const drmModeModeInfo& mode = info->connector()->modes[i]; | |
233 params.modes.push_back(CreateDisplayModeParams(mode)); | |
234 | |
235 if (info->crtc()->mode_valid && SameMode(info->crtc()->mode, mode)) { | |
236 params.has_current_mode = true; | |
237 params.current_mode = params.modes.back(); | |
238 } | |
239 | |
240 if (mode.type & DRM_MODE_TYPE_PREFERRED) { | |
241 params.has_native_mode = true; | |
242 params.native_mode = params.modes.back(); | |
243 } | |
244 } | |
245 | |
246 // If no preferred mode is found then use the first one. Using the first one | |
247 // since it should be the best mode. | |
248 if (!params.has_native_mode && !params.modes.empty()) { | |
249 params.has_native_mode = true; | |
250 params.native_mode = params.modes.front(); | |
251 } | |
252 | |
253 return params; | |
254 } | |
255 | |
103 } // namespace ui | 256 } // namespace ui |
OLD | NEW |