9 #include "flutter/shell/platform/embedder/embedder.h"
17 fl_texture_registrar_impl,
19 TEXTURE_REGISTRAR_IMPL,
22 struct _FlTextureRegistrarImpl {
23 GObject parent_instance;
39 GMutex textures_mutex;
43 FlTextureRegistrarInterface* iface);
48 FlTextureRegistrarImpl,
49 fl_texture_registrar_impl,
51 G_IMPLEMENT_INTERFACE(fl_texture_registrar_get_type(),
54 static
void fl_texture_registrar_default_init(
55 FlTextureRegistrarInterface* iface) {}
58 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(
object);
60 g_mutex_lock(&self->textures_mutex);
61 g_clear_pointer(&self->textures, g_hash_table_unref);
62 g_mutex_unlock(&self->textures_mutex);
64 g_weak_ref_clear(&self->engine);
65 g_mutex_clear(&self->textures_mutex);
67 G_OBJECT_CLASS(fl_texture_registrar_impl_parent_class)->dispose(
object);
71 FlTextureRegistrarImplClass* klass) {
77 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(registrar);
79 if (FL_IS_TEXTURE_GL(texture) || FL_IS_PIXEL_BUFFER_TEXTURE(texture)) {
80 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
81 if (engine ==
nullptr) {
90 int64_t
id =
reinterpret_cast<int64_t
>(texture);
93 g_mutex_lock(&self->textures_mutex);
94 g_hash_table_insert(self->textures, GINT_TO_POINTER(
id),
95 g_object_ref(texture));
96 g_mutex_unlock(&self->textures_mutex);
109 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(registrar);
110 g_mutex_lock(&self->textures_mutex);
111 FlTexture* texture =
reinterpret_cast<FlTexture*
>(
112 g_hash_table_lookup(self->textures, GINT_TO_POINTER(
texture_id)));
113 g_mutex_unlock(&self->textures_mutex);
118 FlTexture* texture) {
119 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(registrar);
121 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
122 if (engine ==
nullptr) {
131 FlTexture* texture) {
132 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(registrar);
134 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
135 if (engine ==
nullptr) {
142 g_mutex_lock(&self->textures_mutex);
143 if (!g_hash_table_remove(self->textures,
145 g_warning(
"Unregistering a non-existent texture %p", texture);
147 g_mutex_unlock(&self->textures_mutex);
152 static void shutdown(FlTextureRegistrar* registrar) {
153 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(registrar);
156 g_mutex_lock(&self->textures_mutex);
157 g_autoptr(GHashTable) textures =
self->textures;
158 self->textures = g_hash_table_new_full(g_direct_hash, g_direct_equal,
nullptr,
160 g_hash_table_remove_all(textures);
161 g_mutex_unlock(&self->textures_mutex);
165 FlTextureRegistrarInterface* iface) {
175 self->textures = g_hash_table_new_full(g_direct_hash, g_direct_equal,
nullptr,
178 g_mutex_init(&self->textures_mutex);
182 FlTextureRegistrar*
self,
183 FlTexture* texture) {
184 g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(
self), FALSE);
185 g_return_val_if_fail(FL_IS_TEXTURE(texture), FALSE);
187 return FL_TEXTURE_REGISTRAR_GET_IFACE(
self)->register_texture(
self, texture);
192 g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(
self), NULL);
194 return FL_TEXTURE_REGISTRAR_GET_IFACE(
self)->lookup_texture(
self,
texture_id);
198 FlTextureRegistrar*
self,
199 FlTexture* texture) {
200 g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(
self), FALSE);
202 return FL_TEXTURE_REGISTRAR_GET_IFACE(
self)->mark_texture_frame_available(
207 FlTextureRegistrar*
self,
208 FlTexture* texture) {
209 g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(
self), FALSE);
211 return FL_TEXTURE_REGISTRAR_GET_IFACE(
self)->unregister_texture(
self,
216 g_return_if_fail(FL_IS_TEXTURE_REGISTRAR(
self));
218 return FL_TEXTURE_REGISTRAR_GET_IFACE(
self)->shutdown(
self);
222 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(
223 g_object_new(fl_texture_registrar_impl_get_type(),
nullptr));
226 FL_IS_TEXTURE_REGISTRAR_IMPL(
self);
228 g_weak_ref_init(&self->engine, G_OBJECT(engine));
230 return FL_TEXTURE_REGISTRAR(
self);