Skip to content

Commit

Permalink
Fixed ContextEgl construction for eglstreams. Added support for Nvidi…
Browse files Browse the repository at this point in the history
…a Tegra TX1/TX2 (#381)

Signed-off-by: Stanislav Shmarov <github@snarpix.com>
  • Loading branch information
Snarpix authored Aug 25, 2023
1 parent 311e9f1 commit c696e5b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ FlafyDev <flafyarazi@gmail.com>
Makoto Sato (makoto.sato@atmark-techno.com)
Yunhao Tian (t123yh@outlook.com)
Luke Howard <lukeh@padl.com>
Stanislav Shmarov <github@snarpix.com>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace flutter {

ContextEglStream::ContextEglStream(
std::unique_ptr<EnvironmentEglStream> environment)
: ContextEgl(std::move(environment), EGL_STREAM_BIT_KHR) {
: ContextEgl(std::move(environment), false, EGL_STREAM_BIT_KHR) {
if (!valid_) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <chrono>
#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -262,29 +263,31 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler {
}

constexpr char kFileNameSeparator[] = "/";
auto pos = device_filename.find_last_of(kFileNameSeparator);
if (pos == std::string::npos) {
ELINUX_LOG(ERROR) << "Failed to get device name position.";
udev_unref(udev);
return false;
}
if (device_filename != "drm-nvdc") {
auto pos = device_filename.find_last_of(kFileNameSeparator);
if (pos == std::string::npos) {
ELINUX_LOG(ERROR) << "Failed to get device name position.";
udev_unref(udev);
return false;
}

auto device_name = device_filename.substr(pos + 1);
auto device = udev_device_new_from_subsystem_sysname(
udev, kUdevMonitorSubsystemDrm, device_name.c_str());
if (!device) {
ELINUX_LOG(ERROR) << "Failed to get device from " << device_name;
udev_unref(udev);
return false;
}
auto device_name = device_filename.substr(pos + 1);
auto device = udev_device_new_from_subsystem_sysname(
udev, kUdevMonitorSubsystemDrm, device_name.c_str());
if (!device) {
ELINUX_LOG(ERROR) << "Failed to get device from " << device_name;
udev_unref(udev);
return false;
}

auto sysnum = udev_device_get_sysnum(device);
if (!sysnum) {
ELINUX_LOG(ERROR) << "Failed to get device id.";
udev_unref(udev);
return false;
auto sysnum = udev_device_get_sysnum(device);
if (!sysnum) {
ELINUX_LOG(ERROR) << "Failed to get device id.";
udev_unref(udev);
return false;
}
drm_device_id_ = std::atoi(sysnum);
}
drm_device_id_ = std::atoi(sysnum);
udev_unref(udev);

if (sd_event_new(&udev_drm_event_loop_) < 0) {
Expand Down Expand Up @@ -348,7 +351,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler {
if (!sysnum) {
ELINUX_LOG(ERROR) << "Failed to get device id.";
return false;
} else if (std::atoi(sysnum) != drm_device_id_) {
} else if (drm_device_id_ && std::atoi(sysnum) != *drm_device_id_) {
ELINUX_LOG(ERROR) << "Not expected device id.";
return false;
}
Expand Down Expand Up @@ -721,7 +724,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler {

sd_event* udev_drm_event_loop_ = nullptr;
udev_monitor* udev_monitor_ = nullptr;
int drm_device_id_;
std::optional<int> drm_device_id_;
};

} // namespace flutter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ namespace flutter {
NativeWindowDrm::NativeWindowDrm(const char* device_filename,
const uint16_t rotation,
bool enable_vsync) {
drm_device_ = open(device_filename, O_RDWR | O_CLOEXEC);
if (!strcmp("drm-nvdc", device_filename)) {
drm_device_ = drmOpen(device_filename, nullptr);
} else {
drm_device_ = open(device_filename, O_RDWR | O_CLOEXEC);
}
if (drm_device_ == -1) {
ELINUX_LOG(ERROR) << "Couldn't open " << device_filename;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <xf86drmMode.h>

#include <cstddef>
#include <cstdint>
#include <string>

#include "flutter/shell/platform/linux_embedded/surface/surface_gl.h"
Expand Down

0 comments on commit c696e5b

Please sign in to comment.