JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug816OSXCALayerPos03aB729AWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.awt;
30
31import java.awt.BorderLayout;
32import java.awt.Checkbox;
33import java.awt.Frame;
34import java.awt.event.ItemEvent;
35import java.awt.event.ItemListener;
36import java.lang.reflect.InvocationTargetException;
37
38import com.jogamp.opengl.GLCapabilities;
39import com.jogamp.opengl.GLProfile;
40import com.jogamp.opengl.awt.GLCanvas;
41
42import org.junit.Assert;
43import org.junit.FixMethodOrder;
44import org.junit.Test;
45import org.junit.runners.MethodSorters;
46
47import com.jogamp.newt.event.TraceWindowAdapter;
48import com.jogamp.newt.event.awt.AWTWindowAdapter;
49import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
50import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
51import com.jogamp.opengl.test.junit.util.MiscUtils;
52import com.jogamp.opengl.test.junit.util.QuitAdapter;
53import com.jogamp.opengl.test.junit.util.UITestCase;
54import com.jogamp.opengl.util.Animator;
55
56/**
57 * AWT Frame BorderLayout w/ Checkbox North, GLCanvas Center.
58 * <p>
59 * Checkbox toggles GLCanvas visibility state.
60 * </p>
61 * <p>
62 * Validates bugs:
63 * <ul>
64 * <li>Bug 816: OSX CALayer Positioning Bug</li>
65 * <li>Bug 729: OSX CALayer shall honor the Component's visibility state</li>
66 * </ul>
67 * </p>
68 * <p>
69 * Diff. OSX CALayer positioning w/ java6, [7uxx..7u40[, and >= 7u40
70 * </p>
71 */
72@FixMethodOrder(MethodSorters.NAME_ASCENDING)
74 static long duration = 1600; // ms
75 static int width=640, height=480;
76
77 @Test
78 public void test() throws InterruptedException, InvocationTargetException {
79 final GLCapabilities caps = new GLCapabilities(getGLP());
80
81 final Frame frame = new Frame("TestBug816OSXCALayerPos03aAWT");
82 Assert.assertNotNull(frame);
83
84 final GLCanvas glCanvas1 = new GLCanvas(caps);
85 Assert.assertNotNull(glCanvas1);
86 glCanvas1.addGLEventListener(new GearsES2(1));
87
88 final Animator animator = new Animator();
89 animator.add(glCanvas1);
90
91 final QuitAdapter quitAdapter = new QuitAdapter();
92 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame);
93
94 // Create a check box that hides / shows canvas
95 final Checkbox checkbox = new Checkbox("Visible canvas", true);
96 checkbox.addItemListener(new ItemListener() {
97 public void itemStateChanged(final ItemEvent ev) {
98 final boolean visible = checkbox.getState();
99 System.err.println("XXXX Canvas setVisible "+visible);
100 glCanvas1.setVisible(visible);
101 System.err.println("XXXX Canvas visible: "+glCanvas1.isVisible());
102 if( glCanvas1.isVisible() ) {
103 frame.validate(); // take care of resized frame while hidden
104 }
105 }
106 });
107
108 // Build a GUI that displays canvas and check box
109 frame.setLayout(new BorderLayout());
110 frame.add(glCanvas1, BorderLayout.CENTER);
111 frame.add(checkbox, BorderLayout.NORTH);
112
113 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
114 public void run() {
115 frame.setSize(width, height);
116 frame.setVisible(true);
117 }});
118 Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true, null));
119 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true, null));
120
121 animator.start();
122 Assert.assertTrue(animator.isStarted());
123 Assert.assertTrue(animator.isAnimating());
124
125 final long t0 = System.currentTimeMillis();
126 long t1 = t0;
127 while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
128 Thread.sleep(100);
129 t1 = System.currentTimeMillis();
130 }
131
132 Assert.assertNotNull(frame);
133 Assert.assertNotNull(glCanvas1);
134
135 Assert.assertNotNull(animator);
136 animator.stop();
137 Assert.assertFalse(animator.isAnimating());
138 Assert.assertFalse(animator.isStarted());
139
140 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
141 public void run() {
142 frame.setVisible(false);
143 }});
144 Assert.assertEquals(false, frame.isVisible());
145 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
146 public void run() {
147 frame.remove(glCanvas1);
148 frame.dispose();
149 }});
150 }
151
152 static GLProfile getGLP() {
154 }
155
156 public static void main(final String args[]) {
157 for(int i=0; i<args.length; i++) {
158 if(args[i].equals("-time")) {
159 i++;
160 duration = MiscUtils.atol(args[i], duration);
161 }
162 }
163
164 org.junit.runner.JUnitCore.main(TestBug816OSXCALayerPos03aB729AWT.class.getName());
165 }
166}
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getMaxProgrammableCore(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the programmable shader core pipeline only.
Definition: GLProfile.java:854
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
static boolean waitForRealized(final java.awt.Component comp, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368