CefSharp
CefSharp copied to clipboard
WPF - Rendering not refreshed at maximum framerate.
I noticed a strange behavior in the WPF CefSharp browser. When watching a video (YouTube for example), the video is not totaly fluid. but if something else is hapenning in the application, like an animation, the video is completly fluid. My theory is that the animation cause WPF do redraw at 60 FPS and it cause the CefSharp browser to redraw at this rate. When no animation is running, the default CefSharp redraw rate is smalller.
I tried differents values for the CefCommandLineArgs --off-screen-frame-rate ( 25, 30 , 60, 120 ) but the result is the same.
I am using The WPF nuget version 63.0.0 on WIndows 10. I use the following command line
settings.CefCommandLineArgs.Add("enable-gpu", "1");
settings.CefCommandLineArgs.Add("enable-webgl", "1");
settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling", "1");
settings.CefCommandLineArgs.Add("--off-screen-frame-rate", "60");
with gpu disabled, the result is the same.
This may not be due to CefSharp as it is just a wrapper around CEF. If you re-read the new issue template you should see a section on running the CEF sample application (cefclient) with offscreen rendering parameters. Could you try this and report back what you find?
Did you search old issues to see if this issue has been reported previously, and if so what did you find?
I tried differents values for the CefCommandLineArgs --off-screen-frame-rate ( 25, 30 , 60, 120 ) but the result is the same.
It's my understanding that command line option is only implemented in the cefclient reference application. You can adjust the frame rate through BrowserSettings or a method on the IBrowserHost, you'll have to look up the API Doc or search the source to find the example property/method.
http://cefsharp.github.io/api/
I ran the cefclient sample with the command cefclient.exe -off-screen-rendering-enabled and video run at full speed.
I can't reproduce the issue with Cef alone because it is linked to WPF. When the Wpf application is drawing something, the browser rendering is refreshed at full speed.
I tried BrowserSettings = new BrowserSettings() { WindowlessFrameRate = 60, }; but i change nothing.
I display something under the mouse cursor using a DrawingVisual and just passing the mouse over the application without clicking or without being above the browser is enough to have the browser render speedup.
Do you think it's a problem with CefSharp? To me it sounds more of a problem with WPF.
The rendering used for WPF has been rewritine, so you should have a much easier time debugging
https://github.com/cefsharp/CefSharp/issues/2237
Maybe Changing the dispatcher priority in InteropBitmapFactory and WritableBitmapFactory will solve the problem.
I already had a similar problem where a Render priority gave me a slugish rendering. putting the priority to DataBind gave me 60 FPS rendering.
I will download the CefSharp source and try this.
If that is the case then the priority should be made configurable.
I changed the priority of all the Dispatcher call I found in the WPF solution but nothing changed.
It seem to be a bug from WPF. The OnPaint() function in ChromiumWebBrowser is called with the same frequency when the rendering is slugish and when it is not.
What version of .net do you have installed? You can try the different bitmap implementations, see if one is better. Have you tested on a different machine to verify it's not just a GPU driver issue?
Can you provide a code sample of an animation you are using that forces the browser to render at a different speed?
I just do
var rec = new Rectangle { Width = 100, Height = 100 };
var rotate = new RotateTransform();
rec.RenderTransform = rotate;
var anim = new DoubleAnimation
{
From = 0,
To = 360,
RepeatBehavior = RepeatBehavior.Forever
};
rotate.BeginAnimation(RotateTransform.AngleProperty, anim);
the animated rectangle can be placed anywhere in the application.
I tried it on different machine with NVidia GPU (geforce GTX 960 and geforce GT 750M )
Thanks
https://github.com/dotnet/wpf/issues/1908 describes a similar behaviour in WPF.
Adding an animation appears to workaround the issue.
If we have one or more active Rendering events it's the same as having an active animation so we know that we'll need to render another frame.
As per https://referencesource.microsoft.com/#PresentationCore/Core/CSharp/System/Windows/Media/MediaContext.cs,595
Using CompositionTarget.Rendering may improve performance if we are constantly updating the UI. There is already an experimental implementation of the CompositionTargetRenderHandler
Assign a new instance to http://cefsharp.github.io/api/79.1.x/html/P_CefSharp_Wpf_ChromiumWebBrowser_RenderHandler.htm
browser.RenderHandler = new CompositionTargetRenderHandler(browser, browser.DpiScaleFactor, browser.DpiScaleFactor);
I have same problem, I have two windows computes.
first is xps15, run sample on that it can load page right.
second is Lenovo, run sample it load page to blank, when you Resize windows, the page show right.

WPF the browser stops redrawing when running on Intel Iris Xe Integrated GPU(11th Gen). Intel have released an updated driver, see https://www.intel.com/content/www/us/en/support/articles/000058136/graphics/graphics-for-11th-generation-intel-processors.html See dotnet/wpf#3817 for workaround if you are unable to install the updated driver.
As per the release notes https://github.com/cefsharp/CefSharp/releases/tag/v94.4.20
@amaitland think you~
@valhentai mentioned this solution and and said it didn't work
I tried BrowserSettings = new BrowserSettings() { WindowlessFrameRate = 60, }; but i change nothing.
It worked for me! Now getting 60 fps from my webgl2 web application.
BrowserSettings settings = new BrowserSettings();
settings.WindowlessFrameRate = 60;
settings.WebGl = CefState.Enabled;
ChromiumWebBrowser chrome_browser = new ChromiumWebBrowser(url)
{
BrowserSettings = settings
};