Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion shell/platform/linux/fl_texture_registrar.cc
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ static gboolean register_texture(FlTextureRegistrar* registrar,
return FALSE;
}

int64_t id = self->next_id++;
// We ideally would use numeric IDs, but for backwards compatibility with
// existing code use the address of the texture. Once all code uses
// fl_texture_get_id we can re-enable this method. See
// https://github.com/flutter/flutter/issues/124009 int64_t id =
// self->next_id++;
int64_t id = reinterpret_cast<int64_t>(texture);
if (fl_engine_register_external_texture(self->engine, id)) {
fl_texture_set_id(texture, id);
g_mutex_lock(&self->textures_mutex);
Expand Down
17 changes: 11 additions & 6 deletions shell/platform/linux/fl_texture_registrar_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ static void* add_mock_texture_to_registrar(void* pointer) {
FlTextureRegistrar* registrar = FL_TEXTURE_REGISTRAR(pointer);
g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
fl_texture_registrar_register_texture(registrar, texture);
pthread_exit(NULL);
int64_t* id = static_cast<int64_t*>(malloc(sizeof(int64_t)));
id[0] = fl_texture_get_id(texture);
pthread_exit(id);
}

// Checks can make a mock registrar.
Expand Down Expand Up @@ -121,18 +123,21 @@ TEST(FlTextureRegistrarTest, RegistrarRegisterTextureInMultipleThreads) {
g_autoptr(FlEngine) engine = make_mock_engine();
g_autoptr(FlTextureRegistrar) registrar = fl_texture_registrar_new(engine);
pthread_t threads[kThreadCount];
int64_t ids[kThreadCount];

for (uint64_t t = 0; t < kThreadCount; t++) {
EXPECT_EQ(pthread_create(&threads[t], NULL, add_mock_texture_to_registrar,
(void*)registrar),
0);
}
for (uint64_t t = 0; t < kThreadCount; t++) {
pthread_join(threads[t], NULL);
void* id;
pthread_join(threads[t], &id);
ids[t] = static_cast<int64_t*>(id)[0];
free(id);
};
// Check the texture named from [1, threadCount].
for (uint64_t t = 1; t <= kThreadCount; t++) {
EXPECT_TRUE(fl_texture_registrar_lookup_texture(registrar, (int64_t)t) !=
NULL);
// Check all the textures were created.
for (uint64_t t = 0; t < kThreadCount; t++) {
EXPECT_TRUE(fl_texture_registrar_lookup_texture(registrar, ids[t]) != NULL);
};
}