JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
ExclusiveContextBase00AWT.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.acore.ect;
30
31import java.awt.BorderLayout;
32import java.awt.Component;
33import java.awt.Container;
34import java.awt.Dimension;
35import java.awt.EventQueue;
36import java.awt.Frame;
37
38import com.jogamp.opengl.GLAutoDrawable;
39import com.jogamp.opengl.GLCapabilitiesImmutable;
40import com.jogamp.opengl.awt.GLCanvas;
41
42import org.junit.Assert;
43import org.junit.BeforeClass;
44import org.junit.AfterClass;
45import org.junit.FixMethodOrder;
46import org.junit.runners.MethodSorters;
47
48import com.jogamp.common.os.Platform;
49import com.jogamp.common.util.VersionNumber;
50
51/**
52 * ExclusiveContextThread base implementation to test correctness of the ExclusiveContext feature _and_ AnimatorBase with AWT.
53 */
54@FixMethodOrder(MethodSorters.NAME_ASCENDING)
56
57 static Thread awtEDT;
58 static boolean osxCALayerAWTModBug;
59
60 @BeforeClass
61 public static void initClass00AWT() {
62
63 final VersionNumber version170 = new VersionNumber(1, 7, 0);
64 osxCALayerAWTModBug = Platform.OSType.MACOS == Platform.getOSType() &&
65 0 > Platform.getJavaVersionNumber().compareTo(version170);
66 System.err.println("OSX CALayer AWT-Mod Bug "+osxCALayerAWTModBug);
67 System.err.println("OSType "+Platform.getOSType());
68 System.err.println("Java Version "+Platform.getJavaVersionNumber());
69
70 try {
71 EventQueue.invokeAndWait(new Runnable() {
72 public void run() {
73 awtEDT = Thread.currentThread();
74 } } );
75 } catch (final Exception e) {
76 e.printStackTrace();
77 Assert.assertNull(e);
78 }
79
80 }
81
82 @AfterClass
83 public static void releaseClass00AWT() {
84 }
85
86 @Override
87 protected boolean isAWTTestCase() { return true; }
88
89 @Override
90 protected Thread getAWTRenderThread() {
91 return awtEDT;
92 }
93
94 @Override
95 protected GLAutoDrawable createGLAutoDrawable(final String title, final int x, final int y, final int width, final int height, final GLCapabilitiesImmutable caps) {
96 final GLCanvas glCanvas = new GLCanvas();
97
98 // FIXME: Below AWT layouts freezes OSX/Java7 @ setVisible: Window.setVisible .. CWrapper@NSWindow.isKeyWindow
99 // final Dimension sz = new Dimension(width, height);
100 // glCanvas.setMinimumSize(sz);
101 // glCanvas.setPreferredSize(sz);
102 // glCanvas.setSize(sz);
103 try {
104 EventQueue.invokeAndWait(new Runnable() {
105 public void run() {
106 final Frame frame = new Frame();
107 frame.setLayout(new BorderLayout());
108 frame.setMinimumSize(new Dimension(width, height));
109 frame.setBounds(x, y, width, height);
110 frame.add(glCanvas, BorderLayout.CENTER);
111 // frame.pack();
112 frame.validate();
113 if( !osxCALayerAWTModBug ) {
114 frame.setTitle(title);
115 }
116 } });
117 } catch (final Exception e) {
118 e.printStackTrace();
119 Assert.assertNull(e);
120 }
121
122 return glCanvas;
123 }
124
125 protected Frame getFrame(final GLAutoDrawable glad) {
126 Container p = ((Component)glad).getParent();
127 while( null != p && !( p instanceof Frame ) ) {
128 p = p.getParent();
129 }
130 return (Frame)p;
131 }
132
133 @Override
134 protected void setGLAutoDrawableVisible(final GLAutoDrawable[] glads) {
135 try {
136 EventQueue.invokeAndWait(new Runnable() {
137 public void run() {
138 final int count = glads.length;
139 for(int i=0; i<count; i++) {
140 final GLAutoDrawable glad = glads[i];
141 final Frame frame = getFrame(glad);
142 frame.setVisible(true);
143 }
144 } } );
145 } catch (final Exception e) {
146 e.printStackTrace();
147 Assert.assertNull(e);
148 }
149 }
150
151 @Override
152 protected void destroyGLAutoDrawableVisible(final GLAutoDrawable glad) {
153 final Frame frame = getFrame(glad);
154 try {
155 EventQueue.invokeAndWait(new Runnable() {
156 public void run() {
157 frame.dispose();
158 } } );
159 } catch (final Exception e) {
160 e.printStackTrace();
161 Assert.assertNull(e);
162 }
163 }
164}
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
ExclusiveContextThread base implementation to test correctness of the ExclusiveContext feature and An...
GLAutoDrawable createGLAutoDrawable(final String title, final int x, final int y, final int width, final int height, final GLCapabilitiesImmutable caps)
ExclusiveContextThread base implementation to test correctness of the ExclusiveContext feature and An...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
Specifies an immutable set of OpenGL capabilities.