Ejemplo n.º 1
0
 /**
  * Default implementation to destroys the drawable and context of this GLAutoDrawable:
  *
  * <ul>
  *   <li>issues the GLEventListener dispose call, if drawable and context are valid
  *   <li>destroys the GLContext, if valid
  *   <li>destroys the GLDrawable, if valid
  * </ul>
  *
  * <p>Method assumes the lock is being hold.
  *
  * <p>Override it to extend it to destroy your resources, i.e. the actual window. In such case
  * call <code>super.destroyImplInLock</code> first.
  */
 protected void destroyImplInLock() {
   if (preserveGLELSAtDestroy) {
     preserveGLStateAtDestroy(false);
     preserveGLEventListenerState();
   }
   if (null != context) {
     if (context.isCreated()) {
       // Catch dispose GLExceptions by GLEventListener, just 'print' them
       // so we can continue with the destruction.
       try {
         helper.disposeGL(this, context, true);
       } catch (GLException gle) {
         gle.printStackTrace();
       }
     }
     context = null;
   }
   if (null != drawable) {
     final AbstractGraphicsDevice device =
         drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice();
     drawable.setRealized(false);
     drawable = null;
     if (ownsDevice) {
       device.close();
     }
   }
 }
Ejemplo n.º 2
0
 public final void defaultSwapBuffers() throws GLException {
   final RecursiveLock _lock = getLock();
   _lock.lock();
   try {
     if (null != drawable) {
       drawable.swapBuffers();
     }
   } finally {
     _lock.unlock();
   }
 }
Ejemplo n.º 3
0
 /**
  * Default implementation to handle resize events from the windowing system. All required locks
  * are being claimed.
  */
 protected final void defaultWindowResizedOp(int newWidth, int newHeight)
     throws NativeWindowException, GLException {
   GLDrawableImpl _drawable = drawable;
   if (null != _drawable) {
     if (DEBUG) {
       final long surfaceHandle =
           null != getNativeSurface() ? getNativeSurface().getSurfaceHandle() : 0;
       System.err.println(
           "GLAutoDrawableBase.sizeChanged: ("
               + getThreadName()
               + "): "
               + newWidth
               + "x"
               + newHeight
               + " - surfaceHandle 0x"
               + Long.toHexString(surfaceHandle));
     }
     if (!_drawable.getChosenGLCapabilities().isOnscreen()) {
       final RecursiveLock _lock = getLock();
       _lock.lock();
       try {
         final GLDrawableImpl _drawableNew =
             GLDrawableHelper.resizeOffscreenDrawable(_drawable, context, newWidth, newHeight);
         if (_drawable != _drawableNew) {
           // write back
           _drawable = _drawableNew;
           drawable = _drawableNew;
         }
       } finally {
         _lock.unlock();
       }
     }
     sendReshape = true; // async if display() doesn't get called below, but avoiding deadlock
     if (_drawable.isRealized()) {
       if (!_drawable.getNativeSurface().isSurfaceLockedByOtherThread()
           && !helper.isAnimatorAnimatingOnOtherThread()) {
         display();
       }
     }
   }
 }
Ejemplo n.º 4
0
 protected final void defaultDisplay() {
   if (sendDestroy) {
     sendDestroy = false;
     destroy();
     return;
   }
   final RecursiveLock _lock = getLock();
   _lock.lock();
   try {
     if (null == context) {
       boolean contextCreated = false;
       final GLDrawableImpl _drawable = drawable;
       if (null != _drawable
           && _drawable.isRealized()
           && 0 < _drawable.getWidth() * _drawable.getHeight()) {
         final GLContext[] shareWith = {null};
         if (!helper.isSharedGLContextPending(shareWith)) {
           if (!restoreGLEventListenerState()) {
             context = (GLContextImpl) _drawable.createContext(shareWith[0]);
             context.setContextCreationFlags(additionalCtxCreationFlags);
             contextCreated = true;
             // surface is locked/unlocked implicit by context's makeCurrent/release
             helper.invokeGL(_drawable, context, defaultDisplayAction, defaultInitAction);
           }
         }
       }
       if (DEBUG) {
         System.err.println("GLAutoDrawableBase.defaultDisplay: contextCreated " + contextCreated);
       }
     } else {
       // surface is locked/unlocked implicit by context's makeCurrent/release
       helper.invokeGL(drawable, context, defaultDisplayAction, defaultInitAction);
     }
   } finally {
     _lock.unlock();
   }
 }
