private long getWindowHandle() { if (window_handle_ == 0) { NativeSurface surface = canvas_.getNativeSurface(); if (surface != null) { surface.lockSurface(); window_handle_ = getWindowHandle(surface.getSurfaceHandle()); surface.unlockSurface(); assert (window_handle_ != 0); } } return window_handle_; }
/** * Returns an uninitialized {@link EGLGraphicsDevice}. User needs to issue {@link EGLGraphicsDevice#open()} before usage. * <p> * Using {@link #eglGetDisplayAndInitialize(long[])} for the {@link EGLGraphicsDevice#open()} implementation * and {@link #eglTerminate(long)} for {@link EGLGraphicsDevice#close()}. * </p> * <p> * Using the default {@link ToolkitLock}, via {@link NativeWindowFactory#getDefaultToolkitLock(String, long)}. * </p> * @param surface * @return an uninitialized EGLGraphicsDevice */ public static EGLGraphicsDevice eglCreateEGLGraphicsDevice(final NativeSurface surface) { final long nativeDisplayID; if( NativeWindowFactory.TYPE_WINDOWS == NativeWindowFactory.getNativeWindowType(false) ) { nativeDisplayID = surface.getSurfaceHandle(); // don't even ask .. } else { nativeDisplayID = surface.getDisplayHandle(); // 0 == EGL.EGL_DEFAULT_DISPLAY } final AbstractGraphicsDevice adevice = surface.getGraphicsConfiguration().getScreen().getDevice(); return new EGLGraphicsDevice(nativeDisplayID, EGL.EGL_NO_DISPLAY, adevice.getConnection(), adevice.getUnitID(), eglLifecycleCallback); } }
@Override protected final void resetGammaRamp(final NativeSurface surface, final Buffer originalGammaRamp) { if (originalGammaRamp == null) { return; // getGammaRamp failed originally } final long display = surface.getDisplayHandle(); if(0 == display) { return; } final int screenIdx = surface.getScreenIndex(); resetGammaRamp(display, screenIdx, originalGammaRamp); }
@Override public String toString() { final String us_s; final int sw, sh; if( null != upstreamSurface ) { us_s = upstreamSurface.getClass().getName() + ": 0x" + Long.toHexString(upstreamSurface.getSurfaceHandle()); sw = upstreamSurface.getSurfaceWidth(); sh = upstreamSurface.getSurfaceHeight(); } else { us_s = "nil"; sw = -1; sh = -1; } return "EGLUpstreamSurfaceHook[ "+ sw + "x" + sh + ", " + us_s+ "]"; }
@Override public synchronized final void resetDisplayGamma(final NativeSurface surface) { if( NativeSurface.LOCK_SURFACE_NOT_READY >= surface.lockSurface() ) { return; } try { final AbstractGraphicsScreen screen = surface.getGraphicsConfiguration().getScreen(); final DeviceScreenID deviceScreenID = new DeviceScreenID(screen.getDevice().getConnection(), screen.getIndex()); final Buffer originalGammaRamp = screen2OrigGammaRamp.remove(deviceScreenID); if( null != originalGammaRamp ) { resetGammaRamp(surface, originalGammaRamp); } } finally { surface.unlockSurface(); } }
if(NativeSurface.LOCK_SURFACE_NOT_READY >= ns.lockSurface()) { throw new GLException("Surface not ready (lockSurface)"); final long hdc = ns.getSurfaceHandle(); if (0 == hdc) { throw new GLException("Error: HDC is null"); final WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration) ns.getGraphicsConfiguration(); ns.unlockSurface();
@Override public final void create(final ProxySurface surface) { final String dbgPrefix; if(DEBUG) { dbgPrefix = getThreadName() + ": EGLUpstreamSurfaceHook.create( up "+upstreamSurface.getClass().getSimpleName()+" -> this "+surface.getClass().getSimpleName()+" ): "; System.err.println(dbgPrefix+this); } else { dbgPrefix = null; } if(upstreamSurface instanceof ProxySurface) { // propagate createNotify(..) so upstreamSurface will be created ((ProxySurface)upstreamSurface).createNotify(); } // lock upstreamSurface, so it can be used in case EGLDisplay is derived from it! if(NativeSurface.LOCK_SURFACE_NOT_READY >= upstreamSurface.lockSurface()) { throw new GLException("Could not lock: "+upstreamSurface); } try { evalUpstreamSurface(dbgPrefix, surface); } finally { upstreamSurface.unlockSurface(); } }
@Override public long getHandle() { return surface.getSurfaceHandle(); }
public EGLWrappedSurface(final NativeSurface surface) { super(surface.getGraphicsConfiguration(), EGL.EGL_NO_SURFACE, new EGLUpstreamSurfaceHook(surface), false /* tbd in UpstreamSurfaceHook */); if(EGLDrawableFactory.DEBUG) { System.err.println("EGLWrappedSurface.ctor(): "+this); } }
@Override public String toString() { return getClass().getName()+"[realized "+isRealized()+ ",\n\tfactory "+getFactory()+ ",\n\tsurface "+getNativeSurface()+ ",\n\teglSurface "+toHexString(surface.getSurfaceHandle())+ ",\n\teglConfig "+surface.getGraphicsConfiguration()+ ",\n\trequested "+getRequestedGLCapabilities()+ ",\n\tchosen "+getChosenGLCapabilities()+"]"; } }
protected void destroyPbuffer() { final NativeSurface ns = getNativeSurface(); if (ns.getSurfaceHandle() != 0) { GLX.glXDestroyPbuffer(ns.getDisplayHandle(), ns.getSurfaceHandle()); } ((MutableSurface)ns).setSurfaceHandle(0); if (DEBUG) { System.err.println(getThreadName()+": Destroyed pbuffer " + this); } }
@Override protected void destroyContextARBImpl(final long ctx) { final long display = drawable.getNativeSurface().getDisplayHandle(); glXMakeContextCurrent(display, 0, 0, 0); GLX.glXDestroyContext(display, ctx); } private static final int ctx_arb_attribs_idx_major = 0;
@Override public final void swapBuffers() throws GLException { if( !realized ) { // volatile OK (locked below) return; // destroyed already } final int lockRes = lockSurface(); // it's recursive, so it's ok within [makeCurrent .. release] if (NativeSurface.LOCK_SURFACE_NOT_READY == lockRes) { return; } try { if( realized ) { // volatile OK final GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable)surface.getGraphicsConfiguration().getChosenCapabilities(); if ( caps.getDoubleBuffered() ) { if(!surface.surfaceSwap()) { swapBuffersImpl(true); } } else { final GLContext ctx = GLContext.getCurrent(); if(null!=ctx && ctx.getGLDrawable()==this) { ctx.getGL().glFlush(); } swapBuffersImpl(false); } } } finally { unlockSurface(); } surface.surfaceUpdated(this, surface, System.currentTimeMillis()); }
private void createPixmap() { final NativeSurface ns = getNativeSurface(); final X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration) ns.getGraphicsConfiguration(); final XVisualInfo vis = config.getXVisualInfo(); final int bitsPerPixel = vis.getDepth(); final AbstractGraphicsScreen aScreen = config.getScreen(); final AbstractGraphicsDevice aDevice = aScreen.getDevice(); final long dpy = aDevice.getHandle(); final int screen = aScreen.getIndex(); pixmap = X11Lib.XCreatePixmap(dpy, X11Lib.RootWindow(dpy, screen), surface.getSurfaceWidth(), surface.getSurfaceHeight(), bitsPerPixel); if (pixmap == 0) { throw new GLException("XCreatePixmap failed"); } final long drawable = GLX.glXCreateGLXPixmap(dpy, vis, pixmap); if (drawable == 0) { X11Lib.XFreePixmap(dpy, pixmap); pixmap = 0; throw new GLException("glXCreateGLXPixmap failed"); } ((MutableSurface)ns).setSurfaceHandle(drawable); if (DEBUG) { System.err.println(getThreadName()+": Created pixmap " + toHexString(pixmap) + ", GLXPixmap " + toHexString(drawable) + ", display " + toHexString(dpy)); } }
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.getNativeSurface().isSurfaceLockedByOtherThread() && !helper.isAnimatorAnimatingOnOtherThread() ) { display();
/** * {@link NativeSurface#unlockSurface() Unlocks} the underlying windowing toolkit {@link NativeSurface surface}, * which may render the {@link #getHandle() drawable handle} invalid. * * @see NativeSurface#unlockSurface() * @see #getHandle() */ public final void unlockSurface() { surface.unlockSurface(); }
@Override protected final StringBuilder getPlatformExtensionsStringImpl() { final NativeSurface ns = drawable.getNativeSurface(); final X11GraphicsDevice x11Device = (X11GraphicsDevice) ns.getGraphicsConfiguration().getScreen().getDevice(); final StringBuilder sb = new StringBuilder(); x11Device.lock(); final String ret = GLX.glXQueryExtensionsString(x11Device.getHandle(), ns.getScreenIndex()); if (DEBUG) { System.err.println("GLX extensions (glXQueryExtensionsString): " + ret); final String ret = GLX.glXQueryServerString(x11Device.getHandle(), ns.getScreenIndex(), GLX.GLX_EXTENSIONS); if (DEBUG) { System.err.println("GLX extensions (glXQueryServerString): " + ret);
final boolean useY = surface.getSurfaceWidth() >= surface.getSurfaceHeight(); // use smallest dimension switch ( eventType ) { case MouseEvent.EVENT_MOUSE_PRESSED: { final int d = Math.abs(edge0-edge1); final int dd = d - zoomLastEdgeDist; final float screenEdge = useY ? surface.getSurfaceHeight() : surface.getSurfaceWidth(); final float delta = dd / screenEdge; // [-1..1] if(DEBUG) {
final int lockRes = surface.lockSurface(); if ( NativeSurface.LOCK_SURFACE_CHANGED == lockRes && realized ) {
@Override protected boolean createImpl(final long shareWithHandle) throws GLException { final EGLGraphicsConfiguration config = (EGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration(); final long eglDisplay = config.getScreen().getDevice().getHandle(); final GLProfile glProfile = drawable.getGLProfile(); System.err.println(getThreadName() + ": createImpl: setGLFunctionAvailability FAILED delete "+toHexString(contextHandle)); EGL.eglMakeCurrent(drawable.getNativeSurface().getDisplayHandle(), EGL.EGL_NO_SURFACE, EGL.EGL_NO_SURFACE, EGL.EGL_NO_CONTEXT); EGL.eglDestroyContext(drawable.getNativeSurface().getDisplayHandle(), contextHandle); contextHandle = 0; return false;