useful Java2D bridge

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

Re: useful Java2D bridge

Martin
Hi,
No problem to test glg2d on this app, however I unfortunately can't share the source code it will work on.
When I tried your library few month ago, I used to log Graphics2D.getClass().getName() into the renderer main draw(Graphics2D) method, and it did not seam to be any object of your library so we might work on that :).
Do you suggest any tracking/testing method?
Cheers,
Martin



2012/2/17 Brandon Borkholder [via jogamp] <[hidden email]>

Martin, it would be useful to have you app as a testcase.  Java2D painting is amazingly convoluted and I've found it really hard to make sure swing components are being painted in glg2d and not in Java2D.

There's an effort to modularize the painting so it can be delegated properly. Marrio Torre (I believe with Roman Kennke) developed Caciocavallo http://ladybug-studio.com/caciocavallo/ and the idea is to make it easy to have one place to change the painting subsystem. I've been wanting to look at their code, maybe even leverage it.

But the short answer is that you might be right. So far, I've found no speedup when using swing repainting (my UIDemo class) and multiple levels of JComponents. I think the problem is a combination of too much logic in deciding what to paint and being expensive to fire an OpenGL display call when a little button just wants to repaint the border.

But if you ignore that and look at my GraphTest class (a single JPanel painting a lot of objects) glg2d wins easily. It's much more responsive when making a lot of Graphics2D calls on the same paint call.




If you reply to this email, your message will be added to the discussion below:
http://forum.jogamp.org/useful-Java2D-bridge-tp3391708p3753434.html
To unsubscribe from useful Java2D bridge, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: useful Java2D bridge

Brandon Borkholder
On Fri, Feb 17, 2012 at 11:47, Martin [via jogamp] <[hidden email]> wrote:
Hi,
No problem to test glg2d on this app, however I unfortunately can't share the source code it will work on.
When I tried your library few month ago, I used to log Graphics2D.getClass().getName() into the renderer main draw(Graphics2D) method, and it did not seam to be any object of your library so we might work on that :).
Do you suggest any tracking/testing method?
Cheers,
Martin

That's the tricky part.  In many cases I had to put a breakpoint in JComponent.paint(Graphics) to make sure my GLGraphics2D object was being passed in.  It's very difficult to discover how Swing will paint a component because it varies by component and situation.

You mentioned that the issue occurred with JDesktopPane and JInternalFrames.  I haven't tested with those, but I can modify my UIDemo to include those and then I'll be able to test.
Reply | Threaded
Open this post in threaded view
|

Re: useful Java2D bridge

Martin
In reply to this post by Brandon Borkholder
Hi,
Sorry for late reply. I have written a class that simply visits components in order to print the class name of component.getGraphics() (see end of this message).

I was surprised to see what follows, so I believe something might be wrong in my test:

GraphTest: sun.java2d.SunGraphics2D
 JRootPane: sun.java2d.SunGraphics2D
  JPanel: sun.java2d.SunGraphics2D
  JLayeredPane: sun.java2d.SunGraphics2D
   G2DGLPanel: sun.java2d.SunGraphics2D
    GLJPanel: sun.java2d.SunGraphics2D
    NO_CLASS_NAME: sun.java2d.SunGraphics2D

What I do is calling a diagnostic once the main frame is made visible:

public static void main(String[] args) throws Exception {
    JFrame test = new GraphTest();
    ...
    test.setVisible(true);
   
    GraphicsDiagnose gd = new GraphicsDiagnose();
    gd.printGraphics(test);
}

Am I wrong somewhere? Will the GLGraphics2D replace default SunGraphics2D latter?

Martin

--------------------------------------
public class GraphicsDiagnose {
    protected boolean shortName = false;
   
    public void printGraphics(Component c){
        printGraphics(c, 0);
    }
   
    protected void printGraphics(Component c, int depth){
        if(c==null)
            System.out.println(blanks(depth) + "component null");
        else{
            String className = c.getClass().getSimpleName();
            String me = blanks(depth) + ("".equals(className)?"NO_CLASS_NAME":className);
           
            if(c.getGraphics()!=null){
                if(shortName)
                    me += ": " + c.getGraphics().getClass().getSimpleName();
                else
                    me += ": " + c.getGraphics().getClass().getName();
            }
            else
                me += ": graphics is null at this point";
           
            System.out.println(me);
           
            if(c instanceof Container){
                Container ct = ((Container)c);
                for(Component child: ct.getComponents()){
                    printGraphics(child, depth+1);
                }
            }            
        }
    }
   
    protected String blanks(int length){
        String b = "";
        for (int i = 0; i < length; i++)
            b += " ";
        return b;
    }
}
 
Reply | Threaded
Open this post in threaded view
|

Re: useful Java2D bridge

Martin
By the way, I am using a clone of your git repository and the last log is:
03efe90f3d044d287842e0ee263d0a23bc80d7a3 I was working off jdk7 but now removed

I use JOGL2 RC5.

Also added a Thread.sleep(10000) before diagnostic just in case Graphics2D get replaced latter, but it did not change anything.

2012/2/29 Martin [via jogamp] <[hidden email]>
Hi,
Sorry for late reply. I have written a class that simply visits components in order to print the class name of component.getGraphics() (see end of this message).