Ejemplo n.º 5
0
 @Override
 public final GLContext createContext(final GLContext shareWith) {
   final RecursiveLock lock = getLock();
   lock.lock();
   try {
     if (drawable != null) {
       final GLContext _ctx = drawable.createContext(shareWith);
       _ctx.setContextCreationFlags(additionalCtxCreationFlags);
       return _ctx;
     }
     return null;
   } finally {
     lock.unlock();
   }
 }
Ejemplo n.º 6
0
    @Override
    public SharedResourceRunner.Resource createSharedResource(String connection) {
      final X11GraphicsDevice sharedDevice =
          new X11GraphicsDevice(
              X11Util.openDisplay(connection),
              AbstractGraphicsDevice.DEFAULT_UNIT,
              true /* owner */);
      sharedDevice.lock();
      try {
        final X11GraphicsScreen sharedScreen =
            new X11GraphicsScreen(sharedDevice, sharedDevice.getDefaultScreen());

        GLXUtil.initGLXClientDataSingleton(sharedDevice);
        final String glXServerVendorName =
            GLX.glXQueryServerString(sharedDevice.getHandle(), 0, GLX.GLX_VENDOR);
        final boolean glXServerMultisampleAvailable =
            GLXUtil.isMultisampleAvailable(
                GLX.glXQueryServerString(sharedDevice.getHandle(), 0, GLX.GLX_EXTENSIONS));

        final GLProfile glp =
            GLProfile.get(sharedDevice, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false);
        if (null == glp) {
          throw new GLException("Couldn't get default GLProfile for device: " + sharedDevice);
        }

        final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
        final GLDrawableImpl sharedDrawable =
            createOnscreenDrawableImpl(
                createDummySurfaceImpl(sharedDevice, false, caps, caps, null, 64, 64));
        sharedDrawable.setRealized(true);
        final X11GLCapabilities chosenCaps =
            (X11GLCapabilities) sharedDrawable.getChosenGLCapabilities();
        final boolean glxForcedOneOne = !chosenCaps.hasFBConfig();
        final VersionNumber glXServerVersion;
        if (glxForcedOneOne) {
          glXServerVersion = versionOneOne;
        } else {
          glXServerVersion = GLXUtil.getGLXServerVersionNumber(sharedDevice);
        }
        final GLContextImpl sharedContext = (GLContextImpl) sharedDrawable.createContext(null);
        if (null == sharedContext) {
          throw new GLException("Couldn't create shared context for drawable: " + sharedDrawable);
        }

        boolean madeCurrent = false;
        sharedContext.makeCurrent();
        try {
          madeCurrent = sharedContext.isCurrent();
        } finally {
          sharedContext.release();
        }
        if (sharedContext.hasRendererQuirk(GLRendererQuirks.DontCloseX11Display)) {
          X11Util.markAllDisplaysUnclosable();
        }
        if (DEBUG) {
          System.err.println("SharedDevice:  " + sharedDevice);
          System.err.println("SharedScreen:  " + sharedScreen);
          System.err.println("SharedContext: " + sharedContext + ", madeCurrent " + madeCurrent);
          System.err.println("GLX Server Vendor:      " + glXServerVendorName);
          System.err.println(
              "GLX Server Version:     " + glXServerVersion + ", forced " + glxForcedOneOne);
          System.err.println("GLX Server Multisample: " + glXServerMultisampleAvailable);
          System.err.println("GLX Client Vendor:      " + GLXUtil.getClientVendorName());
          System.err.println("GLX Client Version:     " + GLXUtil.getClientVersionNumber());
          System.err.println("GLX Client Multisample: " + GLXUtil.isClientMultisampleAvailable());
        }
        return new SharedResource(
            sharedDevice,
            sharedScreen,
            sharedDrawable,
            sharedContext,
            glXServerVersion,
            glXServerVendorName,
            glXServerMultisampleAvailable && GLXUtil.isClientMultisampleAvailable());
      } catch (Throwable t) {
        throw new GLException(
            "X11GLXDrawableFactory - Could not initialize shared resources for " + connection, t);
      } finally {
        sharedDevice.unlock();
      }
    }
