28
28
#include <flutter_embedder.h>
29
29
30
30
#include "flutter-pi.h"
31
- #include "methodchannel.h"
31
+ #include "platformchannel.h"
32
+ #include "pluginregistry.h"
32
33
33
34
34
35
char * usage = "\
@@ -96,6 +97,7 @@ struct {
96
97
int engine_argc ;
97
98
const char * const * engine_argv ;
98
99
intptr_t next_vblank_baton ;
100
+ struct FlutterPiPluginRegistry * registry ;
99
101
} flutter = {0 };
100
102
101
103
struct {
@@ -284,7 +286,7 @@ const GLubyte* hacked_glGetString(GLenum name) {
284
286
static GLubyte * extensions ;
285
287
286
288
if (extensions == NULL ) {
287
- GLubyte * orig_extensions = glGetString (GL_EXTENSIONS );
289
+ GLubyte * orig_extensions = ( GLubyte * ) glGetString (GL_EXTENSIONS );
288
290
size_t len_orig_extensions = strlen (orig_extensions );
289
291
290
292
extensions = malloc (len_orig_extensions + 1 );
@@ -380,20 +382,9 @@ void* proc_resolver(void* userdata, const char* name) {
380
382
return NULL ;
381
383
}
382
384
void on_platform_message (const FlutterPlatformMessage * message , void * userdata ) {
383
- struct MethodCall * methodcall ;
384
-
385
- if (!MethodChannel_decode (message -> message_size , (uint8_t * ) (message -> message ), & methodcall )) {
386
- fprintf (stderr , "Decoding method call failed\n" );
387
- return ;
388
- }
389
-
390
- printf ("MethodCall: method name: %s argument type: %d\n" , methodcall -> method , methodcall -> argument .type );
391
-
392
- if (strcmp (methodcall -> method , "counter" ) == 0 ) {
393
- printf ("method \"counter\" was called with argument %d\n" , methodcall -> argument .int_value );
394
- }
395
-
396
- MethodChannel_freeMethodCall (& methodcall );
385
+ int ok ;
386
+ if ((ok = PluginRegistry_onPlatformMessage ((FlutterPlatformMessage * )message )) != 0 )
387
+ fprintf (stderr , "PluginRegistry_onPlatformMessage failed: %s\n" , strerror (ok ));
397
388
}
398
389
void vsync_callback (void * userdata , intptr_t baton ) {
399
390
// not yet implemented
@@ -828,6 +819,15 @@ void destroy_display(void) {
828
819
}
829
820
830
821
bool init_application (void ) {
822
+ int ok ;
823
+
824
+ printf ("Initializing Plugin Registry...\n" );
825
+ ok = PluginRegistry_init ();
826
+ if (ok != 0 ) {
827
+ fprintf (stderr , "Could not initialize plugin registry: %s\n" , strerror (ok ));
828
+ return false;
829
+ }
830
+
831
831
// configure flutter rendering
832
832
flutter .renderer_config .type = kOpenGL ;
833
833
flutter .renderer_config .open_gl .struct_size = sizeof (flutter .renderer_config .open_gl );
@@ -837,9 +837,6 @@ bool init_application(void) {
837
837
flutter .renderer_config .open_gl .fbo_callback = fbo_callback ;
838
838
flutter .renderer_config .open_gl .gl_proc_resolver = proc_resolver ;
839
839
840
- for (int i = 0 ; i < flutter .engine_argc ; i ++ )
841
- printf ("engine_argv[%i] = %s\n" , i , flutter .engine_argv [i ]);
842
-
843
840
// configure flutter
844
841
flutter .args .struct_size = sizeof (FlutterProjectArgs );
845
842
flutter .args .assets_path = flutter .asset_bundle_path ;
@@ -868,17 +865,13 @@ bool init_application(void) {
868
865
869
866
// spin up the engine
870
867
FlutterEngineResult _result = FlutterEngineRun (FLUTTER_ENGINE_VERSION , & flutter .renderer_config , & flutter .args , NULL , & engine );
871
-
872
- for (int i = 0 ; i < flutter .engine_argc ; i ++ )
873
- printf ("engine_argv[%i] = %s\n" , i , flutter .engine_argv [i ]);
874
-
875
868
if (_result != kSuccess ) {
876
869
fprintf (stderr , "Could not run the flutter engine\n" );
877
870
return false;
878
871
}
879
872
880
873
// update window size
881
- bool ok = FlutterEngineSendWindowMetricsEvent (
874
+ ok = FlutterEngineSendWindowMetricsEvent (
882
875
engine ,
883
876
& (FlutterWindowMetricsEvent ) {.struct_size = sizeof (FlutterWindowMetricsEvent ), .width = width , .height = height , .pixel_ratio = pixel_ratio }
884
877
) == kSuccess ;
@@ -891,16 +884,19 @@ bool init_application(void) {
891
884
return true;
892
885
}
893
886
void destroy_application (void ) {
894
- if (engine == NULL ) return ;
895
-
896
- FlutterEngineResult _result = FlutterEngineShutdown (engine );
897
-
898
- if (_result != kSuccess ) {
899
- fprintf (stderr , "Could not shutdown the flutter engine.\n" );
900
- }
901
- }
887
+ int ok ;
902
888
889
+ if (engine != NULL ) {
890
+ if (FlutterEngineShutdown (engine ) != kSuccess )
891
+ fprintf (stderr , "Could not shutdown the flutter engine.\n" );
903
892
893
+ engine = NULL ;
894
+ }
895
+
896
+ if ((ok = PluginRegistry_deinit ()) != 0 ) {
897
+ fprintf (stderr , "Could not deinitialize plugin registry: %s\n" , strerror (ok ));
898
+ }
899
+ }
904
900
905
901
/****************
906
902
* Input-Output *
@@ -1101,7 +1097,6 @@ bool run_io_thread(void) {
1101
1097
}
1102
1098
1103
1099
1104
-
1105
1100
bool parse_cmd_args (int argc , char * * argv ) {
1106
1101
int opt ;
1107
1102
int index = 0 ;
@@ -1146,7 +1141,7 @@ bool parse_cmd_args(int argc, char **argv) {
1146
1141
1147
1142
argv [optind ] = argv [0 ];
1148
1143
flutter .engine_argc = argc - optind ;
1149
- flutter .engine_argv = & (argv [optind ]);
1144
+ flutter .engine_argv = ( const char * const * ) & (argv [optind ]);
1150
1145
1151
1146
for (int i = 0 ; i < flutter .engine_argc ; i ++ )
1152
1147
printf ("engine_argv[%i] = %s\n" , i , flutter .engine_argv [i ]);
0 commit comments