From d12ebec132a79e4cc0480af93fa10668923b30b5 Mon Sep 17 00:00:00 2001 From: barri Date: Fri, 20 Sep 2024 06:58:16 -0400 Subject: [PATCH 1/2] Specify DRM connector with FLUTTER_DRM_CONNECTOR --- .../window/native_window_drm.cc | 76 +++++++++++++++++++ .../linux_embedded/window/native_window_drm.h | 4 + 2 files changed, 80 insertions(+) diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc index 59a2902..73023fd 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc @@ -14,6 +14,31 @@ #include "flutter/shell/platform/linux_embedded/surface/cursor_data.h" namespace flutter { +namespace { +constexpr char kFlutterDrmConnectorEnvironmentKey[] = "FLUTTER_DRM_CONNECTOR"; +static const std::unordered_map connector_names = { + {DRM_MODE_CONNECTOR_Unknown, "Unknown"}, + {DRM_MODE_CONNECTOR_VGA, "VGA"}, + {DRM_MODE_CONNECTOR_DVII, "DVI-I"}, + {DRM_MODE_CONNECTOR_DVID, "DVI-D"}, + {DRM_MODE_CONNECTOR_DVIA, "DVI-A"}, + {DRM_MODE_CONNECTOR_Composite, "Composite"}, + {DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO"}, + {DRM_MODE_CONNECTOR_LVDS, "LVDS"}, + {DRM_MODE_CONNECTOR_Component, "Component"}, + {DRM_MODE_CONNECTOR_9PinDIN, "DIN"}, + {DRM_MODE_CONNECTOR_DisplayPort, "DP"}, + {DRM_MODE_CONNECTOR_HDMIA, "HDMI-A"}, + {DRM_MODE_CONNECTOR_HDMIB, "HDMI-B"}, + {DRM_MODE_CONNECTOR_TV, "TV"}, + {DRM_MODE_CONNECTOR_eDP, "eDP"}, + {DRM_MODE_CONNECTOR_VIRTUAL, "Virtual"}, + {DRM_MODE_CONNECTOR_DSI, "DSI"}, + {DRM_MODE_CONNECTOR_DPI, "DPI"}, + {DRM_MODE_CONNECTOR_WRITEBACK, "Writeback"}, + {DRM_MODE_CONNECTOR_SPI, "SPI"}, + {DRM_MODE_CONNECTOR_USB, "USB"}}; +} // namespace NativeWindowDrm::NativeWindowDrm(const char* device_filename, const uint16_t rotation, @@ -104,11 +129,62 @@ bool NativeWindowDrm::ConfigureDisplay(const uint16_t rotation) { return true; } +std::string NativeWindowDrm::GetConnectorName(uint32_t connector_type, + uint32_t connector_type_id) { + auto it = connector_names.find(connector_type); + std::string name = it != connector_names.end() ? it->second : "Unknown"; + return name + "-" + std::to_string(connector_type_id); +} + +drmModeConnectorPtr NativeWindowDrm::GetConnectorByName( + drmModeResPtr resources, + const char* connector_name) { + for (int i = 0; i < resources->count_connectors; i++) { + auto connector = drmModeGetConnector(drm_device_, resources->connectors[i]); + if (!connector) { + continue; + } + auto other_connector_name = GetConnectorName(connector->connector_type, + connector->connector_type_id); + if (connector_name == other_connector_name) { + return connector; + } + drmModeFreeConnector(connector); + } + return nullptr; +} + drmModeConnectorPtr NativeWindowDrm::FindConnector(drmModeResPtr resources) { + auto connector_name = std::getenv(kFlutterDrmConnectorEnvironmentKey); + if (connector_name && connector_name[0] != '\0') { + auto connector = GetConnectorByName(resources, connector_name); + if (!connector) { + ELINUX_LOG(ERROR) << "Couldn't find connector with name " + << connector_name; + return nullptr; + } + + if (connector->connection == DRM_MODE_CONNECTED) { + ELINUX_LOG(DEBUG) << "Using connector " << connector_name; + return connector; + } else { + ELINUX_LOG(ERROR) << "Connector " << connector_name + << " is not connected."; + drmModeFreeConnector(connector); + return nullptr; + } + } + for (int i = 0; i < resources->count_connectors; i++) { auto connector = drmModeGetConnector(drm_device_, resources->connectors[i]); + if (!connector) { + continue; + } // pick the first connected connector if (connector->connection == DRM_MODE_CONNECTED) { + auto other_connetor_name = GetConnectorName(connector->connector_type, + connector->connector_type_id); + ELINUX_LOG(DEBUG) << "Using connector " << other_connetor_name; return connector; } drmModeFreeConnector(connector); diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h index bae9ec0..3d72f7a 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h @@ -39,6 +39,10 @@ class NativeWindowDrm : public NativeWindow { bool enable_impeller) = 0; protected: + std::string GetConnectorName(uint32_t connector_type, + uint32_t connector_type_id); + drmModeConnectorPtr GetConnectorByName(drmModeResPtr resources, + const char* connector_name); drmModeConnectorPtr FindConnector(drmModeResPtr resources); drmModeEncoder* FindEncoder(drmModeRes* resources, From 5ac400bcf97027ae64bc4d17bdf4a9654e080468 Mon Sep 17 00:00:00 2001 From: barri Date: Fri, 20 Sep 2024 07:07:24 -0400 Subject: [PATCH 2/2] Update AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 8529880..6a81626 100644 --- a/AUTHORS +++ b/AUTHORS @@ -17,3 +17,4 @@ Sebastian Urban Ómar Högni Guðmarsson Athaariq Ardhiansyah Anton Sakhon +Bari Rao