Example #1
0
 protected GLEventListener createDemo(final GLCapabilities caps) {
   final GLEventListener demo;
   if (1 == demoType) {
     if (caps.isBitmap() || caps.getGLProfile().isGL2()) {
       final Gears gears = new Gears(swapInterval);
       gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
       demo = gears;
     } else {
       final GearsES2 gears = new GearsES2(swapInterval);
       gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
       demo = gears;
     }
   } else if (0 == demoType) {
     demo = new GLClearOnInitReshape();
   } else {
     demo = null;
   }
   return demo;
 }
  public void asyncEachOneAnimator(final boolean destroyCleanOrder)
      throws InterruptedException, InvocationTargetException {
    final Frame f1 = new Frame();
    final Animator a1 = new Animator();
    final GearsES2 g1 = new GearsES2(0);
    final GLCanvas c1 = createGLCanvas(f1, 0, 0, g1);
    a1.add(c1);
    a1.start();
    // f1.setVisible(true); // we do this post f2 .. to test pending creation!

    final Frame f2 = new Frame();
    final Animator a2 = new Animator();
    final GearsES2 g2 = new GearsES2(0);
    g2.setSharedGears(g1);
    final GLCanvas c2 = createGLCanvas(f2, f1.getX() + width, f1.getY() + 0, g2);
    c2.setSharedAutoDrawable(c1);
    a2.add(c2);
    a2.start();
    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            f2.setVisible(true);
          }
        });

    Thread.sleep(200); // wait a while ..

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            f1.setVisible(true); // test pending creation of f2
          }
        });

    final Frame f3 = new Frame();
    final Animator a3 = new Animator();
    final GearsES2 g3 = new GearsES2(0);
    g3.setSharedGears(g1);
    final GLCanvas c3 = createGLCanvas(f3, f1.getX() + 0, f1.getY() + height, g3);
    c3.setSharedAutoDrawable(c1);
    a3.add(c3);
    a3.start();
    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            f3.setVisible(true);
          }
        });

    Thread.sleep(
        1000 / 60
            * 10); // wait ~10 frames giving a chance to create (blocking until master share is
    // valid)

    Assert.assertTrue(AWTRobotUtil.waitForRealized(c1, true));
    Assert.assertTrue(AWTRobotUtil.waitForVisible(c1, true));
    Assert.assertTrue(AWTRobotUtil.waitForContextCreated(c1, true));
    Assert.assertTrue("Gears1 not initialized", g1.waitForInit(true));

    Assert.assertTrue(AWTRobotUtil.waitForRealized(c2, true));
    Assert.assertTrue(AWTRobotUtil.waitForVisible(c2, true));
    Assert.assertTrue(AWTRobotUtil.waitForContextCreated(c2, true));
    Assert.assertTrue("Gears2 not initialized", g2.waitForInit(true));

    Assert.assertTrue(AWTRobotUtil.waitForRealized(c3, true));
    Assert.assertTrue(AWTRobotUtil.waitForVisible(c3, true));
    Assert.assertTrue(AWTRobotUtil.waitForContextCreated(c3, true));
    Assert.assertTrue("Gears3 not initialized", g3.waitForInit(true));

    final GLContext ctx1 = c1.getContext();
    final GLContext ctx2 = c2.getContext();
    final GLContext ctx3 = c3.getContext();
    {
      final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
      final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
      final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
      MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
      MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
      MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);

      Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
      Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
      Assert.assertTrue("Ctx3 is not shared", ctx3.isShared());
      Assert.assertEquals("Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
      Assert.assertEquals("Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
      Assert.assertEquals("Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
    }

    Assert.assertTrue("Gears1 is shared", !g1.usesSharedGears());
    Assert.assertTrue("Gears2 is not shared", g2.usesSharedGears());
    Assert.assertTrue("Gears3 is not shared", g3.usesSharedGears());

    try {
      Thread.sleep(duration);
    } catch (final Exception e) {
      e.printStackTrace();
    }
    // Stopped animator allows native windowing system 'repaint' event
    // to trigger GLAD 'display'
    a1.stop();
    Assert.assertEquals(false, a1.isAnimating());
    a2.stop();
    Assert.assertEquals(false, a2.isAnimating());
    a3.stop();
    Assert.assertEquals(false, a3.isAnimating());

    if (destroyCleanOrder) {
      System.err.println("XXX Destroy in clean order NOW");
    } else {
      System.err.println(
          "XXX Destroy in creation order NOW - Driver Impl. Ma trigger driver Bug i.e. not postponing GL ctx destruction after releasing all refs.");
    }
    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            try {
              if (destroyCleanOrder) {
                f3.dispose();
              } else {
                f1.dispose();
              }
            } catch (final Throwable t) {
              throw new RuntimeException(t);
            }
          }
        });

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            try {
              f2.dispose();
            } catch (final Throwable t) {
              throw new RuntimeException(t);
            }
          }
        });

    javax.swing.SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            try {
              if (destroyCleanOrder) {
                f1.dispose();
              } else {
                f3.dispose();
              }
            } catch (final Throwable t) {
              throw new RuntimeException(t);
            }
          }
        });

    Assert.assertTrue(AWTRobotUtil.waitForRealized(c1, false));
    Assert.assertTrue(AWTRobotUtil.waitForRealized(c2, false));
    Assert.assertTrue(AWTRobotUtil.waitForRealized(c3, false));
  }