Skip to content

Commit c269562

Browse files
Change back to using the memory address of a texture as its ID. (flutter#40899)
Change back to using the memory address of a texture as its ID.
1 parent 46b5891 commit c269562

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

shell/platform/linux/fl_texture_registrar.cc

100755100644
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ static gboolean register_texture(FlTextureRegistrar* registrar,
9898
return FALSE;
9999
}
100100

101-
int64_t id = self->next_id++;
101+
// We ideally would use numeric IDs, but for backwards compatibility with
102+
// existing code use the address of the texture. Once all code uses
103+
// fl_texture_get_id we can re-enable this method. See
104+
// https://github.com/flutter/flutter/issues/124009 int64_t id =
105+
// self->next_id++;
106+
int64_t id = reinterpret_cast<int64_t>(texture);
102107
if (fl_engine_register_external_texture(self->engine, id)) {
103108
fl_texture_set_id(texture, id);
104109
g_mutex_lock(&self->textures_mutex);

shell/platform/linux/fl_texture_registrar_test.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ static void* add_mock_texture_to_registrar(void* pointer) {
7171
FlTextureRegistrar* registrar = FL_TEXTURE_REGISTRAR(pointer);
7272
g_autoptr(FlTexture) texture = FL_TEXTURE(fl_test_registrar_texture_new());
7373
fl_texture_registrar_register_texture(registrar, texture);
74-
pthread_exit(NULL);
74+
int64_t* id = static_cast<int64_t*>(malloc(sizeof(int64_t)));
75+
id[0] = fl_texture_get_id(texture);
76+
pthread_exit(id);
7577
}
7678

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

125128
for (uint64_t t = 0; t < kThreadCount; t++) {
126129
EXPECT_EQ(pthread_create(&threads[t], NULL, add_mock_texture_to_registrar,
127130
(void*)registrar),
128131
0);
129132
}
130133
for (uint64_t t = 0; t < kThreadCount; t++) {
131-
pthread_join(threads[t], NULL);
134+
void* id;
135+
pthread_join(threads[t], &id);
136+
ids[t] = static_cast<int64_t*>(id)[0];
137+
free(id);
132138
};
133-
// Check the texture named from [1, threadCount].
134-
for (uint64_t t = 1; t <= kThreadCount; t++) {
135-
EXPECT_TRUE(fl_texture_registrar_lookup_texture(registrar, (int64_t)t) !=
136-
NULL);
139+
// Check all the textures were created.
140+
for (uint64_t t = 0; t < kThreadCount; t++) {
141+
EXPECT_TRUE(fl_texture_registrar_lookup_texture(registrar, ids[t]) != NULL);
137142
};
138143
}

0 commit comments

Comments
 (0)