Controlling CEF3 OSR animation frame rate

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Controlling CEF3 OSR animation frame rate

Postby Drawknob » Mon Apr 14, 2014 5:07 pm

Since CefBrowserSettings::animation_frame_rate is only in CEF1, how do I control the animation frame rate in CEF3 (specifically, in off screen rendering)? Also, is it in any way dependent on the frequency with which I call CefDoMessageLoopWork(), or is that strictly for processing incoming events (and so I wouldn't need to call it unless there's user input available)?
Drawknob
Techie
 
Posts: 24
Joined: Wed Mar 05, 2014 3:22 pm

Re: Controlling CEF3 OSR animation frame rate

Postby magreenblatt » Tue Apr 15, 2014 10:42 am

Chromium controls the frame rate internally. You need to call CefDoMessageLoopWork at a regular interval whenever a browser exists.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Controlling CEF3 OSR animation frame rate

Postby Drawknob » Tue Apr 15, 2014 2:42 pm

So why does CEF1 allow the framerate to be adjusted but CEF3 doesn't?

Also, regular interval I understand, but that doesn't tell me what the magnitude of that interval ought to be. For example, I'm currently calling it every 33 ms, but that's just an arbitrary choice. What is the optimal rate, and is the optimum affected by whether there are input events or not?
Drawknob
Techie
 
Posts: 24
Joined: Wed Mar 05, 2014 3:22 pm

Re: Controlling CEF3 OSR animation frame rate

Postby magreenblatt » Tue Apr 15, 2014 3:45 pm

Drawknob wrote:So why does CEF1 allow the framerate to be adjusted but CEF3 doesn't?

CEF1 uses a completely different architecture. More information is available here: https://code.google.com/p/chromiumembed ... chitecture

Drawknob wrote:Also, regular interval I understand, but that doesn't tell me what the magnitude of that interval ought to be. For example, I'm currently calling it every 33 ms, but that's just an arbitrary choice. What is the optimal rate, and is the optimum affected by whether there are input events or not?

The message loop does everything from compositing to user input processing. If you're using CefDoMessageLoopWork then you're already living in a sub-optimal world. Calling it too infrequently will starve the message loop. Calling it too frequently will cause excessive CPU usage. 30fps (33ms) is a reasonable choice. For best performance you should use CefRunMessageLoop instead of CefDoMessageLoopWork.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Controlling CEF3 OSR animation frame rate

Postby Drawknob » Tue Apr 15, 2014 4:22 pm

So is it fine to run CefRunMessageLoop() in OSR mode when there's no window and I'm not sending any Windows events? All user input is sent to my CEF-based application over a pipe from another application. This is my CEF application's main loop, and as you can see, there are no Windows events at all:

Code: Select all
CefInitialize(...);
...
auto nextTime = chrono::steady_clock::now() + chrono::milliseconds(33);
auto fut = inputPipe.AsyncRead(msgBuffers[index]);
while (running)
{
    if (fut.WaitUntil(nextTime))
    {
        for (auto const message : msgBuffers[index]) Process(message); // Will call SendMouseClickEvent() and whatever else, based on message type
        fut = inputPipe.AsyncRead(msgBuffers[index]);
        index = 1 - index; // Flip
    }
    auto timeNow = chrono::steady_clock::now();
    if (timeNow >= nextTime)
    {
        CefDoMessageLoopWork();
        do nextTime += chrono::milliseconds(33);
        while (nextTime < timeNow); // Constant rate
    }
}

Is it more efficient to put CefRunMessageLoop() in a separate thread and not worry about timeouts? There's also the issue that any calls that I need triggered by messages which have to be on the UI thread I'd now have to post as tasks to that thread rather than calling directly, and I also have to worry about synchronization with handler callbacks that are executed on the UI thread, which would now be different from my main loop main thread.
Drawknob
Techie
 
Posts: 24
Joined: Wed Mar 05, 2014 3:22 pm

Re: Controlling CEF3 OSR animation frame rate

Postby magreenblatt » Tue Apr 15, 2014 4:44 pm

Drawknob wrote:So is it fine to run CefRunMessageLoop() in OSR mode when there's no window and I'm not sending any Windows events?

Yes.

Drawknob wrote:Is it more efficient to put CefRunMessageLoop() in a separate thread and not worry about timeouts?

Yes. Initialize and run CEF in the main application thread. Perform your custom blocking work in a separate thread that your application creates.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 80 guests