Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a80f726

Browse files
authored
Revert "Windows: Texture Registrar: Destroy textures on raster thread (#33688)"
This reverts commit 90815e5.
1 parent bfddb61 commit a80f726

16 files changed

+57
-176
lines changed

shell/platform/common/client_wrapper/core_implementations.cc

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -195,32 +195,9 @@ bool TextureRegistrarImpl::MarkTextureFrameAvailable(int64_t texture_id) {
195195
texture_registrar_ref_, texture_id);
196196
}
197197

198-
void TextureRegistrarImpl::UnregisterTexture(int64_t texture_id,
199-
std::function<void()> callback) {
200-
if (callback == nullptr) {
201-
FlutterDesktopTextureRegistrarUnregisterExternalTexture(
202-
texture_registrar_ref_, texture_id, nullptr, nullptr);
203-
return;
204-
}
205-
206-
struct Captures {
207-
std::function<void()> callback;
208-
};
209-
auto captures = new Captures();
210-
captures->callback = std::move(callback);
211-
FlutterDesktopTextureRegistrarUnregisterExternalTexture(
212-
texture_registrar_ref_, texture_id,
213-
[](void* opaque) {
214-
auto captures = reinterpret_cast<Captures*>(opaque);
215-
captures->callback();
216-
delete captures;
217-
},
218-
captures);
219-
}
220-
221198
bool TextureRegistrarImpl::UnregisterTexture(int64_t texture_id) {
222-
UnregisterTexture(texture_id, nullptr);
223-
return true;
199+
return FlutterDesktopTextureRegistrarUnregisterExternalTexture(
200+
texture_registrar_ref_, texture_id);
224201
}
225202

226203
} // namespace flutter

shell/platform/common/client_wrapper/include/flutter/texture_registrar.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,8 @@ class TextureRegistrar {
9595
// the callback that was provided upon creating the texture.
9696
virtual bool MarkTextureFrameAvailable(int64_t texture_id) = 0;
9797

98-
// Asynchronously unregisters an existing texture object.
99-
// Upon completion, the optional |callback| gets invoked.
100-
virtual void UnregisterTexture(int64_t texture_id,
101-
std::function<void()> callback) = 0;
102-
103-
// Unregisters an existing texture object.
104-
// DEPRECATED: Use UnregisterTexture(texture_id, optional_callback) instead.
98+
// Unregisters an existing Texture object.
99+
// Textures must not be unregistered while they're in use.
105100
virtual bool UnregisterTexture(int64_t texture_id) = 0;
106101
};
107102

shell/platform/common/client_wrapper/testing/stub_flutter_api.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,15 @@ int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture(
109109
return result;
110110
}
111111

