|
14 | 14 | #include "flutter/shell/platform/linux_embedded/surface/cursor_data.h" |
15 | 15 |
|
16 | 16 | 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 |
17 | 42 |
|
18 | 43 | NativeWindowDrm::NativeWindowDrm(const char* device_filename, |
19 | 44 | const uint16_t rotation, |
@@ -104,11 +129,62 @@ bool NativeWindowDrm::ConfigureDisplay(const uint16_t rotation) { |
104 | 129 | return true; |
105 | 130 | } |
106 | 131 |
|
| 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 | + |
107 | 157 | 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 | + |
108 | 178 | for (int i = 0; i < resources->count_connectors; i++) { |
109 | 179 | auto connector = drmModeGetConnector(drm_device_, resources->connectors[i]); |
| 180 | + if (!connector) { |
| 181 | + continue; |
| 182 | + } |
110 | 183 | // pick the first connected connector |
111 | 184 | 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; |
112 | 188 | return connector; |
113 | 189 | } |
114 | 190 | drmModeFreeConnector(connector); |
|
0 commit comments