Ejemplo n.º 7
0
    @Override
    public SharedResourceRunner.Resource createSharedResource(
        final AbstractGraphicsDevice adevice) {
      final X11GraphicsDevice device =
          new X11GraphicsDevice(
              X11Util.openDisplay(adevice.getConnection()), adevice.getUnitID(), true /* owner */);
      GLContextImpl context = null;
      boolean contextIsCurrent = false;
      device.lock();
      try {
        final X11GraphicsScreen screen = new X11GraphicsScreen(device, device.getDefaultScreen());

        GLXUtil.initGLXClientDataSingleton(device);
        final String glXServerVendorName =
            GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_VENDOR);
        final boolean glXServerMultisampleAvailable =
            GLXUtil.isMultisampleAvailable(
                GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_EXTENSIONS));

        final GLProfile glp = GLProfile.get(device, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false);
        if (null == glp) {
          throw new GLException("Couldn't get default GLProfile for device: " + device);
        }

        final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
        final GLDrawableImpl drawable =
            createOnscreenDrawableImpl(
                createDummySurfaceImpl(device, false, caps, caps, null, 64, 64));
        drawable.setRealized(true);
        final X11GLCapabilities chosenCaps = (X11GLCapabilities) drawable.getChosenGLCapabilities();
        final boolean glxForcedOneOne = !chosenCaps.hasFBConfig();
        final VersionNumber glXServerVersion;
        if (glxForcedOneOne) {
          glXServerVersion = versionOneOne;
        } else {
          glXServerVersion = GLXUtil.getGLXServerVersionNumber(device);
        }
        context = (GLContextImpl) drawable.createContext(null);
        if (null == context) {
          throw new GLException("Couldn't create shared context for drawable: " + drawable);
        }
        contextIsCurrent = GLContext.CONTEXT_NOT_CURRENT != context.makeCurrent();

        final boolean allowsSurfacelessCtx;
        if (contextIsCurrent && context.getGLVersionNumber().compareTo(GLContext.Version3_0) >= 0) {
          allowsSurfacelessCtx = probeSurfacelessCtx(context, true /* restoreDrawable */);
        } else {
          setNoSurfacelessCtxQuirk(context);
          allowsSurfacelessCtx = false;
        }

        if (context.hasRendererQuirk(GLRendererQuirks.DontCloseX11Display)) {
          X11Util.markAllDisplaysUnclosable();
        }
        if (DEBUG_SHAREDCTX) {
          System.err.println("SharedDevice:  " + device);
          System.err.println("SharedScreen:  " + screen);
          System.err.println("SharedContext: " + context + ", madeCurrent " + contextIsCurrent);
          System.err.println("  allowsSurfacelessCtx " + allowsSurfacelessCtx);
          System.err.println("GLX Server Vendor:      " + glXServerVendorName);
          System.err.println(
              "GLX Server Version:     " + glXServerVersion + ", forced " + glxForcedOneOne);
          System.err.println("GLX Server Multisample: " + glXServerMultisampleAvailable);
          System.err.println("GLX Client Vendor:      " + GLXUtil.getClientVendorName());
          System.err.println("GLX Client Version:     " + GLXUtil.getClientVersionNumber());
          System.err.println("GLX Client Multisample: " + GLXUtil.isClientMultisampleAvailable());
        }
        return new SharedResource(
            device,
            screen,
            drawable,
            context,
            glXServerVersion,
            glXServerVendorName,
            glXServerMultisampleAvailable && GLXUtil.isClientMultisampleAvailable());
      } catch (final Throwable t) {
        throw new GLException(
            "X11GLXDrawableFactory - Could not initialize shared resources for " + adevice, t);
      } finally {
        if (contextIsCurrent) {
          context.release();
        }
        device.unlock();
      }
    }