5#include "flutter/shell/platform/linux/public/flutter_linux/fl_texture_registrar.h"
9#include "flutter/shell/platform/embedder/embedder.h"
10#include "flutter/shell/platform/linux/fl_engine_private.h"
11#include "flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h"
12#include "flutter/shell/platform/linux/fl_texture_gl_private.h"
13#include "flutter/shell/platform/linux/fl_texture_private.h"
14#include "flutter/shell/platform/linux/fl_texture_registrar_private.h"
17 fl_texture_registrar_impl,
19 TEXTURE_REGISTRAR_IMPL,
22struct _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(),
54static
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),
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);
135 FlTextureRegistrarImpl*
self = FL_TEXTURE_REGISTRAR_IMPL(registrar);
137 if (
self->engine ==
nullptr) {
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,
185 g_return_val_if_fail(FL_IS_TEXTURE_REGISTRAR(
self),
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);
199 FlTextureRegistrar*
self,
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,
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);
static uint32_t next_id()
gboolean fl_engine_mark_texture_frame_available(FlEngine *self, int64_t texture_id)
gboolean fl_engine_unregister_external_texture(FlEngine *self, int64_t texture_id)
gboolean fl_engine_register_external_texture(FlEngine *self, int64_t texture_id)
G_DEFINE_INTERFACE(FlKeyboardViewDelegate, fl_keyboard_view_delegate, G_TYPE_OBJECT) static void fl_keyboard_view_delegate_default_init(FlKeyboardViewDelegateInterface *iface)
G_MODULE_EXPORT int64_t fl_texture_get_id(FlTexture *self)
void fl_texture_set_id(FlTexture *self, int64_t id)
static gboolean register_texture(FlTextureRegistrar *registrar, FlTexture *texture)
static gboolean mark_texture_frame_available(FlTextureRegistrar *registrar, FlTexture *texture)
G_MODULE_EXPORT gboolean fl_texture_registrar_register_texture(FlTextureRegistrar *self, FlTexture *texture)
static void engine_weak_notify_cb(gpointer user_data, GObject *where_the_object_was)
G_DEFINE_TYPE_WITH_CODE(FlTextureRegistrarImpl, fl_texture_registrar_impl, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(fl_texture_registrar_get_type(), fl_texture_registrar_impl_iface_init)) static void fl_texture_registrar_default_init(FlTextureRegistrarInterface *iface)
static void fl_texture_registrar_impl_init(FlTextureRegistrarImpl *self)
G_DECLARE_FINAL_TYPE(FlTextureRegistrarImpl, fl_texture_registrar_impl, FL, TEXTURE_REGISTRAR_IMPL, GObject) struct _FlTextureRegistrarImpl
G_MODULE_EXPORT gboolean fl_texture_registrar_unregister_texture(FlTextureRegistrar *self, FlTexture *texture)
G_MODULE_EXPORT gboolean fl_texture_registrar_mark_texture_frame_available(FlTextureRegistrar *self, FlTexture *texture)
FlTexture * fl_texture_registrar_lookup_texture(FlTextureRegistrar *self, int64_t texture_id)
static FlTexture * lookup_texture(FlTextureRegistrar *registrar, int64_t texture_id)
static void fl_texture_registrar_impl_dispose(GObject *object)
static gboolean unregister_texture(FlTextureRegistrar *registrar, FlTexture *texture)
FlTextureRegistrar * fl_texture_registrar_new(FlEngine *engine)
static void fl_texture_registrar_impl_class_init(FlTextureRegistrarImplClass *klass)
static void fl_texture_registrar_impl_iface_init(FlTextureRegistrarInterface *iface)