Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ out
.vscode
build.sh
compile_commands.json
.clang-format
.clang-format
build
150 changes: 150 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#
# MIT License
#
# Copyright (c) 2020 Joel Winarske
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

cmake_minimum_required(VERSION 3.10.2)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug, Release, or MinSizeRel." FORCE)
message(STATUS "CMAKE_BUILD_TYPE not set, defaulting to Release.")
endif()

project(flutter-pi LANGUAGES C)

message(STATUS "Generator .............. ${CMAKE_GENERATOR}")
message(STATUS "Build Type ............. ${CMAKE_BUILD_TYPE}")

if(NOT FLUTTER_ENGINE_LIBRARY)

include(FetchContent)

if(NOT FLUTTER_ENGINE_SHA)

if(NOT CHANNEL)
set(CHANNEL "stable" CACHE STRING "Choose the channel, options are: master, dev, beta, stable" FORCE)
message(STATUS "Flutter Channel not set, defaulting to stable")
endif()

message(STATUS "Flutter Channel ........ ${CHANNEL}")

FetchContent_Declare(engine-version
URL https://raw.githubusercontent.com/flutter/flutter/${CHANNEL}/bin/internal/engine.version
DOWNLOAD_NAME engine.version
DOWNLOAD_NO_EXTRACT TRUE
DOWNLOAD_DIR ${CMAKE_BINARY_DIR}
)

FetchContent_GetProperties(engine-version)
if(NOT engine-version_POPULATED)
FetchContent_Populate(engine-version)
file(READ ${CMAKE_BINARY_DIR}/engine.version FLUTTER_ENGINE_SHA)
string(REPLACE "\n" "" FLUTTER_ENGINE_SHA ${FLUTTER_ENGINE_SHA})
else()
MESSAGE(FATAL "Unable to determine engine-version, please override FLUTTER_ENGINE_SHA")
endif()

endif()

message(STATUS "Engine SHA1 ............ ${FLUTTER_ENGINE_SHA}")

# Download and setup the Flutter Engine.

set(FLUTTER_EMBEDDER_ARTIFACTS_ZIP ${CMAKE_BINARY_DIR}/flutter_embedder_${FLUTTER_ENGINE_SHA}.zip)
set(FLUTTER_BUCKET_BASE "https://storage.googleapis.com/flutter_infra/flutter")