I was surprised to see what follows, so I believe something might be wrong in my test:

GraphTest: sun.java2d.SunGraphics2D
 JRootPane: sun.java2d.SunGraphics2D
  JPanel: sun.java2d.SunGraphics2D
  JLayeredPane: sun.java2d.SunGraphics2D
   G2DGLPanel: sun.java2d.SunGraphics2D
    GLJPanel: sun.java2d.SunGraphics2D
    NO_CLASS_NAME: sun.java2d.SunGraphics2D

What I do is calling a diagnostic once the main frame is made visible:

public static void main(String[] args) throws Exception {
    JFrame test = new GraphTest();
    ...
    test.setVisible(true);
   
    GraphicsDiagnose gd = new GraphicsDiagnose();
    gd.printGraphics(test);
}

Am I wrong somewhere? Will the GLGraphics2D replace default SunGraphics2D latter?

Martin

--------------------------------------
public class GraphicsDiagnose {
    protected boolean shortName = false;
   
    public void printGraphics(Component c){
        printGraphics(c, 0);
    }
   
    protected void printGraphics(Component c, int depth){
        if(c==null)
            System.out.println(blanks(depth) + "component null");
        else{
            String className = c.getClass().getSimpleName();
            String me = blanks(depth) + ("".equals(className)?"NO_CLASS_NAME":className);
           
            if(c.getGraphics()!=null){
                if(shortName)
                    me += ": " + c.getGraphics().getClass().getSimpleName();
                else
                    me += ": " + c.getGraphics().getClass().getName();
            }
            else
                me += ": graphics is null at this point";
           
            System.out.println(me);
           
            if(c instanceof Container){
                Container ct = ((Container)c);
                for(Component child: ct.getComponents()){
                    printGraphics(child, depth+1);
                }
            }            
        }
    }
   
    protected String blanks(int length){
        String b = "";
        for (int i = 0; i < length; i++)
            b += " ";
        return b;
    }
}
 


If you reply to this email, your message will be added to the discussion below:
http://forum.jogamp.org/useful-Java2D-bridge-tp3391708p3786990.html
To unsubscribe from useful Java2D bridge, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: useful Java2D bridge

Brandon Borkholder
Martin, I'm sorry for taking so long to reply.  I've been looking into that issue and I have only a partial answer so far.

Component.getGraphics() is not the right way check if the component is being drawn with GLGraphics2D.  I'm still learning a lot about Swing painting, but most painting calls happen when *something* calls JComponent.paint(Graphics) on the top level, which then calls paint(Graphics) on all the children with the same Graphics object.  So it doesn't matter what JComponent.getGraphics() returns, it matters what's being passed in.  And in my testing, I can verify that's usually the case (unless there's a bug).

The second part of your question - what's the right way to verify then?  Well, I've been trying to use Javassist, Guice, ASM or other libraries to instrument JComponent.paint(Graphics) and print out the Graphics class if it's not GLGraphics2D.  That would tell us painting is not being done into OpenGL.

But that's a work in progress...
Reply | Threaded
Open this post in threaded view
|

Re: useful Java2D bridge

Martin
Brandon Borkholder wrote
Martin, I'm sorry for taking so long to reply.  I've been looking into that
issue and I have only a partial answer so far.
Nooo, sorry for my impatience!

Component.getGraphics() is not the right way check if the component is
being drawn with GLGraphics2D.  I'm still learning a lot about Swing
painting, but most painting calls happen when *something* calls
JComponent.paint(Graphics) on the top level, which then calls
paint(Graphics) on all the children with the same Graphics object.  So it
doesn't matter what JComponent.getGraphics() returns, it matters what's
being passed in.  And in my testing, I can verify that's usually the case
(unless there's a bug).
Thanks for clarifying. Indeed, still in your GraphTest demo, adding:

JPanel paintingComponent = new JPanel() {
  ...
  public void paint(Graphics g){
        super.paint(g);
        System.out.println(g);
  }
};

really print:
glg2d.GLGraphics2D[font=javax.swing.plaf.FontUIResource[family=Dialog,name=Dialog,style=plain,size=12],color=sun.swing.PrintColorUIResource[r=51,g=51,b=51]]



The second part of your question - what's the right way to verify then?
Well, I've been trying to use Javassist, Guice, ASM or other libraries to
instrument JComponent.paint(Graphics) and print out the Graphics class if
it's not GLGraphics2D.  That would tell us painting is not being done into
OpenGL.

But that's a work in progress...
If you want me to test it, do not hesitate to send a piece of javassist or similar code to instrument the painting methods of my component stack.
Reply | Threaded
Open this post in threaded view
|

Re: useful Java2D bridge

Brandon Borkholder
If you want me to test it, do not hesitate to send a piece of javassist or similar code to instrument the painting methods of my component stack.


That would be great.  I just committed a change that adds a new class to the test code, called glg2d.misc.InstrumentPaint.  If you call InstrumentPaint.instrument() as the first line in your main and then use the GLG2D library, it will print to stderr every time a component gets painted with the SunGraphics2D object.

I'd be very interested to hear about your results.
12