Esempio n. 1
0
  @Test
  public void testWindowParenting02CreateVisibleDestroy3Odd() throws InterruptedException {
    int x = 0;
    int y = 0;

    NEWTEventFiFo eventFifo = new NEWTEventFiFo();

    GLWindow glWindow1 = GLWindow.create(glCaps);
    GLEventListener demo1 = new RedSquare();
    setDemoFields(demo1, glWindow1, false);
    glWindow1.addGLEventListener(demo1);

    NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);

    Frame frame = new Frame("AWT Parent Frame");
    Assert.assertNotNull(frame);
    frame.setSize(width, height);

    // visible test
    frame.setVisible(true);

    frame.add(newtCanvasAWT);

    Animator animator1 = new Animator(glWindow1);
    animator1.start();
    while (animator1.isAnimating() && animator1.getDuration() < durationPerTest) {
      Thread.sleep(100);
    }

    Assert.assertEquals(true, animator1.isAnimating()); // !!!

    frame.dispose();
    glWindow1.destroy(true);
  }
Esempio n. 2
0
 public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
   Assert.assertNotNull(demo);
   Assert.assertNotNull(glWindow);
   Window window = glWindow.getInnerWindow();
   if (debug) {
     MiscUtils.setFieldIfExists(demo, "glDebug", true);
     MiscUtils.setFieldIfExists(demo, "glTrace", true);
   }
   if (!MiscUtils.setFieldIfExists(demo, "window", window)) {
     MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
   }
 }
Esempio n. 3
0
  @Test
  public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException {
    int x = 0;
    int y = 0;

    NEWTEventFiFo eventFifo = new NEWTEventFiFo();

    GLWindow glWindow1 = GLWindow.create(glCaps);
    Assert.assertNotNull(glWindow1);
    Assert.assertEquals(false, glWindow1.isVisible());
    Assert.assertEquals(false, glWindow1.isNativeWindowValid());
    Assert.assertNull(glWindow1.getParentNativeWindow());
    glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy");
    GLEventListener demo1 = new RedSquare();
    setDemoFields(demo1, glWindow1, false);
    glWindow1.addGLEventListener(demo1);

    NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);
    Assert.assertNotNull(newtCanvasAWT);
    Assert.assertEquals(false, glWindow1.isVisible());
    Assert.assertEquals(false, glWindow1.isNativeWindowValid());
    Assert.assertNull(glWindow1.getParentNativeWindow());

    Frame frame1 = new Frame("AWT Parent Frame");
    frame1.setLayout(new BorderLayout());
    frame1.add(new Button("North"), BorderLayout.NORTH);
    frame1.add(new Button("South"), BorderLayout.SOUTH);
    frame1.add(new Button("East"), BorderLayout.EAST);
    frame1.add(new Button("West"), BorderLayout.WEST);

    Container container1 = new Container();
    container1.setLayout(new BorderLayout());
    container1.add(new Button("north"), BorderLayout.NORTH);
    container1.add(new Button("south"), BorderLayout.SOUTH);
    container1.add(new Button("east"), BorderLayout.EAST);
    container1.add(new Button("west"), BorderLayout.WEST);
    container1.add(newtCanvasAWT, BorderLayout.CENTER);

    frame1.add(container1, BorderLayout.CENTER);
    frame1.setSize(width, height);

    // visible test
    frame1.setVisible(true);
    Assert.assertEquals(newtCanvasAWT.getNativeWindow(), glWindow1.getParentNativeWindow());

    Animator animator1 = new Animator(glWindow1);
    animator1.start();
    while (animator1.isAnimating() && animator1.getDuration() < durationPerTest) {
      Thread.sleep(100);
    }
    animator1.stop();
    Assert.assertEquals(false, animator1.isAnimating());

    frame1.setVisible(false);
    Assert.assertEquals(false, glWindow1.isDestroyed());

    frame1.setVisible(true);
    Assert.assertEquals(false, glWindow1.isDestroyed());

    frame1.remove(newtCanvasAWT);
    // Assert.assertNull(glWindow1.getParentNativeWindow());
    Assert.assertEquals(false, glWindow1.isDestroyed());

    frame1.dispose();
    Assert.assertEquals(false, glWindow1.isDestroyed());

    glWindow1.destroy(true);
    // Assert.assertEquals(true, glWindow1.isDestroyed());
  }
