Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux texture support #24916

Merged
merged 27 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
669e0b4
Linux texture support
huanghongxun Mar 11, 2021
d305ceb
Merge branch 'master' of https://github.com/flutter/engine into dev/t…
huanghongxun Mar 12, 2021
2774475
fix reference loop
huanghongxun Mar 12, 2021
7e5599d
Use g_clear_pointer
robert-ancell May 6, 2021
e603f73
Take a reference to the texture
robert-ancell May 6, 2021
2b88a31
Split FlPixelBufferTexture into its own module
robert-ancell May 6, 2021
eb9e75b
Add missing comment
robert-ancell May 6, 2021
e137a94
Add missing param check
robert-ancell May 6, 2021
c62c6f1
Fix memory management with texture registrar tests
robert-ancell May 6, 2021
6adb093
Remove callback and make FlPixelBufferTexture derivable
robert-ancell May 6, 2021
c4c7822
Add some comments
huanghongxun May 7, 2021
d545cc3
fix: format
huanghongxun May 7, 2021
13c8f2f
Merge branch 'master' of https://github.com/flutter/engine into dev/t…
huanghongxun May 10, 2021
50fd4ef
Add new file to licenses
robert-ancell May 12, 2021
150f012
Return correct texture ID
robert-ancell May 12, 2021
e31dfdd
Consistent boolean values
robert-ancell May 12, 2021
ef82943
Merge branch 'master' of https://github.com/flutter/engine into dev/t…
huanghongxun Jul 7, 2021
02e56b6
Make FlTexture more general
huanghongxun Jul 7, 2021
3fbd0c3
Fix: It should be assumed that the format of pixel buffer is RGBA.
huanghongxun Aug 20, 2021
034d281
Merge branch 'master' of https://github.com/flutter/engine into dev/t…
huanghongxun Aug 20, 2021
d0923e7
Include fl_texture_gl.h
huanghongxun Aug 23, 2021
bdff886
Merge branch 'master' of https://github.com/flutter/engine into dev/t…
huanghongxun Aug 23, 2021
877c9ad
Merge branch 'master' of https://github.com/flutter/engine into dev/t…
huanghongxun Sep 6, 2021
9ed4178
Add more detailed documentation
huanghongxun Sep 6, 2021
e801652
Remove concept of texture ID in the API.
huanghongxun Sep 13, 2021
84184ae
FlTexture should an interface
huanghongxun Sep 13, 2021
2f596ee
Merge branch 'master' of https://github.com/flutter/engine into dev/t…
huanghongxun Sep 13, 2021
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
8 changes: 8 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,12 @@ FILE: ../../../flutter/shell/platform/linux/fl_string_codec.cc
FILE: ../../../flutter/shell/platform/linux/fl_string_codec_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_text_input_plugin.cc
FILE: ../../../flutter/shell/platform/linux/fl_text_input_plugin.h
FILE: ../../../flutter/shell/platform/linux/fl_texture.cc
FILE: ../../../flutter/shell/platform/linux/fl_texture_private.h
FILE: ../../../flutter/shell/platform/linux/fl_texture_registrar.cc
FILE: ../../../flutter/shell/platform/linux/fl_texture_registrar_private.h
FILE: ../../../flutter/shell/platform/linux/fl_texture_registrar_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_texture_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_value.cc
FILE: ../../../flutter/shell/platform/linux/fl_value_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_view.cc
Expand All @@ -1472,6 +1478,8 @@ FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_plugin_regis
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_texture.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_texture_registrar.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_value.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/fl_view.h
FILE: ../../../flutter/shell/platform/linux/public/flutter_linux/flutter_linux.h
Expand Down
6 changes: 6 additions & 0 deletions shell/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ _public_headers = [
"public/flutter_linux/fl_standard_message_codec.h",
"public/flutter_linux/fl_standard_method_codec.h",
"public/flutter_linux/fl_string_codec.h",
"public/flutter_linux/fl_texture.h",
"public/flutter_linux/fl_texture_registrar.h",
"public/flutter_linux/fl_value.h",
"public/flutter_linux/fl_view.h",
"public/flutter_linux/flutter_linux.h",
Expand Down Expand Up @@ -115,6 +117,8 @@ source_set("flutter_linux_sources") {
"fl_standard_method_codec.cc",
"fl_string_codec.cc",
"fl_text_input_plugin.cc",
"fl_texture.cc",
"fl_texture_registrar.cc",
"fl_value.cc",
"fl_view.cc",
"fl_view_accessible.cc",
Expand Down Expand Up @@ -172,6 +176,8 @@ executable("flutter_linux_unittests") {
"fl_standard_message_codec_test.cc",
"fl_standard_method_codec_test.cc",
"fl_string_codec_test.cc",
"fl_texture_registrar_test.cc",
"fl_texture_test.cc",
"fl_value_test.cc",
"testing/fl_test.cc",
"testing/mock_engine.cc",
Expand Down
50 changes: 49 additions & 1 deletion shell/platform/linux/fl_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

#include <cstring>

#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
#include "flutter/shell/platform/linux/fl_dart_project_private.h"
#include "flutter/shell/platform/linux/fl_engine_private.h"
#include "flutter/shell/platform/linux/fl_plugin_registrar_private.h"
#include "flutter/shell/platform/linux/fl_renderer.h"
#include "flutter/shell/platform/linux/fl_renderer_headless.h"
#include "flutter/shell/platform/linux/fl_settings_plugin.h"
#include "flutter/shell/platform/linux/fl_texture_registrar_private.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registry.h"

static constexpr int kMicrosecondsPerNanosecond = 1000;
Expand All @@ -32,6 +34,7 @@ struct _FlEngine {
FlRenderer* renderer;
FlBinaryMessenger* binary_messenger;
FlSettingsPlugin* settings_plugin;
FlTextureRegistrar* texture_registrar;
FlutterEngineAOTData aot_data;
FLUTTER_API_SYMBOL(FlutterEngine) engine;
FlutterEngineProcTable embedder_api;
Expand Down Expand Up @@ -266,6 +269,21 @@ static bool fl_engine_gl_make_resource_current(void* user_data) {
return result;
}

// Called by the engine to retrieve an external texture.
static bool fl_engine_gl_external_texture_frame_callback(
void* user_data,
int64_t texture_id,
size_t width,
size_t height,
FlutterOpenGLTexture* texture) {
FlEngine* self = static_cast<FlEngine*>(user_data);
if (!self->texture_registrar) {
return false;
}
return fl_texture_registrar_populate_texture(
self->texture_registrar, texture_id, width, height, texture);
}

// Called by the engine to determine if it is on the GTK thread.
static bool fl_engine_runs_task_on_current_thread(void* user_data) {
FlEngine* self = static_cast<FlEngine*>(user_data);
Expand Down Expand Up @@ -336,7 +354,8 @@ static FlPluginRegistrar* fl_engine_get_registrar_for_plugin(
const gchar* name) {
FlEngine* self = FL_ENGINE(registry);

return fl_plugin_registrar_new(nullptr, self->binary_messenger);
return fl_plugin_registrar_new(nullptr, self->binary_messenger,
self->texture_registrar);
}

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

g_clear_object(&self->project);
g_clear_object(&self->renderer);
g_clear_object(&self->texture_registrar);
g_clear_object(&self->binary_messenger);
g_clear_object(&self->settings_plugin);

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

self->texture_registrar = fl_texture_registrar_new(self);
self->binary_messenger = fl_binary_messenger_new(self);
}

Expand Down Expand Up @@ -419,6 +440,8 @@ gboolean fl_engine_start(FlEngine* self, GError** error) {
config.open_gl.fbo_callback = fl_engine_gl_get_fbo;
config.open_gl.present = fl_engine_gl_present;
config.open_gl.make_resource_current = fl_engine_gl_make_resource_current;
config.open_gl.gl_external_texture_frame_callback =
fl_engine_gl_external_texture_frame_callback;

FlutterTaskRunnerDescription platform_task_runner = {};
platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
Expand Down Expand Up @@ -717,8 +740,33 @@ void fl_engine_dispatch_semantics_action(FlEngine* self,
action_data, action_data_length);
}

gboolean fl_engine_mark_texture_frame_available(FlEngine* self,
int64_t texture_id) {
g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
return self->embedder_api.MarkExternalTextureFrameAvailable(
self->engine, texture_id) == kSuccess;
}

gboolean fl_engine_register_external_texture(FlEngine* self,
int64_t texture_id) {
g_return_val_if_fail(FL_IS_ENGINE(self), FALSE);
return self->embedder_api.RegisterExternalTexture(self->engine, texture_id) ==
kSuccess;
}

void fl_engine_unregister_external_texture(FlEngine* self, int64_t texture_id) {
g_return_if_fail(FL_IS_ENGINE(self));
self->embedder_api.UnregisterExternalTexture(self->engine, texture_id);
}

G_MODULE_EXPORT FlBinaryMessenger* fl_engine_get_binary_messenger(
FlEngine* self) {
g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
return self->binary_messenger;
}

G_MODULE_EXPORT FlTextureRegistrar* fl_engine_get_texture_registrar(
FlEngine* self) {
g_return_val_if_fail(FL_IS_ENGINE(self), nullptr);
return self->texture_registrar;
}
36 changes: 36 additions & 0 deletions shell/platform/linux/fl_engine_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,42 @@ GBytes* fl_engine_send_platform_message_finish(FlEngine* engine,
GAsyncResult* result,
GError** error);

/**
* fl_engine_mark_texture_frame_available:
* @engine: an #FlEngine.
* @texture_id: the identifier of the texture whose frame has been updated.
*
* Tells the Flutter engine that a new texture frame is available for the given
* texture.
*
* Returns: %TRUE on success.
*/
gboolean fl_engine_mark_texture_frame_available(FlEngine* engine,
int64_t texture_id);

/**
* fl_engine_register_external_texture:
* @engine: an #FlEngine.
* @texture_id: the identifier of the texture that is available.
*
* Tells the Flutter engine that a new external texture is available.
*
* Returns: %TRUE on success.
*/
gboolean fl_engine_register_external_texture(FlEngine* engine,
int64_t texture_id);

/**
* fl_engine_unregister_external_texture:
* @engine: an #FlEngine.
* @texture_id: the identifier of the texture that is not available anymore.
*
* Tells the Flutter engine that an existing external texture is not available
* anymore.
*/
void fl_engine_unregister_external_texture(FlEngine* engine,
int64_t texture_id);

G_END_DECLS

#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_ENGINE_PRIVATE_H_
18 changes: 16 additions & 2 deletions shell/platform/linux/fl_plugin_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct _FlPluginRegistrar {

// Messenger to communicate on.
FlBinaryMessenger* messenger;

FlTextureRegistrar* texture_registrar;
robert-ancell marked this conversation as resolved.
Show resolved Hide resolved
};

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

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

static void fl_plugin_registrar_init(FlPluginRegistrar* self) {}

FlPluginRegistrar* fl_plugin_registrar_new(FlView* view,
FlBinaryMessenger* messenger) {
FlPluginRegistrar* fl_plugin_registrar_new(
FlView* view,
FlBinaryMessenger* messenger,
FlTextureRegistrar* texture_registrar) {
g_return_val_if_fail(view == nullptr || FL_IS_VIEW(view), nullptr);
g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
robert-ancell marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -55,6 +60,8 @@ FlPluginRegistrar* fl_plugin_registrar_new(FlView* view,
reinterpret_cast<gpointer*>(&(self->view)));
}
self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
self->texture_registrar =
FL_TEXTURE_REGISTRAR(g_object_ref(texture_registrar));

return self;
}
Expand All @@ -66,6 +73,13 @@ G_MODULE_EXPORT FlBinaryMessenger* fl_plugin_registrar_get_messenger(
return self->messenger;
}

G_MODULE_EXPORT FlTextureRegistrar* fl_plugin_registrar_get_texture_registrar(
FlPluginRegistrar* self) {
g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);

return self->texture_registrar;
}

G_MODULE_EXPORT FlView* fl_plugin_registrar_get_view(FlPluginRegistrar* self) {
g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);

Expand Down
7 changes: 5 additions & 2 deletions shell/platform/linux/fl_plugin_registrar_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ G_BEGIN_DECLS
* @view: (allow-none): the #FlView that is being plugged into or %NULL for
* headless mode.
* @messenger: the #FlBinaryMessenger to communicate with.
* @texture_registrar: the #FlTextureRegistrar to communicate with.
*
* Creates a new #FlPluginRegistrar.
*
* Returns: a new #FlPluginRegistrar.
*/
FlPluginRegistrar* fl_plugin_registrar_new(FlView* view,
FlBinaryMessenger* messenger);
FlPluginRegistrar* fl_plugin_registrar_new(
FlView* view,
FlBinaryMessenger* messenger,
FlTextureRegistrar* texture_registrar);

G_END_DECLS

Expand Down
Loading