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

WPF - Rendering not refreshed at maximum framerate. #2275

Open
valhentai opened this issue Feb 12, 2018 · 18 comments
Open

WPF - Rendering not refreshed at maximum framerate. #2275

valhentai opened this issue Feb 12, 2018 · 18 comments
Labels

Comments

@valhentai
Copy link

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.

@jankurianski
Copy link
Member

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?

@amaitland
Copy link
Member

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/

@valhentai
Copy link
Author

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.

@amaitland
Copy link
Member

Do you think it's a problem with CefSharp? To me it sounds more of a problem with WPF.

@amaitland
Copy link
Member

The rendering used for WPF has been rewritine, so you should have a much easier time debugging

#2237

@valhentai
Copy link
Author

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.

@amaitland
Copy link
Member

If that is the case then the priority should be made configurable.

@valhentai
Copy link
Author

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.

@amaitland
Copy link
Member

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?

@amaitland
Copy link
Member

Can you provide a code sample of an animation you are using that forces the browser to render at a different speed?

@valhentai
Copy link
Author

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 )

@amaitland

This comment was marked as outdated.

@amaitland
Copy link
Member

dotnet/wpf#1908 describes a similar behaviour in WPF.

@amaitland
Copy link
Member

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);

@amaitland amaitland changed the title WPF web browser rendering not refreshed at maximum framerate. WPF- Rendering not refreshed at maximum framerate. Oct 28, 2020
@Dev-Wiki

This comment was marked as off-topic.

@amaitland

This comment was marked as off-topic.

@Dev-Wiki

This comment was marked as off-topic.

@barvaz2
Copy link

barvaz2 commented Jan 6, 2022

@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
};

@amaitland amaitland changed the title WPF- Rendering not refreshed at maximum framerate. WPF - Rendering not refreshed at maximum framerate. Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants