28package com.jogamp.opengl;
30import java.util.ArrayList;
33import com.jogamp.nativewindow.AbstractGraphicsConfiguration;
34import com.jogamp.nativewindow.AbstractGraphicsDevice;
35import com.jogamp.nativewindow.DefaultGraphicsDevice;
36import com.jogamp.nativewindow.NativeSurface;
37import com.jogamp.nativewindow.ProxySurface;
38import com.jogamp.opengl.GLAnimatorControl;
39import com.jogamp.opengl.GLAutoDrawable;
40import com.jogamp.opengl.GLCapabilitiesImmutable;
41import com.jogamp.opengl.GLContext;
42import com.jogamp.opengl.GLEventListener;
43import com.jogamp.opengl.GLException;
44import com.jogamp.opengl.GLRunnable;
46import jogamp.opengl.Debug;
48import com.jogamp.common.util.locks.RecursiveLock;
49import com.jogamp.nativewindow.MutableGraphicsConfiguration;
50import com.jogamp.opengl.util.GLDrawableUtil;
73 private static final boolean DEBUG = Debug.debug(
"GLDrawable") || Debug.debug(
"GLEventListenerState");
77 final RecursiveLock upstreamLock,
final NativeSurface lockedSurface,
83 this.upstreamLock = upstreamLock;
84 this.lockedSurface = lockedSurface;
87 this.listenersInit =
new boolean[count];
101 public final boolean isOwner() {
return owner; }
115 private volatile RecursiveLock upstreamLock;
117 private volatile boolean owner;
125 private final Runnable unlockOp =
new Runnable() {
127 final RecursiveLock rl = upstreamLock;
130 lockedSurface =
null;
145 for(
int i=0; i<aSz; i++) {
223 final boolean srcAnimStarted;
224 if(
null != srcAnim ) {
228 srcAnimStarted =
false;
233 srcUpstreamLock.lock();
236 final boolean srcSurfaceLocked = NativeSurface.LOCK_SURFACE_NOT_READY < srcSurface.
lockSurface();
238 throw new GLException(
"Could not lock realized surface "+src);
252 System.err.println(
"GLEventListenerState.moveFrom.0a: orig 0x"+Integer.toHexString(aDevice1.hashCode())+
", "+aDevice1);
253 System.err.println(
"GLEventListenerState.moveFrom.0b: pres 0x"+Integer.toHexString(aDevice2.hashCode())+
", "+aDevice2);
254 System.err.println(
"GLEventListenerState.moveFrom.1: "+srcSurface.getClass().getName());
264 if(DEBUG &&
null != aUpSurface) {
265 System.err.println(
"GLEventListenerState.moveFrom.2: "+aUpSurface.getClass().getName()+
", "+aUpSurface);
267 if(
null != aUpSurface) {
269 _aUpDevice2 = cloneDevice(aUpDevice1);
272 System.err.println(
"GLEventListenerState.moveFrom.3a: up-orig 0x"+Integer.toHexString(aUpDevice1.hashCode())+
", "+aUpDevice1);
273 System.err.println(
"GLEventListenerState.moveFrom.3b: up-pres 0x"+Integer.toHexString(_aUpDevice2.hashCode())+
", "+_aUpDevice2);
274 System.err.println(
"GLEventListenerState.moveFrom.3c: "+srcSurface.getClass().getName()+
", "+srcSurface);
275 System.err.println(
"GLEventListenerState.moveFrom.3d: "+aUpSurface.getClass().getName()+aProxy.
getUpstreamOptionBits(
null).toString());
281 aUpDevice2 = _aUpDevice2;
285 keepLocked ? srcUpstreamLock :
null,
286 srcSurfaceLocked && keepLocked ? srcSurface :
null,
287 src.
getContext(), aSz, srcAnim, srcAnimStarted);
292 for(
int i=0; i<aSz; i++) {
301 if( srcSurfaceLocked && !keepLocked ) {
307 srcUpstreamLock.unlock();
376 final boolean destAnimPaused;
377 if(
null != destAnim ) {
378 destAnimPaused = destAnim.
pause();
381 destAnimPaused =
false;
384 final List<GLRunnable> aGLCmds =
new ArrayList<GLRunnable>();
387 final RecursiveLock destUpstreamLock = dest.getUpstreamLock();
388 destUpstreamLock.lock();
389 final boolean destIsRealized;
392 final boolean destSurfaceLocked = NativeSurface.LOCK_SURFACE_NOT_READY < destSurface.
lockSurface();
393 if( dest.isRealized() && !destSurfaceLocked ) {
394 throw new GLException(
"Could not lock realized surface "+dest);
422 System.err.println(
"GLEventListenerState.moveTo.0 : has aProxy "+(
null!=aProxy));
423 System.err.println(
"GLEventListenerState.moveTo.0 : has aUpSurface "+(
null!=aUpSurface));
426 throw new GLException(
"Incompatible Surface config - Has Upstream-Surface: Prev-Holder = true, New-Holder = false");
430 dest.setContext(
null,
true );
431 destIsRealized = dest.isRealized();
432 if( destIsRealized &&
null != aUpSurface ) {
434 dest.getDelegatedDrawable().setRealized(
false);
440 System.err.println(
"GLEventListenerState.moveTo.0a: orig 0x"+Integer.toHexString(aDevice1.hashCode())+
", "+aDevice1);
441 System.err.println(
"GLEventListenerState.moveTo.0b: pres 0x"+Integer.toHexString(aDevice2.hashCode())+
", "+aDevice2);
446 System.err.println(
"GLEventListenerState.moveTo.1a: orig 0x"+Integer.toHexString(aDevice1.hashCode())+
", "+aDevice1);
447 System.err.println(
"GLEventListenerState.moveTo.1b: pres 0x"+Integer.toHexString(aDevice2.hashCode())+
", "+aDevice2);
452 if(
null != aUpSurface ) {
461 System.err.println(
"GLEventListenerState.moveTo.2a: up-orig 0x"+Integer.toHexString(aUpDevice1.hashCode())+
", "+aUpDevice1);
462 System.err.println(
"GLEventListenerState.moveTo.2b: up-pres 0x"+Integer.toHexString(aUpDevice2.hashCode())+
", "+aUpDevice2);
463 System.err.println(
"GLEventListenerState.moveTo.2c: "+aUpSurface.getClass().getName()+aProxy.
getUpstreamOptionBits(
null).toString());
471 System.err.println(
"GLEventListenerState.moveTo.3a: up-orig 0x"+Integer.toHexString(aUpDevice1.hashCode())+
", "+aUpDevice1);
472 System.err.println(
"GLEventListenerState.moveTo.3b: up-pres 0x"+Integer.toHexString(aUpDevice2.hashCode())+
", "+aUpDevice2);
473 System.err.println(
"GLEventListenerState.moveTo.3c: "+aUpSurface.getClass().getName()+aProxy.
getUpstreamOptionBits(
null).toString());
476 throw new GLException(
"Incompatible Surface config - Has Upstream-Surface: Prev-Holder = false, New-Holder = true");
480 if( destIsRealized &&
null != aUpSurface ) {
481 dest.getDelegatedDrawable().setRealized(
true);
484 System.err.println(
"GLEventListenerState.moveTo.X : has aProxy "+(
null!=aProxy));
485 System.err.println(
"GLEventListenerState.moveTo.X : has aUpSurface "+(
null!=aUpSurface));
487 dest.setContext(
context,
false );
489 if( destSurfaceLocked ) {
494 destUpstreamLock.unlock();
496 if(
null != destUnlockOperation ) {
497 destUnlockOperation.run();
505 aGLCmds.add(setViewport);
506 for(
int i=0; i<aSz; i++) {
511 aGLCmds.add(glFinish);
512 dest.invoke(destIsRealized, aGLCmds);
515 for(
int i=0; i<aSz; i++) {
517 dest.addGLEventListener( l );
522 if(
null != destAnim ) {
525 if( destAnimPaused ) {
528 }
else if (
null !=
anim ) {
545 private static final GLRunnable glFinish =
new GLRunnable() {
547 public boolean run(
final GLAutoDrawable drawable) {
548 drawable.getGL().glFinish();
final AbstractGraphicsScreen getScreen()
Return the screen this graphics configuration is valid for.
boolean close()
Optionally closing the device if handle is not null.
final String getUniqueID()
Returns a unique ID object of this device using type, connection and unitID as it's key components.
static final void swapHandleAndOwnership(final DefaultGraphicsDevice a, final DefaultGraphicsDevice b)
Abstraction for an OpenGL rendering context.
GLEventListenerState is holding GLAutoDrawable components crucial to relocating all its GLEventListen...
final AbstractGraphicsDevice upstreamDevice
final AbstractGraphicsDevice device
void destroy()
Last resort to destroy and loose ownership.
final boolean animStarted
final boolean[] listenersInit
static GLEventListenerState moveFrom(final GLAutoDrawable src, final boolean keepLocked)
Moves all GLEventListenerState components from the given GLAutoDrawable to a newly created instance.
final void moveTo(final GLAutoDrawable dest, final Runnable destUnlockOperation)
Moves all GLEventListenerState components to the given GLAutoDrawable from this instance,...
final boolean isOwner()
Returns true, if this instance is the current owner of the components, otherwise false.
final void moveTo(final GLAutoDrawable dest)
Moves all GLEventListenerState components to the given GLAutoDrawable from this instance,...
static GLEventListenerState moveFrom(final GLAutoDrawable src)
Moves all GLEventListenerState components from the given GLAutoDrawable to a newly created instance.
final GLEventListener[] listeners
final boolean proxyOwnsUpstreamDevice
final int listenerCount()
final GLCapabilitiesImmutable caps
Runnable getUnlockSurfaceOp()
Returns a Runnable unlocking an eventually locked NativeSurface, see moveFrom(GLAutoDrawable,...
final GLAnimatorControl anim
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
GLRunnable to issue GLEventListener#reshape(GLAutoDrawable, int, int, int, int), returning true on GL...
Providing utility functions dealing w/ GLDrawables, GLAutoDrawable and their GLEventListener.
A marker interface describing a graphics configuration, visual, or pixel format in a toolkit-independ...
CapabilitiesImmutable getChosenCapabilities()
Return the capabilities reflecting this graphics configuration, which may differ from the capabilitie...
AbstractGraphicsScreen getScreen()
Return the screen this graphics configuration is valid for.
A interface describing a graphics device in a toolkit-independent manner.
boolean close()
Optionally closing the device if handle is not null.
AbstractGraphicsDevice getDevice()
Return the device this graphics configuration is valid for.
Provides low-level information required for hardware-accelerated rendering using a surface in a platf...
int lockSurface()
Lock the surface of this native window.
AbstractGraphicsConfiguration getGraphicsConfiguration()
Returns the graphics configuration corresponding to this window.
void unlockSurface()
Unlock the surface of this native window.
Provides a mutable NativeSurface, i.e.
NativeSurface getUpstreamSurface()
Returns the optional upstream NativeSurface if used by implementation, otherwise null.
void addUpstreamOptionBits(int v)
Add the given bit-mask to this instance upstream-option-bits using bit-or w/ v.
boolean containsUpstreamOptionBits(int v)
Returns true if the give bit-mask v is set in this instance upstream-option-bits, otherwise false.
StringBuilder getUpstreamOptionBits(StringBuilder sink)
static final int OPT_PROXY_OWNS_UPSTREAM_DEVICE
Implementation specific bit-value stating this ProxySurface owns the upstream's AbstractGraphicsDevic...
An animator control interface, which implementation may drive a com.jogamp.opengl....
boolean start()
Starts this animator, if not running.
boolean resume()
Resumes animation if paused.
void remove(GLAutoDrawable drawable)
Removes a drawable from the animator's list of rendering drawables.
boolean pause()
Pauses this animator.
boolean isStarted()
Indicates whether this animator has been started.
void add(GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GLEventListener getGLEventListener(int index)
Returns the GLEventListener at the given index of this drawable queue.
GLContext setContext(GLContext newCtx, boolean destroyPrevCtx)
Associate the new context, newtCtx, to this auto-drawable.
GLAnimatorControl getAnimator()
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
RecursiveLock getUpstreamLock()
Returns the recursive lock object of the upstream widget to synchronize multithreaded access on top o...
int getGLEventListenerCount()
Returns the number of GLEventListener of this drawable queue.
GLEventListener removeGLEventListener(GLEventListener listener)
Removes the given listener from this drawable queue.
GLContext getContext()
Returns the context associated with this drawable.
boolean getGLEventListenerInitState(GLEventListener listener)
Retrieves whether the given listener is initialized or not.
Specifies an immutable set of OpenGL capabilities.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
boolean isRealized()
Returns true if this drawable is realized, otherwise false.
NativeSurface getNativeSurface()
Returns the associated NativeSurface of this NativeSurfaceHolder.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void glViewport(int x, int y, int width, int height)
Entry point to C language function: void {@native glViewport}(GLint x, GLint y, GLsizei width,...