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 
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  FlView* view;
21 
22  // Messenger to communicate on.
23  FlBinaryMessenger* messenger;
24 
25  // Texture registrar in use.
26  FlTextureRegistrar* texture_registrar;
27 };
28 
29 // Added here to stop the compiler from optimizing this function away.
30 G_MODULE_EXPORT GType fl_plugin_registrar_get_type();
31 
33  FlPluginRegistrarInterface* iface);
34 
35 G_DEFINE_INTERFACE(FlPluginRegistrar, fl_plugin_registrar, G_TYPE_OBJECT)
36 
38  FlPluginRegistrarImpl,
39  fl_plugin_registrar_impl,
40  G_TYPE_OBJECT,
41  G_IMPLEMENT_INTERFACE(fl_plugin_registrar_get_type(),
43 
44 static void fl_plugin_registrar_default_init(
45  FlPluginRegistrarInterface* iface) {}
46 
47 static void fl_plugin_registrar_impl_dispose(GObject* object) {
48  FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(object);
49 
50  if (self->view != nullptr) {
51  g_object_remove_weak_pointer(G_OBJECT(self->view),
52  reinterpret_cast<gpointer*>(&(self->view)));
53  self->view = nullptr;
54  }
55  g_clear_object(&self->messenger);
56  g_clear_object(&self->texture_registrar);
57 
58  G_OBJECT_CLASS(fl_plugin_registrar_impl_parent_class)->dispose(object);
59 }
60 
62  FlPluginRegistrarImplClass* klass) {
63  G_OBJECT_CLASS(klass)->dispose = fl_plugin_registrar_impl_dispose;
64 }
65 
66 static FlBinaryMessenger* get_messenger(FlPluginRegistrar* registrar) {
67  FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(registrar);
68  return self->messenger;
69 }
70 
71 static FlTextureRegistrar* get_texture_registrar(FlPluginRegistrar* registrar) {
72  FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(registrar);
73  return self->texture_registrar;
74 }
75 
76 static FlView* get_view(FlPluginRegistrar* registrar) {
77  FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(registrar);
78  return self->view;
79 }
80 
82  FlPluginRegistrarInterface* iface) {
83  iface->get_messenger = get_messenger;
84  iface->get_texture_registrar = get_texture_registrar;
85  iface->get_view = get_view;
86 }
87 
88 static void fl_plugin_registrar_impl_init(FlPluginRegistrarImpl* self) {}
89 
90 FlPluginRegistrar* fl_plugin_registrar_new(
91  FlView* view,
92  FlBinaryMessenger* messenger,
93  FlTextureRegistrar* texture_registrar) {
94  g_return_val_if_fail(view == nullptr || FL_IS_VIEW(view), nullptr);
95  g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
96  g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(texture_registrar), nullptr);
97 
98  FlPluginRegistrarImpl* self = FL_PLUGIN_REGISTRAR_IMPL(
99  g_object_new(fl_plugin_registrar_impl_get_type(), nullptr));
100 
101  // Added to stop compiler complaining about an unused function.
102  FL_IS_PLUGIN_REGISTRAR_IMPL(self);
103 
104  self->view = view;
105  if (view != nullptr) {
106  g_object_add_weak_pointer(G_OBJECT(view),
107  reinterpret_cast<gpointer*>(&(self->view)));
108  }
109  self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
110  self->texture_registrar =
111  FL_TEXTURE_REGISTRAR(g_object_ref(texture_registrar));
112 
113  return FL_PLUGIN_REGISTRAR(self);
114 }
115 
116 G_MODULE_EXPORT FlBinaryMessenger* fl_plugin_registrar_get_messenger(
117  FlPluginRegistrar* self) {
118  g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
119 
120  return FL_PLUGIN_REGISTRAR_GET_IFACE(self)->get_messenger(self);
121 }
122 
123 G_MODULE_EXPORT FlTextureRegistrar* fl_plugin_registrar_get_texture_registrar(
124  FlPluginRegistrar* self) {
125  g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
126 
127  return FL_PLUGIN_REGISTRAR_GET_IFACE(self)->get_texture_registrar(self);
128 }
129 
130 G_MODULE_EXPORT FlView* fl_plugin_registrar_get_view(FlPluginRegistrar* self) {
131  g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
132 
133  return FL_PLUGIN_REGISTRAR_GET_IFACE(self)->get_view(self);
134 }
FlPluginRegistrar * fl_plugin_registrar_new(FlView *view, FlBinaryMessenger *messenger, FlTextureRegistrar *texture_registrar)
static FlView * get_view(FlPluginRegistrar *registrar)
G_BEGIN_DECLS FlTextureRegistrar * texture_registrar
static void fl_plugin_registrar_impl_iface_init(FlPluginRegistrarInterface *iface)
static FlTextureRegistrar * get_texture_registrar(FlPluginRegistrar *registrar)
G_MODULE_EXPORT FlBinaryMessenger * fl_plugin_registrar_get_messenger(FlPluginRegistrar *self)
G_DECLARE_FINAL_TYPE(FlPluginRegistrarImpl, fl_plugin_registrar_impl, FL, PLUGIN_REGISTRAR_IMPL, GObject) struct _FlPluginRegistrarImpl
G_MODULE_EXPORT FlView * fl_plugin_registrar_get_view(FlPluginRegistrar *self)
static FlBinaryMessenger * get_messenger(FlPluginRegistrar *registrar)
static void fl_plugin_registrar_impl_class_init(FlPluginRegistrarImplClass *klass)
G_MODULE_EXPORT FlTextureRegistrar * fl_plugin_registrar_get_texture_registrar(FlPluginRegistrar *self)
FlView * view
static void fl_plugin_registrar_impl_dispose(GObject *object)
static void fl_plugin_registrar_impl_init(FlPluginRegistrarImpl *self)
g_return_val_if_fail(type==GDK_KEY_PRESS||type==GDK_KEY_RELEASE, false)
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 GType fl_plugin_registrar_get_type()