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

Commit 669e0b4

Browse files
committed
Linux texture support
1 parent 56b9057 commit 669e0b4

20 files changed

+819
-7
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,12 @@ FILE: ../../../flutter/shell/platform/linux/fl_string_codec.cc
14481448
FILE: ../../../flutter/shell/platform/linux/fl_string_codec_test.cc
14491449
FILE: ../../../flutter/shell/platform/linux/fl_text_input_plugin.cc
14501450
FILE: ../../../flutter/shell/platform/linux/fl_text_input_plugin.h
1451+
FILE: ../../../flutter/shell/platform/linux/fl_texture.cc
1452+
FILE: ../../../flutter/shell/platform/linux/fl_texture_private.h
1453+
FILE: ../../../flutter/shell/platform/linux/fl_texture_registrar.cc
1454+
FILE: ../../../flutter/shell/platform/linux/fl_texture_registrar_private.h
1455+
FILE: ../../../flutter/shell/platform/linux/fl_texture_registrar_test.cc
1456+
FILE: ../../../flutter/shell/platform/linux/fl_texture_test.cc
14511457
FILE: ../../../flutter/shell/platform/linux/fl_value.cc
14521458
FILE: ../../../flutter/shell/platform/linux/fl_value_test.cc
14531459
FILE: ../../../flutter/shell/platform/linux/fl_view.cc
@@ -1472,6 +1478,8 @@ FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_plugin_regis
14721478
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h
14731479
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h
14741480
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h
1481+
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_texture.h
1482+
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_texture_registrar.h
14751483
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_value.h
14761484
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_view.h
14771485
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/flutter_linux.h