Esempio n. 4
0
  @Test
  public void testWindowParenting05ReparentAWTWinHopFrame2Frame() throws InterruptedException {
    int x = 0;
    int y = 0;

    NEWTEventFiFo eventFifo = new NEWTEventFiFo();

    GLWindow glWindow1 = GLWindow.create(glCaps, true);
    GLEventListener demo1 = new RedSquare();
    setDemoFields(demo1, glWindow1, false);
    glWindow1.addGLEventListener(demo1);

    NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);

    Frame frame1 = new Frame("AWT Parent Frame");
    frame1.setLayout(new BorderLayout());
    frame1.add(new Button("North"), BorderLayout.NORTH);
    frame1.add(new Button("South"), BorderLayout.SOUTH);
    frame1.add(new Button("East"), BorderLayout.EAST);
    frame1.add(new Button("West"), BorderLayout.WEST);
    frame1.setSize(width, height);
    frame1.setLocation(0, 0);
    frame1.setVisible(true);

    Frame frame2 = new Frame("AWT Parent Frame");
    frame2.setLayout(new BorderLayout());
    frame2.add(new Button("North"), BorderLayout.NORTH);
    frame2.add(new Button("South"), BorderLayout.SOUTH);
    frame2.add(new Button("East"), BorderLayout.EAST);
    frame2.add(new Button("West"), BorderLayout.WEST);
    frame2.setSize(width, height);
    frame2.setLocation(640, 480);
    frame2.setVisible(true);

    frame1.add(newtCanvasAWT, BorderLayout.CENTER);
    Assert.assertEquals(newtCanvasAWT.getNativeWindow(), glWindow1.getParentNativeWindow());

    Animator animator1 = new Animator(glWindow1);
    animator1.start();

    int state = 0;
    while (animator1.isAnimating() && animator1.getDuration() < 3 * durationPerTest) {
      Thread.sleep(durationPerTest);
      switch (state) {
        case 0:
          frame1.remove(newtCanvasAWT);
          frame2.add(newtCanvasAWT, BorderLayout.CENTER);
          break;
        case 1:
          frame2.remove(newtCanvasAWT);
          frame1.add(newtCanvasAWT, BorderLayout.CENTER);
          break;
      }
      state++;
    }

    animator1.stop();
    Assert.assertEquals(false, animator1.isAnimating());

    frame1.dispose();
    frame2.dispose();
    glWindow1.destroy(true);
  }
Esempio n. 5
0
  @Test
  public void testWindowParenting03ReparentNewtWin2Top() throws InterruptedException {
    int x = 0;
    int y = 0;

    NEWTEventFiFo eventFifo = new NEWTEventFiFo();

    GLWindow glWindow1 = GLWindow.create(glCaps);
    GLEventListener demo1 = new RedSquare();
    setDemoFields(demo1, glWindow1, false);
    glWindow1.addGLEventListener(demo1);

    NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow1);

    Frame frame = new Frame("AWT Parent Frame");
    frame.setSize(width, height);
    frame.setLocation(640, 480);
    frame.setVisible(true);

    frame.add(newtCanvasAWT);
    Assert.assertEquals(newtCanvasAWT.getNativeWindow(), glWindow1.getParentNativeWindow());

    Animator animator1 = new Animator(glWindow1);
    animator1.start();

    int state = 0;
    while (animator1.isAnimating() && animator1.getDuration() < 3 * durationPerTest) {
      Thread.sleep(durationPerTest);
      switch (state) {
        case 0:
          glWindow1.reparentWindow(null, null);
          Assert.assertEquals(true, glWindow1.isNativeWindowValid());
          Assert.assertNull(glWindow1.getParentNativeWindow());
          break;
        case 1:
          glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow(), null);
          Assert.assertEquals(true, glWindow1.isNativeWindowValid());
          Assert.assertEquals(newtCanvasAWT.getNativeWindow(), glWindow1.getParentNativeWindow());
          break;
      }
      state++;
    }

    animator1.stop();
    Assert.assertEquals(false, animator1.isAnimating());

    frame.dispose();
    glWindow1.destroy(true);
  }
