JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug642JSplitPaneMixHwLw01AWT.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.junit.jogl.awt;
2
3import java.awt.BorderLayout;
4// import java.awt.Canvas;
5import java.awt.Component;
6import java.awt.Container;
7import java.awt.Dimension;
8import java.awt.GraphicsConfiguration;
9import java.awt.Rectangle;
10import java.awt.Shape;
11import java.io.IOException;
12
13import com.jogamp.opengl.GLAnimatorControl;
14import com.jogamp.opengl.GLAutoDrawable;
15import com.jogamp.opengl.GLCapabilities;
16import com.jogamp.opengl.GLProfile;
17import com.jogamp.opengl.awt.GLCanvas;
18import com.jogamp.opengl.awt.GLJPanel;
19import javax.swing.JFrame;
20import javax.swing.JPanel;
21import javax.swing.JScrollPane;
22import javax.swing.JSplitPane;
23import javax.swing.WindowConstants;
24
25import org.junit.Assert;
26import org.junit.Assume;
27import org.junit.Test;
28import org.junit.FixMethodOrder;
29import org.junit.runners.MethodSorters;
30
31import com.jogamp.common.util.ReflectionUtil;
32import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
33import com.jogamp.opengl.test.junit.util.MiscUtils;
34import com.jogamp.opengl.test.junit.util.UITestCase;
35import com.jogamp.opengl.util.Animator;
36import com.jogamp.opengl.util.FPSAnimator;
37
38/**
39 * Documenting Bug 642 (related to Bug 586)
40 *
41 * <p>
42 * JSplitPane cannot mix hw/lw components, only if setting property '-Dsun.awt.disableMixing=true'.
43 * </p>
44 * See Bug 586
45 * See git commit '8df12ca151dfc577c90b485d4ebfe491b88e55aa'.
46 */
47@FixMethodOrder(MethodSorters.NAME_ASCENDING)
49 static long durationPerTest = 500;
50
51 static {
52 // too late: use at cmd-line '-Dsun.awt.disableMixing=true' works
53 // System.setProperty("sun.awt.disableMixing", "true");
54 }
55
56 /**
57 * Doesn't work either ..
58 */
59 @SuppressWarnings("serial")
60 public static class TransparentJScrollPane extends JScrollPane {
61
62 public TransparentJScrollPane(final Component view) {
63 super(view);
64
65 setOpaque(false);
66
67 try {
68 ReflectionUtil.callStaticMethod(
69 "com.sun.awt.AWTUtilities", "setComponentMixingCutoutShape",
70 new Class<?>[] { Component.class, Shape.class },
71 new Object[] { this, new Rectangle() } ,
72 GraphicsConfiguration.class.getClassLoader());
73 System.err.println("com.sun.awt.AWTUtilities.setComponentMixingCutoutShape(..) passed");
74 } catch (final RuntimeException re) {
75 System.err.println("com.sun.awt.AWTUtilities.setComponentMixingCutoutShape(..) failed: "+re.getMessage());
76 }
77 }
78
79 @Override
80 public void setOpaque(final boolean isOpaque) {
81 }
82 }
83
84 protected void runTestGL(final GLCapabilities caps, final boolean useGLJPanel, final boolean useContainer) throws InterruptedException {
85 final String typeS = useGLJPanel ? "LW" : "HW";
86 final JFrame frame = new JFrame("Mix Hw/Lw Swing - Canvas "+typeS);
87 Assert.assertNotNull(frame);
88
89 final Dimension f_sz = new Dimension(824,568);
90 // final Dimension f_sz = new Dimension(600,400);
91 // final Dimension glc_sz = new Dimension(500,600);
92
93 frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
94
95 final Component glComp;
96 final GLAutoDrawable glad;
97 if(useGLJPanel) {
98 final GLJPanel glJPanel = new GLJPanel(new GLCapabilities(GLProfile.getDefault()));
99 Assert.assertNotNull(glJPanel);
100 glJPanel.addGLEventListener(new GearsES2());
101 glComp = glJPanel;
102 glad = glJPanel;
103 } else {
104 final GLCanvas glCanvas = new GLCanvas(new GLCapabilities(GLProfile.getDefault()));
105 Assert.assertNotNull(glCanvas);
106 glCanvas.addGLEventListener(new GearsES2());
107 if( useContainer ) {
108 final Container cont = new Container();
109 cont.setLayout(new BorderLayout());
110 cont.add(glCanvas, BorderLayout.CENTER);
111 glComp = cont;
112 } else {
113 glComp = glCanvas;
114 }
115 glad = glCanvas;
116 }
117
118 final Container contentPane = frame.getContentPane();
119
120 final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
121 splitPane.setResizeWeight(0.5d);
122 splitPane.setLeftComponent(glComp);
123 // splitPane.setLeftComponent(new JPanel());
124 // splitPane.setLeftComponent(new Canvas());
125 splitPane.setRightComponent(new JPanel());
126 contentPane.add(splitPane, BorderLayout.CENTER);
127
128 final GLAnimatorControl animator = useGLJPanel ? new FPSAnimator(glad, 60) : new Animator(glad);
129 animator.start();
130
131 try {
132 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
133 public void run() {
134 frame.setPreferredSize(f_sz);
135 frame.setSize(f_sz.width+1, f_sz.height+1); // trick to force pack() to work!
136 frame.pack();
137 frame.setVisible(true);
138 // however, Hw/Lw mixing is still a problem ..
139 }});
140 } catch (final Throwable t) {
141 t.printStackTrace();
142 Assume.assumeNoException(t);
143 }
144
145 animator.setUpdateFPSFrames(60, System.err);
146 Thread.sleep(durationPerTest);
147
148 animator.stop();
149
150 try {
151 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
152 public void run() {
153 frame.setVisible(false);
154 frame.dispose();
155 }});
156 } catch (final Throwable t) {
157 t.printStackTrace();
158 Assume.assumeNoException(t);
159 }
160 }
161
162 @Test
163 public void test01JSplitPaneWithHwGLCanvasPlain() throws InterruptedException {
164 final GLProfile glp = GLProfile.getGL2ES2();
165 final GLCapabilities caps = new GLCapabilities(glp);
166 runTestGL(caps, false, false);
167 }
168
169 @Test
170 public void test02JSplitPaneWithHwGLCanvasContainer() throws InterruptedException {
171 final GLProfile glp = GLProfile.getGL2ES2();
172 final GLCapabilities caps = new GLCapabilities(glp);
173 runTestGL(caps, false, true);
174 }
175
176 @Test
177 public void test03JSplitPaneWithLwGLJPanel() throws InterruptedException {
178 final GLProfile glp = GLProfile.getGL2ES2();
179 final GLCapabilities caps = new GLCapabilities(glp);
180 runTestGL(caps, true, false);
181 }
182
183 public static void main(final String args[]) throws IOException {
184 for(int i=0; i<args.length; i++) {
185 if(args[i].equals("-time")) {
186 durationPerTest = MiscUtils.atol(args[++i], durationPerTest);
187 }
188 }
189 /**
190 BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
191 System.err.println("Press enter to continue");
192 System.err.println(stdin.readLine());
193 */
194 System.out.println("durationPerTest: "+durationPerTest);
195 final String tstname = TestBug642JSplitPaneMixHwLw01AWT.class.getName();
196 org.junit.runner.JUnitCore.main(tstname);
197 }
198
199}
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
A lightweight Swing component which provides OpenGL rendering support.
Definition: GLJPanel.java:189
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLJPanel.java:989
void runTestGL(final GLCapabilities caps, final boolean useGLJPanel, final boolean useContainer)
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
An Animator subclass which attempts to achieve a target frames-per-second rate to avoid using all CPU...
void setUpdateFPSFrames(int frames, PrintStream out)
An animator control interface, which implementation may drive a com.jogamp.opengl....
boolean start()
Starts this animator, if not running.
boolean stop()
Stops this animator.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...