JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
GLTestUtil.java
Go to the documentation of this file.
1/**
2 * Copyright 2019 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
29
30package com.jogamp.opengl.test.junit.util;
31
32import com.jogamp.opengl.GLAutoDrawable;
33import com.jogamp.opengl.GLContext;
34import com.jogamp.opengl.GLDrawable;
35
36public class GLTestUtil extends TestUtil {
37
38 /**
39 * @param waitAction if not null, Runnable shall wait {@link #TIME_SLICE} ms, if appropriate
40 * @return True if the GLContext becomes created or not within TIME_OUT
41 */
42 public static boolean waitForContextCreated(final GLAutoDrawable autoDrawable, final boolean created, final Runnable waitAction) throws InterruptedException {
43 if( null == autoDrawable ) {
44 return !created;
45 }
46 int wait;
47 for (wait=0; wait<POLL_DIVIDER ; wait++) {
48 final GLContext ctx = autoDrawable.getContext();
49 if( created ) {
50 if( null != ctx && ctx.isCreated() ) {
51 break;
52 }
53 } else {
54 if( null == ctx || !ctx.isCreated() ) {
55 break;
56 }
57 }
58 if( null != waitAction ) {
59 waitAction.run();
60 } else {
61 Thread.sleep(TIME_SLICE);
62 }
63 }
64 return wait<POLL_DIVIDER;
65 }
66
67 /**
68 *
69 * @param waitAction if not null, Runnable shall wait {@link #TIME_SLICE} ms, if appropriate
70 * @return True if the GLDrawable receives the expected surface size within TIME_OUT
71 */
72 public static boolean waitForSize(final GLDrawable drawable, final int width, final int height, final Runnable waitAction) throws InterruptedException {
73 int wait;
74 for (wait=0; wait<POLL_DIVIDER && ( width != drawable.getSurfaceWidth() || height != drawable.getSurfaceHeight() ) ; wait++) {
75 if( null != waitAction ) {
76 waitAction.run();
77 } else {
78 Thread.sleep(TIME_SLICE);
79 }
80 }
81 return wait<POLL_DIVIDER;
82 }
83
84 /**
85 * @param glad the GLAutoDrawable to wait for
86 * @param realized true if waiting for component to become realized, otherwise false
87 * @param waitAction if not null, Runnable shall wait {@link #TIME_SLICE} ms, if appropriate
88 * @return True if the Component becomes realized (not displayable, native invalid) within TIME_OUT
89 * @throws InterruptedException
90 */
91 public static boolean waitForRealized(final GLAutoDrawable glad, final boolean realized, final Runnable waitAction) throws InterruptedException {
92 final long t0 = System.currentTimeMillis();
93 long t1 = t0;
94 while( (t1-t0) < TIME_OUT && realized != glad.isRealized() ) {
95 if( null != waitAction ) {
96 waitAction.run();
97 } else {
98 Thread.sleep(TIME_SLICE);
99 }
100 t1 = System.currentTimeMillis();
101 }
102 final boolean to = (t1-t0) >= TIME_OUT;
103 final boolean ok = realized == glad.isRealized();
104 System.err.println("waitForRealized: to "+to+", goal reached "+ok);
105 return !to || ok;
106 }
107
108}
109
110
111
Abstraction for an OpenGL rendering context.
Definition: GLContext.java:74
final boolean isCreated()
Indicates whether the underlying native OpenGL context has been created.
Definition: GLContext.java:604
static boolean waitForRealized(final GLAutoDrawable glad, final boolean realized, final Runnable waitAction)
Definition: GLTestUtil.java:91
static boolean waitForSize(final GLDrawable drawable, final int width, final int height, final Runnable waitAction)
Definition: GLTestUtil.java:72
static boolean waitForContextCreated(final GLAutoDrawable autoDrawable, final boolean created, final Runnable waitAction)
Definition: GLTestUtil.java:42
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
An abstraction for an OpenGL rendering target.
Definition: GLDrawable.java:51