112-
void FlutterDesktopTextureRegistrarUnregisterExternalTexture(
112+
bool FlutterDesktopTextureRegistrarUnregisterExternalTexture(
113113
FlutterDesktopTextureRegistrarRef texture_registrar,
114-
int64_t texture_id,
115-
void (*callback)(void* user_data),
116-
void* user_data) {
114+
int64_t texture_id) {
115+
bool result = false;
117116
if (s_stub_implementation) {
118-
s_stub_implementation->TextureRegistrarUnregisterExternalTexture(
119-
texture_id, callback, user_data);
120-
} else if (callback) {
121-
callback(user_data);
117+
result = s_stub_implementation->TextureRegistrarUnregisterExternalTexture(
118+
texture_id);
122119
}
120+
return result;
123121
}
124122

125123
bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(

shell/platform/common/client_wrapper/testing/stub_flutter_api.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,18 @@ class StubFlutterApi {
6565
FlutterDesktopMessageCallback callback,
6666
void* user_data) {}
6767

68-
// Called for FlutterDesktopTextureRegistrarRegisterExternalTexture.
68+
// Called for FlutterDesktopRegisterExternalTexture.
6969
virtual int64_t TextureRegistrarRegisterExternalTexture(
7070
const FlutterDesktopTextureInfo* info) {
7171
return -1;
7272
}
7373

74-
// Called for FlutterDesktopTextureRegistrarUnregisterExternalTexture.
75-
virtual void TextureRegistrarUnregisterExternalTexture(
76-
int64_t texture_id,
77-
void (*callback)(void* user_data),
78-
void* user_data) {}
74+
// Called for FlutterDesktopUnregisterExternalTexture.
75+
virtual bool TextureRegistrarUnregisterExternalTexture(int64_t texture_id) {
76+
return false;
77+
}
7978

80-
// Called for FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable.
79+
// Called for FlutterDesktopMarkExternalTextureFrameAvailable.
8180
virtual bool TextureRegistrarMarkTextureFrameAvailable(int64_t texture_id) {
8281
return false;
8382
}

shell/platform/common/client_wrapper/texture_registrar_impl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ class TextureRegistrarImpl : public TextureRegistrar {
2727
// |flutter::TextureRegistrar|
2828
bool MarkTextureFrameAvailable(int64_t texture_id) override;
2929

30-
// |flutter::TextureRegistrar|
31-
void UnregisterTexture(int64_t texture_id,
32-
std::function<void()> callback) override;
33-
3430
// |flutter::TextureRegistrar|
3531
bool UnregisterTexture(int64_t texture_id) override;
3632

shell/platform/common/client_wrapper/texture_registrar_unittests.cc

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <memory>
99
#include <vector>
1010

11-
#include "flutter/fml/synchronization/waitable_event.h"
1211
#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
1312
#include "flutter/shell/platform/common/client_wrapper/testing/stub_flutter_api.h"
1413
#include "gtest/gtest.h"
@@ -42,17 +41,13 @@ class TestApi : public testing::StubFlutterApi {
4241
return last_texture_id_;
4342
}
4443

45-
void TextureRegistrarUnregisterExternalTexture(
46-
int64_t texture_id,
47-
void (*callback)(void* user_data),
48-
void* user_data) override {
44+
bool TextureRegistrarUnregisterExternalTexture(int64_t texture_id) override {
4945
auto it = textures_.find(texture_id);
5046
if (it != textures_.end()) {
5147
textures_.erase(it);
48+
return true;
5249
}
53-
if (callback) {
54-
callback(user_data);
55-
}
50+
return false;
5651
}
5752

5853
bool TextureRegistrarMarkTextureFrameAvailable(int64_t texture_id) override {
@@ -115,27 +110,24 @@ TEST(TextureRegistrarTest, RegisterUnregisterTexture) {
115110
EXPECT_TRUE(success);
116111
EXPECT_EQ(texture->mark_count, 3);
117112

118-
fml::AutoResetWaitableEvent unregister_latch;
119-
textures->UnregisterTexture(texture_id, [&]() { unregister_latch.Signal(); });
120-
unregister_latch.Wait();
113+
success = textures->UnregisterTexture(texture_id);
114+
EXPECT_TRUE(success);
121115

122116
texture = test_api->GetFakeTexture(texture_id);
123117
EXPECT_EQ(texture, nullptr);
124118
EXPECT_EQ(test_api->textures_size(), static_cast<size_t>(0));
125119
}
126120

127-
// Tests that the unregister callback gets also invoked when attempting to
128-
// unregister a texture with an unknown id.
121+
// Tests that unregistering a texture with an unknown id returns false.
129122
TEST(TextureRegistrarTest, UnregisterInvalidTexture) {
130123
auto dummy_registrar_handle =
131124
reinterpret_cast<FlutterDesktopPluginRegistrarRef>(1);
132125
PluginRegistrar registrar(dummy_registrar_handle);
133126

134127
TextureRegistrar* textures = registrar.texture_registrar();
135128

136-
fml::AutoResetWaitableEvent latch;
137-
textures->UnregisterTexture(42, [&]() { latch.Signal(); });
138-
latch.Wait();
129+
bool success = textures->UnregisterTexture(42);
130+
EXPECT_FALSE(success);
139131
}
140132

141133
// Tests that claiming a new frame being available for an unknown texture

shell/platform/common/public/flutter_texture_registrar.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,13 @@ FLUTTER_EXPORT int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture(
162162
FlutterDesktopTextureRegistrarRef texture_registrar,
163163
const FlutterDesktopTextureInfo* info);
164164

165-
// Asynchronously unregisters the texture identified by |texture_id| from the
166-
// Flutter engine.
167-
// An optional |callback| gets invoked upon completion.
165+
// Unregisters an existing texture from the Flutter engine for a |texture_id|.
166+
// Returns true on success or false if the specified texture doesn't exist.
168167
// This function can be called from any thread.
169-
FLUTTER_EXPORT void FlutterDesktopTextureRegistrarUnregisterExternalTexture(
168+
// However, textures must not be unregistered while they're in use.
169+
FLUTTER_EXPORT bool FlutterDesktopTextureRegistrarUnregisterExternalTexture(
170170
FlutterDesktopTextureRegistrarRef texture_registrar,
171-
int64_t texture_id,
172-
void (*callback)(void* user_data),
173-
void* user_data);
171+
int64_t texture_id);
174172

175173
// Marks that a new texture frame is available for a given |texture_id|.
176174
// Returns true on success or false if the specified texture doesn't exist.

shell/platform/glfw/flutter_glfw.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,10 @@ static void SetUpLocales(FlutterDesktopEngineState* state) {
728728
// Convert the locale list to the locale pointer list that must be provided.
729729
std::vector<const FlutterLocale*> flutter_locale_list;
730730
flutter_locale_list.reserve(flutter_locales.size());
731-
std::transform(flutter_locales.begin(), flutter_locales.end(),
732-
std::back_inserter(flutter_locale_list),
733-
[](const auto& arg) -> const auto* { return &arg; });
731+
std::transform(
732+
flutter_locales.begin(), flutter_locales.end(),
733+
std::back_inserter(flutter_locale_list),
734+
[](const auto& arg) -> const auto* { return &arg; });
734735
FlutterEngineResult result = FlutterEngineUpdateLocales(
735736
state->flutter_engine, flutter_locale_list.data(),
736737
flutter_locale_list.size());
@@ -1113,12 +1114,11 @@ int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture(
11131114
return -1;
11141115
}
11151116

1116-
void FlutterDesktopTextureRegistrarUnregisterExternalTexture(
1117+
bool FlutterDesktopTextureRegistrarUnregisterExternalTexture(
11171118
FlutterDesktopTextureRegistrarRef texture_registrar,
1118-
int64_t texture_id,
1119-
void (*callback)(void* user_data),
1120-
void* user_data) {
1119+
int64_t texture_id) {
11211120
std::cerr << "GLFW Texture support is not implemented yet." << std::endl;
1121+
return false;
11221122
}
11231123

11241124
bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(

shell/platform/windows/angle_surface_manager.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ EGLSurface AngleSurfaceManager::CreateSurfaceFromHandle(
301301
}
302302

303303
bool AngleSurfaceManager::GetDevice(ID3D11Device** device) {
304+
using Microsoft::WRL::ComPtr;
305+
304306
if (!resolved_device_) {
305307
PFNEGLQUERYDISPLAYATTRIBEXTPROC egl_query_display_attrib_EXT =
306308
reinterpret_cast<PFNEGLQUERYDISPLAYATTRIBEXTPROC>(

shell/platform/windows/flutter_windows.cc

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,11 @@ int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture(
302302
->RegisterTexture(texture_info);
303303
}
304304

305-
void FlutterDesktopTextureRegistrarUnregisterExternalTexture(
305+
bool FlutterDesktopTextureRegistrarUnregisterExternalTexture(
306306
FlutterDesktopTextureRegistrarRef texture_registrar,
307-
int64_t texture_id,
308-
void (*callback)(void* user_data),
309-
void* user_data) {
310-
auto registrar = TextureRegistrarFromHandle(texture_registrar);
311-
if (callback) {
312-
registrar->UnregisterTexture(
313-
texture_id, [callback, user_data]() { callback(user_data); });
314-
return;
315-
}
316-
registrar->UnregisterTexture(texture_id);
307+
int64_t texture_id) {
308+
return TextureRegistrarFromHandle(texture_registrar)
309+
->UnregisterTexture(texture_id);
317310
}
318311

319312
bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable(

shell/platform/windows/flutter_windows_engine.cc

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -557,26 +557,6 @@ bool FlutterWindowsEngine::MarkExternalTextureFrameAvailable(
557557
engine_, texture_id) == kSuccess);
558558
}
559559

560-
bool FlutterWindowsEngine::PostRasterThreadTask(fml::closure callback) {
561-
struct Captures {
562-
fml::closure callback;
563-
};
564-
auto captures = new Captures();
565-
captures->callback = std::move(callback);
566-
if (embedder_api_.PostRenderThreadTask(
567-
engine_,
568-
[](void* opaque) {
569-
auto captures = reinterpret_cast<Captures*>(opaque);
570-
captures->callback();
571-
delete captures;
572-
},
573-
captures) == kSuccess) {
574-
return true;
575-
}
576-
delete captures;
577-
return false;
578-
}
579-
580560
bool FlutterWindowsEngine::DispatchSemanticsAction(
581561
uint64_t target,
582562
FlutterSemanticsAction action,

shell/platform/windows/flutter_windows_engine.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ class FlutterWindowsEngine {
190190
// given |texture_id|.
191191
bool MarkExternalTextureFrameAvailable(int64_t texture_id);
192192

193-
// Posts the given callback onto the raster thread.
194-
bool PostRasterThreadTask(fml::closure callback);
195-
196193
// Invoke on the embedder's vsync callback to schedule a frame.
197194
void OnVsync(intptr_t baton);
198195

shell/platform/windows/flutter_windows_engine_unittests.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -446,21 +446,5 @@ TEST(FlutterWindowsEngine, UpdateHighContrastFeature) {
446446
EXPECT_FALSE(engine->high_contrast_enabled());
447447
}
448448

449-
TEST(FlutterWindowsEngine, PostRasterThreadTask) {
450-
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();
451-
EngineModifier modifier(engine.get());
452-
453-
modifier.embedder_api().PostRenderThreadTask = MOCK_ENGINE_PROC(
454-
PostRenderThreadTask, ([](auto engine, auto callback, auto context) {
455-
callback(context);
456-
return kSuccess;
457-
}));
458-
459-
bool called = false;
460-
engine->PostRasterThreadTask([&called]() { called = true; });
461-
462-
EXPECT_TRUE(called);
463-
}
464-
465449
} // namespace testing
466450
} // namespace flutter

shell/platform/windows/flutter_windows_texture_registrar.cc

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,20 @@ int64_t FlutterWindowsTextureRegistrar::EmplaceTexture(
7777
return texture_id;
7878
}
7979

80-
void FlutterWindowsTextureRegistrar::UnregisterTexture(int64_t texture_id,
81-
fml::closure callback) {
80+
bool FlutterWindowsTextureRegistrar::UnregisterTexture(int64_t texture_id) {
81+
{
82+
std::lock_guard<std::mutex> lock(map_mutex_);
83+
auto it = textures_.find(texture_id);
84+
if (it == textures_.end()) {
85+
return false;
86+
}
87+
textures_.erase(it);
88+
}
89+
8290
engine_->task_runner()->RunNowOrPostTask([engine = engine_, texture_id]() {
8391
engine->UnregisterExternalTexture(texture_id);
8492
});
85-
86-
bool posted = engine_->PostRasterThreadTask([this, texture_id, callback]() {
87-
{
88-
std::lock_guard<std::mutex> lock(map_mutex_);
89-
auto it = textures_.find(texture_id);
90-
if (it != textures_.end()) {
91-
textures_.erase(it);
92-
}
93-
}
94-
if (callback) {
95-
callback();
96-
}
97-
});
98-
99-
if (!posted && callback) {
100-
callback();
101-
}
93+
return true;
10294
}
10395

10496
bool FlutterWindowsTextureRegistrar::MarkTextureFrameAvailable(

shell/platform/windows/flutter_windows_texture_registrar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <mutex>
1010
#include <unordered_map>
1111

12-
#include "flutter/fml/closure.h"
1312
#include "flutter/shell/platform/common/public/flutter_texture_registrar.h"
1413
#include "flutter/shell/platform/windows/external_texture.h"
1514

@@ -29,7 +28,8 @@ class FlutterWindowsTextureRegistrar {
2928
int64_t RegisterTexture(const FlutterDesktopTextureInfo* texture_info);
3029

3130
// Attempts to unregister the texture identified by |texture_id|.
32-
void UnregisterTexture(int64_t texture_id, fml::closure callback = nullptr);
31+
// Returns true if the texture was successfully unregistered.
32+
bool UnregisterTexture(int64_t texture_id);
3333

3434
// Notifies the engine about a new frame being available.
3535
// Returns true on success.

0 commit comments

Comments
 (0)