Force rendering of loaded image

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.

Force rendering of loaded image

Postby Kluyg » Wed Sep 02, 2015 7:47 am

Hi! I'm using CEF 3.2454.1318 in off-screen rendering mode. The HTML I'm rendering contains static text + one image. Once it's rendered I'm saving the resulting buffer to a file.
After the call to browser->GetFrame->LoadURL(url) I start receiving OnPaint events. I use javascript to notify when the image loading is finished (I receive OnQuery event). After I receive OnQuery event I receive OnLoadEnd event. Then after OnLoadEnd I receive the "final" OnPaint event with the rendered image. Unfortunately for me, looks like there is no way to know exactly when the image was actually rendered and available in OnPaint buffer, so that I can save it to a file.

I tried the following "trick": to force OnPaint after image is loaded, I do browser->GetHost()->Invalidate(PaintElementType::PET_VIEW); and imidiately after this call I schedule my own method that writes to a file like this:
CefPostTask(TID_UI, base::Bind(&MyClass::SaveImageBufferResult, this));
My idea was that after Invalidate call the OnPaint event is scheduled on TID_UI thread, so my SaveImageBufferResult get scheduled after the OnPaint. And that's exactly what I observe:
Code: Select all
2015-09-02 16:35:19,346 [INFO][140735201030912] OnQuery
2015-09-02 16:35:19,359 [INFO][140735201030912] OnLoadEnd
2015-09-02 16:35:19,360 [INFO][140735201030912] OnPaint
2015-09-02 16:35:19,361 [INFO][140735201030912] SaveImageBufferResult
2015-09-02 16:35:19,384 [INFO][140735201030912] OnPaint

But even after OnQuery (which indicates that image finished loading) and OnLoadEnd (which indicates the page finished loading), the OnPaint triggered by Invalidate - doesn't contain the image!
Notice the last OnPaint - that one contains the image. So I don't understand what's the point of Invalidate if it just "replays" the last OnPaint event without rendering new elements I know are already loaded. Is this a bug?
I would appreciate any help!
Kluyg
Newbie
 
Posts: 5
Joined: Wed Sep 02, 2015 5:08 am

Re: Force rendering of loaded image

Postby magreenblatt » Thu Sep 03, 2015 4:36 am

Kluyg wrote:So I don't understand what's the point of Invalidate if it just "replays" the last OnPaint event without rendering new elements I know are already loaded. Is this a bug?

The compositor will provide results when they're available. Invalidate simply schedules a call to OnPaint. It's not possible to accurately predict the timing, but the compositor should be done within a few hundred ms of the JS image loaded notification (unless the image is huge, then it might take longer). You can then take whatever result was provided by the last OnPaint call.
magreenblatt
Site Admin
 
Posts: 12402
Joined: Fri May 29, 2009 6:57 pm

Re: Force rendering of loaded image

Postby Kluyg » Fri Sep 04, 2015 10:09 am

OK, thanks for the reply.
I ended up implementing a workaround: I'm checking the raw pixels to see if the buffer contains an image. Now I face a different problem: if the image is big, I get multiple OnPaint events that contain a partial image, and only the last one contains the whole image. This brakes my workaround. There should be something in CEF / Chromium code that controls how many OnPaint events will be sent. Can you please suggest where to look? I'm trying to come up with an algorithm to determine that last OnPaint event. I tried to relay on the fact that it should be within a few hundred ms but if the system is under load, it very well can be over 1 second or even more.
Kluyg
Newbie
 
Posts: 5
Joined: Wed Sep 02, 2015 5:08 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 25 guests