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

Off-screen rendering with webview2 #547

Open
ajaymonga opened this issue Oct 20, 2020 · 122 comments
Open

Off-screen rendering with webview2 #547

ajaymonga opened this issue Oct 20, 2020 · 122 comments
Assignees
Labels
feature request feature request tracked We are tracking this work internally.

Comments

@ajaymonga
Copy link

ajaymonga commented Oct 20, 2020

Hi
Is it possible to get webview2 to render into a shared memory region like CEF :
https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage#markdown-header-off-screen-rendering

In my application I use 2 process architecture where main process does not have network access and second process uses CEF to render webcontent into a shared memory region from where main app can read the pixels. I am wondering if I can achieve this using webview2

Thanks

AB#28491736

@champnic
Copy link
Member

Currently this is not possible. We have offscreen rendering on our backlog, and are tracking it in #20, but I think this ask is clearer so I'll also add this issue to our item. Thanks!

@Harvey3141
Copy link

Hi, do you have any updates on this which you're able to share?

@champnic
Copy link
Member

Unfortunately not yet. We have not begun work on this yet. This is a large amount of work, and while very high on our priority list, gets bumped each quarter as higher priority asks come in. I really want to do this work as it's currently one of our top asks, but the earliest that could happen is Q1 2022 at this point.

@avail
Copy link

avail commented Apr 8, 2022

Any news on this?

@champnic
Copy link
Member

champnic commented Apr 8, 2022

We are starting on the design phase of this work. Would you mind sharing your use case so that we can consider it in our plans?

@doxxx
Copy link

doxxx commented Apr 8, 2022

We are currently using CefSharp to render into an offscreen buffer that is sent to an FPGA to be composited onto a live video feed. The render includes playback of MPEG4-encoded video. We were looking into using WebView because CefSharp's default Chromium build does not include the MPEG4 codec. But without offscreen rendering, that's a moot point. We've since produced our own custom build of Chromium to include the codec.

@rjx-ray
Copy link

rjx-ray commented Apr 13, 2022

Our use case is to show web content in our immersive VR spaces. See https://www.igloovision.com/software/enterprise-package/igloo-web

We need access to the web rendered textures so that we can warp and blend multiple images to projector outputs to create a clear seamless view on the inside of a cylinder or room.

Currently we use CEF for the web input with a user maintained patch for getting the shared textures. See https://bitbucket.org/chromiumembedded/cef/pull-requests/285 and read down to the end of the comments for full details. We build CEF with proprietary codecs included. The builds of our app and CEF are done with C++.

This is unsatisfactory because it uses the deprecated custom compositing (which could be removed in future) instead of skia and is difficult to keep updated.

We would look at moving to webview2 if access to the rendered textures could be provided and supported along with the ability to include proprietary codecs

@champnic
Copy link
Member

Thanks for the info @rjx-ray! If you don't need high-frequency rendering you could consider using the CapturePreview function to get an image, but this isn't great for things like videos or other animations.

@rjx-ray
Copy link

rjx-ray commented Apr 13, 2022

Hi @champnic, thanks for the response but we do need high-frequency rendering, typically for YouTube and other web video display.

@avail
Copy link

avail commented Apr 17, 2022

We are starting on the design phase of this work. Would you mind sharing your use case so that we can consider it in our plans?

Game UI development, specifically within DirectX 9 (Ex) / 10 / 11 contexts.

Ability to render into an offscreen texture and display that as overlay of the game.

@champnic champnic added the tracked We are tracking this work internally. label May 10, 2022
@jcain82
Copy link

jcain82 commented May 11, 2022

We are starting on the design phase of this work. Would you mind sharing your use case so that we can consider it in our plans?

Currently, we utilize CefSharp Offscreen for generating a PDF from HTML content or using it to generate screenshots of HTML in a server side environment.

@zziger
Copy link

zziger commented Jul 17, 2022

Hi, are there any updates on this feature?

@lencil
Copy link

lencil commented Jul 21, 2022

We are starting on the design phase of this work. Would you mind sharing your use case so that we can consider it in our plans?

CAD editor software, I want to compose web ui and opengl/d3d rendering together.

@alainza
Copy link

alainza commented Jul 21, 2022

Any XR Application wanting to be able to have some 2D UI inside the 3D Environment: it means being able to render into a DirectX Texture and to be able to inject input in the off-screen view (pointer + keyboard)

