13
13
#include " flutter/shell/platform/linux/fl_texture_private.h"
14
14
#include " flutter/shell/platform/linux/fl_texture_registrar_private.h"
15
15
16
- struct _FlTextureRegistrar {
16
+ G_DECLARE_FINAL_TYPE (FlTextureRegistrarImpl,
17
+ fl_texture_registrar_impl,
18
+ FL,
19
+ TEXTURE_REGISTRAR_IMPL,
20
+ GObject)
21
+
22
+ struct _FlTextureRegistrarImpl {
17
23
GObject parent_instance;
18
24
19
25
// Weak reference to the engine this texture registrar is created for.
@@ -27,11 +33,24 @@ struct _FlTextureRegistrar {
27
33
GHashTable* textures;
28
34
};
29
35
30
- G_DEFINE_TYPE (FlTextureRegistrar, fl_texture_registrar, G_TYPE_OBJECT)
36
+ static void fl_texture_registrar_impl_iface_init (
37
+ FlTextureRegistrarInterface* iface);
38
+
39
+ G_DEFINE_INTERFACE (FlTextureRegistrar, fl_texture_registrar, G_TYPE_OBJECT)
40
+
41
+ G_DEFINE_TYPE_WITH_CODE(
42
+ FlTextureRegistrarImpl,
43
+ fl_texture_registrar_impl,
44
+ G_TYPE_OBJECT,
45
+ G_IMPLEMENT_INTERFACE (fl_texture_registrar_get_type(),
46
+ fl_texture_registrar_impl_iface_init))
47
+
48
+ static void fl_texture_registrar_default_init(
49
+ FlTextureRegistrarInterface* iface) {}
31
50
32
51
static void engine_weak_notify_cb (gpointer user_data,
33
52
GObject* where_the_object_was) {
34
- FlTextureRegistrar * self = FL_TEXTURE_REGISTRAR (user_data);
53
+ FlTextureRegistrarImpl * self = FL_TEXTURE_REGISTRAR_IMPL (user_data);
35
54
self->engine = nullptr ;
36
55
37
56
// Unregister any textures.
@@ -41,8 +60,8 @@ static void engine_weak_notify_cb(gpointer user_data,
41
60
g_hash_table_remove_all (textures);
42
61
}
43
62
44
- static void fl_texture_registrar_dispose (GObject* object) {
45
- FlTextureRegistrar * self = FL_TEXTURE_REGISTRAR (object);
63
+ static void fl_texture_registrar_impl_dispose (GObject* object) {
64
+ FlTextureRegistrarImpl * self = FL_TEXTURE_REGISTRAR_IMPL (object);
46
65
47
66
g_clear_pointer (&self->textures , g_hash_table_unref);
48
67
@@ -51,23 +70,17 @@ static void fl_texture_registrar_dispose(GObject* object) {
51
70
self->engine = nullptr ;
52
71
}
53
72
54
- G_OBJECT_CLASS (fl_texture_registrar_parent_class )->dispose (object);
73
+ G_OBJECT_CLASS (fl_texture_registrar_impl_parent_class )->dispose (object);
55
74
}
56
75
57
- static void fl_texture_registrar_class_init (FlTextureRegistrarClass* klass) {
58
- G_OBJECT_CLASS (klass)->dispose = fl_texture_registrar_dispose;
59
- }
60
-
61
- static void fl_texture_registrar_init (FlTextureRegistrar* self) {
62
- self->textures = g_hash_table_new_full (g_direct_hash, g_direct_equal, nullptr ,
63
- g_object_unref);
76
+ static void fl_texture_registrar_impl_class_init (
77
+ FlTextureRegistrarImplClass* klass) {
78
+ G_OBJECT_CLASS (klass)->dispose = fl_texture_registrar_impl_dispose;
64
79
}
65
80
66
- G_MODULE_EXPORT gboolean
67
- fl_texture_registrar_register_texture (FlTextureRegistrar* self,
68
- FlTexture* texture) {
69
- g_return_val_if_fail (FL_IS_TEXTURE_REGISTRAR (self), FALSE );
70
- g_return_val_if_fail (FL_IS_TEXTURE (texture), FALSE );
81
+ static gboolean register_texture (FlTextureRegistrar* registrar,
82
+ FlTexture* texture) {
83
+ FlTextureRegistrarImpl* self = FL_TEXTURE_REGISTRAR_IMPL (registrar);
71
84
72
85
if (FL_IS_TEXTURE_GL (texture) || FL_IS_PIXEL_BUFFER_TEXTURE (texture)) {
73
86
g_hash_table_insert (self->textures ,
@@ -86,17 +99,23 @@ fl_texture_registrar_register_texture(FlTextureRegistrar* self,
86
99
}
87
100
}
88
101
89
- G_MODULE_EXPORT gboolean
90
- fl_texture_registrar_mark_texture_frame_available (FlTextureRegistrar* self,
91
- FlTexture* texture) {
92
- g_return_val_if_fail (FL_IS_TEXTURE_REGISTRAR (self), FALSE );
102
+ static FlTexture* lookup_texture (FlTextureRegistrar* registrar,
103
+ int64_t texture_id) {
104
+ FlTextureRegistrarImpl* self = FL_TEXTURE_REGISTRAR_IMPL (registrar);
105
+ return reinterpret_cast <FlTexture*>(
106
+ g_hash_table_lookup (self->textures , GINT_TO_POINTER (texture_id)));
107
+ }
108
+
109
+ static gboolean mark_texture_frame_available (FlTextureRegistrar* registrar,
110
+ FlTexture* texture) {
111
+ FlTextureRegistrarImpl* self = FL_TEXTURE_REGISTRAR_IMPL (registrar);
93
112
94
113
if (self->engine == nullptr ) {
95
114
return FALSE ;
96
115
}
97
116
98
- if (fl_texture_registrar_get_texture (
99
- self, fl_texture_get_texture_id (texture)) == nullptr ) {
117
+ if (lookup_texture (registrar, fl_texture_get_texture_id (texture)) ==
118
+ nullptr ) {
100
119
g_warning (" Unregistered texture %p" , texture);
101
120
return FALSE ;
102
121
}
@@ -105,36 +124,9 @@ fl_texture_registrar_mark_texture_frame_available(FlTextureRegistrar* self,
105
124
self->engine , fl_texture_get_texture_id (texture));
106
125
}
107
126
108
- gboolean fl_texture_registrar_populate_gl_external_texture (
109
- FlTextureRegistrar* self,
110
- int64_t texture_id,
111
- uint32_t width,
112
- uint32_t height,
113
- FlutterOpenGLTexture* opengl_texture,
114
- GError** error) {
115
- FlTexture* texture = fl_texture_registrar_get_texture (self, texture_id);
116
- if (texture == nullptr ) {
117
- g_set_error (error, fl_engine_error_quark (), FL_ENGINE_ERROR_FAILED,
118
- " Unable to find texture %" G_GINT64_FORMAT, texture_id);
119
- return FALSE ;
120
- }
121
- if (FL_IS_TEXTURE_GL (texture)) {
122
- return fl_texture_gl_populate (FL_TEXTURE_GL (texture), width, height,
123
- opengl_texture, error);
124
- } else if (FL_IS_PIXEL_BUFFER_TEXTURE (texture)) {
125
- return fl_pixel_buffer_texture_populate (
126
- FL_PIXEL_BUFFER_TEXTURE (texture), width, height, opengl_texture, error);
127
- } else {
128
- g_set_error (error, fl_engine_error_quark (), FL_ENGINE_ERROR_FAILED,
129
- " Unsupported texture type %" G_GINT64_FORMAT, texture_id);
130
- return FALSE ;
131
- }
132
- }
133
-
134
- G_MODULE_EXPORT gboolean
135
- fl_texture_registrar_unregister_texture (FlTextureRegistrar* self,
136
- FlTexture* texture) {
137
- g_return_val_if_fail (FL_IS_TEXTURE_REGISTRAR (self), FALSE );
127
+ static gboolean unregister_texture (FlTextureRegistrar* registrar,
128
+ FlTexture* texture) {
129
+ FlTextureRegistrarImpl* self = FL_TEXTURE_REGISTRAR_IMPL (registrar);
138
130
139
131
if (!g_hash_table_remove (
140
132
self->textures ,
@@ -151,18 +143,62 @@ fl_texture_registrar_unregister_texture(FlTextureRegistrar* self,
151
143
self->engine , fl_texture_get_texture_id (texture));
152
144
}
153
145
154
- FlTexture* fl_texture_registrar_get_texture (FlTextureRegistrar* registrar,
155
- int64_t texture_id) {
156
- return reinterpret_cast <FlTexture*>(
157
- g_hash_table_lookup (registrar->textures , GINT_TO_POINTER (texture_id)));
146
+ static void fl_texture_registrar_impl_iface_init (
147
+ FlTextureRegistrarInterface* iface) {
148
+ iface->register_texture = register_texture;
149
+ iface->lookup_texture = lookup_texture;
150
+ iface->mark_texture_frame_available = mark_texture_frame_available;
151
+ iface->unregister_texture = unregister_texture;
152
+ }
153
+
154
+ static void fl_texture_registrar_impl_init (FlTextureRegistrarImpl* self) {
155
+ self->textures = g_hash_table_new_full (g_direct_hash, g_direct_equal, nullptr ,
156
+ g_object_unref);
157
+ }
158
+
159
+ G_MODULE_EXPORT gboolean
160
+ fl_texture_registrar_register_texture (FlTextureRegistrar* self,
161
+ FlTexture* texture) {
162
+ g_return_val_if_fail (FL_IS_TEXTURE_REGISTRAR (self), FALSE );
163
+ g_return_val_if_fail (FL_IS_TEXTURE (texture), FALSE );
164
+
165
+ return FL_TEXTURE_REGISTRAR_GET_IFACE (self)->register_texture (self, texture);
166
+ }
167
+
168
+ FlTexture* fl_texture_registrar_lookup_texture (FlTextureRegistrar* self,
169
+ int64_t texture_id) {
170
+ g_return_val_if_fail (FL_IS_TEXTURE_REGISTRAR (self), NULL );
171
+
172
+ return FL_TEXTURE_REGISTRAR_GET_IFACE (self)->lookup_texture (self, texture_id);
173
+ }
174
+
175
+ G_MODULE_EXPORT gboolean
176
+ fl_texture_registrar_mark_texture_frame_available (FlTextureRegistrar* self,
177
+ FlTexture* texture) {
178
+ g_return_val_if_fail (FL_IS_TEXTURE_REGISTRAR (self), FALSE );
179
+
180
+ return FL_TEXTURE_REGISTRAR_GET_IFACE (self)->mark_texture_frame_available (
181
+ self, texture);
182
+ }
183
+
184
+ G_MODULE_EXPORT gboolean
185
+ fl_texture_registrar_unregister_texture (FlTextureRegistrar* self,
186
+ FlTexture* texture) {
187
+ g_return_val_if_fail (FL_IS_TEXTURE_REGISTRAR (self), FALSE );
188
+
189
+ return FL_TEXTURE_REGISTRAR_GET_IFACE (self)->unregister_texture (self,
190
+ texture);
158
191
}
159
192
160
193
FlTextureRegistrar* fl_texture_registrar_new (FlEngine* engine) {
161
- FlTextureRegistrar* self = FL_TEXTURE_REGISTRAR (
162
- g_object_new (fl_texture_registrar_get_type (), nullptr ));
194
+ FlTextureRegistrarImpl* self = FL_TEXTURE_REGISTRAR_IMPL (
195
+ g_object_new (fl_texture_registrar_impl_get_type (), nullptr ));
196
+
197
+ // Added to stop compiler complaining about an unused function.
198
+ FL_IS_TEXTURE_REGISTRAR_IMPL (self);
163
199
164
200
self->engine = engine;
165
201
g_object_weak_ref (G_OBJECT (engine), engine_weak_notify_cb, self);
166
202
167
- return self;
203
+ return FL_TEXTURE_REGISTRAR ( self) ;
168
204
}
0 commit comments