Skip to content

Commit 595f7f5

Browse files
authored
Add libuv support as a replacement of systemd + some CMake fixes (sony#420)
* git: prevent accidental push on generated files Signed-off-by: Athaariq Ardhiansyah <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * cmake: enforce regex exactness for safety Signed-off-by: Athaariq Ardhiansyah <[email protected]> * 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 <[email protected]> * author: add Athaariq Ardhiansyah Signed-off-by: Athaariq Ardhiansyah <[email protected]> * style: overhaul to comply the standard Signed-off-by: Athaariq Ardhiansyah <[email protected]> * 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 <[email protected]> * 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 <[email protected]> --------- Signed-off-by: Athaariq Ardhiansyah <[email protected]>
1 parent d73e35a commit 595f7f5

File tree

11 files changed

+147
-28
lines changed

11 files changed

+147
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vscode/
22
/build/
3+
/src/third_party/wayland/protocols/*

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Luke Howard <[email protected]>
1515
Stanislav Shmarov <[email protected]>
1616
Sebastian Urban <[email protected]>
1717
Ómar Högni Guðmarsson <[email protected]>
18+
Athaariq Ardhiansyah <[email protected]>

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ set(CMAKE_CXX_STANDARD 17)
1010
project("flutter_elinux" LANGUAGES CXX C)
1111

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

2526
if(NOT BUILD_ELINUX_SO)
2627
# Load the user project.
27-
set(USER_PROJECT_PATH "examples/flutter-wayland-client" CACHE STRING "")
28+
set(USER_PROJECT_PATH "" CACHE STRING "examples/flutter-wayland-client")
2829
message("User project: ${USER_PROJECT_PATH}")
30+
if(NOT ${BACKEND_TYPE} STREQUAL "WAYLAND")
31+
message(WARNING "BACKEND_TYPE variable is ignored because BUILD_ELINUX_SO is OFF")
32+
endif()
2933
include(${USER_PROJECT_PATH}/cmake/user_config.cmake)
3034
else()
3135
# Set the filename of elinux .so file

cmake/build.cmake

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,24 @@ target_link_libraries(${TARGET}
249249
${LIBINPUT_LIBRARIES}
250250
${LIBUDEV_LIBRARIES}
251251
${LIBSYSTEMD_LIBRARIES}
252+
${LIBUV_LIBRARIES}
252253
${X11_LIBRARIES}
253254
${LIBWESTON_LIBRARIES}
254255
${FLUTTER_EMBEDDER_LIB}
255256
## User libraries
256257
${USER_APP_LIBRARIES}
257258
)
258259

259-
if(${BACKEND_TYPE} MATCHES "DRM-(GBM|EGLSTREAM)")
260-
target_link_libraries(${TARGET}
261-
PRIVATE
262-
Threads::Threads
263-
)
260+
if(${BACKEND_TYPE} MATCHES "^DRM-(GBM|EGLSTREAM)$")
261+
target_link_libraries(${TARGET}
262+
PRIVATE
263+
Threads::Threads
264+
)
265+
266+
# Indicate whether libsystemd must replace libuv
267+
if("${LIBSYSTEMD_FOUND}" STREQUAL "1")
268+
add_definitions(-DUSE_LIBSYSTEMD)
269+
endif()
264270
endif()
265271

266272
set(FLUTTER_EMBEDDER_LIB "${CMAKE_CURRENT_SOURCE_DIR}/build/libflutter_engine.so")

cmake/package.cmake

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,26 @@ pkg_check_modules(EGL REQUIRED egl)
99
pkg_check_modules(XKBCOMMON REQUIRED xkbcommon)
1010

1111
# depends on backend type.
12-
if(${BACKEND_TYPE} MATCHES "DRM-(GBM|EGLSTREAM)")
12+
if(${BACKEND_TYPE} MATCHES "^DRM-(GBM|EGLSTREAM)$")
1313
# DRM backend
1414
pkg_check_modules(DRM REQUIRED libdrm)
1515
pkg_check_modules(LIBINPUT REQUIRED libinput)
1616
pkg_check_modules(LIBUDEV REQUIRED libudev)
17-
pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
17+
pkg_check_modules(LIBSYSTEMD libsystemd)
18+
pkg_check_modules(LIBUV libuv)
1819
if(${BACKEND_TYPE} STREQUAL "DRM-GBM")
1920
pkg_check_modules(GBM REQUIRED gbm)
2021
endif()
2122
set(THREADS_PREFER_PTHREAD_FLAG ON)
2223
find_package(Threads REQUIRED)
24+
# Check if either systemd or libuv exist
25+
if((NOT "${LIBSYSTEMD_FOUND}" STREQUAL "1") AND (NOT "${LIBUV_FOUND}" STREQUAL "1"))
26+
message(FATAL_ERROR
27+
"${BACKEND_TYPE} backend requires either libsystemd or libuv, but
28+
they're not exist.")
29+
elseif(("${LIBSYSTEMD_FOUND}" STREQUAL "1") AND ("${LIBUV_FOUND}" STREQUAL "1"))
30+
message("!! NOTICE: libsystemd found, libuv won't be used.")
31+
endif()
2332
elseif(${BACKEND_TYPE} STREQUAL "X11")
2433
pkg_check_modules(X11 REQUIRED x11)
2534
else()

src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class CustomEncodableValue {
7070

7171
#if defined(FLUTTER_ENABLE_RTTI) && FLUTTER_ENABLE_RTTI
7272
// Passthrough to std::any's type().
73-
const std::type_info& type() const noexcept { return value_.type(); }
73+
const std::type_info& type() const noexcept {
74+
return value_.type();
75+
}
7476
#endif
7577

7678
// This operator exists only to provide a stable ordering for use as a

src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class GpuSurfaceTexture {
107107
// The available texture variants.
108108
// Only PixelBufferTexture is currently implemented.
109109
// Other variants are expected to be added in the future.
110-
typedef std::variant<PixelBufferTexture, GpuSurfaceTexture, EGLImageTexture> TextureVariant;
110+
typedef std::variant<PixelBufferTexture, GpuSurfaceTexture, EGLImageTexture>
111+
TextureVariant;
111112

112113
// An object keeping track of external textures.
113114
//

src/flutter/shell/platform/common/json_method_codec.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ JsonMethodCodec::EncodeErrorEnvelopeInternal(
104104
rapidjson::Document envelope(rapidjson::kArrayType);
105105
auto& allocator = envelope.GetAllocator();
106106
envelope.PushBack(rapidjson::Value(error_code.c_str(), allocator), allocator);
107-
envelope.PushBack(rapidjson::Value(error_message.c_str(), allocator), allocator);
107+
envelope.PushBack(rapidjson::Value(error_message.c_str(), allocator),
108+
allocator);
108109
rapidjson::Value details_value;
109110
if (error_details) {
110111
details_value.CopyFrom(*error_details, allocator);

src/flutter/shell/platform/common/public/flutter_texture_registrar.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ typedef struct {
7676
size_t width;
7777
// Height of the EGLImage.
7878
size_t height;
79-
// An optional callback that gets invoked when the |egl_image| can be released.
79+
// An optional callback that gets invoked when the |egl_image| can be
80+
// released.
8081
void (*release_callback)(void* release_context);
8182
// Opaque data passed to |release_callback|.
8283
void* release_context;
@@ -142,12 +143,12 @@ typedef const FlutterDesktopGpuSurfaceDescriptor* (
142143
size_t height,
143144
void* user_data);
144145

145-
typedef const FlutterDesktopEGLImage* (
146-
*FlutterDesktopEGLImageTextureCallback)(size_t width,
147-
size_t height,
148-
void* egl_display,
149-
void* egl_context,
150-
void* user_data);
146+
typedef const FlutterDesktopEGLImage* (*FlutterDesktopEGLImageTextureCallback)(
147+
size_t width,
148+
size_t height,
149+
void* egl_display,
150+
void* egl_context,
151+
void* user_data);
151152

152153
// An object used to configure pixel buffer textures.
153154
typedef struct {

src/flutter/shell/platform/common/text_range.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <algorithm>
99

10-
//#include "flutter/fml/logging.h"
10+
// #include "flutter/fml/logging.h"
1111

1212
namespace flutter {
1313

@@ -66,7 +66,7 @@ class TextRange {
6666
//
6767
// Asserts that the range is of length 0.
6868
size_t position() const {
69-
//FML_DCHECK(base_ == extent_);
69+
// FML_DCHECK(base_ == extent_);
7070
return extent_;
7171
}
7272

0 commit comments

Comments
 (0)