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 GObject* where_the_object_was) {
59 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(
user_data);
60 self->engine =
nullptr;
63 g_mutex_lock(&self->textures_mutex);
64 g_autoptr(GHashTable) textures =
self->textures;
65 self->textures = g_hash_table_new_full(g_direct_hash, g_direct_equal,
nullptr,
67 g_hash_table_remove_all(textures);
68 g_mutex_unlock(&self->textures_mutex);
72 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(
object);
74 g_mutex_lock(&self->textures_mutex);
75 g_clear_pointer(&self->textures, g_hash_table_unref);
76 g_mutex_unlock(&self->textures_mutex);
78 if (self->engine !=
nullptr) {
80 self->engine =
nullptr;
82 g_mutex_clear(&self->textures_mutex);
84 G_OBJECT_CLASS(fl_texture_registrar_impl_parent_class)->dispose(
object);
88 FlTextureRegistrarImplClass* klass) {
94 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(registrar);
96 if (FL_IS_TEXTURE_GL(texture) || FL_IS_PIXEL_BUFFER_TEXTURE(texture)) {
97 if (self->engine ==
nullptr) {
106 int64_t
id =
reinterpret_cast<int64_t
>(texture);
109 g_mutex_lock(&self->textures_mutex);
110 g_hash_table_insert(self->textures, GINT_TO_POINTER(
id),
111 g_object_ref(texture));
112 g_mutex_unlock(&self->textures_mutex);
125 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(registrar);
126 g_mutex_lock(&self->textures_mutex);
127 FlTexture* texture =
reinterpret_cast<FlTexture*
>(
128 g_hash_table_lookup(self->textures, GINT_TO_POINTER(
texture_id)));
129 g_mutex_unlock(&self->textures_mutex);
134 FlTexture* texture) {
135 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(registrar);
137 if (self->engine ==
nullptr) {
146 FlTexture* texture) {
147 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(registrar);
149 if (self->engine ==
nullptr) {
156 g_mutex_lock(&self->textures_mutex);
157 if (!g_hash_table_remove(self->textures,
159 g_warning(
"Unregistering a non-existent texture %p", texture);
161 g_mutex_unlock(&self->textures_mutex);
167 FlTextureRegistrarInterface* iface) {
176 self->textures = g_hash_table_new_full(g_direct_hash, g_direct_equal,
nullptr,
179 g_mutex_init(&self->textures_mutex);
183 FlTextureRegistrar*
self,
184 FlTexture* texture) {
185 g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(
self), FALSE);
186 g_return_val_if_fail(FL_IS_TEXTURE(texture), FALSE);
188 return FL_TEXTURE_REGISTRAR_GET_IFACE(
self)->register_texture(
self, texture);
193 g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(
self), NULL);
195 return FL_TEXTURE_REGISTRAR_GET_IFACE(
self)->lookup_texture(
self,
texture_id);
199 FlTextureRegistrar*
self,
200 FlTexture* texture) {
201 g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(
self), FALSE);
203 return FL_TEXTURE_REGISTRAR_GET_IFACE(
self)->mark_texture_frame_available(
208 FlTextureRegistrar*
self,
209 FlTexture* texture) {
210 g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(
self), FALSE);
212 return FL_TEXTURE_REGISTRAR_GET_IFACE(
self)->unregister_texture(
self,
217 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(
218 g_object_new(fl_texture_registrar_impl_get_type(),
nullptr));
221 FL_IS_TEXTURE_REGISTRAR_IMPL(
self);
226 return FL_TEXTURE_REGISTRAR(
self);