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 #20714

Closed
wants to merge 8 commits into from
Closed

Conversation

anirudhb
Copy link
Contributor

@anirudhb anirudhb commented Aug 22, 2020

Description

Add support for external textures to the Linux platform shell.

Related Issues

Fixes flutter/flutter#64188.

Tests

I added the following tests:

  • Tests for FlTextureRegistrar
  • Tests for FlExternalTextureGl

Checklist

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@pingbird
Copy link
Member

@anirudhb
Copy link
Contributor Author

Fixed!

@stuartmorgan
Copy link
Contributor

Filed flutter/flutter#64576 for the lint issue; we'll figure out the plan to resolve the unrelated issues there. I'll review the rest for functionality now.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a high level, the structure matches the other desktop platforms, so that part looks good. I'll defer to @robert-ancell on most of the detailed review since I'm still not fluent enough in reading GObject code to feel like I would catch bugs there.

I left some some nits and comments though.

As for tests, at the very least the new classes should all have tests; while the current situation is uneven, the goal is to improve the level of coverage, not regress it. There are examples of tests already; are there specific questions you have about how to test the new classes?

shell/platform/linux/fl_engine.cc Outdated Show resolved Hide resolved
shell/platform/linux/fl_engine.cc Outdated Show resolved Hide resolved
shell/platform/linux/fl_engine.cc Outdated Show resolved Hide resolved
shell/platform/linux/fl_external_texture_gl.cc Outdated Show resolved Hide resolved
shell/platform/linux/fl_external_texture_gl.cc Outdated Show resolved Hide resolved
shell/platform/linux/fl_external_texture_gl.h Show resolved Hide resolved
shell/platform/linux/fl_texture_registrar.cc Show resolved Hide resolved
shell/platform/linux/fl_texture_registrar.cc Outdated Show resolved Hide resolved
@anirudhb
Copy link
Contributor Author

anirudhb commented Aug 27, 2020

@stuartmorgan Resolved nits and added partial tests. I've rolled back the changes that don't touch my code (linting fixes), as you've filed an issue for that. Re-review?

Also addresses nits from code review.
Testing will be complete once I figure out how to stub
`eglGetProcAddress` in the tests.
@stuartmorgan
Copy link
Contributor

Filed flutter/flutter#64576 for the lint issue; we'll figure out the plan to resolve the unrelated issues there.

Based on flutter/flutter#64576, the solution for now should be to add // FLUTTER_NOLINT just after the license header. It's unclear how the file ended up not having it already, but you can just add it to this PR.

@stuartmorgan stuartmorgan self-requested a review August 31, 2020 19:10
@stuartmorgan
Copy link
Contributor

In the future, please don't force-push to in-review PRs. It removes the ability to use very helpful review features like seeing everything that changed since the last review.

shell/platform/linux/BUILD.gn Show resolved Hide resolved
shell/platform/linux/testing/fl_test.cc Outdated Show resolved Hide resolved
shell/platform/linux/testing/fl_test.h Outdated Show resolved Hide resolved
shell/platform/linux/fl_external_texture_gl.cc Outdated Show resolved Hide resolved
shell/platform/linux/fl_external_texture_gl.cc Outdated Show resolved Hide resolved
shell/platform/linux/fl_texture_registrar_test.cc Outdated Show resolved Hide resolved
shell/platform/linux/fl_texture_registrar_test.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@robert-ancell robert-ancell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

@anirudhb
Copy link
Contributor Author

anirudhb commented Sep 5, 2020

I've addressed nits. Finished tests as well by changing the mock implementation in mock_egl.cc.

I ended up taking the approach that @robert-ancell suggested and removed the FlPixelBuffer type in favor of inout parameters to the callback directly.

@flar flar removed their request for review September 7, 2020 01:03
@stuartmorgan
Copy link
Contributor

The conversation starting here is relevant to this PR as well; we should address them the same way, ideally.

@anirudhb
Copy link
Contributor Author

anirudhb commented Sep 8, 2020

I've read that conversation, and my personal thinking is that this initial functionality is worth merging, then we can handle more efficient texture handoff later. Like Windows, Linux doesn't have any graphics API-independent way to hand off textures so I think this is the best way for now, since it abstracts that functionality from the user.

@stuartmorgan
Copy link
Contributor

this initial functionality is worth merging, then we can handle more efficient texture handoff later

As I explained there, it's important that enough thought is given to things like API names in this version that the more efficient version(s) can be added later without it being a breaking change (or being stuck with confusing APIs where there are 2+ variants, but one of them has a confusingly generic name).

Copy link
Contributor Author

@anirudhb anirudhb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stuartmorgan I've left some notes on what I think could be a way to make this API more agnostic of the underlying texture backend. Please comment any thoughts or nits you may have on this design.

Comment on lines +83 to +86
gboolean fl_external_texture_gl_copy_pixel_buffer(
FlExternalTextureGl* external_texture,
size_t* width,
size_t* height);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think renaming this to fl_external_texture_gl_prepare would be more fitting if we wanted to make it agnostic. This should also be a part of the FlExternalTexture interface.