if(NOT EXISTS ${FLUTTER_EMBEDDER_ARTIFACTS_ZIP})
file(DOWNLOAD
${FLUTTER_BUCKET_BASE}/${FLUTTER_ENGINE_SHA}/linux-x64/linux-x64-embedder
${FLUTTER_EMBEDDER_ARTIFACTS_ZIP}
SHOW_PROGRESS
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf ${FLUTTER_EMBEDDER_ARTIFACTS_ZIP}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()

set(FLUTTER_ENGINE_LIBRARY ${CMAKE_BINARY_DIR}/libflutter_engine.so)
else()
message(STATUS "Engine ................. ${FLUTTER_ENGINE_LIBRARY}")
endif()

include(ExternalProject)

set(ENV{PKG_CONFIG_PATH} ${PKG_CONFIG_PATH})
message(STATUS "PKG_CONFIG_PATH ........ $ENV{PKG_CONFIG_PATH}")

include(FindPkgConfig)
pkg_check_modules(GBM REQUIRED gbm)
pkg_check_modules(DRM REQUIRED libdrm)
pkg_check_modules(GLESV2 REQUIRED glesv2)
pkg_check_modules(EGL REQUIRED egl)
pkg_check_modules(GPIOD libgpiod)

set(FLUTTER_PI_SRC
src/flutter-pi.c
src/platformchannel.c
src/pluginregistry.c
src/console_keyboard.c
src/plugins/elm327plugin.c
src/plugins/services.c
src/plugins/testplugin.c
src/plugins/text_input.c
src/plugins/raw_keyboard.c
src/plugins/spidev.c
)

if(GPIOD_FOUND)
list(APPEND FLUTTER_PI_SRC src/plugins/gpiod.c)
add_compile_options(-DBUILD_GPIOD_PLUGIN)
else()
message(STATUS "Could not find gpiod library and development headers. flutter-pi will be built without gpiod support. To install, execute 'sudo apt install libgpiod-dev'")
endif()

add_executable(flutter-pi ${FLUTTER_PI_SRC})

target_link_libraries(flutter-pi
${FLUTTER_ENGINE_LIBRARY} ${GPIOD_LDFLAGS} ${GBM_LDFLAGS}
${DRM_LDFLAGS} ${GLESV2_LDFLAGS} ${EGL_LDFLAGS}
pthread dl
)

target_include_directories(flutter-pi PRIVATE
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/include/plugins
${GBM_INCLUDE_DIRS} ${DRM_INCLUDE_DIRS}
${GLESV2_INCLUDE_DIRS} ${EGL_INCLUDE_DIRS}
)

target_compile_options(flutter-pi PRIVATE
${GBM_CFLAGS} ${DRM_CFLAGS}
${GLESV2_CFLAGS} ${EGL_CFLAGS}
${GPIOD_CFLAGS} -ggdb
-DBUILD_TEXT_INPUT_PLUGIN
-DBUILD_ELM327_PLUGIN
-DBUILD_SPIDEV_PLUGIN
-DBUILD_TEST_PLUGIN
)

install(TARGETS flutter-pi RUNTIME DESTINATION bin)
2 changes: 2 additions & 0 deletions include/platformchannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ static inline int _writeSize(uint8_t **pbuffer, int size, size_t *remaining) {
ok = _write32(pbuffer, (uint32_t) size, remaining);
if (ok != 0) return ok;
}

return ok;
}
static inline int _readSize(uint8_t **pbuffer, uint32_t *psize, size_t *remaining) {
int ok;
Expand Down
2 changes: 1 addition & 1 deletion include/pluginregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef int (*platch_obj_recv_callback)(char *channel, struct platch_obj *object
/// will probably cause the application to crash.
/// deinit is also called AFTER the engine is shut down.
struct flutterpi_plugin {
const char const* name;
const char* name;
init_deinit_cb init;
init_deinit_cb deinit;
};
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/console_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ int console_restore(void) {
}

is_raw = false;

return 0;
}

size_t utf8_symbol_length(char *c) {
Expand Down
94 changes: 46 additions & 48 deletions src/flutter-pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct {
} egl = {0};

struct {
char asset_bundle_path[256];
char asset_bundle_path[240];
char kernel_blob_path[256];
char executable_path[256];
char icu_data_path[256];
Expand Down Expand Up @@ -233,25 +233,23 @@ struct drm_fb *drm_fb_get_from_bo(struct gbm_bo *bo) {
height = gbm_bo_get_height(bo);
format = gbm_bo_get_format(bo);

if (gbm_bo_get_modifier && gbm_bo_get_plane_count && gbm_bo_get_stride_for_plane && gbm_bo_get_offset) {
uint64_t modifiers[4] = {0};
modifiers[0] = gbm_bo_get_modifier(bo);
const int num_planes = gbm_bo_get_plane_count(bo);
uint64_t modifiers[4] = {0};
modifiers[0] = gbm_bo_get_modifier(bo);
const int num_planes = gbm_bo_get_plane_count(bo);

for (int i = 0; i < num_planes; i++) {
strides[i] = gbm_bo_get_stride_for_plane(bo, i);
handles[i] = gbm_bo_get_handle(bo).u32;
offsets[i] = gbm_bo_get_offset(bo, i);
modifiers[i] = modifiers[0];
}

if (modifiers[0]) {
flags = DRM_MODE_FB_MODIFIERS;
}
for (int i = 0; i < num_planes; i++) {
strides[i] = gbm_bo_get_stride_for_plane(bo, i);
handles[i] = gbm_bo_get_handle(bo).u32;
offsets[i] = gbm_bo_get_offset(bo, i);
modifiers[i] = modifiers[0];
}

ok = drmModeAddFB2WithModifiers(drm.fd, width, height, format, handles, strides, offsets, modifiers, &fb->fb_id, flags);
if (modifiers[0]) {
flags = DRM_MODE_FB_MODIFIERS;
}

ok = drmModeAddFB2WithModifiers(drm.fd, width, height, format, handles, strides, offsets, modifiers, &fb->fb_id, flags);

if (ok) {
if (flags)
fprintf(stderr, "drm_fb_get_from_bo: modifiers failed!\n");
Expand Down Expand Up @@ -336,13 +334,13 @@ const GLubyte *hacked_glGetString(GLenum name) {
if (extensions == NULL) {
GLubyte *orig_extensions = (GLubyte *) glGetString(GL_EXTENSIONS);

extensions = malloc(strlen(orig_extensions) + 1);
extensions = malloc(strlen((const char*)orig_extensions) + 1);
if (!extensions) {
fprintf(stderr, "Could not allocate memory for modified GL_EXTENSIONS string\n");
return NULL;
}

strcpy(extensions, orig_extensions);
strcpy((char*)extensions, (const char*)orig_extensions);

/*
* working (apparently)
Expand Down Expand Up @@ -371,40 +369,40 @@ const GLubyte *hacked_glGetString(GLenum name) {
/*
* should be working, but isn't
*/
cut_word_from_string(extensions, "GL_EXT_map_buffer_range");
cut_word_from_string((char*)extensions, "GL_EXT_map_buffer_range");

/*
* definitely broken
*/
cut_word_from_string(extensions, "GL_OES_element_index_uint");
cut_word_from_string(extensions, "GL_OES_fbo_render_mipmap");
cut_word_from_string(extensions, "GL_OES_mapbuffer");
cut_word_from_string(extensions, "GL_OES_rgb8_rgba8");
cut_word_from_string(extensions, "GL_OES_stencil8");
cut_word_from_string(extensions, "GL_OES_texture_3D");
cut_word_from_string(extensions, "GL_OES_packed_depth_stencil");
cut_word_from_string(extensions, "GL_OES_get_program_binary");
cut_word_from_string(extensions, "GL_APPLE_texture_max_level");
cut_word_from_string(extensions, "GL_EXT_discard_framebuffer");
cut_word_from_string(extensions, "GL_EXT_read_format_bgra");
cut_word_from_string(extensions, "GL_EXT_frag_depth");
cut_word_from_string(extensions, "GL_NV_fbo_color_attachments");
cut_word_from_string(extensions, "GL_OES_EGL_sync");
cut_word_from_string(extensions, "GL_OES_vertex_array_object");
cut_word_from_string(extensions, "GL_EXT_unpack_subimage");
cut_word_from_string(extensions, "GL_NV_draw_buffers");
cut_word_from_string(extensions, "GL_NV_read_buffer");
cut_word_from_string(extensions, "GL_NV_read_depth");
cut_word_from_string(extensions, "GL_NV_read_depth_stencil");
cut_word_from_string(extensions, "GL_NV_read_stencil");
cut_word_from_string(extensions, "GL_EXT_draw_buffers");
cut_word_from_string(extensions, "GL_KHR_debug");
cut_word_from_string(extensions, "GL_OES_required_internalformat");
cut_word_from_string(extensions, "GL_OES_surfaceless_context");
cut_word_from_string(extensions, "GL_EXT_separate_shader_objects");
cut_word_from_string(extensions, "GL_KHR_context_flush_control");
cut_word_from_string(extensions, "GL_KHR_no_error");
cut_word_from_string(extensions, "GL_KHR_parallel_shader_compile");
cut_word_from_string((char*)extensions, "GL_OES_element_index_uint");
cut_word_from_string((char*)extensions, "GL_OES_fbo_render_mipmap");
cut_word_from_string((char*)extensions, "GL_OES_mapbuffer");
cut_word_from_string((char*)extensions, "GL_OES_rgb8_rgba8");
cut_word_from_string((char*)extensions, "GL_OES_stencil8");
cut_word_from_string((char*)extensions, "GL_OES_texture_3D");
cut_word_from_string((char*)extensions, "GL_OES_packed_depth_stencil");
cut_word_from_string((char*)extensions, "GL_OES_get_program_binary");
cut_word_from_string((char*)extensions, "GL_APPLE_texture_max_level");
cut_word_from_string((char*)extensions, "GL_EXT_discard_framebuffer");
cut_word_from_string((char*)extensions, "GL_EXT_read_format_bgra");
cut_word_from_string((char*)extensions, "GL_EXT_frag_depth");
cut_word_from_string((char*)extensions, "GL_NV_fbo_color_attachments");
cut_word_from_string((char*)extensions, "GL_OES_EGL_sync");
cut_word_from_string((char*)extensions, "GL_OES_vertex_array_object");
cut_word_from_string((char*)extensions, "GL_EXT_unpack_subimage");
cut_word_from_string((char*)extensions, "GL_NV_draw_buffers");
cut_word_from_string((char*)extensions, "GL_NV_read_buffer");
cut_word_from_string((char*)extensions, "GL_NV_read_depth");
cut_word_from_string((char*)extensions, "GL_NV_read_depth_stencil");
cut_word_from_string((char*)extensions, "GL_NV_read_stencil");
cut_word_from_string((char*)extensions, "GL_EXT_draw_buffers");
cut_word_from_string((char*)extensions, "GL_KHR_debug");
cut_word_from_string((char*)extensions, "GL_OES_required_internalformat");
cut_word_from_string((char*)extensions, "GL_OES_surfaceless_context");
cut_word_from_string((char*)extensions, "GL_EXT_separate_shader_objects");
cut_word_from_string((char*)extensions, "GL_KHR_context_flush_control");
cut_word_from_string((char*)extensions, "GL_KHR_no_error");
cut_word_from_string((char*)extensions, "GL_KHR_parallel_shader_compile");
}

return extensions;
Expand Down
8 changes: 4 additions & 4 deletions src/platformchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ int platch_decode_value_std(uint8_t **pbuffer, size_t *premaining, struct std_va
int32_t *intArray = 0;
uint8_t *byteArray = 0, type_byte = 0;
char *c_string = 0;
size_t size = 0;
uint32_t size = 0;
int ok;

ok = _read8(pbuffer, &type_byte, premaining);
Expand All @@ -451,12 +451,12 @@ int platch_decode_value_std(uint8_t **pbuffer, size_t *premaining, struct std_va
case kStdFalse:
break;
case kStdInt32:
ok = _read32(pbuffer, &value_out->int32_value, premaining);
ok = _read32(pbuffer, (uint32_t*)&value_out->int32_value, premaining);
if (ok != 0) return ok;

break;
case kStdInt64:
ok = _read64(pbuffer, &value_out->int64_value, premaining);
ok = _read64(pbuffer, (uint64_t*)&value_out->int64_value, premaining);
if (ok != 0) return ok;

break;
Expand Down Expand Up @@ -1360,7 +1360,7 @@ bool stdvalue_equals(struct std_value *a, struct std_value *b) {
if (a->list == b->list) return true;

for (int i = 0; i < a->size; i++)
if (!stdvalue_equals(&(a->list[i]), &(b->list[i])));
if (!stdvalue_equals(&(a->list[i]), &(b->list[i])))
return false;

return true;
Expand Down
4 changes: 3 additions & 1 deletion src/pluginregistry.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# include <plugins/elm327plugin.h>
#endif
#ifdef BUILD_GPIOD_PLUGIN
# include <plugins/gpiod.h>
# include <plugins/gpiod_plugin.h>
#endif
#ifdef BUILD_SPIDEV_PLUGIN
# include <plugins/spidev.h>
Expand Down Expand Up @@ -183,4 +183,6 @@ int plugin_registry_deinit() {

/// free the rest
free(pluginregistry.platch_obj_cbs);

return 0;
}
3 changes: 2 additions & 1 deletion src/plugins/elm327plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ int elm_open(char *serial_path, int baudrate) {

ok = elm_command(ELM327_LINEFEEDS_OFF, NULL, 0);
if (ok != 0) {
fprintf(stderr, "[elm327plugin] elm_open: error setting ELM327 linefeeds off using AT L0\n", ok);
fprintf(stderr, "[elm327plugin] elm_open: error setting ELM327 linefeeds off using AT L0\n");
goto error;
}

Expand Down Expand Up @@ -607,6 +607,7 @@ int ELM327Plugin_onReceive(char *channel, struct platch_obj *object, FlutterPlat
} else {
return platch_respond_not_implemented(handle);
}
return 0;
}

int ELM327Plugin_init(void) {
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/gpiod.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#include <pthread.h>
#include <sys/epoll.h>

#include <gpiod.h>

#include <pluginregistry.h>
#include <plugins/gpiod.h>
#include <plugins/gpiod_plugin.h>



Expand Down
Loading