com.jogamp.newt.Display Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jogl-all Show documentation
Show all versions of jogl-all Show documentation
Java™ Binding for the OpenGL® API
/**
* Copyright 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of JogAmp Community.
*/
package com.jogamp.newt;
import com.jogamp.newt.util.EDTUtil;
import jogamp.newt.Debug;
import java.util.*;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeWindowException;
public abstract class Display {
public static final boolean DEBUG = Debug.debug("Display");
/** return precomputed hashCode from FQN {@link #getFQName()} */
public abstract int hashCode();
/** return true if obj is of type Display and both FQN {@link #getFQName()} equals */
public boolean equals(Object obj) {
if (this == obj) { return true; }
if (obj instanceof Display) {
Display d = (Display)obj;
return d.getFQName().equals(getFQName());
}
return false;
}
/**
* Manual trigger the native creation, if it is not done yet.
* This is useful to be able to request the {@link javax.media.nativewindow.AbstractGraphicsDevice}, via
* {@link #getGraphicsDevice()}.
* Otherwise the abstract device won't be available before the dependent components (Screen and Window) are realized.
*
* This method is usually invoke by {@link #addReference()}
*
* @throws NativeWindowException if the native creation failed.
*/
public abstract void createNative() throws NativeWindowException;
/**
* Manually trigger the destruction, incl. native destruction.
*
* This method is usually invoke by {@link #removeReference()}
*
*/
public abstract void destroy();
/**
* Validate EDT running state.
* Stop the running EDT in case this display is destroyed already.
* @return true if EDT has been stopped (destroyed but running), otherwise false.
*/
public abstract boolean validateEDT();
/**
* @return true if the native display handle is valid and ready to operate,
* otherwise false.
*
* @see #destroy()
*/
public abstract boolean isNativeValid();
/**
* @return number of references
*/
public abstract int getReferenceCount();
/**
* The 1st call will initiate native creation,
* since we follow the lazy creation pattern.
*
* @return number of references post operation
* @throws NativeWindowException if the native creation failed.
* @see #removeReference()
*/
public abstract int addReference() throws NativeWindowException ;
/**
* The last call may destroy this instance,
* if {@link #getDestroyWhenUnused()} returns true
.
*
* @return number of references post operation
* @see #addReference()
* @see #getDestroyWhenUnused()
* @see #setDestroyWhenUnused(boolean)
*/
public abstract int removeReference();
/**
* Return the {@link AbstractGraphicsDevice} used for depending resources lifecycle,
* i.e. {@link Screen} and {@link Window}, as well as the event dispatching (EDT). */
public abstract AbstractGraphicsDevice getGraphicsDevice();
/**
* Return the handle of the {@link AbstractGraphicsDevice} as returned by {@link #getGraphicsDevice()}.
*/
public abstract long getHandle();
/**
* @return The fully qualified Display name,
* which is a key of {@link #getType()} + {@link #getName()} + {@link #getId()}.
*/
public abstract String getFQName();
/**
* @return this display internal serial id
*/
public abstract int getId();
/**
* @return This display connection name as defined at creation time.
* The display connection name is a technical platform specific detail, see {@link AbstractGraphicsDevice#getConnection()}.
*
* @see AbstractGraphicsDevice#getConnection()
*/
public abstract String getName();
/**
* @return the native display type, ie {@link javax.media.nativewindow.NativeWindowFactory#getNativeWindowType(boolean)}
*/
public abstract String getType();
/** Return true if this instance is exclusive, i.e. will not be shared. */
public abstract boolean isExclusive();
/**
* Sets a new {@link EDTUtil} and returns the previous one.
*
* If newEDTUtil
is null
,
* the device's default EDTUtil is created and used.
*
*
* If a previous one exists and it differs from the new one,
* it's being stopped, wait-until-idle and reset to allow a restart at a later time.
*
*
* If newEDTUtil
is not null and equals the previous one,
* no change is being made.
*
*
* Note that newEDTUtil
will be started by this method,
* if it is not running yet.
*
*/
public abstract EDTUtil setEDTUtil(EDTUtil newEDTUtil);
public abstract EDTUtil getEDTUtil();
public abstract boolean isEDTRunning();
public abstract void dispatchMessages();
// Global Displays
protected static final ArrayList displayList = new ArrayList();
protected static int displaysActive = 0;
public static void dumpDisplayList(String prefix) {
synchronized(displayList) {
Iterator i = displayList.iterator();
System.err.println(prefix+" DisplayList[] entries: "+displayList.size()+" - "+getThreadName());
for(int j=0; i.hasNext(); j++) {
Display d = i.next();
System.err.println(" ["+j+"] : "+d);
}
}
}
/**
*
* @param type
* @param name
* @param fromIndex start index, then increasing until found or end of list
* @paran shared if true, only shared instances are found, otherwise also exclusive
* @return
*/
public static Display getFirstDisplayOf(String type, String name, int fromIndex, boolean shared) {
return getDisplayOfImpl(type, name, fromIndex, 1, shared);
}
/**
*
* @param type
* @param name
* @param fromIndex start index, then decreasing until found or end of list. -1 is interpreted as size - 1.
* @paran shared if true, only shared instances are found, otherwise also exclusive
* @return
*/
public static Display getLastDisplayOf(String type, String name, int fromIndex, boolean shared) {
return getDisplayOfImpl(type, name, fromIndex, -1, shared);
}
private static Display getDisplayOfImpl(String type, String name, int fromIndex, int incr, boolean shared) {
synchronized(displayList) {
int i = fromIndex >= 0 ? fromIndex : displayList.size() - 1 ;
while( ( incr > 0 ) ? i < displayList.size() : i >= 0 ) {
Display display = (Display) displayList.get(i);
if( display.getType().equals(type) &&
display.getName().equals(name) &&
( !shared || shared && !display.isExclusive() )
) {
return display;
}
i+=incr;
}
}
return null;
}
/** Returns the global display collection */
@SuppressWarnings("unchecked")
public static Collection getAllDisplays() {
ArrayList list;
synchronized(displayList) {
list = (ArrayList) displayList.clone();
}
return list;
}
public static int getActiveDisplayNumber() {
synchronized(displayList) {
return displaysActive;
}
}
public static String getThreadName() {
return Thread.currentThread().getName();
}
public static String toHexString(int hex) {
return "0x" + Integer.toHexString(hex);
}
public static String toHexString(long hex) {
return "0x" + Long.toHexString(hex);
}
public static int hashCodeNullSafe(Object o) {
return ( null != o ) ? o.hashCode() : 0;
}
}