diff options
author | Sven Gothel <[email protected]> | 2008-06-28 14:30:26 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2008-06-28 14:30:26 +0000 |
commit | d96486967efcfb6f43226da9fa60cbc3d68ab323 (patch) | |
tree | adbda7e1a8fce8f3300c46dbba398783e4039a1e | |
parent | 8d00556b137564705a4ae8b963804d0adab078fb (diff) |
3rd round cdcfp - compile clean.
Re-adding cdcfp:
com/sun/opengl/impl/glu/mipmap/*
com/sun/opengl/impl/GLPbufferImpl.java
Using 'BufferUtil.nativeOrder(ByteBuffer)'
to set up the native byte order.
'BufferUtil.nativeOrder' is now public.
GLDrawableFactory:
- removed 'hardcoded' awt attribute.
Cleanup NEWT's AWT wrapping implementation.
- NativeWindowFactory incooperates with the wrapping property.
Bugs on X11/NEWT/AWT:
- no events
- deadlock at shutdown
- deadlock if EGLDrawable with AWT get's locked
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1700 232f8b59-042b-4e1e-8c03-345bb8c30851
58 files changed, 439 insertions, 262 deletions
diff --git a/etc/profile.jogl b/etc/profile.jogl index d3c44e125..08cdc80fe 100755 --- a/etc/profile.jogl +++ b/etc/profile.jogl @@ -16,7 +16,7 @@ function concat_jogl_list() echo $JOGL_LIST } -JOGL_AWT="jogl.awt.jar jogl.util.awt.jar" +JOGL_AWT="jogl.awt.jar jogl.util.awt.jar newt.awt.jar" JOGL_JAR_ALL="jogl.core.jar jogl.oswin.jar jogl.gles1.jar jogl.gles1.dbg.jar jogl.gles2.jar jogl.gles2.dbg.jar jogl.egl.jar jogl.gl2.jar jogl.gl2.dbg.jar jogl.util.jar jogl.util.gl2.jar newt.jar $JOGL_AWT" JOGL_LIB_ALL="libjogl_gl2.so libjogl_es1.so libjogl_es2.so libnewt.so libjogl_awt.so" diff --git a/make/build.xml b/make/build.xml index 3c62f2c36..b35641e43 100644 --- a/make/build.xml +++ b/make/build.xml @@ -149,7 +149,7 @@ <!-- partitioning --> <property name="java.part.egl" - value="com/sun/opengl/impl/egl/**"/> + value="com/sun/opengl/impl/egl/*"/> <property name="java.part.glugl2" value="com/sun/opengl/impl/glu/gl2/**, com/sun/opengl/impl/glu/nurbs/**, com/sun/opengl/impl/glu/registry/**, com/sun/opengl/impl/glu/tessellator/**, javax/media/opengl/glu/gl2/**"/> @@ -173,7 +173,7 @@ value="javax/media/opengl/TraceGLES2.*, javax/media/opengl/DebugGLES2.*"/> <property name="java.part.awt" - value="javax/media/opengl/awt/**, javax/media/opengl/util/awt/**, com/sun/opengl/impl/awt/**"/> + value="javax/media/opengl/awt/**, javax/media/opengl/util/awt/**, com/sun/opengl/impl/awt/**, com/sun/opengl/impl/egl/awt/*"/> <property name="java.part.util" value="com/sun/opengl/util/io/**, com/sun/opengl/util/texture/**"/> @@ -197,7 +197,10 @@ value="${java.part.x11}, ${java.part.win}, ${java.part.macosx}, com/sun/opengl/impl/jawt/*"/> <property name="java.part.newt" - value="com/sun/javafx/newt/**"/> + value="com/sun/javafx/newt/*, com/sun/javafx/newt/x11/*, com/sun/javafx/newt/windows/*"/> + + <property name="java.part.newt.awt" + value="com/sun/javafx/newt/awt/*"/> <!-- condition excludes --> @@ -233,7 +236,7 @@ </condition> <condition property="java.excludes.awt" - value="${java.part.awt}, ${java.part.util.awt}"> + value="${java.part.awt}, ${java.part.util.awt}, ${java.part.newt.awt}"> <isset property="jogl.noAWT"/> </condition> @@ -258,7 +261,7 @@ </condition> <condition property="java.excludes.newt" - value="${java.part.newt}"> + value="${java.part.newt}, ${java.part.newt.awt}"> <isset property="jogl.nonewt"/> </condition> @@ -271,7 +274,7 @@ </condition> <condition property="java.excludes.cdcfp" - value="com/sun/opengl/util/io/TGAWriter*, com/sun/opengl/impl/glu/mipmap/**, com/sun/opengl/impl/GLPbufferImpl*, com/sun/opengl/util/texture/**"> + value="com/sun/opengl/util/io/TGAWriter*, com/sun/opengl/util/texture/**"> <isset property="jogl.cdcfp"/> </condition> @@ -480,6 +483,7 @@ <property name="jogl.gl2.dbg.jar" value="${build}/jogl.gl2.dbg.jar" /> <property name="jogl.awt.jar" value="${build}/jogl.awt.jar" /> <property name="newt.jar" value="${build}/newt.jar" /> + <property name="newt.awt.jar" value="${build}/newt.awt.jar" /> <property name="jogl.oswin.jar" value="${build}/jogl.oswin.jar" /> <property name="jogl.util.jar" value="${build}/jogl.util.jar" /> <property name="jogl.util.gl2.jar" value="${build}/jogl.util.gl2.jar" /> @@ -1585,7 +1589,7 @@ <jar manifest="tempversion" destfile="${jogl.core.jar}"> <fileset dir="${classes}" includes="javax/media/opengl/**, com/sun/gluegen/runtime/**, com/sun/opengl/**" - excludes="${java.excludes.fixme} ${java.part.egl}, ${java.part.gl2}, ${java.part.gl2.dbg}, ${java.part.es1}, ${java.part.es1.dbg}, ${java.part.es2}, ${java.part.es2.dbg}, ${java.part.awt}, ${java.part.glugl2}, ${java.part.util} ${java.part.util.awt} ${java.part.util.gl2}, ${java.part.oswin}, ${java.part.newt}"/> + excludes="${java.excludes.fixme} ${java.part.egl}, ${java.part.gl2}, ${java.part.gl2.dbg}, ${java.part.es1}, ${java.part.es1.dbg}, ${java.part.es2}, ${java.part.es2.dbg}, ${java.part.awt}, ${java.part.glugl2}, ${java.part.util} ${java.part.util.awt} ${java.part.util.gl2}, ${java.part.oswin}, ${java.part.newt}, ${java.part.newt.awt}"/> </jar> <jar manifest="tempversion" destfile="${jogl.gles1.jar}"> <fileset dir="${classes}" @@ -1607,7 +1611,8 @@ </jar> <jar manifest="tempversion" destfile="${jogl.egl.jar}"> <fileset dir="${classes}" - includes="${java.part.egl}"/> + includes="${java.part.egl}" + excludes="${java.part.awt}"/> </jar> <jar manifest="tempversion" destfile="${jogl.gl2.jar}"> <fileset dir="${classes}" @@ -1627,6 +1632,10 @@ <fileset dir="${classes}" includes="${java.part.newt}"/> </jar> + <jar manifest="tempversion" destfile="${newt.awt.jar}"> + <fileset dir="${classes}" + includes="${java.part.newt.awt}"/> + </jar> <jar manifest="tempversion" destfile="${jogl.oswin.jar}"> <fileset dir="${classes}" includes="${java.part.oswin}" diff --git a/make/gl-es1.cfg b/make/gl-es1.cfg index 52a598657..227e4bcb5 100755 --- a/make/gl-es1.cfg +++ b/make/gl-es1.cfg @@ -205,4 +205,5 @@ IncludeAs CustomCCode gl-impl-CustomCCode.c Import javax.media.opengl.GLES1 Import javax.media.opengl.GLES2 Import javax.media.opengl.GL2 +Import javax.media.opengl.util.BufferUtil diff --git a/make/gl-es2.cfg b/make/gl-es2.cfg index c872bd84f..74620253f 100755 --- a/make/gl-es2.cfg +++ b/make/gl-es2.cfg @@ -199,4 +199,5 @@ IncludeAs CustomCCode gl-impl-CustomCCode.c Import javax.media.opengl.GLES1 Import javax.media.opengl.GLES2 Import javax.media.opengl.GL2 +Import javax.media.opengl.util.BufferUtil diff --git a/make/gl-impl-CustomJavaCode-gles1.java b/make/gl-impl-CustomJavaCode-gles1.java index e077acb8e..b50ae9eb2 100755 --- a/make/gl-impl-CustomJavaCode-gles1.java +++ b/make/gl-impl-CustomJavaCode-gles1.java @@ -252,7 +252,7 @@ public java.nio.ByteBuffer glMapBuffer(int target, int access) { java.nio.ByteBuffer _res = (java.nio.ByteBuffer) arbVBOCache.get(key); if (_res == null) { _res = InternalBufferUtils.newDirectByteBuffer(addr, sz); - // FIXME n.a. on JSR-239 CDC: _res.order(java.nio.ByteOrder.nativeOrder()); + BufferUtil.nativeOrder(_res); arbVBOCache.put(key, _res); } _res.position(0); diff --git a/make/gl-impl-CustomJavaCode-gles2.java b/make/gl-impl-CustomJavaCode-gles2.java index d20635ae6..3441b6e63 100755 --- a/make/gl-impl-CustomJavaCode-gles2.java +++ b/make/gl-impl-CustomJavaCode-gles2.java @@ -241,7 +241,7 @@ public java.nio.ByteBuffer glMapBuffer(int target, int access) { java.nio.ByteBuffer _res = (java.nio.ByteBuffer) arbVBOCache.get(key); if (_res == null) { _res = InternalBufferUtils.newDirectByteBuffer(addr, sz); - // FIXME n.a. on JSR-239 CDC: _res.order(java.nio.ByteOrder.nativeOrder()); + BufferUtil.nativeOrder(_res); arbVBOCache.put(key, _res); } _res.position(0); diff --git a/make/glu-CustomJavaCode-gl2.java b/make/glu-CustomJavaCode-gl2.java index 8087d45c9..df76f715e 100644 --- a/make/glu-CustomJavaCode-gl2.java +++ b/make/glu-CustomJavaCode-gl2.java @@ -1387,7 +1387,7 @@ private static final GLUgl2ProcAddressTable getGLUProcAddressTable() { } if (gluProcAddressTable == null) { GLUgl2ProcAddressTable tmp = new GLUgl2ProcAddressTable(); - ProcAddressHelper.resetProcAddressTable(tmp, GLDrawableFactoryImpl.getFactoryImpl(false)); + ProcAddressHelper.resetProcAddressTable(tmp, GLDrawableFactoryImpl.getFactoryImpl()); gluProcAddressTable = tmp; } return gluProcAddressTable; @@ -1395,7 +1395,7 @@ private static final GLUgl2ProcAddressTable getGLUProcAddressTable() { private static final synchronized void loadGLULibrary() { if (!gluLibraryLoaded) { - GLDrawableFactoryImpl.getFactoryImpl(false).loadGLULibrary(); + GLDrawableFactoryImpl.getFactoryImpl().loadGLULibrary(); gluLibraryLoaded = true; } } diff --git a/make/glu-CustomJavaCode-gles1.java b/make/glu-CustomJavaCode-gles1.java index 5023f7584..197e7d7f1 100755 --- a/make/glu-CustomJavaCode-gles1.java +++ b/make/glu-CustomJavaCode-gles1.java @@ -239,8 +239,6 @@ public final void gluPickMatrix(double x, double y, double delX, double delY, In //---------------------------------------------------------------------- // Mipmap and image scaling functionality -/* FIXME n.a. on JSR-239 CDC: java.nio.ByteOrder, used by mipmap - private final java.nio.ByteBuffer copyToByteBuffer(java.nio.Buffer buf) { if (buf instanceof java.nio.ByteBuffer) { if (buf.position() == 0) { @@ -344,8 +342,6 @@ public final int gluBuild3DMipmaps( int target, int internalFormat, int width, depth, format, type, buffer ) ); } -*/ - //---------------------------------------------------------------------- // GLUProcAddressTable handling // diff --git a/make/glu-CustomJavaCode-gles1_if.java b/make/glu-CustomJavaCode-gles1_if.java index 6e17e6a3e..bb9f3d54d 100755 --- a/make/glu-CustomJavaCode-gles1_if.java +++ b/make/glu-CustomJavaCode-gles1_if.java @@ -356,8 +356,6 @@ public abstract void gluPickMatrix(double x, double y, double delX, double delY, public abstract void gluPickMatrix(double x, double y, double delX, double delY, IntBuffer viewport) ; -/* FIXME n.a. on JSR-239 CDC: java.nio.ByteOrder, used by mipmap - public abstract int gluScaleImage( int format, int widthin, int heightin, int typein, java.nio.Buffer datain, int widthout, int heightout, int typeout, java.nio.Buffer dataout ) ; @@ -382,4 +380,3 @@ public abstract int gluBuild3DMipmapLevels( int target, int internalFormat, int public abstract int gluBuild3DMipmaps( int target, int internalFormat, int width, int height, int depth, int format, int type, java.nio.Buffer data ) ; -*/ diff --git a/make/glu-es1.cfg b/make/glu-es1.cfg index 02d529fde..17234e6e5 100755 --- a/make/glu-es1.cfg +++ b/make/glu-es1.cfg @@ -22,8 +22,7 @@ IncludeAs CustomJavaCode GLUes1 glu-CustomJavaCode-gles1.java Import javax.media.opengl.GLES1 Import javax.media.opengl.glu.GLU Import javax.media.opengl.util.BufferUtil -# FIXME n.a. on JSR-239 CDC: java.nio.ByteOrder, used by mipmap -# Import com.sun.opengl.impl.glu.mipmap.Mipmap +Import com.sun.opengl.impl.glu.mipmap.Mipmap Include glu-common.cfg diff --git a/src/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java b/src/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java index 2040c55d1..4bf967a02 100755 --- a/src/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java +++ b/src/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java @@ -45,7 +45,7 @@ public class TestSpatialization { try { // FIXME: this is a hack to get the native library loaded try { - GLDrawableFactory.getFactory(GLDrawableFactory.PROFILE_GLES1, null); + GLDrawableFactory.getFactory(NativeWindow.class); } catch (Exception e) {} // Initialize the audio subsystem Audio audio = Audio.getInstance(); diff --git a/src/classes/com/sun/javafx/newt/Display.java b/src/classes/com/sun/javafx/newt/Display.java index cd3aa75d0..988283aa3 100755 --- a/src/classes/com/sun/javafx/newt/Display.java +++ b/src/classes/com/sun/javafx/newt/Display.java @@ -45,7 +45,7 @@ public abstract class Display { displayClass = Class.forName("com.sun.javafx.newt.windows.WindowsDisplay"); } else if (NewtFactory.X11.equals(type)) { displayClass = Class.forName("com.sun.javafx.newt.x11.X11Display"); - } else if (NewtFactory.MACOSX.equals(type)) { + } else if (NewtFactory.AWT.equals(type)) { displayClass = Class.forName("com.sun.javafx.newt.awt.AWTDisplay"); } else { throw new RuntimeException("Unknown display type \"" + type + "\""); diff --git a/src/classes/com/sun/javafx/newt/NewtFactory.java b/src/classes/com/sun/javafx/newt/NewtFactory.java index 9f19be289..feb623caa 100755 --- a/src/classes/com/sun/javafx/newt/NewtFactory.java +++ b/src/classes/com/sun/javafx/newt/NewtFactory.java @@ -49,6 +49,9 @@ public abstract class NewtFactory { /** Mac OS X window type */ public static final String MACOSX = "MacOSX"; + /** Generic AWT wrapped window type, if available */ + public static final String AWT = "AWT"; + /** Creates a Window of the default type for the current operating system. */ public static String getWindowType() { String osName = System.getProperty("os.name"); @@ -57,7 +60,11 @@ public abstract class NewtFactory { if (osNameLowerCase.startsWith("wind")) { windowType = WINDOWS; } else if (osNameLowerCase.startsWith("mac os x")) { - windowType = MACOSX; + // For the time being, use the AWT on Mac OS X since + // there's no advantage to avoiding its usage -- this + // would change if we were running on the iPhone and + // didn't have an AWT + windowType = AWT; } else { windowType = X11; } @@ -72,6 +79,13 @@ public abstract class NewtFactory { } /** + * Create a Display entity using the given implementation type, incl native creation + */ + public static Display createDisplay(String type, String name) { + return Display.create(type, name); + } + + /** * Create a Screen entity, incl native creation */ public static Screen createScreen(Display display, int index) { @@ -79,6 +93,13 @@ public abstract class NewtFactory { } /** + * Create a Screen entity using the given implementation type, incl native creation + */ + public static Screen createScreen(String type, Display display, int index) { + return Screen.create(type, display, index); + } + + /** * Create a Window entity, incl native creation */ public static Window createWindow(Screen screen, long visualID) { @@ -86,6 +107,13 @@ public abstract class NewtFactory { } /** + * Create a Window entity using the given implementation type, incl native creation + */ + public static Window createWindow(String type, Screen screen, long visualID) { + return Window.create(type, screen, visualID); + } + + /** * Instantiate a Display entity using the native handle. */ public static Display wrapDisplay(String name, long handle) { @@ -108,5 +136,17 @@ public abstract class NewtFactory { return Window.wrapHandle(getWindowType(), screen, visualID, windowHandle, fullscreen, visible, x, y, width, height); } + + private static final boolean instanceOf(Object obj, String clazzName) { + Class clazz = obj.getClass(); + do { + if(clazz.getName().equals(clazzName)) { + return true; + } + clazz = clazz.getSuperclass(); + } while (clazz!=null); + return false; + } + } diff --git a/src/classes/com/sun/javafx/newt/Screen.java b/src/classes/com/sun/javafx/newt/Screen.java index 67322b97f..efb75577c 100755 --- a/src/classes/com/sun/javafx/newt/Screen.java +++ b/src/classes/com/sun/javafx/newt/Screen.java @@ -45,7 +45,7 @@ public abstract class Screen { screenClass = Class.forName("com.sun.javafx.newt.windows.WindowsScreen"); } else if (NewtFactory.X11.equals(type)) { screenClass = Class.forName("com.sun.javafx.newt.x11.X11Screen"); - } else if (NewtFactory.MACOSX.equals(type)) { + } else if (NewtFactory.AWT.equals(type)) { screenClass = Class.forName("com.sun.javafx.newt.awt.AWTScreen"); } else { throw new RuntimeException("Unknown window type \"" + type + "\""); diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java index faf98d3d0..1486091e8 100755 --- a/src/classes/com/sun/javafx/newt/Window.java +++ b/src/classes/com/sun/javafx/newt/Window.java @@ -55,11 +55,7 @@ public abstract class Window implements NativeWindow windowClass = Class.forName("com.sun.javafx.newt.windows.WindowsWindow"); } else if (NewtFactory.X11.equals(type)) { windowClass = Class.forName("com.sun.javafx.newt.x11.X11Window"); - } else if (NewtFactory.MACOSX.equals(type)) { - // For the time being, use the AWT on Mac OS X since - // there's no advantage to avoiding its usage -- this - // would change if we were running on the iPhone and - // didn't have an AWT + } else if (NewtFactory.AWT.equals(type)) { windowClass = Class.forName("com.sun.javafx.newt.awt.AWTWindow"); } else { throw new RuntimeException("Unknown window type \"" + type + "\""); @@ -106,6 +102,8 @@ public abstract class Window implements NativeWindow } } + public abstract boolean isTerminalObject(); + /** * create native windowHandle, ie creates a new native invisible window */ @@ -142,9 +140,12 @@ public abstract class Window implements NativeWindow protected abstract void dispatchMessages(int eventMask); public String toString() { - return "Window[handle "+windowHandle+ + return "NEWT-Window[windowHandle "+getWindowHandle()+ + ", surfaceHandle "+getSurfaceHandle()+ ", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ - ", visible "+isVisible()+"]"; + ", visible "+isVisible()+ + ", wrappedWindow "+getWrappedWindow()+ + ", terminalObject "+isTerminalObject()+"]"; } protected Screen screen; diff --git a/src/classes/com/sun/javafx/newt/awt/AWTWindow.java b/src/classes/com/sun/javafx/newt/awt/AWTWindow.java index b7ac5c5d6..1e0f8d6ee 100644 --- a/src/classes/com/sun/javafx/newt/awt/AWTWindow.java +++ b/src/classes/com/sun/javafx/newt/awt/AWTWindow.java @@ -57,6 +57,10 @@ public class AWTWindow extends Window { private int displayWidth; private int displayHeight; + public final boolean isTerminalObject() { + return false; + } + protected void createNative() { runOnEDT(new Runnable() { public void run() { @@ -162,6 +166,9 @@ public class AWTWindow extends Window { e.getKeyCode(), e.getKeyChar()); } } + if(DEBUG_MOUSE_EVENT) { + System.out.println("dispatchMessages: in event:"+w.getEvent()); + } } } while (w != null); } @@ -199,6 +206,9 @@ public class AWTWindow extends Window { } private void enqueueEvent(boolean isMouseEvent, int type, InputEvent e) { + if(DEBUG_MOUSE_EVENT) { + System.out.println("enqueueEvent: mouse"+isMouseEvent+", event: "+e); + } AWTEventWrapper wrapper = new AWTEventWrapper(isMouseEvent,type, e); synchronized(this) { events.add(wrapper); diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java index 3ee6dbb0f..00ecd5973 100755 --- a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java +++ b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java @@ -52,6 +52,10 @@ public class WindowsWindow extends Window { public WindowsWindow() { } + public final boolean isTerminalObject() { + return true; + } + public long getSurfaceHandle() { if (hdc == 0) { hdc = GetDC(windowHandle); diff --git a/src/classes/com/sun/javafx/newt/x11/X11Window.java b/src/classes/com/sun/javafx/newt/x11/X11Window.java index 101ee813b..290b1e506 100755 --- a/src/classes/com/sun/javafx/newt/x11/X11Window.java +++ b/src/classes/com/sun/javafx/newt/x11/X11Window.java @@ -53,6 +53,10 @@ public class X11Window extends Window { public X11Window() { } + public final boolean isTerminalObject() { + return true; + } + protected void createNative() { long w = CreateWindow(getDisplayHandle(), getScreenHandle(), getScreenIndex(), visualID, x, y, width, height); if (w == 0 || w!=windowHandle) { diff --git a/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java b/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java index 21fe5b386..6eb405b0d 100644 --- a/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java +++ b/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java @@ -62,12 +62,12 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory implements super(); } - public static GLDrawableFactoryImpl getFactoryImpl(boolean awt) { - return (GLDrawableFactoryImpl) getFactory(awt); + public static GLDrawableFactoryImpl getFactoryImpl(Class winClazz) { + return (GLDrawableFactoryImpl) getFactory(winClazz); } - public static GLDrawableFactoryImpl getFactoryImpl(Object target) { - return (GLDrawableFactoryImpl) getFactory(target); + public static GLDrawableFactoryImpl getFactoryImpl() { + return (GLDrawableFactoryImpl) getFactory(); } // Helper function for more lazily loading the GLU library; diff --git a/src/classes/com/sun/opengl/impl/GLDrawableImpl.java b/src/classes/com/sun/opengl/impl/GLDrawableImpl.java index 26f3d6585..3053a91de 100644 --- a/src/classes/com/sun/opengl/impl/GLDrawableImpl.java +++ b/src/classes/com/sun/opengl/impl/GLDrawableImpl.java @@ -52,6 +52,7 @@ public abstract class GLDrawableImpl implements GLDrawable { /** For offscreen GLDrawables (pbuffers and "pixmap" drawables), indicates that native resources should be reclaimed. */ public void destroy() throws GLException { + setRealized(false); } public void swapBuffers() throws GLException { @@ -125,6 +126,12 @@ public abstract class GLDrawableImpl implements GLDrawable { return component.isSurfaceLocked(); } + public String toString() { + return "GLDrawable[realized "+getRealized()+ + ", window "+getNativeWindow()+ + ", factory "+getFactory()+"]"; + } + protected GLDrawableFactory factory; protected NativeWindow component; private GLCapabilities chosenCapabilities; diff --git a/src/classes/com/sun/opengl/impl/GLPbufferImpl.java b/src/classes/com/sun/opengl/impl/GLPbufferImpl.java index 7a7b2772a..1f48ae8a1 100644 --- a/src/classes/com/sun/opengl/impl/GLPbufferImpl.java +++ b/src/classes/com/sun/opengl/impl/GLPbufferImpl.java @@ -43,8 +43,8 @@ package com.sun.opengl.impl; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.event.*; - */ import java.beans.PropertyChangeListener; + */ import javax.media.opengl.*; @@ -186,20 +186,6 @@ public class GLPbufferImpl implements GLPbuffer { return surfaceLocked; } - private boolean tkLocked = false; - - public void lockToolkit() throws GLException { - tkLocked=true; - } - - public void unlockToolkit() { - tkLocked=false; - } - - public boolean isToolkitLocked() { - return tkLocked; - } - //---------------------------------------------------------------------- // No-ops for ComponentEvents // diff --git a/src/classes/com/sun/opengl/impl/GLReflection.java b/src/classes/com/sun/opengl/impl/GLReflection.java index 94e004f30..6898db82d 100644 --- a/src/classes/com/sun/opengl/impl/GLReflection.java +++ b/src/classes/com/sun/opengl/impl/GLReflection.java @@ -89,7 +89,9 @@ public final class GLReflection { } public static final boolean instanceOf(Object obj, String clazzName) { - Class clazz = obj.getClass(); + return instanceOf(obj.getClass(), clazzName); + } + public static final boolean instanceOf(Class clazz, String clazzName) { do { if(clazz.getName().equals(clazzName)) { return true; @@ -100,15 +102,29 @@ public final class GLReflection { } public static final boolean implementationOf(Object obj, String faceName) { - Class[] clazzes = obj.getClass().getInterfaces(); - for(int i=clazzes.length-1; i>=0; i--) { - Class face = clazzes[i]; - if(face.getName().equals(faceName)) { - return true; + return implementationOf(obj.getClass(), faceName); + } + public static final boolean implementationOf(Class clazz, String faceName) { + do { + Class[] clazzes = clazz.getInterfaces(); + for(int i=clazzes.length-1; i>=0; i--) { + Class face = clazzes[i]; + if(face.getName().equals(faceName)) { + return true; + } } - } + clazz = clazz.getSuperclass(); + } while (clazz!=null); return false; } + public static boolean isAWTComponent(Object target) { + return instanceOf(target, "java.awt.Component"); + } + + public static boolean isAWTComponent(Class clazz) { + return instanceOf(clazz, "java.awt.Component"); + } + } diff --git a/src/classes/com/sun/opengl/impl/NullWindow.java b/src/classes/com/sun/opengl/impl/NullWindow.java index ef23083b0..a366a734a 100644 --- a/src/classes/com/sun/opengl/impl/NullWindow.java +++ b/src/classes/com/sun/opengl/impl/NullWindow.java @@ -109,6 +109,10 @@ public class NullWindow implements NativeWindow { return null; } + public final boolean isTerminalObject() { + return true; + } + public void setSize(int width, int height) { this.width=width; this.height=height; diff --git a/src/classes/com/sun/opengl/impl/awt/Java2D.java b/src/classes/com/sun/opengl/impl/awt/Java2D.java index 0595dbed7..0611f799f 100755 --- a/src/classes/com/sun/opengl/impl/awt/Java2D.java +++ b/src/classes/com/sun/opengl/impl/awt/Java2D.java @@ -40,6 +40,7 @@ package com.sun.opengl.impl.awt; import com.sun.opengl.impl.*; +import com.sun.opengl.impl.jawt.*; import java.awt.*; import java.awt.image.*; @@ -288,11 +289,11 @@ public class Java2D { getDefaultScreenDevice(). getDefaultConfiguration()); - GLDrawableFactoryImpl.getFactoryImpl(true).lockToolkit(); + JAWTUtil.lockToolkit(); try { invokeWithOGLContextCurrentMethod.invoke(null, new Object[] {g, r}); } finally { - GLDrawableFactoryImpl.getFactory(true).unlockToolkit(); + JAWTUtil.unlockToolkit(); } } catch (InvocationTargetException e) { throw new GLException(e.getTargetException()); @@ -313,11 +314,11 @@ public class Java2D { checkActive(); try { - GLDrawableFactoryImpl.getFactoryImpl(true).lockToolkit(); + JAWTUtil.lockToolkit(); try { return ((Boolean) invokeWithOGLSharedContextCurrentMethod.invoke(null, new Object[] {g, r})).booleanValue(); } finally { - GLDrawableFactoryImpl.getFactoryImpl(true).unlockToolkit(); + JAWTUtil.unlockToolkit(); } } catch (InvocationTargetException e) { throw new GLException(e.getTargetException()); @@ -558,7 +559,7 @@ public class Java2D { } invokeWithOGLSharedContextCurrent(gc, new Runnable() { public void run() { - j2dFBOShareContext = GLDrawableFactory.getFactory(true).createExternalGLContext(); + j2dFBOShareContext = GLDrawableFactory.getFactory(Component.class).createExternalGLContext(); } }); if (DEBUG) { diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java index b562d7423..034471b00 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java @@ -82,7 +82,11 @@ public class EGLDrawable extends GLDrawableImpl { public void destroy() { setRealized(false); - EGL.eglTerminate(display); + if(EGL.EGL_NO_DISPLAY!=display) { + EGL.eglTerminate(display); + display=EGL.EGL_NO_DISPLAY; + } + super.destroy(); } public _EGLConfig getConfig() { @@ -99,10 +103,18 @@ public class EGLDrawable extends GLDrawableImpl { public void setRealized(boolean realized) { if (realized) { - // Create the window surface - surface = EGL.eglCreateWindowSurface(display, config, component.getWindowHandle(), null); + getFactory().lockToolkit(); + try { + lockSurface(); + + // Create the window surface + surface = EGL.eglCreateWindowSurface(display, config, component.getWindowHandle(), null); + } finally { + unlockSurface(); + getFactory().unlockToolkit(); + } if (surface == EGL.EGL_NO_SURFACE) { - throw new GLException("Creation of window surface (eglCreateWindowSurface) failed"); + throw new GLException("Creation of window surface (eglCreateWindowSurface) failed, component: "+component); } } else if( surface != EGL.EGL_NO_SURFACE ) { // Destroy the window surface @@ -115,6 +127,7 @@ public class EGLDrawable extends GLDrawableImpl { } surface = EGL.EGL_NO_SURFACE; } + super.setRealized(realized); } public void setSize(int width, int height) { @@ -136,16 +149,28 @@ public class EGLDrawable extends GLDrawableImpl { } public void swapBuffers() throws GLException { - EGL.eglSwapBuffers(display, surface); + getFactory().lockToolkit(); + try { + if (component.getSurfaceHandle() == 0) { + if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { + return; + } + } + + EGL.eglSwapBuffers(display, surface); + + } finally { + unlockSurface(); + getFactory().unlockToolkit(); + } } public String toString() { - return "EGLDrawable[ displayHandle " + component.getDisplayHandle() + - ", screenHandle "+ component.getScreenHandle() + - ", windowHandle "+ component.getWindowHandle() + - ", display " + display + - ", config " + config + - ", surface " + surface + - "]"; + return "EGLDrawable[ realized "+getRealized()+ + ", window "+getNativeWindow()+ + ", egl display " + display + + ", egl config " + config + + ", egl surface " + surface + + ", factory "+getFactory()+"]"; } } diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java index a01dd91c7..00f293ffb 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java @@ -115,6 +115,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { public GLDrawable createGLDrawable(NativeWindow target, GLCapabilities capabilities, GLCapabilitiesChooser chooser) { + target = NativeWindowFactory.getNativeWindow(target); return new EGLDrawable(this, target, capabilities, chooser); diff --git a/src/classes/com/sun/opengl/impl/NativeWindowHelper.java b/src/classes/com/sun/opengl/impl/egl/awt/EGLAWTDrawableFactory.java index 5432d8cb1..e5d1387e8 100644 --- a/src/classes/com/sun/opengl/impl/NativeWindowHelper.java +++ b/src/classes/com/sun/opengl/impl/egl/awt/EGLAWTDrawableFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -29,22 +29,27 @@ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. */ -package com.sun.opengl.impl; +package com.sun.opengl.impl.egl.awt; -import javax.media.opengl.*; +import com.sun.opengl.impl.*; +import com.sun.opengl.impl.egl.*; +import com.sun.opengl.impl.jawt.*; -/** Helper class to assist in the case where for example a Newt window - wraps an AWT window. */ +public class EGLAWTDrawableFactory extends EGLDrawableFactory { -public class NativeWindowHelper { - private NativeWindowHelper() {} + public void lockToolkit() { + super.lockToolkit(); + // freezes AWT: JAWTUtil.lockToolkit(); + } + + public void unlockToolkit() { + // freezes AWT: JAWTUtil.unlockToolkit(); + super.unlockToolkit(); + } - public static NativeWindow unwrap(NativeWindow target) { - if (target.getWrappedWindow() != null) { - target = NativeWindowFactory.getNativeWindow(target.getWrappedWindow()); - } - return target; - } } diff --git a/src/classes/com/sun/opengl/impl/glu/mipmap/BuildMipmap.java b/src/classes/com/sun/opengl/impl/glu/mipmap/BuildMipmap.java index 878eeabe7..c30f83d20 100644 --- a/src/classes/com/sun/opengl/impl/glu/mipmap/BuildMipmap.java +++ b/src/classes/com/sun/opengl/impl/glu/mipmap/BuildMipmap.java @@ -47,6 +47,7 @@ package com.sun.opengl.impl.glu.mipmap; import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.glu.GLU; +import javax.media.opengl.util.BufferUtil; import com.sun.opengl.impl.Debug; import java.nio.*; import java.io.*; @@ -73,7 +74,7 @@ public class BuildMipmap { int newImage_width; ShortBuffer otherImage = null; ShortBuffer imageTemp = null; - int memreq; + int memReq; int maxsize; int cmpts; PixelStorageModes psm = new PixelStorageModes(); @@ -88,8 +89,8 @@ public class BuildMipmap { Mipmap.retrieveStoreModes( gl, psm ); try { - newImage = ByteBuffer.allocateDirect( Mipmap.image_size( width, 1, format, - GL2.GL_UNSIGNED_SHORT ) ).order( ByteOrder.nativeOrder() ).asShortBuffer(); + newImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.image_size( width, 1, format, + GL2.GL_UNSIGNED_SHORT ) )).asShortBuffer(); } catch( OutOfMemoryError ome ) { return( GLU.GLU_OUT_OF_MEMORY ); } @@ -114,9 +115,9 @@ public class BuildMipmap { } } else { if( otherImage == null ) { - memreq = Mipmap.image_size( newwidth, 1, format, GL2.GL_UNSIGNED_SHORT ); + memReq = Mipmap.image_size( newwidth, 1, format, GL2.GL_UNSIGNED_SHORT ); try { - otherImage = ByteBuffer.allocateDirect( memreq ).order( ByteOrder.nativeOrder() ).asShortBuffer(); + otherImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )).asShortBuffer(); } catch( OutOfMemoryError ome ) { gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); @@ -161,7 +162,7 @@ public class BuildMipmap { int newImage_height; ShortBuffer otherImage = null; ShortBuffer tempImage = null; - int memreq; + int memReq; int maxsize; int cmpts; PixelStorageModes psm = new PixelStorageModes(); @@ -177,8 +178,8 @@ public class BuildMipmap { } try { - newImage = ByteBuffer.allocateDirect( Mipmap.image_size( width, height, - format, GL2.GL_UNSIGNED_SHORT ) ).order( ByteOrder.nativeOrder() ).asShortBuffer(); + newImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.image_size( width, height, + format, GL2.GL_UNSIGNED_SHORT ) )).asShortBuffer(); } catch( OutOfMemoryError ome ) { return( GLU.GLU_OUT_OF_MEMORY ); } @@ -203,9 +204,9 @@ public class BuildMipmap { newImage_height, 0, format, GL2.GL_UNSIGNED_SHORT, newImage ); } else { if( otherImage == null ) { - memreq = Mipmap.image_size( newwidth[0], newheight[0], format, GL2.GL_UNSIGNED_SHORT ); + memReq = Mipmap.image_size( newwidth[0], newheight[0], format, GL2.GL_UNSIGNED_SHORT ); try { - otherImage = ByteBuffer.allocateDirect( memreq ).order( ByteOrder.nativeOrder() ).asShortBuffer(); + otherImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )).asShortBuffer(); } catch( OutOfMemoryError ome ) { gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); @@ -258,9 +259,10 @@ public class BuildMipmap { int newImage_width; int newImage_height; short[] SWAP_IMAGE = null; - int memreq; + int memReq; int maxsize; int cmpts; + int mark=-1; boolean myswap_bytes; int groups_per_line, element_size, group_size; @@ -305,8 +307,8 @@ public class BuildMipmap { rowsize += psm.getUnpackAlignment() - padding; } - data.position( psm.getUnpackSkipRows() * rowsize + psm.getUnpackSkipPixels() * group_size ); - data.mark(); + mark = psm.getUnpackSkipRows() * rowsize + psm.getUnpackSkipPixels() * group_size; + data.position( mark ); gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, 0 ); gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, 0 ); @@ -339,7 +341,7 @@ public class BuildMipmap { if( nextHeight < 1 ) { nextHeight = 1; } - memreq = Mipmap.image_size( nextWidth, nextHeight, format, type ); + memReq = Mipmap.image_size( nextWidth, nextHeight, format, type ); try { switch( type ) { @@ -362,7 +364,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = ByteBuffer.allocateDirect( memreq ).order( ByteOrder.nativeOrder() ); + dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -453,7 +455,7 @@ public class BuildMipmap { myswap_bytes = false; rowsize = newwidth * group_size; - memreq = Mipmap.image_size( newwidth, newheight, format, type ); + memReq = Mipmap.image_size( newwidth, newheight, format, type ); // swap srcImage and dstImage tempImage = srcImage; srcImage = dstImage; @@ -479,7 +481,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = ByteBuffer.allocateDirect( memreq ).order( ByteOrder.nativeOrder() ); + dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -495,7 +497,7 @@ public class BuildMipmap { // level userLevel+1 is in srcImage; level userLevel already saved level = userLevel + 1; } else { // user's image is not nice powerof2 size square - memreq = Mipmap.image_size( newwidth, newheight, format, type ); + memReq = Mipmap.image_size( newwidth, newheight, format, type ); try { switch( type ) { case( GL2.GL_UNSIGNED_BYTE ): @@ -517,7 +519,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = ByteBuffer.allocateDirect( memreq ).order( ByteOrder.nativeOrder() ); + dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -530,7 +532,7 @@ public class BuildMipmap { gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, (psm.getUnpackSwapBytes() ? 1 : 0) ); return( GLU.GLU_OUT_OF_MEMORY ); } - data.reset(); + data.position( mark ); switch( type ) { case( GL2.GL_UNSIGNED_BYTE ): ScaleInternal.scale_internal_ubyte( cmpts, width, height, data, @@ -629,7 +631,7 @@ public class BuildMipmap { nextHeight = 1; } - memreq = Mipmap.image_size( nextWidth, nextHeight, format, type ); + memReq = Mipmap.image_size( nextWidth, nextHeight, format, type ); try { switch( type ) { case( GL2.GL_UNSIGNED_BYTE ): @@ -651,7 +653,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = ByteBuffer.allocateDirect( memreq ).order( ByteOrder.nativeOrder() ); + dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -845,7 +847,7 @@ public class BuildMipmap { int newImage_height; ByteBuffer otherImage; ByteBuffer imageTemp; - int memreq; + int memReq; int maxsize; int cmpts; @@ -878,8 +880,8 @@ public class BuildMipmap { int i, j; try { - newImage = ByteBuffer.allocateDirect( Mipmap.image_size( - width, height, format, GL2.GL_UNSIGNED_BYTE ) ).order( ByteOrder.nativeOrder() ); + newImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.image_size( + width, height, format, GL2.GL_UNSIGNED_BYTE ) )); } catch( OutOfMemoryError err ) { return( GLU.GLU_OUT_OF_MEMORY ); } @@ -920,9 +922,9 @@ public class BuildMipmap { 0, format, GL2.GL_UNSIGNED_BYTE, newImage ); } else { if( otherImage == null ) { - memreq = Mipmap.image_size( newwidth[0], newheight[0], format, GL2.GL_UNSIGNED_BYTE ); + memReq = Mipmap.image_size( newwidth[0], newheight[0], format, GL2.GL_UNSIGNED_BYTE ); try { - otherImage = ByteBuffer.allocateDirect( memreq ).order( ByteOrder.nativeOrder() ); + otherImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); } catch( OutOfMemoryError err ) { gl.glPixelStorei( GL2.GL_UNPACK_ALIGNMENT, psm.getUnpackAlignment() ); gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, psm.getUnpackSkipRows() ); @@ -975,6 +977,7 @@ public class BuildMipmap { int memReq; int maxSize; int cmpts; + int mark=-1; boolean myswapBytes; int groupsPerLine, elementSize, groupSize; @@ -1033,11 +1036,11 @@ public class BuildMipmap { imageSize = rowsPerImage * rowSize; - usersImage = data.duplicate(); - usersImage.position( psm.getUnpackSkipRows() * rowSize + - psm.getUnpackSkipPixels() * groupSize + - psm.getUnpackSkipImages() * imageSize ); - usersImage.mark(); + usersImage = ByteBuffer.wrap(data.array()); + mark = psm.getUnpackSkipRows() * rowSize + + psm.getUnpackSkipPixels() * groupSize + + psm.getUnpackSkipImages() * imageSize; + usersImage.position( mark ); gl.glPixelStorei( GL2.GL_UNPACK_SKIP_ROWS, 0 ); gl.glPixelStorei( GL2.GL_UNPACK_SKIP_PIXELS, 0 ); @@ -1099,7 +1102,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = ByteBuffer.allocateDirect( memReq ).order( ByteOrder.nativeOrder() ); + dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -1285,7 +1288,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = ByteBuffer.allocateDirect( memReq ).order( ByteOrder.nativeOrder() ); + dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -1326,7 +1329,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = ByteBuffer.allocateDirect( memReq ).order( ByteOrder.nativeOrder() ); + dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -1388,7 +1391,7 @@ public class BuildMipmap { case( GL2.GL_UNSIGNED_INT_8_8_8_8_REV ): case( GL2.GL_UNSIGNED_INT_10_10_10_2 ): case( GL2.GL_UNSIGNED_INT_2_10_10_10_REV ): - dstImage = ByteBuffer.allocateDirect( memReq ).order( ByteOrder.nativeOrder() ); + dstImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( memReq )); break; default: return( GLU.GLU_INVALID_ENUM ); @@ -1410,7 +1413,7 @@ public class BuildMipmap { gl.glPixelStorei( GL2.GL_UNPACK_SWAP_BYTES, GL2.GL_FALSE ); if( baseLevel <= level && level <= maxLevel ) { - usersImage.reset(); + usersImage.position( mark ); gl.getGL2().glTexImage3D( target, level, internalFormat, width, height, depth, 0, format, type, usersImage ); } @@ -1556,7 +1559,7 @@ public class BuildMipmap { newDepth /= 2; } if( baseLevel <= level && level <= maxLevel ) { - usersImage.reset(); + usersImage.position( mark ); gl.getGL2().glTexImage3D( target, level, internalFormat, width, height, depth, 0, format, type, usersImage ); } @@ -1576,7 +1579,7 @@ public class BuildMipmap { int width, int height) { try { FileOutputStream fos = new FileOutputStream(new File(filename)); - ByteBuffer header = ByteBuffer.allocate(TARGA_HEADER_SIZE); + ByteBuffer header = ByteBuffer.allocateDirect(TARGA_HEADER_SIZE); header.put(0, (byte) 0).put(1, (byte) 0); header.put(2, (byte) 2); // uncompressed type header.put(12, (byte) (width & 0xFF)); // width @@ -1584,8 +1587,8 @@ public class BuildMipmap { header.put(14, (byte) (height & 0xFF)); // height header.put(15, (byte) (height >> 8)); // height header.put(16, (byte) 24); // pixel size - fos.getChannel().write(header); - fos.getChannel().write(data); + fos.write(header.array()); + fos.write(data.array()); data.clear(); fos.close(); } catch (IOException e) { diff --git a/src/classes/com/sun/opengl/impl/glu/mipmap/Mipmap.java b/src/classes/com/sun/opengl/impl/glu/mipmap/Mipmap.java index 6f247940d..b048bf1f5 100644 --- a/src/classes/com/sun/opengl/impl/glu/mipmap/Mipmap.java +++ b/src/classes/com/sun/opengl/impl/glu/mipmap/Mipmap.java @@ -47,6 +47,7 @@ package com.sun.opengl.impl.glu.mipmap; import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.glu.GLU; +import javax.media.opengl.util.BufferUtil; import javax.media.opengl.GLException; import java.nio.*; @@ -573,8 +574,8 @@ public class Mipmap { if( !isLegalFormatForPackedPixelType( format, typeout ) ) { return( GLU.GLU_INVALID_OPERATION ); } - beforeimage = ByteBuffer.allocateDirect( image_size( widthin, heightin, format, GL2.GL_UNSIGNED_SHORT ) ).order( ByteOrder.nativeOrder() ); - afterimage = ByteBuffer.allocateDirect( image_size( widthout, heightout, format, GL2.GL_UNSIGNED_SHORT ) ).order( ByteOrder.nativeOrder() ); + beforeimage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( image_size( widthin, heightin, format, GL2.GL_UNSIGNED_SHORT ) )); + afterimage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( image_size( widthout, heightout, format, GL2.GL_UNSIGNED_SHORT ) )); if( beforeimage == null || afterimage == null ) { return( GLU.GLU_OUT_OF_MEMORY ); } diff --git a/src/classes/com/sun/opengl/impl/glu/mipmap/ScaleInternal.java b/src/classes/com/sun/opengl/impl/glu/mipmap/ScaleInternal.java index f4d94412d..70ddab880 100644 --- a/src/classes/com/sun/opengl/impl/glu/mipmap/ScaleInternal.java +++ b/src/classes/com/sun/opengl/impl/glu/mipmap/ScaleInternal.java @@ -47,6 +47,7 @@ package com.sun.opengl.impl.glu.mipmap; import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.glu.GLU; +import javax.media.opengl.util.BufferUtil; import java.nio.*; /** @@ -2424,12 +2425,10 @@ public class ScaleInternal { } try { - beforeImage = ByteBuffer.allocateDirect( Mipmap.imageSize3D( widthIn, - heightIn, depthIn, format, GL2.GL_UNSIGNED_SHORT ) ).order( - ByteOrder.nativeOrder() ).asShortBuffer(); - afterImage = ByteBuffer.allocateDirect( Mipmap.imageSize3D( widthIn, - heightIn, depthIn, format, GL2.GL_UNSIGNED_SHORT ) ).order( - ByteOrder.nativeOrder() ).asShortBuffer(); + beforeImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.imageSize3D( widthIn, + heightIn, depthIn, format, GL2.GL_UNSIGNED_SHORT ) )).asShortBuffer(); + afterImage = BufferUtil.nativeOrder(ByteBuffer.allocateDirect( Mipmap.imageSize3D( widthIn, + heightIn, depthIn, format, GL2.GL_UNSIGNED_SHORT ) )).asShortBuffer(); } catch( OutOfMemoryError err ) { return( GLU.GLU_OUT_OF_MEMORY ); } diff --git a/src/classes/com/sun/opengl/impl/glu/mipmap/Type_Widget.java b/src/classes/com/sun/opengl/impl/glu/mipmap/Type_Widget.java index 7f6ab08c0..d5c6768b3 100644 --- a/src/classes/com/sun/opengl/impl/glu/mipmap/Type_Widget.java +++ b/src/classes/com/sun/opengl/impl/glu/mipmap/Type_Widget.java @@ -56,7 +56,7 @@ public class Type_Widget { /** Creates a new instance of Type_Widget */ public Type_Widget() { - buffer = ByteBuffer.allocate( 4 ); + buffer = ByteBuffer.allocateDirect( 4 ); } public void setUB0( byte b ) { diff --git a/src/classes/com/sun/opengl/impl/jawt/JAWTUtil.java b/src/classes/com/sun/opengl/impl/jawt/JAWTUtil.java index 790d965e9..c542b4703 100644 --- a/src/classes/com/sun/opengl/impl/jawt/JAWTUtil.java +++ b/src/classes/com/sun/opengl/impl/jawt/JAWTUtil.java @@ -64,7 +64,7 @@ public class JAWTUtil { private static boolean lockedToolkit; - public static void lockToolkit() throws GLException { + public static synchronized void lockToolkit() throws GLException { if (lockedToolkit) { throw new GLException("Toolkit already locked"); } @@ -84,13 +84,13 @@ public class JAWTUtil { JAWT.getJAWT().Lock(); } } catch (Exception e) { j2dOk=false; } - } + } if(!j2dOk) { JAWT.getJAWT().Lock(); } } - public static void unlockToolkit() { + public static synchronized void unlockToolkit() { if (lockedToolkit) { if (headlessMode) { // Workaround for running (to some degree) in headless diff --git a/src/classes/com/sun/opengl/impl/jawt/JAWTWindow.java b/src/classes/com/sun/opengl/impl/jawt/JAWTWindow.java index effe49b42..905614952 100644 --- a/src/classes/com/sun/opengl/impl/jawt/JAWTWindow.java +++ b/src/classes/com/sun/opengl/impl/jawt/JAWTWindow.java @@ -65,12 +65,12 @@ public abstract class JAWTWindow implements NativeWindow { protected int screenIndex; public JAWTWindow(Object comp) { - init(comp); + init((Component)comp); } - protected void init(Object windowObject) throws NativeWindowException { + protected void init(Component windowObject) throws NativeWindowException { invalidate(); - this.component = (Component)windowObject; + this.component = windowObject; initNative(); } @@ -124,7 +124,11 @@ public abstract class JAWTWindow implements NativeWindow { } public Object getWrappedWindow() { - return null; + return component; + } + + public final boolean isTerminalObject() { + return true; } public void setSize(int width, int height) { @@ -166,4 +170,13 @@ public abstract class JAWTWindow implements NativeWindow { return false; // FIXME } + public String toString() { + return "JAWT-Window[windowHandle "+getWindowHandle()+ + ", surfaceHandle "+getSurfaceHandle()+ + ", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ + ", visible "+isVisible()+ + ", wrappedWindow "+getWrappedWindow()+ + ", terminalObject "+isTerminalObject()+"]"; + } + } diff --git a/src/classes/com/sun/opengl/impl/jawt/x11/X11JAWTWindow.java b/src/classes/com/sun/opengl/impl/jawt/x11/X11JAWTWindow.java index 022010ebd..4e22babee 100644 --- a/src/classes/com/sun/opengl/impl/jawt/x11/X11JAWTWindow.java +++ b/src/classes/com/sun/opengl/impl/jawt/x11/X11JAWTWindow.java @@ -54,7 +54,7 @@ public class X11JAWTWindow extends JAWTWindow { protected void initNative() throws NativeWindowException { } - public int lockSurface() throws NativeWindowException { + public synchronized int lockSurface() throws NativeWindowException { int ret = super.lockSurface(); if(LOCK_SUCCESS != ret) { return ret; @@ -113,7 +113,7 @@ public class X11JAWTWindow extends JAWTWindow { return ret; } - public void unlockSurface() { + public synchronized void unlockSurface() { if(!isSurfaceLocked()) return; ds.FreeDrawingSurfaceInfo(dsi); ds.Unlock(); diff --git a/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java b/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java index ccafc6738..c52b46c7b 100644 --- a/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java @@ -87,9 +87,6 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl { this.chooser = chooser; } - public void destroy() { - } - public GLCapabilities getChosenGLCapabilities() { int numFormats = 1; GLCapabilities availableCaps[] = new GLCapabilities[numFormats]; diff --git a/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java index a52348bdd..c905ed48e 100644 --- a/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -66,7 +66,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { if (target == null) { throw new IllegalArgumentException("Null target"); } - target = NativeWindowHelper.unwrap(target); + target = NativeWindowFactory.getNativeWindow(target); if (capabilities == null) { capabilities = new GLCapabilities(); } diff --git a/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java b/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java index d5291af39..dab06f19a 100644 --- a/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java @@ -77,6 +77,7 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { } finally { getFactory().unlockToolkit(); } + super.destroy(); } public void setSize(int width, int height) { diff --git a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java index 85447f00b..bfd23bb0a 100644 --- a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java @@ -96,5 +96,6 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { WGL.DestroyWindow(hwnd); hwnd = 0; } + super.destroy(); } } diff --git a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java index 3a8f75d8e..826acc613 100755 --- a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java @@ -73,7 +73,4 @@ public class WindowsExternalWGLDrawable extends WindowsWGLDrawable { public int getHeight() { throw new GLException("Should not call this"); } - - public void destroy() { - } } diff --git a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java index 9f47a03d6..59eff795b 100644 --- a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java @@ -134,5 +134,6 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { } finally { getFactory().unlockToolkit(); } + super.destroy(); } } diff --git a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java index 7e55e715c..eabaaa796 100644 --- a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java @@ -101,6 +101,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { } finally { getFactory().unlockToolkit(); } + super.destroy(); } public void setSize(int newWidth, int newHeight) { diff --git a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index fac3d1ff6..78a617f8e 100644 --- a/src/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -73,7 +73,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { if (target == null) { throw new IllegalArgumentException("Null target"); } - target = NativeWindowHelper.unwrap(target); + target = NativeWindowFactory.getNativeWindow(target); if (capabilities == null) { capabilities = new GLCapabilities(); } diff --git a/src/classes/com/sun/opengl/impl/x11/glx/X11ExternalGLXDrawable.java b/src/classes/com/sun/opengl/impl/x11/glx/X11ExternalGLXDrawable.java index bbb33bd42..9b1ef65da 100755 --- a/src/classes/com/sun/opengl/impl/x11/glx/X11ExternalGLXDrawable.java +++ b/src/classes/com/sun/opengl/impl/x11/glx/X11ExternalGLXDrawable.java @@ -109,9 +109,6 @@ public class X11ExternalGLXDrawable extends X11GLXDrawable { throw new GLException("Should not call this"); } - public void destroy() { - } - class Context extends X11GLXContext { Context(X11GLXDrawable drawable, GLContext shareWith) { super(drawable, shareWith); diff --git a/src/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java b/src/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java index 457240503..5312e29c9 100644 --- a/src/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java +++ b/src/classes/com/sun/opengl/impl/x11/glx/X11GLXContext.java @@ -325,7 +325,7 @@ public abstract class X11GLXContext extends GLContextImpl { public boolean isOptimizable() { return (super.isOptimizable() && - !X11GLXDrawableFactory.getX11Factory().isVendorATI()); + !((X11GLXDrawableFactory)getGLDrawable().getFactory()).isVendorATI()); } //---------------------------------------------------------------------- diff --git a/src/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java index 075106005..8bf18e670 100644 --- a/src/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -114,7 +114,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { if (target == null) { throw new IllegalArgumentException("Null target"); } - target = NativeWindowHelper.unwrap(target); + target = NativeWindowFactory.getNativeWindow(target); X11OnscreenGLXDrawable drawable = new X11OnscreenGLXDrawable(this, target); long visualID = target.getVisualID(); int screen = target.getScreenIndex(); @@ -424,12 +424,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return caps; } - public void lockToolkit() { - } - - public void unlockToolkit() { - } - // Display connection for use by visual selection algorithm and by all offscreen surfaces private static long staticDisplay=0; private static boolean xineramaEnabled=false; @@ -508,10 +502,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return tmp[tmp_offset]; } - public static X11GLXDrawableFactory getX11Factory() { - return (X11GLXDrawableFactory) getFactory(false); - } - /** Workaround for apparent issue with ATI's proprietary drivers where direct contexts still send GLX tokens for GL calls */ public static boolean isVendorATI() { diff --git a/src/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java b/src/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java index 446d6f4e5..74b2191ab 100644 --- a/src/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java +++ b/src/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java @@ -131,11 +131,11 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { drawable = 0; pixmap = 0; display = 0; - nw.invalidate(); setChosenGLCapabilities(null); } finally { getFactory().unlockToolkit(); } + super.destroy(); } public boolean isDoubleBuffered() { diff --git a/src/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java b/src/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java index 1741ba72a..107eba9d2 100644 --- a/src/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java +++ b/src/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java @@ -66,23 +66,17 @@ public class X11OnscreenGLXDrawable extends X11GLXDrawable { public void swapBuffers() throws GLException { getFactory().lockToolkit(); - try { - boolean didLock = false; - + try { if (component.getSurfaceHandle() == 0) { if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { return; } - - didLock = true; } GLX.glXSwapBuffers(component.getDisplayHandle(), component.getSurfaceHandle()); - if (didLock) { - unlockSurface(); - } } finally { + unlockSurface(); getFactory().unlockToolkit(); } } diff --git a/src/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java b/src/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java index 3f29095cb..d5cdd6016 100644 --- a/src/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java +++ b/src/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java @@ -89,6 +89,7 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { } finally { getFactory().unlockToolkit(); } + super.destroy(); } public void setSize(int width, int height) { diff --git a/src/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXDrawableFactory.java b/src/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXDrawableFactory.java index a6f545b87..a5ec4c46c 100644 --- a/src/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXDrawableFactory.java @@ -171,11 +171,13 @@ public class X11AWTGLXDrawableFactory extends X11GLXDrawableFactory { } public void lockToolkit() { + super.lockToolkit(); JAWTUtil.lockToolkit(); } public void unlockToolkit() { JAWTUtil.unlockToolkit(); + super.unlockToolkit(); } } diff --git a/src/classes/javax/media/opengl/GLDrawable.java b/src/classes/javax/media/opengl/GLDrawable.java index e99764af7..ec1b5fc2d 100644 --- a/src/classes/javax/media/opengl/GLDrawable.java +++ b/src/classes/javax/media/opengl/GLDrawable.java @@ -151,4 +151,6 @@ public interface GLDrawable { public int lockSurface() throws GLException; public void unlockSurface(); public boolean isSurfaceLocked(); + + public String toString(); } diff --git a/src/classes/javax/media/opengl/GLDrawableFactory.java b/src/classes/javax/media/opengl/GLDrawableFactory.java index 2e6e2ccac..50cf96a33 100644 --- a/src/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/classes/javax/media/opengl/GLDrawableFactory.java @@ -90,7 +90,7 @@ public abstract class GLDrawableFactory { // and if so, try to instantiate the EGLDrawableFactory if (GLProfile.isGLES()) { try { - awtFactory = (GLDrawableFactory) GLReflection.createInstance("com.sun.opengl.impl.egl.awt.EGLDrawableFactory"); + awtFactory = (GLDrawableFactory) GLReflection.createInstance("com.sun.opengl.impl.egl.awt.EGLAWTDrawableFactory"); return; } catch (Exception e) { e.printStackTrace(); @@ -134,6 +134,19 @@ public abstract class GLDrawableFactory { } } + private static GLDrawableFactory getAWTFactory() + throws GLException + { + if(null==GLProfile.getProfile()) { + throw new GLException("No choosen/preset profile"); + } + initializeAWTFactory(); + if(awtFactory == null) { + throw new GLException("Could not determine the AWT-GLDrawableFactory"); + } + return awtFactory; + } + /** Initializes the sole GLDrawableFactory instance for the given profile. */ private static void initializeNWFactory() throws GLException { if (nwFactory != null) { @@ -183,51 +196,60 @@ public abstract class GLDrawableFactory { } } + private static GLDrawableFactory getNWFactory() + throws GLException + { + if(null==GLProfile.getProfile()) { + throw new GLException("No choosen/preset profile"); + } + initializeNWFactory(); + if(nwFactory == null) { + throw new GLException("Could not determine the NativeWindow-GLDrawableFactory"); + } + return nwFactory; + } + /** Creates a new GLDrawableFactory instance. End users do not need to call this method. */ protected GLDrawableFactory() { } - public static GLDrawableFactory getFactory(Object target) + /** Returns a GLDrawableFactory suitable to the passed winObj. + In case winObj is a NativeWindow, the wrapped window object will be used. */ + public static GLDrawableFactory getFactory(Object winObj) throws GLException { - if (target == null) { - throw new IllegalArgumentException("target is null"); + if (winObj == null) { + throw new IllegalArgumentException("winObj is null"); } - if (target instanceof NativeWindow) { - if (((NativeWindow) target).getWrappedWindow() != null) { - target = ((NativeWindow) target).getWrappedWindow(); + if ( winObj instanceof NativeWindow ) { + NativeWindow nw = (NativeWindow)winObj; + if(null!=nw.getWrappedWindow()) { + winObj = nw.getWrappedWindow(); } } - if (target instanceof NativeWindow) { - return getFactory(false); - } else if (NativeWindowFactory.isAWTComponent(target)) { - return getFactory(true); + return getFactory(winObj.getClass()); + } + + /** Returns a GLDrawableFactory suitable to the passed winClazz. */ + public static GLDrawableFactory getFactory(Class winClazz) + throws GLException + { + if (GLReflection.implementationOf(winClazz, NativeWindow.class.getName())) { + return getNWFactory(); + } else if (GLReflection.isAWTComponent(winClazz)) { + return getAWTFactory(); } throw new IllegalArgumentException("Target type is unsupported. Currently supported: \n"+ "\tjavax.media.opengl.NativeWindow\n"+ "\tjava.awt.Component\n"); } - public static GLDrawableFactory getFactory(boolean awt) + /** Returns the common GLDrawableFactory, suitable for NativeWindow. */ + public static GLDrawableFactory getFactory() throws GLException { - if(null==GLProfile.getProfile()) { - throw new GLException("No choosen/preset profile"); - } - if(awt) { - initializeAWTFactory(); - if(awtFactory == null) { - throw new GLException("Could not determine the AWT-GLDrawableFactory"); - } - return awtFactory; - } else { - initializeNWFactory(); - if(nwFactory == null) { - throw new GLException("Could not determine the NativeWindow-GLDrawableFactory"); - } - return nwFactory; - } + return getNWFactory(); } /** Shuts down this GLDrawableFactory, releasing resources diff --git a/src/classes/javax/media/opengl/NativeWindow.java b/src/classes/javax/media/opengl/NativeWindow.java index 1ab7c7c7a..f9785ccc6 100644 --- a/src/classes/javax/media/opengl/NativeWindow.java +++ b/src/classes/javax/media/opengl/NativeWindow.java @@ -39,6 +39,26 @@ package javax.media.opengl; +/** Interface for a native window object. + This can be a representation of a fully functional + native window, i.e. a terminal object, where + {@link NativeWindow#isTerminalObject()} returns true. + Otherwise it is a a proxy for a wrapped + Java-level window toolkit window object (e.g. java.awt.Component), + which can be retrieved with + {@link NativeWindow#getWrappedWindow()}. + + In case the NativeWindow is a terminal object, + where the NativeWindow implementation took care of exposing + all necessary native windowing information, + the utilizing toolkit (e.g. JOGL) will use a generic implementation + and use the native information directly. + + In case the NativeWindow is a proxy object, + where no native windowing information is available yet, + the utilizing toolkit (e.g. JOGL) is expected to have a specific implementation + path to handle the wrapped Java-level window toolkit window object. */ + public interface NativeWindow { public static final int LOCK_NOT_SUPPORTED = 0; public static final int LOCK_SURFACE_NOT_READY = 1; @@ -99,10 +119,18 @@ public interface NativeWindow { /** * If this NativeWindow actually wraps a window from a Java-level - * window toolkit like the AWT, returns the underlying window. + * window toolkit, return the underlying window object. */ public Object getWrappedWindow(); + /** + * @return True, if this NativeWindow is a terminal object, + * i.e. all native windowing information is available. + * False otherwise, ie. it holds a wrapped window object, + * from which native handles must be derived by the utilizing tookit. + */ + public boolean isTerminalObject(); + public void setSize(int width, int height); public void setPosition(int x, int y); public int getWidth(); diff --git a/src/classes/javax/media/opengl/NativeWindowFactory.java b/src/classes/javax/media/opengl/NativeWindowFactory.java index 006cb03ba..ee28bfea1 100644 --- a/src/classes/javax/media/opengl/NativeWindowFactory.java +++ b/src/classes/javax/media/opengl/NativeWindowFactory.java @@ -82,44 +82,59 @@ public class NativeWindowFactory { } /** - * Returns true, if the given object is an instance of java.awt.Component. - * This check is performed on a Class.getName() basis, - * hence the independency to the java.awt.* package. - */ - public static boolean isAWTComponent(Object target) { - return GLReflection.instanceOf(target, "java.awt.Component"); - } - - /** * Returns a NativeWindow. * - * @throws IllegalArgumentException if the passed target is null + * This method digest a window object 'winObj'. + * This can be either itself a NativeWindow, + * or any other Java-level window toolkit window object. + * + * In case 'winObj' is a terminal NativeWindow, where + * {@link NativeWindow#isTerminalObject()} returns true, + * it is passed through directly. + * + * Otherwise either the non NativeWindow object, + * or the wrapped window object within the proxy NativeWindow + * will be used to factor a terminal NativeWindow. + * + * @throws IllegalArgumentException if the passed winObj is null + * @throws NativeWindowException if the passed winObj's is a proxy NativeWindow + * and does not hold a supported wrapped window object, + * or it is not a supported window object. * @throws GLException if any window system-specific errors caused * the creation of the GLDrawable to fail. */ - public static NativeWindow getNativeWindow(Object target) - throws IllegalArgumentException, GLException + public static NativeWindow getNativeWindow(Object winObj) + throws IllegalArgumentException, GLException, NativeWindowException { - if(null==target) { - throw new IllegalArgumentException("target is null"); + if(null==winObj) { + throw new IllegalArgumentException("winObj is null"); } - if(target instanceof NativeWindow) { - return (NativeWindow)target; + if(winObj instanceof NativeWindow) { + NativeWindow nw = (NativeWindow) winObj; + if(nw.isTerminalObject()) { + return nw; // use the terminal NativeWindow object directly + } + Object wrappedWindow = nw.getWrappedWindow(); + if(null==wrappedWindow) { + throw new NativeWindowException("Proxy NativeWindow holds no wrapped window: "+nw); + } + winObj = wrappedWindow; } - if (isAWTComponent(target)) { + + if (GLReflection.isAWTComponent(winObj)) { initializeAWTFactory(); if(awtFactory == null) { throw new GLException("Could not determine an AWT-NativeWindow constructor"); } try { - return (NativeWindow) awtFactory.newInstance(new Object[] { target }); + return (NativeWindow) awtFactory.newInstance(new Object[] { winObj }); } catch (Exception ie) { ie.printStackTrace(); } } - throw new IllegalArgumentException("Target type is unsupported. Currently supported: \n"+ - "\tjavax.media.opengl.NativeWindow\n"+ - "\tjava.awt.Component\n"); + throw new NativeWindowException("Target type is unsupported. Currently supported: \n"+ + "\tjavax.media.opengl.NativeWindow\n"+ + "\tjava.awt.Component\n"); } } diff --git a/src/classes/javax/media/opengl/awt/GLCanvas.java b/src/classes/javax/media/opengl/awt/GLCanvas.java index d002b58de..838ce7129 100644 --- a/src/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/classes/javax/media/opengl/awt/GLCanvas.java @@ -43,6 +43,7 @@ import javax.media.opengl.*; import java.awt.Canvas; import java.awt.Color; +import java.awt.Component; import java.awt.EventQueue; import java.awt.FontMetrics; import java.awt.Graphics; @@ -141,8 +142,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { this.glCaps = capabilities; } if (!Beans.isDesignTime()) { - drawable = GLDrawableFactory.getFactory(true).createGLDrawable(NativeWindowFactory.getNativeWindow(this), - capabilities, chooser); + drawable = GLDrawableFactory.getFactory(this.getClass()).createGLDrawable(NativeWindowFactory.getNativeWindow(this), + capabilities, chooser); context = (GLContextImpl) drawable.createContext(shareWith); context.setSynchronized(true); } @@ -549,9 +550,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { } AWTGraphicsConfiguration config = (AWTGraphicsConfiguration) - GLDrawableFactory.getFactory(true).chooseGraphicsConfiguration(capabilities, - chooser, - new AWTGraphicsDevice(device)); + GLDrawableFactory.getFactory(Component.class).chooseGraphicsConfiguration(capabilities, + chooser, + new AWTGraphicsDevice(device)); if (config == null) { return null; } diff --git a/src/classes/javax/media/opengl/awt/gl2/GL2JPanel.java b/src/classes/javax/media/opengl/awt/gl2/GL2JPanel.java index 951bee66c..a48fa3676 100644 --- a/src/classes/javax/media/opengl/awt/gl2/GL2JPanel.java +++ b/src/classes/javax/media/opengl/awt/gl2/GL2JPanel.java @@ -211,7 +211,7 @@ public class GL2JPanel extends JPanel implements AWTGLAutoDrawable { getDefaultConfiguration()); } GLProfile.setProfile(GLProfile.GL2); - factory = GLDrawableFactoryImpl.getFactoryImpl(true); + factory = GLDrawableFactoryImpl.getFactoryImpl(Component.class); } /** Creates a new GL2JPanel component with a default set of OpenGL diff --git a/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp b/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp index 97d54b932..3ead1a4e9 100755 --- a/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp +++ b/src/classes/javax/media/opengl/util/BufferUtil.java.javame_cdc_fp @@ -229,18 +229,7 @@ public class BufferUtil { return dest; } - //---------------------------------------------------------------------- - // Internals only below this point - // - - // NOTE that this work must be done reflectively at the present time - // because this code must compile and run correctly on both CDC/FP and J2SE - private static boolean isCDCFP; - private static Class byteOrderClass; - private static Object nativeOrderObject; - private static Method orderMethod; - - private static void nativeOrder(ByteBuffer buf) { + public static ByteBuffer nativeOrder(ByteBuffer buf) { if (!isCDCFP) { try { if (byteOrderClass == null) { @@ -261,5 +250,18 @@ public class BufferUtil { } } } + return buf; } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + // NOTE that this work must be done reflectively at the present time + // because this code must compile and run correctly on both CDC/FP and J2SE + private static boolean isCDCFP; + private static Class byteOrderClass; + private static Object nativeOrderObject; + private static Method orderMethod; + } diff --git a/src/classes/javax/media/opengl/util/BufferUtil.java.javase b/src/classes/javax/media/opengl/util/BufferUtil.java.javase index 2c49d5fae..66a8acaff 100755 --- a/src/classes/javax/media/opengl/util/BufferUtil.java.javase +++ b/src/classes/javax/media/opengl/util/BufferUtil.java.javase @@ -252,18 +252,7 @@ public class BufferUtil { return dest; } - //---------------------------------------------------------------------- - // Internals only below this point - // - - // NOTE that this work must be done reflectively at the present time - // because this code must compile and run correctly on both CDC/FP and J2SE - private static boolean isCDCFP; - private static Class byteOrderClass; - private static Object nativeOrderObject; - private static Method orderMethod; - - private static void nativeOrder(ByteBuffer buf) { + public static ByteBuffer nativeOrder(ByteBuffer buf) { if (!isCDCFP) { try { if (byteOrderClass == null) { @@ -284,5 +273,18 @@ public class BufferUtil { } } } + return buf; } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + // NOTE that this work must be done reflectively at the present time + // because this code must compile and run correctly on both CDC/FP and J2SE + private static boolean isCDCFP; + private static Class byteOrderClass; + private static Object nativeOrderObject; + private static Method orderMethod; + } diff --git a/src/classes/javax/media/opengl/util/Gamma.java b/src/classes/javax/media/opengl/util/Gamma.java index 201144e3f..ba7bc5a32 100755 --- a/src/classes/javax/media/opengl/util/Gamma.java +++ b/src/classes/javax/media/opengl/util/Gamma.java @@ -87,7 +87,7 @@ public class Gamma { * out-of-bounds */ public static boolean setDisplayGamma(float gamma, float brightness, float contrast) throws IllegalArgumentException { - return GLDrawableFactoryImpl.getFactoryImpl(false).setDisplayGamma(gamma, brightness, contrast); + return GLDrawableFactoryImpl.getFactoryImpl().setDisplayGamma(gamma, brightness, contrast); } /** @@ -101,6 +101,6 @@ public class Gamma { * unspecified behavior during JVM teardown. */ public static void resetDisplayGamma() { - GLDrawableFactoryImpl.getFactoryImpl(false).resetDisplayGamma(); + GLDrawableFactoryImpl.getFactoryImpl().resetDisplayGamma(); } } |