@champnic
Copy link
Member

Thanks for the info! Unfortunately our design work is slow going due to high priority bugs, but we're still making progress.

@danielvandenberg95
Copy link

Is #579 related?

@honzapatCZ
Copy link

My use case would be Game Overlay.
And actually dotnet/maui(and in extension WPF/WinForms)'s BlazorWebView could benefit from this change too as they wouldn't have to create the fake elements(they are just precisely tracking the WebView window on top), but could do normal real elements in their respective apis without any weird quirks and bugs.

@honzapatCZ
Copy link

I'd say an api like CefSharp would be quite pleasant and easy to port over existing CefSharp code.
https://github.com/cefsharp/CefSharp/blob/d8674fd076c021eddcc0cb579687ca3c51a63767/CefSharp.OffScreen/DefaultRenderHandler.cs

@Harvey3141
Copy link

Hi, do you have any updates you're able to share?

@VentuzTammoHinrichs
Copy link

VentuzTammoHinrichs commented Nov 4, 2022

Adding another use case: Presentations on screens that are not just Windows desktops.

From our experience with CEF we'd need the following (in descending priority order) to switch:

  • Rendering into either a raw CPU buffer or into a fully accelerated DXGI surface (higher level APIs optional but this is what most people use)
  • Full control over the presentation parameters, such as resolution, frame rate, display scaling, output color space (including WCG/HDR), etc. Fully manual VSync is appreciated; the client engine might render ahead and buffer, or batch render to disk, so it's not strictly in real time.
  • Proper graphics resource lifetime management. Client app must be able to exactly specify when/how it is able to receive frames and when it is finished processing them; no spurious callbacks when client isn't ready (anymore), and no mutexes that render either side unresponsive when held a bit too long or not acknowledged (that one probably came out a bit too detailed, but you might be able to feel the pain here).
  • Full manual input injection, such as keyboard, mouse, and multi touch inputs.
  • Audio should also be redirected. Ideally per browser instance but globally would be fine at first. Client must be able to specify the sample format and channel layout, and it should be a pull model in which the client requests a certain # of sample frames and WebView2 outputs that number of frames exactly, in order to avoid timing discontinuities between the browser audio and the actual audio path the client uses.
  • ... and you might recognize a pattern here. There are other subsystems that would be cool to have redirected to an API, for example audio/video input (for web based streaming/conference services) or geolocation. A feature to auto-block all outside interaction that's not intercepted (Midi, Bluetooth, notifications, printing (possible security hole there!), etc) would perhaps be helpful, too.

It might be tempting to keep these APIs as close to the corresponding Windows APIs as possible but it's not strictly necessary - this feature will mostly be used from deep within client code, and very possibly behind a bunch of abstraction layers, so I'd aim for minimal and clean first.

Hope this was not too much/harsh but currently a whole industry is dependent on that CEF pull request above which has been in PR limbo for years and will soon just stop working altogether, and an alternative to that would be a very appreciated thing ;)

@DanielsCode
Copy link

@champnic - Is there any news you can share with us?

@robotsinthesun
Copy link

+1

@Hethsron
Copy link

Hi
Sorry to come back to the subject, but a lot has happened since it was opened.

And these days, I think there are solutions that should allow you to provide WebView2 on Linux and especially to add this mode.

