Page 1 of 1

Question for CefRenderHandler::OnPaint

PostPosted: Wed Apr 07, 2021 2:27 am
by JokerLD
I am little confused about the CefRenderHandler::OnPaint function, does every time when chromium doing paint in its render pipeine, the OnPaint function get called synchronously?
In my project, I opened one single website, and execuate JS code to play animation, then get frame data from the OnPaint function, it seems that after one animation update, the OnPaint function get called one or more times. And the timing of OnPaint callback is not consistent with the paint of chromium.
In order to get one frame after I do one time JS animation update, I register CefMessageRouterBrowserSide::Handler.
My logic is
(1) I execuate JS function to update one frame by calling CefFrame::ExecuteJavaScript in Cpp side.
(2) After the JS function completed updating one frame, it will call sendMessage to send a message to Cpp side
(3) I get frame data from OnPaint function, but the OnPaint function may be called multiple times so I get one or more frames after one update.
(4) I receive message from the JS side, then I know that one update is completed, so I will start next update which means we will go back to (1)

I open the same website in chrome, and use performance tools to see the execuation order. And just like the image shows below.

As the image shows, it will first seek(the animation update function), then paint, composite and finally sendmessage to the cpp side. So I assume that OnPaint shall be called before receiving message. However, I found that in my code the OnPaint functions were always being called after I received message from JS side. And that cause my frame update logic messed up, because I don't know the exact time of the completion of the frame update.

So could someone help explain the when and how OnPaint function being called?

Re: Question for CefRenderHandler::OnPaint

PostPosted: Wed Apr 07, 2021 8:56 am
by magreenblatt