|
6 | 6 | #include "flutter/shell/platform/linux/fl_engine_private.h" |
7 | 7 |
|
8 | 8 | #include "flutter/shell/platform/linux/fl_binary_messenger_private.h" |
| 9 | +#include "flutter/shell/platform/linux/fl_plugin_registrar_private.h" |
9 | 10 | #include "flutter/shell/platform/linux/fl_renderer.h" |
| 11 | +#include "flutter/shell/platform/linux/fl_renderer_headless.h" |
| 12 | +#include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registry.h" |
10 | 13 |
|
11 | 14 | #include <gmodule.h> |
12 | 15 |
|
@@ -35,7 +38,15 @@ struct _FlEngine { |
35 | 38 |
|
36 | 39 | G_DEFINE_QUARK(fl_engine_error_quark, fl_engine_error) |
37 | 40 |
|
38 | | -G_DEFINE_TYPE(FlEngine, fl_engine, G_TYPE_OBJECT) |
| 41 | +static void fl_engine_plugin_registry_iface_init( |
| 42 | + FlPluginRegistryInterface* iface); |
| 43 | + |
| 44 | +G_DEFINE_TYPE_WITH_CODE( |
| 45 | + FlEngine, |
| 46 | + fl_engine, |
| 47 | + G_TYPE_OBJECT, |
| 48 | + G_IMPLEMENT_INTERFACE(fl_plugin_registry_get_type(), |
| 49 | + fl_engine_plugin_registry_iface_init)) |
39 | 50 |
|
40 | 51 | // Subclass of GSource that integrates Flutter tasks into the GLib main loop. |
41 | 52 | typedef struct { |
@@ -169,6 +180,20 @@ static void fl_engine_platform_message_response_cb(const uint8_t* data, |
169 | 180 | (GDestroyNotify)g_bytes_unref); |
170 | 181 | } |
171 | 182 |
|
| 183 | +// Implements FlPluginRegistry::get_registrar_for_plugin. |
| 184 | +static FlPluginRegistrar* fl_engine_get_registrar_for_plugin( |
| 185 | + FlPluginRegistry* registry, |
| 186 | + const gchar* name) { |
| 187 | + FlEngine* self = FL_ENGINE(registry); |
| 188 | + |
| 189 | + return fl_plugin_registrar_new(nullptr, self->binary_messenger); |
| 190 | +} |
| 191 | + |
| 192 | +static void fl_engine_plugin_registry_iface_init( |
| 193 | + FlPluginRegistryInterface* iface) { |
| 194 | + iface->get_registrar_for_plugin = fl_engine_get_registrar_for_plugin; |
| 195 | +} |
| 196 | + |
172 | 197 | static void fl_engine_dispose(GObject* object) { |
173 | 198 | FlEngine* self = FL_ENGINE(object); |
174 | 199 |
|
@@ -210,13 +235,17 @@ FlEngine* fl_engine_new(FlDartProject* project, FlRenderer* renderer) { |
210 | 235 | g_return_val_if_fail(FL_IS_DART_PROJECT(project), nullptr); |
211 | 236 | g_return_val_if_fail(FL_IS_RENDERER(renderer), nullptr); |
212 | 237 |
|
213 | | - FlEngine* self = |
214 | | - static_cast<FlEngine*>(g_object_new(fl_engine_get_type(), nullptr)); |
215 | | - self->project = static_cast<FlDartProject*>(g_object_ref(project)); |
216 | | - self->renderer = static_cast<FlRenderer*>(g_object_ref(renderer)); |
| 238 | + FlEngine* self = FL_ENGINE(g_object_new(fl_engine_get_type(), nullptr)); |
| 239 | + self->project = FL_DART_PROJECT(g_object_ref(project)); |
| 240 | + self->renderer = FL_RENDERER(g_object_ref(renderer)); |
217 | 241 | return self; |
218 | 242 | } |
219 | 243 |
|
| 244 | +G_MODULE_EXPORT FlEngine* fl_engine_new_headless(FlDartProject* project) { |
| 245 | + g_autoptr(FlRendererHeadless) renderer = fl_renderer_headless_new(); |
| 246 | + return fl_engine_new(project, FL_RENDERER(renderer)); |
| 247 | +} |
| 248 | + |
220 | 249 | gboolean fl_engine_start(FlEngine* self, GError** error) { |
221 | 250 | g_return_val_if_fail(FL_IS_ENGINE(self), FALSE); |
222 | 251 |
|
|
0 commit comments