Frame with transparent background

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Frame with transparent background

Christophe LAFOLET
Sorry to post my message here, someone may have already encountered the same problem

The code below seems to works well with the default rendering
but if I activate the opengl pipeline with sun.java2d.opengl=true, there is a color saturation if the root window contains light colors
it seems there is a problem in the JDK  to convert RGBA color in pre-multiplied colors with X11 ?

Environment : Linux, X11, JDK8, Nvidia card

Christophe

------------------------------------------------------------------------------------------


import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.*;

public class CircleSplashScreen {

    public CircleSplashScreen() {
        JFrame frame = new JFrame();
        frame.getContentPane().add(new ImagePanel());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setUndecorated(true);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setBackground(new Color(0, 0, 0, 0));
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new CircleSplashScreen();
            }
        });
    }

    @SuppressWarnings("serial")
    public class ImagePanel extends JPanel {

        BufferedImage img;

        public ImagePanel() {
            setOpaque(false);
            setLayout(new GridBagLayout());
            try {
                img = ImageIO.read(new URL("http://www.iconsdb.com/icons/preview/royal-blue/stackoverflow-4-xxl.png"));
            } catch (IOException ex) {
                Logger.getLogger(CircleSplashScreen.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(500, 500);
        }
    }
}

Reply | Threaded
Open this post in threaded view
|

Re: Frame with transparent background

gouessej
Administrator
Hello

The OpenGL pipeline of Java2D in Java >= 8 doesn't rely on JOGL, it uses its own native pipeline with JNI, you can look at the source code of the classes in the package "sun.java2d.opengl" to confirm.

P.S: Maybe this helps:
https://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Frame with transparent background

Christophe LAFOLET
Yes,

I know that Java2D use its own pipeline (not JOGL), but I would like to know if someone has found a solution for this "simple" case.
I inspect package "sun.java2d.opengl" for several days and I have not found the bug.

Christophe


Reply | Threaded
Open this post in threaded view
|

Re: Frame with transparent background

gouessej
Administrator
Ok. Why not filling a bug report against Oracle Java?

In my humble opinion, it might be a limitation of Java2D OpenGL pipeline which was implemented earlier than the public API for translucent windows (the private API for that is a lot older, see AWTUtilities).

You claim that it's a simple case but it requires a lot of complicated source code to access to some native APIs to produce the expected behavior.

Have you tried "-Dsun.java2d.trace=log"? If so, what does it mention?

"-Dsun.java2d.opengl.fbobject=false"?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Frame with transparent background

gouessej
Administrator
In reply to this post by Christophe LAFOLET
It's a known concern:
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6655001

We'll need to disable HW acceleration (both OpenGL and
D3D pipelines) for non-opaque windows on systems other
than Vista.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Frame with transparent background

Sven Gothel
Administrator
In reply to this post by gouessej

On 2/6/20 10:27 AM, gouessej [via jogamp] wrote:

> Ok. Why not filling a bug report against Oracle Java?
>
> In my humble opinion, it might be a limitation of Java2D OpenGL pipeline which
> was implemented earlier than the public API for translucent windows (the
> private API for that is a lot older, see AWTUtilities).
>
> You claim that it's a simple case but it requires a lot of complicated source
> code to access to some native APIs to produce the expected behavior.
>
> Have you tried "-Dsun.java2d.trace=log"? If so, what does it mention?
>
> "-Dsun.java2d.opengl.fbobject=false"?

and ..

On 2/6/20 10:37 AM, gouessej [via jogamp] wrote:
> It's a known concern:
> https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6655001
>
>     We'll need to disable HW acceleration (both OpenGL and
>     D3D pipelines) for non-opaque windows on systems other
>     than Vista.

Great digging Julien.

Yes, it is a complicated not well supported experimental
feature. AFAIK AWT and Swing is hardly supported these days.

Complicated due to side effects and not specified implementation
of the renderer backend - even though it did its job quite well.

This is the same criticism I throw towards OpenJFX,
blackboxing the renderer by intention does not allow others
to benefit from it and maintenance for 3rd parties is hard.

Hence my 'long sighted' proposal for OpenJFX to utilize
NEWT and JOGL (OpenGL or Vulkan) for the OpenJFX backend
<https://jogamp.org/bugzilla//show_bug.cgi?id=607#c20>
This is how we had it in the earlier days ;-)

~Sven
Reply | Threaded
Open this post in threaded view
|

Re: Frame with transparent background

Christophe LAFOLET
Hello

The problem is in file sun/java2d/opengl/GLXGraphicsConfig.c
In the method GLXGC_InitFBConfig(), a score is computed to select a visual with the minimal Vram usage but it do not take into account the alpha.
According to the list of visuals, if the visuals with alpha are at the beginning of the list, they can be selected, if they are at the end of the list (our case), they are never selected.

Christophe