Flutter Engine
The Flutter Engine
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
10G_DECLARE_FINAL_TYPE(FlPluginRegistrarImpl,
11 fl_plugin_registrar_impl,
12 FL,
13 PLUGIN_REGISTRAR_IMPL,
14 GObject)
15
16struct _FlPluginRegistrarImpl {
17 GObject parent_instance;
18
19 // View that plugin is controlling.
20 FlView* view;
21
22 // Messenger to communicate on.
23 FlBinaryMessenger* messenger;
24
25 // Texture registrar in use.
26 FlTextureRegistrar* texture_registrar;
27};
28
30 FlPluginRegistrarInterface* iface);
31
32G_DEFINE_INTERFACE(FlPluginRegistrar, fl_plugin_registrar, G_TYPE_OBJECT)
33
35 FlPluginRegistrarImpl,
36 fl_plugin_registrar_impl,
37 G_TYPE_OBJECT,
38 G_IMPLEMENT_INTERFACE(fl_plugin_registrar_get_type(),
40
41static void fl_plugin_registrar_default_init(
42 FlPluginRegistrarInterface* iface) {}
43
44static void fl_plugin_registrar_impl_dispose(GObject* object) {
45 FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(object);
46
47 if (self->view != nullptr) {
48 g_object_remove_weak_pointer(G_OBJECT(self->view),
49 reinterpret_cast<gpointer*>(&(self->view)));
50 self->view = nullptr;
51 }
52 g_clear_object(&self->messenger);
53 g_clear_object(&self->texture_registrar);
54
55 G_OBJECT_CLASS(fl_plugin_registrar_impl_parent_class)->dispose(object);
56}
57
59 FlPluginRegistrarImplClass* klass) {
60 G_OBJECT_CLASS(klass)->dispose = fl_plugin_registrar_impl_dispose;
61}
62
63static FlBinaryMessenger* get_messenger(FlPluginRegistrar* registrar) {
64 FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(registrar);
65 return self->messenger;
66}
67
68static FlTextureRegistrar* get_texture_registrar(FlPluginRegistrar* registrar) {
69 FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(registrar);
70 return self->texture_registrar;
71}
72
73static FlView* get_view(FlPluginRegistrar* registrar) {
74 FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(registrar);
75 return self->view;
76}
77
79 FlPluginRegistrarInterface* iface) {
80 iface->get_messenger = get_messenger;
81 iface->get_texture_registrar = get_texture_registrar;
82 iface->get_view = get_view;
83}
84
85static void fl_plugin_registrar_impl_init(FlPluginRegistrarImpl* self) {}
86
87FlPluginRegistrar* fl_plugin_registrar_new(
88 FlView* view,
89 FlBinaryMessenger* messenger,
90 FlTextureRegistrar* texture_registrar) {
91 g_return_val_if_fail(view == nullptr || FL_IS_VIEW(view), nullptr);
92 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
93 g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(texture_registrar), nullptr);
94
95 FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(
96 g_object_new(fl_plugin_registrar_impl_get_type(), nullptr));
97
98 // Added to stop compiler complaining about an unused function.
99 FL_IS_PLUGIN_REGISTRAR_IMPL(self);
100
101 self->view = view;
102 if (view != nullptr) {
103 g_object_add_weak_pointer(G_OBJECT(view),
104 reinterpret_cast<gpointer*>(&(self->view)));
105 }
106 self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
107 self->texture_registrar =
108 FL_TEXTURE_REGISTRAR(g_object_ref(texture_registrar));
109
110 return FL_PLUGIN_REGISTRAR(self);
111}
112
113G_MODULE_EXPORT FlBinaryMessenger* fl_plugin_registrar_get_messenger(
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_messenger(self);
118}
119
120G_MODULE_EXPORT FlTextureRegistrar* fl_plugin_registrar_get_texture_registrar(
121 FlPluginRegistrar* self) {
122 g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
123
124 return FL_PLUGIN_REGISTRAR_GET_IFACE(self)->get_texture_registrar(self);
125}
126
127G_MODULE_EXPORT FlView* fl_plugin_registrar_get_view(FlPluginRegistrar* self) {
128 g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
129
130 return FL_PLUGIN_REGISTRAR_GET_IFACE(self)->get_view(self);
131}
G_DEFINE_INTERFACE(FlKeyboardViewDelegate, fl_keyboard_view_delegate, G_TYPE_OBJECT) static void fl_keyboard_view_delegate_default_init(FlKeyboardViewDelegateInterface *iface)
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)
G_MODULE_EXPORT FlTextureRegistrar * fl_plugin_registrar_get_texture_registrar(FlPluginRegistrar *self)
G_MODULE_EXPORT FlView * fl_plugin_registrar_get_view(FlPluginRegistrar *self)
static void fl_plugin_registrar_impl_dispose(GObject *object)
FlPluginRegistrar * fl_plugin_registrar_new(FlView *view, FlBinaryMessenger *messenger, FlTextureRegistrar *texture_registrar)
static FlView * get_view(FlPluginRegistrar *registrar)
static void fl_plugin_registrar_impl_init(FlPluginRegistrarImpl *self)
static FlBinaryMessenger * get_messenger(FlPluginRegistrar *registrar)
static void fl_plugin_registrar_impl_class_init(FlPluginRegistrarImplClass *klass)
G_DECLARE_FINAL_TYPE(FlPluginRegistrarImpl, fl_plugin_registrar_impl, FL, PLUGIN_REGISTRAR_IMPL, GObject) struct _FlPluginRegistrarImpl
static FlTextureRegistrar * get_texture_registrar(FlPluginRegistrar *registrar)
static void fl_plugin_registrar_impl_iface_init(FlPluginRegistrarInterface *iface)
G_MODULE_EXPORT FlBinaryMessenger * fl_plugin_registrar_get_messenger(FlPluginRegistrar *self)
G_BEGIN_DECLS FlTextureRegistrar * texture_registrar