Offscreen rendering of browser's window

Having problems with building or using the JCEF Java binding? Ask your questions here.

Offscreen rendering of browser's window

Postby epietrig » Mon Oct 10, 2016 10:02 am

Hi,

I would like to know if there is a way to ask JCEF to render a CEF browser window offscreen in, e.g., a java.awt.image.BufferedImage?

I have looked at the javadoc and searched the forum, but could not find any obvious way of achieving this.

thanks,
Emmanuel
epietrig
Newbie
 
Posts: 3
Joined: Mon Oct 10, 2016 9:56 am

Re: Offscreen rendering of browser's window

Postby magreenblatt » Tue Oct 11, 2016 1:28 pm

The detailed example demonstrates off-screen rendering. Pass the `--off-screen-rendering-enabled` command-line flag.
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: Offscreen rendering of browser's window

Postby epietrig » Wed Oct 12, 2016 3:48 am

Thanks. I looked at the detailed example, but I could not find code that would let me render the browser's componentUI to an image.

I've tried rendering to a BufferedImage using the component's paintAll(Graphics2D) method, but this does not work (I get an empty image):

Code: Select all
CefSettings settings = new CefSettings();
settings.windowless_rendering_enabled = true;
cefApp = CefApp.getInstance(settings);
cefClient = cefApp.createClient();
cefBrowser = cefClient.createBrowser(url.toString(), true, false);
cefComp = cefBrowser.getUIComponent();
cefComp.setSize(cefCompWidth, cefCompHeight);
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage image = gc.createCompatibleImage(cefComp.getWidth(), cefComp.getHeight(), Transparency.TRANSLUCENT);
Graphics2D g2 = ((BufferedImage)image).createGraphics();
System.out.println(cefComp);
cefComp.paintAll(g2);
g2.dispose();
image.setAccelerationPriority(1);


This is probably expected, given what the above println statement yields:
Code: Select all
AWT-GLCanvas[Realized false,
   null-drawable,
   Factory   null,
   handle    0x0,
   Drawable size -1x-1 surface[800x600],
   AWT[pos 0/0, size 800x600,
   visible true, displayable false, showing false,
   null]]


compared to what I get if I add my component to a JFrame (in which case it renders fine, but this is not what I want in my case):
Code: Select all
AWT-GLCanvas[Realized true,
   jogamp.opengl.x11.glx.X11OnscreenGLXDrawable,
   Factory   jogamp.opengl.x11.glx.X11GLXDrawableFactory@6c49835d,
   handle    0x3200048,
   Drawable size 800x600 surface[800x600],
   AWT[pos 0/0, size 800x600,
   visible true, displayable true, showing true,
   AWTGraphicsConfiguration[AWTGraphicsScreen[AWTGraphicsDevice[type .awt, connection :0.0, unitID 0, awtDevice X11GraphicsDevice[screen=0], handle 0x0], idx 0],
   chosen    GLCaps[glx vid 0x18b, fbc 0x9d: rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/0/0, dbl, mono  , hw, GLProfile[GL2/GL2.hw], on-scr[.]],
   requested GLCaps[rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, dbl, mono  , hw, GLProfile[GL2/GL2.hw], on-scr[.]],
   X11GraphicsConfig[dev=X11GraphicsDevice[screen=0],vis=0x18b],
   encapsulated X11GLXGraphicsConfiguration[X11GraphicsScreen[X11GraphicsDevice[type .x11, connection :0, unitID 0, handle 0x7f2a0869bde0, owner true, JAWTToolkitLock[obj 0x5e853265, isOwner false, <67205a84, 7d0587f1>[count 0, qsz 0, owner <NULL>]]], idx 0], visualID 0x18b, fbConfigID 0x9d,
   requested GLCaps[rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, dbl, mono  , hw, GLProfile[GL2/GL2.hw], on-scr[.]],
   chosen    GLCaps[glx vid 0x18b, fbc 0x9d: rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/0/0, dbl, mono  , hw, GLProfile[GL2/GL2.hw], on-scr[.]]]]]]


Is there a way to realize this GLCanvas offscreen and get it to render to a BufferedImage?

thanks,
epietrig
Newbie
 
Posts: 3
Joined: Mon Oct 10, 2016 9:56 am

Re: Offscreen rendering of browser's window

Postby magreenblatt » Wed Oct 12, 2016 10:23 pm

Look at the CefBrowserWindowOsr class: https://bitbucket.org/chromiumembedded/ ... ew-default
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: Offscreen rendering of browser's window

Postby epietrig » Mon Oct 17, 2016 6:19 am

Thanks for the link. But after looking in detail at this part of the code, I still don't understand how I can __from the outside__ get the browser's content drawn in an offscreen image. It looks like to do this I would need to implement my own CefRenderHandler and do something with the ByteBuffer in the onPaint() method (like make a BufferedImage out of it). But there is no way to set my own CefRenderHandler, it would seem. I guess I could implement my own variant of CefBrowserOsr, but since that class is not public, it does not look like I can do this outside the org.cef.browser package.

But I may be looking at this from the wrong angle... Any help appreciated.

Thanks!
Emmanuel
p.s. I'm also looking for an "efficient" solution. I'd rather avoid having to convert the ByteBuffer to a BufferedImage manually by iterating over all pixels and calling setPixel() on the Raster. So I am not even sure that working in CefRenderHandler.onPaint() is what I am actually looking for in the first place.
epietrig
Newbie
 
Posts: 3
Joined: Mon Oct 10, 2016 9:56 am

Re: Offscreen rendering of browser's window

Postby magreenblatt » Mon Oct 17, 2016 9:21 am

JCEF's public API does not support the specific functionality that you're looking for. You should modify the source code to fit your needs.
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 15 guests