Skip to content

Commit

Permalink
Add libuv support as a replacement of systemd + some CMake fixes (#420)
Browse files Browse the repository at this point in the history
* git: prevent accidental push on generated files

Signed-off-by: Athaariq Ardhiansyah <foss@athaariq.my.id>

* cmake: fix wrong option usage

The option() function only dedicated for boolean type. For enumerated string, better use both set(... CACHE STRING ...) and set_property(CACHE ... PROPERTY STRINGS ...).

Signed-off-by: Athaariq Ardhiansyah <foss@athaariq.my.id>

* cmake: fix wrong string cache syntax in set()

For further information, visit the documentation at https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry

Signed-off-by: Athaariq Ardhiansyah <foss@athaariq.my.id>

* cmake: warn if BUILD_ELINUX_SO is OFF but BACKEND_TYPE was modified

This commit prevents other new contributors from mistakenly blame CMakeLists.txt. Therefore, I added a warning just in case they forgot to turn on BUILD_ELINUX_SO while modifying BACKEND_TYPE.

Signed-off-by: Athaariq Ardhiansyah <foss@athaariq.my.id>

* cmake: enforce regex exactness for safety

Signed-off-by: Athaariq Ardhiansyah <foss@athaariq.my.id>

* drm: add libuv support as systemd replacement

Not all embedded systems can include systemd due to their constrained resource limit. Our requirement from libsystemd is only event loop (sd-event). Therefore, libuv is perfect as drop-in replacement of sd-event. I tested the changes on Raspberry Pi 5 with Buildroot (yes, I am working on it too) and a x86-64 laptop with Arch Linux. Both are working as intended. Interestingly, libuv makes flutter-elinux smoother on my laptop. I have no idea how to benchmark it, but it is a good sign for us.

For now, I am assuming users are still relying on libsystemd. Therefore, libuv only be used if the target device has no systemd. If maintainer want to drop the systemd dependency, I suggest to deprecate it gracefully and plan to drop it later. Otherwise, it would be a breaking change.

Signed-off-by: Athaariq Ardhiansyah <foss@athaariq.my.id>

* author: add Athaariq Ardhiansyah

Signed-off-by: Athaariq Ardhiansyah <foss@athaariq.my.id>

* style: overhaul to comply the standard

Signed-off-by: Athaariq Ardhiansyah <foss@athaariq.my.id>

* style: format with clang-format v14.0.6

I realized that clang-format is inconsistent between its versions. So, Arch Linux (clang v17) and Ubuntu Jammy (clang v14) will output different formatting result. For Arch Linux users, the clang14 package has no clang-format included. You need to compile the entire clang on your own until the downstream maintainer include it.

Signed-off-by: Athaariq Ardhiansyah <foss@athaariq.my.id>

* cmake: fix error for CMake before v3.28

On some distributions with non-latest CMake, it will fail on configuration due to its incapability of substition from unset variable to an empty string. To fix this, we need to add double quotes between variables that will be tested by EQUAL, LESS, GREATER, and other related keywords. For better compatibility, use STREQUAL instead of EQUAL if possible.

Signed-off-by: Athaariq Ardhiansyah <foss@athaariq.my.id>

---------

Signed-off-by: Athaariq Ardhiansyah <foss@athaariq.my.id>
  • Loading branch information
Thor-x86 committed Jun 2, 2024
1 parent d73e35a commit 595f7f5
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode/
/build/
/src/third_party/wayland/protocols/*
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Luke Howard <lukeh@padl.com>
Stanislav Shmarov <github@snarpix.com>
Sebastian Urban <surban@surban.net>
Ómar Högni Guðmarsson <ohg@skaginn3x.com>
Athaariq Ardhiansyah <foss@athaariq.my.id>
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ set(CMAKE_CXX_STANDARD 17)
project("flutter_elinux" LANGUAGES CXX C)

# Build options.
option(BACKEND_TYPE "Select WAYLAND, DRM-GBM, DRM-EGLSTREAM, or X11 as the display backend type" WAYLAND)
set(BACKEND_TYPE "WAYLAND" CACHE STRING "Select WAYLAND, DRM-GBM, DRM-EGLSTREAM, or X11 as the display backend type")
set_property(CACHE BACKEND_TYPE PROPERTY STRINGS "WAYLAND" "DRM-GBM" "DRM-EGLSTREAM" "X11")
# Disabled USE_DIRTY_REGION_MANAGEMENT due flicker issue.
# See https://github.com/sony/flutter-embedded-linux/issues/334
option(USE_DIRTY_REGION_MANAGEMENT "Use Flutter dirty region management" OFF)
Expand All @@ -24,8 +25,11 @@ option(FLUTTER_RELEASE "Build Flutter Engine with release mode" OFF)

if(NOT BUILD_ELINUX_SO)
# Load the user project.
set(USER_PROJECT_PATH "examples/flutter-wayland-client" CACHE STRING "")
set(USER_PROJECT_PATH "" CACHE STRING "examples/flutter-wayland-client")
message("User project: ${USER_PROJECT_PATH}")
if(NOT ${BACKEND_TYPE} STREQUAL "WAYLAND")
message(WARNING "BACKEND_TYPE variable is ignored because BUILD_ELINUX_SO is OFF")
endif()
include(${USER_PROJECT_PATH}/cmake/user_config.cmake)
else()
# Set the filename of elinux .so file
Expand Down
16 changes: 11 additions & 5 deletions cmake/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,24 @@ target_link_libraries(${TARGET}
${LIBINPUT_LIBRARIES}
${LIBUDEV_LIBRARIES}
${LIBSYSTEMD_LIBRARIES}
${LIBUV_LIBRARIES}
${X11_LIBRARIES}
${LIBWESTON_LIBRARIES}
${FLUTTER_EMBEDDER_LIB}
## User libraries
${USER_APP_LIBRARIES}
)

if(${BACKEND_TYPE} MATCHES "DRM-(GBM|EGLSTREAM)")
target_link_libraries(${TARGET}
PRIVATE
Threads::Threads
)
if(${BACKEND_TYPE} MATCHES "^DRM-(GBM|EGLSTREAM)$")
target_link_libraries(${TARGET}
PRIVATE
Threads::Threads
)

# Indicate whether libsystemd must replace libuv
if("${LIBSYSTEMD_FOUND}" STREQUAL "1")
add_definitions(-DUSE_LIBSYSTEMD)
endif()
endif()

set(FLUTTER_EMBEDDER_LIB "${CMAKE_CURRENT_SOURCE_DIR}/build/libflutter_engine.so")
Expand Down
13 changes: 11 additions & 2 deletions cmake/package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@ pkg_check_modules(EGL REQUIRED egl)
pkg_check_modules(XKBCOMMON REQUIRED xkbcommon)

# depends on backend type.
if(${BACKEND_TYPE} MATCHES "DRM-(GBM|EGLSTREAM)")
if(${BACKEND_TYPE} MATCHES "^DRM-(GBM|EGLSTREAM)$")
# DRM backend
pkg_check_modules(DRM REQUIRED libdrm)
pkg_check_modules(LIBINPUT REQUIRED libinput)
pkg_check_modules(LIBUDEV REQUIRED libudev)
pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
pkg_check_modules(LIBSYSTEMD libsystemd)
pkg_check_modules(LIBUV libuv)
if(${BACKEND_TYPE} STREQUAL "DRM-GBM")
pkg_check_modules(GBM REQUIRED gbm)
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Check if either systemd or libuv exist
if((NOT "${LIBSYSTEMD_FOUND}" STREQUAL "1") AND (NOT "${LIBUV_FOUND}" STREQUAL "1"))
message(FATAL_ERROR
"${BACKEND_TYPE} backend requires either libsystemd or libuv, but
they're not exist.")
elseif(("${LIBSYSTEMD_FOUND}" STREQUAL "1") AND ("${LIBUV_FOUND}" STREQUAL "1"))
message("!! NOTICE: libsystemd found, libuv won't be used.")
endif()
elseif(${BACKEND_TYPE} STREQUAL "X11")
pkg_check_modules(X11 REQUIRED x11)
else()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class CustomEncodableValue {

#if defined(FLUTTER_ENABLE_RTTI) && FLUTTER_ENABLE_RTTI
// Passthrough to std::any's type().
const std::type_info& type() const noexcept { return value_.type(); }
const std::type_info& type() const noexcept {
return value_.type();
}
#endif

// This operator exists only to provide a stable ordering for use as a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class GpuSurfaceTexture {
// The available texture variants.
// Only PixelBufferTexture is currently implemented.
// Other variants are expected to be added in the future.
typedef std::variant<PixelBufferTexture, GpuSurfaceTexture, EGLImageTexture> TextureVariant;
typedef std::variant<PixelBufferTexture, GpuSurfaceTexture, EGLImageTexture>
TextureVariant;

// An object keeping track of external textures.
//
Expand Down
3 changes: 2 additions & 1 deletion src/flutter/shell/platform/common/json_method_codec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ JsonMethodCodec::EncodeErrorEnvelopeInternal(
rapidjson::Document envelope(rapidjson::kArrayType);
auto& allocator = envelope.GetAllocator();
envelope.PushBack(rapidjson::Value(error_code.c_str(), allocator), allocator);
envelope.PushBack(rapidjson::Value(error_message.c_str(), allocator), allocator);
envelope.PushBack(rapidjson::Value(error_message.c_str(), allocator),
allocator);
rapidjson::Value details_value;
if (error_details) {
details_value.CopyFrom(*error_details, allocator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ typedef struct {
size_t width;
// Height of the EGLImage.
size_t height;
// An optional callback that gets invoked when the |egl_image| can be released.
// An optional callback that gets invoked when the |egl_image| can be
// released.
void (*release_callback)(void* release_context);
// Opaque data passed to |release_callback|.
void* release_context;
Expand Down Expand Up @@ -142,12 +143,12 @@ typedef const FlutterDesktopGpuSurfaceDescriptor* (
size_t height,
void* user_data);

typedef const FlutterDesktopEGLImage* (
*FlutterDesktopEGLImageTextureCallback)(size_t width,
size_t height,
void* egl_display,
void* egl_context,
void* user_data);
typedef const FlutterDesktopEGLImage* (*FlutterDesktopEGLImageTextureCallback)(
size_t width,
size_t height,
void* egl_display,
void* egl_context,
void* user_data);

// An object used to configure pixel buffer textures.
typedef struct {
Expand Down
4 changes: 2 additions & 2 deletions src/flutter/shell/platform/common/text_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <algorithm>

//#include "flutter/fml/logging.h"
// #include "flutter/fml/logging.h"

namespace flutter {

Expand Down Expand Up @@ -66,7 +66,7 @@ class TextRange {
//
// Asserts that the range is of length 0.
size_t position() const {
//FML_DCHECK(base_ == extent_);
// FML_DCHECK(base_ == extent_);
return extent_;
}

Expand Down
Loading

0 comments on commit 595f7f5

Please sign in to comment.