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..b81866b19828a308d8c1cfdbe1bcc8a6ed637022 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,96 @@ uint32_t GetCrtc(int fd, |
return 0; |
} |
+// Computes the refresh rate for the specific mode. If we have enough |
+// information use the mode timings to compute a more exact value otherwise |
+// fallback to using the mode's vertical refresh rate (the kernel computes this |
+// the same way, however there is a loss in precision since |vrefresh| is sent |
+// as an integer). |
+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; |
+ } |
+} |
+ |
+int GetDrmProperty(int fd, |
+ drmModeConnector* connector, |
+ const std::string& name, |
+ ScopedDrmPropertyPtr* property) { |
+ for (int i = 0; i < connector->count_props; ++i) { |
+ ScopedDrmPropertyPtr tmp(drmModeGetProperty(fd, connector->props[i])); |
+ if (!tmp) |
+ continue; |
+ |
+ if (name == tmp->name) { |
+ *property = tmp.Pass(); |
+ return i; |
+ } |
+ } |
+ |
+ return -1; |
+} |
+ |
+std::string GetNameForEnumValue(drmModePropertyRes* property, uint32_t value) { |
+ for (int i = 0; i < property->count_enums; ++i) |
+ if (property->enums[i].value == value) |
+ return property->enums[i].name; |
+ |
+ return std::string(); |
+} |
+ |
+ScopedDrmPropertyBlobPtr GetDrmPropertyBlob(int fd, |
+ drmModeConnector* connector, |
+ const std::string& name) { |
+ ScopedDrmPropertyPtr property; |
+ int index = GetDrmProperty(fd, connector, name, &property); |
+ if (index < 0) |
+ return nullptr; |
+ |
+ if (property->flags & DRM_MODE_PROP_BLOB) { |
+ return ScopedDrmPropertyBlobPtr( |
+ drmModeGetPropertyBlob(fd, connector->prop_values[index])); |
+ } |
+ |
+ return nullptr; |
+} |
+ |
+bool IsAspectPreserving(int fd, drmModeConnector* connector) { |
+ ScopedDrmPropertyPtr property; |
+ int index = GetDrmProperty(fd, connector, "scaling mode", &property); |
+ if (index < 0) |
+ return false; |
+ |
+ return (GetNameForEnumValue(property.get(), connector->prop_values[index]) == |
+ "Full aspect"); |
+} |
+ |
} // namespace |
HardwareDisplayControllerInfo::HardwareDisplayControllerInfo( |
@@ -100,4 +196,69 @@ bool SameMode(const drmModeModeInfo& lhs, const drmModeModeInfo& rhs) { |
lhs.flags == rhs.flags && strcmp(lhs.name, rhs.name) == 0; |
} |
+DisplayMode_Params CreateDisplayModeParams(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 CreateDisplaySnapshotParams( |
+ HardwareDisplayControllerInfo* info, |
+ int fd, |
+ size_t display_index) { |
+ DisplaySnapshot_Params params; |
+ params.display_id = display_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, display_index, ¶ms.display_id)) |
+ params.display_id = display_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) { |
+ const drmModeModeInfo& mode = info->connector()->modes[i]; |
+ params.modes.push_back(CreateDisplayModeParams(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 |