Skip to content

Adding config file feature #281

New issue

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

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

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: feature/compositor-ng
Choose a base branch
from
167 changes: 167 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# SPDX-License-Identifier: MIT
#
# For more information, see:
#
# Documentation/process/clang-format.rst
# https://clang.llvm.org/docs/ClangFormat.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
#
---
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
#AlignArrayOfStructures: Right
AlignConsecutiveAssignments: false
#AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
#AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
#AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
AttributeMacros:
- 'MAYBE_UNUSED'
- 'ATTR_MALLOC'
- 'NONNULL'
- 'ATTR_PURE'
- 'ATTR_CONST'

BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
AlwaysBreakBeforeMultilineStrings: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
#ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: false
ForEachMacros:
- 'for_each_pointer_in_pset'
- 'for_each_pointer_in_cpset'
- 'for_each_connector_in_drmdev'
- 'for_each_encoder_in_drmdev'
- 'for_each_crtc_in_drmdev'
- 'for_each_plane_in_drmdev'
- 'for_each_mode_in_connector'
- 'for_each_unreserved_plane_in_atomic_req'

IncludeBlocks: Regroup
IncludeCategories:
# C standard library headers
- Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>$'
Priority: 1
- Regex: '^<(ctype|dlfcn|fcntl|glob|limits|locale|poll|pthread|regex|semaphore|unistd|sys/mman|sys/stat|sys/types)\.h>$'
Priority: 2
- Regex: '^<(elf|features|getopt|langinfo)\.h>$'
Priority: 3
- Regex: '^<(linux/[^.]*|sys/eventfd)\.h>$'
Priority: 4
- Regex: '^<(plugins/[^.]*|backing_store[^.]*|collection|compositor_ng|cursor|dmabuf_surface|egl_info|egl|flutter-pi|gbm_surface_backing_store|gl_renderer|gles|jsmn|keyboard|locales|modesetting|notifier_listener|pixel_format|platform_view|platformchannel|pluginregistry|surface[^.]*|texture_registry|tracer|user_input)\.h>$'
Priority: 6
- Regex: '.*'
Priority: 5

IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 8
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true

PenaltyBreakAssignment: 60
PenaltyBreakBeforeFirstCallParameter: 0
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 0
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 60

