Skip to content

plugin registry, completely reworked platform channels, test plugin #5

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

Merged
merged 4 commits into from
Sep 29, 2019
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
63 changes: 29 additions & 34 deletions src/flutter-pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
#include <flutter_embedder.h>

#include "flutter-pi.h"
#include "methodchannel.h"
#include "platformchannel.h"
#include "pluginregistry.h"


char* usage ="\
Expand Down Expand Up @@ -96,6 +97,7 @@ struct {
int engine_argc;
const char* const *engine_argv;
intptr_t next_vblank_baton;
struct FlutterPiPluginRegistry *registry;
} flutter = {0};

struct {
Expand Down Expand Up @@ -284,7 +286,7 @@ const GLubyte* hacked_glGetString(GLenum name) {
static GLubyte* extensions;

if (extensions == NULL) {
GLubyte* orig_extensions = glGetString(GL_EXTENSIONS);
GLubyte* orig_extensions = (GLubyte *) glGetString(GL_EXTENSIONS);
size_t len_orig_extensions = strlen(orig_extensions);

extensions = malloc(len_orig_extensions+1);
Expand Down Expand Up @@ -380,20 +382,9 @@ void* proc_resolver(void* userdata, const char* name) {
return NULL;
}
void on_platform_message(const FlutterPlatformMessage* message, void* userdata) {
struct MethodCall* methodcall;

if (!MethodChannel_decode(message->message_size, (uint8_t*) (message->message), &methodcall)) {
fprintf(stderr, "Decoding method call failed\n");
return;
}

printf("MethodCall: method name: %s argument type: %d\n", methodcall->method, methodcall->argument.type);

if (strcmp(methodcall->method, "counter") == 0) {
printf("method \"counter\" was called with argument %d\n", methodcall->argument.int_value);
}

MethodChannel_freeMethodCall(&methodcall);
int ok;
if ((ok = PluginRegistry_onPlatformMessage((FlutterPlatformMessage *)message)) != 0)
fprintf(stderr, "PluginRegistry_onPlatformMessage failed: %s\n", strerror(ok));
}
void vsync_callback(void* userdata, intptr_t baton) {
// not yet implemented
Expand Down Expand Up @@ -828,6 +819,15 @@ void destroy_display(void) {
}

bool init_application(void) {
int ok;

printf("Initializing Plugin Registry...\n");
ok = PluginRegistry_init();
if (ok != 0) {
fprintf(stderr, "Could not initialize plugin registry: %s\n", strerror(ok));
return false;
}

// configure flutter rendering
flutter.renderer_config.type = kOpenGL;
flutter.renderer_config.open_gl.struct_size = sizeof(flutter.renderer_config.open_gl);
Expand All @@ -837,9 +837,6 @@ bool init_application(void) {
flutter.renderer_config.open_gl.fbo_callback = fbo_callback;
flutter.renderer_config.open_gl.gl_proc_resolver= proc_resolver;

for (int i=0; i<flutter.engine_argc; i++)
printf("engine_argv[%i] = %s\n", i, flutter.engine_argv[i]);

// configure flutter
flutter.args.struct_size = sizeof(FlutterProjectArgs);
flutter.args.assets_path = flutter.asset_bundle_path;
Expand Down Expand Up @@ -868,17 +865,13 @@ bool init_application(void) {

// spin up the engine
FlutterEngineResult _result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &flutter.renderer_config, &flutter.args, NULL, &engine);

for (int i=0; i<flutter.engine_argc; i++)
printf("engine_argv[%i] = %s\n", i, flutter.engine_argv[i]);

if (_result != kSuccess) {
fprintf(stderr, "Could not run the flutter engine\n");
return false;
}

// update window size
bool ok = FlutterEngineSendWindowMetricsEvent(
ok = FlutterEngineSendWindowMetricsEvent(
engine,
&(FlutterWindowMetricsEvent) {.struct_size = sizeof(FlutterWindowMetricsEvent), .width=width, .height=height, .pixel_ratio = pixel_ratio}
) == kSuccess;
Expand All @@ -891,16 +884,19 @@ bool init_application(void) {
return true;
}
void destroy_application(void) {
if (engine == NULL) return;

FlutterEngineResult _result = FlutterEngineShutdown(engine);

if (_result != kSuccess) {
fprintf(stderr, "Could not shutdown the flutter engine.\n");
}
}
int ok;

if (engine != NULL) {
if (FlutterEngineShutdown(engine) != kSuccess)
fprintf(stderr, "Could not shutdown the flutter engine.\n");

engine = NULL;
}

if ((ok = PluginRegistry_deinit()) != 0) {
fprintf(stderr, "Could not deinitialize plugin registry: %s\n", strerror(ok));
}
}

/****************
* Input-Output *
Expand Down Expand Up @@ -1101,7 +1097,6 @@ bool run_io_thread(void) {
}



bool parse_cmd_args(int argc, char **argv) {
int opt;
int index = 0;
Expand Down Expand Up @@ -1146,7 +1141,7 @@ bool parse_cmd_args(int argc, char **argv) {

argv[optind] = argv[0];
flutter.engine_argc = argc-optind;
flutter.engine_argv = &(argv[optind]);
flutter.engine_argv = (const char* const*) &(argv[optind]);

for (int i=0; i<flutter.engine_argc; i++)
printf("engine_argv[%i] = %s\n", i, flutter.engine_argv[i]);
Expand Down
Loading