Index: ui/ozone/platform/drm/common/drm_util.cc |
diff --git a/ui/ozone/platform/drm/common/drm_util.cc b/ui/ozone/platform/drm/common/drm_util.cc |
index f85e3cd9c99d98c48255851d085a3d5627cf4e0f..4c44ee55028c5bcc668394c56d44f3acd1f2b572 100644 |
--- a/ui/ozone/platform/drm/common/drm_util.cc |
+++ b/ui/ozone/platform/drm/common/drm_util.cc |
@@ -9,6 +9,12 @@ |
#include <sys/mman.h> |
#include <xf86drmMode.h> |
+#include "ui/display/util/edid_parser.h" |
+ |
+#if !defined(DRM_MODE_CONNECTOR_DSI) |
+#define DRM_MODE_CONNECTOR_DSI 16 |
+#endif |
+ |
namespace ui { |
namespace { |
@@ -53,6 +59,89 @@ uint32_t GetCrtc(int fd, |
return 0; |
} |
+float GetRefreshRate(const drmModeModeInfo& mode) { |
+ if (!mode.htotal || !mode.vtotal) |
+ return mode.vrefresh; |
+ |
+ float clock = mode.clock; |
+ float htotal = mode.htotal; |
+ float vtotal = mode.vtotal; |
+ |
+ return (clock * 1000.0f) / (htotal * vtotal); |
+} |
+ |
+DisplayConnectionType GetDisplayType(drmModeConnector* connector) { |
+ switch (connector->connector_type) { |
+ case DRM_MODE_CONNECTOR_VGA: |
+ return DISPLAY_CONNECTION_TYPE_VGA; |
+ case DRM_MODE_CONNECTOR_DVII: |
+ case DRM_MODE_CONNECTOR_DVID: |
+ case DRM_MODE_CONNECTOR_DVIA: |
+ return DISPLAY_CONNECTION_TYPE_DVI; |
+ case DRM_MODE_CONNECTOR_LVDS: |
+ case DRM_MODE_CONNECTOR_eDP: |
+ case DRM_MODE_CONNECTOR_DSI: |
+ return DISPLAY_CONNECTION_TYPE_INTERNAL; |
+ case DRM_MODE_CONNECTOR_DisplayPort: |
+ return DISPLAY_CONNECTION_TYPE_DISPLAYPORT; |
+ case DRM_MODE_CONNECTOR_HDMIA: |
+ case DRM_MODE_CONNECTOR_HDMIB: |
+ return DISPLAY_CONNECTION_TYPE_HDMI; |
+ default: |
+ return DISPLAY_CONNECTION_TYPE_UNKNOWN; |
+ } |
+} |
+ |
+ScopedDrmPropertyPtr GetDrmProperty(int fd, |
+ drmModeConnector* connector, |
+ const std::string& name) { |
+ for (int i = 0; i < connector->count_props; ++i) { |
spang
2015/05/11 22:21:32
How come we don't remember the property ids anywhe
dnicoara
2015/05/12 15:17:10
They can change between display events and we only
spang
2015/05/12 16:58:53
I don't think the ids can change. It looks like th
dnicoara
2015/05/12 18:05:02
From what I can tell (at least for the standard pr
spang
2015/05/12 18:28:48
If it changes and chrome breaks for a device it wo
|
+ ScopedDrmPropertyPtr property(drmModeGetProperty(fd, connector->props[i])); |
+ if (!property) |
+ continue; |
+ |
+ if (name == property->name) |
+ return property.Pass(); |
+ } |
+ |
+ return ScopedDrmPropertyPtr(); |
+} |
+ |
+ScopedDrmPropertyBlobPtr GetDrmPropertyBlob(int fd, |
+ drmModeConnector* connector, |
+ const std::string& name) { |
+ for (int i = 0; i < connector->count_props; ++i) { |
+ ScopedDrmPropertyPtr property(drmModeGetProperty(fd, connector->props[i])); |
+ if (!property) |
+ continue; |
+ |
+ if (name == property->name && property->flags & DRM_MODE_PROP_BLOB) |
spang
2015/05/11 22:21:32
Can you add another pair of parenthesis here aroun
dnicoara
2015/05/12 15:17:10
Simplified, so I don't think it should matter anym
|
+ return ScopedDrmPropertyBlobPtr( |
+ drmModeGetPropertyBlob(fd, connector->prop_values[i])); |
+ } |
+ |
+ return ScopedDrmPropertyBlobPtr(); |
+} |
+ |
+bool IsAspectPreserving(int fd, drmModeConnector* connector) { |
+ ScopedDrmPropertyPtr property(GetDrmProperty(fd, connector, "scaling mode")); |
+ if (!property) |
+ return false; |
+ |
+ for (int props_i = 0; props_i < connector->count_props; ++props_i) { |
spang
2015/05/11 22:21:32
Could GetDrmProperty return the index instead of f
dnicoara
2015/05/12 15:17:10
Done.
|
+ if (connector->props[props_i] != property->prop_id) |
+ continue; |
+ |
+ for (int enums_i = 0; enums_i < property->count_enums; ++enums_i) { |
spang
2015/05/11 22:21:32
There's too much going on here. Please factor this
dnicoara
2015/05/12 15:17:10
Now that the outer for-loop is gone this should be
spang
2015/05/12 16:58:53
I still think it would be more obvious what it doe
dnicoara
2015/05/12 18:05:02
Done.
|
+ if (property->enums[enums_i].value == connector->prop_values[props_i] && |
+ strcmp(property->enums[enums_i].name, "Full aspect") == 0) |
+ return true; |
+ } |
+ } |
+ |
+ return false; |
+} |
+ |
} // namespace |
HardwareDisplayControllerInfo::HardwareDisplayControllerInfo( |
@@ -100,4 +189,68 @@ bool SameMode(const drmModeModeInfo& lhs, const drmModeModeInfo& rhs) { |
lhs.flags == rhs.flags && strcmp(lhs.name, rhs.name) == 0; |
} |
+DisplayMode_Params ParseDrmMode(const drmModeModeInfo& mode) { |
+ DisplayMode_Params params; |
+ params.size = gfx::Size(mode.hdisplay, mode.vdisplay); |
+ params.is_interlaced = mode.flags & DRM_MODE_FLAG_INTERLACE; |
+ params.refresh_rate = GetRefreshRate(mode); |
+ |
+ return params; |
+} |
+ |
+DisplaySnapshot_Params ParseDrmDisplay(HardwareDisplayControllerInfo* info, |
+ int fd, |
+ size_t index) { |
+ DisplaySnapshot_Params params; |
+ params.display_id = index; |
+ params.physical_size = |
+ gfx::Size(info->connector()->mmWidth, info->connector()->mmHeight); |
+ params.type = GetDisplayType(info->connector()); |
+ params.is_aspect_preserving_scaling = |
+ IsAspectPreserving(fd, info->connector()); |
+ |
+ ScopedDrmPropertyBlobPtr edid_blob( |
+ GetDrmPropertyBlob(fd, info->connector(), "EDID")); |
+ |
+ if (edid_blob) { |
+ std::vector<uint8_t> edid( |
+ static_cast<uint8_t*>(edid_blob->data), |
+ static_cast<uint8_t*>(edid_blob->data) + edid_blob->length); |
+ |
+ if (!GetDisplayIdFromEDID(edid, index, ¶ms.display_id)) |
+ params.display_id = index; |
+ |
+ ParseOutputDeviceData(edid, nullptr, ¶ms.display_name, nullptr, |
+ nullptr); |
+ ParseOutputOverscanFlag(edid, ¶ms.has_overscan); |
+ } else { |
+ VLOG(1) << "Failed to get EDID blob for connector " |
+ << info->connector()->connector_id; |
+ } |
+ |
+ for (int i = 0; i < info->connector()->count_modes; ++i) { |
+ drmModeModeInfo& mode = info->connector()->modes[i]; |
spang
2015/05/11 22:21:32
Google style guide only allows const & and *
dnicoara
2015/05/12 15:17:10
Oops, done.
|
+ params.modes.push_back(ParseDrmMode(mode)); |
+ |
+ if (info->crtc()->mode_valid && SameMode(info->crtc()->mode, mode)) { |
+ params.has_current_mode = true; |
+ params.current_mode = params.modes.back(); |
+ } |
+ |
+ if (mode.type & DRM_MODE_TYPE_PREFERRED) { |
+ params.has_native_mode = true; |
+ params.native_mode = params.modes.back(); |
+ } |
+ } |
+ |
+ // If no preferred mode is found then use the first one. Using the first one |
+ // since it should be the best mode. |
+ if (!params.has_native_mode && !params.modes.empty()) { |
+ params.has_native_mode = true; |
+ params.native_mode = params.modes.front(); |
+ } |
+ |
+ return params; |
+} |
+ |
} // namespace ui |