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

Create Snapshot using Bitblt #2286

Closed
Ratcha9 opened this issue Feb 22, 2018 · 17 comments
Closed

Create Snapshot using Bitblt #2286

Ratcha9 opened this issue Feb 22, 2018 · 17 comments

Comments

@Ratcha9
Copy link

Ratcha9 commented Feb 22, 2018

  • What version of the product are you using?
    Nuget Package 63.0.1

  • What architecture x86 or x64?
    x64

  • On what operating system?
    Windows10

  • Are you using WinForms, WPF or OffScreen?
    WinForms component in WPF application

  • What steps will reproduce the problem?
    I've pushed an example to MinimalExample. There I've modified the WPF proj:

  • Removed WPF CefSharp Browser

  • Winforms CefSharp browser added

  • Button added on top

A click on the button creates a Bitmap with the recommended gist and shows the image in a new window.
Since the update to version 63.0.1 I am getting a black image. With version 57.0 it is working fine

  • What is the expected output? What do you see instead?
    Expectation: screenshot of the browser content
    Actual result: black bitmap

  • Please provide any additional information below.
    In my real wpf application I am using Bitblt and PrintWindow. In order to mitigate the airspace issue, while we are showing e.g. modal dialogs "above" the browser, we hide the winforms hwnd, take pictures of it with PrintWindow and render that bitmap in WPF. This hacky workaround was pretty useful, since it worked with about 7-30 fps. I can reimplement this in the example, if it would help

@jankurianski
Copy link
Member

Hi, I wrote the gist but unfortunately I haven't had time to upgrade to 63 yet. Do you know if the problem also occurs in a pure WinForms environment? If you have another gist that works specifically in a WinForms+WPF hosted environment I'd be happy to link to it from my gist.

@Ratcha9
Copy link
Author

Ratcha9 commented Feb 26, 2018

Hi, thank you for your reply. Sorry, I am not aware whether bitblt works in pure winforms application. Unfortunately neither the bitblt nor the printwindow approach work with the new version. I can add the implementation to the minimal example in the next days

@Ratcha9
Copy link
Author

Ratcha9 commented Mar 5, 2018

so, I've added a basic implementation for using printwindow in my example fork.
@jankurianski when do you think you could check this?

@Ratcha9 Ratcha9 closed this as completed Mar 5, 2018
@Ratcha9 Ratcha9 reopened this Mar 5, 2018
@Ratcha9
Copy link
Author

Ratcha9 commented Mar 6, 2018

Thank you for your reply.
I use webgl content in the browser with user interaction like panning or zooming with the mouse. The Winforms version is as fast as native in chrome. The wpf version is significantly slower and does not feel smooth.

@803617
Copy link

803617 commented Mar 6, 2018

Have the same problem after update 57->63 in WinForms application. Snapshot per BitBlt with version 57 works fine, with version 63 black.

@chylex
Copy link
Contributor

chylex commented Mar 7, 2018

In general, the only time I remember black screens is when the window or control isn't visible (as you describe with hide the winforms hwnd), but that shouldn't have changed since 57, i.e. if that's your issue then I don't know why it worked before in the first place.

@803617 Would be helpful if you showed your code, I've been using BitBlt on a Form with a browser in it for a while and haven't noticed any issues when updating to 63 or newer.

@Ratcha9
Copy link
Author

Ratcha9 commented Mar 8, 2018

@chylex Well , BitBlt isn't working either when the form is visible :(
@amaitland Thanks for your reply, but the wpf version is really far away from the performance of the winforms version

@803617
Copy link

803617 commented Mar 8, 2018

My test project creates this black snapshot for me.
Removed binary file

@chylex
Copy link
Contributor

chylex commented Mar 8, 2018

Here's my WinForms code, maybe it'll help. I'm calling it with the Form handle, the Form is visible but outside all monitors, if you need to simulate invisible forms.
https://github.com/chylex/TweetDuck/blob/64977964e8e8c7bc4c419a0babbc37bfa7de92c7/Core/Utils/NativeMethods.cs#L133-L143
https://github.com/chylex/TweetDuck/blob/07af99f862d6e0f44ab352dbf86d71c0541452a4/Core/Notification/Screenshot/FormNotificationScreenshotable.cs#L48-L65

