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