Comment on lines +21 to +25
/**
* FlExternalTextureGl:
*
* #FlExternalTextureGl is an abstraction over OpenGL textures.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On making this agnostic-- It could be better if this inherited from a base type FlExternalTexture, and the texture registrar would handle those instead of FlExternalTextureGl.

Comment on lines +67 to +68
int64_t fl_external_texture_gl_texture_id(
FlExternalTextureGl* external_texture);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be a part of the interface as well. Since each subclass of FlExternalTexture should represent one graphics API's textures, ids shouldn't be overlapping.

Comment on lines +54 to +58
gboolean fl_external_texture_gl_populate_texture(
FlExternalTextureGl* external_texture,
size_t width,
size_t height,
FlutterOpenGLTexture* opengl_texture);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be part of the interface, but maybe swapping FlutterOpenGLTexture* for a void* since each subclass will want a different texture type. Keeping this out of the interface doesn't make sense since every subclass will have to do this at some point. This could also be renamed to fl_external_texture_gl_prepare_for_embedder, but that's a bit more verbose.

Comment on lines +36 to +38
FlExternalTextureGl* fl_external_texture_gl_new(
FlTextureCallback texture_callback,
void* user_data);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should definitely be part of the interface but not sure how to make it generic based on FlTextureCallback returning different values. One way would be to change the output buffer of FlTextureCallback to a void*, then the subclass defines what is supposed to be output.

Comment on lines +37 to +42
bool fl_texture_registrar_populate_texture(
FlTextureRegistrar* registrar,
int64_t texture_id,
size_t width,
size_t height,
FlutterOpenGLTexture* opengl_texture);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, the FlutterOpenGLTexture should be changed to a void*.

*/
typedef gboolean (*FlTextureCallback)(size_t* width,
size_t* height,
const uint8_t** buffer,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be better redefined as void* out, so it is agnostic of the underlying output and can therefore be safely passed to all FlExternalTexture subclasses.

Comment on lines +37 to +41
/**
* FlTextureRegistrar:
*
* #FlTextureRegistrar is used when registering textures.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally, the FlTextureRegistrar hashmap should be managing FlExternalTextures not their subclasses.

Comment on lines +53 to +56
int64_t fl_texture_registrar_register_texture(
FlTextureRegistrar* registrar,
FlTextureCallback texture_callback,
void* user_data);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On making this agnostic-- it might make sense to make an enum here to differentiate which type of texture is being registered (i.e. OpenGL, Vulkan or Pixel Buffer which should be agnostic). Then the texture registrar would instantiate the respective underlying FlExternalTexture subclass. Managing Pixel Buffer callbacks could be done by the texture registrar itself, maybe by simply wrapping it with another callback.

@@ -39,3 +48,14 @@ gchar* bytes_to_hex_string(GBytes* bytes) {
g_string_append_printf(hex_string, "%02x", data[i]);
return g_string_free(hex_string, FALSE);
}

FlEngine* make_mock_engine() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you split this change out into a separate PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a number of cases where this could be common.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, #21585.

@stuartmorgan
Copy link
Contributor

@stuartmorgan I've left some notes on what I think could be a way to make this API more agnostic of the underlying texture backend. Please comment any thoughts or nits you may have on this design.

Some of #19405 (review) (the C API layer part) is relevant here.

You've suggested void* in several places; that's a solution of absolute last resort because it means we're no longer providing any type safety for that portion of the API. I don't see any fundamental reason that a discriminated-union-style approach, just as is used for the embedder.h texture API, couldn't be used here to allow for a set of possible textures (this would stand in for the std::variant at the C++ wrapper layer in my comments on the Windows version).

Or maybe there's something that's a higher-level std::variant-like tool in GObject that would be useful instead of a discriminated union? @robert-ancell ?

@chinmaygarde
Copy link
Member

From PR triage, is there any progress being made on this PR? If not, can we close this as it looks stale (last update 21 days ago).

@anirudhb
Copy link
Contributor Author

I do plan to make progress on this PR, but I'm waiting on #21585 being merged first to avoid conflicts. Additionally, this and #19405 both seem to be stalled on working out a proper API design, so it would be nice to keep it consistent across both platforms.

@chinmaygarde chinmaygarde added the Work in progress (WIP) Not ready (yet) for review! label Oct 23, 2020
@stuartmorgan
Copy link
Contributor

Additionally, this and #19405 both seem to be stalled on working out a proper API design

I outlined a path forward in 19405 for the API.

@anirudhb anirudhb marked this pull request as draft November 12, 2020 16:46
@anirudhb
Copy link
Contributor Author

Looks like this PR will need quite a bit of refactoring to pass review again. I don't think I'll have time for the next month or so, so I've left this as a draft for now. I am definitely still interested in adding support, and will undraft the PR when I feel it's ready :)

@chinmaygarde
Copy link
Member

Looks like progress on this has stalled. Closing it for now. Please re-open when needed.

@dnsoumik
Copy link

dnsoumik commented Mar 9, 2021

This needs to re-Open lots of things depend on this one,
Can anyone tell me when this request will be merged?

@stuartmorgan
Copy link
Contributor

Please read the recent comments; it's not ready for final review yet, so can't be merged as-is.

@huanghongxun
Copy link
Contributor

I have redesigned API and resubmit this PR #24916.
Please have a look.

@stuartmorgan stuartmorgan mentioned this pull request Mar 10, 2021
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Work in progress (WIP) Not ready (yet) for review!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Texture widget in Linux embedding
8 participants