Skip to content

Commit 48a047c

Browse files
drm: add multiple dri cards support using FLUTTER_DRM_DEVIE env (#295)
Fixed sony/flutter-elinux#143 Signed-off-by: Hidenori Matsubayashi <[email protected]>
1 parent 9a1c5e1 commit 48a047c

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

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

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
#include <chrono>
1515
#include <memory>
16+
#include <string>
1617
#include <unordered_map>
18+
#include <vector>
1719

1820
#include "flutter/shell/platform/linux_embedded/logger.h"
1921
#include "flutter/shell/platform/linux_embedded/surface/surface_gl.h"
@@ -108,23 +110,42 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler {
108110

109111
// |FlutterWindowBindingHandler|
110112
bool CreateRenderSurface(int32_t width, int32_t height) override {
113+
std::vector<std::string> devices;
111114
auto device_filename = std::getenv(kFlutterDrmDeviceEnvironmentKey);
112-
if ((!device_filename) || (device_filename[0] == '\0')) {
115+
if (device_filename && device_filename[0] != '\0') {
116+
devices = split(std::string(device_filename), ':');
117+
}
118+
if (devices.empty()) {
113119
ELINUX_LOG(WARNING) << kFlutterDrmDeviceEnvironmentKey
114120
<< " is not set, use " << kDrmDeviceDefaultFilename;
115-
device_filename = const_cast<char*>(kDrmDeviceDefaultFilename);
116-
}
121+
devices.push_back(const_cast<char*>(kDrmDeviceDefaultFilename));
122+
}
123+
124+
bool device_found = false;
125+
for (auto i = 0; i < devices.size(); i++) {
126+
native_window_ =
127+
std::make_unique<T>(devices[i].c_str(), current_rotation_);
128+
if (!native_window_->IsValid()) {
129+
ELINUX_LOG(ERROR) << "Failed to create the native window ("
130+
<< devices[i] << ").";
131+
native_window_ = nullptr;
132+
continue;
133+
}
117134

118-
native_window_ = std::make_unique<T>(device_filename, current_rotation_);
119-
if (!native_window_->IsValid()) {
120-
ELINUX_LOG(ERROR) << "Failed to create the native window";
121-
return false;
122-
}
135+
if (!RegisterUdevDrmEventLoop(devices[i].c_str())) {
136+
ELINUX_LOG(ERROR) << "Failed to register udev drm event loop ("
137+
<< devices[i] << ").";
138+
native_window_ = nullptr;
139+
continue;
140+
}
123141

124-
if (!RegisterUdevDrmEventLoop(device_filename)) {
125-
ELINUX_LOG(ERROR) << "Failed to register udev drm event loop.";
142+
device_found = true;
143+
ELINUX_LOG(INFO) << devices[i] << " was selected as the DRM device.";
144+
}
145+
if (!device_found) {
126146
return false;
127147
}
148+
128149
display_valid_ = true;
129150

130151
render_surface_ = native_window_->CreateRenderSurface();
@@ -667,6 +688,19 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler {
667688
kScrollOffsetMultiplier);
668689
}
669690

691+
std::vector<std::string> split(std::string s, char delim) {
692+
std::vector<std::string> res;
693+
std::string item;
694+
std::stringstream ss(s);
695+
696+
while (getline(ss, item, delim)) {
697+
if (!item.empty()) {
698+
res.push_back(item);
699+
}
700+
}
701+
return res;
702+
}
703+
670704
struct LibinputDeviceData {
671705
size_t id;
672706
bool is_pointer_device;

0 commit comments

Comments
 (0)