So, is it possible to provide offscreen-rendering using Ozone Layer ? (cf. chromiumembedded/cef#3263)

The CEF team will be migrating to this architecture. So if, like them, your heart is in Chromium, you can either do what they do or do it better.

Regards

@reitowo
Copy link

reitowo commented Apr 26, 2024

As you can see in chromium/src/ui/ozone/platform, there's no clue about ozone Windows/macOS support, which I think Chromium/CEF won't migrate to this shortly. In fact, it is also hard to know which platform the OSR host is on, so I think sharing dmabuf is a better solution for now on Linux.
FYI, the viz based OSR has been merged to CEF recently: https://bitbucket.org/chromiumembedded/cef/pull-requests/734
I think Webview2 can easily implement GPU OSR using FrameSinkVideoCapturer.

@Hethsron
Copy link

Hethsron commented Apr 26, 2024

Hello @reitolab

I don't think it was merged because this pull request was rejected. The CEF strategy is described here: chromiumembedded/cef#3685
chromiumembedded/cef#3681

What is certain is that Microsoft has what it takes to offer OSR on both Linux and Windows.

@reitowo
Copy link

reitowo commented Apr 26, 2024

@Hethsron

  1. It is, the decline message says: Manually merged in master revision 260dd0ca24 with minor style and documentation fixes.
  2. I don't think switching alloy/chrome affects off-screen rendering, they are seperated modules to me.
  3. The OSR is implementable on all platforms (Windows/macOS/Linux), as CEF already does.

@Hethsron
Copy link

Hethsron commented Apr 26, 2024

@reitolab

I think Webview2 can easily implement GPU OSR using FrameSinkVideoCapturer.

So what's the target date? When will we have this mode?

@microdee
Copy link

this hasn't been done in 4 years, so I wouldn't expect it in this decade either

@reitowo
Copy link

reitowo commented Apr 26, 2024

I'm not the Webview2 dev, so I can't give any date. I was posting CEF solution here just to provide a example, and hoping someone in MS could done it. I've working on that viz solution for 3 months and it finally merged into cef 3 days ago.

@Hethsron
Copy link

this hasn't been done in 4 years, so I wouldn't expect it in this decade either

@microdee
Let's be optimistic.

One thing's for sure: if they need help, they can count on us. Right? @reitolab

@Hethsron
Copy link

Hello @bradp0721

Don't you have any specific information to give us on the subject?

What are your current bottlenecks?
How can we help you?

Regards

@reitowo
Copy link

reitowo commented Apr 26, 2024

Maybe it is faster to apply a MS job and implement it yourself

@Hethsron
Copy link

Maybe it is faster to apply a MS job and implement it yourself

I'm fine. I'm just helping out. @reitolab Are you employed by CEF?

@reitowo
Copy link

reitowo commented Apr 26, 2024

No, I'm not. I think we shouldn't continue chat here.

@microdee
Copy link

Are CoreWebView2Texture, CoreWebView2TextureStream or CoreWebView2WebTexture classes related to this request? Documentation seems a bit sparse.

@reitowo
Copy link

reitowo commented Aug 14, 2024

wow, seems promising

@microdee
Copy link

apparently those are in there for a year and a half, see WebView2 release notes however I think it's more like sharing a texture resource between JS and the host, not rendering the entire HTML page onto a texture, however I'd be glad to be proven wrong there ;)

@reitowo
Copy link

reitowo commented Aug 14, 2024

is there any js api to use the texture?

@microdee
Copy link

microdee commented Aug 14, 2024

I have no idea but I found this old example
From the example it looks like the webpage is streamed on the texture, I will try this in my free time at some point and report back, however I don't know when that'll happen

@reitowo
Copy link

reitowo commented Aug 14, 2024

Maybe this one? https://github.com/MicrosoftEdge/WebView2Feedback/pull/2743/files

@microdee
Copy link

ah bummer it's not rendering HTML to texture indeed as what's this thread is about but serving a texture as a media source for JS, regardless it's a cool feature I don't remember CEF having anything like that for example.

@reitowo
Copy link

reitowo commented Aug 14, 2024

That's also something I want, I did a little dig about WebGPU, and I think it is possible to do that with a GPUTexture, with dawn native, not standard WebGPU, unless further modification to chromium.

I also saw some API of WebView2 that receiving a texture from JS? So probably we can also get a texture of the screen? not sure

@weltkante
Copy link

I also saw some API of WebView2 that receiving a texture from JS? So probably we can also get a texture of the screen? not sure

the PR linked above uses the API to modify the stream from the host (a video stream) and the host reading back the modifications; unless you saw some API to get access to the browsers texture/framebuffer its probably just that, video editing capabilities

@selastingeorge
Copy link

Any Update on this.

@leaanthony
Copy link

Another ping for this thread....

@mdrejhon
Copy link

Me too!
(TestUFO 2.1 is out, and I need to find ways to add VRR support through some method.)

@fredemmott
Copy link

This issue appears to in effect be a wontfix: when faced with the same problem, even the WebView2 team have apparently chosen to ship new public APIs built on top of Windows::Graphics::Capture wrappers instead of addressing this:

https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.wpf.webview2compositioncontrol?view=webview2-dotnet-1.0.2950-prerelease

Note that the WebView2CompositionControl uses a GraphicsCaptureSession to capture the screen content from the underlying browser processes. As such, you may experience lower framerates compared to the standard WebView2 control, and DRM protected content will fail to play or display properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests