mixing off-screen rendering and regular rendering

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.

mixing off-screen rendering and regular rendering

Postby gcx » Wed Dec 18, 2013 4:09 am

I have derived my app from the cef sample. It is using the regular, window based rendering.
I would like at the same time (same app) to leverage the off-screen capability of cef in order to capture bitmaps of things similar to what is rendered in my window.

I was planning to create a second browser, with CefBrowserHost::CreateBrowser, attaching a specific CefWindowInfo.

This is were I got lost. I can not get this working.
Is the approach viable ? and if yes what is the minimal structure to provide to cef to get my OnPaint call back called on my custom CefRenderHandler ?

Thanks for your help
Gregoire
gcx
Newbie
 
Posts: 3
Joined: Wed Dec 18, 2013 3:37 am

Re: mixing off-screen rendering and regular rendering

Postby magreenblatt » Wed Dec 18, 2013 11:25 pm

What content are you loading in the browser? In most cases with dynamic content it will be impossible to have identical contents in both browsers and keep them perfectly synchonized. Also, off-screen browsers may render differently due to the lack of hardware acceleration.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: mixing off-screen rendering and regular rendering

Postby gcx » Fri Dec 20, 2013 8:15 am

Thanks for the answer.
My content is not that dynamic, and generated for off-screen rendering + capture. In the end, it is html + some svg. I am going to reuse my initial browser through inheritance or composition, I will see.
The simplest running code I found is like :
class BrowserClient : public CefClient, CefRenderHandler
{
CefString url;
CefString path;
public:
BrowserClient(CefString url,CefString path):url(url),path(path)
{}
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() {
return this;
}
// CefRenderHandler interface
bool done = false;
public:
bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect)
{
rect.Set(0, 0, 800, 600);
return true;
}
void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList &dirtyRects, const void *buffer, int width, int height)
{
if (!browser->IsLoading() && !done)
{
saveBitmap(path.ToString().c_str(),buffer,width,height);
done=true;
}
}
IMPLEMENT_REFCOUNTING(BrowserClient);
};

I don't quite get when the OnPaint is called so when it is time to get some kind of screenshot.
The render quality is very different indeed on my mac, probably good enough for some thumbnails though.
gcx
Newbie
 
Posts: 3
Joined: Wed Dec 18, 2013 3:37 am

Re: mixing off-screen rendering and regular rendering

Postby magreenblatt » Fri Dec 20, 2013 11:15 am

OnPaint will be called whenever an updated region is received from Blink. Your best option might be allocating a bitmap for the off-screen browser and applying the update every time OnPaint is called (pay attention to |dirtyRects| if you want to optimize). You can then save the bitmap to file whenever you want. Make sure to only access the bitmap on the CEF UI thread.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: mixing off-screen rendering and regular rendering

Postby gcx » Fri Dec 20, 2013 11:48 am

Now that you put words ... I won't be able to know when it is time to capture the bitmap, except with a weak heuristic like 'no paint event for some time so it is time to capture'.

A better option would be for the things that will be rendered off-screen to notify that rendering is at a stage where capture is worth it.
In other other words, only the renderer knows when it is "done", assuming no transition, no call back on timer etc ... the browser can not really tell.
I probably need some more messages to sync all of this.
Gregoire
gcx
Newbie
 
Posts: 3
Joined: Wed Dec 18, 2013 3:37 am

Re: mixing off-screen rendering and regular rendering

Postby magreenblatt » Fri Dec 20, 2013 12:08 pm

gcx wrote:In other other words, only the renderer knows when it is "done", assuming no transition, no call back on timer etc ... the browser can not really tell.

CefLoadHandler::OnLoadingStateChange will be called when the browser feels that loading is "done". Note that asynchronous loading may still continue via XHR, timers, etc.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: mixing off-screen rendering and regular rendering

Postby dshaulov » Sun Dec 22, 2013 3:48 am

Hi Marshal,

Is OnLoadingStateChange more/less reliable than OnLoadEnd? Can you explain the difference if there is any?
dshaulov
Techie
 
Posts: 37
Joined: Sun Dec 09, 2012 10:58 am

Re: mixing off-screen rendering and regular rendering

Postby magreenblatt » Sun Dec 22, 2013 12:16 pm

Easier to use than OnLoadEnd, and the signal timing is somewhat different. See the source code documentation here: http://code.google.com/p/chromiumembedd ... _handler.h
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: mixing off-screen rendering and regular rendering

Postby fotoguy42 » Sat Jan 18, 2014 5:59 pm

There is an issue using OnLoadEnd or OnLoadingStateChange in that if you load a large image, the final OnPaint event happens some time after, and seems variable. I even added a CefV8Handler so that my javascript can let me know when it's done, but it still takes time for the renderer finish a viewRect of 7500x5000. There must be some kind of queue in the renderer (Blink right?) to know if there is anything it is still working on.
fotoguy42
Newbie
 
Posts: 1
Joined: Sat Jan 18, 2014 5:33 pm

Re: mixing off-screen rendering and regular rendering

Postby daktor » Sun Aug 24, 2014 7:09 pm

I am using CEF to render webpages of a static image. I'm using OnLoadingStateChange to know when the website finishes loading, then OnPaint to capture the image. I'm running into the same issue as fotoguy42 in that OnLoadingStateChange shows the site as finished loading, but it's not until some time later that OnPaint gives the completed render. Is there a way to know when OnPaint has caught up?

Thanks!
daktor
Techie
 
Posts: 14
Joined: Wed May 22, 2013 3:39 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 47 guests