shell/platform/linux/BUILD.gn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ _public_headers = [
6060
"public/flutter_linux/fl_standard_message_codec.h",
6161
"public/flutter_linux/fl_standard_method_codec.h",
6262
"public/flutter_linux/fl_string_codec.h",
63+
"public/flutter_linux/fl_texture.h",
64+
"public/flutter_linux/fl_texture_registrar.h",
6365
"public/flutter_linux/fl_value.h",
6466
"public/flutter_linux/fl_view.h",
6567
"public/flutter_linux/flutter_linux.h",
@@ -115,6 +117,8 @@ source_set("flutter_linux_sources") {
115117
"fl_standard_method_codec.cc",
116118
"fl_string_codec.cc",
117119
"fl_text_input_plugin.cc",
120+
"fl_texture.cc",
121+
"fl_texture_registrar.cc",
118122
"fl_value.cc",
119123
"fl_view.cc",
120124
"fl_view_accessible.cc",
@@ -172,6 +176,8 @@ executable("flutter_linux_unittests") {
172176
"fl_standard_message_codec_test.cc",
173177
"fl_standard_method_codec_test.cc",
174178
"fl_string_codec_test.cc",
179+
"fl_texture_registrar_test.cc",
180+
"fl_texture_test.cc",
175181
"fl_value_test.cc",
176182
"testing/fl_test.cc",
177183
"testing/mock_engine.cc",

shell/platform/linux/fl_engine.cc

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88

99
#include <cstring>
1010

11+
#include "flutter/shell/platform/embedder/embedder.h"
1112
#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
1213
#include "flutter/shell/platform/linux/fl_dart_project_private.h"
1314
#include "flutter/shell/platform/linux/fl_engine_private.h"
1415
#include "flutter/shell/platform/linux/fl_plugin_registrar_private.h"
1516
#include "flutter/shell/platform/linux/fl_renderer.h"
1617
#include "flutter/shell/platform/linux/fl_renderer_headless.h"
1718
#include "flutter/shell/platform/linux/fl_settings_plugin.h"
19+
#include "flutter/shell/platform/linux/fl_texture_registrar_private.h"
1820
#include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registry.h"
1921

2022
static constexpr int kMicrosecondsPerNanosecond = 1000;
@@ -32,6 +34,7 @@ struct _FlEngine {
3234
FlRenderer* renderer;
3335
FlBinaryMessenger* binary_messenger;
3436
FlSettingsPlugin* settings_plugin;
37+
FlTextureRegistrar* texture_registrar;
3538
FlutterEngineAOTData aot_data;
3639
FLUTTER_API_SYMBOL(FlutterEngine) engine;
3740
FlutterEngineProcTable embedder_api;
@@ -266,6 +269,21 @@ static bool fl_engine_gl_make_resource_current(void* user_data) {
266269
return result;
267270
}
268271

272+
// Called by the engine to retrieve an external texture.
273+
static bool fl_engine_gl_external_texture_frame_callback(
274+
void* user_data,
275+
int64_t texture_id,
276+
size_t width,
277+
size_t height,
278+
FlutterOpenGLTexture* texture) {
279+
FlEngine* self = static_cast<FlEngine*>(user_data);
280+
if (!self->texture_registrar) {
281+
return false;
282+
}
283+
return fl_texture_registrar_populate_texture(
284+
self->texture_registrar, texture_id, width, height, texture);
285+
}
286+
269287
// Called by the engine to determine if it is on the GTK thread.
270288
static bool fl_engine_runs_task_on_current_thread(void* user_data) {
271289
FlEngine* self = static_cast<FlEngine*>(user_data);
@@ -336,7 +354,8 @@ static FlPluginRegistrar* fl_engine_get_registrar_for_plugin(
336354
const gchar* name) {
337355
FlEngine* self = FL_ENGINE(registry);
338356

339-
return fl_plugin_registrar_new(nullptr, self->binary_messenger);
357+
return fl_plugin_registrar_new(nullptr, self->binary_messenger,
358+
self->texture_registrar);
340359
}
341360

342361
static void fl_engine_plugin_registry_iface_init(
@@ -359,6 +378,7 @@ static void fl_engine_dispose(GObject* object) {
359378

360379
g_clear_object(&self->project);
361380
g_clear_object(&self->renderer);
381+
g_clear_object(&self->texture_registrar);
362382
g_clear_object(&self->binary_messenger);
363383
g_clear_object(&self->settings_plugin);
364384

@@ -389,6 +409,7 @@ static void fl_engine_init(FlEngine* self) {
389409
self->embedder_api.struct_size = sizeof(FlutterEngineProcTable);
390410
FlutterEngineGetProcAddresses(&self->embedder_api);
391411

412+
self->texture_registrar = fl_texture_registrar_new(self);
392413
self->binary_messenger = fl_binary_messenger_new(self);
393414
}
394415

@@ -419,6 +440,8 @@ gboolean fl_engine_start(FlEngine* self, GError** error) {
419440
config.open_gl.fbo_callback = fl_engine_gl_get_fbo;
420441
config.open_gl.present = fl_engine_gl_present;
421442
config.open_gl.make_resource_current = fl_engine_gl_make_resource_current;
443+
config.open_gl.gl_external_texture_frame_callback =
444+
fl_engine_gl_external_texture_frame_callback;
422445

423446
FlutterTaskRunnerDescription platform_task_runner = {};
424447
platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
@@ -717,8 +740,33 @@ void fl_engine_dispatch_semantics_action(FlEngine* self,
717740
action_data, action_data_length);
718741
}
719742

743+
gboolean fl_engine_mark_texture_frame_available(FlEngine* self,
744+
int64_t texture_id) {
745+
g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
746+
return self->embedder_api.MarkExternalTextureFrameAvailable(
747+
self->engine, texture_id) == kSuccess;
748+
}
749+
750+
gboolean fl_engine_register_external_texture(FlEngine* self,
751+
int64_t texture_id) {
752+
g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
753+
return self->embedder_api.RegisterExternalTexture(self->engine, texture_id) ==
754+
kSuccess;
755+
}
756+
757+
void fl_engine_unregister_external_texture(FlEngine* self, int64_t texture_id) {
758+
g_return_if_fail(FL_IS_ENGINE(self));
759+
self->embedder_api.UnregisterExternalTexture(self->engine, texture_id);
760+
}
761+
720762
G_MODULE_EXPORT FlBinaryMessenger* fl_engine_get_binary_messenger(
721763
FlEngine* self) {
722764
g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
723765
return self->binary_messenger;
724766
}
767+
768+
G_MODULE_EXPORT FlTextureRegistrar* fl_engine_get_texture_registrar(
769+
FlEngine* self) {
770+
g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
771+
return self->texture_registrar;
772+
}

shell/platform/linux/fl_engine_private.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,42 @@ GBytes* fl_engine_send_platform_message_finish(FlEngine* engine,
226226
GAsyncResult* result,
227227
GError** error);
228228

229+
/**
230+
* fl_engine_mark_texture_frame_available:
231+
* @engine: an #FlEngine.
232+
* @texture_id: the identifier of the texture whose frame has been updated.
233+
*
234+
* Tells the Flutter engine that a new texture frame is available for the given
235+
* texture.
236+
*
237+
* Returns: %TRUE on success.
238+
*/
239+
gboolean fl_engine_mark_texture_frame_available(FlEngine* engine,
240+
int64_t texture_id);
241+
242+
/**
243+
* fl_engine_register_external_texture:
244+
* @engine: an #FlEngine.
245+
* @texture_id: the identifier of the texture that is available.
246+
*
247+
* Tells the Flutter engine that a new external texture is available.
248+
*
249+
* Returns: %TRUE on success.
250+
*/
251+
gboolean fl_engine_register_external_texture(FlEngine* engine,
252+
int64_t texture_id);
253+
254+
/**
255+
* fl_engine_unregister_external_texture:
256+
* @engine: an #FlEngine.
257+
* @texture_id: the identifier of the texture that is not available anymore.
258+
*
259+
* Tells the Flutter engine that an existing external texture is not available
260+
* anymore.
261+
*/
262+
void fl_engine_unregister_external_texture(FlEngine* engine,
263+
int64_t texture_id);
264+
229265
G_END_DECLS
230266

231267
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_ENGINE_PRIVATE_H_

shell/platform/linux/fl_plugin_registrar.cc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ struct _FlPluginRegistrar {
1515

1616
// Messenger to communicate on.
1717
FlBinaryMessenger* messenger;
18+
19+
FlTextureRegistrar* texture_registrar;
1820
};
1921

2022
// Added here to stop the compiler from optimizing this function away.
@@ -31,6 +33,7 @@ static void fl_plugin_registrar_dispose(GObject* object) {
3133
self->view = nullptr;
3234
}
3335
g_clear_object(&self->messenger);
36+
g_clear_object(&self->texture_registrar);
3437

3538
G_OBJECT_CLASS(fl_plugin_registrar_parent_class)->dispose(object);
3639
}
@@ -41,8 +44,10 @@ static void fl_plugin_registrar_class_init(FlPluginRegistrarClass* klass) {
4144

4245
static void fl_plugin_registrar_init(FlPluginRegistrar* self) {}
4346

44-
FlPluginRegistrar* fl_plugin_registrar_new(FlView* view,
45-
FlBinaryMessenger* messenger) {
47+
FlPluginRegistrar* fl_plugin_registrar_new(
48+
FlView* view,
49+
FlBinaryMessenger* messenger,
50+
FlTextureRegistrar* texture_registrar) {
4651
g_return_val_if_fail(view == nullptr || FL_IS_VIEW(view), nullptr);
4752
g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
4853

@@ -55,6 +60,8 @@ FlPluginRegistrar* fl_plugin_registrar_new(FlView* view,
5560
reinterpret_cast<gpointer*>(&(self->view)));
5661
}
5762
self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
63+
self->texture_registrar =
64+
FL_TEXTURE_REGISTRAR(g_object_ref(texture_registrar));
5865

5966
return self;
6067
}
@@ -66,6 +73,13 @@ G_MODULE_EXPORT FlBinaryMessenger* fl_plugin_registrar_get_messenger(
6673
return self->messenger;
6774
}
6875

76+
G_MODULE_EXPORT FlTextureRegistrar* fl_plugin_registrar_get_texture_registrar(
77+
FlPluginRegistrar* self) {
78+
g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
79+
80+
return self->texture_registrar;
81+
}
82+
6983
G_MODULE_EXPORT FlView* fl_plugin_registrar_get_view(FlPluginRegistrar* self) {
7084
g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
7185

shell/platform/linux/fl_plugin_registrar_private.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ G_BEGIN_DECLS
1515
* @view: (allow-none): the #FlView that is being plugged into or %NULL for
1616
* headless mode.
1717
* @messenger: the #FlBinaryMessenger to communicate with.
18+
* @texture_registrar: the #FlTextureRegistrar to communicate with.
1819
*
1920
* Creates a new #FlPluginRegistrar.
2021
*
2122
* Returns: a new #FlPluginRegistrar.
2223
*/
23-
FlPluginRegistrar* fl_plugin_registrar_new(FlView* view,
24-
FlBinaryMessenger* messenger);
24+
FlPluginRegistrar* fl_plugin_registrar_new(
25+
FlView* view,
26+
FlBinaryMessenger* messenger,
27+
FlTextureRegistrar* texture_registrar);
2528

2629
G_END_DECLS
2730

0 commit comments

Comments
 (0)