Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support eglstream #52

Merged
merged 20 commits into from Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,22 @@ jobs:
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE

- name: Configure CMake for drm backend
- name: Configure CMake for drm backend with GBM
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DUSER_PROJECT_PATH=examples/flutter-drm-backend ..
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DUSER_PROJECT_PATH=examples/flutter-drm-gbm-backend ..

- name: Build for drm backend
- name: Build for drm backend with GBM
working-directory: ${{github.workspace}}/build
shell: bash
run: cmake --build . --config $BUILD_TYPE

- name: Configure CMake for drm backend with EGLStream
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DUSER_PROJECT_PATH=examples/flutter-drm-eglstream-backend ..

- name: Build for drm backend with EGLStream
working-directory: ${{github.workspace}}/build
shell: bash
run: cmake --build . --config $BUILD_TYPE
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_STANDARD 17)

# Build options.
option(USE_DRM "Select WAYLAND or DRM as the display backend type" OFF)
option(BACKEND_TYPE "Select WAYLAND or DRM-GBM or DRM-EGLSTREAM or X11 as the display backend type" WAYLAND)
HidenoriMatsubayashi marked this conversation as resolved.
Show resolved Hide resolved
option(DESKTOP_SHELL "Work as weston desktop-shell" OFF)
option(USE_VIRTUAL_KEYBOARD "Use virtual keyboard" OFF)
option(USE_GLES3 "Use OpenGL ES3 (default is OpenGL ES2)" OFF)
Expand Down
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ We would be grateful if you could give us feedback on bugs and new feature reque
- [Wayland](https://wayland.freedesktop.org/) backend support
- Direct rendering module ([DRM](https://en.wikipedia.org/wiki/Direct_Rendering_Manager)) backend support
- [x] Generic Buffer Management ([GBM](https://en.wikipedia.org/wiki/Mesa_(computer_graphics)))
- [ ] [EGLStream](https://docs.nvidia.com/drive/drive_os_5.1.6.1L/nvvib_docs/index.html#page/DRIVE_OS_Linux_SDK_Development_Guide/Graphics/graphics_eglstream_user_guide.html) for NVIDIA devices (coming soon)
- [x] [EGLStream](https://docs.nvidia.com/drive/drive_os_5.1.6.1L/nvvib_docs/index.html#page/DRIVE_OS_Linux_SDK_Development_Guide/Graphics/graphics_eglstream_user_guide.html) for NVIDIA devices
- X11 backend supoort
- This is for the purpose of developing Flutter apps in Linux desktops. It is not intended for use in embedded systems.
- Always single window fullscreen
Expand All @@ -39,7 +39,7 @@ This embedder supports x64 and Arm64 (aarch64, ARMv8) architectures on Linux whi
| QEMU (x86_64) | QEMU | [AGL (Automotive Grade Linux)](https://wiki.automotivelinux.org/) jellyfish / koi | Wayland | :heavy_check_mark: |
| QEMU (x86_64) | QEMU | [AGL (Automotive Grade Linux)](https://wiki.automotivelinux.org/) jellyfish / koi | DRM | :heavy_check_mark: |
| [Jetson Nano](https://developer.nvidia.com/embedded/jetson-nano-developer-kit) | NVIDIA | JetPack 4.3 | Wayland | :heavy_check_mark: |
| [Jetson Nano](https://developer.nvidia.com/embedded/jetson-nano-developer-kit) | NVIDIA | JetPack 4.3 | DRM | See: [#1](https://github.com/sony/flutter-embedded-linux/issues/1) |
| [Jetson Nano](https://developer.nvidia.com/embedded/jetson-nano-developer-kit) | NVIDIA | JetPack 4.3 | DRM | :heavy_check_mark: ([#1](https://github.com/sony/flutter-embedded-linux/issues/1))|
HidenoriMatsubayashi marked this conversation as resolved.
Show resolved Hide resolved
| [Raspberry Pi 4 Model B](https://www.raspberrypi.org/products/raspberry-pi-4-model-b/) | Raspberry Pi Foundation | Ubuntu 20.10 | Wayland | :heavy_check_mark: |
| [Raspberry Pi 4 Model B](https://www.raspberrypi.org/products/raspberry-pi-4-model-b/) | Raspberry Pi Foundation | Ubuntu 20.10 | DRM | :heavy_check_mark: ([#9](https://github.com/sony/flutter-embedded-linux/issues/9)) |
| [i.MX 8MQuad EVK](https://www.nxp.com/design/development-boards/i-mx-evaluation-and-development-boards/evaluation-kit-for-the-i-mx-8m-applications-processor:MCIMX8M-EVK) | NXP | Sumo (kernel 4.14.98) | Wayland | :heavy_check_mark: |
Expand Down Expand Up @@ -163,10 +163,21 @@ $ cmake --build .

### Build for DRM backend

#### Use GBM

```Shell
$ mkdir build
$ cd build
$ cmake -DUSER_PROJECT_PATH=examples/flutter-drm-gbm-backend ..
$ cmake --build .
```

#### Use EGLStream

```Shell
$ mkdir build
$ cd build
$ cmake -DUSER_PROJECT_PATH=examples/flutter-drm-backend ..
$ cmake -DUSER_PROJECT_PATH=examples/flutter-drm-eglstream-backend ..
$ cmake --build .
```

Expand Down Expand Up @@ -198,8 +209,7 @@ Please edit `cmake/user_config.cmake` file.

| Option | Description |
| ------------- | ------------- |
| USE_DRM | Use DRM backend instead of Wayland |
| USE_X11 | Use X11 backend instead of Wayland |
| BACKEND_TYPE | Select WAYLAND or DRM-GBM or DRM-EGLSTREAM or X11 as the display backend type (The default setting is WAYLAND) |
| DESKTOP_SHELL | Work as Weston desktop-shell |
| USE_VIRTUAL_KEYBOARD | Use Virtual Keyboard (only when you use `DESKTOP_SHELL`) |
| USE_GLES3 | Use OpenGLES3 instead of OpenGLES2 |
Expand Down Expand Up @@ -270,7 +280,7 @@ You need to switch from GUI which is running X11 or Wayland to the Character Use

```Shell
$ Ctrl + Alt + F3 # Switching to CUI
$ sudo FLUTTER_DRM_DEVICE="/dev/dri/card1" ./flutter-drm-backend ./sample/build/linux/x64/release/bundle
$ sudo FLUTTER_DRM_DEVICE="/dev/dri/card1" <./binary_file_name> ./sample/build/linux/x64/release/bundle
HidenoriMatsubayashi marked this conversation as resolved.
Show resolved Hide resolved
```

If you want to switch back from CUI to GUI, run `Ctrl + Alt + F2` keys in a terminal.
Expand Down
20 changes: 11 additions & 9 deletions cmake/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ cmake_minimum_required(VERSION 3.10)

# display backend type.
set(DISPLAY_BACKEND_SRC "")
if(USE_DRM)
add_definitions(-DDISPLAY_BACKEND_TYPE_DRM)
if(${BACKEND_TYPE} STREQUAL "DRM-GBM")
add_definitions(-DDISPLAY_BACKEND_TYPE_DRM_GBM)
set(DISPLAY_BACKEND_SRC
src/flutter/shell/platform/linux_embedded/window/linuxes_window_drm.cc
src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc
src/flutter/shell/platform/linux_embedded/surface/linuxes_surface_gl_drm.cc)
elseif(USE_X11)
src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc)
elseif(${BACKEND_TYPE} STREQUAL "DRM-EGLSTREAM")
add_definitions(-DDISPLAY_BACKEND_TYPE_DRM_EGLSTREAM)
set(DISPLAY_BACKEND_SRC
src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc)
elseif(${BACKEND_TYPE} STREQUAL "X11")
add_definitions(-DDISPLAY_BACKEND_TYPE_X11)
set(DISPLAY_BACKEND_SRC
src/flutter/shell/platform/linux_embedded/window/linuxes_window_x11.cc
Expand Down Expand Up @@ -42,13 +44,13 @@ else()
endif()

# desktop-shell for weston.
if(NOT USE_DRM AND DESKTOP_SHELL)
HidenoriMatsubayashi marked this conversation as resolved.
Show resolved Hide resolved
if(DESKTOP_SHELL)
add_definitions(-DDESKTOP_SHELL)
endif()

# wayland & weston protocols.
set(WAYLAND_PROTOCOL_SRC "")
if(NOT USE_DRM AND DESKTOP_SHELL)
if(DESKTOP_SHELL)
HidenoriMatsubayashi marked this conversation as resolved.
Show resolved Hide resolved
set(WAYLAND_PROTOCOL_SRC ${WAYLAND_PROTOCOL_SRC} src/wayland/protocol/weston-desktop-shell-protocol.c)

if(USE_VIRTUAL_KEYBOARD)
Expand Down Expand Up @@ -154,7 +156,7 @@ target_link_libraries(${TARGET}
${USER_APP_LIBRARIES}
)

if(USE_DRM)
if(${BACKEND_TYPE} MATCHES "DRM-(GBM|EGLSTREAM)")
target_link_libraries(${TARGET}
PRIVATE
Threads::Threads
Expand Down
8 changes: 5 additions & 3 deletions cmake/package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ pkg_check_modules(EGL REQUIRED egl)
pkg_check_modules(XKBCOMMON REQUIRED xkbcommon)

# depends on backend type.
if(USE_DRM)
if(${BACKEND_TYPE} MATCHES "DRM-(GBM|EGLSTREAM)")
# DRM backend
pkg_check_modules(DRM REQUIRED libdrm)
pkg_check_modules(GBM REQUIRED gbm)
pkg_check_modules(LIBINPUT REQUIRED libinput)
pkg_check_modules(LIBUDEV REQUIRED libudev)
pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
elseif(USE_X11)
if(${BACKEND_TYPE} STREQUAL "DRM-GBM")
HidenoriMatsubayashi marked this conversation as resolved.
Show resolved Hide resolved
pkg_check_modules(GBM REQUIRED gbm)
endif()
elseif(${BACKEND_TYPE} STREQUAL "X11")
pkg_check_modules(XCB REQUIRED xcb)
pkg_check_modules(X11_XCB REQUIRED x11-xcb)
else()
Expand Down
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ These are an example of how to use embedded Linux embedding for Flutter.
- [flutter-wayland-client](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-wayland-client): Wayland client app
- [flutter-weston-desktop-shell](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-weston-desktop-shell): Works on Weston desktop-shell
- [flutter-weston-desktop-shell-virtual-keyboard](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-weston-desktop-shell-virtual-keyboard): Works on Weston desktop-shell with the virtual keyboard
- [flutter-drm-backend](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-drm-backend): Fullscreen app on DRM backend
- [flutter-drm-gbm-backend](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-drm-gbm-backend): Fullscreen app on DRM backend with GBM
- [flutter-drm-eglstream-backend](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-drm-eglstream-backend): Fullscreen app on DRM backend with EGLStream
- [flutter-x11-client](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-x11-client): X11 client app
- [flutter-external-texture-plugin](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-external-texture-plugin): Wayland client app using external texture plugin
25 changes: 25 additions & 0 deletions examples/flutter-drm-eglstream-backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Overview

This is the example of DRM backend with EGLStream.

## Building

```Shell
$ mkdir build
$ cd build
$ cmake -DUSER_PROJECT_PATH=examples/flutter-drm-eglstream-backend ..
$ cmake --build .
```

## Running Flutter app

You need to switch from GUI which is running X11 or Wayland to the Character User Interface (CUI). In addition, `FLUTTER_DRM_DEVICE` must be set properly. The default value is `/dev/dri/card0`.

```Shell
$ Ctrl + Alt + F3 # Switching to CUI
$ FLUTTER_DRM_DEVICE="/dev/dri/card1" ./flutter-drm-eglstream-backend FLUTTER_BUNDLE_PATH
```

Note that replace `FLUTTER_BUNDLE_PATH` with the flutter bundle path you want to use like ./sample/build/linux/x64/release/bundle.

If you want to switch back from CUI to GUI, run `Ctrl + Alt + F2` keys in a terminal.
25 changes: 25 additions & 0 deletions examples/flutter-drm-eglstream-backend/cmake/user_build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.10)

# user binary name.
set(TARGET flutter-drm-eglstream-backend)

# source files for user apps.
set(USER_APP_SRCS
examples/flutter-drm-eglstream-backend/main.cc
)

# header files for user apps.
set(USER_APP_INCLUDE_DIRS
## Public APIs for developers (Don't edit!).
src/client_wrapper/include
src/flutter/shell/platform/common/client_wrapper
src/flutter/shell/platform/common/client_wrapper/include/flutter
src/flutter/shell/platform/common/public
src/flutter/shell/platform/linux_embedded/public
src/public/include
## header file include path for user apps.
examples/flutter-drm-eglstream-backend
)

# link libraries for user apps.
set(USER_APP_LIBRARIES "")
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ cmake_minimum_required(VERSION 3.10)

# Flutter embedder configurations.
# See: https://github.com/sony/flutter-embedded-linux#user-configuration-parameters-cmake-options
set(USE_DRM ON)
set(USE_X11 OFF)
set(BACKEND_TYPE DRM-EGLSTREAM)
set(DESKTOP_SHELL OFF)
set(USE_VIRTUAL_KEYBOARD OFF)
set(USE_GLES3 OFF)
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Overview

This is the example of DRM backend.
This is the example of DRM backend with GBM.

## Building

```Shell
$ mkdir build
$ cd build
$ cmake -DUSER_PROJECT_PATH=examples/flutter-drm-backend ..
$ make
$ cmake -DUSER_PROJECT_PATH=examples/flutter-drm-gbm-backend ..
$ cmake --build .
```

## Running Flutter app
Expand All @@ -17,7 +17,7 @@ You need to switch from GUI which is running X11 or Wayland to the Character Use

```Shell
$ Ctrl + Alt + F3 # Switching to CUI
$ FLUTTER_DRM_DEVICE="/dev/dri/card1" ./flutter-drm-backend FLUTTER_BUNDLE_PATH
$ FLUTTER_DRM_DEVICE="/dev/dri/card1" ./flutter-drm-gbm-backend FLUTTER_BUNDLE_PATH
```

Note that replace `FLUTTER_BUNDLE_PATH` with the flutter bundle path you want to use like ./sample/build/linux/x64/release/bundle.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.10)

# user binary name.
set(TARGET flutter-drm-backend)
set(TARGET flutter-drm-gbm-backend)

# source files for user apps.
set(USER_APP_SRCS
examples/flutter-drm-backend/main.cc
examples/flutter-drm-gbm-backend/main.cc
)

# header files for user apps.
Expand All @@ -18,7 +18,7 @@ set(USER_APP_INCLUDE_DIRS
src/flutter/shell/platform/linux_embedded/public
src/public/include
## header file include path for user apps.
examples/flutter-drm-backend
examples/flutter-drm-gbm-backend
)

# link libraries for user apps.
Expand Down
8 changes: 8 additions & 0 deletions examples/flutter-drm-gbm-backend/cmake/user_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.10)

# Flutter embedder configurations.
# See: https://github.com/sony/flutter-embedded-linux#user-configuration-parameters-cmake-options
set(BACKEND_TYPE DRM-GBM)
set(DESKTOP_SHELL OFF)
set(USE_VIRTUAL_KEYBOARD OFF)
set(USE_GLES3 OFF)
82 changes: 82 additions & 0 deletions examples/flutter-drm-gbm-backend/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2021 Sony Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h>

#include <chrono>
#include <iostream>
#include <memory>
#include <string>
#include <thread>

static void PrintHelp() {
std::cout << "Usage: ./${execute filename} {Flutter project bundle path}"
<< std::endl;
}

int main(int argc, char** argv) {
if (argc != 2) {
PrintHelp();
return 0;
}

bool show_cursor = true;
std::string str(argv[1]);
std::wstring fl_path(str.begin(), str.end());

// The project to run.
flutter::DartProject project(fl_path);
auto command_line_arguments = std::vector<std::string>();
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));

// The Flutter instance hosted by this window.
int width = 640;
int height = 480;
auto flutter_controller = std::make_unique<flutter::FlutterViewController>(
flutter::FlutterViewController::ViewMode::kFullscreen, width, height,
show_cursor, project);

// Ensure that basic setup of the controller was successful.
if (!flutter_controller->engine() || !flutter_controller->view()) {
return 0;
}

// Main loop.
auto next_flutter_event_time =
std::chrono::steady_clock::time_point::clock::now();
while (flutter_controller->view()->DispatchEvent()) {
// Wait until the next event.
{
auto wait_duration =
std::max(std::chrono::nanoseconds(0),
next_flutter_event_time -
std::chrono::steady_clock::time_point::clock::now());
std::this_thread::sleep_for(
std::chrono::duration_cast<std::chrono::milliseconds>(wait_duration));
}

// Processes any pending events in the Flutter engine, and returns the
// number of nanoseconds until the next scheduled event (or max, if none).
auto wait_duration = flutter_controller->engine()->ProcessMessages();
{
auto next_event_time = std::chrono::steady_clock::time_point::max();
if (wait_duration != std::chrono::nanoseconds::max()) {
auto next_wakeup =
std::max(std::chrono::steady_clock::time_point::max(),
std::chrono::steady_clock::time_point::clock::now() +
wait_duration);
next_event_time = std::min(next_event_time, next_wakeup);
} else {
// Wait 1/60 [sec] = 13 [msec] if no events.
next_event_time = std::chrono::steady_clock::time_point::clock::now() +
std::chrono::milliseconds(13);
}
next_flutter_event_time =
std::max(next_flutter_event_time, next_event_time);
}
}

return 0;
}
2 changes: 1 addition & 1 deletion examples/flutter-external-texture-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is the example of External Texture Plugin. Source files are implemented bas
$ mkdir build
$ cd build
$ cmake -DUSER_PROJECT_PATH=examples/flutter-external-texture-plugin ..
$ make
$ cmake --build .
```

## Dart sample code for Flutter app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ cmake_minimum_required(VERSION 3.10)

# Flutter embedder configurations.
# See: https://github.com/sony/flutter-embedded-linux#user-configuration-parameters-cmake-options
set(USE_DRM OFF)
set(USE_X11 OFF)
set(BACKEND_TYPE Wayland)
HidenoriMatsubayashi marked this conversation as resolved.
Show resolved Hide resolved
set(DESKTOP_SHELL OFF)
set(USE_VIRTUAL_KEYBOARD OFF)
set(USE_GLES3 OFF)
Loading