| Flutter Linux Embedder |

fl_plugin_registrar.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registrar.h"
6 #include "flutter/shell/platform/linux/fl_plugin_registrar_private.h"
7
8 #include <gmodule.h>
9
10 G_DECLARE_FINAL_TYPE(FlPluginRegistrarImpl,
11 fl_plugin_registrar_impl,
12 FL,
13 PLUGIN_REGISTRAR_IMPL,
14 GObject)
15
16 struct _FlPluginRegistrarImpl {
17 GObject parent_instance;
18
19 // View that plugin is controlling.
20 GWeakRef view;
21
22 // Messenger to communicate on.
23 FlBinaryMessenger* messenger;
24
25 // Texture registrar in use.
26 FlTextureRegistrar* texture_registrar;
27 };
28
29 static void fl_plugin_registrar_impl_iface_init(
30 FlPluginRegistrarInterface* iface);
31
32 G_DEFINE_INTERFACE(FlPluginRegistrar, fl_plugin_registrar, G_TYPE_OBJECT)
33
34 G_DEFINE_TYPE_WITH_CODE(
35 FlPluginRegistrarImpl,
36 fl_plugin_registrar_impl,
37 G_TYPE_OBJECT,
38 G_IMPLEMENT_INTERFACE(fl_plugin_registrar_get_type(),
39 fl_plugin_registrar_impl_iface_init))
40
41 static void fl_plugin_registrar_default_init(
42 FlPluginRegistrarInterface* iface) {}
43
44 static void fl_plugin_registrar_impl_dispose(GObject* object) {
45 FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(object);
46
47 g_weak_ref_clear(&self->view);
48 g_clear_object(&self->messenger);
49 g_clear_object(&self->texture_registrar);
50
51 G_OBJECT_CLASS(fl_plugin_registrar_impl_parent_class)->dispose(object);
52 }
53
54 static void fl_plugin_registrar_impl_class_init(
55 FlPluginRegistrarImplClass* klass) {
56 G_OBJECT_CLASS(klass)->dispose = fl_plugin_registrar_impl_dispose;
57 }
58
59 static FlBinaryMessenger* get_messenger(FlPluginRegistrar* registrar) {
60 FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(registrar);
61 return self->messenger;
62 }
63
64 static FlTextureRegistrar* get_texture_registrar(FlPluginRegistrar* registrar) {
65 FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(registrar);
66 return self->texture_registrar;
67 }
68
69 static FlView* get_view(FlPluginRegistrar* registrar) {
70 FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(registrar);
71 g_autoptr(FlView) view = FL_VIEW(g_weak_ref_get(&self->view));
72 return view;
73 }
74
75 static void fl_plugin_registrar_impl_iface_init(
76 FlPluginRegistrarInterface* iface) {
77 iface->get_messenger = get_messenger;
78 iface->get_texture_registrar = get_texture_registrar;
79 iface->get_view = get_view;
80 }
81
82 static void fl_plugin_registrar_impl_init(FlPluginRegistrarImpl* self) {}
83
84 FlPluginRegistrar* fl_plugin_registrar_new(
85 FlView* view,
86 FlBinaryMessenger* messenger,
87 FlTextureRegistrar* texture_registrar) {
88 g_return_val_if_fail(view == nullptr || FL_IS_VIEW(view), nullptr);
89 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
90 g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(texture_registrar), nullptr);
91
92 FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(
93 g_object_new(fl_plugin_registrar_impl_get_type(), nullptr));
94
95 // Added to stop compiler complaining about an unused function.
96 FL_IS_PLUGIN_REGISTRAR_IMPL(self);
97
98 g_weak_ref_init(&self->view, view);
99 self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
100 self->texture_registrar =
101 FL_TEXTURE_REGISTRAR(g_object_ref(texture_registrar));
102
103 return FL_PLUGIN_REGISTRAR(self);
104 }
105
106 G_MODULE_EXPORT FlBinaryMessenger* fl_plugin_registrar_get_messenger(
107 FlPluginRegistrar* self) {
108 g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
109
110 return FL_PLUGIN_REGISTRAR_GET_IFACE(self)->get_messenger(self);
111 }
112
113 G_MODULE_EXPORT FlTextureRegistrar* fl_plugin_registrar_get_texture_registrar(
114 FlPluginRegistrar* self) {
115 g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
116
117 return FL_PLUGIN_REGISTRAR_GET_IFACE(self)->get_texture_registrar(self);
118 }
119
120 G_MODULE_EXPORT FlView* fl_plugin_registrar_get_view(FlPluginRegistrar* self) {
121 g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
122
123 return FL_PLUGIN_REGISTRAR_GET_IFACE(self)->get_view(self);
124 }
view
FlView * view
Definition: fl_application.cc:36
FL
FL
Definition: fl_binary_messenger.cc:27
G_DEFINE_TYPE_WITH_CODE
G_DEFINE_TYPE_WITH_CODE(FlPluginRegistrarImpl, fl_plugin_registrar_impl, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(fl_plugin_registrar_get_type(), fl_plugin_registrar_impl_iface_init)) static void fl_plugin_registrar_default_init(FlPluginRegistrarInterface *iface)
Definition: fl_plugin_registrar.cc:34
get_view
static FlView * get_view(FlPluginRegistrar *registrar)
Definition: fl_plugin_registrar.cc:69
fl_plugin_registrar_get_texture_registrar
G_MODULE_EXPORT FlTextureRegistrar * fl_plugin_registrar_get_texture_registrar(FlPluginRegistrar *self)
Definition: fl_plugin_registrar.cc:113
fl_plugin_registrar_new
FlPluginRegistrar * fl_plugin_registrar_new(FlView *view, FlBinaryMessenger *messenger, FlTextureRegistrar *texture_registrar)
Definition: fl_plugin_registrar.cc:84
fl_plugin_registrar_impl_dispose
static void fl_plugin_registrar_impl_dispose(GObject *object)
Definition: fl_plugin_registrar.cc:44
get_texture_registrar
static FlTextureRegistrar * get_texture_registrar(FlPluginRegistrar *registrar)
Definition: fl_plugin_registrar.cc:64
fl_plugin_registrar_impl_init
static void fl_plugin_registrar_impl_init(FlPluginRegistrarImpl *self)
Definition: fl_plugin_registrar.cc:82
get_messenger
static FlBinaryMessenger * get_messenger(FlPluginRegistrar *registrar)
Definition: fl_plugin_registrar.cc:59
fl_plugin_registrar_impl_class_init
static void fl_plugin_registrar_impl_class_init(FlPluginRegistrarImplClass *klass)
Definition: fl_plugin_registrar.cc:54
fl_plugin_registrar_get_view
G_MODULE_EXPORT FlView * fl_plugin_registrar_get_view(FlPluginRegistrar *self)
Definition: fl_plugin_registrar.cc:120
G_DECLARE_FINAL_TYPE
G_DECLARE_FINAL_TYPE(FlPluginRegistrarImpl, fl_plugin_registrar_impl, FL, PLUGIN_REGISTRAR_IMPL, GObject) struct _FlPluginRegistrarImpl
Definition: fl_plugin_registrar.cc:10
fl_plugin_registrar_impl_iface_init
static void fl_plugin_registrar_impl_iface_init(FlPluginRegistrarInterface *iface)
Definition: fl_plugin_registrar.cc:75
fl_plugin_registrar_get_messenger
G_MODULE_EXPORT FlBinaryMessenger * fl_plugin_registrar_get_messenger(FlPluginRegistrar *self)
Definition: fl_plugin_registrar.cc:106
fl_plugin_registrar.h
fl_plugin_registrar_private.h