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

Implement PlatformView support on Linux #41724

Open
stuartmorgan opened this issue Oct 1, 2019 · 23 comments
Open

Implement PlatformView support on Linux #41724

stuartmorgan opened this issue Oct 1, 2019 · 23 comments
Labels
a: desktop Running on desktop c: new feature Nothing broken; request for a new capability customer: crowd Affects or could affect many people, though not necessarily a specific customer. P2 Important issues not at the top of the work list platform-linux Building on or for Linux specifically team-desktop Owned by Desktop platforms team triaged-desktop Triaged by Desktop platforms team

Comments

@stuartmorgan
Copy link
Contributor

stuartmorgan commented Oct 1, 2019

We'll want to support embedding native views in a Flutter view, as is currently supported on mobile.

This is of course blocked on #30729 since until we have a view-based toolkit implementation for Linux, there's no concept of a "view" to embed.

@stuartmorgan stuartmorgan added c: new feature Nothing broken; request for a new capability platform-linux Building on or for Linux specifically a: desktop Running on desktop labels Oct 1, 2019
@handicraftsman
Copy link

It will be hard to do with GTK, because it wants access to X/Wayland server through GDK. So you cannot simply make an opengl context to render GTK there.

Qt seems to work in custom opengl contexts, although i never used that.

@handicraftsman

This comment has been minimized.

@stuartmorgan stuartmorgan added the P2 Important issues not at the top of the work list label Jun 9, 2020
@jeanluc243

This comment has been minimized.

@stuartmorgan
Copy link
Contributor Author

@jeanluc243 You're looking for #41726; this issue is about platform view support in general.

@stuartmorgan
Copy link
Contributor Author

So you cannot simply make an opengl context to render GTK there.

The goal of PlatformView is not to render GTK controls into a texture, it's to embed actual GTK views.

@NicholasHwang

This comment was marked as off-topic.

@nmcain

This comment was marked as off-topic.

@stuartmorgan
Copy link
Contributor Author

If there were updates, they would have been posted here. Please see https://github.com/flutter/flutter/wiki/Issue-hygiene#when-will-my-bug-be-fixed

If a bug has no assignee or milestone, pinging for updates is not constructive; it just spams people subscribed to the issue.

@cosmotek
Copy link

cosmotek commented Dec 3, 2020

Where would one find resources to learn more about how flutter integrates with native things? I'd love to help and I have some mild experience with OpenGL, but none with Skia....

@cosmotek
Copy link

cosmotek commented Dec 3, 2020

I'm thinking if I can get an OpenGL context to render in, I could get a video player working easily.

@stuartmorgan
Copy link
Contributor Author

Where would one find resources to learn more about how flutter integrates with native things?

The source for the Linux embedding is at https://github.com/flutter/engine/tree/master/shell/platform/linux. I'm not sure if that's what you mean by "integrates with native things".

I'd love to help and I have some mild experience with OpenGL, but none with Skia....

I wouldn't expect implementing PlatformView support in a desktop embedding to involve Skia.

@maks
Copy link

maks commented Jan 31, 2022

Thank you @huanghongxun for doing the work on this.
It was a bit confusing to go through all the opened-closed PRs but from what I can tell both #74814 and flutter/engine#26288 need to land in order for platform views to be available on Linux, is that correct?

@vinman1
Copy link

vinman1 commented Mar 18, 2023

If I've correctly understood this issue's activity, it was pretty close to landing with #74814 and flutter/engine#26288 before it was decided to do some API consolidation.

A Linux PlatformView is still very relevant. Just wondering if now would be a good time to revive this issue and possibly those PRs? Because some time has now passed since that decision was taken.

@maks
Copy link

maks commented Mar 18, 2023

@cbracken there weren't any issues linked in your comments on that linked prwhere the MacOS work you were doing is, would you have a pointer to issues to subscribe to to track that work?

@noelex
Copy link

noelex commented Jun 22, 2023

Given that flutter/engine#39473 has been merged, which means that approaches like flutter/engine#26288 won't work any more.

So I guess the only option left for us is to do off-screen rendering for the platform view (via GtkOffscreenWindow or whatever), and present it with a FlTextureGL?😅

@stuartmorgan
Copy link
Contributor Author