PointerAlignment: Right
ReflowComments: false
SortIncludes: CaseInsensitive
SortUsingDeclarations: false
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp03
StatementMacros:
- 'DECLARE_REF_OPS'
- 'DEFINE_REF_OPS'
- 'DEFINE_STATIC_REF_OPS'
- 'DECLARE_LOCK_OPS'
- 'DEFINE_LOCK_OPS'
- 'DEFINE_STATIC_LOCK_OPS'
- 'DEFINE_INLINE_LOCK_OPS'
- 'UUID'
- 'CONST_UUID'
TabWidth: 4
TypenameMacros:
- 'BMAP_ELEMENT_TYPE'
- 'MAX_ALIGNMENT'
UseTab: Never
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.vscode
.clang-format
build
131 changes: 115 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ option(BUILD_RAW_KEYBOARD_PLUGIN "Include the raw keyboard plugin in the finishe
option(BUILD_TEST_PLUGIN "Include the test plugin in the finished binary. Allows testing platform channel communication." OFF)
option(BUILD_OMXPLAYER_VIDEO_PLAYER_PLUGIN "Include the omxplayer_video_player plugin in the finished binary. Allows for hardware accelerated video playback in flutter using omxplayer." OFF)
option(BUILD_GSTREAMER_VIDEO_PLAYER_PLUGIN "Include the gstreamer_video_player plugin in the finished binary. Allows for more stable, hardware accelerated video playback in flutter using gstreamer." ON)
option(ENABLE_OPENGL "Build with EGL/OpenGL rendering support." ON)
option(TRY_ENABLE_OPENGL "Don't throw an error if EGL/OpenGL aren't found, instead just build without EGL/OpenGL support in that case." ON)
option(ENABLE_VULKAN "Build with Vulkan rendering support." OFF)
option(TRY_ENABLE_VULKAN "Don't throw an error if vulkan isn't found, instead just build without vulkan support in that case." OFF)
set(VULKAN_DEBUG "AUTO" CACHE STRING "Enable vulkan validation layers and verbose vulkan logging. (ON/OFF/AUTO)")
set_property(CACHE VULKAN_DEBUG PROPERTY STRINGS ON OFF AUTO)
option(ENABLE_SOFTWARE "Build with software rendering support." ON)
option(DUMP_ENGINE_LAYERS "True if flutter-pi should dump the list of rendering layers that the flutter engine sends to flutter-pi on each draw." OFF)
option(WARN_MISSING_FIELD_INITIALIZERS "True of the compiler should be instructed to warn about missing field initializers. This needs some hacky workarounds in the code so gcc won't report spurious warnings, so this should only be enabled if the warnings are explicitly required." OFF)
option(ENABLE_TSAN "True to build & link with -fsanitize=thread" OFF)
option(ENABLE_ASAN "True to build & link with -fsanitize=address" OFF)
option(ENABLE_UBSAN "True to build & link with -fsanitize=undefined" OFF)
Expand Down Expand Up @@ -103,8 +111,6 @@ message(STATUS "PKG_CONFIG_PATH ........ $ENV{PKG_CONFIG_PATH}")
include(FindPkgConfig)
pkg_check_modules(DRM REQUIRED libdrm)
pkg_check_modules(GBM REQUIRED gbm)
pkg_check_modules(EGL REQUIRED egl)
pkg_check_modules(GLESV2 REQUIRED glesv2)
pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
pkg_check_modules(LIBINPUT REQUIRED libinput)
pkg_check_modules(LIBXKBCOMMON REQUIRED xkbcommon)
Expand All @@ -115,7 +121,9 @@ add_executable(flutter-pi
src/platformchannel.c
src/pluginregistry.c
src/texture_registry.c
src/compositor.c
# src/compositor.c
src/gl_renderer.c
src/vk_renderer.c
src/modesetting.c
src/collection.c
src/cursor.c
Expand All @@ -124,14 +132,19 @@ add_executable(flutter-pi
src/locales.c
src/notifier_listener.c
src/pixel_format.c
src/compositor_ng.c
src/surface.c
src/backing_store.c
src/gbm_surface_backing_store.c
src/vk_gbm_backing_store.c
src/tracer.c
src/dmabuf_surface.c
src/plugins/services.c
)

target_link_libraries(flutter-pi
${DRM_LDFLAGS}
${GBM_LDFLAGS}
${EGL_LDFLAGS}
${GLESV2_LDFLAGS}
${LIBSYSTEMD_LDFLAGS}
${LIBINPUT_LDFLAGS}
${LIBUDEV_LDFLAGS}
Expand All @@ -145,8 +158,6 @@ target_include_directories(flutter-pi PRIVATE
${CMAKE_SOURCE_DIR}/include/plugins
${DRM_INCLUDE_DIRS}
${GBM_INCLUDE_DIRS}
${EGL_INCLUDE_DIRS}
${GLESV2_INCLUDE_DIRS}
${LIBSYSTEMD_INCLUDE_DIRS}
${LIBINPUT_INCLUDE_DIRS}
${LIBUDEV_INCLUDE_DIRS}
Expand All @@ -156,19 +167,103 @@ target_include_directories(flutter-pi PRIVATE
target_compile_options(flutter-pi PRIVATE
${DRM_CFLAGS}
${GBM_CFLAGS}
${EGL_CFLAGS}
${GLESV2_CFLAGS}
${LIBSYSTEMD_CFLAGS}
${LIBINPUT_CFLAGS}
${LIBUDEV_CFLAGS}
${LIBXKBCOMMON_CFLAGS}
$<$<CONFIG:Debug>:-O0 -Wall -Wextra -Wno-unused-function -Wno-sign-compare -Wno-missing-field-initializers -Werror -ggdb -DDEBUG>
$<$<CONFIG:RelWithDebInfo>:-O2 -Wall -Wextra -Wno-unused-function -Wno-sign-compare -Wno-missing-field-initializers -ggdb>
$<$<CONFIG:Release>:-O2 -Wall -Wextra -Wno-unused-function -Wno-sign-compare -Wno-missing-field-initializers -ggdb>
$<$<CONFIG:Debug>:-O0 -Wall -Wextra -Werror -Wno-sign-compare -ggdb -DDEBUG> # -Wno-unused-function
$<$<CONFIG:RelWithDebInfo>:-O2 -Wall -Wextra -Wno-unused-function -Wno-sign-compare -ggdb>
$<$<CONFIG:Release>:-O2 -Wall -Wextra -Wno-unused-function -Wno-sign-compare -ggdb>
)

# TODO: Just unconditionally define those, make them optional later
target_compile_definitions(flutter-pi PRIVATE HAS_KMS HAS_EGL HAS_GBM HAS_FBDEV)
target_compile_definitions(flutter-pi PRIVATE HAS_KMS HAS_GBM HAS_FBDEV)

if (WARN_MISSING_FIELD_INITIALIZERS)
target_compile_options(flutter-pi PRIVATE -Wmissing-field-initializers -Wno-error=missing-field-initializers)
target_compile_definitions(flutter-pi PRIVATE WARN_MISSING_FIELD_INITIALIZERS)
else()
target_compile_options(flutter-pi PRIVATE -Wno-missing-field-initializers)
endif()

if (ENABLE_OPENGL)
if (TRY_ENABLE_OPENGL)
pkg_check_modules(EGL egl)
pkg_check_modules(GLESV2 glesv2)
else()
pkg_check_modules(EGL REQUIRED egl)
pkg_check_modules(GLESV2 REQUIRED glesv2)
endif()

if (EGL_FOUND)
target_compile_definitions(flutter-pi PRIVATE HAS_EGL)
target_include_directories(flutter-pi PRIVATE ${EGL_INCLUDE_DIRS})
target_compile_options(flutter-pi PRIVATE ${EGL_CFLAGS})
target_link_libraries(flutter-pi ${EGL_LDFLAGS})
else()
FetchContent_Declare(
EGL_REGISTRY
GIT_REPOSITORY "https://github.com/KhronosGroup/EGL-Registry"
GIT_TAG "main"
)
FetchContent_MakeAvailable(EGL_REGISTRY)
target_include_directories(flutter-pi PRIVATE ${EGL_REGISTRY_SOURCE_DIR}/api/)
endif()

if (GLESV2_FOUND)
target_compile_definitions(flutter-pi PRIVATE HAS_GL)
target_include_directories(flutter-pi PRIVATE ${GLESV2_INCLUDE_DIRS})
target_compile_options(flutter-pi PRIVATE ${GLESV2_CFLAGS})
target_link_libraries(flutter-pi ${GLESV2_LDFLAGS})
else()
FetchContent_Declare(
OGL_REGISTRY
GIT_REPOSITORY "https://github.com/KhronosGroup/OpenGL-Registry"
GIT_TAG "main"
)
FetchContent_MakeAvailable(OGL_REGISTRY)
target_include_directories(flutter-pi PRIVATE ${OGL_REGISTRY_SOURCE_DIR}/api/)
endif()

if ( NOT (GLESV2_FOUND AND EGL_FOUND))
if (TRY_ENABLE_OPENGL)
message("EGL and/or OpenGL was not found. Flutter-pi will build without EGL/OpenGL rendering support.")
else()
message(SEND_ERROR "EGL and/or OpenGL was not found. Try building with `-DTRY_ENABLE_OPENGL=On` if you want to just disable EGL/OpenGL support in that case.")
endif()
endif()
endif()

if (ENABLE_VULKAN)
if (TRY_ENABLE_VULKAN)
pkg_check_modules(VULKAN vulkan)
else()
pkg_check_modules(VULKAN REQUIRED vulkan)
endif()

if (VULKAN_FOUND)
target_compile_definitions(flutter-pi PRIVATE HAS_VULKAN)
target_include_directories(flutter-pi PRIVATE ${VULKAN_INCLUDE_DIRS})
target_compile_options(flutter-pi PRIVATE ${VULKAN_CFLAGS})
target_link_libraries(flutter-pi ${VULKAN_LDFLAGS})
else()
FetchContent_Declare(
VULKAN_HEADERS
GIT_REPOSITORY "https://github.com/KhronosGroup/Vulkan-Headers"
GIT_TAG "main"
)
FetchContent_MakeAvailable(VULKAN_HEADERS)
target_include_directories(flutter-pi PRIVATE ${VULKAN_HEADERS_SOURCE_DIR}/include/)
endif()

if ( NOT VULKAN_FOUND )
if (TRY_ENABLE_VULKAN)
message("Vulkan was not found. Flutter-pi will build without vulkan rendering support.")
else()
message(SEND_ERROR "Vulkan was not found. Try building with `-DTRY_ENABLE_VULKAN=On` if you want to just disable vulkan support in that case.")
endif()
endif()
endif()

# TODO: We actually don't need the compile definitions anymore, except for
# text input and raw keyboard plugin (because those have special treatment
Expand Down Expand Up @@ -230,9 +325,13 @@ endif()

# Needed so dart VM can actually resolve symbols in the same
# executable.
target_link_options(flutter-pi PRIVATE
-rdynamic
)
target_link_options(flutter-pi PRIVATE -rdynamic)

if (VULKAN_DEBUG STREQUAL "AUTO")
target_compile_definitions(flutter-pi PRIVATE $<$<CONFIG:Debug>:VULKAN_DEBUG>)
elseif (VULKAN_DEBUG)
target_compile_definitions(flutter-pi PRIVATE VULKAN_DEBUG)
endif()

if (ENABLE_TSAN)
target_link_options(flutter-pi PRIVATE -fsanitize=thread)
Expand Down
32 changes: 32 additions & 0 deletions include/backing_store.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
/*
* Backing Stores
*
* - implements flutter backing stores (used for the compositor interface)
*
* Copyright (c) 2022, Hannes Winkler <[email protected]>
*/


#ifndef _FLUTTERPI_INCLUDE_BACKING_STORE_H
#define _FLUTTERPI_INCLUDE_BACKING_STORE_H

#include <collection.h>
#include <flutter_embedder.h>

struct surface;
struct backing_store;

#define CAST_BACKING_STORE_UNCHECKED(ptr) ((struct backing_store*) (ptr))
#ifdef DEBUG
# define CAST_BACKING_STORE(ptr) __checked_cast_backing_store(ptr)
ATTR_PURE struct backing_store *__checked_cast_backing_store(void *ptr);
#else
# define CAST_BACKING_STORE(ptr) CAST_BACKING_STORE_UNCHECKED(ptr)
#endif

int backing_store_fill(struct backing_store *store, FlutterBackingStore *fl_store);

int backing_store_queue_present(struct backing_store *store, const FlutterBackingStore *fl_store);

#endif // _FLUTTERPI_INCLUDE_BACKING_STORE_H
Loading