Skip to content

Commit 9dc1156

Browse files
Specify DRM connector with FLUTTER_DRM_CONNECTOR (sony#425)
* Specify DRM connector with FLUTTER_DRM_CONNECTOR * Update AUTHORS --------- Co-authored-by: barri <[email protected]>
1 parent 63b57ca commit 9dc1156

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ Sebastian Urban <[email protected]>
1717
Ómar Högni Guðmarsson <[email protected]>
1818
Athaariq Ardhiansyah <[email protected]>
1919
Anton Sakhon <[email protected]>
20+

src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,31 @@
1414
#include "flutter/shell/platform/linux_embedded/surface/cursor_data.h"
1515

1616
namespace flutter {
17+
namespace {
18+
constexpr char kFlutterDrmConnectorEnvironmentKey[] = "FLUTTER_DRM_CONNECTOR";
19+
static const std::unordered_map<uint32_t, std::string> connector_names = {
20+
{DRM_MODE_CONNECTOR_Unknown, "Unknown"},
21+
{DRM_MODE_CONNECTOR_VGA, "VGA"},
22+
{DRM_MODE_CONNECTOR_DVII, "DVI-I"},
23+
{DRM_MODE_CONNECTOR_DVID, "DVI-D"},
24+
{DRM_MODE_CONNECTOR_DVIA, "DVI-A"},
25+
{DRM_MODE_CONNECTOR_Composite, "Composite"},
26+
{DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO"},
27+
{DRM_MODE_CONNECTOR_LVDS, "LVDS"},
28+
{DRM_MODE_CONNECTOR_Component, "Component"},
29+
{DRM_MODE_CONNECTOR_9PinDIN, "DIN"},
30+
{DRM_MODE_CONNECTOR_DisplayPort, "DP"},
31+
{DRM_MODE_CONNECTOR_HDMIA, "HDMI-A"},
32+
{DRM_MODE_CONNECTOR_HDMIB, "HDMI-B"},
33+
{DRM_MODE_CONNECTOR_TV, "TV"},
34+
{DRM_MODE_CONNECTOR_eDP, "eDP"},
35+
{DRM_MODE_CONNECTOR_VIRTUAL, "Virtual"},
36+
{DRM_MODE_CONNECTOR_DSI, "DSI"},
37+
{DRM_MODE_CONNECTOR_DPI, "DPI"},
38+
{DRM_MODE_CONNECTOR_WRITEBACK, "Writeback"},
39+
{DRM_MODE_CONNECTOR_SPI, "SPI"},
40+
{DRM_MODE_CONNECTOR_USB, "USB"}};
41+
} // namespace
1742

1843
NativeWindowDrm::NativeWindowDrm(const char* device_filename,
1944
const uint16_t rotation,
@@ -104,11 +129,62 @@ bool NativeWindowDrm::ConfigureDisplay(const uint16_t rotation) {
104129
return true;
105130
}
106131

132+
std::string NativeWindowDrm::GetConnectorName(uint32_t connector_type,
133+
uint32_t connector_type_id) {
134+
auto it = connector_names.find(connector_type);
135+
std::string name = it != connector_names.end() ? it->second : "Unknown";
136+
return name + "-" + std::to_string(connector_type_id);
137+
}
138+
139+
drmModeConnectorPtr NativeWindowDrm::GetConnectorByName(
140+
drmModeResPtr resources,
141+
const char* connector_name) {
142+
for (int i = 0; i < resources->count_connectors; i++) {
143+
auto connector = drmModeGetConnector(drm_device_, resources->connectors[i]);
144+
if (!connector) {
145+
continue;
146+
}
147+
auto other_connector_name = GetConnectorName(connector->connector_type,
148+
connector->connector_type_id);
149+
if (connector_name == other_connector_name) {
150+
return connector;
151+
}
152+
drmModeFreeConnector(connector);
153+
}
154+
return nullptr;
155+
}
156+
107157
drmModeConnectorPtr NativeWindowDrm::FindConnector(drmModeResPtr resources) {
158+
auto connector_name = std::getenv(kFlutterDrmConnectorEnvironmentKey);
159+
if (connector_name && connector_name[0] != '\0') {
160+
auto connector = GetConnectorByName(resources, connector_name);
161+
if (!connector) {
162+
ELINUX_LOG(ERROR) << "Couldn't find connector with name "
163+
<< connector_name;
164+
return nullptr;
165+
}
166+
167+
if (connector->connection == DRM_MODE_CONNECTED) {
168+
ELINUX_LOG(DEBUG) << "Using connector " << connector_name;
169+
return connector;
170+
} else {
171+
ELINUX_LOG(ERROR) << "Connector " << connector_name
172+
<< " is not connected.";
173+
drmModeFreeConnector(connector);
174+
return nullptr;
175+
}
176+
}
177+
108178
for (int i = 0; i < resources->count_connectors; i++) {
109179
auto connector = drmModeGetConnector(drm_device_, resources->connectors[i]);
180+
if (!connector) {
181+
continue;
182+
}
110183
// pick the first connected connector
111184
if (connector->connection == DRM_MODE_CONNECTED) {
185+
auto other_connetor_name = GetConnectorName(connector->connector_type,
186+
connector->connector_type_id);
187+
ELINUX_LOG(DEBUG) << "Using connector " << other_connetor_name;
112188
return connector;
113189
}
114190
drmModeFreeConnector(connector);

src/flutter/shell/platform/linux_embedded/window/native_window_drm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class NativeWindowDrm : public NativeWindow {
3939
bool enable_impeller) = 0;
4040

4141
protected:
42+
std::string GetConnectorName(uint32_t connector_type,
43+
uint32_t connector_type_id);
44+
drmModeConnectorPtr GetConnectorByName(drmModeResPtr resources,
45+
const char* connector_name);
4246
drmModeConnectorPtr FindConnector(drmModeResPtr resources);
4347

4448
drmModeEncoder* FindEncoder(drmModeRes* resources,

0 commit comments

Comments
 (0)