Esempio n. 6
0
  protected void runTestGL(final GLCapabilitiesImmutable caps) throws InterruptedException {
    final Display nDisplay =
        NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null, false); // local display
    final Screen nScreen = NewtFactory.createScreen(nDisplay, 0); // screen 0
    final Window nWindow = NewtFactory.createWindow(nScreen, caps);

    final GLWindow glWindow = GLWindow.create(nWindow);
    Assert.assertNotNull(glWindow);
    glWindow.setTitle("Gears NewtAWTWrapper Test");

    glWindow.addGLEventListener(new GearsES2(1));

    final Animator animator = useAnimator ? new Animator(glWindow) : null;
    final QuitAdapter quitAdapter = new QuitAdapter();

    glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
    glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));

    if (useAnimator) {
      animator.start();
    }

    int div = 3;
    glWindow.setSize(width / div, height / div);
    glWindow.setVisible(true);
    if (doResizeTest) {
      glWindow.display();
      final int[] expSurfaceSize =
          glWindow.getNativeSurface().convertToPixelUnits(new int[] {width / div, height / div});
      Assert.assertTrue(
          "Surface Size not reached: Expected "
              + expSurfaceSize[0]
              + "x"
              + expSurfaceSize[1]
              + ", Is "
              + glWindow.getSurfaceWidth()
              + "x"
              + glWindow.getSurfaceHeight(),
          AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1]));
      Thread.sleep(600);

      div = 2;
      glWindow.setSize(width / div, height / div);
      glWindow.display();
      expSurfaceSize[0] = width / div;
      expSurfaceSize[1] = height / div;
      glWindow.getNativeSurface().convertToPixelUnits(expSurfaceSize);
      Assert.assertTrue(
          "Surface Size not reached: Expected "
              + expSurfaceSize[0]
              + "x"
              + expSurfaceSize[1]
              + ", Is "
              + glWindow.getSurfaceWidth()
              + "x"
              + glWindow.getSurfaceHeight(),
          AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1]));
      Thread.sleep(600);

      div = 1;
      glWindow.setSize(width / div, height / div);
      glWindow.display();
      expSurfaceSize[0] = width / div;
      expSurfaceSize[1] = height / div;
      glWindow.getNativeSurface().convertToPixelUnits(expSurfaceSize);
      Assert.assertTrue(
          "Surface Size not reached: Expected "
              + expSurfaceSize[0]
              + "x"
              + expSurfaceSize[1]
              + ", Is "
              + glWindow.getSurfaceWidth()
              + "x"
              + glWindow.getSurfaceHeight(),
          AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1]));
      Thread.sleep(600);
    }

    final long t0 = System.currentTimeMillis();
    long t1 = t0;
    while (!quitAdapter.shouldQuit() && t1 - t0 < duration) {
      Thread.sleep(100);
      t1 = System.currentTimeMillis();
    }

    if (useAnimator) {
      animator.stop();
    }
    glWindow.destroy();
  }
Esempio n. 7
0
  public static void run(
      GLWindow windowOffScreen,
      GLEventListener demo,
      GLWindow windowOnScreen,
      WindowListener wl,
      MouseListener ml,
      SurfaceUpdatedListener ul,
      int frames,
      boolean snapshot,
      boolean debug) {
    Assert.assertNotNull(windowOffScreen);
    Assert.assertNotNull(demo);

    setDemoFields(demo, windowOffScreen, windowOffScreen, debug);
    windowOffScreen.addGLEventListener(demo);

    if (null != windowOnScreen) {
      if (null != wl) {
        windowOnScreen.addWindowListener(wl);
      }
      if (null != ml) {
        windowOnScreen.addMouseListener(ml);
      }
      windowOnScreen.setVisible(true);
    }

    GLDrawable readDrawable = windowOffScreen.getContext().getGLDrawable();

    if (null == windowOnScreen) {
      if (snapshot) {
        Surface2File s2f = new Surface2File();
        windowOffScreen.addSurfaceUpdatedListener(s2f);
      }
    } else {
      ReadBuffer2Screen readDemo = new ReadBuffer2Screen(readDrawable);
      windowOnScreen.addGLEventListener(readDemo);
    }
    if (null != ul) {
      windowOffScreen.addSurfaceUpdatedListener(ul);
    }

    if (debug) {
      System.out.println("+++++++++++++++++++++++++++");
      System.out.println(windowOffScreen);
      System.out.println("+++++++++++++++++++++++++++");
    }

    while (windowOffScreen.getTotalFrames() < frames) {
      windowOffScreen.display();
    }
    windowOffScreen.removeAllSurfaceUpdatedListener();
  }