|
13 | 13 |
|
14 | 14 | #include <chrono> |
15 | 15 | #include <memory> |
| 16 | +#include <string> |
16 | 17 | #include <unordered_map> |
| 18 | +#include <vector> |
17 | 19 |
|
18 | 20 | #include "flutter/shell/platform/linux_embedded/logger.h" |
19 | 21 | #include "flutter/shell/platform/linux_embedded/surface/surface_gl.h" |
@@ -108,23 +110,42 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { |
108 | 110 |
|
109 | 111 | // |FlutterWindowBindingHandler| |
110 | 112 | bool CreateRenderSurface(int32_t width, int32_t height) override { |
| 113 | + std::vector<std::string> devices; |
111 | 114 | 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()) { |
113 | 119 | ELINUX_LOG(WARNING) << kFlutterDrmDeviceEnvironmentKey |
114 | 120 | << " 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 | + } |
117 | 134 |
|
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 | + } |
123 | 141 |
|
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) { |
126 | 146 | return false; |
127 | 147 | } |
| 148 | + |
128 | 149 | display_valid_ = true; |
129 | 150 |
|
130 | 151 | render_surface_ = native_window_->CreateRenderSurface(); |
@@ -667,6 +688,19 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { |
667 | 688 | kScrollOffsetMultiplier); |
668 | 689 | } |
669 | 690 |
|
| 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 | + |
670 | 704 | struct LibinputDeviceData { |
671 | 705 | size_t id; |
672 | 706 | bool is_pointer_device; |
|
0 commit comments