onPaint HiDPI/retina

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

onPaint HiDPI/retina

Postby shannah » Fri Jul 10, 2020 11:10 am

On retina, the onPaint callback returns low-dpi pixels.

E.g.
Code: Select all
@Override
    public void onPaint(CefBrowser browser, boolean popup, final Rectangle[] dirtyRects,
            ByteBuffer buffer, int width, int height) {
        // Note: component_ is the swing component i'm using to render/size the offscreen browser
 
        System.out.println("onPaint width="+width+", height="+height+", cmpWidth="+component_.getWidth()+", cmpHeight="+component_.getHeight());
...


Outputs

Code: Select all
onPaint width=522, height=642, cmpWidth=522, cmpHeight=642


On a device with retina (so scale is 2.0).

What I would hope for is output like:

Code: Select all
onPaint width=1044, height=1284, cmpWidth=522, cmpHeight=642


Meaning that the pixels I receive are double the density of the Swing component's dimensions.

Is there a way to configure this?
shannah
Techie
 
Posts: 30
Joined: Wed Jul 08, 2020 8:01 am

Re: onPaint HiDPI/retina

Postby magreenblatt » Fri Jul 10, 2020 11:19 am

You would need to implement CefRenderHandler::GetScreenInfo, and possibly perform some scaling in CefBrowserOsr and/or CefRenderer. High-dpi support is only available in Java 9+, support for which was landed quite recently. A PR to add high-dpi support for OSR would be welcome.
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: onPaint HiDPI/retina

Postby shannah » Fri Jul 10, 2020 2:04 pm

That's perfect! Thanks. I've added retina support in my fork, and it's working nicely so far. Java8 and Java9+ supported for offscreen rendering.

https://github.com/shannah/java-cef/com ... 0dad784fb5

I'm not using the standard renderers. I'm using my own that renders to a BufferedImage, but you can see that implementation here:
https://github.com/codenameone/Codename ... .java#L435

Note: In order to use a custom renderer, I needed to refactor it to allow me to register my own factory.
https://github.com/shannah/java-cef/com ... 5a421a4a26
shannah
Techie
 
Posts: 30
Joined: Wed Jul 08, 2020 8:01 am

Re: onPaint HiDPI/retina

Postby Slartie » Sun Aug 23, 2020 12:29 pm

I've incorporated your commit enabling access to GetScreenInfo into a pull request that I had already open for some time which originally had the purpose of adding a screenshotting functionality to the original OSR mode of JCEF (I kept your author name in the commit, hope you're okay with that; it's basically exactly your code, plus some format fixing and cleanup). That screenshotting code also needs to take display scaling into account in order to not crash due to invalid buffer sizes, so when I found this thread I decided to just port full support for scaling to JCEF's OSR mode instead of doing some half-hearted fix for the buffer size problem.

Here's the open pull request: https://bitbucket.org/chromiumembedded/ ... tting/diff
Slartie
Techie
 
Posts: 11
Joined: Mon Sep 03, 2018 5:47 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 16 guests