29package com.jogamp.opengl.test.junit.jogl.javafx;
31import com.jogamp.opengl.GLAutoDrawable;
32import com.jogamp.opengl.GLCapabilities;
33import com.jogamp.opengl.GLCapabilitiesImmutable;
34import com.jogamp.opengl.GLEventListener;
35import com.jogamp.opengl.GLProfile;
37import org.junit.Assert;
38import org.junit.Assume;
39import org.junit.Before;
40import org.junit.BeforeClass;
41import org.junit.After;
42import org.junit.AfterClass;
44import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
47import com.jogamp.common.util.RunnableTask;
48import com.jogamp.nativewindow.javafx.JFXAccessor;
49import com.jogamp.newt.NewtFactory;
50import com.jogamp.newt.Screen;
51import com.jogamp.newt.event.WindowAdapter;
52import com.jogamp.newt.event.WindowEvent;
53import com.jogamp.newt.javafx.NewtCanvasJFX;
54import com.jogamp.newt.opengl.GLWindow;
55import com.jogamp.newt.opengl.util.NEWTDemoListener;
56import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
57import com.jogamp.opengl.test.junit.jogl.demos.es2.MultisampleDemoES2;
58import com.jogamp.opengl.test.junit.newt.parenting.NewtJFXReparentingKeyAdapter;
59import com.jogamp.opengl.test.junit.newt.parenting.NewtReparentingKeyAdapter;
60import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
61import com.jogamp.opengl.test.junit.util.MiscUtils;
62import com.jogamp.opengl.test.junit.util.NewtTestUtil;
63import com.jogamp.opengl.test.junit.util.UITestCase;
64import com.jogamp.opengl.util.Animator;
65import com.jogamp.opengl.util.GLReadBufferUtil;
66import com.jogamp.opengl.util.texture.TextureIO;
68import javafx.application.Application;
69import javafx.application.Platform;
70import javafx.beans.value.ChangeListener;
71import javafx.beans.value.ObservableValue;
72import javafx.scene.Group;
73import javafx.scene.Scene;
74import javafx.scene.canvas.Canvas;
75import javafx.scene.canvas.GraphicsContext;
76import javafx.scene.paint.Color;
77import javafx.scene.text.Font;
78import javafx.scene.text.Text;
79import javafx.stage.Stage;
104@FixMethodOrder(MethodSorters.NAME_ASCENDING)
107 static int duration = 5000;
108 static int manualTestID = -1;
112 public static class JFXApp extends Application {
115 final static Object sync =
new Object();
116 static volatile boolean isLaunched =
false;
121 @Override
public void init() throws Exception {
123 System.err.println(
"JFX init ...: "+Thread.currentThread());
126 @Override
public void start(
final Stage stage) {
127 System.err.println(
"JFX start.0 ...: "+Thread.currentThread());
131 final Scene scene =
new Scene(
new Group(), defWidth, defHeight);
133 stage.setScene(scene);
137 System.err.println(
"t1 - Native window: 0x"+Long.toHexString(h));
142 System.err.println(
"t2 - Native window: 0x"+Long.toHexString(h));
144 JFXApp.stage = stage;
150 System.err.println(
"JFX start.X ...: "+Thread.currentThread());
152 @Override
public void stop() throws Exception {
153 System.err.println(
"JFX stop ...: "+Thread.currentThread());
155 public static void startup() throws InterruptedException {
159 Platform.setImplicitExit(
false);
161 final Thread ct = Thread.currentThread();
162 RunnableTask.invokeOnNewThread(ct.getThreadGroup(), ct.getName()+
"JFXLauncher",
false,
165 Application.launch(
JFXApp.class);
172 System.err.println(
"JFX launched ...");
178 if(
null != stage ) {
186 public static void startup() throws InterruptedException {
203 jfxNewtDisplay =
null;
206 class WaitAction
implements Runnable {
207 private final long sleepMS;
209 WaitAction(
final long sleepMS) {
210 this.sleepMS = sleepMS;
215 Thread.sleep(sleepMS);
216 }
catch (
final InterruptedException e) { }
219 final WaitAction awtRobotWaitAction =
new WaitAction(AWTRobotUtil.TIME_SLICE);
220 final WaitAction generalWaitAction =
new WaitAction(10);
222 static final int defWidth = 800, defHeight = 600;
224 static void populateScene(
final Scene scene,
final boolean postAttach,
225 final GLWindow glWindow,
226 final int width,
final int height,
final boolean useBorder,
227 final NewtCanvasJFX[] res) {
228 final javafx.stage.Window w = scene.getWindow();
229 final boolean isShowing =
null != w && w.isShowing();
230 final Group g =
new Group();
232 final int cx, cy, cw, ch, bw, bh;
234 bw = width/5; bh = height/5;
235 cx = bw; cy = bh; cw = width-bw-bw; ch = height-bh-bh;
238 cx = 0; cy = 0; cw = width; ch = height;
240 System.err.println(
"Scene "+width+
"x"+height+
", isShowing "+isShowing+
", postAttach "+postAttach);
241 System.err.println(
"Scene.canvas "+cx+
"/"+cy+
" "+cw+
"x"+ch);
242 System.err.println(
"Scene.border "+bw+
"x"+bh);
246 JFXAccessor.runOnJFXThread(
true,
new Runnable() {
256 final Canvas canvas0;
258 canvas0 =
new Canvas();
260 res[0] =
new NewtCanvasJFX( glWindow );
263 canvas0.setWidth(cw);
264 canvas0.setHeight(ch);
266 final GraphicsContext gc = canvas0.getGraphicsContext2D();
267 gc.setFill(Color.BLUE);
268 gc.fillRect(0, 0, cw, ch);
270 canvas0.relocate(cx, cy);
272 final Text text0 =
new Text(0, 0,
"left");
274 text0.setFont(
new Font(40));
275 text0.relocate(0, height/2);
277 final Text text1 =
new Text(0, 0,
"above");
279 text1.setFont(
new Font(40));
280 text1.relocate(width/2, bh-40);
282 final Text text2 =
new Text(0, 0,
"right");
284 text2.setFont(
new Font(40));
285 text2.relocate(width-bw, height/2);
287 final Text text3 =
new Text(0, 0,
"below");
289 text3.setFont(
new Font(40));
290 text3.relocate(width/2, height-bh);
292 final Runnable attach2Group =
new Runnable() {
295 g.getChildren().add(text0);
296 g.getChildren().add(text1);
297 g.getChildren().add(canvas0);
298 g.getChildren().add(text2);
299 g.getChildren().add(text3);
301 if( !postAttach && isShowing ) {
302 JFXAccessor.runOnJFXThread(
true, attach2Group);
308 JFXAccessor.runOnJFXThread(
true,
new Runnable() {
320 final boolean postAttachNewtCanvas,
final boolean postAttachGLWindow,
321 final boolean useAnimator )
throws InterruptedException {
323 System.err.println(
"JFX not available");
333 Assert.assertNotNull(glWindow1);
334 Assert.assertEquals(
false, glWindow1.
isVisible());
336 Assert.assertNull(glWindow1.
getParent());
339 int displayCount = 0;
341 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) { }
343 if(displayCount < 3) {
344 snapshot(displayCount++,
null, drawable.
getGL(), screenshot,
TextureIO.
PNG,
null);
353 final Scene scene =
new Scene(
new Group(), defWidth, defHeight);
354 if(!postAttachNewtCanvas) {
355 System.err.println(
"Stage set.A0");
358 System.err.println(
"Stage set.A1");
359 JFXApp.stage.setScene(scene);
360 JFXApp.stage.sizeToScene();
361 System.err.println(
"Stage set.AX");
364 populateScene( scene, postAttachNewtCanvas, postAttachGLWindow?
null:glWindow1, defWidth, defHeight,
true, glCanvas);
365 if(postAttachNewtCanvas) {
366 System.err.println(
"Stage set.B0");
369 System.err.println(
"Stage set.B1");
370 JFXApp.stage.setScene(scene);
371 JFXApp.stage.sizeToScene();
372 System.err.println(
"Stage set.BX");
376 if(postAttachGLWindow &&
null != demo) {
380 if(
null != glWindow1 ) {
397 final ChangeListener<Number> sizeListener =
new ChangeListener<Number>() {
398 @Override
public void changed(
final ObservableValue<? extends Number> observable,
final Number oldValue,
final Number newValue) {
401 JFXApp.stage.widthProperty().addListener(sizeListener);
402 JFXApp.stage.heightProperty().addListener(sizeListener);
406 System.err.println(
"NewtCanvasJFX LOS.0: "+glCanvas[0].getNativeWindow().getLocationOnScreen(
null));
410 if(useAnimator &&
null != demo) {
417 final long lStartTime = System.currentTimeMillis();
418 final long lEndTime = lStartTime + duration;
420 while( (System.currentTimeMillis() < lEndTime) ) {
421 generalWaitAction.run();
423 }
catch(
final Throwable throwable ) {
424 throwable.printStackTrace();
425 Assume.assumeNoException( throwable );
433 populateScene(
JFXApp.stage.getScene(),
false,
null, defWidth, defHeight,
true,
null);
434 JFXApp.stage.sizeToScene();
439 public void test00() throws InterruptedException {
440 if( 0 > manualTestID || 0 == manualTestID ) {
441 runTestAGL(
null,
null,
442 false ,
false ,
false );
448 if( 0 > manualTestID || 11 == manualTestID ) {
450 false ,
false ,
false );
456 if( 0 > manualTestID || 12 == manualTestID ) {
458 true ,
false ,
false );
464 if( 0 > manualTestID || 13 == manualTestID ) {
466 false ,
true ,
false );
472 if( 0 > manualTestID || 14 == manualTestID ) {
474 true ,
true ,
false );
480 if( 0 > manualTestID || 21 == manualTestID ) {
482 false ,
false ,
true );
488 if( 0 > manualTestID || 22 == manualTestID ) {
490 true ,
false ,
true );
496 if( 0 > manualTestID || 30 == manualTestID ) {
501 false ,
false ,
false );
505 public static void main(
final String args[]) {
506 for(
int i=0; i<args.length; i++) {
507 if(args[i].equals(
"-time")) {
510 if(args[i].equals(
"-test")) {
514 System.out.println(
"durationPerTest: "+duration+
", test "+manualTestID);
static long getWindowHandle(final Window stageWindow)
static boolean isJFXAvailable()
static void runOnJFXThread(final boolean wait, final Runnable task)
Runs given task on the JFX Thread if it has not stopped and if caller is not already on the JFX Threa...
static Display createDisplay(final String name)
Create a Display entity.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
NEWT Window events are provided for notification purposes ONLY.
A NEWT based JFX Canvas specialization allowing a NEWT child Window to be attached using native paren...
Window setNEWTChild(final Window newChild)
Sets a new NEWT child, provoking reparenting.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Point getLocationOnScreen(final Point storage)
Returns the window's top-left client-area position in the screen.
final NativeWindow getParent()
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final boolean isNativeValid()
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
final int getX()
Returns the current x position of this window, relative to it's parent.
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
final boolean isVisible()
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
void quitAdapterEnable(final boolean v)
Specifies a set of OpenGL capabilities.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
Specifies the the OpenGL profile.
static String glAvailabilityToString(final AbstractGraphicsDevice device)
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
void start(final Stage stage)
NewtCanvasJFX basic functional integration test of its native parented NEWT child GLWindow attached t...
void runTestAGL(final GLCapabilitiesImmutable caps, final GLEventListener demo, final boolean postAttachNewtCanvas, final boolean postAttachGLWindow, final boolean useAnimator)
void test14_postAttachNewtGL_NoAnim()
static void main(final String args[])
void test21_preAttachNewtGL_DoAnim()
void test30_MultisampleAndAlpha()
void test12_postAttachNewt_NoAnim()
void test22_postAttachNewt_DoAnim()
void test13_postAttachGL_NoAnim()
void test11_preAttachNewtGL_NoAnim()
JavaFX specializing demo functionality of NewtReparentingKeyAdapter, includes NEWTDemoListener.
Extending demo functionality of NEWTDemoListener.
static int atoi(final String str, final int def)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
static final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.