@Ratcha9
Copy link
Author

Ratcha9 commented Mar 9, 2018

@chylex Thank you for sharing your code. That's exactly the same code I am using. Do you set any specific cef settings or any cmd line args for cef? Could you share them?

@chylex
Copy link
Contributor

chylex commented Mar 9, 2018

Nothing that should affect BitBlt, afaik. I'm on CefSharp 64.0.0-CI2508 with legacy JS binding, so it should be consistent with previous versions. The code has been working since 55, and only had minor changes (like screenshoting window border, which was then removed when I decided to move the screenshotted Form outside all monitors where borders aren't rendered).

@Ratcha9
Copy link
Author

Ratcha9 commented Mar 11, 2018

BitBlt works, if I disable the gpu of course. I'm wondering if there are any other cmd line args you are using @chylex ?

@chylex
Copy link
Contributor

chylex commented Mar 11, 2018

By default, only disable-pdf-extension=1, disable-plugins-discovery=1, enable-system-flash=0. GPU is enabled.

@Ratcha9
Copy link
Author

Ratcha9 commented Mar 12, 2018

Unfortunately those args did not change anything. I did some research and I've found a PR on bitbucket for CEF: https://bitbucket.org/chromiumembedded/cef/pull-requests/96/osr-fix-gpu-cpu-readback-performance/diff
By trial and error I've found out that the arg use-angle helped without any performance decrease.
settings.CefCommandLineArgs.Add("use-angle", "gl");

I am not aware of any side effects by using this argument.
@amaitland do you have any concerns/thoughts?

@Ratcha9
Copy link
Author

Ratcha9 commented Mar 12, 2018

Description for use-angle switch:

Select which ANGLE backend to use. Options are: default: Attempts several ANGLE renderers until one successfully initializes, varying ES support by platform. d3d9: Legacy D3D9 renderer, ES2 only. d3d11: D3D11 renderer, ES2 and ES3. warp: D3D11 renderer using software rasterization, ES2 and ES3. gl: Desktop GL renderer, ES2 and ES3. gles: GLES renderer, ES2 and ES3. 

@Ratcha9
Copy link
Author

Ratcha9 commented Mar 14, 2018

use-angle did not work on different environments. Especially with intel HD graphiccards BitBlt did not work. We tested the following settings and until now it is working like a charm:
settings.CefCommandLineArgs.Add("in-process-gpu", "1");
settings.CefCommandLineArgs.Add("enable-gpu", "1");
settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling", "1");
Does anyone have any concerns using these switches?

@amaitland
Copy link
Member

@Ratcha9 Thanks for posting your workaround 👍

Restricted by its sandbox, the Renderer process (which contains an instance of Blink and of cc) cannot directly issue calls to the 3D APIs provided by the OS (GL / D3D). For that reason we use a separate process to access the device. We call this process the GPU Process. The GPU process is specifically designed to provide access to the system's 3D APIs from within the Renderer sandbox or the even more restrictive Native Client "jail". It works via a client-server model as follows:

https://www.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome

Chrome by default uses a separate process for GPU Acceleration due to it's sand boxing. By default there is no Sandboxing in CefSharp (cannot directly link the native .lib file required into a Managed Exe). The little I've read about the topic suggests that In Process GPU is used for Android, so should be a fairly well tested piece of code, though not on Windows. If you use this method and experience any rendering problems then you'll have to raise them with Chromium.

Intel GPU's are notoriously problematic and it's quite common to disable GPU acceleration for older models as they simple don't render properly. Chrome maintains list of problem cards and workarounds. (there are versions specific to each branch, open chrome://gpu/ and there will be a link to the exact version that's relevant to the branch you are using).

https://cs.chromium.org/chromium/src/gpu/config/software_rendering_list.json
https://cs.chromium.org/chromium/src/gpu/config/gpu_driver_bug_list.json

As a general note, making sure you have the latest graphics drivers, if you look at the Software Rendering List you'll see that quite a few entries are driver version specific.

Closing as this isn't a bug in CefSharp, just a byproduct of some Chrome changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants