├── .gitignore ├── .clang-format ├── CONTRIBUTING.md ├── examples ├── flutter-wayland-client │ ├── flutter │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ ├── README.md │ ├── cmake │ │ ├── user_config.cmake │ │ └── user_build.cmake │ ├── flutter_window.h │ └── main.cc ├── flutter-x11-client │ ├── flutter │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ ├── README.md │ ├── cmake │ │ ├── user_config.cmake │ │ └── user_build.cmake │ ├── flutter_window.h │ └── main.cc ├── flutter-drm-gbm-backend │ ├── flutter │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ ├── cmake │ │ ├── user_config.cmake │ │ └── user_build.cmake │ ├── README.md │ ├── flutter_window.h │ └── main.cc ├── flutter-drm-eglstream-backend │ ├── flutter │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ ├── cmake │ │ ├── user_config.cmake │ │ └── user_build.cmake │ ├── README.md │ ├── flutter_window.h │ └── main.cc ├── flutter-video-player-plugin │ ├── cmake │ │ ├── user_config.cmake │ │ └── user_build.cmake │ ├── flutter │ │ ├── generated_plugin_registrant.h │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugins.cmake │ │ └── plugins │ │ │ └── video_player │ │ │ └── elinux │ │ │ ├── messages │ │ │ ├── messages.h │ │ │ ├── texture_message.h │ │ │ ├── mix_with_others_message.h │ │ │ ├── volume_message.h │ │ │ ├── playback_speed_message.h │ │ │ ├── looping_message.h │ │ │ └── position_message.h │ │ │ ├── include │ │ │ └── video_player │ │ │ │ └── video_player_plugin.h │ │ │ ├── CMakeLists.txt │ │ │ ├── video_player_stream_handler.h │ │ │ ├── video_player_stream_handler_impl.h │ │ │ └── gst_video_player.h │ ├── flutter_window.h │ ├── README.md │ └── main.cc ├── flutter-external-texture-plugin │ ├── cmake │ │ ├── user_config.cmake │ │ └── user_build.cmake │ ├── flutter │ │ ├── generated_plugin_registrant.h │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugins.cmake │ │ └── plugins │ │ │ └── external_texture_test │ │ │ └── elinux │ │ │ ├── CMakeLists.txt │ │ │ └── include │ │ │ └── external_texture_test │ │ │ └── external_texture_test_plugin.h │ ├── flutter_window.h │ ├── README.md │ └── main.cc └── README.md ├── cmake ├── rapidjson.cmake ├── install.cmake ├── cross-toolchain-aarch64-template.cmake ├── generate_wayland_protocols.cmake ├── cross-toolchain-aarch64-yocto-template.cmake └── package.cmake ├── src ├── flutter │ ├── shell │ │ └── platform │ │ │ ├── common │ │ │ ├── client_wrapper │ │ │ │ ├── engine_method_result.cc │ │ │ │ ├── string_message_codec.cc │ │ │ │ ├── include │ │ │ │ │ └── flutter │ │ │ │ │ │ ├── plugin_registry.h │ │ │ │ │ │ ├── method_call.h │ │ │ │ │ │ ├── string_message_codec.h │ │ │ │ │ │ ├── binary_messenger.h │ │ │ │ │ │ ├── standard_message_codec.h │ │ │ │ │ │ ├── event_sink.h │ │ │ │ │ │ └── message_codec.h │ │ │ │ ├── texture_registrar_impl.h │ │ │ │ ├── binary_messenger_impl.h │ │ │ │ └── plugin_registrar.cc │ │ │ ├── path_utils.h │ │ │ ├── path_utils.cc │ │ │ ├── public │ │ │ │ ├── flutter_export.h │ │ │ │ └── flutter_plugin_registrar.h │ │ │ ├── engine_switches.h │ │ │ ├── json_message_codec.h │ │ │ ├── engine_switches.cc │ │ │ ├── json_message_codec.cc │ │ │ ├── incoming_message_dispatcher.cc │ │ │ └── json_method_codec.h │ │ │ ├── linux_embedded │ │ │ ├── surface │ │ │ │ ├── egl_utils.h │ │ │ │ ├── environment_egl_stream.h │ │ │ │ ├── surface_gl_delegate.h │ │ │ │ ├── context_egl_stream.h │ │ │ │ ├── surface_gl.cc │ │ │ │ ├── context_egl.h │ │ │ │ ├── surface_gl.h │ │ │ │ ├── egl_utils.cc │ │ │ │ ├── surface_base.h │ │ │ │ ├── surface_base.cc │ │ │ │ ├── elinux_egl_surface.h │ │ │ │ ├── surface_decoration.cc │ │ │ │ └── surface_decoration.h │ │ │ ├── plugins │ │ │ │ ├── keyboard_glfw_util.h │ │ │ │ ├── lifecycle_plugin.h │ │ │ │ ├── navigation_plugin.h │ │ │ │ ├── platform_plugin.h │ │ │ │ ├── mouse_cursor_plugin.h │ │ │ │ ├── key_event_plugin.h │ │ │ │ ├── lifecycle_plugin.cc │ │ │ │ ├── navigation_plugin.cc │ │ │ │ ├── settings_plugin.h │ │ │ │ └── text_input_plugin.h │ │ │ ├── window │ │ │ │ ├── renderer │ │ │ │ │ ├── elinux_shader_context.h │ │ │ │ │ ├── elinux_shader_program.h │ │ │ │ │ ├── window_decoration_titlebar.h │ │ │ │ │ ├── elinux_shader.h │ │ │ │ │ ├── window_decoration_button.h │ │ │ │ │ ├── elinux_shader.cc │ │ │ │ │ └── window_decoration.h │ │ │ │ ├── native_window_x11.h │ │ │ │ ├── native_window_wayland.h │ │ │ │ ├── native_window_wayland_decoration.h │ │ │ │ ├── native_window_drm_gbm.h │ │ │ │ ├── native_window_drm_eglstream.h │ │ │ │ ├── native_window_drm.h │ │ │ │ ├── elinux_window.h │ │ │ │ └── native_window.h │ │ │ ├── vsync_waiter.h │ │ │ ├── system_utils.h │ │ │ ├── vsync_waiter.cc │ │ │ ├── logger.h │ │ │ ├── external_texture_pixelbuffer.h │ │ │ ├── external_texture_egl_image.h │ │ │ ├── external_texture.h │ │ │ └── flutter_elinux_texture_registrar.h │ │ │ └── embedder │ │ │ └── embedder_struct_macros.h │ ├── fml │ │ ├── macros.h │ │ └── closure.h │ └── common │ │ └── constants.h ├── client_wrapper │ └── include │ │ └── flutter │ │ └── flutter_view.h └── third_party │ └── rapidjson │ └── include │ └── rapidjson │ └── internal │ ├── swap.h │ └── strfunc.h ├── AUTHORS ├── LICENSE └── CMakeLists.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | /build/ 3 | /src/third_party/wayland/protocols/* -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | # Based on https://github.com/flutter/engine/blob/master/.clang-format 2 | BasedOnStyle: Chromium 3 | Standard: Cpp11 4 | SortIncludes: true -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to flutter-embedded-linux 2 | Welcome to this project. We welcome all your contribution and feedback. If you've never submitted code before, you must add your (or your organization's) name and contact info to the [AUTHORS](./AUTHORS) file. 3 | -------------------------------------------------------------------------------- /examples/flutter-wayland-client/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | void RegisterPlugins(flutter::PluginRegistry* registry) { 10 | } 11 | -------------------------------------------------------------------------------- /examples/flutter-x11-client/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | void RegisterPlugins(flutter::PluginRegistry* registry) { 10 | } 11 | -------------------------------------------------------------------------------- /examples/flutter-drm-gbm-backend/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | void RegisterPlugins(flutter::PluginRegistry* registry) { 10 | } 11 | -------------------------------------------------------------------------------- /examples/flutter-drm-eglstream-backend/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | void RegisterPlugins(flutter::PluginRegistry* registry) { 10 | } 11 | -------------------------------------------------------------------------------- /examples/flutter-x11-client/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | This is the example of X11 backend + stand-alone application. 4 | 5 | ## Building 6 | 7 | ```Shell 8 | $ mkdir build 9 | $ cd build 10 | $ cmake -DUSER_PROJECT_PATH=examples/flutter-x11-client .. 11 | $ cmake --build . 12 | ``` 13 | -------------------------------------------------------------------------------- /examples/flutter-wayland-client/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | This is the example of Wayland backend + stand-alone application. 4 | 5 | ## Building 6 | 7 | ```Shell 8 | $ mkdir build 9 | $ cd build 10 | $ cmake -DUSER_PROJECT_PATH=examples/flutter-wayland-client .. 11 | $ cmake --build . 12 | ``` 13 | -------------------------------------------------------------------------------- /cmake/rapidjson.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # same with Flutter Engine building option 4 | add_definitions( 5 | -DRAPIDJSON_HAS_STDSTRING 6 | -DRAPIDJSON_HAS_CXX11_RANGE_FOR 7 | -DRAPIDJSON_HAS_CXX11_RVALUE_REFS 8 | -DRAPIDJSON_HAS_CXX11_TYPETRAITS 9 | -DRAPIDJSON_HAS_CXX11_NOEXCEPT 10 | ) 11 | -------------------------------------------------------------------------------- /examples/flutter-x11-client/cmake/user_config.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # Flutter embedder configurations. 4 | # See: https://github.com/sony/flutter-embedded-linux/wiki/Building-Embedded-Linux-embedding-for-Flutter#user-configuration-parameters-cmake-options 5 | set(BACKEND_TYPE X11) 6 | set(USE_GLES3 OFF) 7 | -------------------------------------------------------------------------------- /examples/flutter-drm-gbm-backend/cmake/user_config.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # Flutter embedder configurations. 4 | # See: https://github.com/sony/flutter-embedded-linux/wiki/Building-Embedded-Linux-embedding-for-Flutter#user-configuration-parameters-cmake-options 5 | set(BACKEND_TYPE DRM-GBM) 6 | set(USE_GLES3 OFF) 7 | -------------------------------------------------------------------------------- /examples/flutter-wayland-client/cmake/user_config.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # Flutter embedder configurations. 4 | # See: https://github.com/sony/flutter-embedded-linux/wiki/Building-Embedded-Linux-embedding-for-Flutter#user-configuration-parameters-cmake-options 5 | set(BACKEND_TYPE WAYLAND) 6 | set(USE_GLES3 OFF) 7 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/cmake/user_config.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # Flutter embedder configurations. 4 | # See: https://github.com/sony/flutter-embedded-linux/wiki/Building-Embedded-Linux-embedding-for-Flutter#user-configuration-parameters-cmake-options 5 | set(BACKEND_TYPE WAYLAND) 6 | set(USE_GLES3 OFF) 7 | -------------------------------------------------------------------------------- /examples/flutter-external-texture-plugin/cmake/user_config.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # Flutter embedder configurations. 4 | # See: https://github.com/sony/flutter-embedded-linux/wiki/Building-Embedded-Linux-embedding-for-Flutter#user-configuration-parameters-cmake-options 5 | set(BACKEND_TYPE WAYLAND) 6 | set(USE_GLES3 OFF) 7 | -------------------------------------------------------------------------------- /examples/flutter-drm-eglstream-backend/cmake/user_config.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # Flutter embedder configurations. 4 | # See: https://github.com/sony/flutter-embedded-linux/wiki/Building-Embedded-Linux-embedding-for-Flutter#user-configuration-parameters-cmake-options 5 | set(BACKEND_TYPE DRM-EGLSTREAM) 6 | set(USE_GLES3 OFF) 7 | -------------------------------------------------------------------------------- /examples/flutter-x11-client/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /examples/flutter-drm-gbm-backend/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /examples/flutter-wayland-client/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /examples/flutter-drm-eglstream-backend/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /examples/flutter-external-texture-plugin/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | 11 | void RegisterPlugins(flutter::PluginRegistry* registry) { 12 | VideoPlayerPluginRegisterWithRegistrar( 13 | registry->GetRegistrarForPlugin("VideoPlayerPlugin")); 14 | } 15 | -------------------------------------------------------------------------------- /examples/flutter-external-texture-plugin/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | 11 | void RegisterPlugins(flutter::PluginRegistry* registry) { 12 | ExternalTextureTestPluginRegisterWithRegistrar( 13 | registry->GetRegistrarForPlugin("ExternalTextureTestPlugin")); 14 | } 15 | -------------------------------------------------------------------------------- /examples/flutter-x11-client/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | set(PLUGIN_BUNDLED_LIBRARIES) 9 | 10 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 11 | add_subdirectory( 12 | ${USER_PROJECT_PATH}/flutter/plugins/${plugin}/elinux plugins/${plugin}) 13 | 14 | target_link_libraries(${TARGET} 15 | PRIVATE 16 | ${plugin}_plugin 17 | ) 18 | 19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES 20 | ${PROJECT_BINARY_DIR}/plugins/${plugin}/lib${plugin}_plugin.so 21 | ) 22 | endforeach(plugin) 23 | -------------------------------------------------------------------------------- /examples/flutter-drm-gbm-backend/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | set(PLUGIN_BUNDLED_LIBRARIES) 9 | 10 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 11 | add_subdirectory( 12 | ${USER_PROJECT_PATH}/flutter/plugins/${plugin}/elinux plugins/${plugin}) 13 | 14 | target_link_libraries(${TARGET} 15 | PRIVATE 16 | ${plugin}_plugin 17 | ) 18 | 19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES 20 | ${PROJECT_BINARY_DIR}/plugins/${plugin}/lib${plugin}_plugin.so 21 | ) 22 | endforeach(plugin) 23 | -------------------------------------------------------------------------------- /examples/flutter-wayland-client/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | set(PLUGIN_BUNDLED_LIBRARIES) 9 | 10 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 11 | add_subdirectory( 12 | ${USER_PROJECT_PATH}/flutter/plugins/${plugin}/elinux plugins/${plugin}) 13 | 14 | target_link_libraries(${TARGET} 15 | PRIVATE 16 | ${plugin}_plugin 17 | ) 18 | 19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES 20 | ${PROJECT_BINARY_DIR}/plugins/${plugin}/lib${plugin}_plugin.so 21 | ) 22 | endforeach(plugin) 23 | -------------------------------------------------------------------------------- /examples/flutter-drm-eglstream-backend/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | set(PLUGIN_BUNDLED_LIBRARIES) 9 | 10 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 11 | add_subdirectory( 12 | ${USER_PROJECT_PATH}/flutter/plugins/${plugin}/elinux plugins/${plugin}) 13 | 14 | target_link_libraries(${TARGET} 15 | PRIVATE 16 | ${plugin}_plugin 17 | ) 18 | 19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES 20 | ${PROJECT_BINARY_DIR}/plugins/${plugin}/lib${plugin}_plugin.so 21 | ) 22 | endforeach(plugin) 23 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | video_player 7 | ) 8 | 9 | set(PLUGIN_BUNDLED_LIBRARIES) 10 | 11 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 12 | add_subdirectory( 13 | ${USER_PROJECT_PATH}/flutter/plugins/${plugin}/elinux plugins/${plugin}) 14 | 15 | target_link_libraries(${TARGET} 16 | PRIVATE 17 | ${plugin}_plugin 18 | ) 19 | 20 | list(APPEND PLUGIN_BUNDLED_LIBRARIES 21 | ${PROJECT_BINARY_DIR}/plugins/${plugin}/lib${plugin}_plugin.so 22 | ) 23 | endforeach(plugin) 24 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/engine_method_result.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // This file is deprecated in favor of core_implementations.cc. This is a 6 | // temporary forwarding implementation so that the switch to 7 | // core_implementations.cc isn't an immediate breaking change, allowing for the 8 | // template to be updated to include it and update the template version before 9 | // removing this file. 10 | 11 | #include "core_implementations.cc" 12 | -------------------------------------------------------------------------------- /examples/flutter-external-texture-plugin/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | external_texture_test 7 | ) 8 | 9 | set(PLUGIN_BUNDLED_LIBRARIES) 10 | 11 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 12 | add_subdirectory( 13 | ${USER_PROJECT_PATH}/flutter/plugins/${plugin}/elinux plugins/${plugin}) 14 | 15 | target_link_libraries(${TARGET} 16 | PRIVATE 17 | ${plugin}_plugin 18 | ) 19 | 20 | list(APPEND PLUGIN_BUNDLED_LIBRARIES 21 | ${PROJECT_BINARY_DIR}/plugins/${plugin}/lib${plugin}_plugin.so 22 | ) 23 | endforeach(plugin) 24 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/egl_utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_EGL_UTILS_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_EGL_UTILS_H_ 7 | 8 | #include 9 | 10 | namespace flutter { 11 | 12 | std::string get_egl_error_cause(); 13 | bool has_egl_extension(const char* extensions, const char* name); 14 | 15 | } // namespace flutter 16 | 17 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_EGL_UTILS_H_ -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/path_utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_GLFW_PATH_UTILS_H_ 6 | #define FLUTTER_SHELL_PLATFORM_GLFW_PATH_UTILS_H_ 7 | 8 | #include 9 | 10 | namespace flutter { 11 | 12 | // Returns the path of the directory containing this executable, or an empty 13 | // path if the directory cannot be found. 14 | std::filesystem::path GetExecutableDirectory(); 15 | 16 | } // namespace flutter 17 | 18 | #endif // FLUTTER_SHELL_PLATFORM_GLFW_PATH_UTILS_H_ 19 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/messages/messages.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MESSAGES_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MESSAGES_H_ 7 | 8 | #include "create_message.h" 9 | #include "looping_message.h" 10 | #include "mix_with_others_message.h" 11 | #include "playback_speed_message.h" 12 | #include "position_message.h" 13 | #include "texture_message.h" 14 | #include "volume_message.h" 15 | 16 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MESSAGES_H_ 17 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # Below is a list of people and organizations that have contributed 2 | # to sony/flutter-embedded-linux. Names should be added to the list 3 | # like so: 4 | # 5 | # Name/Organization 6 | 7 | Sony Group Corporation 8 | Hidenori Matsubayashi (hidenori.matsubayashi@gmail.com) 9 | Andrea Daoud (andreadaoud6@gmail.com) 10 | Valentin Hăloiu (valentin.haloiu@gmail.com) 11 | FlafyDev 12 | Makoto Sato (makoto.sato@atmark-techno.com) 13 | Yunhao Tian (t123yh@outlook.com) 14 | Luke Howard 15 | Stanislav Shmarov 16 | Sebastian Urban 17 | Ómar Högni Guðmarsson 18 | Athaariq Ardhiansyah 19 | Anton Sakhon 20 | Bari Rao 21 | -------------------------------------------------------------------------------- /cmake/install.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 4 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 5 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 6 | endif() 7 | 8 | # Start with a clean build bundle directory every time. 9 | install(CODE " 10 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 11 | " COMPONENT Runtime) 12 | 13 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 14 | 15 | install(FILES "${FLUTTER_EMBEDDER_LIB}" 16 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 17 | COMPONENT Runtime 18 | ) 19 | 20 | if(PLUGIN_BUNDLED_LIBRARIES) 21 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 22 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 23 | COMPONENT Runtime 24 | ) 25 | endif() 26 | -------------------------------------------------------------------------------- /examples/flutter-external-texture-plugin/flutter/plugins/external_texture_test/elinux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | set(PROJECT_NAME "external_texture_test") 4 | set(PLUGIN_NAME "${PROJECT_NAME}_plugin") 5 | project(${PROJECT_NAME} LANGUAGES CXX) 6 | 7 | add_library(${PLUGIN_NAME} 8 | SHARED 9 | "${PLUGIN_NAME}.cc" 10 | ) 11 | 12 | target_compile_definitions(${PLUGIN_NAME} 13 | PRIVATE 14 | FLUTTER_PLUGIN_IMPL 15 | ) 16 | 17 | target_include_directories(${PLUGIN_NAME} 18 | INTERFACE 19 | ${CMAKE_CURRENT_SOURCE_DIR}/include 20 | ) 21 | 22 | target_include_directories(${PLUGIN_NAME} 23 | PRIVATE 24 | ${CMAKE_SOURCE_DIR}/src/flutter/shell/platform/common/client_wrapper/include 25 | ${CMAKE_SOURCE_DIR}/src/flutter/shell/platform/common/public 26 | ) 27 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/plugins/keyboard_glfw_util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_KEYBOARD_GLFW_UTIL_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_KEYBOARD_GLFW_UTIL_H_ 7 | 8 | #include 9 | 10 | namespace flutter { 11 | 12 | // Converts modifiers for xkb to modifiers for GLFW. 13 | uint32_t GetGlfwModifiers(xkb_keymap* xkb_keymap, xkb_mod_mask_t& xkb_mod_mask); 14 | 15 | // Converts xkb keycode to GLFW keycode. 16 | uint32_t GetGlfwKeycode(uint32_t xkb_keycode); 17 | 18 | } // namespace flutter 19 | 20 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_KEYBOARD_GLFW_UTIL_H_ 21 | -------------------------------------------------------------------------------- /cmake/cross-toolchain-aarch64-template.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | set(CMAKE_SYSTEM_NAME Linux) 4 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 5 | 6 | # Specify the sysroot. 7 | # You need to modify appropriately for your environment. 8 | set(target_sysroot ) 9 | set(CMAKE_SYSROOT ${target_sysroot}) 10 | 11 | # Specify the cross compiler. 12 | set(triple aarch64-linux-gnu) 13 | set(CMAKE_C_COMPILER_TARGET ${triple}) 14 | set(CMAKE_C_COMPILER clang) 15 | set(CMAKE_CXX_COMPILER_TARGET ${triple}) 16 | set(CMAKE_CXX_COMPILER clang++) 17 | 18 | set(CMAKE_FIND_ROOT_PATH ${target_sysroot}) 19 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 20 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 22 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 23 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/include/video_player/video_player_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_INCLUDE_VIDEO_PLAYER_VIDEO_PLAYER_PLUGIN_H_ 2 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_INCLUDE_VIDEO_PLAYER_VIDEO_PLAYER_PLUGIN_H_ 3 | 4 | #include 5 | 6 | #ifdef FLUTTER_PLUGIN_IMPL 7 | #define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default"))) 8 | #else 9 | #define FLUTTER_PLUGIN_EXPORT 10 | #endif 11 | 12 | #if defined(__cplusplus) 13 | extern "C" { 14 | #endif 15 | 16 | FLUTTER_PLUGIN_EXPORT void VideoPlayerPluginRegisterWithRegistrar( 17 | FlutterDesktopPluginRegistrarRef registrar); 18 | 19 | #if defined(__cplusplus) 20 | } // extern "C" 21 | #endif 22 | 23 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_INCLUDE_VIDEO_PLAYER_VIDEO_PLAYER_PLUGIN_H_ 24 | -------------------------------------------------------------------------------- /cmake/generate_wayland_protocols.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | function(generate_wayland_client_protocol) 4 | cmake_parse_arguments(ARGS "" "PROTOCOL_FILE" "CODE_FILE;HEADER_FILE" ${ARGN}) 5 | 6 | find_program(WaylandScannerExec NAMES wayland-scanner) 7 | 8 | get_filename_component(_xml_file ${ARGS_PROTOCOL_FILE} ABSOLUTE) 9 | set_source_files_properties(${ARGS_HEADER_FILE} GENERATED) 10 | set_source_files_properties(${ARGS_CODE_FILE} GENERATED) 11 | 12 | add_custom_command( 13 | OUTPUT ${ARGS_HEADER_FILE} 14 | COMMAND ${WaylandScannerExec} client-header ${_xml_file} ${ARGS_HEADER_FILE} 15 | DEPENDS ${_xml_file} VERBATIM 16 | ) 17 | 18 | add_custom_command( 19 | OUTPUT ${ARGS_CODE_FILE} 20 | COMMAND ${WaylandScannerExec} private-code ${_xml_file} ${ARGS_CODE_FILE} 21 | DEPENDS ${_xml_file} ${ARGS_HEADER_FILE} VERBATIM 22 | ) 23 | endfunction() 24 | -------------------------------------------------------------------------------- /examples/flutter-drm-gbm-backend/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | This is the example of DRM backend with GBM. 4 | 5 | ## Building 6 | 7 | ```Shell 8 | $ mkdir build 9 | $ cd build 10 | $ cmake -DUSER_PROJECT_PATH=examples/flutter-drm-gbm-backend .. 11 | $ cmake --build . 12 | ``` 13 | 14 | ## Running Flutter app 15 | 16 | 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`. 17 | 18 | ```Shell 19 | $ Ctrl + Alt + F3 # Switching to CUI 20 | $ FLUTTER_DRM_DEVICE="/dev/dri/card1" ./flutter-drm-gbm-backend --bundle=FLUTTER_BUNDLE_PATH 21 | ``` 22 | 23 | Note that replace `FLUTTER_BUNDLE_PATH` with the flutter bundle path you want to use like ./sample/build/linux/x64/release/bundle. 24 | 25 | If you want to switch back from CUI to GUI, run `Ctrl + Alt + F2` keys in a terminal. 26 | -------------------------------------------------------------------------------- /examples/flutter-drm-eglstream-backend/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | This is the example of DRM backend with EGLStream. 4 | 5 | ## Building 6 | 7 | ```Shell 8 | $ mkdir build 9 | $ cd build 10 | $ cmake -DUSER_PROJECT_PATH=examples/flutter-drm-eglstream-backend .. 11 | $ cmake --build . 12 | ``` 13 | 14 | ## Running Flutter app 15 | 16 | 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`. 17 | 18 | ```Shell 19 | $ Ctrl + Alt + F3 # Switching to CUI 20 | $ FLUTTER_DRM_DEVICE="/dev/dri/card1" ./flutter-drm-eglstream-backend --bundle=FLUTTER_BUNDLE_PATH 21 | ``` 22 | 23 | Note that replace `FLUTTER_BUNDLE_PATH` with the flutter bundle path you want to use like ./sample/build/linux/x64/release/bundle. 24 | 25 | If you want to switch back from CUI to GUI, run `Ctrl + Alt + F2` keys in a terminal. 26 | -------------------------------------------------------------------------------- /examples/flutter-x11-client/cmake/user_build.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # user binary name. 4 | set(TARGET flutter-x11-client) 5 | 6 | # source files for user apps. 7 | set(USER_APP_SRCS 8 | examples/flutter-x11-client/flutter/generated_plugin_registrant.cc 9 | examples/flutter-x11-client/flutter_window.cc 10 | examples/flutter-x11-client/main.cc 11 | ) 12 | 13 | # header files for user apps. 14 | set(USER_APP_INCLUDE_DIRS 15 | ## Public APIs for developers (Don't edit!). 16 | src/client_wrapper/include 17 | src/flutter/shell/platform/common/client_wrapper 18 | src/flutter/shell/platform/common/client_wrapper/include 19 | src/flutter/shell/platform/common/client_wrapper/include/flutter 20 | src/flutter/shell/platform/common/public 21 | src/flutter/shell/platform/linux_embedded/public 22 | ## header file include path for user apps. 23 | examples/flutter-x11-client 24 | ) 25 | 26 | # link libraries for user apps. 27 | set(USER_APP_LIBRARIES) 28 | -------------------------------------------------------------------------------- /examples/flutter-wayland-client/cmake/user_build.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # user binary name. 4 | set(TARGET flutter-client) 5 | 6 | # source files for user apps. 7 | set(USER_APP_SRCS 8 | examples/flutter-wayland-client/flutter/generated_plugin_registrant.cc 9 | examples/flutter-wayland-client/flutter_window.cc 10 | examples/flutter-wayland-client/main.cc 11 | ) 12 | 13 | # header files for user apps. 14 | set(USER_APP_INCLUDE_DIRS 15 | ## Public APIs for developers (Don't edit!). 16 | src/client_wrapper/include 17 | src/flutter/shell/platform/common/client_wrapper 18 | src/flutter/shell/platform/common/client_wrapper/include 19 | src/flutter/shell/platform/common/client_wrapper/include/flutter 20 | src/flutter/shell/platform/common/public 21 | src/flutter/shell/platform/linux_embedded/public 22 | ## header file include path for user apps. 23 | examples/flutter-wayland-client 24 | ) 25 | 26 | # link libraries for user apps. 27 | set(USER_APP_LIBRARIES) 28 | -------------------------------------------------------------------------------- /examples/flutter-drm-gbm-backend/cmake/user_build.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # user binary name. 4 | set(TARGET flutter-drm-gbm-backend) 5 | 6 | # source files for user apps. 7 | set(USER_APP_SRCS 8 | examples/flutter-drm-gbm-backend/flutter/generated_plugin_registrant.cc 9 | examples/flutter-drm-gbm-backend/flutter_window.cc 10 | examples/flutter-drm-gbm-backend/main.cc 11 | ) 12 | 13 | # header files for user apps. 14 | set(USER_APP_INCLUDE_DIRS 15 | ## Public APIs for developers (Don't edit!). 16 | src/client_wrapper/include 17 | src/flutter/shell/platform/common/client_wrapper 18 | src/flutter/shell/platform/common/client_wrapper/include 19 | src/flutter/shell/platform/common/client_wrapper/include/flutter 20 | src/flutter/shell/platform/common/public 21 | src/flutter/shell/platform/linux_embedded/public 22 | ## header file include path for user apps. 23 | examples/flutter-drm-gbm-backend 24 | ) 25 | 26 | # link libraries for user apps. 27 | set(USER_APP_LIBRARIES) 28 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/cmake/user_build.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # user binary name. 4 | set(TARGET flutter-client) 5 | 6 | # source files for user apps. 7 | set(USER_APP_SRCS 8 | examples/flutter-video-player-plugin/flutter/generated_plugin_registrant.cc 9 | examples/flutter-video-player-plugin/flutter_window.cc 10 | examples/flutter-video-player-plugin/main.cc 11 | ) 12 | 13 | # header files for user apps. 14 | set(USER_APP_INCLUDE_DIRS 15 | ## Public APIs for developers (Don't edit!). 16 | src/client_wrapper/include 17 | src/flutter/shell/platform/common/client_wrapper 18 | src/flutter/shell/platform/common/client_wrapper/include 19 | src/flutter/shell/platform/common/client_wrapper/include/flutter 20 | src/flutter/shell/platform/common/public 21 | src/flutter/shell/platform/linux_embedded/public 22 | ## header file include path for user apps. 23 | examples/flutter-video-player-plugin 24 | ) 25 | 26 | # link libraries for user apps. 27 | set(USER_APP_LIBRARIES) 28 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/renderer/elinux_shader_context.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_ELINUX_SHADER_CONTEXT_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_ELINUX_SHADER_CONTEXT_H_ 7 | 8 | #ifdef USE_GLES3 9 | #include 10 | #else 11 | #include 12 | #endif 13 | 14 | #include 15 | 16 | #include "flutter/shell/platform/linux_embedded/logger.h" 17 | 18 | namespace flutter { 19 | 20 | class ELinuxShaderContext { 21 | public: 22 | ELinuxShaderContext(std::string code, GLenum type); 23 | ~ELinuxShaderContext(); 24 | 25 | GLuint Shader() const { return shader_; } 26 | 27 | private: 28 | GLuint shader_; 29 | }; 30 | 31 | } // namespace flutter 32 | 33 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_ELINUX_SHADER_CONTEXT_H_ 34 | -------------------------------------------------------------------------------- /examples/flutter-external-texture-plugin/cmake/user_build.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # user binary name. 4 | set(TARGET flutter-client) 5 | 6 | # source files for user apps. 7 | set(USER_APP_SRCS 8 | examples/flutter-external-texture-plugin/flutter/generated_plugin_registrant.cc 9 | examples/flutter-external-texture-plugin/flutter_window.cc 10 | examples/flutter-external-texture-plugin/main.cc 11 | ) 12 | 13 | # header files for user apps. 14 | set(USER_APP_INCLUDE_DIRS 15 | ## Public APIs for developers (Don't edit!). 16 | src/client_wrapper/include 17 | src/flutter/shell/platform/common/client_wrapper 18 | src/flutter/shell/platform/common/client_wrapper/include 19 | src/flutter/shell/platform/common/client_wrapper/include/flutter 20 | src/flutter/shell/platform/common/public 21 | src/flutter/shell/platform/linux_embedded/public 22 | ## header file include path for user apps. 23 | examples/flutter-external-texture-plugin 24 | ) 25 | 26 | # link libraries for user apps. 27 | set(USER_APP_LIBRARIES) 28 | -------------------------------------------------------------------------------- /examples/flutter-drm-eglstream-backend/cmake/user_build.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # user binary name. 4 | set(TARGET flutter-drm-eglstream-backend) 5 | 6 | # source files for user apps. 7 | set(USER_APP_SRCS 8 | examples/flutter-drm-eglstream-backend/flutter/generated_plugin_registrant.cc 9 | examples/flutter-drm-eglstream-backend/flutter_window.cc 10 | examples/flutter-drm-eglstream-backend/main.cc 11 | ) 12 | 13 | # header files for user apps. 14 | set(USER_APP_INCLUDE_DIRS 15 | ## Public APIs for developers (Don't edit!). 16 | src/client_wrapper/include 17 | src/flutter/shell/platform/common/client_wrapper 18 | src/flutter/shell/platform/common/client_wrapper/include 19 | src/flutter/shell/platform/common/client_wrapper/include/flutter 20 | src/flutter/shell/platform/common/public 21 | src/flutter/shell/platform/linux_embedded/public 22 | ## header file include path for user apps. 23 | examples/flutter-drm-eglstream-backend 24 | ) 25 | 26 | # link libraries for user apps. 27 | set(USER_APP_LIBRARIES) 28 | -------------------------------------------------------------------------------- /examples/flutter-x11-client/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /examples/flutter-drm-gbm-backend/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /examples/flutter-wayland-client/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /cmake/cross-toolchain-aarch64-yocto-template.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | set(CMAKE_SYSTEM_NAME Linux) 4 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 5 | 6 | # Specify the sysroot. 7 | # You need to modify appropriately for your environment. 8 | set(target_sysroot "") 9 | 10 | # Specify the cross compiler. 11 | # You need to modify appropriately for your environment. 12 | set(toolchain "") 13 | 14 | set(CMAKE_SYSROOT ${target_sysroot}) 15 | set(toolchain_prefix "aarch64-poky-linux-") 16 | set(triple aarch64-poky-linux) 17 | set(CMAKE_C_COMPILER_TARGET ${triple}) 18 | set(CMAKE_C_COMPILER ${toolchain}${toolchain_prefix}clang) 19 | set(CMAKE_CXX_COMPILER_TARGET ${triple}) 20 | set(CMAKE_CXX_COMPILER ${toolchain}${toolchain_prefix}clang++) 21 | 22 | set(CMAKE_FIND_ROOT_PATH ${target_sysroot}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 27 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /examples/flutter-drm-eglstream-backend/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /examples/flutter-external-texture-plugin/flutter_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_WINDOW_ 6 | #define FLUTTER_WINDOW_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | class FlutterWindow { 14 | public: 15 | explicit FlutterWindow( 16 | const flutter::FlutterViewController::ViewProperties view_properties, 17 | const flutter::DartProject project); 18 | ~FlutterWindow() = default; 19 | 20 | // Prevent copying. 21 | FlutterWindow(FlutterWindow const&) = delete; 22 | FlutterWindow& operator=(FlutterWindow const&) = delete; 23 | 24 | bool OnCreate(); 25 | void OnDestroy(); 26 | void Run(); 27 | 28 | private: 29 | flutter::FlutterViewController::ViewProperties view_properties_; 30 | flutter::DartProject project_; 31 | std::unique_ptr flutter_view_controller_; 32 | }; 33 | 34 | #endif // FLUTTER_WINDOW_ 35 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/vsync_waiter.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_VSYNC_WAITER_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_VSYNC_WAITER_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "flutter/shell/platform/embedder/embedder.h" 12 | 13 | namespace flutter { 14 | 15 | class VsyncWaiter { 16 | public: 17 | VsyncWaiter(); 18 | ~VsyncWaiter() = default; 19 | 20 | void NotifyWaitForVsync(intptr_t baton); 21 | 22 | void NotifyVsync(FLUTTER_API_SYMBOL(FlutterEngine) engine, 23 | FlutterEngineProcTable* embedder_api, 24 | uint64_t frame_start_time_nanos, 25 | uint64_t frame_target_time_nanos); 26 | 27 | private: 28 | intptr_t baton_; 29 | uint32_t event_counter_; 30 | std::mutex mutex_; 31 | }; 32 | 33 | } // namespace flutter 34 | 35 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_VSYNC_WAITER_H_ 36 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/string_message_codec.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "include/flutter/string_message_codec.h" 6 | 7 | #include 8 | 9 | namespace flutter { 10 | 11 | // static 12 | const StringMessageCodec& StringMessageCodec::GetInstance() { 13 | static StringMessageCodec sInstance; 14 | return sInstance; 15 | } 16 | 17 | std::unique_ptr> StringMessageCodec::EncodeMessageInternal( 18 | const std::string& message) const { 19 | return std::make_unique>(message.begin(), message.end()); 20 | } 21 | 22 | std::unique_ptr StringMessageCodec::DecodeMessageInternal( 23 | const uint8_t* binary_message, 24 | const size_t message_size) const { 25 | if (!binary_message) { 26 | return nullptr; 27 | } 28 | 29 | auto raw_message = reinterpret_cast(binary_message); 30 | 31 | return std::make_unique(raw_message, message_size); 32 | } 33 | 34 | } // namespace flutter 35 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_LIFECYCLE_PLUGIN_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_LIFECYCLE_PLUGIN_H_ 7 | 8 | #include 9 | 10 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h" 11 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" 12 | 13 | namespace flutter { 14 | 15 | class LifecyclePlugin { 16 | public: 17 | LifecyclePlugin(BinaryMessenger* messenger); 18 | ~LifecyclePlugin() = default; 19 | 20 | void OnInactive() const; 21 | 22 | void OnResumed() const; 23 | 24 | void OnPaused() const; 25 | 26 | void OnDetached() const; 27 | 28 | void OnHidden() const; 29 | 30 | private: 31 | std::unique_ptr> channel_; 32 | }; 33 | 34 | } // namespace flutter 35 | 36 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_LIFECYCLE_PLUGIN_H_ 37 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/environment_egl_stream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_ENVIRONMENT_EGL_STREAM_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_ENVIRONMENT_EGL_STREAM_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "flutter/shell/platform/linux_embedded/surface/environment_egl.h" 12 | 13 | namespace flutter { 14 | 15 | class EnvironmentEglStream : public EnvironmentEgl { 16 | public: 17 | EnvironmentEglStream(bool sub_environment = false); 18 | ~EnvironmentEglStream() = default; 19 | 20 | private: 21 | bool SetEglExtensionFunctionPointers(); 22 | 23 | EGLDeviceEXT GetEglDevice(); 24 | 25 | PFNEGLQUERYDEVICESEXTPROC eglQueryDevicesEXT_; 26 | PFNEGLQUERYDEVICESTRINGEXTPROC eglQueryDeviceStringEXT_; 27 | PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT_; 28 | }; 29 | 30 | } // namespace flutter 31 | 32 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_ENVIRONMENT_EGL_STREAM_H_ 33 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples of embedded Linux embedding for Flutter 2 | 3 | ## Description 4 | These are an example of how to use embedded Linux embedding for Flutter. 5 | 6 | ## Each backend examples 7 | - [flutter-wayland-client](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-wayland-client): Wayland client app 8 | - [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 9 | - [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 10 | - [flutter-x11-client](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-x11-client): X11 client app 11 | 12 | ## Examples using Flutter Plugins 13 | - [flutter-video-player-plugin](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-video-player-plugin): Flutter video player plugin 14 | - [flutter-external-texture-plugin](https://github.com/sony/flutter-embedded-linux/tree/master/examples/flutter-external-texture-plugin): Flutter external texture plugin 15 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/native_window_x11.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_X11_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_X11_H_ 7 | 8 | #include 9 | 10 | #include "flutter/shell/platform/linux_embedded/window/native_window.h" 11 | 12 | namespace flutter { 13 | 14 | class NativeWindowX11 : public NativeWindow { 15 | public: 16 | NativeWindowX11(Display* display, 17 | VisualID visual_id, 18 | const char* title, 19 | const size_t width, 20 | const size_t height, 21 | bool enable_vsync, 22 | bool fullscreen); 23 | ~NativeWindowX11() = default; 24 | 25 | // |NativeWindow| 26 | bool Resize(const size_t width, const size_t height) override; 27 | 28 | void Destroy(Display* display); 29 | 30 | private: 31 | }; 32 | 33 | } // namespace flutter 34 | 35 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_X11_H_ -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/path_utils.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter/shell/platform/common/path_utils.h" 6 | 7 | #if defined(_WIN32) 8 | #include 9 | #elif defined(__linux__) 10 | #include 11 | #include 12 | #endif 13 | 14 | namespace flutter { 15 | 16 | std::filesystem::path GetExecutableDirectory() { 17 | #if defined(_WIN32) 18 | wchar_t buffer[MAX_PATH]; 19 | if (GetModuleFileName(nullptr, buffer, MAX_PATH) == 0) { 20 | return std::filesystem::path(); 21 | } 22 | std::filesystem::path executable_path(buffer); 23 | return executable_path.remove_filename(); 24 | #elif defined(__linux__) 25 | char buffer[PATH_MAX + 1]; 26 | ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer)); 27 | if (length > PATH_MAX) { 28 | return std::filesystem::path(); 29 | } 30 | std::filesystem::path executable_path(std::string(buffer, length)); 31 | return executable_path.remove_filename(); 32 | #else 33 | return std::filesystem::path(); 34 | #endif 35 | } 36 | 37 | } // namespace flutter 38 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/plugins/navigation_plugin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_NAVIGATION_PLUGIN_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_NAVIGATION_PLUGIN_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" 14 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h" 15 | 16 | namespace flutter { 17 | 18 | class NavigationPlugin { 19 | public: 20 | NavigationPlugin(BinaryMessenger* messenger); 21 | ~NavigationPlugin() = default; 22 | 23 | void SetInitialRoute(std::string initial_route) const; 24 | 25 | void PushRoute(std::string route) const; 26 | 27 | void PopRoute() const; 28 | 29 | private: 30 | std::unique_ptr> channel_; 31 | }; 32 | 33 | } // namespace flutter 34 | 35 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_NAVIGATION_PLUGIN_H_ 36 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/public/flutter_export.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_PUBLIC_FLUTTER_EXPORT_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_PUBLIC_FLUTTER_EXPORT_H_ 7 | 8 | #ifdef FLUTTER_DESKTOP_LIBRARY 9 | // Add visibility/export annotations when building the library. 10 | 11 | #ifdef _WIN32 12 | #define FLUTTER_EXPORT __declspec(dllexport) 13 | #else 14 | #define FLUTTER_EXPORT __attribute__((visibility("default"))) 15 | #endif 16 | 17 | #else // FLUTTER_DESKTOP_LIBRARY 18 | 19 | // Add import annotations when consuming the library. 20 | #ifdef _WIN32 21 | #define FLUTTER_EXPORT __declspec(dllimport) 22 | #else 23 | #define FLUTTER_EXPORT 24 | #endif 25 | 26 | #endif // FLUTTER_DESKTOP_LIBRARY 27 | 28 | #if __has_include() 29 | #include 30 | #else 31 | #define SWIFT_UNSAFE_REFERENCE 32 | #define SWIFT_SHARED_REFERENCE(_retain, _release) 33 | #define SWIFT_RETURNS_RETAINED 34 | #define SWIFT_RETURNS_UNRETAINED 35 | #endif 36 | 37 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_PUBLIC_FLUTTER_EXPORT_H_ 38 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/engine_switches.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_ENGINE_SWITCHES_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_ENGINE_SWITCHES_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace flutter { 12 | 13 | // Returns an array of engine switches suitable to pass to the embedder API 14 | // in FlutterProjectArgs, based on parsing variables from the environment in 15 | // the form: 16 | // FLUTTER_ENGINE_SWITCHES= 17 | // FLUTTER_ENGINE_SWITCH_1=... 18 | // FLUTTER_ENGINE_SWITCH_2=... 19 | // ... 20 | // Values should match those in shell/common/switches.h 21 | // 22 | // The returned array does not include the initial dummy argument expected by 23 | // the embedder API, so command_line_argv should not be set directly from it. 24 | // 25 | // In release mode, not all switches from the environment will necessarily be 26 | // returned. See the implementation for details. 27 | std::vector GetSwitchesFromEnvironment(); 28 | 29 | } // namespace flutter 30 | 31 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_ENGINE_SWITCHES_H_ 32 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/surface_gl_delegate.h: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2023 Sony Corporation. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_GL_DELEGATE_H_ 7 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_GL_DELEGATE_H_ 8 | 9 | #include 10 | 11 | #include "flutter/shell/platform/embedder/embedder.h" 12 | 13 | namespace flutter { 14 | 15 | class SurfaceGlDelegate { 16 | public: 17 | virtual bool GLContextMakeCurrent() const = 0; 18 | 19 | virtual bool GLContextClearCurrent() const = 0; 20 | 21 | virtual bool GLContextPresent(uint32_t fbo_id) const = 0; 22 | 23 | virtual bool GLContextPresentWithInfo( 24 | const FlutterPresentInfo* info) const = 0; 25 | 26 | virtual void PopulateExistingDamage(const intptr_t fbo_id, 27 | FlutterDamage* existing_damage) const = 0; 28 | 29 | virtual uint32_t GLContextFBO() const = 0; 30 | 31 | virtual void* GlProcResolver(const char* name) const = 0; 32 | }; 33 | 34 | } // namespace flutter 35 | 36 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_GL_DELEGATE_H_ 37 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/system_utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SYSTEM_UTILS_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SYSTEM_UTILS_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "flutter/shell/platform/embedder/embedder.h" 12 | 13 | namespace flutter { 14 | 15 | // Components of a system language/locale. 16 | struct LanguageInfo { 17 | std::string language; 18 | std::string territory; 19 | std::string codeset; 20 | std::string modifier; 21 | }; 22 | 23 | // Returns the list of user-preferred languages, in preference order, 24 | // parsed into LanguageInfo structures. 25 | std::vector GetPreferredLanguageInfo(); 26 | 27 | // Converts a vector of LanguageInfo structs to a vector of FlutterLocale 28 | // structs. |languages| must outlive the returned value, since the returned 29 | // elements have pointers into it. 30 | std::vector ConvertToFlutterLocale( 31 | const std::vector& languages); 32 | 33 | } // namespace flutter 34 | 35 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SYSTEM_UTILS_H_ 36 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/renderer/elinux_shader_program.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_SHADER_PROGRAM_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_SHADER_PROGRAM_H_ 7 | 8 | #ifdef USE_GLES3 9 | #include 10 | #else 11 | #include 12 | #endif 13 | 14 | #include 15 | 16 | #include "flutter/shell/platform/linux_embedded/logger.h" 17 | #include "flutter/shell/platform/linux_embedded/window/renderer/elinux_shader_context.h" 18 | 19 | namespace flutter { 20 | 21 | class ELinuxShaderProgram { 22 | public: 23 | ELinuxShaderProgram(std::unique_ptr vertex_shader, 24 | std::unique_ptr fragment_shader); 25 | ~ELinuxShaderProgram(); 26 | 27 | GLuint Program() const { return program_; } 28 | 29 | private: 30 | GLuint program_; 31 | std::unique_ptr vertex_shader_; 32 | std::unique_ptr fragment_shader_; 33 | }; 34 | 35 | } // namespace flutter 36 | 37 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_SHADER_PROGRAM_H_ 38 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_WINDOW_DECORATION_TITLEBAR_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_WINDOW_DECORATION_TITLEBAR_H_ 7 | 8 | #include "flutter/shell/platform/linux_embedded/window/renderer/window_decoration.h" 9 | 10 | namespace flutter { 11 | 12 | class WindowDecorationTitlebar : public WindowDecoration { 13 | public: 14 | WindowDecorationTitlebar( 15 | std::unique_ptr native_window, 16 | std::unique_ptr render_surface); 17 | ~WindowDecorationTitlebar(); 18 | 19 | void Draw() override; 20 | 21 | // |WindowDecoration| 22 | void SetPosition(const int32_t x_dip, const int32_t y_dip) override; 23 | 24 | // |WindowDecoration| 25 | void Resize(const size_t width_px, const size_t height_px) override; 26 | 27 | // |WindowDecoration| 28 | void SetScaleFactor(float scale_factor) override; 29 | }; 30 | 31 | } // namespace flutter 32 | 33 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_WINDOW_DECORATION_TITLEBAR_H_ 34 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | set(PROJECT_NAME "video_player") 4 | set(PLUGIN_NAME "${PROJECT_NAME}_plugin") 5 | project(${PROJECT_NAME} LANGUAGES CXX) 6 | 7 | find_package(PkgConfig) 8 | pkg_check_modules(GLIB REQUIRED glib-2.0) 9 | pkg_check_modules(GSTREAMER REQUIRED 10 | gstreamer-1.0 11 | gstreamer-app-1.0 12 | gstreamer-video-1.0 13 | gstreamer-audio-1.0 14 | ) 15 | 16 | add_library(${PLUGIN_NAME} 17 | SHARED 18 | "${PLUGIN_NAME}.cc" 19 | "gst_video_player.cc" 20 | ) 21 | 22 | target_compile_definitions(${PLUGIN_NAME} 23 | PRIVATE 24 | FLUTTER_PLUGIN_IMPL 25 | ) 26 | 27 | target_include_directories(${PLUGIN_NAME} 28 | INTERFACE 29 | ${CMAKE_CURRENT_SOURCE_DIR}/include 30 | ) 31 | 32 | target_include_directories(${PLUGIN_NAME} 33 | PRIVATE 34 | ${CMAKE_SOURCE_DIR}/src/flutter/shell/platform/common/client_wrapper/include 35 | ${CMAKE_SOURCE_DIR}/src/flutter/shell/platform/common/public 36 | ) 37 | 38 | target_include_directories(${PLUGIN_NAME} 39 | PRIVATE 40 | ${GLIB_INCLUDE_DIRS} 41 | ${GSTREAMER_INCLUDE_DIRS} 42 | ${CMAKE_CURRENT_SOURCE_DIR}/src 43 | ) 44 | 45 | target_link_libraries(${PLUGIN_NAME} 46 | PRIVATE 47 | ${GLIB_LIBRARIES} 48 | ${GSTREAMER_LIBRARIES} 49 | ) 50 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_WAYLAND_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_WAYLAND_H_ 7 | 8 | #include 9 | 10 | #include "flutter/shell/platform/linux_embedded/window/native_window.h" 11 | 12 | namespace flutter { 13 | 14 | class NativeWindowWayland : public NativeWindow { 15 | public: 16 | // @param[in] width_px Physical width of the window. 17 | // @param[in] height_px Physical height of the window. 18 | NativeWindowWayland(wl_compositor* compositor, 19 | const size_t width_px, 20 | const size_t height_px, 21 | bool enable_vsync); 22 | ~NativeWindowWayland(); 23 | 24 | // |NativeWindow| 25 | bool Resize(const size_t width_px, const size_t height_px) override; 26 | 27 | wl_surface* Surface() const { return surface_; } 28 | 29 | private: 30 | wl_surface* surface_ = nullptr; 31 | wl_surface* surface_offscreen_ = nullptr; 32 | }; 33 | 34 | } // namespace flutter 35 | 36 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_WAYLAND_H_ 37 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registry.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRY_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRY_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace flutter { 13 | 14 | // Vends PluginRegistrars for named plugins. 15 | // 16 | // Plugins are identified by unique string keys, typically the name of the 17 | // plugin's main class. 18 | class PluginRegistry { 19 | public: 20 | PluginRegistry() = default; 21 | virtual ~PluginRegistry() = default; 22 | 23 | // Prevent copying. 24 | PluginRegistry(PluginRegistry const&) = delete; 25 | PluginRegistry& operator=(PluginRegistry const&) = delete; 26 | 27 | // Returns the FlutterDesktopPluginRegistrarRef to register a plugin with the 28 | // given name. 29 | // 30 | // The name must be unique across the application. 31 | virtual FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin( 32 | const std::string& plugin_name) = 0; 33 | }; 34 | 35 | } // namespace flutter 36 | 37 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRY_H_ 38 | -------------------------------------------------------------------------------- /src/client_wrapper/include/flutter/flutter_view.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_VIEW_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_VIEW_H_ 7 | 8 | #include 9 | 10 | namespace flutter { 11 | 12 | // A view displaying Flutter content. 13 | class FlutterView { 14 | public: 15 | explicit FlutterView(FlutterDesktopViewRef view) : view_(view) {} 16 | 17 | virtual ~FlutterView() = default; 18 | 19 | // Prevent copying. 20 | FlutterView(FlutterView const&) = delete; 21 | FlutterView& operator=(FlutterView const&) = delete; 22 | 23 | // Dispatches window events such as mouse and keyboard inputs. For Wayland, 24 | // you have to call this every time in the main loop. 25 | bool DispatchEvent() { return FlutterDesktopViewDispatchEvent(view_); } 26 | 27 | // Returns the display frame rate. 28 | int32_t GetFrameRate() { return FlutterDesktopViewGetFrameRate(view_); } 29 | 30 | private: 31 | // Handle for interacting with the C API's view. 32 | FlutterDesktopViewRef view_ = nullptr; 33 | }; 34 | 35 | } // namespace flutter 36 | 37 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_VIEW_H_ 38 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/renderer/elinux_shader.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_ELINUX_SHADER_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_ELINUX_SHADER_H_ 7 | 8 | #ifdef USE_GLES3 9 | #include 10 | #else 11 | #include 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | #include "flutter/shell/platform/linux_embedded/logger.h" 18 | #include "flutter/shell/platform/linux_embedded/window/renderer/elinux_shader_context.h" 19 | #include "flutter/shell/platform/linux_embedded/window/renderer/elinux_shader_program.h" 20 | 21 | namespace flutter { 22 | 23 | class ELinuxShader { 24 | public: 25 | ELinuxShader() = default; 26 | ~ELinuxShader() = default; 27 | 28 | void LoadProgram(std::string vertex_code, std::string fragment_code); 29 | void Bind(); 30 | void Unbind(); 31 | GLuint Program() const { return program_->Program(); } 32 | 33 | private: 34 | std::unique_ptr program_; 35 | std::unique_ptr vertex_; 36 | std::unique_ptr fragment_; 37 | }; 38 | 39 | } // namespace flutter 40 | 41 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_ELINUX_SHADER_H_ 42 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/video_player_stream_handler.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_H_ 7 | 8 | class VideoPlayerStreamHandler { 9 | public: 10 | VideoPlayerStreamHandler() = default; 11 | virtual ~VideoPlayerStreamHandler() = default; 12 | 13 | // Prevent copying. 14 | VideoPlayerStreamHandler(VideoPlayerStreamHandler const&) = delete; 15 | VideoPlayerStreamHandler& operator=(VideoPlayerStreamHandler const&) = delete; 16 | 17 | // Notifies the completion of initializing the video player. 18 | void OnNotifyInitialized() { OnNotifyInitializedInternal(); } 19 | 20 | // Notifies the completion of decoding a video frame. 21 | void OnNotifyFrameDecoded() { OnNotifyFrameDecodedInternal(); } 22 | 23 | // Notifies the completion of playing a video. 24 | void OnNotifyCompleted() { OnNotifyCompletedInternal(); } 25 | 26 | protected: 27 | virtual void OnNotifyInitializedInternal() = 0; 28 | virtual void OnNotifyFrameDecodedInternal() = 0; 29 | virtual void OnNotifyCompletedInternal() = 0; 30 | }; 31 | 32 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_H_ 33 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/vsync_waiter.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter/shell/platform/linux_embedded/vsync_waiter.h" 6 | 7 | #include 8 | 9 | #include "flutter/shell/platform/embedder/embedder.h" 10 | #include "flutter/shell/platform/linux_embedded/logger.h" 11 | 12 | namespace flutter { 13 | 14 | VsyncWaiter::VsyncWaiter() : event_counter_(0) {} 15 | 16 | void VsyncWaiter::NotifyWaitForVsync(intptr_t baton) { 17 | std::lock_guard lk(mutex_); 18 | baton_ = baton; 19 | event_counter_++; 20 | } 21 | 22 | void VsyncWaiter::NotifyVsync(FLUTTER_API_SYMBOL(FlutterEngine) engine, 23 | FlutterEngineProcTable* embedder_api, 24 | uint64_t frame_start_time_nanos, 25 | uint64_t frame_target_time_nanos) { 26 | std::lock_guard lk(mutex_); 27 | if (event_counter_ > 0 && baton_ != 0) { 28 | assert(event_counter_ == 1); 29 | event_counter_--; 30 | auto result = embedder_api->OnVsync(engine, baton_, frame_start_time_nanos, 31 | frame_target_time_nanos); 32 | if (result != kSuccess) { 33 | ELINUX_LOG(ERROR) << "FlutterEngineOnVsync failed: batton = " << baton_; 34 | } 35 | } 36 | } 37 | 38 | } // namespace flutter 39 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_CONTEXT_EGL_STREAM_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_CONTEXT_EGL_STREAM_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "flutter/shell/platform/linux_embedded/surface/context_egl.h" 12 | #include "flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h" 13 | #include "flutter/shell/platform/linux_embedded/surface/environment_egl_stream.h" 14 | 15 | namespace flutter { 16 | 17 | class ContextEglStream : public ContextEgl { 18 | public: 19 | ContextEglStream(std::unique_ptr environment); 20 | ~ContextEglStream() = default; 21 | 22 | // |ContextEgl| 23 | std::unique_ptr CreateOnscreenSurface( 24 | NativeWindow* window) const override; 25 | 26 | private: 27 | bool SetEglExtensionFunctionPointers(); 28 | 29 | PFNEGLGETOUTPUTLAYERSEXTPROC eglGetOutputLayersEXT_; 30 | PFNEGLCREATESTREAMKHRPROC eglCreateStreamKHR_; 31 | PFNEGLSTREAMCONSUMEROUTPUTEXTPROC eglStreamConsumerOutputEXT_; 32 | PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC eglCreateStreamProducerSurfaceKHR_; 33 | }; 34 | 35 | } // namespace flutter 36 | 37 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_CONTEXT_EGL_STREAM_H_ 38 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_WINDOW_DECORATION_BUTTON_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_WINDOW_DECORATION_BUTTON_H_ 7 | 8 | #include "flutter/shell/platform/linux_embedded/window/renderer/elinux_shader.h" 9 | #include "flutter/shell/platform/linux_embedded/window/renderer/window_decoration.h" 10 | 11 | namespace flutter { 12 | 13 | class WindowDecorationButton : public WindowDecoration { 14 | public: 15 | WindowDecorationButton( 16 | DecorationType decoration_type, 17 | std::unique_ptr native_window, 18 | std::unique_ptr render_surface); 19 | ~WindowDecorationButton(); 20 | 21 | void Draw() override; 22 | 23 | // |WindowDecoration| 24 | void SetPosition(const int32_t x_dip, const int32_t y_dip) override; 25 | 26 | // |WindowDecoration| 27 | void Resize(const size_t width_px, const size_t height_px) override; 28 | 29 | // |WindowDecoration| 30 | void SetScaleFactor(float scale_factor) override; 31 | 32 | private: 33 | void LoadShader(); 34 | 35 | std::unique_ptr shader_; 36 | }; 37 | 38 | } // namespace flutter 39 | 40 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_WINDOW_DECORATION_BUTTON_H_ 41 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/plugins/platform_plugin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_PLATFORM_PLUGIN_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_PLATFORM_PLUGIN_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" 13 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h" 14 | #include "flutter/shell/platform/linux_embedded/window_binding_handler.h" 15 | 16 | namespace flutter { 17 | 18 | class PlatformPlugin { 19 | public: 20 | PlatformPlugin(BinaryMessenger* messenger, WindowBindingHandler* delegate); 21 | ~PlatformPlugin() = default; 22 | 23 | private: 24 | // Called when a method is called on |channel_|; 25 | void HandleMethodCall( 26 | const flutter::MethodCall& method_call, 27 | std::unique_ptr> result); 28 | 29 | // The MethodChannel used for communication with the Flutter engine. 30 | std::unique_ptr> channel_; 31 | 32 | // The delegate for clipboard data gets and sets. 33 | WindowBindingHandler* delegate_; 34 | }; 35 | 36 | } // namespace flutter 37 | 38 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_PLATFORM_PLUGIN_H_ 39 | -------------------------------------------------------------------------------- /src/flutter/fml/macros.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_FML_MACROS_H_ 6 | #define FLUTTER_FML_MACROS_H_ 7 | 8 | #ifndef FML_USED_ON_EMBEDDER 9 | 10 | #define FML_EMBEDDER_ONLY [[deprecated]] 11 | 12 | #else // FML_USED_ON_EMBEDDER 13 | 14 | #define FML_EMBEDDER_ONLY 15 | 16 | #endif // FML_USED_ON_EMBEDDER 17 | 18 | #define FML_DISALLOW_COPY(TypeName) TypeName(const TypeName&) = delete 19 | 20 | #define FML_DISALLOW_ASSIGN(TypeName) \ 21 | TypeName& operator=(const TypeName&) = delete 22 | 23 | #define FML_DISALLOW_MOVE(TypeName) \ 24 | TypeName(TypeName&&) = delete; \ 25 | TypeName& operator=(TypeName&&) = delete 26 | 27 | #define FML_DISALLOW_COPY_AND_ASSIGN(TypeName) \ 28 | TypeName(const TypeName&) = delete; \ 29 | TypeName& operator=(const TypeName&) = delete 30 | 31 | #define FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName) \ 32 | TypeName(const TypeName&) = delete; \ 33 | TypeName(TypeName&&) = delete; \ 34 | TypeName& operator=(const TypeName&) = delete; \ 35 | TypeName& operator=(TypeName&&) = delete 36 | 37 | #define FML_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ 38 | TypeName() = delete; \ 39 | FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName) 40 | 41 | #define FML_FRIEND_TEST(test_case_name, test_name) \ 42 | friend class test_case_name##_##test_name##_Test 43 | 44 | #endif // FLUTTER_FML_MACROS_H_ 45 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/surface_gl.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter/shell/platform/linux_embedded/surface/surface_gl.h" 6 | 7 | namespace flutter { 8 | 9 | SurfaceGl::SurfaceGl(std::unique_ptr context) { 10 | context_ = std::move(context); 11 | } 12 | 13 | bool SurfaceGl::GLContextMakeCurrent() const { 14 | return onscreen_surface_->MakeCurrent(); 15 | } 16 | 17 | bool SurfaceGl::GLContextClearCurrent() const { 18 | return context_->ClearCurrent(); 19 | } 20 | 21 | bool SurfaceGl::GLContextPresent(uint32_t fbo_id) const { 22 | if (!onscreen_surface_->SwapBuffers()) { 23 | return false; 24 | } 25 | native_window_->SwapBuffers(); 26 | return true; 27 | } 28 | 29 | bool SurfaceGl::GLContextPresentWithInfo(const FlutterPresentInfo* info) const { 30 | if (!onscreen_surface_->SwapBuffers(info)) { 31 | return false; 32 | } 33 | native_window_->SwapBuffers(); 34 | return true; 35 | } 36 | 37 | void SurfaceGl::PopulateExistingDamage(const intptr_t fbo_id, 38 | FlutterDamage* existing_damage) const { 39 | onscreen_surface_->PopulateExistingDamage(fbo_id, existing_damage); 40 | } 41 | 42 | uint32_t SurfaceGl::GLContextFBO() const { 43 | return 0; 44 | } 45 | 46 | void* SurfaceGl::GlProcResolver(const char* name) const { 47 | return context_->GlProcResolver(name); 48 | } 49 | 50 | } // namespace flutter 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2013 The Flutter Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of the Flutter Authors nor the names of its 13 | contributors may be used to endorse or promote products derived 14 | from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/include/flutter/method_call.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_TYPED_METHOD_CALL_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_TYPED_METHOD_CALL_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace flutter { 12 | 13 | class EncodableValue; 14 | 15 | // An object encapsulating a method call from Flutter whose arguments are of 16 | // type T. 17 | template 18 | class MethodCall { 19 | public: 20 | // Creates a MethodCall with the given name and arguments. 21 | MethodCall(const std::string& method_name, std::unique_ptr arguments) 22 | : method_name_(method_name), arguments_(std::move(arguments)) {} 23 | 24 | virtual ~MethodCall() = default; 25 | 26 | // Prevent copying. 27 | MethodCall(MethodCall const&) = delete; 28 | MethodCall& operator=(MethodCall const&) = delete; 29 | 30 | // The name of the method being called. 31 | const std::string& method_name() const { return method_name_; } 32 | 33 | // The arguments to the method call, or NULL if there are none. 34 | const T* arguments() const { return arguments_.get(); } 35 | 36 | private: 37 | std::string method_name_; 38 | std::unique_ptr arguments_; 39 | }; 40 | 41 | } // namespace flutter 42 | 43 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_TYPED_METHOD_CALL_H_ 44 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/json_message_codec.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_JSON_MESSAGE_CODEC_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_JSON_MESSAGE_CODEC_H_ 7 | 8 | #include 9 | 10 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/message_codec.h" 11 | 12 | namespace flutter { 13 | 14 | // A message encoding/decoding mechanism for communications to/from the 15 | // Flutter engine via JSON channels. 16 | class JsonMessageCodec : public MessageCodec { 17 | public: 18 | // Returns the shared instance of the codec. 19 | static const JsonMessageCodec& GetInstance(); 20 | 21 | ~JsonMessageCodec() = default; 22 | 23 | // Prevent copying. 24 | JsonMessageCodec(JsonMessageCodec const&) = delete; 25 | JsonMessageCodec& operator=(JsonMessageCodec const&) = delete; 26 | 27 | protected: 28 | // Instances should be obtained via GetInstance. 29 | JsonMessageCodec() = default; 30 | 31 | // |flutter::MessageCodec| 32 | std::unique_ptr DecodeMessageInternal( 33 | const uint8_t* binary_message, 34 | const size_t message_size) const override; 35 | 36 | // |flutter::MessageCodec| 37 | std::unique_ptr> EncodeMessageInternal( 38 | const rapidjson::Document& message) const override; 39 | }; 40 | 41 | } // namespace flutter 42 | 43 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_JSON_MESSAGE_CODEC_H_ 44 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/logger.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_LOGGER_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_LOGGER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace flutter { 14 | 15 | constexpr int ELINUX_LOG_TRACE = 0; 16 | constexpr int ELINUX_LOG_DEBUG = 1; 17 | constexpr int ELINUX_LOG_INFO = 2; 18 | constexpr int ELINUX_LOG_WARNING = 3; 19 | constexpr int ELINUX_LOG_ERROR = 4; 20 | constexpr int ELINUX_LOG_FATAL = 5; 21 | constexpr int ELINUX_LOG_NUM = 6; 22 | 23 | #if defined(ENABLE_ELINUX_EMBEDDER_LOG) 24 | #if defined(NDEBUG) 25 | // We don't use __FILE__ macro with release build. 26 | #define ELINUX_LOG(level) \ 27 | Logger(ELINUX_LOG_##level, __FUNCTION__, __LINE__).stream() 28 | #else 29 | #define __LOG_FILE_NAME__ \ 30 | (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) 31 | 32 | #define ELINUX_LOG(level) \ 33 | Logger(ELINUX_LOG_##level, __LOG_FILE_NAME__, __LINE__).stream() 34 | #endif 35 | #else 36 | #define ELINUX_LOG(level) Logger(-1, "", 0).stream() 37 | #endif 38 | 39 | class Logger { 40 | public: 41 | Logger(int level, const char* file, int line); 42 | ~Logger(); 43 | 44 | std::ostream& stream() { return stream_; } 45 | 46 | private: 47 | const int level_; 48 | std::ostringstream stream_; 49 | }; 50 | 51 | } // namespace flutter 52 | 53 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_LOGGER_H_ -------------------------------------------------------------------------------- /src/flutter/shell/platform/embedder/embedder_struct_macros.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_ 6 | #define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_ 7 | 8 | #include 9 | 10 | // Checks if the given struct contains a member, whether set or not. 11 | #define STRUCT_HAS_MEMBER(pointer, member) \ 12 | ((offsetof(std::remove_pointer::type, member) + \ 13 | sizeof(pointer->member) <= \ 14 | pointer->struct_size)) 15 | 16 | #define SAFE_ACCESS(pointer, member, default_value) \ 17 | ([=]() { \ 18 | if (STRUCT_HAS_MEMBER(pointer, member)) { \ 19 | return pointer->member; \ 20 | } \ 21 | return static_castmember)>((default_value)); \ 22 | })() 23 | 24 | /// Checks if the member exists and is non-null. 25 | #define SAFE_EXISTS(pointer, member) \ 26 | (SAFE_ACCESS(pointer, member, nullptr) != nullptr) 27 | 28 | /// Checks if exactly one of member1 or member2 exists and is non-null. 29 | #define SAFE_EXISTS_ONE_OF(pointer, member1, member2) \ 30 | (SAFE_EXISTS(pointer, member1) != SAFE_EXISTS(pointer, member2)) 31 | 32 | #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_ 33 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/context_egl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_CONTEXT_EGL_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_CONTEXT_EGL_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h" 13 | #include "flutter/shell/platform/linux_embedded/surface/environment_egl.h" 14 | #include "flutter/shell/platform/linux_embedded/window/native_window.h" 15 | 16 | namespace flutter { 17 | 18 | class ContextEgl { 19 | public: 20 | ContextEgl(std::unique_ptr environment, 21 | bool enable_impeller, 22 | EGLint egl_surface_type = EGL_WINDOW_BIT); 23 | ~ContextEgl() = default; 24 | 25 | virtual std::unique_ptr CreateOnscreenSurface( 26 | NativeWindow* window) const; 27 | 28 | std::unique_ptr CreateOffscreenSurface( 29 | NativeWindow* window_resource) const; 30 | 31 | bool IsValid() const; 32 | 33 | bool ClearCurrent() const; 34 | 35 | void* GlProcResolver(const char* name) const; 36 | 37 | EGLint GetAttrib(EGLint attribute); 38 | 39 | protected: 40 | std::unique_ptr environment_; 41 | EGLConfig config_; 42 | EGLContext context_; 43 | EGLContext resource_context_; 44 | bool valid_; 45 | }; 46 | 47 | } // namespace flutter 48 | 49 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_CONTEXT_EGL_H_ 50 | -------------------------------------------------------------------------------- /src/third_party/rapidjson/include/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | Flutter video player example using video player plugin for Embedded Linux. The interface of the plugin is compatible with [the Flutter official video player plugin](https://github.com/flutter/plugins/tree/master/packages/video_player/video_player). 3 | 4 | Note that this is just example for eLinux embedder, so please use [sony/flutter-elinux-plugins/packages/video_player](https://github.com/sony/flutter-elinux-plugins/tree/main/packages/video_player) 5 | 6 | ![image](https://user-images.githubusercontent.com/62131389/124210378-43f06400-db26-11eb-8723-40dad0eb67b0.png) 7 | 8 | ## Quick start 9 | 10 | ### Install libraries 11 | This plugin uses GStreamer internally. 12 | 13 | ```Shell 14 | $ sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-0 \ 15 | gstreamer1.0-plugins-base gstreamer1.0-plugins-good \ 16 | gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav 17 | ``` 18 | 19 | ### Building the embedder 20 | 21 | ```Shell 22 | $ mkdir build 23 | $ cd build 24 | $ cmake -DUSER_PROJECT_PATH=examples/flutter-video-player-plugin .. 25 | $ cmake --build . 26 | ``` 27 | 28 | ### Building Flutter app with debug mode 29 | 30 | ```Shell 31 | $ git clone https://github.com/flutter/plugins.git 32 | $ cd plugins/packages/video_player/video_player 33 | $ flutter build bundle --asset-dir=./bundle/data/flutter_assets 34 | $ cp /bin/cache/artifacts/engine/linux-*/icudtl.dat ./bundle/data 35 | ``` 36 | 37 | ### Running Flutter app 38 | 39 | ```Shell 40 | $ cd 41 | $ LD_LIBRARY_PATH=./plugins/video_player/ ./flutter-client -b ./bundle/ 42 | ``` 43 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/plugins/mouse_cursor_plugin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_MOUSE_CURSOR_PLUGIN_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_MOUSE_CURSOR_PLUGIN_H_ 7 | 8 | #include 9 | 10 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h" 11 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" 12 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h" 13 | #include "flutter/shell/platform/linux_embedded/window_binding_handler.h" 14 | 15 | namespace flutter { 16 | 17 | class MouseCursorPlugin { 18 | public: 19 | using MouseCursorUpdate = std::function; 20 | 21 | MouseCursorPlugin(BinaryMessenger* messenger, WindowBindingHandler* delegate); 22 | ~MouseCursorPlugin() = default; 23 | 24 | private: 25 | // Called when a method is called on |channel_|; 26 | void HandleMethodCall( 27 | const flutter::MethodCall& method_call, 28 | std::unique_ptr> result); 29 | 30 | // The MethodChannel used for communication with the Flutter engine. 31 | std::unique_ptr> channel_; 32 | 33 | // The delegate for cursor updates. 34 | WindowBindingHandler* delegate_; 35 | }; 36 | 37 | } // namespace flutter 38 | 39 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_MOUSE_CURSOR_PLUGIN_H_ 40 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/surface_gl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_GL_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_GL_H_ 7 | 8 | #include 9 | 10 | #include "flutter/shell/platform/linux_embedded/surface/context_egl.h" 11 | #include "flutter/shell/platform/linux_embedded/surface/surface_base.h" 12 | #include "flutter/shell/platform/linux_embedded/surface/surface_gl_delegate.h" 13 | 14 | namespace flutter { 15 | 16 | class SurfaceGl final : public SurfaceBase, public SurfaceGlDelegate { 17 | public: 18 | SurfaceGl(std::unique_ptr context); 19 | ~SurfaceGl() = default; 20 | 21 | // |SurfaceGlDelegate| 22 | bool GLContextMakeCurrent() const override; 23 | 24 | // |SurfaceGlDelegate| 25 | bool GLContextClearCurrent() const override; 26 | 27 | // |SurfaceGlDelegate| 28 | bool GLContextPresent(uint32_t fbo_id) const override; 29 | 30 | // |SurfaceGlDelegate| 31 | bool GLContextPresentWithInfo(const FlutterPresentInfo* info) const override; 32 | 33 | // |SurfaceGlDelegate| 34 | void PopulateExistingDamage(const intptr_t fbo_id, 35 | FlutterDamage* existing_damage) const override; 36 | 37 | // |SurfaceGlDelegate| 38 | uint32_t GLContextFBO() const override; 39 | 40 | // |SurfaceGlDelegate| 41 | void* GlProcResolver(const char* name) const override; 42 | }; 43 | 44 | } // namespace flutter 45 | 46 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_GL_H_ 47 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/engine_switches.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter/shell/platform/common/engine_switches.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace flutter { 13 | 14 | std::vector GetSwitchesFromEnvironment() { 15 | std::vector switches; 16 | // Read engine switches from the environment in debug/profile. If release mode 17 | // support is needed in the future, it should likely use a whitelist. 18 | #ifndef FLUTTER_RELEASE 19 | const char* switch_count_key = "FLUTTER_ENGINE_SWITCHES"; 20 | const int kMaxSwitchCount = 50; 21 | const char* switch_count_string = std::getenv(switch_count_key); 22 | if (!switch_count_string) { 23 | return switches; 24 | } 25 | int switch_count = std::min(kMaxSwitchCount, atoi(switch_count_string)); 26 | for (int i = 1; i <= switch_count; ++i) { 27 | std::ostringstream switch_key; 28 | switch_key << "FLUTTER_ENGINE_SWITCH_" << i; 29 | const char* switch_value = std::getenv(switch_key.str().c_str()); 30 | if (switch_value) { 31 | std::ostringstream switch_value_as_flag; 32 | switch_value_as_flag << "--" << switch_value; 33 | switches.push_back(switch_value_as_flag.str()); 34 | } else { 35 | std::cerr << switch_count << " keys expected from " << switch_count_key 36 | << ", but " << switch_key.str() << " is missing." << std::endl; 37 | } 38 | } 39 | #endif // !FLUTTER_RELEASE 40 | return switches; 41 | } 42 | 43 | } // namespace flutter 44 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/texture_registrar_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_TEXTURE_REGISTRAR_IMPL_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_TEXTURE_REGISTRAR_IMPL_H_ 7 | 8 | #include "include/flutter/texture_registrar.h" 9 | 10 | namespace flutter { 11 | 12 | // Wrapper around a FlutterDesktopTextureRegistrarRef that implements the 13 | // TextureRegistrar API. 14 | class TextureRegistrarImpl : public TextureRegistrar { 15 | public: 16 | explicit TextureRegistrarImpl( 17 | FlutterDesktopTextureRegistrarRef texture_registrar_ref); 18 | virtual ~TextureRegistrarImpl(); 19 | 20 | // Prevent copying. 21 | TextureRegistrarImpl(TextureRegistrarImpl const&) = delete; 22 | TextureRegistrarImpl& operator=(TextureRegistrarImpl const&) = delete; 23 | 24 | // |flutter::TextureRegistrar| 25 | int64_t RegisterTexture(TextureVariant* texture) override; 26 | 27 | // |flutter::TextureRegistrar| 28 | bool MarkTextureFrameAvailable(int64_t texture_id) override; 29 | 30 | // |flutter::TextureRegistrar| 31 | void UnregisterTexture(int64_t texture_id, 32 | std::function callback) override; 33 | 34 | // |flutter::TextureRegistrar| 35 | bool UnregisterTexture(int64_t texture_id) override; 36 | 37 | private: 38 | // Handle for interacting with the C API. 39 | FlutterDesktopTextureRegistrarRef texture_registrar_ref_; 40 | }; 41 | 42 | } // namespace flutter 43 | 44 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_TEXTURE_REGISTRAR_IMPL_H_ 45 | -------------------------------------------------------------------------------- /cmake/package.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | find_package(PkgConfig) 4 | 5 | # common libraries. 6 | pkg_check_modules(EGL REQUIRED egl) 7 | 8 | # requires for supporting keyboard inputs. 9 | pkg_check_modules(XKBCOMMON REQUIRED xkbcommon) 10 | 11 | # depends on backend type. 12 | if(${BACKEND_TYPE} MATCHES "^DRM-(GBM|EGLSTREAM)$") 13 | # DRM backend 14 | pkg_check_modules(DRM REQUIRED libdrm) 15 | pkg_check_modules(LIBINPUT REQUIRED libinput) 16 | pkg_check_modules(LIBUDEV REQUIRED libudev) 17 | pkg_check_modules(LIBSYSTEMD libsystemd) 18 | pkg_check_modules(LIBUV libuv) 19 | if(${BACKEND_TYPE} STREQUAL "DRM-GBM") 20 | pkg_check_modules(GBM REQUIRED gbm) 21 | endif() 22 | set(THREADS_PREFER_PTHREAD_FLAG ON) 23 | 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() 32 | elseif(${BACKEND_TYPE} STREQUAL "X11") 33 | pkg_check_modules(X11 REQUIRED x11) 34 | else() 35 | # Wayland backend 36 | pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols) 37 | pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client>=1.16.0) 38 | pkg_check_modules(WAYLAND_CURSOR REQUIRED wayland-cursor>=1.16.0) 39 | pkg_check_modules(WAYLAND_EGL REQUIRED wayland-egl>=1.16.0) 40 | endif() 41 | 42 | # requires for supporting external texture plugin. 43 | # OpenGL ES3 are included in glesv2. 44 | pkg_check_modules(GLES REQUIRED glesv2) 45 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/json_message_codec.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter/shell/platform/common/json_message_codec.h" 6 | 7 | #include 8 | #include 9 | 10 | #include "rapidjson/error/en.h" 11 | #include "rapidjson/stringbuffer.h" 12 | #include "rapidjson/writer.h" 13 | 14 | namespace flutter { 15 | 16 | // static 17 | const JsonMessageCodec& JsonMessageCodec::GetInstance() { 18 | static JsonMessageCodec sInstance; 19 | return sInstance; 20 | } 21 | 22 | std::unique_ptr> JsonMessageCodec::EncodeMessageInternal( 23 | const rapidjson::Document& message) const { 24 | // TODO: Look into alternate writers that would avoid the buffer copy. 25 | rapidjson::StringBuffer buffer; 26 | rapidjson::Writer writer(buffer); 27 | message.Accept(writer); 28 | const char* buffer_start = buffer.GetString(); 29 | return std::make_unique>( 30 | buffer_start, buffer_start + buffer.GetSize()); 31 | } 32 | 33 | std::unique_ptr JsonMessageCodec::DecodeMessageInternal( 34 | const uint8_t* binary_message, 35 | const size_t message_size) const { 36 | auto raw_message = reinterpret_cast(binary_message); 37 | auto json_message = std::make_unique(); 38 | rapidjson::ParseResult result = 39 | json_message->Parse(raw_message, message_size); 40 | if (result.IsError()) { 41 | std::cerr << "Unable to parse JSON message:" << std::endl 42 | << rapidjson::GetParseError_En(result.Code()) << std::endl; 43 | return nullptr; 44 | } 45 | return json_message; 46 | } 47 | 48 | } // namespace flutter 49 | -------------------------------------------------------------------------------- /examples/flutter-external-texture-plugin/flutter/plugins/external_texture_test/elinux/include/external_texture_test/external_texture_test_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef PLUGINS_EXTERNAL_TEXTURE_TEST_ELINUX_EXTERNAL_TEXTURE_TEST_PLUGIN_H_ 2 | #define PLUGINS_EXTERNAL_TEXTURE_TEST_ELINUX_EXTERNAL_TEXTURE_TEST_PLUGIN_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace { 10 | class ColorBarTexture { 11 | public: 12 | ColorBarTexture(); 13 | virtual ~ColorBarTexture() {} 14 | const FlutterDesktopPixelBuffer* CopyBuffer(size_t width, size_t height); 15 | 16 | private: 17 | void PrepareBuffer(); 18 | 19 | std::unique_ptr buffer_; 20 | std::unique_ptr pixels_; 21 | int32_t request_count_; 22 | }; 23 | 24 | class ExternalTextureTestPlugin : public flutter::Plugin { 25 | public: 26 | static void RegisterWithRegistrar(flutter::PluginRegistrar* registrar); 27 | 28 | ExternalTextureTestPlugin(flutter::TextureRegistrar* textures) 29 | : textures_(textures), texture_(nullptr), color_bar_texture_(nullptr) {} 30 | 31 | virtual ~ExternalTextureTestPlugin() {} 32 | 33 | private: 34 | // Called when a method is called on this plugin's channel from Dart. 35 | void HandleMethodCall( 36 | const flutter::MethodCall& method_call, 37 | std::unique_ptr> result); 38 | 39 | flutter::TextureRegistrar* textures_; 40 | std::unique_ptr texture_; 41 | std::unique_ptr color_bar_texture_; 42 | }; 43 | 44 | } // namespace 45 | 46 | void ExternalTextureTestPluginRegisterWithRegistrar( 47 | FlutterDesktopPluginRegistrarRef registrar); 48 | 49 | #endif // PLUGINS_EXTERNAL_TEXTURE_TEST_ELINUX_EXTERNAL_TEXTURE_TEST_PLUGIN_H_ 50 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/public/flutter_plugin_registrar.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_PUBLIC_FLUTTER_PLUGIN_REGISTRAR_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_PUBLIC_FLUTTER_PLUGIN_REGISTRAR_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "flutter_export.h" 12 | #include "flutter_messenger.h" 13 | #include "flutter_texture_registrar.h" 14 | 15 | #if defined(__cplusplus) 16 | extern "C" { 17 | #endif // defined(__cplusplus) 18 | 19 | // Opaque reference to a plugin registrar. 20 | typedef struct FlutterDesktopPluginRegistrar* FlutterDesktopPluginRegistrarRef; 21 | 22 | // Function pointer type for registrar destruction callback. 23 | typedef void (*FlutterDesktopOnPluginRegistrarDestroyed)( 24 | FlutterDesktopPluginRegistrarRef); 25 | 26 | // Returns the engine messenger associated with this registrar. 27 | FLUTTER_EXPORT FlutterDesktopMessengerRef 28 | FlutterDesktopPluginRegistrarGetMessenger( 29 | FlutterDesktopPluginRegistrarRef registrar) SWIFT_RETURNS_UNRETAINED; 30 | 31 | // Returns the texture registrar associated with this registrar. 32 | FLUTTER_EXPORT FlutterDesktopTextureRegistrarRef 33 | FlutterDesktopRegistrarGetTextureRegistrar( 34 | FlutterDesktopPluginRegistrarRef registrar); 35 | 36 | // Registers a callback to be called when the plugin registrar is destroyed. 37 | FLUTTER_EXPORT void FlutterDesktopPluginRegistrarSetDestructionHandler( 38 | FlutterDesktopPluginRegistrarRef registrar, 39 | FlutterDesktopOnPluginRegistrarDestroyed callback); 40 | 41 | #if defined(__cplusplus) 42 | } // extern "C" 43 | #endif 44 | 45 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_PUBLIC_FLUTTER_PLUGIN_REGISTRAR_H_ 46 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/binary_messenger_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_BINARY_MESSENGER_IMPL_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_BINARY_MESSENGER_IMPL_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include "include/flutter/binary_messenger.h" 14 | 15 | namespace flutter { 16 | 17 | // Wrapper around a FlutterDesktopMessengerRef that implements the 18 | // BinaryMessenger API. 19 | class BinaryMessengerImpl : public BinaryMessenger { 20 | public: 21 | explicit BinaryMessengerImpl(FlutterDesktopMessengerRef core_messenger); 22 | 23 | virtual ~BinaryMessengerImpl(); 24 | 25 | // Prevent copying. 26 | BinaryMessengerImpl(BinaryMessengerImpl const&) = delete; 27 | BinaryMessengerImpl& operator=(BinaryMessengerImpl const&) = delete; 28 | 29 | // |flutter::BinaryMessenger| 30 | void Send(const std::string& channel, 31 | const uint8_t* message, 32 | size_t message_size, 33 | BinaryReply reply) const override; 34 | 35 | // |flutter::BinaryMessenger| 36 | void SetMessageHandler(const std::string& channel, 37 | BinaryMessageHandler handler) override; 38 | 39 | private: 40 | // Handle for interacting with the C API. 41 | FlutterDesktopMessengerRef messenger_; 42 | 43 | // A map from channel names to the BinaryMessageHandler that should be called 44 | // for incoming messages on that channel. 45 | std::map handlers_; 46 | }; 47 | 48 | } // namespace flutter 49 | 50 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_BINARY_MESSENGER_IMPL_H_ 51 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_WAYLAND_DECORATION_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_WAYLAND_DECORATION_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "flutter/shell/platform/linux_embedded/window/native_window.h" 12 | 13 | namespace flutter { 14 | 15 | class NativeWindowWaylandDecoration : public NativeWindow { 16 | public: 17 | // @param[in] width_px Physical width of the window. 18 | // @param[in] height_px Physical height of the window. 19 | NativeWindowWaylandDecoration(wl_compositor* compositor, 20 | wl_subcompositor* subcompositor, 21 | wl_surface* parent_surface, 22 | const size_t width_px, 23 | const size_t height_px, 24 | bool enable_vsync); 25 | ~NativeWindowWaylandDecoration(); 26 | 27 | // |NativeWindow| 28 | bool Resize(const size_t width_px, const size_t height_px) override; 29 | 30 | // |NativeWindow| 31 | void SetPosition(const int32_t x_dip, const int32_t y_dip) override; 32 | 33 | // Sets the scale factor for the next commit. Scale factor persists until a 34 | // new one is set. 35 | void SetScaleFactor(float scale_factor); 36 | 37 | wl_surface* Surface() const { return surface_; } 38 | 39 | private: 40 | wl_surface* surface_ = nullptr; 41 | wl_subsurface* subsurface_ = nullptr; 42 | }; 43 | 44 | } // namespace flutter 45 | 46 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_WAYLAND_DECORATION_H_ 47 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/messages/texture_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class TextureMessage { 12 | public: 13 | TextureMessage() = default; 14 | ~TextureMessage() = default; 15 | 16 | // Prevent copying. 17 | TextureMessage(TextureMessage const&) = default; 18 | TextureMessage& operator=(TextureMessage const&) = default; 19 | 20 | void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } 21 | 22 | int64_t GetTextureId() const { return texture_id_; } 23 | 24 | flutter::EncodableValue ToMap() { 25 | flutter::EncodableMap map = {{flutter::EncodableValue("textureId"), 26 | flutter::EncodableValue(texture_id_)}}; 27 | return flutter::EncodableValue(map); 28 | } 29 | 30 | static TextureMessage FromMap(const flutter::EncodableValue& value) { 31 | TextureMessage message; 32 | if (std::holds_alternative(value)) { 33 | auto map = std::get(value); 34 | 35 | flutter::EncodableValue& texture_id = 36 | map[flutter::EncodableValue("textureId")]; 37 | if (std::holds_alternative(texture_id) || 38 | std::holds_alternative(texture_id)) { 39 | message.SetTextureId(texture_id.LongValue()); 40 | } 41 | } 42 | return message; 43 | } 44 | 45 | private: 46 | int64_t texture_id_ = 0; 47 | }; 48 | 49 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_TEXTURE_MESSAGE_H_ 50 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_DRM_GBM_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_DRM_GBM_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include "flutter/shell/platform/linux_embedded/window/native_window_drm.h" 15 | 16 | namespace flutter { 17 | 18 | class NativeWindowDrmGbm : public NativeWindowDrm { 19 | public: 20 | NativeWindowDrmGbm(const char* device_filename, 21 | const uint16_t rotation, 22 | bool enable_vsync); 23 | ~NativeWindowDrmGbm(); 24 | 25 | // |NativeWindowDrm| 26 | bool ShowCursor(double x, double y) override; 27 | 28 | // |NativeWindowDrm| 29 | bool UpdateCursor(const std::string& cursor_name, 30 | double x, 31 | double y) override; 32 | 33 | // |NativeWindowDrm| 34 | bool DismissCursor() override; 35 | 36 | // |NativeWindowDrm| 37 | std::unique_ptr CreateRenderSurface(bool enable_impeller) override; 38 | 39 | // |NativeWindow| 40 | bool IsNeedRecreateSurfaceAfterResize() const override; 41 | 42 | // |NativeWindow| 43 | bool Resize(const size_t width, const size_t height) override; 44 | 45 | // |NativeWindow| 46 | void SwapBuffers() override; 47 | 48 | private: 49 | bool CreateGbmSurface(); 50 | 51 | bool CreateCursorBuffer(const std::string& cursor_name); 52 | 53 | gbm_bo* gbm_previous_bo_ = nullptr; 54 | uint32_t gbm_previous_fb_; 55 | gbm_device* gbm_device_ = nullptr; 56 | gbm_bo* gbm_cursor_bo_ = nullptr; 57 | }; 58 | 59 | } // namespace flutter 60 | 61 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_DRM_GBM_H_ 62 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/include/flutter/string_message_codec.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef __CODE_FLUTTER_EMBEDDED_LINUX_SRC_FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STRING_MESSAGE_CODEC_H_ 6 | #define __CODE_FLUTTER_EMBEDDED_LINUX_SRC_FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STRING_MESSAGE_CODEC_H_ 7 | 8 | #include "message_codec.h" 9 | 10 | namespace flutter { 11 | 12 | // A message encoding/decoding mechanism for communications to/from the Flutter 13 | // engine via UTF-8 encoded string messages. 14 | // 15 | // This codec is guaranteed to be compatible with the corresponding 16 | // [StringCodec](https://api.flutter.dev/flutter/services/StringCodec-class.html) 17 | // on the Dart side. These parts of the Flutter SDK are evolved synchronously. 18 | class StringMessageCodec : public MessageCodec { 19 | public: 20 | // Returns the shared instance of the codec. 21 | static const StringMessageCodec& GetInstance(); 22 | 23 | ~StringMessageCodec() = default; 24 | 25 | // Prevent copying. 26 | StringMessageCodec(StringMessageCodec const&) = delete; 27 | StringMessageCodec& operator=(StringMessageCodec const&) = delete; 28 | 29 | protected: 30 | // Instances should be obtained via GetInstance. 31 | StringMessageCodec() = default; 32 | 33 | // |flutter::MessageCodec| 34 | std::unique_ptr DecodeMessageInternal( 35 | const uint8_t* binary_message, 36 | const size_t message_size) const override; 37 | 38 | // |flutter::MessageCodec| 39 | std::unique_ptr> EncodeMessageInternal( 40 | const std::string& message) const override; 41 | }; 42 | 43 | } // namespace flutter 44 | 45 | #endif // __CODE_FLUTTER_EMBEDDED_LINUX_SRC_FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STRING_MESSAGE_CODEC_H_ 46 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/egl_utils.cc: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2023 Sony Corporation. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #include "flutter/shell/platform/linux_embedded/surface/egl_utils.h" 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace flutter { 15 | 16 | std::string get_egl_error_cause() { 17 | static const std::vector> table = { 18 | {EGL_SUCCESS, "EGL_SUCCESS"}, 19 | {EGL_NOT_INITIALIZED, "EGL_NOT_INITIALIZED"}, 20 | {EGL_BAD_ACCESS, "EGL_BAD_ACCESS"}, 21 | {EGL_BAD_ALLOC, "EGL_BAD_ALLOC"}, 22 | {EGL_BAD_ATTRIBUTE, "EGL_BAD_ATTRIBUTE"}, 23 | {EGL_BAD_CONTEXT, "EGL_BAD_CONTEXT"}, 24 | {EGL_BAD_CONFIG, "EGL_BAD_CONFIG"}, 25 | {EGL_BAD_CURRENT_SURFACE, "EGL_BAD_CURRENT_SURFACE"}, 26 | {EGL_BAD_DISPLAY, "EGL_BAD_DISPLAY"}, 27 | {EGL_BAD_SURFACE, "EGL_BAD_SURFACE"}, 28 | {EGL_BAD_MATCH, "EGL_BAD_MATCH"}, 29 | {EGL_BAD_PARAMETER, "EGL_BAD_PARAMETER"}, 30 | {EGL_BAD_NATIVE_PIXMAP, "EGL_BAD_NATIVE_PIXMAP"}, 31 | {EGL_BAD_NATIVE_WINDOW, "EGL_BAD_NATIVE_WINDOW"}, 32 | {EGL_CONTEXT_LOST, "EGL_CONTEXT_LOST"}, 33 | }; 34 | 35 | auto egl_error = eglGetError(); 36 | for (auto t : table) { 37 | if (egl_error == t.first) { 38 | return std::string("eglGetError: " + t.second); 39 | } 40 | } 41 | return nullptr; 42 | } 43 | 44 | // Auxiliary function used to check if the given list of extensions contains the 45 | // requested extension name. 46 | bool has_egl_extension(const char* extensions, const char* name) { 47 | const char* r = std::strstr(extensions, name); 48 | auto len = std::strlen(name); 49 | 50 | // check that the extension name is terminated by space or null terminator 51 | return r != nullptr && (r[len] == ' ' || r[len] == 0); 52 | } 53 | 54 | } // namespace flutter 55 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/messages/mix_with_others_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MIX_WITH_OTHERS_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MIX_WITH_OTHERS_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class MixWithOthersMessage { 12 | public: 13 | MixWithOthersMessage() = default; 14 | ~MixWithOthersMessage() = default; 15 | 16 | // Prevent copying. 17 | MixWithOthersMessage(MixWithOthersMessage const&) = default; 18 | MixWithOthersMessage& operator=(MixWithOthersMessage const&) = default; 19 | 20 | void SetMixWithOthers(bool mixWithOthers) { 21 | mix_with_others_ = mixWithOthers; 22 | } 23 | 24 | bool GetMixWithOthers() const { return mix_with_others_; } 25 | 26 | flutter::EncodableValue ToMap() { 27 | flutter::EncodableMap map = {{flutter::EncodableValue("mixWithOthers"), 28 | flutter::EncodableValue(mix_with_others_)}}; 29 | 30 | return flutter::EncodableValue(map); 31 | } 32 | 33 | static MixWithOthersMessage FromMap(const flutter::EncodableValue& value) { 34 | MixWithOthersMessage message; 35 | if (std::holds_alternative(value)) { 36 | auto map = std::get(value); 37 | 38 | flutter::EncodableValue& mixWithOthers = 39 | map[flutter::EncodableValue("mixWithOthers")]; 40 | if (std::holds_alternative(mixWithOthers)) { 41 | message.SetMixWithOthers(std::get(mixWithOthers)); 42 | } 43 | } 44 | 45 | return message; 46 | } 47 | 48 | private: 49 | bool mix_with_others_ = false; 50 | }; 51 | 52 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_MIX_WITH_OTHERS_MESSAGE_H_ 53 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_PIXELBUFFER_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_PIXELBUFFER_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "flutter/shell/platform/common/public/flutter_texture_registrar.h" 13 | 14 | #include "flutter/shell/platform/linux_embedded/external_texture.h" 15 | 16 | namespace flutter { 17 | 18 | typedef struct ExternalTexturePixelBufferState ExternalTexturePixelBufferState; 19 | 20 | // An abstraction of an pixel-buffer based texture. 21 | class ExternalTexturePixelBuffer : public ExternalTexture { 22 | public: 23 | ExternalTexturePixelBuffer( 24 | FlutterDesktopPixelBufferTextureCallback texture_callback, 25 | void* user_data, 26 | const GlProcs& gl_procs); 27 | 28 | virtual ~ExternalTexturePixelBuffer(); 29 | 30 | // |ExternalTexture| 31 | bool PopulateTexture(size_t width, 32 | size_t height, 33 | FlutterOpenGLTexture* opengl_texture) override; 34 | 35 | private: 36 | // Attempts to copy the pixel buffer returned by |texture_callback_| to 37 | // OpenGL. 38 | // The |width| and |height| will be set to the actual bounds of the copied 39 | // pixel buffer. 40 | // Returns true on success or false if the pixel buffer returned 41 | // by |texture_callback_| was invalid. 42 | bool CopyPixelBuffer(size_t& width, size_t& height); 43 | 44 | std::unique_ptr state_; 45 | FlutterDesktopPixelBufferTextureCallback texture_callback_ = nullptr; 46 | void* const user_data_ = nullptr; 47 | const GlProcs& gl_; 48 | }; 49 | 50 | } // namespace flutter 51 | 52 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_PIXELBUFFER_H_ 53 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/plugins/key_event_plugin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_KEY_EVENT_PLUGIN_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_KEY_EVENT_PLUGIN_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h" 15 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" 16 | 17 | namespace flutter { 18 | 19 | class KeyeventPlugin { 20 | public: 21 | KeyeventPlugin(BinaryMessenger* messenger); 22 | ~KeyeventPlugin(); 23 | 24 | void OnKeymap(uint32_t format, uint32_t fd, uint32_t size); 25 | 26 | void OnKey(uint32_t keycode, bool pressed); 27 | 28 | void OnModifiers(uint32_t mods_depressed, 29 | uint32_t mods_latched, 30 | uint32_t mods_locked, 31 | uint32_t group); 32 | 33 | uint32_t GetCodePoint(uint32_t keycode); 34 | 35 | bool IsTextInputSuppressed(uint32_t code_point); 36 | 37 | private: 38 | void SendKeyEvent(uint32_t keycode, 39 | uint32_t unicode, 40 | uint32_t modifiers, 41 | bool pressed); 42 | void OnModifiers(uint32_t keycode, bool pressed); 43 | xkb_keymap* CreateKeymap(xkb_context* context); 44 | std::unordered_map GetKeyboardConfig( 45 | std::string filename); 46 | 47 | std::unique_ptr> channel_; 48 | xkb_context* xkb_context_; 49 | xkb_state* xkb_state_; 50 | xkb_keymap* xkb_keymap_; 51 | xkb_mod_mask_t xkb_mods_mask_; 52 | }; 53 | 54 | } // namespace flutter 55 | 56 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_KEY_EVENT_PLUGIN_H_ 57 | -------------------------------------------------------------------------------- /src/flutter/common/constants.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_COMMON_CONSTANTS_H_ 6 | #define FLUTTER_COMMON_CONSTANTS_H_ 7 | 8 | namespace flutter { 9 | constexpr double kMegaByteSizeInBytes = (1 << 20); 10 | 11 | // The ID for the implicit view if the implicit view is enabled. 12 | // 13 | // The implicit view is a compatibility mechanism to help the transition from 14 | // the older single-view APIs to the newer multi-view APIs. The two sets of APIs 15 | // use different models for view management. The implicit view mechanism allows 16 | // single-view APIs to operate a special view as if other views don't exist. 17 | // 18 | // In the regular multi-view model, all views should be created by 19 | // `Shell::AddView` before being used, and removed by `Shell::RemoveView` to 20 | // signify that they are gone. If a view is added or removed, the framework 21 | // (`PlatformDispatcher`) will be notified. New view IDs are always unique, 22 | // never reused. Operating a non-existing view is an error. 23 | // 24 | // The implicit view is another special view in addition to the "regular views" 25 | // as above. The shell starts up having the implicit view, which has a fixed 26 | // view ID of `kFlutterImplicitViewId` and is available throughout the lifetime 27 | // of the shell. `Shell::AddView` or `RemoveView` must not be called for this 28 | // view. Even when the window that shows the view is closed, the framework is 29 | // unaware and might continue rendering into or operating this view. 30 | // 31 | // The single-view APIs, which are APIs that do not specify view IDs, operate 32 | // the implicit view. The multi-view APIs can operate all views, including the 33 | // implicit view if the target ID is `kFlutterImplicitViewId`, unless specified 34 | // otherwise. 35 | constexpr int64_t kFlutterImplicitViewId = 0; 36 | } // namespace flutter 37 | 38 | #endif // FLUTTER_COMMON_CONSTANTS_H_ 39 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/plugin_registrar.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "include/flutter/plugin_registrar.h" 6 | 7 | #include 8 | #include 9 | 10 | #include "binary_messenger_impl.h" 11 | #include "include/flutter/engine_method_result.h" 12 | #include "include/flutter/method_channel.h" 13 | #include "texture_registrar_impl.h" 14 | 15 | namespace flutter { 16 | 17 | // ===== PluginRegistrar ===== 18 | 19 | PluginRegistrar::PluginRegistrar(FlutterDesktopPluginRegistrarRef registrar) 20 | : registrar_(registrar) { 21 | auto core_messenger = FlutterDesktopPluginRegistrarGetMessenger(registrar_); 22 | messenger_ = std::make_unique(core_messenger); 23 | 24 | auto texture_registrar = 25 | FlutterDesktopRegistrarGetTextureRegistrar(registrar_); 26 | texture_registrar_ = 27 | std::make_unique(texture_registrar); 28 | } 29 | 30 | PluginRegistrar::~PluginRegistrar() { 31 | // This must always be the first call. 32 | ClearPlugins(); 33 | 34 | // Explicitly cleared to facilitate testing of destruction order. 35 | messenger_.reset(); 36 | } 37 | 38 | void PluginRegistrar::AddPlugin(std::unique_ptr plugin) { 39 | plugins_.insert(std::move(plugin)); 40 | } 41 | 42 | void PluginRegistrar::ClearPlugins() { 43 | plugins_.clear(); 44 | } 45 | 46 | // ===== PluginRegistrarManager ===== 47 | 48 | // static 49 | PluginRegistrarManager* PluginRegistrarManager::GetInstance() { 50 | static PluginRegistrarManager* instance = new PluginRegistrarManager(); 51 | return instance; 52 | } 53 | 54 | PluginRegistrarManager::PluginRegistrarManager() = default; 55 | 56 | // static 57 | void PluginRegistrarManager::OnRegistrarDestroyed( 58 | FlutterDesktopPluginRegistrarRef registrar) { 59 | GetInstance()->registrars()->erase(registrar); 60 | } 61 | 62 | } // namespace flutter 63 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/external_texture_egl_image.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_EGL_IMAGE_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_EGL_IMAGE_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "flutter/shell/platform/common/public/flutter_texture_registrar.h" 13 | 14 | #include "flutter/shell/platform/linux_embedded/external_texture.h" 15 | 16 | namespace flutter { 17 | 18 | typedef struct ExternalTextureEGLImageState ExternalTextureEGLImageState; 19 | 20 | // An abstraction of an EGL Image based texture. 21 | class ExternalTextureEGLImage : public ExternalTexture { 22 | public: 23 | ExternalTextureEGLImage( 24 | FlutterDesktopEGLImageTextureCallback texture_callback, 25 | void* user_data, 26 | const GlProcs& gl_procs); 27 | 28 | virtual ~ExternalTextureEGLImage(); 29 | 30 | // |ExternalTexture| 31 | bool PopulateTexture(size_t width, 32 | size_t height, 33 | FlutterOpenGLTexture* opengl_texture) override; 34 | 35 | private: 36 | // Attempts to get the EGLImage returned by |texture_callback_| to 37 | // OpenGL. 38 | // The |width| and |height| will be set to the actual bounds of the EGLImage 39 | // Returns true on success or false if the EGLImage returned 40 | // by |texture_callback_| was invalid. 41 | bool GetEGLImage(size_t& width, 42 | size_t& height, 43 | void* egl_display, 44 | void* egl_context); 45 | 46 | std::unique_ptr state_; 47 | FlutterDesktopEGLImageTextureCallback texture_callback_ = nullptr; 48 | void* const user_data_ = nullptr; 49 | const GlProcs& gl_; 50 | }; 51 | 52 | } // namespace flutter 53 | 54 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_EGL_IMAGE_H_ 55 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.h" 6 | 7 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/string_message_codec.h" 8 | #include "flutter/shell/platform/linux_embedded/logger.h" 9 | 10 | namespace flutter { 11 | 12 | namespace { 13 | constexpr char kChannelName[] = "flutter/lifecycle"; 14 | constexpr char kInactive[] = "AppLifecycleState.inactive"; 15 | constexpr char kResumed[] = "AppLifecycleState.resumed"; 16 | constexpr char kPaused[] = "AppLifecycleState.paused"; 17 | constexpr char kDetached[] = "AppLifecycleState.detached"; 18 | constexpr char kHidden[] = "AppLifecycleState.hidden"; 19 | 20 | } // namespace 21 | 22 | LifecyclePlugin::LifecyclePlugin(BinaryMessenger* messenger) 23 | : channel_(std::make_unique>( 24 | messenger, 25 | kChannelName, 26 | &StringMessageCodec::GetInstance())) {} 27 | 28 | void LifecyclePlugin::OnInactive() const { 29 | ELINUX_LOG(DEBUG) << "App lifecycle changed to inactive state."; 30 | channel_->Send(std::string(kInactive)); 31 | } 32 | 33 | void LifecyclePlugin::OnResumed() const { 34 | ELINUX_LOG(DEBUG) << "App lifecycle changed to resumed state."; 35 | channel_->Send(std::string(kResumed)); 36 | } 37 | 38 | void LifecyclePlugin::OnPaused() const { 39 | ELINUX_LOG(DEBUG) << "App lifecycle changed to paused state."; 40 | channel_->Send(std::string(kPaused)); 41 | } 42 | 43 | void LifecyclePlugin::OnDetached() const { 44 | ELINUX_LOG(DEBUG) << "App lifecycle changed to detached state."; 45 | channel_->Send(std::string(kDetached)); 46 | } 47 | 48 | void LifecyclePlugin::OnHidden() const { 49 | ELINUX_LOG(DEBUG) << "App lifecycle changed to hidden state."; 50 | channel_->Send(std::string(kHidden)); 51 | } 52 | 53 | } // namespace flutter 54 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/surface_base.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_BASE_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_BASE_H_ 7 | 8 | #include 9 | 10 | #include "flutter/shell/platform/linux_embedded/surface/context_egl.h" 11 | #include "flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h" 12 | #include "flutter/shell/platform/linux_embedded/window/native_window.h" 13 | 14 | namespace flutter { 15 | 16 | class SurfaceBase { 17 | public: 18 | SurfaceBase() = default; 19 | virtual ~SurfaceBase() = default; 20 | 21 | // Shows a surface is valid or not. 22 | bool IsValid() const; 23 | 24 | // Sets a netive platform's window. 25 | bool SetNativeWindow(NativeWindow* window); 26 | 27 | // Changes an on-screen surface size. 28 | // On-screen surface needs to be recreated after window size changed only when 29 | // using DRM-GBM backend. Because gbm-surface is recreated when the window 30 | // size changed. 31 | // @param[in] width_px Physical width of the surface. 32 | // @param[in] height_px Physical height of the surface. 33 | bool OnScreenSurfaceResize(const size_t width_px, const size_t height_px); 34 | 35 | // Clears current on-screen context. 36 | bool ClearCurrentContext() const; 37 | 38 | // Clears and destroys current ons-screen context. 39 | void DestroyOnScreenContext(); 40 | 41 | // Makes an off-screen resource context. 42 | bool ResourceContextMakeCurrent() const; 43 | 44 | protected: 45 | std::unique_ptr context_; 46 | NativeWindow* native_window_ = nullptr; 47 | std::unique_ptr onscreen_surface_ = nullptr; 48 | std::unique_ptr offscreen_surface_ = nullptr; 49 | }; 50 | 51 | } // namespace flutter 52 | 53 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_BASE_H_ 54 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/renderer/elinux_shader.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifdef USE_GLES3 6 | #include 7 | #else 8 | #include 9 | #include 10 | #endif 11 | #include 12 | 13 | #include 14 | 15 | #include "flutter/shell/platform/linux_embedded/logger.h" 16 | #include "flutter/shell/platform/linux_embedded/window/renderer/elinux_shader.h" 17 | 18 | namespace flutter { 19 | 20 | namespace { 21 | 22 | struct GlProcs { 23 | PFNGLUSEPROGRAMPROC glUseProgram; 24 | bool valid; 25 | }; 26 | 27 | static const GlProcs& GlProcs() { 28 | static struct GlProcs procs = {}; 29 | static bool initialized = false; 30 | if (!initialized) { 31 | procs.glUseProgram = reinterpret_cast( 32 | eglGetProcAddress("glUseProgram")); 33 | procs.valid = procs.glUseProgram; 34 | if (!procs.valid) { 35 | ELINUX_LOG(ERROR) << "Failed to load GlProcs"; 36 | } 37 | initialized = true; 38 | } 39 | return procs; 40 | } 41 | 42 | } // namespace 43 | 44 | void ELinuxShader::LoadProgram(std::string vertex_code, 45 | std::string fragment_code) { 46 | auto vertex = 47 | std::make_unique(vertex_code, GL_VERTEX_SHADER); 48 | auto fragment = 49 | std::make_unique(fragment_code, GL_FRAGMENT_SHADER); 50 | program_ = std::make_unique(std::move(vertex), 51 | std::move(fragment)); 52 | } 53 | 54 | void ELinuxShader::Bind() { 55 | const auto& gl = GlProcs(); 56 | if (!gl.valid) { 57 | return; 58 | } 59 | gl.glUseProgram(program_->Program()); 60 | } 61 | 62 | void ELinuxShader::Unbind() { 63 | const auto& gl = GlProcs(); 64 | if (!gl.valid) { 65 | return; 66 | } 67 | gl.glUseProgram(false); 68 | } 69 | 70 | } // namespace flutter 71 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/plugins/navigation_plugin.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter/shell/platform/linux_embedded/plugins/navigation_plugin.h" 6 | 7 | #include "flutter/shell/platform/common/json_method_codec.h" 8 | #include "flutter/shell/platform/linux_embedded/logger.h" 9 | 10 | namespace flutter { 11 | 12 | namespace { 13 | constexpr char kChannelName[] = "flutter/navigation"; 14 | 15 | constexpr char kSetInitialRouteMethod[] = "setInitialRoute"; 16 | constexpr char kPushRouteMethod[] = "pushRoute"; 17 | constexpr char kPopRouteMethod[] = "popRoute"; 18 | } // namespace 19 | 20 | NavigationPlugin::NavigationPlugin(BinaryMessenger* messenger) 21 | : channel_(std::make_unique>( 22 | messenger, 23 | kChannelName, 24 | &flutter::JsonMethodCodec::GetInstance())) {} 25 | 26 | void NavigationPlugin::SetInitialRoute(std::string route) const { 27 | ELINUX_LOG(DEBUG) << "SetInitialRoute = " << route; 28 | 29 | auto args = std::make_unique(rapidjson::kObjectType); 30 | args->Parse("\"" + route + "\""); 31 | if (args->HasParseError()) { 32 | ELINUX_LOG(ERROR) << "Failed to parse the initial route: " << route; 33 | return; 34 | } 35 | channel_->InvokeMethod(kSetInitialRouteMethod, std::move(args)); 36 | } 37 | 38 | void NavigationPlugin::PushRoute(std::string route) const { 39 | ELINUX_LOG(DEBUG) << "PushRoute = " << route; 40 | 41 | auto args = std::make_unique(rapidjson::kObjectType); 42 | args->Parse("\"" + route + "\""); 43 | if (args->HasParseError()) { 44 | ELINUX_LOG(ERROR) << "Failed to parse the route: " << route; 45 | return; 46 | } 47 | channel_->InvokeMethod(kPushRouteMethod, std::move(args)); 48 | } 49 | 50 | void NavigationPlugin::PopRoute() const { 51 | ELINUX_LOG(DEBUG) << "PopRoute"; 52 | channel_->InvokeMethod(kPopRouteMethod, nullptr); 53 | } 54 | 55 | } // namespace flutter 56 | -------------------------------------------------------------------------------- /examples/flutter-external-texture-plugin/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | This is the example of External Texture Plugin. Source files are implemented based on [this reference](https://github.com/jnschulze/flutter-playground/tree/master/windows_texture_test). 4 | 5 | ## Building (Wayland backend stand-alone application) 6 | 7 | ```Shell 8 | $ mkdir build 9 | $ cd build 10 | $ cmake -DUSER_PROJECT_PATH=examples/flutter-external-texture-plugin .. 11 | $ cmake --build . 12 | ``` 13 | 14 | ## Dart sample code for Flutter app 15 | 16 | ```Dart 17 | import 'package:flutter/material.dart'; 18 | import 'package:flutter/services.dart'; 19 | import 'dart:async'; 20 | 21 | void main() { 22 | runApp(MyApp()); 23 | } 24 | 25 | class MyApp extends StatefulWidget { 26 | @override 27 | _MyAppState createState() => _MyAppState(); 28 | } 29 | 30 | class _MyAppState extends State { 31 | int _textureId = 0; 32 | 33 | @override 34 | void initState() { 35 | super.initState(); 36 | initialize().then((value) => setState(() {})); 37 | } 38 | 39 | Future initialize() async { 40 | late Completer creatingCompleter; 41 | try { 42 | creatingCompleter = Completer(); 43 | var channel = const MethodChannel('external_texture_test'); 44 | final reply = 45 | await channel.invokeMapMethod('initialize'); 46 | if (reply != null) { 47 | _textureId = reply['textureId']; 48 | } 49 | } on PlatformException catch (e) {} 50 | 51 | creatingCompleter.complete(); 52 | return creatingCompleter.future; 53 | } 54 | 55 | @override 56 | Widget build(BuildContext context) { 57 | return MaterialApp( 58 | home: Scaffold( 59 | backgroundColor: Colors.blue, 60 | appBar: AppBar( 61 | title: const Text('External Texture Plugin sample'), 62 | ), 63 | body: Center( 64 | child: AspectRatio( 65 | aspectRatio: 16 / 9, child: Texture(textureId: _textureId)), 66 | ), 67 | ), 68 | ); 69 | } 70 | } 71 | ``` 72 | 73 | ### Note 74 | 75 | Needs the Flutter SDK version 1.20 and above. 76 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_WINDOW_DECORATION_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_WINDOW_DECORATION_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "flutter/shell/platform/linux_embedded/surface/surface_decoration.h" 13 | #include "flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h" 14 | 15 | namespace flutter { 16 | 17 | class WindowDecoration { 18 | public: 19 | enum DecorationType { 20 | CLOSE_BUTTON = 0, 21 | MAXIMISE_BUTTON, 22 | MINIMISE_BUTTON, 23 | TITLE_BAR, 24 | }; 25 | 26 | WindowDecoration() = default; 27 | virtual ~WindowDecoration() = default; 28 | 29 | virtual void Draw() = 0; 30 | 31 | // @param[in] x_dip The x coordinate in logical pixels. 32 | // @param[in] y_dip The y coordinate in logical pixels. 33 | virtual void SetPosition(const int32_t x_dip, const int32_t y_dip) = 0; 34 | 35 | // @param[in] width_px Physical width of the window. 36 | // @param[in] height_px Physical height of the window. 37 | virtual void Resize(const size_t width_px, const size_t height_px) = 0; 38 | 39 | // Sets the scale factor for the next commit. Scale factor persists until a 40 | // new one is set. 41 | virtual void SetScaleFactor(float scale_factor) = 0; 42 | 43 | void DestroyContext() const { render_surface_->DestroyContext(); }; 44 | 45 | wl_surface* Surface() const { return native_window_->Surface(); }; 46 | 47 | DecorationType Type() const { return decoration_type_; }; 48 | 49 | protected: 50 | std::unique_ptr native_window_; 51 | std::unique_ptr render_surface_; 52 | DecorationType decoration_type_; 53 | }; 54 | 55 | } // namespace flutter 56 | 57 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_RENDERER_WINDOW_DECORATION_H_ 58 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BINARY_MESSENGER_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BINARY_MESSENGER_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace flutter { 12 | 13 | // A binary message reply callback. 14 | // 15 | // Used for submitting a binary reply back to a Flutter message sender. 16 | typedef std::function 17 | BinaryReply; 18 | 19 | // A message handler callback. 20 | // 21 | // Used for receiving messages from Flutter and providing an asynchronous reply. 22 | typedef std::function< 23 | void(const uint8_t* message, size_t message_size, BinaryReply reply)> 24 | BinaryMessageHandler; 25 | 26 | // A protocol for a class that handles communication of binary data on named 27 | // channels to and from the Flutter engine. 28 | class BinaryMessenger { 29 | public: 30 | virtual ~BinaryMessenger() = default; 31 | 32 | // Sends a binary message to the Flutter engine on the specified channel. 33 | // 34 | // If |reply| is provided, it will be called back with the response from the 35 | // engine. 36 | virtual void Send(const std::string& channel, 37 | const uint8_t* message, 38 | size_t message_size, 39 | BinaryReply reply = nullptr) const = 0; 40 | 41 | // Registers a message handler for incoming binary messages from the Flutter 42 | // side on the specified channel. 43 | // 44 | // Replaces any existing handler. Provide a null handler to unregister the 45 | // existing handler. 46 | virtual void SetMessageHandler(const std::string& channel, 47 | BinaryMessageHandler handler) = 0; 48 | }; 49 | 50 | } // namespace flutter 51 | 52 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BINARY_MESSENGER_H_ 53 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/incoming_message_dispatcher.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter/shell/platform/common/incoming_message_dispatcher.h" 6 | 7 | namespace flutter { 8 | 9 | IncomingMessageDispatcher::IncomingMessageDispatcher( 10 | FlutterDesktopMessengerRef messenger) 11 | : messenger_(messenger) {} 12 | 13 | IncomingMessageDispatcher::~IncomingMessageDispatcher() = default; 14 | 15 | /// @note Procedure doesn't copy all closures. 16 | void IncomingMessageDispatcher::HandleMessage( 17 | const FlutterDesktopMessage& message, 18 | const std::function& input_block_cb, 19 | const std::function& input_unblock_cb) { 20 | std::string channel(message.channel); 21 | 22 | // Find the handler for the channel; if there isn't one, report the failure. 23 | if (callbacks_.find(channel) == callbacks_.end()) { 24 | FlutterDesktopMessengerSendResponse(messenger_, message.response_handle, 25 | nullptr, 0); 26 | return; 27 | } 28 | auto& callback_info = callbacks_[channel]; 29 | FlutterDesktopMessageCallback message_callback = callback_info.first; 30 | 31 | // Process the call, handling input blocking if requested. 32 | bool block_input = input_blocking_channels_.count(channel) > 0; 33 | if (block_input) { 34 | input_block_cb(); 35 | } 36 | message_callback(messenger_, &message, callback_info.second); 37 | if (block_input) { 38 | input_unblock_cb(); 39 | } 40 | } 41 | 42 | void IncomingMessageDispatcher::SetMessageCallback( 43 | const std::string& channel, 44 | FlutterDesktopMessageCallback callback, 45 | void* user_data) { 46 | if (!callback) { 47 | callbacks_.erase(channel); 48 | return; 49 | } 50 | callbacks_[channel] = std::make_pair(callback, user_data); 51 | } 52 | 53 | void IncomingMessageDispatcher::EnableInputBlockingForChannel( 54 | const std::string& channel) { 55 | input_blocking_channels_.insert(channel); 56 | } 57 | 58 | } // namespace flutter 59 | -------------------------------------------------------------------------------- /examples/flutter-wayland-client/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /examples/flutter-x11-client/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /examples/flutter-drm-gbm-backend/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /examples/flutter-drm-eglstream-backend/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /examples/flutter-external-texture-plugin/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter_embedder_options.h" 13 | #include "flutter_window.h" 14 | 15 | int main(int argc, char** argv) { 16 | FlutterEmbedderOptions options; 17 | if (!options.Parse(argc, argv)) { 18 | return 0; 19 | } 20 | 21 | // Creates the Flutter project. 22 | const auto bundle_path = options.BundlePath(); 23 | const std::wstring fl_path(bundle_path.begin(), bundle_path.end()); 24 | flutter::DartProject project(fl_path); 25 | auto command_line_arguments = std::vector(); 26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 27 | 28 | flutter::FlutterViewController::ViewProperties view_properties = {}; 29 | view_properties.width = options.WindowWidth(); 30 | view_properties.height = options.WindowHeight(); 31 | view_properties.view_mode = options.WindowViewMode(); 32 | view_properties.view_rotation = options.WindowRotation(); 33 | view_properties.title = options.WindowTitle(); 34 | view_properties.app_id = options.WindowAppID(); 35 | view_properties.use_mouse_cursor = options.IsUseMouseCursor(); 36 | view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); 37 | view_properties.use_window_decoration = options.IsUseWindowDecoraation(); 38 | view_properties.text_scale_factor = options.TextScaleFactor(); 39 | view_properties.enable_high_contrast = options.EnableHighContrast(); 40 | view_properties.force_scale_factor = options.IsForceScaleFactor(); 41 | view_properties.scale_factor = options.ScaleFactor(); 42 | view_properties.enable_vsync = options.EnableVsync(); 43 | 44 | // The Flutter instance hosted by this window. 45 | FlutterWindow window(view_properties, project); 46 | if (!window.OnCreate()) { 47 | return 0; 48 | } 49 | window.Run(); 50 | window.OnDestroy(); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/surface_base.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter/shell/platform/linux_embedded/surface/surface_base.h" 6 | 7 | #include "flutter/shell/platform/linux_embedded/logger.h" 8 | 9 | namespace flutter { 10 | 11 | bool SurfaceBase::IsValid() const { 12 | return offscreen_surface_ && context_->IsValid(); 13 | }; 14 | 15 | bool SurfaceBase::SetNativeWindow(NativeWindow* window) { 16 | native_window_ = window; 17 | 18 | onscreen_surface_ = context_->CreateOnscreenSurface(native_window_); 19 | if (!onscreen_surface_->IsValid()) { 20 | return false; 21 | } 22 | 23 | offscreen_surface_ = context_->CreateOffscreenSurface(native_window_); 24 | if (!offscreen_surface_->IsValid()) { 25 | offscreen_surface_ = nullptr; 26 | return false; 27 | } 28 | 29 | return true; 30 | }; 31 | 32 | bool SurfaceBase::OnScreenSurfaceResize(const size_t width_px, 33 | const size_t height_px) { 34 | onscreen_surface_->SurfaceResize(width_px, height_px); 35 | if (!native_window_->Resize(width_px, height_px)) { 36 | ELINUX_LOG(ERROR) << "Failed to resize."; 37 | return false; 38 | } 39 | 40 | if (native_window_->IsNeedRecreateSurfaceAfterResize()) { 41 | DestroyOnScreenContext(); 42 | onscreen_surface_ = context_->CreateOnscreenSurface(native_window_); 43 | if (!onscreen_surface_->IsValid()) { 44 | ELINUX_LOG(WARNING) << "Failed to recreate on-screen surface."; 45 | onscreen_surface_ = nullptr; 46 | return false; 47 | } 48 | onscreen_surface_->SurfaceResize(width_px, height_px); 49 | } 50 | return true; 51 | }; 52 | 53 | bool SurfaceBase::ClearCurrentContext() const { 54 | return context_->ClearCurrent(); 55 | }; 56 | 57 | void SurfaceBase::DestroyOnScreenContext() { 58 | context_->ClearCurrent(); 59 | onscreen_surface_ = nullptr; 60 | }; 61 | 62 | bool SurfaceBase::ResourceContextMakeCurrent() const { 63 | if (!offscreen_surface_) { 64 | return false; 65 | } 66 | return offscreen_surface_->MakeCurrent(); 67 | }; 68 | 69 | } // namespace flutter 70 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/video_player_stream_handler_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_IMPL_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_IMPL_H_ 7 | 8 | #include 9 | 10 | #include "video_player_stream_handler.h" 11 | 12 | class VideoPlayerStreamHandlerImpl : public VideoPlayerStreamHandler { 13 | public: 14 | using OnNotifyInitialized = std::function; 15 | using OnNotifyFrameDecoded = std::function; 16 | using OnNotifyCompleted = std::function; 17 | 18 | VideoPlayerStreamHandlerImpl(OnNotifyInitialized on_notify_initialized, 19 | OnNotifyFrameDecoded on_notify_frame_decoded, 20 | OnNotifyCompleted on_notify_completed) 21 | : on_notify_initialized_(on_notify_initialized), 22 | on_notify_frame_decoded_(on_notify_frame_decoded), 23 | on_notify_completed_(on_notify_completed) {} 24 | virtual ~VideoPlayerStreamHandlerImpl() = default; 25 | 26 | // Prevent copying. 27 | VideoPlayerStreamHandlerImpl(VideoPlayerStreamHandlerImpl const&) = delete; 28 | VideoPlayerStreamHandlerImpl& operator=(VideoPlayerStreamHandlerImpl const&) = 29 | delete; 30 | 31 | protected: 32 | // |VideoPlayerStreamHandler| 33 | void OnNotifyInitializedInternal() { 34 | if (on_notify_initialized_) { 35 | on_notify_initialized_(); 36 | } 37 | } 38 | 39 | // |VideoPlayerStreamHandler| 40 | void OnNotifyFrameDecodedInternal() { 41 | if (on_notify_frame_decoded_) { 42 | on_notify_frame_decoded_(); 43 | } 44 | } 45 | 46 | // |VideoPlayerStreamHandler| 47 | void OnNotifyCompletedInternal() { 48 | if (on_notify_completed_) { 49 | on_notify_completed_(); 50 | } 51 | } 52 | 53 | OnNotifyInitialized on_notify_initialized_; 54 | OnNotifyFrameDecoded on_notify_frame_decoded_; 55 | OnNotifyCompleted on_notify_completed_; 56 | }; 57 | 58 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_IMPL_H_ 59 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_ELINUX_EGL_SURFACE_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_ELINUX_EGL_SURFACE_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "flutter/shell/platform/embedder/embedder.h" 16 | 17 | namespace flutter { 18 | 19 | class ELinuxEGLSurface { 20 | public: 21 | // Note that EGLSurface will be destroyed in this class's destructor. 22 | ELinuxEGLSurface(EGLSurface surface, 23 | EGLDisplay display, 24 | EGLContext context, 25 | bool vsync_enabled); 26 | ~ELinuxEGLSurface(); 27 | 28 | bool IsValid() const; 29 | 30 | void SurfaceResize(const size_t width_px, const size_t height_px); 31 | 32 | bool MakeCurrent() const; 33 | 34 | bool SwapBuffers() const; 35 | 36 | bool SwapBuffers(const FlutterPresentInfo* info); 37 | 38 | void PopulateExistingDamage(const intptr_t fbo_id, 39 | FlutterDamage* existing_damage); 40 | 41 | private: 42 | // Auxiliary function used to transform a FlutterRect into the format that is 43 | // expected by the EGL functions (i.e. array of EGLint). 44 | std::array RectToInts(const FlutterRect rect); 45 | 46 | EGLDisplay display_; 47 | EGLSurface surface_; 48 | EGLContext context_; 49 | bool vsync_enabled_; 50 | 51 | size_t width_px_; 52 | size_t height_px_; 53 | 54 | PFNEGLSETDAMAGEREGIONKHRPROC eglSetDamageRegionKHR_ = nullptr; 55 | PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC eglSwapBuffersWithDamageEXT_ = nullptr; 56 | 57 | // Keeps track of the most recent frame damages so that existing damage can 58 | // be easily computed. 59 | std::list damage_history_; 60 | 61 | // Keeps track of the existing damage associated with each FBO ID 62 | std::unordered_map existing_damage_map_; 63 | }; 64 | 65 | } // namespace flutter 66 | 67 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_ELINUX_EGL_SURFACE_H_ 68 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/messages/volume_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_VOLUME_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_VOLUME_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class VolumeMessage { 12 | public: 13 | VolumeMessage() = default; 14 | ~VolumeMessage() = default; 15 | 16 | // Prevent copying. 17 | VolumeMessage(VolumeMessage const&) = default; 18 | VolumeMessage& operator=(VolumeMessage const&) = default; 19 | 20 | void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } 21 | 22 | int64_t GetTextureId() const { return texture_id_; } 23 | 24 | void SetVolume(double volume) { volume_ = volume; } 25 | 26 | double GetVolume() const { return volume_; } 27 | 28 | flutter::EncodableValue ToMap() { 29 | flutter::EncodableMap map = { 30 | {flutter::EncodableValue("textureId"), 31 | flutter::EncodableValue(texture_id_)}, 32 | {flutter::EncodableValue("volume"), flutter::EncodableValue(volume_)}}; 33 | return flutter::EncodableValue(map); 34 | } 35 | 36 | static VolumeMessage FromMap(const flutter::EncodableValue& value) { 37 | VolumeMessage message; 38 | if (std::holds_alternative(value)) { 39 | auto map = std::get(value); 40 | 41 | flutter::EncodableValue& texture_id = 42 | map[flutter::EncodableValue("textureId")]; 43 | if (std::holds_alternative(texture_id) || 44 | std::holds_alternative(texture_id)) { 45 | message.SetTextureId(texture_id.LongValue()); 46 | } 47 | 48 | flutter::EncodableValue& volume = map[flutter::EncodableValue("volume")]; 49 | if (std::holds_alternative(volume)) { 50 | message.SetVolume(std::get(volume)); 51 | } 52 | } 53 | 54 | return message; 55 | } 56 | 57 | private: 58 | int64_t texture_id_ = 0; 59 | double volume_ = 0; 60 | }; 61 | 62 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_VOLUME_MESSAGE_H_ 63 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_DRM_EGLSTREAM_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_DRM_EGLSTREAM_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include "flutter/shell/platform/linux_embedded/window/native_window_drm.h" 14 | 15 | namespace flutter { 16 | 17 | class NativeWindowDrmEglstream : public NativeWindowDrm { 18 | public: 19 | NativeWindowDrmEglstream(const char* device_filename, 20 | const uint16_t rotation, 21 | bool enable_vsync); 22 | ~NativeWindowDrmEglstream(); 23 | 24 | // |NativeWindowDrm| 25 | bool ShowCursor(double x, double y) override; 26 | 27 | // |NativeWindowDrm| 28 | bool UpdateCursor(const std::string& cursor_name, 29 | double x, 30 | double y) override; 31 | 32 | // |NativeWindowDrm| 33 | bool DismissCursor() override; 34 | 35 | // |NativeWindowDrm| 36 | std::unique_ptr CreateRenderSurface(bool enable_impeller) override; 37 | 38 | // |NativeWindow| 39 | bool Resize(const size_t width, const size_t height) override; 40 | 41 | uint32_t PlaneId() { return drm_plane_id_; } 42 | 43 | private: 44 | struct DrmProperty { 45 | const char* name; 46 | uint64_t value; 47 | }; 48 | 49 | bool ConfigureDisplayAdditional(); 50 | 51 | bool SetDrmClientCapabilities(); 52 | 53 | uint32_t FindPrimaryPlaneId(drmModePlaneResPtr resources); 54 | 55 | uint64_t GetPropertyValue(uint32_t id, uint32_t type, const char* prop_name); 56 | 57 | bool AssignAtomicRequest(drmModeAtomicReqPtr atomic); 58 | 59 | template 60 | bool AssignAtomicPropertyValue( 61 | drmModeAtomicReqPtr atomic, 62 | uint32_t id, 63 | uint32_t type, 64 | NativeWindowDrmEglstream::DrmProperty (&table)[N]); 65 | 66 | uint32_t drm_plane_id_; 67 | uint32_t drm_property_blob_ = 0; 68 | }; 69 | 70 | } // namespace flutter 71 | 72 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_DRM_EGLSTREAM_H_ 73 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/include/flutter/standard_message_codec.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STANDARD_MESSAGE_CODEC_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STANDARD_MESSAGE_CODEC_H_ 7 | 8 | #include 9 | 10 | #include "encodable_value.h" 11 | #include "message_codec.h" 12 | #include "standard_codec_serializer.h" 13 | 14 | namespace flutter { 15 | 16 | // A binary message encoding/decoding mechanism for communications to/from the 17 | // Flutter engine via message channels. 18 | class StandardMessageCodec : public MessageCodec { 19 | public: 20 | // Returns an instance of the codec, optionally using a custom serializer to 21 | // add support for more types. 22 | // 23 | // If provided, |serializer| must be long-lived. If no serializer is provided, 24 | // the default will be used. 25 | // 26 | // The instance returned for a given |serializer| will be shared, and 27 | // any instance returned from this will be long-lived, and can be safely 28 | // passed to, e.g., channel constructors. 29 | static const StandardMessageCodec& GetInstance( 30 | const StandardCodecSerializer* serializer = nullptr); 31 | 32 | ~StandardMessageCodec(); 33 | 34 | // Prevent copying. 35 | StandardMessageCodec(StandardMessageCodec const&) = delete; 36 | StandardMessageCodec& operator=(StandardMessageCodec const&) = delete; 37 | 38 | protected: 39 | // |flutter::MessageCodec| 40 | std::unique_ptr DecodeMessageInternal( 41 | const uint8_t* binary_message, 42 | const size_t message_size) const override; 43 | 44 | // |flutter::MessageCodec| 45 | std::unique_ptr> EncodeMessageInternal( 46 | const EncodableValue& message) const override; 47 | 48 | private: 49 | // Instances should be obtained via GetInstance. 50 | explicit StandardMessageCodec(const StandardCodecSerializer* serializer); 51 | 52 | const StandardCodecSerializer* serializer_; 53 | }; 54 | 55 | } // namespace flutter 56 | 57 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STANDARD_MESSAGE_CODEC_H_ 58 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/json_method_codec.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_JSON_METHOD_CODEC_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_JSON_METHOD_CODEC_H_ 7 | 8 | #include 9 | 10 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/method_call.h" 11 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/method_codec.h" 12 | 13 | namespace flutter { 14 | 15 | // An implementation of MethodCodec that uses JSON strings as the serialization. 16 | class JsonMethodCodec : public MethodCodec { 17 | public: 18 | // Returns the shared instance of the codec. 19 | static const JsonMethodCodec& GetInstance(); 20 | 21 | ~JsonMethodCodec() = default; 22 | 23 | // Prevent copying. 24 | JsonMethodCodec(JsonMethodCodec const&) = delete; 25 | JsonMethodCodec& operator=(JsonMethodCodec const&) = delete; 26 | 27 | protected: 28 | // Instances should be obtained via GetInstance. 29 | JsonMethodCodec() = default; 30 | 31 | // |flutter::MethodCodec| 32 | std::unique_ptr> DecodeMethodCallInternal( 33 | const uint8_t* message, 34 | const size_t message_size) const override; 35 | 36 | // |flutter::MethodCodec| 37 | std::unique_ptr> EncodeMethodCallInternal( 38 | const MethodCall& method_call) const override; 39 | 40 | // |flutter::MethodCodec| 41 | std::unique_ptr> EncodeSuccessEnvelopeInternal( 42 | const rapidjson::Document* result) const override; 43 | 44 | // |flutter::MethodCodec| 45 | std::unique_ptr> EncodeErrorEnvelopeInternal( 46 | const std::string& error_code, 47 | const std::string& error_message, 48 | const rapidjson::Document* error_details) const override; 49 | 50 | // |flutter::MethodCodec| 51 | bool DecodeAndProcessResponseEnvelopeInternal( 52 | const uint8_t* response, 53 | const size_t response_size, 54 | MethodResult* result) const override; 55 | }; 56 | 57 | } // namespace flutter 58 | 59 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_JSON_METHOD_CODEC_H_ 60 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/native_window_drm.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_DRM_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_DRM_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "flutter/shell/platform/linux_embedded/surface/surface_gl.h" 15 | #include "flutter/shell/platform/linux_embedded/window/native_window.h" 16 | 17 | namespace flutter { 18 | 19 | class NativeWindowDrm : public NativeWindow { 20 | public: 21 | NativeWindowDrm(const char* device_filename, 22 | const uint16_t rotation, 23 | bool enable_vsync); 24 | virtual ~NativeWindowDrm(); 25 | 26 | bool ConfigureDisplay(const uint16_t rotation); 27 | 28 | bool MoveCursor(double x, double y); 29 | 30 | virtual bool ShowCursor(double x, double y) = 0; 31 | 32 | virtual bool UpdateCursor(const std::string& cursor_name, 33 | double x, 34 | double y) = 0; 35 | 36 | virtual bool DismissCursor() = 0; 37 | 38 | virtual std::unique_ptr CreateRenderSurface( 39 | bool enable_impeller) = 0; 40 | 41 | protected: 42 | std::string GetConnectorName(uint32_t connector_type, 43 | uint32_t connector_type_id); 44 | drmModeConnectorPtr GetConnectorByName(drmModeResPtr resources, 45 | const char* connector_name); 46 | drmModeConnectorPtr FindConnector(drmModeResPtr resources); 47 | 48 | drmModeEncoder* FindEncoder(drmModeRes* resources, 49 | drmModeConnector* connector); 50 | 51 | // Convert Flutter's cursor value to cursor data. 52 | const uint32_t* GetCursorData(const std::string& cursor_name); 53 | 54 | int drm_device_; 55 | uint32_t drm_connector_id_; 56 | drmModeCrtc* drm_crtc_ = nullptr; 57 | drmModeModeInfo drm_mode_info_; 58 | 59 | std::string cursor_name_ = ""; 60 | std::pair cursor_hotspot_ = {0, 0}; 61 | }; 62 | 63 | } // namespace flutter 64 | 65 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_DRM_H_ 66 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Corporation. All rights reserved. 2 | // Copyright 2013 The Flutter Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style license that can be 4 | // found in the LICENSE file. 5 | 6 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_SETTINGS_PLUGIN_H_ 7 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_SETTINGS_PLUGIN_H_ 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h" 14 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" 15 | #include "flutter/shell/platform/linux_embedded/window_binding_handler.h" 16 | 17 | namespace flutter { 18 | 19 | // Abstract settings plugin. 20 | // 21 | // Used to look up and notify Flutter of user-configured system settings. 22 | // These are typically set in the control panel. 23 | class SettingsPlugin { 24 | public: 25 | enum struct PlatformBrightness { kDark, kLight }; 26 | 27 | explicit SettingsPlugin(BinaryMessenger* messenger, 28 | WindowBindingHandler* delegate); 29 | ~SettingsPlugin() = default; 30 | 31 | // Sends settings (e.g., platform brightness) to the engine. 32 | void SendSettings(); 33 | 34 | // Update the always use 24hour-format status of the system. 35 | void UpdateAlwaysUse24HourFormat(bool is_always_use_24hour_format); 36 | 37 | // Update the high contrast status of the system. 38 | void UpdateHighContrastMode(bool is_high_contrast); 39 | 40 | // Update the text scale factor of the system. 41 | void UpdateTextScaleFactor(float factor); 42 | 43 | private: 44 | // Returns `true` if the user uses 24 hour time. 45 | bool GetAlwaysUse24HourFormat(); 46 | 47 | // Returns the user-preferred text scale factor. 48 | float GetTextScaleFactor(); 49 | 50 | // Returns the user-preferred brightness. 51 | PlatformBrightness GetPreferredBrightness(); 52 | 53 | std::unique_ptr> channel_; 54 | WindowBindingHandler* delegate_; 55 | bool is_high_contrast_ = false; 56 | bool is_always_use_24hour_format_ = true; 57 | float text_scaling_factor_ = 1.0; 58 | }; 59 | 60 | } // namespace flutter 61 | 62 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_SETTINGS_PLUGIN_H_ 63 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/include/flutter/event_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_SINK_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_SINK_H_ 7 | 8 | namespace flutter { 9 | 10 | class EncodableValue; 11 | 12 | // Event callback. Events to be sent to Flutter application 13 | // act as clients of this interface for sending events. 14 | template 15 | class EventSink { 16 | public: 17 | EventSink() = default; 18 | virtual ~EventSink() = default; 19 | 20 | // Prevent copying. 21 | EventSink(EventSink const&) = delete; 22 | EventSink& operator=(EventSink const&) = delete; 23 | 24 | // Consumes a successful event 25 | void Success(const T& event) { SuccessInternal(&event); } 26 | 27 | // Consumes a successful event. 28 | void Success() { SuccessInternal(nullptr); } 29 | 30 | // Consumes an error event. 31 | void Error(const std::string& error_code, 32 | const std::string& error_message, 33 | const T& error_details) { 34 | ErrorInternal(error_code, error_message, &error_details); 35 | } 36 | 37 | // Consumes an error event. 38 | void Error(const std::string& error_code, 39 | const std::string& error_message = "") { 40 | ErrorInternal(error_code, error_message, nullptr); 41 | } 42 | 43 | // Consumes end of stream. Ensuing calls to Success() or 44 | // Error(), if any, are ignored. 45 | void EndOfStream() { EndOfStreamInternal(); } 46 | 47 | protected: 48 | // Implementation of the public interface, to be provided by subclasses. 49 | virtual void SuccessInternal(const T* event = nullptr) = 0; 50 | 51 | // Implementation of the public interface, to be provided by subclasses. 52 | virtual void ErrorInternal(const std::string& error_code, 53 | const std::string& error_message, 54 | const T* error_details) = 0; 55 | 56 | // Implementation of the public interface, to be provided by subclasses. 57 | virtual void EndOfStreamInternal() = 0; 58 | }; 59 | 60 | } // namespace flutter 61 | 62 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_SINK_H_ 63 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/messages/playback_speed_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_PLAYBACK_SPEED_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_PLAYBACK_SPEED_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class PlaybackSpeedMessage { 12 | public: 13 | PlaybackSpeedMessage() = default; 14 | ~PlaybackSpeedMessage() = default; 15 | 16 | // Prevent copying. 17 | PlaybackSpeedMessage(PlaybackSpeedMessage const&) = default; 18 | PlaybackSpeedMessage& operator=(PlaybackSpeedMessage const&) = default; 19 | 20 | void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } 21 | 22 | int64_t GetTextureId() const { return texture_id_; } 23 | 24 | void SetSpeed(double speed) { speed_ = speed; } 25 | 26 | double GetSpeed() const { return speed_; } 27 | 28 | flutter::EncodableValue ToMap() { 29 | flutter::EncodableMap map = { 30 | {flutter::EncodableValue("textureId"), 31 | flutter::EncodableValue(texture_id_)}, 32 | {flutter::EncodableValue("speed"), flutter::EncodableValue(speed_)}}; 33 | return flutter::EncodableValue(map); 34 | } 35 | 36 | static PlaybackSpeedMessage FromMap(const flutter::EncodableValue& value) { 37 | PlaybackSpeedMessage message; 38 | if (std::holds_alternative(value)) { 39 | auto map = std::get(value); 40 | 41 | flutter::EncodableValue& texture_id = 42 | map[flutter::EncodableValue("textureId")]; 43 | if (std::holds_alternative(texture_id) || 44 | std::holds_alternative(texture_id)) { 45 | message.SetTextureId(texture_id.LongValue()); 46 | } 47 | 48 | flutter::EncodableValue& speed = map[flutter::EncodableValue("speed")]; 49 | if (std::holds_alternative(speed)) { 50 | message.SetSpeed(std::get(speed)); 51 | } 52 | } 53 | 54 | return message; 55 | } 56 | 57 | private: 58 | int64_t texture_id_ = 0; 59 | double speed_ = 1.0; 60 | }; 61 | 62 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_PLAYBACK_SPEED_MESSAGE_H_ 63 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/messages/looping_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_LOOPING_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_LOOPING_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class LoopingMessage { 12 | public: 13 | LoopingMessage() = default; 14 | ~LoopingMessage() = default; 15 | 16 | // Prevent copying. 17 | LoopingMessage(LoopingMessage const&) = default; 18 | LoopingMessage& operator=(LoopingMessage const&) = default; 19 | 20 | void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } 21 | 22 | int64_t GetTextureId() const { return texture_id_; } 23 | 24 | void SetIsLooping(bool is_looping) { is_looping_ = is_looping; } 25 | 26 | bool GetIsLooping() const { return is_looping_; } 27 | 28 | flutter::EncodableValue ToMap() { 29 | flutter::EncodableMap map = {{flutter::EncodableValue("textureId"), 30 | flutter::EncodableValue(texture_id_)}, 31 | {flutter::EncodableValue("isLooping"), 32 | flutter::EncodableValue(is_looping_)}}; 33 | return flutter::EncodableValue(map); 34 | } 35 | 36 | static LoopingMessage FromMap(const flutter::EncodableValue& value) { 37 | LoopingMessage message; 38 | if (std::holds_alternative(value)) { 39 | auto map = std::get(value); 40 | 41 | flutter::EncodableValue& texture_id = 42 | map[flutter::EncodableValue("textureId")]; 43 | if (std::holds_alternative(texture_id) || 44 | std::holds_alternative(texture_id)) { 45 | message.SetTextureId(texture_id.LongValue()); 46 | } 47 | 48 | flutter::EncodableValue& is_looping = 49 | map[flutter::EncodableValue("isLooping")]; 50 | if (std::holds_alternative(is_looping)) { 51 | message.SetIsLooping(std::get(is_looping)); 52 | } 53 | } 54 | 55 | return message; 56 | } 57 | 58 | private: 59 | int64_t texture_id_ = 0; 60 | bool is_looping_ = false; 61 | }; 62 | 63 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_LOOPING_MESSAGE_H_ 64 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "flutter/shell/platform/linux_embedded/surface/surface_decoration.h" 6 | 7 | #include "flutter/shell/platform/linux_embedded/logger.h" 8 | 9 | namespace flutter { 10 | 11 | SurfaceDecoration::SurfaceDecoration(std::unique_ptr context) { 12 | context_ = std::move(context); 13 | } 14 | 15 | bool SurfaceDecoration::IsValid() const { 16 | return context_->IsValid(); 17 | }; 18 | 19 | bool SurfaceDecoration::SetNativeWindow(NativeWindow* window) { 20 | native_window_ = window; 21 | 22 | surface_ = context_->CreateOnscreenSurface(native_window_); 23 | if (!surface_->IsValid()) { 24 | return false; 25 | } 26 | 27 | return true; 28 | }; 29 | 30 | bool SurfaceDecoration::Resize(const size_t width_px, const size_t height_px) { 31 | if (!native_window_->Resize(width_px, height_px)) { 32 | ELINUX_LOG(ERROR) << "Failed to resize."; 33 | return false; 34 | } 35 | 36 | if (native_window_->IsNeedRecreateSurfaceAfterResize()) { 37 | DestroyContext(); 38 | surface_ = context_->CreateOnscreenSurface(native_window_); 39 | if (!surface_->IsValid()) { 40 | ELINUX_LOG(WARNING) << "Failed to recreate decoration surface."; 41 | surface_ = nullptr; 42 | return false; 43 | } 44 | } 45 | return true; 46 | }; 47 | 48 | void SurfaceDecoration::DestroyContext() { 49 | context_->ClearCurrent(); 50 | surface_ = nullptr; 51 | }; 52 | 53 | bool SurfaceDecoration::GLContextMakeCurrent() const { 54 | return surface_->MakeCurrent(); 55 | } 56 | 57 | bool SurfaceDecoration::GLContextClearCurrent() const { 58 | return context_->ClearCurrent(); 59 | } 60 | 61 | bool SurfaceDecoration::GLContextPresent(uint32_t fbo_id) const { 62 | return surface_->SwapBuffers(); 63 | } 64 | 65 | bool SurfaceDecoration::GLContextPresentWithInfo( 66 | const FlutterPresentInfo* info) const { 67 | return true; 68 | } 69 | 70 | void SurfaceDecoration::PopulateExistingDamage( 71 | const intptr_t fbo_id, 72 | FlutterDamage* existing_damage) const {} 73 | 74 | uint32_t SurfaceDecoration::GLContextFBO() const { 75 | return 0; 76 | } 77 | 78 | void* SurfaceDecoration::GlProcResolver(const char* name) const { 79 | return context_->GlProcResolver(name); 80 | } 81 | 82 | } // namespace flutter 83 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_TEXT_INPUT_PLUGIN_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_TEXT_INPUT_PLUGIN_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" 13 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h" 14 | #include "flutter/shell/platform/common/text_input_model.h" 15 | #include "flutter/shell/platform/linux_embedded/window_binding_handler.h" 16 | 17 | namespace flutter { 18 | 19 | class TextInputPlugin { 20 | public: 21 | TextInputPlugin(BinaryMessenger* messenger, WindowBindingHandler* delegate); 22 | ~TextInputPlugin() = default; 23 | 24 | void OnKeyPressed(uint32_t keycode, uint32_t code_point); 25 | 26 | private: 27 | // Sends the current state of the given model to the Flutter engine. 28 | void SendStateUpdate(const TextInputModel& model); 29 | 30 | // Sends an action triggered by the Enter key to the Flutter engine. 31 | void EnterPressed(TextInputModel* model); 32 | 33 | // Called when a method is called on |channel_|; 34 | void HandleMethodCall( 35 | const flutter::MethodCall& method_call, 36 | std::unique_ptr> result); 37 | 38 | // The MethodChannel used for communication with the Flutter engine. 39 | std::unique_ptr> channel_; 40 | 41 | // The active client id. 42 | int client_id_ = 0; 43 | 44 | // The active model. nullptr if not set. 45 | std::unique_ptr active_model_; 46 | 47 | // Keyboard type of the client. See available options: 48 | // https://docs.flutter.io/flutter/services/TextInputType-class.html 49 | std::string input_type_; 50 | 51 | // An action requested by the user on the input client. See available options: 52 | // https://docs.flutter.io/flutter/services/TextInputAction-class.html 53 | std::string input_action_; 54 | 55 | // The delegate for virtual keyboard updates. 56 | WindowBindingHandler* delegate_; 57 | }; 58 | 59 | } // namespace flutter 60 | 61 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_TEXT_INPUT_PLUGIN_H_ 62 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/gst_video_player.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Group Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_GST_VIDEO_PLAYER_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_GST_VIDEO_PLAYER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "video_player_stream_handler.h" 15 | 16 | class GstVideoPlayer { 17 | public: 18 | GstVideoPlayer(const std::string& uri, 19 | std::unique_ptr handler); 20 | ~GstVideoPlayer(); 21 | 22 | static void GstLibraryLoad(); 23 | static void GstLibraryUnload(); 24 | 25 | bool Play(); 26 | bool Pause(); 27 | bool Stop(); 28 | bool SetVolume(double volume); 29 | bool SetPlaybackRate(double rate); 30 | void SetAutoRepeat(bool auto_repeat) { auto_repeat_ = auto_repeat; }; 31 | bool SetSeek(int64_t position); 32 | int64_t GetDuration(); 33 | int64_t GetCurrentPosition(); 34 | const uint8_t* GetFrameBuffer(); 35 | int32_t GetWidth() const { return width_; }; 36 | int32_t GetHeight() const { return height_; }; 37 | 38 | private: 39 | struct GstVideoElements { 40 | GstElement* pipeline; 41 | GstElement* playbin; 42 | GstElement* video_convert; 43 | GstElement* video_sink; 44 | GstElement* output; 45 | GstBus* bus; 46 | GstBuffer* buffer; 47 | }; 48 | 49 | static void HandoffHandler(GstElement* fakesink, GstBuffer* buf, 50 | GstPad* new_pad, gpointer user_data); 51 | static gboolean HandleGstMessage(GstBus* bus, GstMessage* message, 52 | gpointer user_data); 53 | std::string ParseUri(const std::string& uri); 54 | bool CreatePipeline(); 55 | void DestroyPipeline(); 56 | void Preroll(); 57 | void GetVideoSize(int32_t& width, int32_t& height); 58 | 59 | GstVideoElements gst_; 60 | std::string uri_; 61 | std::unique_ptr pixels_; 62 | int32_t width_; 63 | int32_t height_; 64 | double volume_ = 1.0; 65 | double playback_rate_ = 1.0; 66 | bool mute_ = false; 67 | bool auto_repeat_ = false; 68 | std::shared_mutex mutex_buffer_; 69 | std::unique_ptr stream_handler_; 70 | }; 71 | 72 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_GST_VIDEO_PLAYER_H_ 73 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # We only support clang, so the build will be faild if you try to build with gcc compiler instead of it. 4 | if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) 5 | set(CMAKE_C_COMPILER clang) 6 | set(CMAKE_CXX_COMPILER clang++) 7 | endif() 8 | set(CMAKE_CXX_STANDARD 17) 9 | 10 | project("flutter_elinux" LANGUAGES CXX C) 11 | 12 | # Build options. 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") 15 | # Disabled USE_DIRTY_REGION_MANAGEMENT due flicker issue. 16 | # See https://github.com/sony/flutter-embedded-linux/issues/334 17 | option(USE_DIRTY_REGION_MANAGEMENT "Use Flutter dirty region management" OFF) 18 | option(USE_GLES3 "Use OpenGL ES3 (default is OpenGL ES2)" OFF) 19 | option(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER "Enable alpha component of the EGL color buffer" ON) 20 | # todo: need to investigate https://github.com/sony/flutter-embedded-linux/pull/376 when enabling this option. 21 | option(ENABLE_VSYNC "Enable embedder vsync" OFF) 22 | option(BUILD_ELINUX_SO "Build .so file of elinux embedder" OFF) 23 | option(ENABLE_ELINUX_EMBEDDER_LOG "Enable logger of eLinux embedder" ON) 24 | option(FLUTTER_RELEASE "Build Flutter Engine with release mode" OFF) 25 | 26 | if(NOT BUILD_ELINUX_SO) 27 | # Load the user project. 28 | set(USER_PROJECT_PATH "" CACHE STRING "examples/flutter-wayland-client") 29 | 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() 33 | include(${USER_PROJECT_PATH}/cmake/user_config.cmake) 34 | else() 35 | # Set the filename of elinux .so file 36 | if(${BACKEND_TYPE} STREQUAL "DRM-GBM") 37 | set(TARGET_SUFFIX "gbm") 38 | elseif(${BACKEND_TYPE} STREQUAL "DRM-EGLSTREAM") 39 | set(TARGET_SUFFIX "eglstream") 40 | elseif(${BACKEND_TYPE} STREQUAL "X11") 41 | set(TARGET_SUFFIX "x11") 42 | else() 43 | set(TARGET_SUFFIX "wayland") 44 | endif() 45 | set(TARGET "flutter_elinux_${TARGET_SUFFIX}") 46 | endif() 47 | 48 | # System level dependent library. 49 | include(cmake/package.cmake) 50 | 51 | # Rules of 3rd party libraries. 52 | # RapidJson library. 53 | include(cmake/rapidjson.cmake) 54 | 55 | # Build for target. 56 | include(cmake/build.cmake) 57 | 58 | # Install the bundle. 59 | include(cmake/install.cmake) 60 | -------------------------------------------------------------------------------- /src/third_party/rapidjson/include/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | #include 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | namespace internal { 23 | 24 | //! Custom strlen() which works on different character types. 25 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 26 | \param s Null-terminated input string. 27 | \return Number of characters in the string. 28 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 29 | */ 30 | template 31 | inline SizeType StrLen(const Ch* s) { 32 | RAPIDJSON_ASSERT(s != 0); 33 | const Ch* p = s; 34 | while (*p) ++p; 35 | return SizeType(p - s); 36 | } 37 | 38 | template <> 39 | inline SizeType StrLen(const char* s) { 40 | return SizeType(std::strlen(s)); 41 | } 42 | 43 | template <> 44 | inline SizeType StrLen(const wchar_t* s) { 45 | return SizeType(std::wcslen(s)); 46 | } 47 | 48 | //! Returns number of code points in a encoded string. 49 | template 50 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 51 | RAPIDJSON_ASSERT(s != 0); 52 | RAPIDJSON_ASSERT(outCount != 0); 53 | GenericStringStream is(s); 54 | const typename Encoding::Ch* end = s + length; 55 | SizeType count = 0; 56 | while (is.src_ < end) { 57 | unsigned codepoint; 58 | if (!Encoding::Decode(is, &codepoint)) 59 | return false; 60 | count++; 61 | } 62 | *outCount = count; 63 | return true; 64 | } 65 | 66 | } // namespace internal 67 | RAPIDJSON_NAMESPACE_END 68 | 69 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 70 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/common/client_wrapper/include/flutter/message_codec.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_MESSAGE_CODEC_H_ 6 | #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_MESSAGE_CODEC_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace flutter { 13 | 14 | // Translates between a binary message and higher-level method call and 15 | // response/error objects. 16 | template 17 | class MessageCodec { 18 | public: 19 | MessageCodec() = default; 20 | 21 | virtual ~MessageCodec() = default; 22 | 23 | // Prevent copying. 24 | MessageCodec(MessageCodec const&) = delete; 25 | MessageCodec& operator=(MessageCodec const&) = delete; 26 | 27 | // Returns the message encoded in |binary_message|, or nullptr if it cannot be 28 | // decoded by this codec. 29 | std::unique_ptr DecodeMessage(const uint8_t* binary_message, 30 | const size_t message_size) const { 31 | return std::move(DecodeMessageInternal(binary_message, message_size)); 32 | } 33 | 34 | // Returns the message encoded in |binary_message|, or nullptr if it cannot be 35 | // decoded by this codec. 36 | std::unique_ptr DecodeMessage( 37 | const std::vector& binary_message) const { 38 | size_t size = binary_message.size(); 39 | const uint8_t* data = size > 0 ? &binary_message[0] : nullptr; 40 | return std::move(DecodeMessageInternal(data, size)); 41 | } 42 | 43 | // Returns a binary encoding of the given |message|, or nullptr if the 44 | // message cannot be serialized by this codec. 45 | std::unique_ptr> EncodeMessage(const T& message) const { 46 | return std::move(EncodeMessageInternal(message)); 47 | } 48 | 49 | protected: 50 | // Implementation of the public interface, to be provided by subclasses. 51 | virtual std::unique_ptr DecodeMessageInternal( 52 | const uint8_t* binary_message, 53 | const size_t message_size) const = 0; 54 | 55 | // Implementation of the public interface, to be provided by subclasses. 56 | virtual std::unique_ptr> EncodeMessageInternal( 57 | const T& message) const = 0; 58 | }; 59 | 60 | } // namespace flutter 61 | 62 | #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_MESSAGE_CODEC_H_ 63 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/surface/surface_decoration.h: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_DECORATION_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_DECORATION_H_ 7 | 8 | #include 9 | 10 | #include "flutter/shell/platform/linux_embedded/surface/context_egl.h" 11 | #include "flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h" 12 | #include "flutter/shell/platform/linux_embedded/surface/surface_gl_delegate.h" 13 | #include "flutter/shell/platform/linux_embedded/window/native_window.h" 14 | 15 | namespace flutter { 16 | 17 | // Surface for window decorations such as a toolbar and max/min buttons. 18 | class SurfaceDecoration : public SurfaceGlDelegate { 19 | public: 20 | SurfaceDecoration(std::unique_ptr context); 21 | ~SurfaceDecoration() = default; 22 | 23 | // Shows a surface is valid or not. 24 | bool IsValid() const; 25 | 26 | // Sets a netive platform's window. 27 | bool SetNativeWindow(NativeWindow* window); 28 | 29 | // Changes a decoration surface size. 30 | // @param[in] width_px Physical width of the surface. 31 | // @param[in] height_px Physical height of the surface. 32 | bool Resize(const size_t width_px, const size_t height_px); 33 | 34 | // Clears and destroys current decoration context. 35 | void DestroyContext(); 36 | 37 | // |SurfaceGlDelegate| 38 | bool GLContextMakeCurrent() const override; 39 | 40 | // |SurfaceGlDelegate| 41 | bool GLContextClearCurrent() const override; 42 | 43 | // |SurfaceGlDelegate| 44 | bool GLContextPresent(uint32_t fbo_id) const override; 45 | 46 | // |SurfaceGlDelegate| 47 | bool GLContextPresentWithInfo(const FlutterPresentInfo* info) const override; 48 | 49 | // |SurfaceGlDelegate| 50 | void PopulateExistingDamage(const intptr_t fbo_id, 51 | FlutterDamage* existing_damage) const override; 52 | 53 | // |SurfaceGlDelegate| 54 | uint32_t GLContextFBO() const override; 55 | 56 | // |SurfaceGlDelegate| 57 | void* GlProcResolver(const char* name) const override; 58 | 59 | protected: 60 | std::unique_ptr context_; 61 | NativeWindow* native_window_ = nullptr; 62 | std::unique_ptr surface_ = nullptr; 63 | }; 64 | 65 | } // namespace flutter 66 | 67 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_SURFACE_DECORATION_H_ 68 | -------------------------------------------------------------------------------- /examples/flutter-video-player-plugin/flutter/plugins/video_player/elinux/messages/position_message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_POSITION_MESSAGE_H_ 6 | #define PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_POSITION_MESSAGE_H_ 7 | 8 | #include 9 | #include 10 | 11 | class PositionMessage { 12 | public: 13 | PositionMessage() = default; 14 | ~PositionMessage() = default; 15 | 16 | // Prevent copying. 17 | PositionMessage(PositionMessage const&) = default; 18 | PositionMessage& operator=(PositionMessage const&) = default; 19 | 20 | void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } 21 | 22 | int64_t GetTextureId() const { return texture_id_; } 23 | 24 | void SetPosition(int64_t position) { position_ = position; } 25 | 26 | int64_t GetPosition() const { return position_; } 27 | 28 | flutter::EncodableValue ToMap() { 29 | flutter::EncodableMap toMapResult = {{flutter::EncodableValue("textureId"), 30 | flutter::EncodableValue(texture_id_)}, 31 | {flutter::EncodableValue("position"), 32 | flutter::EncodableValue(position_)}}; 33 | 34 | return flutter::EncodableValue(toMapResult); 35 | } 36 | 37 | static PositionMessage FromMap(const flutter::EncodableValue& value) { 38 | PositionMessage message; 39 | if (std::holds_alternative(value)) { 40 | auto map = std::get(value); 41 | 42 | flutter::EncodableValue& texture_id = 43 | map[flutter::EncodableValue("textureId")]; 44 | if (std::holds_alternative(texture_id) || 45 | std::holds_alternative(texture_id)) { 46 | message.SetTextureId(texture_id.LongValue()); 47 | } 48 | 49 | flutter::EncodableValue& position = 50 | map[flutter::EncodableValue("position")]; 51 | if (std::holds_alternative(position) || 52 | std::holds_alternative(position)) { 53 | message.SetPosition(position.LongValue()); 54 | } 55 | } 56 | 57 | return message; 58 | } 59 | 60 | private: 61 | int64_t texture_id_ = 0; 62 | int64_t position_ = 0; 63 | }; 64 | 65 | #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_MESSAGES_POSITION_MESSAGE_H_ 66 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/external_texture.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_H_ 6 | #define FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_H_ 7 | 8 | #include "flutter/shell/platform/embedder/embedder.h" 9 | 10 | #ifdef USE_GLES3 11 | #include 12 | #else 13 | #include 14 | #include 15 | #endif 16 | 17 | namespace flutter { 18 | 19 | typedef void (*glGenTexturesProc)(GLsizei n, GLuint* textures); 20 | typedef void (*glDeleteTexturesProc)(GLsizei n, const GLuint* textures); 21 | typedef void (*glBindTextureProc)(GLenum target, GLuint texture); 22 | typedef void (*glTexParameteriProc)(GLenum target, GLenum pname, GLint param); 23 | typedef void (*glTexImage2DProc)(GLenum target, 24 | GLint level, 25 | GLint internalformat, 26 | GLsizei width, 27 | GLsizei height, 28 | GLint border, 29 | GLenum format, 30 | GLenum type, 31 | const void* data); 32 | typedef void (*glEGLImageTargetTexture2DOESProc)(GLenum target, 33 | GLeglImageOES image); 34 | 35 | // A struct containing pointers to resolved gl* functions. 36 | struct GlProcs { 37 | glGenTexturesProc glGenTextures; 38 | glDeleteTexturesProc glDeleteTextures; 39 | glBindTextureProc glBindTexture; 40 | glTexParameteriProc glTexParameteri; 41 | glTexImage2DProc glTexImage2D; 42 | glEGLImageTargetTexture2DOESProc glEGLImageTargetTexture2DOES; 43 | bool valid; 44 | }; 45 | 46 | // Abstract external texture. 47 | class ExternalTexture { 48 | public: 49 | virtual ~ExternalTexture() = default; 50 | 51 | // Returns the unique id of this texture. 52 | int64_t texture_id() const { return reinterpret_cast(this); }; 53 | 54 | // Attempts to populate the specified |opengl_texture| with texture details 55 | // such as the name, width, height and the pixel format. 56 | // Returns true on success. 57 | virtual bool PopulateTexture(size_t width, 58 | size_t height, 59 | FlutterOpenGLTexture* opengl_texture) = 0; 60 | }; 61 | 62 | } // namespace flutter 63 | 64 | #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_H_ 65 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_FLUTTER_ELINUX_TEXTURE_REGISTRAR_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_FLUTTER_ELINUX_TEXTURE_REGISTRAR_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "flutter/fml/closure.h" 13 | #include "flutter/shell/platform/common/public/flutter_texture_registrar.h" 14 | #include "flutter/shell/platform/linux_embedded/external_texture.h" 15 | 16 | namespace flutter { 17 | 18 | class FlutterELinuxEngine; 19 | 20 | // An object managing the registration of an external texture. 21 | // Thread safety: All member methods are thread safe. 22 | class FlutterELinuxTextureRegistrar { 23 | public: 24 | explicit FlutterELinuxTextureRegistrar(FlutterELinuxEngine* engine, 25 | const GlProcs& gl_procs); 26 | 27 | // Registers a texture described by the given |texture_info| object. 28 | // Returns the non-zero, positive texture id or -1 on error. 29 | int64_t RegisterTexture(const FlutterDesktopTextureInfo* texture_info); 30 | 31 | // Attempts to unregister the texture identified by |texture_id|. 32 | void UnregisterTexture(int64_t texture_id, fml::closure callback = nullptr); 33 | 34 | // Notifies the engine about a new frame being available. 35 | // Returns true on success. 36 | bool MarkTextureFrameAvailable(int64_t texture_id); 37 | 38 | // Attempts to populate the given |texture| by copying the 39 | // contents of the texture identified by |texture_id|. 40 | // Returns true on success. 41 | bool PopulateTexture(int64_t texture_id, 42 | size_t width, 43 | size_t height, 44 | FlutterOpenGLTexture* texture); 45 | 46 | // Populates the OpenGL function pointers in |gl_procs|. 47 | static void ResolveGlFunctions(GlProcs& gl_procs); 48 | 49 | private: 50 | FlutterELinuxEngine* engine_ = nullptr; 51 | const GlProcs& gl_procs_; 52 | 53 | // All registered textures, keyed by their IDs. 54 | std::unordered_map> 55 | textures_; 56 | std::mutex map_mutex_; 57 | 58 | int64_t EmplaceTexture(std::unique_ptr texture); 59 | } SWIFT_UNSAFE_REFERENCE; 60 | 61 | }; // namespace flutter 62 | 63 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_FLUTTER_ELINUX_TEXTURE_REGISTRAR_H_ 64 | -------------------------------------------------------------------------------- /src/flutter/fml/closure.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_FML_CLOSURE_H_ 6 | #define FLUTTER_FML_CLOSURE_H_ 7 | 8 | #include 9 | 10 | #include "flutter/fml/macros.h" 11 | 12 | namespace fml { 13 | 14 | using closure = std::function; 15 | 16 | //------------------------------------------------------------------------------ 17 | /// @brief Wraps a closure that is invoked in the destructor unless 18 | /// released by the caller. 19 | /// 20 | /// This is especially useful in dealing with APIs that return a 21 | /// resource by accepting ownership of a sub-resource and a closure 22 | /// that releases that resource. When such APIs are chained, each 23 | /// link in the chain must check that the next member in the chain 24 | /// has accepted the resource. If not, it must invoke the closure 25 | /// eagerly. Not doing this results in a resource leak in the 26 | /// erroneous case. Using this wrapper, the closure can be released 27 | /// once the next call in the chain has successfully accepted 28 | /// ownership of the resource. If not, the closure gets invoked 29 | /// automatically at the end of the scope. This covers the cases 30 | /// where there are early returns as well. 31 | /// 32 | class ScopedCleanupClosure final { 33 | public: 34 | ScopedCleanupClosure() = default; 35 | 36 | ScopedCleanupClosure(ScopedCleanupClosure&& other) { 37 | closure_ = other.Release(); 38 | } 39 | 40 | ScopedCleanupClosure& operator=(ScopedCleanupClosure&& other) { 41 | closure_ = other.Release(); 42 | return *this; 43 | } 44 | 45 | explicit ScopedCleanupClosure(const fml::closure& closure) 46 | : closure_(closure) {} 47 | 48 | ~ScopedCleanupClosure() { Reset(); } 49 | 50 | fml::closure SetClosure(const fml::closure& closure) { 51 | auto old_closure = closure_; 52 | closure_ = closure; 53 | return old_closure; 54 | } 55 | 56 | fml::closure Release() { 57 | fml::closure closure = closure_; 58 | closure_ = nullptr; 59 | return closure; 60 | } 61 | 62 | void Reset() { 63 | if (closure_) { 64 | closure_(); 65 | closure_ = nullptr; 66 | } 67 | } 68 | 69 | private: 70 | fml::closure closure_; 71 | 72 | FML_DISALLOW_COPY_AND_ASSIGN(ScopedCleanupClosure); 73 | }; 74 | 75 | } // namespace fml 76 | 77 | #endif // FLUTTER_FML_CLOSURE_H_ 78 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/elinux_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_ELINUX_WINDOW_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_ELINUX_WINDOW_H_ 7 | 8 | #include 9 | 10 | #include "flutter/shell/platform/linux_embedded/public/flutter_elinux.h" 11 | #include "flutter/shell/platform/linux_embedded/window_binding_handler.h" 12 | 13 | namespace flutter { 14 | 15 | class ELinuxWindow { 16 | public: 17 | ELinuxWindow() = default; 18 | virtual ~ELinuxWindow() = default; 19 | 20 | protected: 21 | virtual bool IsValid() const = 0; 22 | 23 | // Get current window width in physical pixels. 24 | uint32_t GetCurrentWidth() const { 25 | return view_properties_.width * current_scale_; 26 | } 27 | 28 | // Get current window height in physical pixels. 29 | uint32_t GetCurrentHeight() const { 30 | return view_properties_.height * current_scale_; 31 | } 32 | 33 | void SetRotation(FlutterDesktopViewRotation rotation) { 34 | if (rotation == FlutterDesktopViewRotation::kRotation_90) { 35 | current_rotation_ = 90; 36 | } else if (rotation == FlutterDesktopViewRotation::kRotation_180) { 37 | current_rotation_ = 180; 38 | } else if (rotation == FlutterDesktopViewRotation::kRotation_270) { 39 | current_rotation_ = 270; 40 | } else { 41 | current_rotation_ = 0; 42 | } 43 | } 44 | 45 | void NotifyDisplayInfoUpdates() const { 46 | if (binding_handler_delegate_) { 47 | binding_handler_delegate_->UpdateDisplayInfo( 48 | std::trunc(1000000.0 / frame_rate_), GetCurrentWidth(), 49 | GetCurrentHeight(), current_scale_); 50 | } 51 | } 52 | 53 | FlutterDesktopViewProperties view_properties_; 54 | 55 | // A pointer to a FlutterWindowsView that can be used to update engine 56 | // windowing and input state. 57 | WindowBindingHandlerDelegate* binding_handler_delegate_ = nullptr; 58 | 59 | int32_t display_max_width_ = -1; 60 | int32_t display_max_height_ = -1; 61 | int32_t frame_rate_ = 60000; 62 | double current_scale_ = 1.0; 63 | uint16_t current_rotation_ = 0; 64 | // The x coordinate of the pointer in physical pixels. 65 | double pointer_x_ = 0; 66 | // The y coordinate of the pointer in physical pixels. 67 | double pointer_y_ = 0; 68 | std::string clipboard_data_ = ""; 69 | }; 70 | 71 | } // namespace flutter 72 | 73 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_ELINUX_WINDOW_H_ 74 | -------------------------------------------------------------------------------- /src/flutter/shell/platform/linux_embedded/window/native_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 Sony Corporation. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_H_ 6 | #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_H_ 7 | 8 | #include 9 | 10 | namespace flutter { 11 | 12 | class NativeWindow { 13 | public: 14 | NativeWindow() = default; 15 | virtual ~NativeWindow() = default; 16 | 17 | bool IsValid() const { return valid_; }; 18 | 19 | EGLNativeWindowType Window() const { return window_; } 20 | 21 | // Gets a window (GBM surface) for offscreen resource. 22 | EGLNativeWindowType WindowOffscreen() const { return window_offscreen_; } 23 | 24 | // Get physical width of the window. 25 | int32_t Width() const { 26 | if (!valid_) { 27 | return -1; 28 | } 29 | return width_; 30 | } 31 | 32 | // Get physical height of the window. 33 | int32_t Height() const { 34 | if (!valid_) { 35 | return -1; 36 | } 37 | return height_; 38 | } 39 | 40 | bool EnableVsync() const { return enable_vsync_; } 41 | 42 | virtual bool IsNeedRecreateSurfaceAfterResize() const { return false; } 43 | 44 | // Sets a window position. Basically, this API is used for window decorations 45 | // such as titlebar. 46 | // @param[in] x_dip The x coordinate in logical pixels. 47 | // @param[in] y_dip The y coordinate in logical pixels. 48 | virtual void SetPosition(const int32_t x_dip, const int32_t y_dip) { 49 | x_ = x_dip; 50 | y_ = y_dip; 51 | }; 52 | 53 | // @param[in] width_px Physical width of the window. 54 | // @param[in] height_px Physical height of the window. 55 | virtual bool Resize(const size_t width_px, const size_t height_px) = 0; 56 | 57 | // Swaps frame buffers. This API performs processing only for the DRM-GBM 58 | // backend. It is prepared to make the interface common. 59 | virtual void SwapBuffers() { /* do nothing. */ }; 60 | 61 | protected: 62 | EGLNativeWindowType window_; 63 | EGLNativeWindowType window_offscreen_; 64 | bool enable_vsync_; 65 | // Physical width of the window. 66 | int32_t width_; 67 | // Physical height of the window. 68 | int32_t height_; 69 | // The x coordinate of the window in logical pixels. 70 | int32_t x_; 71 | // The y coordinate of the window in logical pixels. 72 | int32_t y_; 73 | bool valid_ = false; 74 | }; 75 | 76 | } // namespace flutter 77 | 78 | #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_NATIVE_WINDOW_H_ 79 | --------------------------------------------------------------------------------