Off-screen rendering has had significant drawbacks on other platforms. I'm not familiar with the context of the simplification PR above, but on other platforms we do on-demand separation of Flutter content into multiple layers in the specific case of showing platform views, and it's likely that we will want to (re-?)introduce whatever structure is needed to make that possible as part of implementing platform view support. It looks like part of the issue being resolved there was the existence of complexity without a use case, which wouldn't be the case once there's concrete platform view support in progress.

@noelex
Copy link

noelex commented Jun 25, 2023

I tried reverting those PRs and merged flutter/engine#26288 into 3.10.5 and managed to get WebKit2.WebView working with Flutter.

But I noticed a serious performance issue with this approach. That is the application runs at extremely low frame rate (10 fps-ish on my laptop) when the WebView renders at high frame rate (60 fps), most likely due to this:

I once read that somewhere: when adding widgets on top of a GtkGLArea, e.g. using a GtkOverlay, GTK resorts to read back the frame buffer from GPU to CPU in order to correctly blend GL content with Cairo content.

I can also confirm the issue by using the stable branch of Flutter without using the platform view, and simply place the WebView onto Flutter's GtkGLArea by using GtkOverlay.

Although I can't find a source supporting this statement. But if it's true, I think this will have to be addressed in order to implement platform view support on Linux.

Several options I can think of:

  • Render to GtkGLArea directly via FlTextureGL. Not a general solution as the widget being embedded must support rendering to external textures.
  • Off-screen rendering. Not really a solution, as GPU-CPU-GPU (hardware rendering) or at least CPU-GPU (software rendering) copy will still occur.
  • Switch to GTK 4. This would be the ultimate solution but I don't think that's happenning in the short term.

For my specific scenario, the only way to go fo now, is to put the WebView into a separate toplevel GtkWindow and make it 'appears' like embeded into the Flutter application, which is rather fragile, and unpleasant.

@flutter-triage-bot flutter-triage-bot bot added team-desktop Owned by Desktop platforms team triaged-desktop Triaged by Desktop platforms team labels Jul 7, 2023
@noelex
Copy link

noelex commented Oct 13, 2023

For anyone who's still looking for a pratical and performant workaround for embedding platform views, if you're not limited to GTK, please take a look at Qt's QQuickRenderControl, which allows you to render Qt scenegraphs to any external texture, be it OpenGL, Vulkan, Metal, or Direct 3D.

My Linux Flutter app finally gets its properly functioning webview.

@leisu1
Copy link

leisu1 commented Oct 19, 2023

For anyone who's still looking for a pratical and performant workaround for embedding platform views, if you're not limited to GTK, please take a look at Qt's QQuickRenderControl, which allows you to render Qt scenegraphs to any external texture, be it OpenGL, Vulkan, Metal, or Direct 3D.

My Linux Flutter app finally gets its properly functioning webview.

Hello! I am writing a PC cross-platform software with flutter, which has a lot of webview applications. I'm totally unfamiliar with both qt and gtk. Is there a demo or some information about your solution? Thank you very much

@noelex
Copy link

noelex commented Oct 19, 2023

@leisu1 You'll need to write a native plugin to embed Qt's webview into a Flutter application. This can be done with the following steps:

  1. Retrieve Flutter's OpenGL context via GTK or GLX/EGL, call it context A.
  2. Spin up a QGuiApplication in a separate thread and create a OpenGL context, B, which shares resources with context A.
  3. Setup a QQuickView with a QQuickRenderControl which contains a single WebEngineView, and instruct the view to render using context B.
  4. When FlTextureGL wants to populate a texture, create an OpenGL texture with context B and ask the QQuickView to render into this texture.
  5. Flutter renders the texture containing the webview in your application.

Some useful links:

@stuartmorgan
Copy link
Contributor Author

Please use another forum for any detailed discussion of alternate approaches to rendering content; see https://github.com/flutter/flutter/wiki/Issue-hygiene#comments-providing-workarounds

@PearlByte

This comment was marked as off-topic.

@PearlByte

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: desktop Running on desktop c: new feature Nothing broken; request for a new capability customer: crowd Affects or could affect many people, though not necessarily a specific customer. P2 Important issues not at the top of the work list platform-linux Building on or for Linux specifically team-desktop Owned by Desktop platforms team triaged-desktop Triaged by Desktop platforms team
Projects
None yet
Development

Successfully merging a pull request may close this issue.